Skip to content

Commit 7810d84

Browse files
authored
[HLSL] Boolean in a RawBuffer should be i32 and Boolean vector in a RawBuffer should be <N x i32> (#135848)
Instead of converting the type in a RawBuffer to its HLSL type using 'ConvertType', use 'ConvertTypeForMem'. ConvertTypeForMem handles booleans being i32 and boolean vectors being < N x i32 >. Add tests to show booleans and boolean vectors in RawBuffers now have the correct type of i32, and <N x i32> respectively. Closes #135635
1 parent de0153d commit 7810d84

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

clang/lib/CodeGen/Targets/DirectX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
5252
return nullptr;
5353

5454
// convert element type
55-
llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
55+
llvm::Type *ElemType = CGM.getTypes().ConvertTypeForMem(ContainedTy);
5656

5757
llvm::StringRef TypeName =
5858
ResAttrs.RawBuffer ? "dx.RawBuffer" : "dx.TypedBuffer";

clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct MyStruct {
2020
// DXIL: %"class.hlsl::AppendStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 0)
2121
// DXIL: %"class.hlsl::AppendStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct, 1, 0)
2222
// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }
23+
// DXIL: %"class.hlsl::AppendStructuredBuffer.13" = type { target("dx.RawBuffer", i32, 1, 0)
24+
// DXIL: %"class.hlsl::AppendStructuredBuffer.14" = type { target("dx.RawBuffer", <4 x i32>, 1, 0)
2325

2426
AppendStructuredBuffer<int16_t> BufI16;
2527
AppendStructuredBuffer<uint16_t> BufU16;
@@ -41,6 +43,8 @@ AppendStructuredBuffer<float3> BufF32x3;
4143
// TODO: AppendStructuredBuffer<snorm double> BufSNormF64;
4244
// TODO: AppendStructuredBuffer<unorm double> BufUNormF64;
4345
AppendStructuredBuffer<MyStruct> BufMyStruct;
46+
AppendStructuredBuffer<bool> BufBool;
47+
AppendStructuredBuffer<bool4> BufBoolVec;
4448

4549
[numthreads(1,1,1)]
4650
void main(int GI : SV_GroupIndex) {

clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct MyStruct {
2020
// DXIL: %"class.hlsl::ConsumeStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 0)
2121
// DXIL: %"class.hlsl::ConsumeStructuredBuffer.12" = type { target("dx.RawBuffer", %struct.MyStruct, 1, 0)
2222
// DXIL: %struct.MyStruct = type { <4 x float>, <2 x i32>, [8 x i8] }
23+
// DXIL: %"class.hlsl::ConsumeStructuredBuffer.13" = type { target("dx.RawBuffer", i32, 1, 0)
24+
// DXIL: %"class.hlsl::ConsumeStructuredBuffer.14" = type { target("dx.RawBuffer", <4 x i32>, 1, 0)
2325

2426
ConsumeStructuredBuffer<int16_t> BufI16;
2527
ConsumeStructuredBuffer<uint16_t> BufU16;
@@ -41,6 +43,8 @@ ConsumeStructuredBuffer<float3> BufF32x3;
4143
// TODO: ConsumeStructuredBuffer<snorm double> BufSNormF64;
4244
// TODO: ConsumeStructuredBuffer<unorm double> BufUNormF64;
4345
ConsumeStructuredBuffer<MyStruct> BufMyStruct;
46+
ConsumeStructuredBuffer<bool> BufBool;
47+
ConsumeStructuredBuffer<bool4> BufBoolVec;
4448

4549
[numthreads(1,1,1)]
4650
void main(int GI : SV_GroupIndex) {

clang/test/CodeGenHLSL/builtins/RWStructuredBuffer-elementtype.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// CHECK: %"class.hlsl::RWStructuredBuffer.9" = type { target("dx.RawBuffer", <3 x i32>, 1, 0) }
1414
// CHECK: %"class.hlsl::RWStructuredBuffer.10" = type { target("dx.RawBuffer", <2 x half>, 1, 0) }
1515
// CHECK: %"class.hlsl::RWStructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 1, 0) }
16+
// CHECK: %"class.hlsl::RWStructuredBuffer.12" = type { target("dx.RawBuffer", i32, 1, 0) }
17+
// CHECK: %"class.hlsl::RWStructuredBuffer.13" = type { target("dx.RawBuffer", <4 x i32>, 1, 0) }
1618

1719
RWStructuredBuffer<int16_t> BufI16;
1820
RWStructuredBuffer<uint16_t> BufU16;
@@ -27,6 +29,8 @@ RWStructuredBuffer< vector<int16_t, 4> > BufI16x4;
2729
RWStructuredBuffer< vector<uint, 3> > BufU32x3;
2830
RWStructuredBuffer<half2> BufF16x2;
2931
RWStructuredBuffer<float3> BufF32x3;
32+
RWStructuredBuffer<bool> BufBool;
33+
RWStructuredBuffer<bool4> BufBoolVec;
3034
// TODO: RWStructuredBuffer<snorm half> BufSNormF16;
3135
// TODO: RWStructuredBuffer<unorm half> BufUNormF16;
3236
// TODO: RWStructuredBuffer<snorm float> BufSNormF32;
@@ -49,4 +53,6 @@ void main(int GI : SV_GroupIndex) {
4953
BufU32x3[GI] = 0;
5054
BufF16x2[GI] = 0;
5155
BufF32x3[GI] = 0;
56+
BufBool[GI] = false;
57+
BufBool[GI] = false;
5258
}

clang/test/CodeGenHLSL/builtins/StructuredBuffer-elementtype.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// CHECK: %"class.hlsl::StructuredBuffer.9" = type { target("dx.RawBuffer", <3 x i32>, 0, 0) }
1414
// CHECK: %"class.hlsl::StructuredBuffer.10" = type { target("dx.RawBuffer", <2 x half>, 0, 0) }
1515
// CHECK: %"class.hlsl::StructuredBuffer.11" = type { target("dx.RawBuffer", <3 x float>, 0, 0) }
16+
// CHECK: %"class.hlsl::StructuredBuffer.12" = type { target("dx.RawBuffer", i32, 0, 0) }
17+
// CHECK: %"class.hlsl::StructuredBuffer.13" = type { target("dx.RawBuffer", <4 x i32>, 0, 0) }
1618

1719
StructuredBuffer<int16_t> BufI16;
1820
StructuredBuffer<uint16_t> BufU16;
@@ -27,6 +29,8 @@ StructuredBuffer< vector<int16_t, 4> > BufI16x4;
2729
StructuredBuffer< vector<uint, 3> > BufU32x3;
2830
StructuredBuffer<half2> BufF16x2;
2931
StructuredBuffer<float3> BufF32x3;
32+
StructuredBuffer<bool> BufBool;
33+
StructuredBuffer<bool4> BufBoolVec;
3034
// TODO: StructuredBuffer<snorm half> BufSNormF16;
3135
// TODO: StructuredBuffer<unorm half> BufUNormF16;
3236
// TODO: StructuredBuffer<snorm float> BufSNormF32;
@@ -49,4 +53,6 @@ void main(int GI : SV_GroupIndex) {
4953
vector<int, 3> v11 = BufU32x3[GI];
5054
half2 v12 = BufF16x2[GI];
5155
float3 v13 = BufF32x3[GI];
56+
bool v14 = BufBool[GI];
57+
bool4 v15 = BufBoolVec[GI];
5258
}

0 commit comments

Comments
 (0)