yum-mirror/slang

Making it easier to work with shaders

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

skallweitNVenable more metal tests (#4326)712ce653d

master
982 B47 linesraw
1// generic-func-param-default-arg.slang
2
3// Test that generic functions can have default argument values on their parameters.
4
5//TEST(compute):COMPARE_COMPUTE: -shaderobj
6//TEST_DISABLED:SIMPLE:-target hlsl -entry computeMain -dump-ir
7
8
9interface IValue
10{
11    __init();
12
13    This plusA(This other);
14    This plusB(int other);
15}
16
17T sum<T : IValue>(T value, T other = T(), int extra = 0)
18{
19    return value.plusA(other).plusB(extra);
20}
21
22struct Simple : IValue
23{
24    int val;
25
26    __init() { val = 0; }
27    __init(int val) { this.val = val; }
28
29    Simple plusA(Simple other) { return Simple(val + other.val); }
30    Simple plusB(int other) { return Simple(val + other); }
31}
32
33int test(int val)
34{
35    let s = Simple(val);
36    return sum<Simple>(s).val + 16*sum(s).val;
37}
38
39//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gBuffer
40RWStructuredBuffer<int> gBuffer;
41
42[shader("compute")]
43[numthreads(4)]
44void computeMain(int tid : SV_DispatchThreadID)
45{
46    gBuffer[tid] = test(tid);
47}