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

RDAT: Check flags and WaveSize for min SM; fix flag detection and merging #6207

Merged
merged 27 commits into from
Feb 10, 2024

Conversation

tex3d
Copy link
Contributor

@tex3d tex3d commented Jan 25, 2024

Add ShaderKind::Last_1_8 for shader mask
Add shader model comments before flag groupings in DxilConstants.h and DxilShaderFlags.

Add missing flag checks for min shader model in RDAT function info. Move ShaderCompatInfo computation into DxilModule, propagate callee info.

Move computation of shader model requirements based on flags into DxilModule. Finalize requirements for entry functions in AdjustMinimumShaderModelAndFlags.

Fixes for function level flag tracking:

  • DerivativesInMeshAndAmpShaders: use flag to track deriv use, then adjust for entry functions.
  • hasUAVs: based on resource use in function instead of global resources.
  • WriteableMSAATextures: based on use in function instead of global resources.
    • Also catch cases for dynamic res from any use by looking at create/annotate handle, not just the TextureStoreSample op.
  • RaytracingTier1_1: move module-level detection to CollectShaderFlagsForModule
  • Marked deriv and quad ops as being supported in node.
  • Fixed SampleCmpBias to be considered gradient op.
  • Update RDAT definitions to dump more useful info for testing

Fixes #6218.

Copy link
Contributor

github-actions bot commented Jan 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Adding OptFeatureInfo_UsesDerivatives to track per-function derivative usage,
otherwise we can't set DerivativesInMeshAndAmpShaders or min shader target properly.

This uses a feature bit in a special optional set of flags defined by the runtime to be ignored if set and unrecognized.
Since it's not a real feature requirement but a special flag used in computing feature requirements after accounting for all functions at link time, this is a good place for this special flag.
hasUAVs and hasWriteableMSAATextures were set based on global resource properties, instead of what the function actually used.
This change fixes that, additionally detecting cases that would have been missed by catching all handle cases.
This check did not belong in per-function CollectShaderFlags.
Moved to module.
OP::GetMinShaderModelAndMask needed to account for new Node shader.
Also, the barrier op check was not robust to an invalid operand, hit by validation test.
…rget

Feature flags were not taken into account when computing minimum shader targets.
Also, once a function is known to be a particular shader, we can translate the UsesDerivatives into the correct min target and potential DerivativesInMeshAndAmpShaders feature flag.

This also takes into account min target for WaveSize and WaveSize with Range.
ShaderCompatInfo was used to track per-function feature flag and min target for RDAT.
But internal calls were not traversed and the global feature flag collection had to do all the same work as the RDAT writer did redundantly.

This change moves this into DxilModule, where it can be computed once and cached for both the CollectShaderFlagsForModule, as well as the RDAT per-function lookup.
Along the way, DxilModule& needed to be made non-const for DxilRDATWriter so it could update the compat info, in case it was unwritten.
@tex3d tex3d marked this pull request as ready for review January 30, 2024 02:38
@tex3d
Copy link
Contributor Author

tex3d commented Jan 30, 2024

If you start here, then step through commits with [Next], it's a lot more digestible.

Add tests for several classes of deriv ops in node.
This also adds testing for barrier in node, which was a fix in this PR.
Copy link
Contributor

github-actions bot commented Feb 6, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Member

@pow2clk pow2clk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite done I'm afraid, but I wanted to give what I had.

A lot of this is nits to make it more readable, but there are some substantive comments too. Let me know if any are unclear which they are.

include/dxc/DXIL/DxilConstants.h Show resolved Hide resolved
include/dxc/DXIL/DxilConstants.h Outdated Show resolved Hide resolved
include/dxc/DXIL/DxilModule.h Outdated Show resolved Hide resolved
include/dxc/DXIL/DxilShaderFlags.h Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilModule.cpp Outdated Show resolved Hide resolved
One notable change is the elimination of the optimization in ComputeShaderCompatInfo where a function would be skipped if it already had ShaderCompatInfo.
This was incorrect, since this is happening inside the same loop that iterates intrinsics, which could add the compat info based on intrinsic usage.
That doesn't mean flags have been computed for the function, so I removed this and clear the map at the beginning of ComputeShaderCompatInfo to ensure it's fresh.

I also added IR tests, and ones that reorder intrinsics and the called function to ensure function ordering doesn't cause a problem.

I made these and the sm66_derivatives.hlsl test they were based on go back to SM 6.6, since there was another detail on that validator version that was different - it didn't set min shader model properly for lib functions.
The 1.6 validator is the one included in the latest Windows SDK, so going back this far seems good.

I also added the OptFeatureInfo flags to disassembly.
@tex3d tex3d requested a review from pow2clk February 8, 2024 03:18
Function-level UsesDerivatives flag is not necessary at global library level, so always clear it in CollectShaderFlagsForModule.

Prior code used !(SM->IsCS() || SM->IsPS()), which covered any new shader stages.
This flag only matters for VS, HS, DS, and GS.
I fixed the code, but left the old logic in for validator version 1.7 and below for compatibility.

Add bit index comments for the raw ShaderFlags bitfields to make decoding raw flags easier.

Fix metadata for validator version 1.7 in SM 6.7 IL test.
Add test for global ShaderFlags checking:
- masking of UsesDerivatives
- DerivativesInMeshAndAmpShaders from called function
- removal of UAVsAtEveryStage for library profile
Copy link
Member

@pow2clk pow2clk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with a long change like this, my comments tend toward complaining about how hard it is to read and review. Sorry about that.

I tried to make suggested changes where possible. Overall, this improves more than I expected to fix this bug. Now that it's done, that's great!

I don't think much needs to change, I just have a couple concerns and many readability suggestions.

lib/DXIL/DxilOperations.cpp Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Outdated Show resolved Hide resolved
lib/HLSL/DxilContainerReflection.cpp Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Outdated Show resolved Hide resolved
lib/DXIL/DxilShaderFlags.cpp Outdated Show resolved Hide resolved
lib/DxilContainer/DxilContainerAssembler.cpp Show resolved Hide resolved
Copy link
Member

@pow2clk pow2clk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the pretty printing! Thanks for all the responses!

@tex3d tex3d merged commit 9c518db into microsoft:main Feb 10, 2024
13 checks passed
tex3d added a commit to tex3d/DirectXShaderCompiler that referenced this pull request Feb 10, 2024
…ging (microsoft#6207)

Add ShaderKind::Last_1_8 for shader mask
Add shader model comments before flag groupings in DxilConstants.h and DxilShaderFlags.

Add missing flag checks for min shader model in RDAT function info. Move ShaderCompatInfo computation into DxilModule, propagate callee info.

Move computation of shader model requirements based on flags into DxilModule. Finalize requirements for entry functions in AdjustMinimumShaderModelAndFlags.

Fixes for function level flag tracking:
- DerivativesInMeshAndAmpShaders: use flag to track deriv use, then adjust for entry functions.
- hasUAVs: based on resource use in function instead of global resources.
- WriteableMSAATextures: based on use in function instead of global resources.
  - Also catch cases for dynamic res from any use by looking at create/annotate handle, not just the TextureStoreSample op.
- RaytracingTier1_1: move module-level detection to CollectShaderFlagsForModule
- Marked deriv and quad ops as being supported in node.
- Fixed SampleCmpBias to be considered gradient op.
- Update RDAT definitions to dump more useful info for testing

Fixes microsoft#6218.

(cherry picked from commit 9c518db)
tex3d added a commit that referenced this pull request Feb 10, 2024
…ging (#6207) (#6273)

Add ShaderKind::Last_1_8 for shader mask
Add shader model comments before flag groupings in DxilConstants.h and
DxilShaderFlags.

Add missing flag checks for min shader model in RDAT function info. Move
ShaderCompatInfo computation into DxilModule, propagate callee info.

Move computation of shader model requirements based on flags into
DxilModule. Finalize requirements for entry functions in
AdjustMinimumShaderModelAndFlags.

Fixes for function level flag tracking:
- DerivativesInMeshAndAmpShaders: use flag to track deriv use, then
adjust for entry functions.
- hasUAVs: based on resource use in function instead of global
resources.
- WriteableMSAATextures: based on use in function instead of global
resources.
- Also catch cases for dynamic res from any use by looking at
create/annotate handle, not just the TextureStoreSample op.
- RaytracingTier1_1: move module-level detection to
CollectShaderFlagsForModule
- Marked deriv and quad ops as being supported in node.
- Fixed SampleCmpBias to be considered gradient op.
- Update RDAT definitions to dump more useful info for testing

Fixes #6218.

(cherry picked from commit 9c518db)
@tex3d tex3d deleted the rdat-minsm-check-flags branch February 10, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Per-function feature flags and min target in RDAT are incorrect
4 participants