summaryrefslogtreecommitdiffstats
path: root/tests/autodiff/dynamic-dispatch-ptr.slang
blob: 5a0614769be1144b38755f3eb8da0c246f3f74e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -output-using-type -emit-spirv-directly
//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -output-using-type

//CHECK: 1.0 

//TEST_INPUT: type_conformance Sensor:ISensor = 1;

[anyValueSize(16)]
interface ISensor
{
    [Differentiable]
    float4 splat(float4 point);
}

struct Sensor : ISensor
{
    [Differentiable]
    float4 splat(float4 point)
    {
        return point;
    }
}

[Differentiable]
float4 splat(ISensor* obj, float4 point)
{
    return obj->splat(point);
}

//TEST_INPUT: set s = ubuffer(data=[0 0 1 0 0 0 0 0])
uniform ISensor *s;

//TEST_INPUT: set outBuffer = out ubuffer(data=[0 0 0 0], stride=4)
RWStructuredBuffer<float4> outBuffer;

[shader("compute"), numthreads(1, 1, 1)]
void computeMain(
    uint3 id : SV_DispatchThreadID
)
{
    DifferentialPair<float4> dp;
    bwd_diff(splat)(s, dp, float4(1.0f));
    outBuffer[id.x] = dp.d;
}