Skip to content

Commit 9373b34

Browse files
sindneysudonatalie
authored andcommitted
[spirv] isRelaxedPrecisionType() check for reference and pointer types with test cases.
1 parent af24013 commit 9373b34

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

tools/clang/lib/SPIRV/AstTypeProbe.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,14 @@ bool isRelaxedPrecisionType(QualType type, const SpirvCodeGenOptions &opts) {
11421142
}
11431143
}
11441144

1145+
// Reference types
1146+
if (const auto *refType = type->getAs<ReferenceType>())
1147+
return isRelaxedPrecisionType(refType->getPointeeType(), opts);
1148+
1149+
// Pointer types
1150+
if (const auto *ptrType = type->getAs<PointerType>())
1151+
return isRelaxedPrecisionType(ptrType->getPointeeType(), opts);
1152+
11451153
return false;
11461154
}
11471155

tools/clang/test/CodeGenSPIRV/spirv.stage-io.16bit.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// CHECK: OpDecorate %out_var_D Location 7
1717
// CHECK: OpDecorate %out_var_E Location 8
1818

19+
// CHECK: %half = OpTypeFloat 16
20+
// CHECK-NOT: %float = OpTypeFloat 32
21+
1922
// CHECK: %in_var_A = OpVariable %_ptr_Input__arr_v2half_uint_4 Input
2023
// CHECK: %in_var_B = OpVariable %_ptr_Input__arr_v3ushort_uint_2 Input
2124
// CHECK: %in_var_C = OpVariable %_ptr_Input_short Input
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %dxc -T vs_6_2 -E main
2+
3+
// CHECK: OpDecorate %in_var_A Location 0
4+
// CHECK: OpDecorate %in_var_B Location 4
5+
// CHECK: OpDecorate %in_var_C Location 6
6+
// CHECK: OpDecorate %in_var_D Location 7
7+
// CHECK: OpDecorate %in_var_E Location 8
8+
9+
// CHECK: OpDecorate %out_var_A Location 0
10+
// CHECK: OpDecorate %out_var_B Location 2
11+
// CHECK: OpDecorate %out_var_C Location 6
12+
// CHECK: OpDecorate %out_var_D Location 7
13+
// CHECK: OpDecorate %out_var_E Location 8
14+
15+
// CHECK: OpDecorate %in_var_A RelaxedPrecision
16+
// CHECK: OpDecorate %in_var_B RelaxedPrecision
17+
// CHECK: OpDecorate %in_var_C RelaxedPrecision
18+
// CHECK: OpDecorate %in_var_D RelaxedPrecision
19+
// CHECK: OpDecorate %in_var_E RelaxedPrecision
20+
21+
// CHECK: OpDecorate %out_var_A RelaxedPrecision
22+
// CHECK: OpDecorate %out_var_B RelaxedPrecision
23+
// CHECK: OpDecorate %out_var_C RelaxedPrecision
24+
// CHECK: OpDecorate %out_var_D RelaxedPrecision
25+
// CHECK: OpDecorate %out_var_E RelaxedPrecision
26+
27+
// CHECK: %float = OpTypeFloat 32
28+
// CHECK-NOT: %half = OpTypeFloat 16
29+
30+
// CHECK: %in_var_A = OpVariable %_ptr_Input__arr_v2float_uint_4 Input
31+
// CHECK: %in_var_B = OpVariable %_ptr_Input__arr_v3uint_uint_2 Input
32+
// CHECK: %in_var_C = OpVariable %_ptr_Input_int Input
33+
// CHECK: %in_var_D = OpVariable %_ptr_Input_v2uint Input
34+
// CHECK: %in_var_E = OpVariable %_ptr_Input_mat3v2float Input
35+
36+
// CHECK: %out_var_A = OpVariable %_ptr_Output_mat2v3float Output
37+
// CHECK: %out_var_B = OpVariable %_ptr_Output__arr_v2int_uint_4 Output
38+
// CHECK: %out_var_C = OpVariable %_ptr_Output_float Output
39+
// CHECK: %out_var_D = OpVariable %_ptr_Output_v2int Output
40+
// CHECK: %out_var_E = OpVariable %_ptr_Output_v3uint Output
41+
42+
struct VSOut {
43+
min16float2x3 outA : A; // 2 locations: 0, 1
44+
min16int2 outB[4] : B; // 4 locations: 2, 3, 4, 5
45+
min16float outC : C; // 1 location : 6
46+
min16int2 outD : D; // 1 location : 7
47+
min16uint3 outE : E; // 1 location : 8
48+
};
49+
50+
VSOut main(
51+
min16float2 inA[4] : A, // 4 locations: 0, 1, 2, 3
52+
min16uint2x3 inB : B, // 2 locations: 4, 5
53+
min16int inC : C, // 1 location : 6
54+
min16uint2 inD : D, // 1 location : 7
55+
min16float3x2 inE : E // 3 location : 8, 9, 10
56+
) {
57+
VSOut o;
58+
o.outA = inA[0].x;
59+
o.outB[0] = inB[0][0];
60+
o.outC = inC.x;
61+
o.outD = inD[0];
62+
o.outE = inE[0][0];
63+
return o;
64+
}

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,10 @@ TEST_F(FileTest, SpirvStageIO16bitTypes) {
16741674
runFileTest("spirv.stage-io.16bit.hlsl");
16751675
}
16761676

1677+
TEST_F(FileTest, SpirvStageIORelaxedPrecisionTypes) {
1678+
runFileTest("spirv.stage-io.relaxed-precision.hlsl");
1679+
}
1680+
16771681
TEST_F(FileTest, SpirvInterpolationPS) {
16781682
runFileTest("spirv.interpolation.ps.hlsl");
16791683
}

0 commit comments

Comments
 (0)