| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-compute -finclude-default-header \ |
| 2 |
// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s -check-prefixes=CHECK,DXIL |
| 3 |
// RUN: %clang_cc1 -finclude-default-header -triple spirv-unknown-vulkan-compute \ |
| 4 |
// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s -check-prefixes=CHECK,SPV |
| 5 |
|
| 6 |
// CHECK: @[[BufA:.*]] = private unnamed_addr constant [2 x i8] c"A\00", align 1 |
| 7 |
// CHECK: @[[BufB:.*]] = private unnamed_addr constant [2 x i8] c"B\00", align 1 |
| 8 |
|
| 9 |
RWBuffer<float> A[] : register(u10, space1); |
| 10 |
RWBuffer<int> B[][5][4]; |
| 11 |
|
| 12 |
RWStructuredBuffer<float> Out; |
| 13 |
|
| 14 |
float foo(RWBuffer<int> Arr[4], uint Index) { |
| 15 |
return (float)Arr[Index][0]; |
| 16 |
} |
| 17 |
|
| 18 |
[numthreads(4,1,1)] |
| 19 |
void main(uint GI : SV_GroupIndex) { |
| 20 |
// CHECK: define internal{{.*}} void @main(unsigned int)(i32 noundef %GI) |
| 21 |
// CHECK: %[[GI_alloca:.*]] = alloca i32, align 4 |
| 22 |
// CHECK-NEXT: %a = alloca float, align 4 |
| 23 |
// CHECK-NEXT: %[[Tmp0:.*]] = alloca %"class.hlsl::RWBuffer |
| 24 |
// CHECK-NEXT: %b = alloca float, align 4 |
| 25 |
// CHECK-NEXT: %[[Tmp1:.*]] = alloca [4 x %"class.hlsl::RWBuffer"] |
| 26 |
// CHECK-NEXT: %[[Tmp2:.*]] = alloca [4 x %"class.hlsl::RWBuffer"] |
| 27 |
// CHECK-NEXT: store i32 %GI, ptr %[[GI_alloca]], align 4 |
| 28 |
|
| 29 |
// Make sure A[100] is translated to a RWBuffer<float> constructor call with range -1 and index 100 |
| 30 |
// and explicit binding (u10, space1) |
| 31 |
// CHECK: @hlsl::RWBuffer<float>::__createFromBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 32 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWBuffer.0") align {{(4|8)}} %[[Tmp0]], |
| 33 |
// CHECK-SAME: i32 noundef 10, i32 noundef 1, i32 noundef -1, i32 noundef 100, ptr noundef @A.str) |
| 34 |
// CHECK-NEXT: %[[BufPtr:.*]] = call {{.*}} ptr{{.*}} @hlsl::RWBuffer<float>::operator[](unsigned int)(ptr {{.*}} %[[Tmp0]], i32 noundef 0) |
| 35 |
// CHECK-NEXT: %[[Value1:.*]] = load float, ptr{{.*}} %[[BufPtr]], align 4 |
| 36 |
// CHECK-NEXT: store float %[[Value1]], ptr %a, align 4 |
| 37 |
float a = A[100][0]; |
| 38 |
|
| 39 |
// Make sure B[2][3] is translated to a local RWBuffer<int>[4] array where each array element |
| 40 |
// is initialized by a constructor call with range -1 and index 52-55 and implicit binding |
| 41 |
// (space 0, order_id 0) |
| 42 |
// The first index is calculated from the array dimensions (unbounded x 5 x 4) and indices (2, 3) |
| 43 |
// as 2 * 5 * 4 + 3 * 4 = 52 and the following indices are sequential. |
| 44 |
|
| 45 |
// CHECK-NEXT: %[[Ptr_Tmp2_0:.*]] = getelementptr [4 x %"class.hlsl::RWBuffer"], ptr %[[Tmp2]], i32 0, i32 0 |
| 46 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 47 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWBuffer") align {{(4|8)}} %[[Ptr_Tmp2_0]], |
| 48 |
// CHECK-SAME: i32 noundef 0, i32 noundef 0, i32 noundef -1, i32 noundef 52, ptr noundef @[[BufB]]) |
| 49 |
|
| 50 |
// CHECK-NEXT: %[[Ptr_Tmp2_1:.*]] = getelementptr [4 x %"class.hlsl::RWBuffer"], ptr %[[Tmp2]], i32 0, i32 1 |
| 51 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 52 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWBuffer") align {{(4|8)}} %[[Ptr_Tmp2_1]], |
| 53 |
// CHECK-SAME: i32 noundef 0, i32 noundef 0, i32 noundef -1, i32 noundef 53, ptr noundef @[[BufB]]) |
| 54 |
|
| 55 |
// CHECK-NEXT: %[[Ptr_Tmp2_2:.*]] = getelementptr [4 x %"class.hlsl::RWBuffer"], ptr %[[Tmp2]], i32 0, i32 2 |
| 56 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 57 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWBuffer") align {{(4|8)}} %[[Ptr_Tmp2_2]], |
| 58 |
// CHECK-SAME: i32 noundef 0, i32 noundef 0, i32 noundef -1, i32 noundef 54, ptr noundef @[[BufB]]) |
| 59 |
|
| 60 |
// CHECK-NEXT: %[[Ptr_Tmp2_3:.*]] = getelementptr [4 x %"class.hlsl::RWBuffer"], ptr %[[Tmp2]], i32 0, i32 3 |
| 61 |
// CHECK-NEXT: call void @hlsl::RWBuffer<int>::__createFromImplicitBinding(unsigned int, unsigned int, int, unsigned int, char const*) |
| 62 |
// CHECK-SAME: (ptr {{.*}} sret(%"class.hlsl::RWBuffer") align {{(4|8)}} %[[Ptr_Tmp2_3]], |
| 63 |
// CHECK-SAME: i32 noundef 0, i32 noundef 0, i32 noundef -1, i32 noundef 55, ptr noundef @[[BufB]]) |
| 64 |
|
| 65 |
// DXIL-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %[[Tmp1]], ptr align 4 %[[Tmp2]], i32 16, i1 false) |
| 66 |
// SPV-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %[[Tmp1]], ptr align 8 %[[Tmp2]], i64 32, i1 false) |
| 67 |
|
| 68 |
// CHECK-NEXT: %[[GI:.*]] = load i32, ptr %[[GI_alloca]], align 4 |
| 69 |
// CHECK-NEXT: %[[Value2:.*]] = call {{.*}} float @foo(hlsl::RWBuffer<int> [4], unsigned int) |
| 70 |
// CHECK-SAME: (ptr noundef byval([4 x %"class.hlsl::RWBuffer"]) align {{(4|8)}} %[[Tmp1]], i32 noundef %[[GI]]) |
| 71 |
|
| 72 |
// CHECK-NEXT: store float %[[Value2]], ptr %b, align 4 |
| 73 |
float b = foo(B[2][3], GI); |
| 74 |
|
| 75 |
Out[0] = a + b; |
| 76 |
} |