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
|
// struct-generic-value-param.slang
// This test reproduces a few bugs related to declarations
// not being emitted IR and specialized correctly.
//
// First, it tests that a method in a generic `struct`
// gets properly emitted to the IR of its own module.
//
// Second, it tests that witness tables for an empty
// `interface` can be emitted and used to specialize
// code with generic type parameters constrained to
// those interfaces.
// This file is attempting to stress-test use of a `struct`
// type with a generic value parameter. In particular, it
// it can reproduce a bug that was encountered by a user
// when trying out the feature.
//TEST(compute):COMPARE_COMPUTE: -shaderobj
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj
import struct_generic_value_param_import;
Data<N> makeData<let N : int>( int val )
{
Data<N> result = { val };
return result;
}
void doThings<D : IData>(D data, inout int v)
{
v++;
}
int test(int val)
{
var data = makeData<4>(val);
// Note: with the original bug, this call emitted
// as `/* unhandled */(data)` which meant the call
// acted as a no-op.
//
data.doStuff();
// Note: with the original bug, this call emitted
// as `/* uhandled */(data, val)` which is also
// a no-op (that happens to use `operator,`).
//
doThings(data, val);
return data.state + val*16;
}
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
int tid = dispatchThreadID.x;
int inVal = tid;
int outVal = test(inVal);
outputBuffer[tid] = outVal;
}
|