summaryrefslogtreecommitdiffstats
path: root/tests/autodiff/differentiable-constructor.slang
blob: 857bdb659abb9f0ec221c0118df32de321f09684 (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
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -shaderobj -output-using-type

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<float> outputBuffer;

interface IFoo : IDifferentiable
{
    [Differentiable]
    __init();

    float compute(float y);
}

struct Impl : IFoo
{
    float x;
    [Differentiable]
    __init()
    {
        x = 4.0;
    }

    float compute(int id) { return outputBuffer[id] = detach(x);}
}

float test<T : IFoo>(int id)
{
    T t;
    return t.compute(id);
}

[numthreads(1, 1, 1)]
void computeMain(uint id : SV_DispatchThreadID)
{
    // CHECK: 4.0
    test<Impl>(id); 
}