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.8 KiB85 linesraw
1//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
2
3/* The purpose of these tests is to use generics to be able to traverse
4a 'linked list' of different related types. 
5
6tests/current-bugs/generic/byte-address-ptr-2.slang(75): note 99999: an internal error threw an exception while working on code near this location
7(0): error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: assert failure: witnessTableVal->getOp() != kIROp_StructKey
8*/
9
10//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
11
12//TEST_INPUT:ubuffer(data=[0]):name=gB
13ByteAddressBuffer gB;
14
15enum Type : int
16{
17    A,
18    B,
19    C,
20};
21
22interface IBase 
23{
24    static bool isType(Type type);
25};
26
27struct Base : IBase
28{
29    static bool isType(Type type) { return true; }
30    Type type;
31};
32
33struct Ptr
34{
35    Type getType() { return gB.Load<Base>(offset).type; }
36    
37    __generic<T : IBase>
38    bool isType() { return T::isType(getType()); }
39    // Changing to T : IBase causes an internal compiler crash
40    __generic<T>
41    T as()
42    {
43        // I want a way to assert if not an appropriate cast.
44        return gB.Load<T>(offset);
45    }
46    int offset;
47};
48
49struct A : Base
50{
51    static bool isType(Type type) { return type == Type::A; }
52    Ptr next;
53    int something;
54};
55
56struct B : Base
57{
58    static bool isType(Type type) { return type == Type::C || type == Type::B; }
59    int someData;
60};
61
62struct C : B
63{
64    static bool isType(Type type) { return type == Type::C; }
65    int somethingElse;
66};
67
68RWStructuredBuffer<int> outputBuffer;
69
70[numthreads(4, 1, 1)]
71void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
72{    
73    Ptr ptr = { 0 };
74    int total = 0;
75    
76    while (ptr.isType<A>())    
77    {
78        A a = ptr.as<A>();
79        total += a.something;
80
81        ptr = a.next;
82    }
83
84    outputBuffer[dispatchThreadID.x] = total;
85}