yum-mirror/slang

Making it easier to work with shaders

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

Jay KwakFix intermittent debug failures with Debug build (#7369)7dad68f86

master
1.2 KiB63 linesraw
1//TEST:LANG_SERVER:
2//HOVER:6,15
3
4// Test that we can specialize a generic method called through a dynamic interface.
5
6interface IValue
7{
8    float getVal();
9}
10
11struct SimpleVal : IValue
12{
13    float val;
14    float getVal() { return val; }
15}
16
17[anyValueSize(16)]
18interface IInterface
19{
20    associatedtype V : IValue;
21    V run<let N : int>(float arr[N]);
22}
23
24struct Add : IInterface
25{
26    float base;
27    typealias V
28    float run<let N : int>(float arr[N])
29    {
30        float sum = base;
31        for (int i = 0; i < N; i++)
32            sum += arr[i];
33        return sum;
34    }
35}
36
37struct Mul : IInterface
38{
39    float base;
40
41    float run<let N : int>(float arr[N])
42    {
43        float sum = base;
44        for (int i = 0; i < N; i++)
45            sum *= arr[i];
46        return sum;
47    }
48}
49
50//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
51RWStructuredBuffer<float> gOutputBuffer;
52
53//TEST_INPUT:type_conformance Add:IInterface=1
54//TEST_INPUT:type_conformance Mul:IInterface=2
55
56[numthreads(1, 1, 1)]
57void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
58{
59    var obj = createDynamicObject<IInterface>(1, 1.0); // Add.
60    float arr[3] = { 2, 3, 4 };
61    gOutputBuffer[0] = obj.run(arr);
62
63}