-
Notifications
You must be signed in to change notification settings - Fork 808
Disallow illegal Atomic targets + propagate consts #4453
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
This disallows a number of illegal destination parameters to atomic operations. This includes SRVs and other const values, non-groupshared and non-resourse variables, members of typed resources, and bitfield members of any resource. In addition, this correctly propagates const information so that they can be properly rejected and also the information is reflected. This involves the consolidation and earlier detection of a number of these failures as well as an expansion of that detection. Also adds validation checks that the targets are not const and either UAVs or groupshared address space. Add compilation tests as well as validation tests for all. Fixes microsoft#4319 Fixes microsoft#4377 Fixes microsoft#4437
| dxilutil::EmitErrorOnInstruction(userCall, "Invalid operation on typed buffer."); | ||
| return; | ||
| break; | ||
| } |
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.
All of this was just to generate different errors when atomic ops were performed on typed resources had non-scalar elements. Because this is handled elsewhere, the distinction need not be done here anymore
tools/clang/test/HLSLFileCheck/hlsl/intrinsics/atomic/atomic_restypes.hlsl
Outdated
Show resolved
Hide resolved
|
✅ Build DirectXShaderCompiler 1.0.1619 completed (commit 41fe64520e by @pow2clk) |
|
✅ Build DirectXShaderCompiler 1.0.1620 completed (commit 52d9b4952b by @pow2clk) |
tools/clang/test/HLSLFileCheck/hlsl/diagnostics/errors/write_const_arrays.hlsl
Outdated
Show resolved
Hide resolved
tools/clang/test/HLSLFileCheck/hlsl/diagnostics/errors/write_const_arrays.hlsl
Outdated
Show resolved
Hide resolved
tools/clang/test/HLSLFileCheck/hlsl/intrinsics/atomic/atomic_restypes.hlsl
Outdated
Show resolved
Hide resolved
add test for reviewer commented lib export func test remove unintended and fairly weird unsubscripted references to resources in restypes test add more specific checks for unfound atomics for resources in restypes
|
✅ Build DirectXShaderCompiler 1.0.1624 completed (commit 93afc07e4a by @pow2clk) |
pow2clk
left a comment
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.
Respond to feedback
tools/clang/test/HLSLFileCheck/hlsl/diagnostics/errors/write_const_arrays.hlsl
Outdated
Show resolved
Hide resolved
tools/clang/test/HLSLFileCheck/hlsl/diagnostics/errors/write_const_arrays.hlsl
Outdated
Show resolved
Hide resolved
Add location information for overload mismatch notes. Their absence was preventing verifier tests from working. For note referring to declaration location, skip if ther is no location due to being builtin Convert all new error tests to verifier tests Reword an erorr message revise test to be valid HLSL
|
❌ Build DirectXShaderCompiler 1.0.1634 failed (commit 5f0d0fd41e by @pow2clk) |
Add drilling through GEP and BC for groupshared atomic validation Add validation test for const groupshared atomic used through a GEP Enhance error detection for atomics at lowering time by accounting for any sequence of GEP and subscript operations that might end with a valid resource. Add various new testing for atomic operations performed on destination values that are attached to a string of GEP and subscripts.
|
❌ Build DirectXShaderCompiler 1.0.1635 failed (commit d1c4caa2e6 by @pow2clk) |
|
❌ Build DirectXShaderCompiler 1.0.1636 failed (commit c4dbf01bdd by @pow2clk) |
|
❌ Build DirectXShaderCompiler 1.0.1637 failed (commit b4a701ef50 by @pow2clk) |
|
✅ Build DirectXShaderCompiler 1.0.1639 completed (commit 15f597ffed by @pow2clk) |
tex3d
left a comment
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.
Comments about strange/misleading error messages are really just to note, not for fixing in this PR. Makes sense to add new verifier tests to VerifierHelper though.
| // Assigning using dest param of atomics | ||
| // Distinct because of special handling of atomics dest param | ||
| InterlockedAdd(local[0], 1); /* expected-error {{no matching function for call to 'InterlockedAdd'}} expected-note {{candidate function not viable: 1st argument ('const uint') would lose const qualifier}} expected-note {{candidate function not viable: no known conversion from 'const uint' to 'unsigned long long &' for 1st argument}} */ | ||
| InterlockedAdd(gs_val[0], 1); /* expected-error {{no matching function for call to 'InterlockedAdd'}} expected-note {{candidate function not viable: 1st argument ('const uint') would lose const qualifier}} expected-note {{candidate function not viable: no known conversion from 'const uint' to 'unsigned long long' for 1st argument}} */ |
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.
Strange, why does this one (and next two) say to 'unsigned long long' instead of 'unsigned long long &' like the first one?
And why would it be unsigned long long in the first place, since I presume this should take a 32-bit reference?
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.
Another "quirk" of how atomics are lowered. The dest param is not made a reference until the candidate function is first added to the used intrinsics. Subsequent candidates are found to match the existing so their params don't get converted. It's only an issue for matching failures. We should talk about why it was designed this way in the first place.
| InterlockedOr(str[tid.y].q, 2); /* expected-error {{no matching function for call to 'InterlockedOr'}} expected-note {{candidate function not viable: no known conversion from 'uint' to 'unsigned int' for 1st argument}} expected-note {{candidate function not viable: no known conversion from 'uint' to 'unsigned long long' for 1st argument}} */ | ||
| InterlockedCompareStore(str[tid.y].q, 3, 1); /* expected-error {{no matching function for call to 'InterlockedCompareStore'}} expected-note {{candidate function not viable: no known conversion from 'uint' to 'unsigned int' for 1st argument}} expected-note {{candidate function not viable: no known conversion from 'uint' to 'unsigned long long' for 1st argument}} */ | ||
|
|
||
| InterlockedOr(gs.q, 2); /* expected-error {{no matching function for call to 'InterlockedOr'}} expected-note {{candidate function not viable: 1st argument ('__attribute__((address_space(3))) uint') is in address space 3, but parameter must be in address space 0}} expected-note {{candidate function not viable: no known conversion from '__attribute__((address_space(3))) uint' to 'unsigned long long' for 1st argument}} */ |
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.
It's a shame about the address space error, since it's misleading.
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.
Less so than the previous I'd say. Bitfields just make the compiler do your shifting and casting for you. The result of that operation is a local. Granted, shader authors may not know that. We could consider creating some custom mismatch types at some point. That would be useful in all versions of LLVM unless they've seriously overhauled this system
|
✅ Build DirectXShaderCompiler 1.0.1647 completed (commit 2d493afa0b by @pow2clk) |
Change some function signatures and local variables in SemaHLSL to try to avoid mistakenly comparing matching opcodes from different namespaces
|
✅ Build DirectXShaderCompiler 1.0.1651 completed (commit 0d8242bcc6 by @pow2clk) |
This disallows a number of illegal destination parameters to atomic
operations. This includes SRVs and other const values, non-groupshared
and non-resourse variables, members of typed resources, and bitfield
members of any resource.
In addition, this correctly propagates const information so that they
can be properly rejected and also the information is reflected.
This involves the consolidation and earlier detection of a number of
these failures as well as an expansion of that detection.
Also adds validation checks that the targets are not const and either
UAVs or groupshared address space.
Add compilation tests as well as validation tests for all.
Fixes #4319
Fixes #4377
Fixes #4437