Skip to content

[SPIR-V] Huge memory usage #7488

Closed as duplicate
Closed as duplicate

Description

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.

Environment

  • dxcompiler.dll 1.8
  • Windows 10

dxc_repro.zip

Activity

  1. added
    bug
    spirv
    needs-triage
    on May 27, 2025
  2. brakhane commented on May 27, 2025

    @brakhane

    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

  3. turanszkij commented on May 28, 2025

    @turanszkij
    Author

    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:

    inline FrameCB GetFrame()
    {
    	return g_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.

  4. s-perron commented on May 29, 2025

    @s-perron
    Collaborator

    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.

  5. s-perron commented on May 29, 2025

    @s-perron
    Collaborator

    not enough to just remove the inline

    Inlining is very aggressive. We will inline every function call unless it is marked as no inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugspirv

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions