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.9 KiB87 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.slang(77): 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 : IBase>
41    T as()
42    {
43        bool isOk = isType<T>();
44        // I want a way to assert!
45        // assert(isOk);
46        return gB.Load<T>(offset);
47    }
48    int offset;
49};
50
51struct A : Base
52{
53    static bool isType(Type type) { return type == Type::A; }
54    Ptr next;
55    int something;
56};
57
58struct B : Base
59{
60    static bool isType(Type type) { return type == Type::C || type == Type::B; }
61    int someData;
62};
63
64struct C : B
65{
66    static bool isType(Type type) { return type == Type::C; }
67    int somethingElse;
68};
69
70RWStructuredBuffer<int> outputBuffer;
71
72[numthreads(4, 1, 1)]
73void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
74{    
75    Ptr ptr = { 0 };
76    int total = 0;
77    
78    while (ptr.isType<A>())    
79    {
80        A a = ptr.as<A>();
81        total += a.something;
82
83        ptr = a.next;
84    }
85
86    outputBuffer[dispatchThreadID.x] = total;
87}