Skip to content

Commit 9c2b828

Browse files
authored
Add tests for literal overloads of fmod, length, and normalize (#6437)
Certain HL ops with no double overload will generate double overloads for literal types. These are lowered to double DXIL overloads, some of which are not legal for these ops. We currently rely on illegal intermediate DXIL op overloads for constant evaluation. If constant evaluation fails, we end up with illegal DXIL overloads in final DXIL, which is caught by the validator. The prior revert restored the ability to run these scenarios (with asserts disabled). This change adds tests for #6419 so automated testing will test across configurations and prevent regressions of this scenario in this branch.
1 parent 11ee8de commit 9c2b828

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %dxc -T vs_6_0 %s -E main | FileCheck %s
2+
// RUN: not %dxc -T vs_6_0 %s -E main -DNO_FOLD 2>&1 | FileCheck %s --check-prefixes=NO_FOLD
3+
4+
// The code path for this case asserts, but the assert does not indicate a
5+
// serious problem with internal state. The invalid overload will either be
6+
// constant folded away, or caught by the validator.
7+
// UNSUPPORTED: asserts
8+
9+
// Ensure fmod is constant evaluated during codegen, or dxil const eval
10+
// TODO: handle fp specials properly!
11+
12+
RWBuffer<float4> results : register(u0);
13+
14+
[shader("vertex")]
15+
void main(bool b : B) {
16+
uint i = 0;
17+
18+
// Literal float
19+
// 2.5, -2.5, 2.5, -2.5
20+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00, i8 15)
21+
results[i++] = float4(fmod(5.5, 3.0),
22+
fmod(-5.5, 3.0),
23+
fmod(5.5, -3.0),
24+
fmod(-5.5, -3.0));
25+
26+
// Explicit float
27+
// 2.5, -2.5, 2.5, -2.5
28+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 2.500000e+00, float -2.500000e+00, float 2.500000e+00, float -2.500000e+00, i8 15)
29+
results[i++] = float4(fmod(5.5f, 3.0f),
30+
fmod(-5.5f, 3.0f),
31+
fmod(5.5f, -3.0f),
32+
fmod(-5.5f, -3.0f));
33+
34+
#ifdef NO_FOLD
35+
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
36+
// double overloads. If this doesn't happen, we expect a validation error.
37+
// Ternary operator can return literal type, while not being foldable due
38+
// non-constant condition.
39+
// NO_FOLD: error: validation errors
40+
// NO_FOLD: error: DXIL intrinsic overload must be valid.
41+
float result = fmod(-5.5, b ? 1.5 : 0.5);
42+
results[i++] = float4(result, 0, 0, 0);
43+
#endif // NO_FOLD
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %dxc -T vs_6_0 %s -E main | FileCheck %s
2+
// RUN: not %dxc -T vs_6_0 %s -E main -DNO_FOLD 2>&1 | FileCheck %s --check-prefixes=NO_FOLD
3+
4+
// The code path for this case asserts, but the assert does not indicate a
5+
// serious problem with internal state. The invalid overload will either be
6+
// constant folded away, or caught by the validator.
7+
// UNSUPPORTED: asserts
8+
9+
// Ensure length is constant evaluated during codegen, or dxil const eval
10+
// TODO: handle fp specials properly!
11+
12+
RWBuffer<float4> results : register(u0);
13+
14+
[shader("vertex")]
15+
void main(bool b : B) {
16+
uint i = 0;
17+
18+
// Literal float
19+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 0x3FE6A09E60000000, float 0x4004C8DC20000000, float 0.000000e+00, float 0.000000e+00, i8 15)
20+
results[i++] = float4(length(0.5.xx),
21+
length(-1.5.xxx),
22+
length(0.0.xxxx),
23+
length(-0.0.xxxx));
24+
25+
// Explicit float
26+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 0x3FE6A09E60000000, float 0x4004C8DC20000000, float 0.000000e+00, float 0.000000e+00, i8 15)
27+
results[i++] = float4(length(0.5F.xx),
28+
length(-1.5F.xxx),
29+
length(0.0F.xxxx),
30+
length(-0.0F.xxxx));
31+
32+
#ifdef NO_FOLD
33+
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
34+
// double overloads. If this doesn't happen, we expect a validation error.
35+
// Ternary operator can return literal type, while not being foldable due
36+
// non-constant condition.
37+
// NO_FOLD: error: validation errors
38+
// NO_FOLD: error: DXIL intrinsic overload must be valid.
39+
float result = length((b ? 1.5 : 0.5).xxx);
40+
results[i++] = float4(result, 0, 0, 0);
41+
#endif // NO_FOLD
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %dxc -T vs_6_0 %s -E main | FileCheck %s
2+
// RUN: not %dxc -T vs_6_0 %s -E main -DNO_FOLD 2>&1 | FileCheck %s --check-prefixes=NO_FOLD
3+
4+
// The code path for this case asserts, but the assert does not indicate a
5+
// serious problem with internal state. The invalid overload will either be
6+
// constant folded away, or caught by the validator.
7+
// UNSUPPORTED: asserts
8+
9+
// Ensure normalize is constant evaluated during codegen, or dxil const eval
10+
// TODO: handle fp specials properly!
11+
12+
RWBuffer<float4> results : register(u0);
13+
14+
[shader("vertex")]
15+
void main(bool b : B) {
16+
uint i = 0;
17+
18+
// Literal float
19+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 0, i32 undef, float 0x3FE6A09E60000000, float 0xBFE279A740000000, float 0x7FF8000000000000, float 0x7FF8000000000000, i8 15)
20+
results[i++] = float4(normalize(0.5.xx).x,
21+
normalize(-1.5.xxx).x,
22+
normalize(0.0.xxxx).x,
23+
normalize(-0.0.xxxx).x);
24+
25+
// Explicit float
26+
// CHECK: call void @dx.op.bufferStore.f32(i32 69, %dx.types.Handle %{{.+}}, i32 1, i32 undef, float 0x3FE6A09E60000000, float 0xBFE279A740000000, float 0x7FF8000000000000, float 0x7FF8000000000000, i8 15)
27+
results[i++] = float4(normalize(0.5F.xx).x,
28+
normalize(-1.5F.xxx).x,
29+
normalize(0.0F.xxxx).x,
30+
normalize(-0.0F.xxxx).x);
31+
32+
#ifdef NO_FOLD
33+
// Currently, we rely on constant folding of DXIL ops to get rid of illegal
34+
// double overloads. If this doesn't happen, we expect a validation error.
35+
// Ternary operator can return literal type, while not being foldable due
36+
// non-constant condition.
37+
// NO_FOLD: error: validation errors
38+
// NO_FOLD: error: DXIL intrinsic overload must be valid.
39+
results[i++] = normalize((b ? 1.25 : 2.5).xxxx);
40+
#endif // NO_FOLD
41+
}

0 commit comments

Comments
 (0)