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
953 B39 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
8typedef DifferentialPair<float> dpfloat;
9
10interface IFoo : IDifferentiable
11{
12    [ForwardDifferentiable]
13    float getVal();
14}
15
16struct A : IFoo
17{
18    float x;
19    [ForwardDifferentiable]
20    float getVal(){return x;}
21}
22
23[ForwardDifferentiable]
24float f(float x, no_diff IFoo y)
25{
26    return x * x + y.getVal();
27}
28
29[numthreads(1, 1, 1)]
30void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
31{
32    {
33        A a;
34        a.x = 2.0;
35        let rs = __fwd_diff(f)(dpfloat(1.5, 1.0), a);
36        outputBuffer[0] = rs.p; // Expect: 6.25
37        outputBuffer[1] = rs.d; // Expect: 3.0
38    }
39}