forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassoctype-nested.slang
62 lines (52 loc) · 1.32 KB
/
assoctype-nested.slang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// assoctype-nested.slang
// Confirm that an associated type can be declared nested in its parent.
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
interface IRandomGenerator
{
[mutating] int generateVal();
}
interface IRandomStrategy
{
associatedtype Generator : IRandomGenerator;
Generator makeGenerator(int seed);
}
int helper<T:IRandomStrategy>(T strategy, int seed)
{
var generator = strategy.makeGenerator(seed);
let val = generator.generateVal();
return val;
}
struct CounterStrategy : IRandomStrategy
{
struct Generator : IRandomGenerator
{
int state;
[mutating] int generateVal()
{
return state++;
}
}
Generator makeGenerator(int seed)
{
Generator generator = { seed };
return generator;
}
}
int test(int val)
{
CounterStrategy strategy;
return helper(strategy, val);
}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<int> gOutputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
int inputVal = tid;
int outputVal = test(inputVal);
gOutputBuffer[tid] = outputVal;
}