yum-mirror/slang

Making it easier to work with shaders

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

Yong HeOverhaul `transposeParameterBlock` to support `inout` params. (#2621)228e71dab

master
2.1 KiB98 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 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float> dpfloat;
9typedef float.Differential dfloat;
10
11[BackwardDifferentiable]
12float test_simple_single_iter_loop(float y)
13{
14    float x = 0;
15
16    for (int i = 0; i < 1; i++)
17    {
18        if (y > 0.6)
19        {
20            x = y * 10.0f;
21            break;
22        }
23        else
24        {
25            x = y * 6.0f;
26            break;
27        }
28    }
29    
30    return x;
31}
32
33[BackwardDifferentiable]
34float test_nested_if_else_single_iter_loop(float y)
35{
36    float x = 0;
37
38    for (int i = 0; i < 1; i++)
39    {
40        if (y > 0.6)
41        {
42            if (y > 0.8)
43            {
44                x = y * 10.0f;
45                break;
46            }
47            else
48            {
49                x = y * 4.0f;
50                break;
51            }
52        }
53
54        x = y * 6.0f;
55        break;
56    }
57
58    return x;
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_single_iter_loop)(dpa, 1.0f);
68        outputBuffer[0] = dpa.d; // Expect: 10.0
69    }
70
71    {
72        dpfloat dpa = dpfloat(0.4, 0.0);
73        
74        __bwd_diff(test_simple_single_iter_loop)(dpa, 1.0f);
75        outputBuffer[1] = dpa.d; // Expect: 6.0
76    }
77
78    {
79        dpfloat dpa = dpfloat(1.0, 0.0);
80
81        __bwd_diff(test_nested_if_else_single_iter_loop)(dpa, 1.0f);
82        outputBuffer[2] = dpa.d; // Expect: 10.0
83    }
84
85    {
86        dpfloat dpa = dpfloat(0.7, 0.0);
87
88        __bwd_diff(test_nested_if_else_single_iter_loop)(dpa, 1.0f);
89        outputBuffer[3] = dpa.d; // Expect: 4.0
90    }
91
92    {
93        dpfloat dpa = dpfloat(0.4, 0.0);
94
95        __bwd_diff(test_nested_if_else_single_iter_loop)(dpa, 1.0f);
96        outputBuffer[4] = dpa.d; // Expect: 6.0
97    }
98}