yum-mirror/slang

Making it easier to work with shaders

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

Tim FoleyConvert more tests to use shader objects (#1659)2a5d5b323

master
1.4 KiB66 linesraw
1//TEST(compute):COMPARE_COMPUTE:-dx11 -shaderobj
2//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj
3//TEST(compute):COMPARE_COMPUTE:-cpu -xslang -disable-specialization -shaderobj
4//TEST(compute):COMPARE_COMPUTE:-cuda -xslang -disable-specialization -shaderobj
5
6// Test dynamic dispatch code gen for static member functions
7// of associated type.
8[anyValueSize(8)]
9interface IGetter
10{
11    int getVal();
12};
13[anyValueSize(8)]
14interface IAssoc
15{
16    int get();
17    static int getBase<T:IGetter>(T getter);
18}
19[anyValueSize(16)]
20interface IInterface
21{
22    associatedtype Assoc : IAssoc;
23	int Compute(int inVal);
24};
25
26struct GetterImpl : IGetter
27{
28    int getVal() { return 1; }
29};
30
31int GenericCompute<T:IInterface>(T obj, int inVal)
32{
33    GetterImpl getter;
34	return obj.Compute(inVal) + T.Assoc.getBase(getter);
35}
36
37struct Impl : IInterface
38{
39    struct Assoc : IAssoc
40    {
41        int val;
42        int get() { return val; }
43        static int getBase<T:IGetter>(T t) { return t.getVal(); }
44    };
45    int base;
46	int Compute(int inVal) { return base + inVal * inVal; }
47};
48
49int test(int inVal)
50{
51    Impl obj;
52    obj.base = 1;
53	return GenericCompute<Impl>(obj, inVal);
54}
55
56//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):out,name=outputBuffer
57RWStructuredBuffer<int> outputBuffer;
58
59[numthreads(4, 1, 1)]
60void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
61{
62	uint tid = dispatchThreadID.x;
63	int inVal = outputBuffer[tid];
64	int outVal = test(inVal);
65	outputBuffer[tid] = outVal;
66}