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
2.7 KiB123 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj
3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -output-using-type -shaderobj
4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj
5//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj
6//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -output-using-type -shaderobj
7
8//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
9RWStructuredBuffer<float4> outputBuffer;
10
11typedef float Float;
12
13typedef vector<Float, 3> FloatVector;
14typedef vector<int, 3> IntVector;
15typedef vector<uint, 3> UIntVector;
16
17void subf(inout FloatVector ft, FloatVector f, int idx, Float vf)
18{
19
20    ft += log(f + 10.0);
21    ft += log2(f * 3 + 2);
22
23    {
24        float v[] = { 1, 10, 100, 1000 };
25        ft += IntVector(log10(FloatVector(v[idx] + vf) + 0.5f));
26    }
27
28    ft += abs(f * 4 - 2.0f);
29
30    ft += min(0.5, f);
31    ft += max(f, 0.75);
32
33    ft += pow(0.5, f);
34
35    ft += smoothstep(0.2, 0.7, f);
36    ft += lerp(-100, 100, f);
37
38    ft += clamp(f, 0.1, 0.3);
39
40    ft += step(f, 0.5);
41}
42
43[numthreads(4, 1, 1)]
44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
45{
46    int idx = int(dispatchThreadID.x);
47
48    Float vf = idx * (1.0f / (4.0f));
49     
50    FloatVector f = FloatVector(0.1f, vf, vf + 0.2f);
51    
52    // Operate over all values
53    FloatVector ft = {};
54
55    // fmod
56    ft += FloatVector(IntVector(((f % 0.11f) * 100) + 0.5));
57    
58    ft += sin(f);
59    ft += cos(f);
60    ft += tan(f);
61    
62    {
63        // Vector specific
64        FloatVector nv = normalize(f);
65        ft += nv;
66        
67        FloatVector perp = cross(nv, f.zxy); 
68        ft += perp;
69  
70        ft += dot(perp, f.zyx);
71        ft += length(perp);
72  
73        ft += reflect(f, perp.yzx);
74    }
75    
76    ft += asin(f);
77    ft += acos(f);
78    ft += atan(f);
79    
80    ft += atan2(f, 2.0);
81
82#if 0
83    {
84        // Disabled because not supported on VK (glsl) in vector form
85        FloatVector sf, cf;
86        sincos(f, sf, cf);
87        
88        ft += sf;
89        ft += cf;
90    }
91#endif     
92     
93#if 0     
94    // Disabled because not supported on VK (glsl) in vector form
95    ft += rcp(1.0 + f);
96#endif
97
98    ft += sign(f - 0.5);
99    
100    ft += saturate(f * 4 - 2.0);
101    
102    ft += sqrt(f);
103    ft += rsqrt(1.0f + f);
104    
105    ft += exp2(f);
106    ft += exp(f);
107     
108    ft += frac(f * 3);
109    ft += ceil(f * 5 - 3);
110    
111    ft += floor(f * 10 - 7.01);
112
113    ft += trunc(f * 7);
114
115    subf(ft, f, idx, vf);
116
117    {
118        IntVector vi = asint(f - f) + idx;
119        ft += FloatVector(vi);   
120    }
121    
122    outputBuffer[idx] = vector<Float, 4>(ft, 0);
123}