blob: 7c7b9bc609a3025101b79a401b3b201525bbd25a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
//TEST:SIMPLE(filecheck=CHECK): -target spirv
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type -emit-spirv-directly
//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;
// `OpSpecConstantOp` can only contain integer operations when targeting Vulkan SPIRV, not floating-point operations.
// This test checks that floating-point operations that strictly contain specialization constant variables are not declared with `OpSpecContantOp`,
// while integer operations that strictly contain specializaton constant operands are declared as `OpSpecConstantOp`.
// CHECK-DAG: OpSpecConstant %float 1
// CHECK-DAG: OpSpecConstant %ulong 256
// CHECK-DAG: OpSpecConstant %float 100
// CHECK-NOT: OpSpecConstantOp {{.*}} FAdd
// CHECK-NOT: OpSpecConstantOp {{.*}} FSub
// CHECK-NOT: OpSpecConstantOp {{.*}} FMul
// CHECK-NOT: OpSpecConstantOp {{.*}} FDiv
// CHECK-NOT: OpSpecConstantOp {{.*}} SpvOpConvertUToF
// CHECK-NOT: OpSpecConstantOp {{.*}} SpvOpConvertFToU
[[SpecializationConstant]]
const float X = 1.0;
[[SpecializationConstant]]
const uint64_t Y = 256;
[[SpecializationConstant]]
const float Z = 100.0;
int func1()
{
// Test float-to-float and int-to-int conversions.
int a = int(Y);
half b = half(X);
int16_t c = int16_t(Y);
// Test comparisons.
if (X < 2.0)
{
a = 3;
}
else if (X > 5.0)
{
a = 5;
}
if (Y < 200)
{
b = 2.0h;
}
else if (Y > 500)
{
b = 5.0h;
}
return a + int(b) + int(c);
}
float func2()
{
// Test floating-point arithmetic.
float a = X + Z;
a += (X - Z);
a += (X * Z);
a += (X / Z);
return a;
}
float func3()
{
// Test float-to-int and int-to-float conversions.
int a = int(Z) * 2;
return float(Y) + float(a);
}
[shader("compute")]
[numthreads(1, 1, 1)]
void computeMain()
{
// BUF: 818.01
outputBuffer[0] = float(func1()) + func2() + func3();
}
|