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
1.0 KiB43 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
8struct D : IDifferentiable
9{
10    float n;
11    float m;
12}
13
14[BackwardDifferentiable]
15void g(D d, int i, out D outArray[1][2])
16{
17    outArray[0][0].m = d.n;
18    outArray[0][0].n = d.m * 3.0f + 1.0;
19
20    outArray[0][i].m = d.n * d.n;
21    outArray[0][i].n = d.m * 4.0f + 1.0;
22}
23
24[BackwardDifferentiable]
25void f(D d, int i, out D outArray[1][2])
26{
27    g(d, 0, outArray);
28    g(d, i, outArray);
29}
30
31[numthreads(1, 1, 1)]
32void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
33{
34    D d = { 1.0, 2.0 };
35
36    var dpd = diffPair(d);
37
38    D.Differential tmp[1][2] = { { { 1.0, 1.0 }, { 1.0, 1.0 } } };
39    __bwd_diff(f)(dpd, 1, tmp);
40
41    outputBuffer[0] = dpd.d.m;
42    outputBuffer[1] = dpd.d.n;
43}