yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
0ec8e5b01
master
1// global-generic-value-param.slang 2 3//DISABLED_TEST(compute):COMPARE_COMPUTE: -shaderobj 4 5// This is a basic test of support for global generic 6// value parameters: explicit named parameters at global 7// scope that can be used to generate specialized kernel 8// code based on different values. 9 10// We start by declaring a global generic value parameter: 11// 12// Note: only `int` parameters are expected to work for now. 13// Note: the default `= 0` intializer isn't used right now. 14// 15__generic_value_param kOffset : uint = 0; 16 17// For the test framework, we also need to specify what 18// value we want to specialize to. 19// 20// Note: this value (7) will be fed in to the compiler API 21// as a specialization argument, and will not be visible 22// to the compiler when it initially compiles the code 23// to IR. 24// 25//TEST_INPUT: globalSpecializationArg 7 26 27// Next we will declare a buffer of data just so that we 28// can index into something and make the shader logic a 29// bit less trivial. 30// 31RWStructuredBuffer<uint> vals; 32//TEST_INPUT: ubuffer(data=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15], stride=4):name vals 33 34// The core test function will use the `kOffset` value 35// we declared above along with the input value (the 36// thread ID) to index into our buffer of values and 37// compute a result. All of the math here is just to 38// make the result easy to validate by eye. 39// 40uint test(uint value) 41{ 42 return value * 16 + vals[(value + kOffset) & 0xF]; 43} 44 45// And finally we have the boilerplate cruft that almost 46// all of our compute tests use. 47 48//TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer 49RWStructuredBuffer<uint> outputBuffer; 50 51[numthreads(16, 1, 1)] 52void computeMain( 53 uint3 dispatchThreadID : SV_DispatchThreadID) 54{ 55 uint tid = dispatchThreadID.x; 56 uint inVal = tid; 57 uint outVal = test(inVal); 58 outputBuffer[tid] = outVal; 59}