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.2 KiB56 linesraw
1//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2
3/* A test for equality around interface types
4
5Here again trying to apply equality *outside* of the types (MyStruct) definition.  
6
7Doesn't work:
8
9.slang(24): error 30019: expected an expression of type 'Type', got 'T'
10    return T::isEqual(a, b);
11    
12Note! This may be somewhat of a silly example for equality. We could get what we want here by just
13implementing 'isEqual(MyStruct a, MyStruct b)` as a free function and use overloading.     
14 */
15
16//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
17RWStructuredBuffer<float> outputBuffer;
18
19struct MyStruct
20{
21    int a = 10;
22};
23
24interface IEquality
25{
26    associatedtype Type;
27    static bool isEqual(Type a, Type b);
28}
29
30extension MyStruct : IEquality
31{
32    // Do I need this? Is the type This?
33    typedef MyStruct Type;
34    static bool isEqual(Type a, Type b) { return a.a == b.a; }
35};
36
37__generic<T : IEquality>
38bool isEqual(T a, T b)
39{
40    return T::isEqual(a, b);
41}
42             
43[numthreads(4, 1, 1)]
44void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
45{
46    int index = dispatchThreadID.x;
47
48    MyStruct a = { 1 };
49    MyStruct b = { 2 };
50    
51    bool res = isEqual(a, b);
52
53	outputBuffer[index] = 1 + int(res);
54}
55
56