yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
3.8 KiB137 linesraw
1// TODO(JS):
2// NOTE we can't test on VK/gl at the moment because we don't support intrinsics over matrices on that target currently
3
4//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
5//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
6//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -shaderobj -render-feature hardware-device
7//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
8//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
9//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -mtl
10// Not supported in WGSL: Integer matrices, Double and other unsupported scalar types
11//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-wgpu
12
13//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
14RWStructuredBuffer<float> outputBuffer;
15
16typedef matrix<float, 2, 2> FloatMatrix;
17typedef matrix<int, 2, 2> IntMatrix;
18typedef matrix<uint, 2, 2> UIntMatrix;
19typedef vector<float, 2> FloatVector;
20
21float calcResult(FloatMatrix v) 
22{ 
23    // Multiply diffent parts by different amounts to make order important
24    return v[0][0] + v[0][1] * 2 + v[1][0] * 3 + v[1][1] * 4;
25}
26
27FloatMatrix makeFloatMatrix(float f)
28{
29    FloatMatrix m = { { f, f }, { f, f } };
30    return m;
31}
32
33IntMatrix makeIntMatrix(int v)
34{
35    IntMatrix m = { { v, v }, { v, v } };
36    return m;
37}
38
39[numthreads(4, 1, 1)]
40void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
41{
42    int idx = int(dispatchThreadID.x);
43
44    float scalarF = idx * (1.0f / (4.0f));
45
46    FloatMatrix ft = {}; 
47
48    FloatMatrix f = { { scalarF + 0.01, scalarF + 0.02f}, { scalarF + 0.011f, scalarF + 0.022f}};
49    
50    ft += transpose(f);
51    
52    // fmod
53    ft += FloatMatrix(IntMatrix(((f % makeFloatMatrix(0.11f)) * makeFloatMatrix(100)) + makeFloatMatrix(0.5)));
54    
55    ft += sin(f);
56      
57    // Lets try some matrix/matrix
58    ft = f * ft;
59    
60    // Lets try some vector matrix
61    
62    {
63        FloatMatrix r = {mul(f[0], ft), mul(ft, f[1])};
64        ft += r;
65    }
66    
67    // Back to the transcendentals
68   
69    ft += cos(f);
70    ft += tan(f);
71    
72    ft += asin(f);
73    ft += acos(f);
74    ft += atan(f);
75    
76    ft += atan2(f, makeFloatMatrix(2)); 
77
78#if 0
79    // TODO(JS):
80    // This fails from DXC with a validation error(!)
81    {
82        FloatMatrix sf, cf;
83        sincos(f, sf, cf);
84        
85        ft += sf;
86        ft += cf;
87    }
88#endif 
89    
90    ft += rcp(makeFloatMatrix(1.0) + f);
91    ft += FloatMatrix(sign(f - makeFloatMatrix(0.5)));
92   
93    ft += saturate(f * makeFloatMatrix(4) - makeFloatMatrix(2.0));
94    
95    ft += sqrt(f);
96    ft += rsqrt(makeFloatMatrix(1.0f) + f);
97    
98    ft += exp2(f);
99    ft += exp(f);
100    ft += exp10(f);
101                
102    ft += frac(f * makeFloatMatrix(3));
103    ft += ceil(f * makeFloatMatrix(5) - makeFloatMatrix(3));
104    
105    ft += floor(f * makeFloatMatrix(10) - makeFloatMatrix(7));
106    ft += trunc(f * makeFloatMatrix(7));
107     
108    ft += log(f + makeFloatMatrix(10.0));
109    ft += log2(f * makeFloatMatrix(3) + makeFloatMatrix(2));
110
111    {
112        float scalarVs[] = { 1, 10, 100, 1000 };
113        ft += FloatMatrix(IntMatrix(log10(makeFloatMatrix(scalarVs[idx])) + makeFloatMatrix(0.5f)));
114    }
115       
116    ft += abs(f * makeFloatMatrix(4) - makeFloatMatrix(2.0f));
117    
118    ft += min(makeFloatMatrix(0.5), f);
119    ft += max(f, makeFloatMatrix(0.75));
120
121    ft += pow(makeFloatMatrix(0.5), f);
122
123    ft += smoothstep(makeFloatMatrix(0.2), makeFloatMatrix(0.7), f);
124    ft += lerp(makeFloatMatrix(-100), makeFloatMatrix(100), f);
125
126    ft += clamp(f, makeFloatMatrix(0.1), makeFloatMatrix(0.3));
127
128    ft += step(f, makeFloatMatrix(0.5));
129
130    IntMatrix vi = asint(makeFloatMatrix(idx)); 
131    ft += asfloat(vi);
132    
133    UIntMatrix vu = asuint(f);
134    ft += asfloat(vu);
135   
136    outputBuffer[idx] = calcResult(ft);
137}