yum-mirror/slang

Making it easier to work with shaders

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

Harsh Aggarwal (NVIDIA)Fix 7723 - Add autodiff tests (#7919)d10732742

master
1.1 KiB45 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8static const uint levels = 8;
9
10[Differentiable]
11void eval(float3 p, out float4 output[levels])
12{
13    [ForceUnroll] for (int level = 0; level < 3; ++level) 
14    {
15        float4 f = 0.f;
16
17        // tri-linear time!
18        [ForceUnroll] for (int z = 0; z < 2; ++z)
19        {
20            float wx = 0;
21            if (z != 0)
22                wx = p.x;
23            else
24                wx = p.y;
25
26            f += wx;
27        }
28
29        output[level] = f;
30    }
31}
32
33[numthreads(1, 1, 1)]
34void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
35{
36    float3 p = float3(2.0, 3.0, 0);
37
38    float4 output[levels];
39    eval(p, output);
40    DifferentialPair<float3> dp = DifferentialPair<float3>(p, 0);
41    __bwd_diff(eval)(dp, output);
42
43    // Write output
44    outputBuffer[0] = dp.d.x;
45}