Skip to content

Commit b596824

Browse files
committed
Add more tests for implicit binding attributes, add assert, formatting nit
1 parent e12a7a9 commit b596824

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,6 +4932,7 @@ def HLSLResourceBinding: InheritableAttr {
49324932
return SpaceNumber;
49334933
}
49344934
void setImplicitBindingOrderID(uint32_t Value) {
4935+
assert(!hasImplicitBindingOrderID() && "attribute already has implicit binding order id");
49354936
ImplicitBindingOrderID = Value;
49364937
}
49374938
bool hasImplicitBindingOrderID() const {

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,8 @@ getResourceArrayHandleType(VarDecl *VD) {
351351
assert(VD->getType()->isHLSLResourceRecordArray() &&
352352
"expected array of resource records");
353353
const Type *Ty = VD->getType()->getUnqualifiedDesugaredType();
354-
while (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) {
354+
while (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
355355
Ty = CAT->getArrayElementTypeNoTypeQual()->getUnqualifiedDesugaredType();
356-
}
357356
return HLSLAttributedResourceType::findHandleTypeOnResource(Ty);
358357
}
359358

clang/test/AST/HLSL/resource_binding_attr.hlsl

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -ast-dump -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -ast-dump -o - %s | FileCheck %s -check-prefixes=CHECK,DXIL
2+
// RUN: %clang_cc1 -triple spirv-unknown-vulkan-library -finclude-default-header -ast-dump -o - %s | FileCheck %s -check-prefixes=CHECK,SPV
23

34
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 4]]:9 cbuffer CB
45
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
@@ -64,15 +65,40 @@ S s : register(c10);
6465
//
6566
// Implicit binding
6667

67-
// Constant buffers should have implicit binding attribute added by SemaHLSL
68+
// Constant buffers should have implicit binding attribute added by SemaHLSL,
69+
// unless the target is SPIR-V and there is [[vk::binding]] attribute.
6870
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 3]]:9 cbuffer CB2
6971
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
7072
// CHECK-NEXT: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
7173
cbuffer CB2 {
7274
float4 c;
7375
}
7476

75-
// Resource arrays should have implicit binding attribute added by SemaHLSL
77+
// CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 7]]:9 cbuffer CB3
78+
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
79+
// DXIL: HLSLResourceBindingAttr {{.*}} Implicit
80+
// DXIL-NOT: HLSLVkBindingAttr
81+
// SPV: HLSLVkBindingAttr {{.*}} 1 0
82+
// SPV-NOT: HLSLResourceBindingAttr {{.*}} Implicit
83+
[[vk::binding(1)]]
84+
cbuffer CB3 {
85+
float2 d;
86+
}
87+
88+
// Resource arrays should have implicit binding attribute added by SemaHLSL,
89+
// unless the target is SPIR-V and there is [[vk::binding]] attribute.
7690
// CHECK: VarDecl {{.*}} SB 'StructuredBuffer<float>[10]'
7791
// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"
7892
StructuredBuffer<float> SB[10];
93+
94+
// CHECK: VarDecl {{.*}} SB2 'StructuredBuffer<float>[10]'
95+
// DXIL: HLSLResourceBindingAttr {{.*}} Implicit
96+
// DXIL-NOT: HLSLVkBindingAttr
97+
// SPV: HLSLVkBindingAttr {{.*}} 2 0
98+
// SPV-NOT: HLSLResourceBindingAttr {{.*}} Implicit
99+
[[vk::binding(2)]]
100+
StructuredBuffer<float> SB2[10];
101+
102+
// $Globals should have implicit binding attribute added by SemaHLSL
103+
// CHECK: HLSLBufferDecl {{.*}} implicit cbuffer $Globals
104+
// CHECK: HLSLResourceBindingAttr {{.*}} Implicit "" "0"

0 commit comments

Comments
 (0)