yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
9ec6b9168
master
1// struct-generic-value-param.slang 2 3// This test reproduces a few bugs related to declarations 4// not being emitted IR and specialized correctly. 5// 6// First, it tests that a method in a generic `struct` 7// gets properly emitted to the IR of its own module. 8// 9// Second, it tests that witness tables for an empty 10// `interface` can be emitted and used to specialize 11// code with generic type parameters constrained to 12// those interfaces. 13 14// This file is attempting to stress-test use of a `struct` 15// type with a generic value parameter. In particular, it 16// it can reproduce a bug that was encountered by a user 17// when trying out the feature. 18 19//TEST(compute):COMPARE_COMPUTE: -shaderobj 20//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj 21 22import struct_generic_value_param_import; 23 24Data<N> makeData<let N : int>( int val ) 25{ 26 Data<N> result = { val }; 27 return result; 28} 29 30void doThings<D : IData>(D data, inout int v) 31{ 32 v++; 33} 34 35int test(int val) 36{ 37 var data = makeData<4>(val); 38 39 // Note: with the original bug, this call emitted 40 // as `/* unhandled */(data)` which meant the call 41 // acted as a no-op. 42 // 43 data.doStuff(); 44 45 // Note: with the original bug, this call emitted 46 // as `/* uhandled */(data, val)` which is also 47 // a no-op (that happens to use `operator,`). 48 // 49 doThings(data, val); 50 51 return data.state + val*16; 52} 53 54//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 55RWStructuredBuffer<int> outputBuffer; 56 57[numthreads(4, 1, 1)] 58void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 59{ 60 int tid = dispatchThreadID.x; 61 int inVal = tid; 62 int outVal = test(inVal); 63 outputBuffer[tid] = outVal; 64}