Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V] SV_ShadingRate disables optimizations #6915

Open
Error-mdl opened this issue Sep 13, 2024 · 3 comments · May be fixed by #6980
Open

[SPIR-V] SV_ShadingRate disables optimizations #6915

Error-mdl opened this issue Sep 13, 2024 · 3 comments · May be fixed by #6980
Assignees
Labels
bug Bug, regression, crash spirv Work related to SPIR-V
Milestone

Comments

@Error-mdl
Copy link

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
@Error-mdl Error-mdl added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Sep 13, 2024
@Error-mdl
Copy link
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.

@s-perron s-perron reopened this Sep 14, 2024
@s-perron
Copy link
Collaborator

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

@s-perron s-perron removed the needs-triage Awaiting triage label Sep 14, 2024
@s-perron s-perron added this to the Next Release milestone Sep 14, 2024
@s-perron
Copy link
Collaborator

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

Keenuts added a commit to Keenuts/DirectXShaderCompiler that referenced this issue Oct 22, 2024
Updated the SPIRV-Tools version.

Fixes microsoft#6915

Signed-off-by: Nathan Gauër <brioche@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash spirv Work related to SPIR-V
Projects
Status: New
Status: Triaged
Development

Successfully merging a pull request may close this issue.

3 participants