-
Notifications
You must be signed in to change notification settings - Fork 787
[SPIR-V] Fixed a crash if encounter constant buffer fields with overlapping register assignments #7636
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
Conversation
…apping register assignments
✅ With the latest revision this PR passed the C/C++ code formatter. |
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, but we should add a test to https://github.com/microsoft/DirectXShaderCompiler/tree/68dedee546982f23a47766c20d37d587befb5ed0/tools/clang/test/CodeGenSPIRV.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! LGTM, but will require a test before approval/merging 😊
Sorry for the delay - fixed formatting and added a test |
Sorry I forgot to check this during the initial review, but seems like we have a behavior divergence between SPIR-V and DXIL. I think what you implemented is correct but need to double check in case that's a known HLSL weirdness. @spall : is DXIL allowing an overlap expected or a bug? // RUN: %dxc -T vs_6_6 -E vs_main %s -O3
// RUN: %dxc -T vs_6_6 -E vs_main %s -O3 -spirv
uniform float4x4 gMVP : register(c0);
uniform float4 gFoo : register(c0);
float4 vs_main(float4 pos : POSITION) : SV_Position {
return mul(gMVP, pos * gFoo);
}
|
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Hi @Keenuts, This is the separate DXC issue I've came across - it detects registers overlap, but not if it overlaps with the array. I was going to dive into that one separately. |
Yes, this is a DXC bug. Some of the corner cases for register bindings are broken in DXC, and this is one of them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM then!
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
The issue:
simple vertex shader like so
will result in an internal crash
Due to
LowerTypeVisitor
trying to assign offsets to fields without explicit locations.It'll sort fields first, which will fill the map with the fields first. And since it's using
std::map
- if there's fields with the sameregister
number - it'll only insert first, other will be left out, resulting nullptrs in the output vector.We read the content of the vector down the road crashing.
My change fixes the crash and tries to output somewhat useful info about compilation fail.
I hope this helps you in fixing it properly, or you can take it as it is.