You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Hi, I am seeing incredibly huge memory usage when compiling my shaders for SPIRV with the latest release (2025 February). It gets up to 16 GB, but only because I have that much RAM in my system, I think it would go above even that if it could. The compilation is also incredibly slow, which is probably related to this.
Steps to Reproduce
I created a repro main.cpp which is a small c++ win32 console application that will compile my shaders that I provided in the dxc_repro.zip.
The top of the main.cpp file has two defines:
#define COMPILE_SPIRV -- this enables spirv compilation, otherwise it they will be compiled to DXIL (which doesn't have memory issues)
#define COMPILE_WITH_THREADS -- this enables compiling with multiple threads (if not using this, then compilation is too slow)
Actual Behavior
Memory usage goes up to 16 GB and stays there.
Another thing that is weird is that the -spv-max-id setting is necessary, otherwise it runs foul of the 0x3fffff limit during compilation of some shaders; however once the shaders are actually compiled, spirv-val confirms that the max id isn't even close to the 0x3fffff limit. I'm assuming DXC creates a lot of intermediary ids that get optimized away later
There has been a development, Dennis Brakhane (@brakhane) found the main cause of the slowdown, and a workaround. This function in globals.hlsli is a global function that simply returns a big structure that is stored in a constant buffer:
inlineFrameCBGetFrame()
{
returng_xFrame;
}
If I rewrite it to use a macro, or add [noinline] (not enough to just remove the inline) then the whole compilation speed and memory issue is normal.
With this change it is also no longer necessary to use -fspv-max-id 4fffff for compilation.
Another thing that is weird is that the -spv-max-id setting is necessary, otherwise it runs foul of the 0x3fffff limit during compilation of some shaders; however once the shaders are actually compiled, spirv-val confirms that the max id isn't even close to the 0x3fffff limit. I'm assuming DXC creates a lot of intermediary ids that get optimized away later
The optimizer will use a new id every time it needs one. If there was an instruction that uses 3 and is then deleted, 3 will still not be used again. After the optimizations are done, DXC will run the "compact ids" pass that will renumber every so the ids are dense. So it is possible to run out of ids in the middle of optimizations.
Activity
brakhane commentedon May 27, 2025
Another thing that is weird is that the -spv-max-id setting is necessary, otherwise it runs foul of the 0x3fffff limit during compilation of some shaders; however once the shaders are actually compiled, spirv-val confirms that the max id isn't even close to the 0x3fffff limit. I'm assuming DXC creates a lot of intermediary ids that get optimized away later
turanszkij commentedon May 28, 2025
There has been a development, Dennis Brakhane (@brakhane) found the main cause of the slowdown, and a workaround. This function in globals.hlsli is a global function that simply returns a big structure that is stored in a constant buffer:
If I rewrite it to use a macro, or add
[noinline](not enough to just remove the inline) then the whole compilation speed and memory issue is normal.With this change it is also no longer necessary to use
-fspv-max-id 4ffffffor compilation.s-perron commentedon May 29, 2025
The optimizer will use a new id every time it needs one. If there was an instruction that uses 3 and is then deleted, 3 will still not be used again. After the optimizations are done, DXC will run the "compact ids" pass that will renumber every so the ids are dense. So it is possible to run out of ids in the middle of optimizations.
s-perron commentedon May 29, 2025
Inlining is very aggressive. We will inline every function call unless it is marked as no inline.