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.4 KiB61 linesraw
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type
3
4//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
5RWStructuredBuffer<float> outputBuffer;
6
7typedef DifferentialPair<float> dpfloat;
8typedef float.Differential dfloat;
9
10
11struct SpatialVertex : IDifferentiable
12{
13    float x;
14};
15
16struct MaterialVertex
17{
18    float x;
19};
20
21//TEST_INPUT:ubuffer(data=[2.0 2.0 2.0 2.0 2.0], stride=4):name=pathVertices
22RWStructuredBuffer<MaterialVertex> pathVertices;
23
24[Differentiable]
25SpatialVertex transform(float p, MaterialVertex m)
26{
27    return { p * m.x };
28}
29
30[Differentiable]
31float test_simple_loop(float y)
32{
33    SpatialVertex vShade[2];
34    int pathLength = 1;
35
36    [ForceUnroll]
37    for (int i = 0; i < 2; i++)
38    {
39        if (!(pathVertices[i].x > 1.4))
40        {
41            pathLength = i;
42            break;
43        }
44
45        vShade[i] = transform(y, pathVertices[i]);
46    }
47
48    return vShade[0].x + vShade[1].x;
49}
50
51[numthreads(1, 1, 1)]
52void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
53{
54    {
55        dpfloat dpy = dpfloat(1.0, 1.0);
56
57        var dpresult = fwd_diff(test_simple_loop)(dpy);
58        outputBuffer[0] = pathVertices[0].x; // CHECK: 2.0
59        outputBuffer[1] = dpresult.d; // CHECK: 4.0
60    }
61}