yum-mirror/slang

Making it easier to work with shaders

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

Yong HeOverhaul `transposeParameterBlock` to support `inout` params. (#2621)228e71dab

master
834 B31 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
8[BackwardDifferentiable]
9void g(float x, out float y)
10{
11    y = (x + 1) * (x + 1);
12}
13
14[BackwardDifferentiable]
15void f(float x, out float y)
16{
17    g(x, y);
18    g(x, y);
19}
20
21[numthreads(1, 1, 1)]
22void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
23{
24    var x = diffPair(5.0);
25    float yDiffOut = 1.0;
26
27    __bwd_diff(f)(x, yDiffOut);
28
29    outputBuffer[0] = x.p; // should be 5, since bwd_diff does not write back new primal val.
30    outputBuffer[1] = x.d; // 12.0
31}