-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL] Diagnose overlapping resource bindings #140982
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s | ||
|
||
; Check overlap error for two resource arrays. | ||
|
||
; A overlaps with B | ||
; RWBuffer<float> A[10] : register(u0); | ||
; RWBuffer<float> B[10] : register(u5); | ||
|
||
; CHECK: error: resource A at register 0 overlaps with resource B at register 5 in space 0 | ||
|
||
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1 | ||
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1 | ||
|
||
define void @test_overlapping() { | ||
entry: | ||
%h1 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 4, i1 false, ptr @A.str) | ||
%h2 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 5, i32 10, i32 4, i1 false, ptr @B.str) | ||
ret void | ||
} |
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,19 @@ | ||
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s | ||
|
||
; Check overlap error for two resources with identical binding | ||
|
||
; R overlaps exactly with S | ||
; RWBuffer<float> R : register(u5, space10); | ||
; RWBuffer<float> S : register(u5, space10); | ||
|
||
; CHECK: error: resource R at register 5 overlaps with resource S at register 5 in space 10 | ||
|
||
@R.str = private unnamed_addr constant [2 x i8] c"R\00", align 1 | ||
@S.str = private unnamed_addr constant [2 x i8] c"S\00", align 1 | ||
|
||
define void @test_overlapping() { | ||
entry: | ||
%h1 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 10, i32 5, i32 1, i32 0, i1 false, ptr @R.str) | ||
%h2 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 10, i32 5, i32 1, i32 0, i1 false, ptr @S.str) | ||
ret void | ||
} |
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,46 @@ | ||
; Use llc for this test so that we don't abort after the first error. | ||
; RUN: not llc %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
; Check multiple overlap errors. | ||
; Also check different resource class with same binding values is ok (no error expected). | ||
|
||
; C overlaps with A | ||
; C overlaps with B | ||
; StructuredBuffer<float> A : register(t5); | ||
; StructuredBuffer<float> B : register(t9); | ||
; StructuredBuffer<float> C[10] : register(t0); | ||
; RWBuffer<float> S[10] : register(u0); | ||
|
||
; CHECK: error: resource C at register 0 overlaps with resource A at register 5 in space 0 | ||
; CHECK: error: resource C at register 0 overlaps with resource B at register 9 in space 0 | ||
|
||
target triple = "dxil-pc-shadermodel6.3-library" | ||
|
||
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1 | ||
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1 | ||
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1 | ||
@S.str = private unnamed_addr constant [2 x i8] c"S\00", align 1 | ||
|
||
; Fake globals to store handles in; this is to make sure the handlefrombinding calls | ||
; are not optimized away by llc. | ||
@One = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Two = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Three = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Four = internal global { target("dx.TypedBuffer", float, 1, 0, 0) } poison, align 4 | ||
|
||
define void @test_overlapping() "hlsl.export" { | ||
entry: | ||
%h1 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 5, i32 1, i32 0, i1 false, ptr @A.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h1, ptr @One, align 4 | ||
|
||
%h2 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 9, i32 1, i32 0, i1 false, ptr @B.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h2, ptr @Two, align 4 | ||
|
||
%h3 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 10, i32 4, i1 false, ptr @C.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h3, ptr @Three, align 4 | ||
|
||
%h4 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false, ptr @S.str) | ||
store target("dx.TypedBuffer", float, 1, 0, 0) %h4, ptr @Four, align 4 | ||
|
||
ret void | ||
} |
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,41 @@ | ||
; Use llc for this test so that we don't abort after the first error. | ||
; RUN: not llc %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
; Check multiple overlap errors. | ||
|
||
; A overlaps with B | ||
; A overlaps with C | ||
; B overlaps with C | ||
; StructuredBuffer<float> A[5] : register(t1); // 1-5 | ||
; StructuredBuffer<float> B[2] : register(t2); // 2-3 | ||
; StructuredBuffer<float> C[3] : register(t3); // 3-5 | ||
|
||
; CHECK: error: resource A at register 1 overlaps with resource B at register 2 in space 0 | ||
; CHECK: error: resource A at register 1 overlaps with resource C at register 3 in space 0 | ||
; CHECK: error: resource B at register 2 overlaps with resource C at register 3 in space 0 | ||
|
||
target triple = "dxil-pc-shadermodel6.3-library" | ||
|
||
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1 | ||
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1 | ||
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1 | ||
|
||
; Fake globals to store handles in; this is to make sure the handlefrombinding calls | ||
; are not optimized away by llc. | ||
@One = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Two = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Three = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
|
||
define void @test_overlapping() "hlsl.export" { | ||
entry: | ||
%h1 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 5, i32 0, i1 false, ptr @A.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h1, ptr @One, align 4 | ||
|
||
%h2 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 2, i32 0, i1 false, ptr @B.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h2, ptr @Two, align 4 | ||
|
||
%h3 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 3, i32 3, i32 4, i1 false, ptr @C.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h3, ptr @Three, align 4 | ||
|
||
ret void | ||
} |
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,39 @@ | ||
; Use llc for this test so that we don't abort after the first error. | ||
; RUN: not llc %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
; Check multiple overlap errors. | ||
|
||
; A overlaps with B | ||
; B overlaps with C | ||
; StructuredBuffer<float> A[5] : register(t1, space11); // 1-5 | ||
; StructuredBuffer<float> B[6] : register(t2, space11); // 2-7 | ||
; StructuredBuffer<float> C[3] : register(t6, space11); // 6-8 | ||
|
||
; CHECK: error: resource A at register 1 overlaps with resource B at register 2 in space 11 | ||
; CHECK: error: resource B at register 2 overlaps with resource C at register 6 in space 11 | ||
|
||
target triple = "dxil-pc-shadermodel6.3-library" | ||
|
||
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1 | ||
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1 | ||
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1 | ||
|
||
; Fake globals to store handles in; this is to make sure the handlefrombinding calls | ||
; are not optimized away by llc. | ||
@One = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Two = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
@Three = internal global { target("dx.RawBuffer", float, 0, 0) } poison, align 4 | ||
|
||
define void @test_overlapping() "hlsl.export" { | ||
entry: | ||
%h1 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 11, i32 1, i32 5, i32 0, i1 false, ptr @A.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h1, ptr @One, align 4 | ||
|
||
%h2 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 11, i32 2, i32 6, i32 0, i1 false, ptr @B.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h2, ptr @Two, align 4 | ||
|
||
%h3 = call target("dx.RawBuffer", float, 0, 0) @llvm.dx.resource.handlefrombinding(i32 11, i32 6, i32 3, i32 4, i1 false, ptr @C.str) | ||
store target("dx.RawBuffer", float, 0, 0) %h3, ptr @Three, align 4 | ||
|
||
ret void | ||
} |
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
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.