protonscr

GPU offloading and shader precaching

steamopen
ValveSoftware/steam-for-linux#7903 · opened 2021-07-05 by sabian2008 · updated 2026-01-03 · 12 comments · github
Ssabian2008 2021-07-05 github

Hi

I've looked everywhere on internet and searched this bug trucker with tons of keywords without finding an answer to this simple question.

How does shader precaching work when paired up with offloading, in particular NVidia offloading? I can think of three scenarios

  1. I start steam on the iGPU but then I add __NV_PRIME_RENDER_OFFLOAD=1 %command% (and, eventually, the other GLX/VK flags) to the launch options of a certain game, do shaders get precompiled for my NVidia card?
  2. I start steam on the iGPU but then I add gamemoderun %command%, with the following environment variable defined
    GAMEMODERUNEXEC=env __NV_PRIME_RENDER_OFFLOAD=1 env __GLX_VENDOR_LIBRARY_NAME=nvidia env __VK_LAYER_NV_optimus=NVIDIA_only
    to the launch options of a certain game, do shaders get precompiled for my NVidia card? (`gamemoderun is used as an example here, any other script that indirectly sets the appropriate envvars should do it).
  3. I start steam with __NV_PRIME_RENDER_OFFLOAD=1 steam and play everything using the dGPU, do shaders get precompiled for the NVidia card?

Sorry for the inconvenience, but I've been wondering this for months, and the only hits I found on Google were people with the same question who couldn't get a definitive answer. This is probably not an issue but a question addressed to @kisak-valve or anyone else with the technical knowledge of how is precaching implemented. I hope that by asking here, the question can serve other people.

P.S: If it serves for something, I am running Fedora 33 with the latest stable drivers from rpmfusion and using 1650 SUPER with an i7 4790K.

Kkisak-valve maintainer 2021-07-05 github

Hello @sabian2008, I do not have any insight beyond what you can observe on your own. That said, I would not expect per-game launch options to influence the fossilize child process when replaying .foz to warm the video driver's on-disk shader cache. My assumption would be that case 1 and 2 would not influence shader pre-caching, but case 3 could.

While fossilize is running to replay shaders, you should be able to use htop, find the running fossilize process, then press e to view the environment variables of the process, and look for the PRIME offload related variables. That should be a decent indicator which video driver should be in use.

Ssabian2008 2021-07-05 github

Thanks a lot for the answer. I tested 3. yesterday and I could see fossilize processes running on the dGPU, but that is expected, as they are children of a process running on dGPU (steam). Next time I get a shader precaching I will look at the envvars to see if I notice something useful.

Will write back if I find anything worth reporting.

Is precaching support for offloading setups planned? Trying to answer the question myself, I guess offloading should be officially supported via GUI options (as I've seen discussed in another issue) first.

Kkakra 2021-07-07 github

As far as I know from discussion with Hans in the fossilize bug tracker, the GPU isn't utilized anyways by the shader pre-compile, so nothing gets offloaded to it. It's purely done in CPU. But the cache is dependent on the driver implementation, thus the fossilize process would need to know which driver it has to use. I think this question may be better placed in the fossilize bug tracker. I may have seen a note somewhere that it processes shaders for all GPUs available but I'm not sure.

The discussion about CPU and GPU utilization was part of the system overloading thread where I contributed some ideas and patches to improve the behavior, and the issue has been fixed since then - thanks to a great implementation by Hans.

This may be related: https://github.com/ValveSoftware/Fossilize/issues/110

Pphilipl 2022-02-03 github

My anecdotal experience is that even with steam running on the dGPU, shader conversion is targeting the iGPU, based on how it did a full conversion run after I switched from only using the dGPU to a hybrid off-load configuration.

RRoot-Core 2023-01-25 github

@kisak-valve One interesting question that came to my mind is, which version of the shader chache is downloaded? The iGPU is recognized as my system's GPU by Steam. So I would expect Steam to download the Shaders accordingly?

There should be more options in the GUI.. maybe max. threads / RAM and the index of GPU in question.

Sstephematician 2024-01-26 github

Is there any official word on this issue? I'm suspicious that shader pre-caching is not working in most games that are run via offloading - I get a lot of 'stutters' when I enter new areas in games but they disappear if I reload and play through again.

RRoot-Core 2024-01-26 github

I can't say anything definitive, but in my files are nvidiav1 folders.

~/.steam/steam/steamapps/shadercache/[...]/nvidiav1/GLCache/[...]/[...]/steam_shader_cache.bin

The fossilize process has no env variable containing "prime", but it wouldn't be relevant anyways, as the process does not utilize the GPU.

There are env variables for AMD and Nvidia, but only files for Nvidia.
I'm mildly positive that it works as intended.

Furthermore, the shader_log.txt has NVIDIA all over the place:

Processing NVIDIA cache file
Writing NVIDIA cache of 1 buckets
Done with merging potential NVIDIA fragments.
Finding NVIDIA cache files, base directory:

This is with an Intel/Nvidia combination. Steam recognizes the Intel GPU in the system information.

EDIT: I've looked into the fossilize code and it seems to pick the first GPU reported by the OS, if no index is specified. So it might differ on different machines / kernel or driver versions.

EDIT 2: Steam actually sets --device-index 0 - I'm not sure if it always sets 0, or if it actually selects the dGPU.

MMy1 2026-01-03 github

On that note the fossilize doesn't seem to run on gpu nearly at all for me (rx 7800xt on kubuntu 24.04) according to to nvtop they spawn in with 2MiB gpu mem but do all on the cpu (in my case a ryzen 1700x), which is a bit awkward and takes a decent while

Kkakra 2026-01-03 github

On that note the fossilize doesn't seem to run on gpu nearly at all for me (rx 7800xt on kubuntu 24.04) according to to nvtop they spawn in with 2MiB gpu mem but do all on the cpu (in my case a ryzen 1700x), which is a bit awkward and takes a decent while

This is normal: shaders are compiled on the CPU for the GPU. The shader cache only collects the raw source shaders as discovered by running games (using crowd-sourcing). fossilize will pass them through the driver to pre-compile them so they are ready when the game needs it. It needs to redo that for each driver version you run. GPUs don't compile shaders, they just run them.

Think of it like source code compiled on your local CPU, but the final target architecture where you run the binary is your GPU or a different CPU.

MMy1 2026-01-03 github

Oh, I'm sorry then, i thought one could offload the shader compilation to the gpu, but i guess not.

MMy1 2026-01-03 · hidden on GitHub github

Oh, I'm sorry then, i thought one could offload the shader compilation to the gpu, but i guess not.

Kkakra 2026-01-03 github

No worries... :-) Offloading is actually not a thing here, it's about pre-compiling in advance: fossilize is just about compiling shaders in advance, so games would not stutter when they need those shaders - it would result in short render freezes if the shaders needed to be compiled in advance (uses CPU, the rendering needs to wait for the shaders to be ready to run, etc), so it's better to have them compiled in advance.