Skip to content

[SPIR-V] SV_ShadingRate disables optimizations #6915

Closed

Description

@Error-mdl

Description
If the SV_ShadingRate semantic is used in any shader stage that supports it, the compiler seems to skip optimizing out unused resources as though the -fspv-preserve-bindings flag were set. Additionally it does not remove unused variables in the input. Directly appending just the SPV_KHR_fragment_shading_rate extension via inline SPIR-V produces the same result.

Steps to Reproduce
Godbolt Link

Using this shader: test.hlsl:

Compile 3 times with the following command line arguments:
normal: -E vertex -T vs_6_5 -spirv -fspv-target-env=vulkan1.2
with SV_ShadingRate: -E vertex -T vs_6_5 -spirv -fspv-target-env=vulkan1.2 -D SHADING_RATE
with just the extension: -E vertex -T vs_6_5 -spirv -fspv-target-env=vulkan1.2 -D EXT_ONLY

Results:
Normal
Shading Rate
Extension Only

Behavior
This vertex shader outputs a constant 0, so we should expect that all the textures, samplers, and cbuffer should be removed and the input vertex and texcoord semantics should be optimized away as well. This happens when the base shader is compiled. When adding SV_ShadingRate to the output or simply declaring the extension via inline SPIR-V, no resources are removed and the unused position and texcoord semantics are loaded.

Environment

  • DXC version 1.8.2407
  • Host Operating System: Windows 10 22H2

Activity

  1. added
    bug
    needs-triage
    spirv
    on Sep 13, 2024
  2. Error-mdl commented on Sep 14, 2024

    @Error-mdl
    Author

    Managed to track down the issue. Its the SPIRV-Tools aggressive dead code elimination pass. There's a whitelist of allowed extensions, and if the code contains an extension not on it the pass exits: https://github.com/KhronosGroup/SPIRV-Tools/blob/4451f6ab13dda98bf255a7cd7b4d120132dc0dfd/source/opt/aggressive_dead_code_elim_pass.cpp#L952 . I see no reason why SPV_KHR_fragment_shading_rate isn't in the list, and adding myself seems to work fine.

  3. s-perron commented on Sep 14, 2024

    @s-perron
    Collaborator

    Reopening to make sure we update the allow lists in spirv-opt. There are three passes that need to be updated.

  4. s-perron commented on Sep 14, 2024

    @s-perron
    Collaborator

    Reopening to make sure we update the allow lists in spirv-opt. There are three passes that need to be updated.

  5. added 3 commits that reference this issue on Oct 22, 2024
    1769192
    30bd159
    7db3308
  6. hosea1008 commented on Oct 25, 2024

    @hosea1008

    This also fixes #6982

  7. added a commit that references this issue on Oct 28, 2024
    e090984
  8. added a commit that references this issue on Jul 24, 2025
    a88efe4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugspirv

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions