-
Notifications
You must be signed in to change notification settings - Fork 833
[Validator] Add validation for createHandleFromBinding #8205
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
Open
damyanp
wants to merge
17
commits into
microsoft:main
Choose a base branch
from
damyanp:copilot/fix-issue-7019-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+208
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e0ec755
Initial plan
Copilot d0d701c
Fix createHandleFromBinding index validation and add test (issue #7019)
Copilot c780148
Add test for index above upper bound in createHandleFromBinding valid…
Copilot 5dc365f
Add release note for CreateHandleFromBinding index validation fix
Copilot da8d8c3
Update release note to identify DXIL validation change
Copilot 9f17031
Verify code format changes come from the github-actions bot
damyanp 3c5196f
Merge remote-tracking branch 'origin/main' into copilot/fix-issue-701…
Copilot 41a15f9
Add comprehensive validation for CreateHandleFromBinding
Copilot 3b74288
Fix resourceClass comment in test to match enum values
Copilot 7dd68e5
Merge branch 'main' of https://github.com/damyanp/DirectXShaderCompil…
Copilot ca0336e
Update release note wording and add test for non-constant bind parameter
Copilot 99c3cc3
Restructure tests into passing/failing pair, drop non-constant bind test
Copilot 60dd05d
Restore non-constant bind test as third test file
Copilot 57301f7
Fix inaccurate comment in createHandleFromBinding_failing.ll
Copilot 0d38ccf
Reject non-constant index for non-array CreateHandleFromBinding
damyanp 3562ff9
Revert non-array index check; keep array non-constant index test
damyanp d815050
Apply LLVM naming conventions to CreateHandleFromBinding validation
damyanp 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
60 changes: 60 additions & 0 deletions
60
tools/clang/test/LitDXILValidation/createHandleFromBinding_failing.ll
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| ; REQUIRES: dxil-1-8 | ||
| ; RUN: not %dxv %s 2>&1 | FileCheck %s | ||
|
|
||
| ; Verify that createHandleFromBinding rejects out-of-range indices | ||
| ; and invalid resource classes. | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| %dx.types.Handle = type { i8* } | ||
| %dx.types.ResBind = type { i32, i32, i32, i8 } | ||
| %dx.types.ResourceProperties = type { i32, i32 } | ||
| %struct.RWByteAddressBuffer = type { i32 } | ||
|
|
||
| ; --- Index below lower bound --- | ||
| ; CHECK-DAG: error: Constant values must be in-range for operation. | ||
| ; CHECK-DAG: note: at '%1 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 0, i1 false)' in block '#0' of function 'main'. | ||
|
|
||
| ; --- Index above upper bound --- | ||
| ; CHECK-DAG: error: Constant values must be in-range for operation. | ||
| ; CHECK-DAG: note: at '%3 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 4, i1 false)' in block '#0' of function 'main'. | ||
|
|
||
| ; --- Invalid resource class --- | ||
| ; CHECK-DAG: error: Constant values must be in-range for operation. | ||
| ; CHECK-DAG: note: at '%5 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 5 }, i32 0, i1 false)' in block '#0' of function 'main'. | ||
|
|
||
| define void @main() { | ||
| ; Index 0 is below rangeLowerBound=1 | ||
| %1 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 0, i1 false) | ||
| %2 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ; Index 4 is above rangeUpperBound=3 | ||
| %3 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 4, i1 false) | ||
| %4 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %3, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ; resourceClass=5 is invalid (valid: 0=SRV, 1=UAV, 2=CBuffer, 3=Sampler) | ||
| %5 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 0, i32 0, i32 0, i8 5 }, i32 0, i1 false) | ||
| %6 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %5, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ret void | ||
| } | ||
|
|
||
| declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #0 | ||
| declare %dx.types.Handle @dx.op.createHandleFromBinding(i32, %dx.types.ResBind, i32, i1) #0 | ||
|
|
||
| attributes #0 = { nounwind readnone } | ||
|
|
||
| !llvm.ident = !{!0} | ||
| !dx.version = !{!1} | ||
| !dx.valver = !{!1} | ||
| !dx.shaderModel = !{!2} | ||
| !dx.resources = !{!3} | ||
| !dx.entryPoints = !{!6} | ||
|
|
||
| !0 = !{!"dxc(private) 1.8.0.15017 (main, 4e0f5364a-dirty)"} | ||
| !1 = !{i32 1, i32 8} | ||
| !2 = !{!"cs", i32 6, i32 8} | ||
| !3 = !{null, !4, null, null} | ||
| !4 = !{!5} | ||
| !5 = !{i32 0, %struct.RWByteAddressBuffer* undef, !"", i32 0, i32 1, i32 3, i32 11, i1 false, i1 false, i1 false, null} | ||
| !6 = !{void ()* @main, !"main", null, !3, !7} | ||
| !7 = !{i32 0, i64 8589934608, i32 4, !8} | ||
| !8 = !{i32 4, i32 1, i32 1} |
47 changes: 47 additions & 0 deletions
47
tools/clang/test/LitDXILValidation/createHandleFromBinding_non_constant_bind.ll
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ; REQUIRES: dxil-1-8 | ||
| ; RUN: not %dxv %s 2>&1 | FileCheck %s | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| %dx.types.Handle = type { i8* } | ||
| %dx.types.ResBind = type { i32, i32, i32, i8 } | ||
| %dx.types.ResourceProperties = type { i32, i32 } | ||
| %struct.RWByteAddressBuffer = type { i32 } | ||
|
|
||
| ; CHECK: error: Constant values must be in-range for operation. | ||
| ; CHECK: note: at '%2 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind %1, | ||
|
|
||
| define void @main(i32 %lowerBound) { | ||
| ; Construct a non-constant bind struct using a function parameter | ||
| %1 = insertvalue %dx.types.ResBind { i32 undef, i32 1, i32 0, i8 1 }, i32 %lowerBound, 0 | ||
| ; Pass non-constant bind to createHandleFromBinding — should fail validation | ||
| %2 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind %1, i32 0, i1 false) ; CreateHandleFromBinding(bind,index,nonUniformIndex) | ||
| %3 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %2, %dx.types.ResourceProperties { i32 4107, i32 0 }) ; AnnotateHandle(res,props) resource: RWByteAddressBuffer | ||
| ret void | ||
| } | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #0 | ||
|
|
||
| ; Function Attrs: nounwind readnone | ||
| declare %dx.types.Handle @dx.op.createHandleFromBinding(i32, %dx.types.ResBind, i32, i1) #0 | ||
|
|
||
| attributes #0 = { nounwind readnone } | ||
|
|
||
| !llvm.ident = !{!0} | ||
| !dx.version = !{!1} | ||
| !dx.valver = !{!1} | ||
| !dx.shaderModel = !{!2} | ||
| !dx.resources = !{!3} | ||
| !dx.entryPoints = !{!6} | ||
|
|
||
| !0 = !{!"dxc(private) 1.8.0.15017 (main, 4e0f5364a-dirty)"} | ||
| !1 = !{i32 1, i32 8} | ||
| !2 = !{!"cs", i32 6, i32 8} | ||
| !3 = !{null, !4, null, null} | ||
| !4 = !{!5} | ||
| !5 = !{i32 0, %struct.RWByteAddressBuffer* undef, !"", i32 0, i32 0, i32 1, i32 11, i1 false, i1 false, i1 false, null} | ||
| !6 = !{void (i32)* @main, !"main", null, !3, !7} | ||
| !7 = !{i32 0, i64 8589934608, i32 4, !8} | ||
| !8 = !{i32 4, i32 1, i32 1} |
53 changes: 53 additions & 0 deletions
53
tools/clang/test/LitDXILValidation/createHandleFromBinding_passing.ll
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ; REQUIRES: dxil-1-8 | ||
| ; RUN: %dxv %s | FileCheck %s | ||
|
|
||
| ; CHECK: Validation succeeded. | ||
bob80905 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ; Verify that valid createHandleFromBinding calls pass DXIL validation: | ||
| ; in-range constant indices, valid resource classes, and non-constant | ||
| ; indices on array resources. | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| %dx.types.Handle = type { i8* } | ||
| %dx.types.ResBind = type { i32, i32, i32, i8 } | ||
| %dx.types.ResourceProperties = type { i32, i32 } | ||
| %struct.RWByteAddressBuffer = type { i32 } | ||
|
|
||
| define void @main() { | ||
| ; Valid: index 1 is within [1, 3], resourceClass=1 (UAV) | ||
| %1 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 1, i1 false) | ||
| %2 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %1, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ; Valid: index 3 is within [1, 3] (upper bound) | ||
| %3 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 3, i1 false) | ||
| %4 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %3, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ; Valid: non-constant index on array resource (range [1, 3]) | ||
| %5 = call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96) | ||
| %6 = call %dx.types.Handle @dx.op.createHandleFromBinding(i32 217, %dx.types.ResBind { i32 1, i32 3, i32 0, i8 1 }, i32 %5, i1 false) | ||
| %7 = call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %6, %dx.types.ResourceProperties { i32 4107, i32 0 }) | ||
| ret void | ||
| } | ||
|
|
||
| declare i32 @dx.op.flattenedThreadIdInGroup.i32(i32) #0 | ||
| declare %dx.types.Handle @dx.op.annotateHandle(i32, %dx.types.Handle, %dx.types.ResourceProperties) #0 | ||
| declare %dx.types.Handle @dx.op.createHandleFromBinding(i32, %dx.types.ResBind, i32, i1) #0 | ||
|
|
||
| attributes #0 = { nounwind readnone } | ||
|
|
||
| !llvm.ident = !{!0} | ||
| !dx.version = !{!1} | ||
| !dx.valver = !{!1} | ||
| !dx.shaderModel = !{!2} | ||
| !dx.resources = !{!3} | ||
| !dx.entryPoints = !{!6} | ||
|
|
||
| !0 = !{!"dxc(private) 1.8.0.15017 (main, 4e0f5364a-dirty)"} | ||
| !1 = !{i32 1, i32 8} | ||
| !2 = !{!"cs", i32 6, i32 8} | ||
| !3 = !{null, !4, null, null} | ||
| !4 = !{!5} | ||
| !5 = !{i32 0, %struct.RWByteAddressBuffer* undef, !"", i32 0, i32 1, i32 3, i32 11, i1 false, i1 false, i1 false, null} | ||
| !6 = !{void ()* @main, !"main", null, !3, !7} | ||
| !7 = !{i32 0, i64 8589934608, i32 4, !8} | ||
| !8 = !{i32 4, i32 1, i32 1} | ||
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.