forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhalf-vector-calc.slang
51 lines (38 loc) · 1.39 KB
/
half-vector-calc.slang
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
//DISABLE_TEST(compute):COMPARE_COMPUTE:-dx12 -compute -output-using-type -use-dxil -profile cs_6_2 -render-features half -shaderobj
//TEST(compute):COMPARE_COMPUTE:-vk -compute -output-using-type -profile cs_6_2 -render-features half -shaderobj
//TEST(compute):COMPARE_COMPUTE:-cuda -compute -output-using-type -render-features half -shaderobj
// Test for doing a calculation using half
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
RWStructuredBuffer<float> outputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
int x = tid.x;
half2 v3 = half2(float(x));
half2 v0 = half2(float2(x * 2.0f, x * 0.5f));
half3 v1 = half3(half(x * 2.0f), half(x * 0.5f), half(x - 1.0f));
half4 v2 = half4(half(x + 1), half(x - 1), half(x + 2) , half(x - 2));
v1 += v0.yxy;
v1 += v2.wzy;
v2 += v0.xyxy;
v1 ++;
--v2;
v3++;
// Unary
v2 = +v2.yxwz;
v2.xyz = -v2.zwx;
// Scalar vector
v1 = v1 + v2.x;
v2 = v2 * half(2.0f);
v0 = half(2.0f) * v0;
v2 = v2 / half(2.0f);
v0 *= half(2.0f);
v0 = v0 + v0 * v0;
v1 = v1 + v1 * v1;
v2 = v2 + v2 * v2;
half o2 = v2.x + v2.y + v2.z + v2.w;
half o1 = v1.x + v1.y + v1.z;
half o0 = v0.x + v0.y;
outputBuffer[tid] = o0 + o1 + o2 + v3.y;
}