yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Fix intrinsic LoadLocalRootTableConstant for optix (#7949)e595743b5

master
3.9 KiB139 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target cuda -capability optix_coopvec
2//TEST:SIMPLE(filecheck=CHECK-PTX): -target ptx -Xnvrtc -I"./external/optix-dev/include/"
3
4// CHECK-PTX: add.f32
5// CHECK: optixCoopVecLoad
6// CHECK: OptixCoopVec
7// CHECK: optixCoopVecTanh
8// CHECK: optixCoopVecAdd
9// CHECK: optixCoopVecCvt
10// CHECK: optixCoopVecFFMA
11// CHECK: optixCoopVecMax
12// CHECK: optixCoopVecMin
13// CHECK: optixCoopVecMul
14// CHECK: optixCoopVecOuterProductAccumulate
15// CHECK: optixCoopVecReduceSumAccumulate
16// CHECK: optixCoopVecStep
17// CHECK: optixCoopVecSub
18// CHECK: optixCoopVecLog2
19// CHECK: optixCoopVecExp2
20
21
22//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
23RWStructuredBuffer<float> outputBuffer;
24
25//TEST_INPUT:ubuffer(data=[1.0 2.0 3.0 4.0], stride=4),name=input1
26ByteAddressBuffer input1;
27
28//TEST_INPUT:ubuffer(data=[1.0 2.0 3.0 4.0], stride=4),name=input2
29ByteAddressBuffer input2;
30
31//TEST_INPUT:ubuffer(data=[1.0 2.0 3.0 4.0], stride=4),name=input3
32ByteAddressBuffer input3;
33
34//TEST_INPUT: set inputBuffer = ubuffer(data=[1 2 3 4 5 6 7 8 9 10 11 12], stride=4);
35uniform int32_t* inputBuffer;
36
37//TEST_INPUT:ubuffer(data=[67305985 134678021 202050057 269422093], stride=4),name=matrix
38//[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
39ByteAddressBuffer matrix;
40
41//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4),name=outputMat
42RWByteAddressBuffer outputMat;
43
44//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4),name=outputMat2
45RWByteAddressBuffer outputMat2;
46
47//TEST_INPUT:ubuffer(data=[5 6 7 8], stride=4),name=bias
48ByteAddressBuffer bias;
49
50struct RayPayload
51{
52    float4 color;
53    float2x4 lssData;
54    bool isSphere;
55    bool isLss;
56};
57
58
59[numthreads(1, 1, 1)]
60[shader("closesthit")]
61void closestHitShader(inout RayPayload payload, in BuiltInTriangleIntersectionAttributes attr)
62{
63    CoopVec<float, 4> vec1 = coopVecLoad<4, float>(input1);
64    CoopVec<float, 4> vec2 = coopVecLoad<4, float>(input2);
65    CoopVec<float, 4> vec3 = coopVecLoad<4, float>(input3);
66
67    CoopVec<float, 4> resultTan = tanh(vec1);
68
69    let resultAdd = vec1 + vec2;
70
71    CoopVec<float, 4> resultCopy = coopVecLoad<4, float>(input1);
72    resultCopy.copyFrom<float>(vec2);
73
74    CoopVec<float, 4> resultFMA = fma(vec1, vec2, vec3);
75    
76    CoopVec<float, 4> vec = coopVecLoad<4, float>(input1);
77    let resultMul = coopVecMatMulAdd<float, 4, 4>(
78        vec,
79        CoopVecComponentType::Float32,
80        matrix,
81        0,
82        CoopVecComponentType::Float32,
83        bias,
84        0,
85        CoopVecComponentType::SignedInt32,
86        CoopVecMatrixLayout::RowMajor,
87        false,
88        4
89    );
90    
91    CoopVec<float, 4> resultMax = max(vec1, vec2);
92    CoopVec<float, 4> resultMin = min(vec1, vec2);
93    
94    CoopVec<float, 4> resultVecMul = vec1 * vec2;
95    
96    outputMat.Store<float>(0, float(1));
97    coopVecOuterProductAccumulate(
98        vec1,
99        vec2,
100        outputMat,
101        0,
102        32,
103        CoopVecMatrixLayout::RowMajor,
104        CoopVecComponentType::Float32,
105    );
106
107    outputMat2.Store(0, float(1));
108    coopVecReduceSumAccumulate(
109        vec1,
110        outputMat2,
111        0,
112    );
113    
114    CoopVec<float, 4> resultStep = step(vec1, vec2);
115
116    CoopVec<float, 4> resultSub = vec1 - vec2;
117    
118    CoopVec<float, 4> resultLog2 = log2(vec1);
119    
120    CoopVec<float, 4> resultExp2 = exp2(vec1);
121
122    for(int i = 0; i < resultTan.getCount(); ++i)
123    {
124        outputBuffer[i] = resultTan[i]  +
125                          resultAdd[i]  +
126                          resultCopy[i] +
127                          resultFMA[i]  +
128                          resultMul[i]  +
129                          resultMax[i]  +
130                          resultMin[i]  +
131                          resultVecMul[i] +
132                          outputMat.Load<float>(i)  +
133                          outputMat2.Load<float>(i) +
134                          resultStep[i] +
135                          resultSub[i]  +
136                          resultLog2[i] +
137                          resultExp2[i];
138    }
139}