yum-mirror/slang

Making it easier to work with shaders

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

jsmall-nvidiaLanguage experiments (#2068)447b7e0e2

master
1.3 KiB60 linesraw
1//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2
3/* A test around use of an array like container. 
4 */
5
6//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
7RWStructuredBuffer<float> outputBuffer;
8
9/* Here is an attempt to provide an interface to check equality. 
10But is the definition right anyway? Really I want the This and Type to be 
11the same type. I guess this enforces that but in an odd manner.
12*/
13interface IEquality
14{
15    associatedtype Type;
16    bool isEqual(Type rhs);
17};
18
19extension int : IEquality
20{
21    typedef int Type;
22    bool isEqual(Type rhs)
23    {
24        // This use of `this` is going to seem odd to a C++ programmer 
25        return this == rhs;
26    }
27};
28
29struct FixedArray<T : IEquality> 
30{
31    static const int SIZE = 4;
32    
33    [mutating] void setAt(int i, T value) { elements[i] = value; }
34    T getAt(int i) { return elements[i]; }
35    int indexOf(T v)
36    {
37        for (int i = 0; i < SIZE; ++i)
38        {
39            if (v.isEqual(elements[i]))
40            {
41                return i;
42            }
43            return -1;
44        }
45    }
46    T elements[SIZE];
47};
48
49
50[numthreads(4, 1, 1)]
51void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
52{
53    int index = dispatchThreadID.x;
54
55    FixedArray<int> arr;
56    arr.setAt(0, index);
57    
58	outputBuffer[index] = 1 + arr.getAt(0);
59}
60