blob: 6c1a6939f88800c6f58caa551d86dd85115222b6 (
plain)
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
63
64
65
|
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile sm_5_0 -use-dxbc -output-using-type
// Test that we can specialize a generic method called through a dynamic interface.
interface IValue
{
float getVal();
}
struct SimpleVal : IValue
{
float val;
float getVal() { return val; }
}
[anyValueSize(16)]
interface IInterface
{
associatedtype V : IValue;
V run<let N : int>(float arr[N]);
}
struct Add : IInterface
{
float base;
typealias V = SimpleVal;
V run<let N : int>(float arr[N])
{
float sum = base;
for (int i = 0; i < N; i++)
sum += arr[i];
V rs;
rs.val = sum;
return rs;
}
}
struct Mul : IInterface
{
float base;
typealias V = SimpleVal;
V run<let N : int>(float arr[N])
{
float sum = base;
for (int i = 0; i < N; i++)
sum *= arr[i];
V rs;
rs.val = sum;
return rs;
}
}
//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<float> gOutputBuffer;
//TEST_INPUT:type_conformance Add:IInterface=1
//TEST_INPUT:type_conformance Mul:IInterface=2
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
var obj = createDynamicObject<IInterface>(1, 1.0); // Add.
float arr[3] = { 2, 3, 4 };
gOutputBuffer[0] = obj.run(arr).getVal();
}
|