2
$\begingroup$

I am involved in a project that had been modified to run on Apple and Linux computers, when it was originally Windows only. Specifically, Metal and Vulkan renderers have been written alongside the Direct3D one.

Something I have noticed is that there is a static startup image for 3-4 mins with the text "warming shaders", which is not there in the Windows version. This screen is not present after the first launch.

Searching online did not give me any results that shed light on this. The one SO question asked about "background prewarming" which I presume could be used to avoid a long load screen? In any case, it doesn't explain what it IS.

Simply put, what is shader warming, and why does Metal and Vulkan seem to require it? I have experience with OpenGL from many years ago where shaders were compiled from source at runtime. Is this a related concept? As I understand it, both Metal and Vulkan use binary/bytecode shaders, so compiling shouldn't be necessary.

$\endgroup$
5
$\begingroup$

I hadn't heard the phrase 'shader warming' before, but from some googling around, it seems that some games/engines use this term for a method of forcing the shaders to be fully compiled during level load, as explained in this answer, to avoid hitches during gameplay.

In Metal/Vulkan/D3D12, it's true that shaders are precompiled to a bytecode form, but this is hardware-independent bytecode; the shaders still need to be further compiled to the GPU-specific machine code, which (in those APIs) is done by the graphics driver when a pipeline state object is created. If there are a lot of shaders, that can potentially take awhile. The fully compiled shaders can also be cached, so this only needs to be done the first time you run the app (at least until you update the driver, which could invalidate the cached results).

So my guess about what's going on in your app is that the Metal/Vulkan renderers are calling it 'shader warming' when they go through and create all the pipeline state objects they're going to need—which entails compiling all the shaders. Meanwhile, in the Windows renderer, assuming it's D3D11 or earlier (not D3D12), perhaps the app is relying on the driver to compile shaders in the background, which lets it appear to load faster—at the cost of potentially having hitches a bit later if it tries to use a shader that's not finished compiling yet.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.