yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeIntellisense: show info on decl kind and differentiability. (#2847)7be108c37

master
1.3 KiB53 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:-cpu -compute -output-using-type -shaderobj
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8interface IFoo
9{
10    float doSomething();
11}
12
13struct A : IFoo
14{
15    float doSomething()
16    {
17        return 0.0f;
18    }
19}
20
21// A normal function that calls doSomething().
22float original<T : IFoo>(T p, float x)
23{
24    p.doSomething();
25    return x * x;
26}
27
28[PrimalSubstituteOf(original)]
29[BackwardDifferentiable]
30float primalSubst<T : IFoo>(T p, float x)
31{
32    return 2.0f * x * x;
33}
34
35[BackwardDifferentiable]
36float caller(IFoo d, float x)
37{
38    return original(d, x);
39}
40
41//TEST_INPUT: type_conformance A:IFoo = 0
42
43[numthreads(1, 1, 1)]
44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
45{
46    var obj = createDynamicObject<IFoo>(dispatchThreadID.x, 0); // A
47
48    var a = diffPair(3.0, 1.0);
49    __bwd_diff(caller)(obj, a, 1.0);
50    outputBuffer[0] = a.d;                                         // Expect: 12.0
51    outputBuffer[1] = __fwd_diff(caller)(obj, diffPair(3.0, 1.0)).p; // Expect: 18.0
52    outputBuffer[2] = caller(obj, 3.0); // Expect: 9.0
53}