Skip to content

Commit 36d3537

Browse files
committed
Add structured buffer resource to the test
1 parent 22780b1 commit 36d3537

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

clang/test/SemaHLSL/static_resources.hlsl

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s
22

3-
// CHECK: [[ONE_STR:@.*]] = private unnamed_addr constant [4 x i8] c"One\00"
4-
// CHECK: [[ARRAY_STR:@.*]] = private unnamed_addr constant [6 x i8] c"Array\00"
3+
// CHECK-DAG: [[ONE_STR:@.*]] = private unnamed_addr constant [4 x i8] c"One\00"
4+
// CHECK-DAG: [[ARRAY_STR:@.*]] = private unnamed_addr constant [6 x i8] c"Array\00"
5+
// CHECK-DAG: [[ONEWITHCOUNTER_STR:@.*]] = private unnamed_addr constant [15 x i8] c"OneWithCounter\00"
6+
// CHECK-DAG: [[ARRAYWITHCOUNTER_STR:@.*]] = private unnamed_addr constant [17 x i8] c"ArrayWithCounter\00"
57
// CHECK-NOT: private unnamed_addr constant [{{[0-9]+}} x i8] c"Static
68

79
RWBuffer<float> One : register(u1, space5);
810
RWBuffer<float> Array[2] : register(u10, space6);
11+
RWStructuredBuffer<int> OneWithCounter : register(u2, space4);
12+
RWStructuredBuffer<int> ArrayWithCounter[2] : register(u7, space4);
913

1014
// Check that the non-static resource One is initialized from binding on
1115
// startup (register 1, space 5).
@@ -14,6 +18,13 @@ RWBuffer<float> Array[2] : register(u10, space6);
1418
// CHECK-NEXT: call void @hlsl::RWBuffer<float>::__createFromBinding(unsigned int, unsigned int, int, unsigned int, char const*)
1519
// CHECK-SAME: (ptr {{.*}} @One, i32 noundef 1, i32 noundef 5, i32 noundef 1, i32 noundef 0, ptr noundef [[ONE_STR]])
1620

21+
// Check that the non-static resource OneWithCounter is initialized from binding on
22+
// startup (register 2, space 4).
23+
// CHECK: define internal void @__cxx_global_var_init{{.*}}
24+
// CHECK-NEXT: entry:
25+
// CHECK-NEXT: call void @hlsl::RWStructuredBuffer<int>::__createFromBindingWithImplicitCounter(unsigned int, unsigned int, int, unsigned int, char const*, unsigned int)
26+
// CHECK-SAME: (ptr {{.*}} @OneWithCounter, i32 noundef 2, i32 noundef 4, i32 noundef 1, i32 noundef 0, ptr noundef [[ONEWITHCOUNTER_STR]], i32 noundef 0)
27+
1728
// Note that non-static resource arrays are not initialized on startup.
1829
// The individual resources from the array are initialized on access.
1930

@@ -41,6 +52,14 @@ static RWBuffer<float> StaticArray[2];
4152
// CHECK: arrayctor.cont: ; preds = %arrayctor.loop
4253
// CHECK-NEXT: ret void
4354

55+
static RWStructuredBuffer<int> StaticOneWithCounter;
56+
57+
// Check that StaticOneWithCounter resource is initialized on startup with the default
58+
// constructor and not from binding. It will initalize the handle to poison.
59+
// CHECK: define internal void @__cxx_global_var_init{{.*}}
60+
// CHECK-NEXT: entry:
61+
// CHECK-NEXT: call void @hlsl::RWStructuredBuffer<int>::RWStructuredBuffer()(ptr {{.*}} @StaticOneWithCounter)
62+
4463
// No other global initialization routines should be present.
4564
// CHECK-NOT: define internal void @__cxx_global_var_init{{.*}}
4665

@@ -91,6 +110,28 @@ void main() {
91110
// CHECK-NEXT: %[[PTR2:.*]] = call {{.*}} ptr @hlsl::RWBuffer<float>::operator[](unsigned int)
92111
// CHECK-SAME: (ptr {{.*}} getelementptr inbounds ([2 x %"class.hlsl::RWBuffer"], ptr @StaticArray, i32 0, i32 1), i32 noundef 2)
93112
// CHECK-NEXT: store float 7.890000e+02, ptr %[[PTR2]], align 4
113+
114+
static RWStructuredBuffer<int> StaticLocalWithCounter;
115+
// Check that StaticLocalWithCounter is initialized by default constructor (handle set to poison)
116+
// and not from binding.
117+
// call void @hlsl::RWStructuredBuffer<int>::RWStructuredBuffer()(ptr {{.*}} @main()::StaticLocalWithCounter)
118+
119+
static RWStructuredBuffer<int> StaticLocalArrayWithCounter[2];
120+
121+
StaticLocalWithCounter = OneWithCounter;
122+
// Operator = call to assign non-static OneWithCounter handles to StaticLocalWithCounter handles.
123+
// CHECK: call {{.*}} ptr @hlsl::RWStructuredBuffer<int>::operator=(hlsl::RWStructuredBuffer<int> const&)(ptr {{.*}} @main()::StaticLocalWithCounter, ptr {{.*}} @OneWithCounter)
124+
125+
StaticLocalArrayWithCounter = ArrayWithCounter;
126+
// Check that each elements of StaticLocalArrayWithCounter is initialized from binding
127+
// of ArrayWithCounter (register 7, space 4, indices 0 and 1).
128+
// CHECK: call void @hlsl::RWStructuredBuffer<int>::__createFromBindingWithImplicitCounter(unsigned int, unsigned int, int, unsigned int, char const*, unsigned int)
129+
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWStructuredBuffer") align 4 @main()::StaticLocalArrayWithCounter,
130+
// CHECK-SAME: i32 noundef 7, i32 noundef 4, i32 noundef 2, i32 noundef 0, ptr noundef [[ARRAYWITHCOUNTER_STR]], i32 noundef 1)
131+
132+
// CHECK-NEXT: call void @hlsl::RWStructuredBuffer<int>::__createFromBindingWithImplicitCounter(unsigned int, unsigned int, int, unsigned int, char const*, unsigned int)
133+
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWStructuredBuffer") align 4 getelementptr ([2 x %"class.hlsl::RWStructuredBuffer"], ptr @main()::StaticLocalArrayWithCounter, i32 0, i32 1),
134+
// CHECK-SAME: i32 noundef 7, i32 noundef 4, i32 noundef 2, i32 noundef 1, ptr noundef [[ARRAYWITHCOUNTER_STR]], i32 noundef 1)
94135
}
95136

96137
// No other binding initialization calls should be present.

0 commit comments

Comments
 (0)