yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
1023 B40 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-dx12 -shaderobj -output-using-type
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -shaderobj -output-using-type
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -output-using-type
5
6struct Functor : IMutatingFunc<float, float>
7{
8    int context;
9
10    [mutating]
11    float operator()(float p)
12    {
13        context += (int)p;
14        return context;
15    }
16}
17
18float apply<T:IMutatingFunc<float,float>>(inout T f, float p)
19{
20    return f(p);
21}
22
23//TEST_INPUT:ubuffer(data=[0 3 2 2], stride=4):out,name=outputBuffer
24RWStructuredBuffer<uint> outputBuffer;
25
26[numthreads(1, 1, 1)]
27void computeMain(uint tid: SV_DispatchThreadID)
28{
29    Functor f;
30    f.context = 0;
31    
32    f(1.0f);
33    f.operator()(1.0f); // explicit operator () call should also work.
34
35    apply(f, 2.0f);
36    apply(f, 3.0f);
37
38    // CHECK: 7
39    outputBuffer[0] = (uint)f.context;
40}