Nvidia driver - shader cache setting not available?

Ask here if you experience technical problems with X4: Foundations.

Moderator: Moderators for English X Forum

Post Reply
user1679
Posts: 803
Joined: Fri, 20. Jul 18, 23:20

Nvidia driver - shader cache setting not available?

Post by user1679 » Tue, 12. Mar 24, 18:54

I have an RTX 3060 and recently updated my drivers to 551.76. I decided to add X4 under the "program settings" so I could tweak my AA settings a bit further. On the "global" settings tab of the driver panel there is a "shader caceh size" setting that can be anywhere from "default" to "unlimited" with varying GB sizes inbetween. For some reason this setting is not presented on the "program settings" tab for X4.exe.

I haven't found much information on this setting in regards to specific games. Is this something that X4.exe doesn't expose to the Nvidia driver? Is this perhaps something Nvidia has to add on a per-game basis? Does the global setting even effect X4.exe considering it uses Vulkan?

Thanks

Imperial Good
Moderator (English)
Moderator (English)
Posts: 4764
Joined: Fri, 21. Dec 18, 18:23
x4

Re: Nvidia driver - shader cache setting not available?

Post by Imperial Good » Tue, 12. Mar 24, 21:52

I think X4 manages and uses its own shader cache. I think the Nvidia shader cache is mostly targeting older games or games that for some other reason do not handle their own shader caches.

user1679
Posts: 803
Joined: Fri, 20. Jul 18, 23:20

Re: Nvidia driver - shader cache setting not available?

Post by user1679 » Wed, 13. Mar 24, 02:13

Imperial Good wrote:
Tue, 12. Mar 24, 21:52
I think X4 manages and uses its own shader cache. I think the Nvidia shader cache is mostly targeting older games or games that for some other reason do not handle their own shader caches.
Thanks, I did find this: AutomaticShaderCache8 on developer.nvidia.com. It looks like the Nvidia shader cache is for GL only. I have a little experience programming Direct X / OpenGL (though not shaders), but none with Vulkan. From what I can tell though, Vulkan doesn't really understand what GL shaders are and uses SPIR-V shaders but the Nvidia driver runs Vulkan within an OpenGL context, allowing GLSL shaders to be loaded by Vulkan.

So I would guess the Nvidia driver will compile shaders and hand them off to Vulkan but I'm still not positive that setting actually does anything for X4. My pipelinecache file in X4 directory didn't change much when enabling it but my GLCache file from Nvidia (%LocalAppData%\NVIDIA\GLCache) did grow to 37 MB.

Imperial Good
Moderator (English)
Moderator (English)
Posts: 4764
Joined: Fri, 21. Dec 18, 18:23
x4

Re: Nvidia driver - shader cache setting not available?

Post by Imperial Good » Wed, 13. Mar 24, 16:18

user1679 wrote:
Wed, 13. Mar 24, 02:13
From what I can tell though, Vulkan doesn't really understand what GL shaders are and uses SPIR-V shaders but the Nvidia driver runs Vulkan within an OpenGL context, allowing GLSL shaders to be loaded by Vulkan.
Vulkan defines its own shaders which have different feature support from OpenGL or DirectX shaders. To improve shader compile and load speed, as well as portability, Vulkan uses an intermediate binary language for shaders. Typically, human readable shader code is converted into this intermediate binary format at compile time, with the intermediate binary format shaders being loaded and compiled at runtime by the driver into machine specific shader bytecode. This machine specific shader bytecode can be cached per machine and potentially loaded directly in subsequent runs to reduce compiler overhead, as the compiler is still a non-trivial step, especially with complex shader programs.
user1679 wrote:
Wed, 13. Mar 24, 02:13
So I would guess the Nvidia driver will compile shaders and hand them off to Vulkan but I'm still not positive that setting actually does anything for X4. My pipelinecache file in X4 directory didn't change much when enabling it but my GLCache file from Nvidia (%LocalAppData%\NVIDIA\GLCache) did grow to 37 MB.
The Nvidia driver implements Vulkan. The public Vulkan API outsources to appropriate driver implementations. What these implementations do is then up to the implementation creator. Using the public API calls, the driver can be instructed to compile the intermediate binary formatted shaders into hardware specific shader bytecode that is executed by the GPU core. Other high level calls exist to fetch the resulting shader bytecode, as well as load such shader bytecode instead of needing to compile it from the intermediate binary format.

As far as X4 goes, I suspect all the shader bytecode is cached in the pipelinecache file in the X4 user directory. Every time there is a graphic driver change, GPU change or X4 update, the contents of the cache will likely be invalidated and shaders recompiled from the intermediate binary formatted files next time X4 runs. I am unsure when the shaders are compiled, but it will either be during load, or cause a brief stutter during transitions.

Above I do not use the exact Vulkan terminology to try and make it easier to understand. If you want more details as to how it works with Vulkan the following link provides some.
https://docs.vulkan.org/guide/latest/pi ... cache.html

Your GLCache file growing in size might be from other applications.

user1679
Posts: 803
Joined: Fri, 20. Jul 18, 23:20

Re: Nvidia driver - shader cache setting not available?

Post by user1679 » Thu, 14. Mar 24, 01:28

Very interesting, thanks for the link.

Post Reply

Return to “X4: Foundations - Technical Support”