-
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
Merged
+702
−124
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a1a30bb
Disallow illegal Atomic targets + propagate consts
192090e
simplify atomic verifier shader
1cd4f13
add lib test, refine restype test
9e9cdcb
repond to feedback
fd37bb2
Finish responding to feedback
f1a7a61
Add Zi to get automated test to replace proper variable
a1beefd
Make atomicsconst validation test reg name independent
7efb0b0
remove hack left in by mistake
73049ac
Include verifier tests in script
35d8c06
Add some foolproofing to opcode checks in codegen
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4421,6 +4421,44 @@ static Value* SkipAddrSpaceCast(Value* Ptr) { | |
| return Ptr; | ||
| } | ||
|
|
||
| // For known non-groupshared, verify that the destination param is valid | ||
| void ValidateAtomicDestination(CallInst *CI, HLObjectOperationLowerHelper *pObjHelper) { | ||
| Value *dest = CI->getArgOperand(HLOperandIndex::kInterlockedDestOpIndex); | ||
| // If we encounter a gep, we may provide a more specific error message | ||
| bool hasGep = isa<GetElementPtrInst>(dest); | ||
|
|
||
| // Confirm that dest is a properly-used UAV | ||
|
|
||
| // Drill through subscripts and geps, anything else indicates a misuse | ||
| while(true) { | ||
| if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(dest)) { | ||
| dest = gep->getPointerOperand(); | ||
| continue; | ||
| } | ||
| if (CallInst *handle = dyn_cast<CallInst>(dest)) { | ||
| hlsl::HLOpcodeGroup group = hlsl::GetHLOpcodeGroup(handle->getCalledFunction()); | ||
| if (group != HLOpcodeGroup::HLSubscript) | ||
| break; | ||
| dest = handle->getArgOperand(HLOperandIndex::kSubscriptObjectOpIdx); | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| if(pObjHelper->GetRC(dest) == DXIL::ResourceClass::UAV) { | ||
| DXIL::ResourceKind RK = pObjHelper->GetRK(dest); | ||
| if (DXIL::IsStructuredBuffer(RK)) | ||
| return; // no errors | ||
| if (DXIL::IsTyped(RK)) { | ||
| if (hasGep) | ||
| dxilutil::EmitErrorOnInstruction(CI, "Typed resources used in atomic operations must have a scalar element type."); | ||
| return; // error emitted or else no errors | ||
| } | ||
| } | ||
|
|
||
| dxilutil::EmitErrorOnInstruction(CI, "Atomic operation targets must be groupshared or UAV."); | ||
| } | ||
|
|
||
| Value *TranslateIopAtomicBinaryOperation(CallInst *CI, IntrinsicOp IOP, | ||
| DXIL::OpCode opcode, | ||
| HLOperationLowerHelper &helper, HLObjectOperationLowerHelper *pObjHelper, bool &Translated) { | ||
|
|
@@ -4431,11 +4469,13 @@ Value *TranslateIopAtomicBinaryOperation(CallInst *CI, IntrinsicOp IOP, | |
| if (addressSpace == DXIL::kTGSMAddrSpace) | ||
| TranslateSharedMemAtomicBinOp(CI, IOP, addr); | ||
| else { | ||
| // buffer atomic translated in TranslateSubscript. | ||
| // Do nothing here. | ||
| // Mark not translated. | ||
| // If not groupshared, we either have an error case or will translate | ||
| // the atomic op in the process of translating users of the subscript operator | ||
| // Mark not translated and validate dest param | ||
| Translated = false; | ||
| ValidateAtomicDestination(CI, pObjHelper); | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
|
|
@@ -4480,10 +4520,11 @@ Value *TranslateIopAtomicCmpXChg(CallInst *CI, IntrinsicOp IOP, | |
| if (addressSpace == DXIL::kTGSMAddrSpace) | ||
| TranslateSharedMemAtomicCmpXChg(CI, addr); | ||
| else { | ||
| // buffer atomic translated in TranslateSubscript. | ||
| // Do nothing here. | ||
| // Mark not translated. | ||
| // If not groupshared, we either have an error case or will translate | ||
| // the atomic op in the process of translating users of the subscript operator | ||
| // Mark not translated and validate dest param | ||
| Translated = false; | ||
| ValidateAtomicDestination(CI, pObjHelper); | ||
| } | ||
|
|
||
| return nullptr; | ||
|
|
@@ -7698,50 +7739,10 @@ void TranslateDefaultSubscript(CallInst *CI, HLOperationLowerHelper &helper, HL | |
| LI->eraseFromParent(); | ||
| continue; | ||
| } | ||
| if (!isa<CallInst>(GEPUser)) { | ||
| // Invalid operations. | ||
| Translated = false; | ||
| dxilutil::EmitErrorOnInstruction(GEP, "Invalid operation on typed buffer."); | ||
| return; | ||
| } | ||
| CallInst *userCall = cast<CallInst>(GEPUser); | ||
| HLOpcodeGroup group = | ||
| hlsl::GetHLOpcodeGroupByName(userCall->getCalledFunction()); | ||
| if (group != HLOpcodeGroup::HLIntrinsic) { | ||
| // Invalid operations. | ||
| Translated = false; | ||
| dxilutil::EmitErrorOnInstruction(userCall, "Invalid operation on typed buffer."); | ||
| return; | ||
| } | ||
| unsigned opcode = hlsl::GetHLOpcode(userCall); | ||
| IntrinsicOp IOP = static_cast<IntrinsicOp>(opcode); | ||
| switch (IOP) { | ||
| case IntrinsicOp::IOP_InterlockedAdd: | ||
| case IntrinsicOp::IOP_InterlockedAnd: | ||
| case IntrinsicOp::IOP_InterlockedExchange: | ||
| case IntrinsicOp::IOP_InterlockedMax: | ||
| case IntrinsicOp::IOP_InterlockedMin: | ||
| case IntrinsicOp::IOP_InterlockedUMax: | ||
| case IntrinsicOp::IOP_InterlockedUMin: | ||
| case IntrinsicOp::IOP_InterlockedOr: | ||
| case IntrinsicOp::IOP_InterlockedXor: | ||
| case IntrinsicOp::IOP_InterlockedCompareStore: | ||
| case IntrinsicOp::IOP_InterlockedCompareExchange: | ||
| case IntrinsicOp::IOP_InterlockedCompareStoreFloatBitwise: | ||
| case IntrinsicOp::IOP_InterlockedCompareExchangeFloatBitwise: { | ||
| // Invalid operations. | ||
| Translated = false; | ||
| dxilutil::EmitErrorOnInstruction( | ||
| userCall, "Typed resources used in atomic operations must have a scalar element type."); | ||
| return; | ||
| } break; | ||
| default: | ||
| // Invalid operations. | ||
| Translated = false; | ||
| dxilutil::EmitErrorOnInstruction(userCall, "Invalid operation on typed buffer."); | ||
| return; | ||
| break; | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| // Invalid operations. | ||
| Translated = false; | ||
| dxilutil::EmitErrorOnInstruction(GEP, "Invalid operation on typed buffer."); | ||
| return; | ||
| } | ||
| GEP->eraseFromParent(); | ||
| } else { | ||
|
|
@@ -7754,29 +7755,8 @@ void TranslateDefaultSubscript(CallInst *CI, HLOperationLowerHelper &helper, HL | |
| if (RC == DXIL::ResourceClass::SRV) { | ||
| // Invalid operations. | ||
| Translated = false; | ||
| switch (IOP) { | ||
| case IntrinsicOp::IOP_InterlockedAdd: | ||
| case IntrinsicOp::IOP_InterlockedAnd: | ||
| case IntrinsicOp::IOP_InterlockedExchange: | ||
| case IntrinsicOp::IOP_InterlockedMax: | ||
| case IntrinsicOp::IOP_InterlockedMin: | ||
| case IntrinsicOp::IOP_InterlockedUMax: | ||
| case IntrinsicOp::IOP_InterlockedUMin: | ||
| case IntrinsicOp::IOP_InterlockedOr: | ||
| case IntrinsicOp::IOP_InterlockedXor: | ||
| case IntrinsicOp::IOP_InterlockedCompareStore: | ||
| case IntrinsicOp::IOP_InterlockedCompareExchange: | ||
| case IntrinsicOp::IOP_InterlockedCompareStoreFloatBitwise: | ||
| case IntrinsicOp::IOP_InterlockedCompareExchangeFloatBitwise: { | ||
| dxilutil::EmitErrorOnInstruction( | ||
| userCall, "Atomic operation targets must be groupshared or UAV."); | ||
| return; | ||
| } break; | ||
| default: | ||
| dxilutil::EmitErrorOnInstruction(userCall, "Invalid operation on typed buffer."); | ||
| return; | ||
| break; | ||
| } | ||
pow2clk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dxilutil::EmitErrorOnInstruction(userCall, "Invalid operation on SRV."); | ||
| return; | ||
| } | ||
| switch (IOP) { | ||
| case IntrinsicOp::IOP_InterlockedAdd: { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.