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
851 B37 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
8
9struct Foo : IDifferentiable
10{
11    typealias Differential = Foo;
12    float x[3];
13};
14
15[Differentiable]
16Foo getFoo(float x)
17{
18    return { { x, x, x } };
19}
20
21[Differentiable]
22float foobar(float x)
23{
24    int i = 3 * int(floor(x));
25    Foo foo = getFoo(x);
26    return foo.x[i] * foo.x[i];
27}
28
29[numthreads(1, 1, 1)]
30void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
31{
32    {
33        float a = 0.5;
34        var d = fwd_diff(foobar)(diffPair(a, 1.0)).d;
35        outputBuffer[0] = d;
36    }
37}