yum-mirror/slang

Making it easier to work with shaders

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

Sai Praveen BangaruMore fixes for reverse-mode on complicated loops (#2675)10e2d9c7c

master
1.0 KiB47 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:-cpu -compute -output-using-type -shaderobj
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef float.Differential dfloat;
10
11[BackwardDifferentiable]
12float test_simple_loop(float y)
13{
14    float t = y;
15
16    if (y > 0.5)
17    {
18        for (int i = 0; i < 3; i++)
19        {
20            t = t * t;
21        }
22    }
23    else
24    {
25        t = t * 10.f;
26    }
27
28    return t;
29}
30
31[numthreads(1, 1, 1)]
32void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
33{
34    {
35        dpfloat dpa = dpfloat(1.0, 0.0);
36
37        __bwd_diff(test_simple_loop)(dpa, 1.0f);
38        outputBuffer[0] = dpa.d; // Expect: 8.0
39    }
40
41    {
42        dpfloat dpa = dpfloat(0.4, 0.0);
43
44        __bwd_diff(test_simple_loop)(dpa, 1.0f);
45        outputBuffer[1] = dpa.d; // Expect: 10.0
46    }
47}