Skip to content

[HLSL] Add a warning for implicit bindings #135909

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 6 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/test/AST/HLSL/pch.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// Make sure PCH works by using function declared in PCH header and declare a RWBuffer in current file.
// CHECK:FunctionDecl 0x[[FOO:[0-9a-f]+]] <{{.*}}:2:1, line:4:1> line:2:8 imported used foo 'float2 (float2, float2)'
// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:7:1, col:23> col:23 Buffer 'hlsl::RWBuffer<float>'
// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:{{[0-9]+}}:1, col:23> col:23 Buffer 'hlsl::RWBuffer<float>'
hlsl::RWBuffer<float> Buffer;

float2 bar(float2 a, float2 b) {
Expand Down
6 changes: 3 additions & 3 deletions clang/test/AST/HLSL/pch_hlsl_buffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ float foo() {
}

// Make sure cbuffer/tbuffer works for PCH.
// CHECK: HLSLBufferDecl {{.*}} line:4:9 imported <undeserialized declarations> cbuffer A
// CHECK: HLSLBufferDecl {{.*}} line:{{[0-9]+}}:9 imported <undeserialized declarations> cbuffer A
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
// CHECK-NEXT: VarDecl 0x[[A:[0-9a-f]+]] {{.*}} imported used a 'hlsl_constant float'
// CHECK-NEXT: CXXRecordDecl {{.*}} imported implicit <undeserialized declarations> struct __cblayout_A definition
// CHECK: FieldDecl {{.*}} imported a 'float'

// CHECK: HLSLBufferDecl {{.*}} line:8:9 imported <undeserialized declarations> tbuffer B
// CHECK: HLSLBufferDecl {{.*}} line:{{[0-9]+}}:9 imported <undeserialized declarations> tbuffer B
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit SRV
// CHECK-NEXT: VarDecl 0x[[B:[0-9a-f]+]] {{.*}} imported used b 'hlsl_constant float'
// CHECK-NEXT: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} imported implicit <undeserialized declarations> struct __cblayout_B definition
// CHECK: FieldDecl 0x{{[0-9a-f]+}} {{.*}} imported b 'float'

// CHECK-NEXT: FunctionDecl {{.*}} line:12:7 imported foo 'float ()'
// CHECK-NEXT: FunctionDecl {{.*}} line:{{[0-9]+}}:7 imported foo 'float ()'
// CHECK-NEXT: CompoundStmt {{.*}}
// CHECK-NEXT: ReturnStmt {{.*}}
// CHECK-NEXT: BinaryOperator {{.*}} 'float' '+'
Expand Down
2 changes: 1 addition & 1 deletion clang/test/AST/HLSL/pch_with_buf.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Make sure buffer defined in PCH works.
// CHECK:VarDecl 0x{{[0-9a-f]+}} <line:6:1, col:17> col:17 imported Buf 'RWBuffer<float>'
// Make sure declare a RWBuffer in current file works.
// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:10:1, col:23> col:23 Buf2 'hlsl::RWBuffer<float>'
// CHECK:VarDecl 0x{{[0-9a-f]+}} <{{.*}}:{{[0-9]+}}:1, col:23> col:23 Buf2 'hlsl::RWBuffer<float>'
hlsl::RWBuffer<float> Buf2;

float2 bar(float2 a, float2 b) {
Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaHLSL/resource_binding_implicit.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ RWBuffer<int> c;
// No warning - explicit binding.
RWBuffer<float> d : register(u0);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

RWBuffer<float> dd : register(space1);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be tested util #135287 goes in, but it should warn. I added a commented out test and a TODO comment.

// No warning - explicit binding.
RWBuffer<float> dd : register(space1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a warning here?
Though the space param is being explicitly bound, the register number within that space is implicitly bound, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're correct. I've updated the latest, though this is commented out now because we can't actually write this test until #135287 goes in


// No warning - explicit binding.
RWBuffer<float> ddd : register(u3, space4);

struct S { int x; };
// expected-warning@+1 {{resource has implicit register binding}}
StructuredBuffer<S> e;
Expand Down
Loading