yum-mirror/slang

Making it easier to work with shaders

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

ArielG-NVFix `tests\autodiff\reverse-while-loop-3.slang` test (#4886)03e1e1774

master
1.6 KiB71 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -output-using-type -shaderobj
4
5//TEST_INPUT:ubuffer(data=[1], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8// This test isn't actually testing the output, but rather that the compiler doesn't crash upon 
9// encountering a specific loop pattern. ('Data' is non-differentiable here, so the expected output is 0)
10// 
11
12typedef DifferentialPair<float> dpfloat;
13typedef float.Differential dfloat;
14
15struct P
16{
17    bool terminated;
18    bool isTerminated() { return terminated; }
19    bool isHit() { return !terminated; }
20};
21
22struct Data
23{
24    __init(float dataIn)
25    {
26        this.t = dataIn;
27    }
28    float t;
29};
30
31void updateData(Data data)
32{
33    data.t = data.t * data.t;
34}
35
36[BackwardDifferentiable]
37float test_simple_while(float y, uint n)
38{
39    Data d = Data(y);
40    P p;
41    p.terminated = false;
42    int i = n;
43
44    if (p.isTerminated())
45        return d.t;
46
47    [MaxIters(4)]
48    while (!p.isTerminated())
49    {
50        updateData(d);
51        p.terminated = (i-- == 0);
52        if (p.isTerminated())
53            break;
54
55        if (!p.isHit())
56            break;
57    }
58    return d.t;
59}
60
61[numthreads(1, 1, 1)]
62void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
63{
64    {
65        dpfloat dpa = dpfloat(1.0, 0.0);
66
67        __bwd_diff(test_simple_while)(dpa, 2, 1.0f);
68        outputBuffer[0] = dpa.d;
69        //BUF: 0
70    }
71}