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 KiB40 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
8typedef DifferentialPair<float2> dpfloat2;
9typedef DifferentialPair<float3> dpfloat3;
10typedef DifferentialPair<float4> dpfloat4;
11
12[Differentiable]
13float2 f(float3 x)
14{
15    float3 u;
16    u.zy = x.yx;
17    return u.zy;
18}
19
20[numthreads(1, 1, 1)]
21void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
22{
23    {
24        float3 a = float3(2.0, 2.0, 2.0);
25        float3 da = float3(1.0, 0.5, 1.0);
26
27        outputBuffer[0] = fwd_diff(f)(dpfloat3(a, da)).d.x;
28    }
29
30    {
31        float3 a = float3(2.0, 2.0, 2.0);
32        var dpa = diffPair(a);
33
34        bwd_diff(f)(dpa, float2(0.5, 1.0));
35
36        outputBuffer[1] = dpa.d.x; // 1.0
37        outputBuffer[2] = dpa.d.y; // 0.5
38        outputBuffer[3] = dpa.d.z; // 0.0
39    }
40}