|
| 1 | +// kernel-context-threading.slang |
| 2 | + |
| 3 | +// This test tests out the slang-ir-explicit-global-context functionality for C++ like targets. |
| 4 | +// In particular these require that the KernelContext is threaded through functions that access globals. |
| 5 | +// Currently this is only really applicable to C++, but for completeness all targets are tested. |
| 6 | + |
| 7 | +//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj |
| 8 | +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj |
| 9 | +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -compile-arg -O3 -xslang -matrix-layout-row-major -shaderobj |
| 10 | +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj |
| 11 | +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -xslang -matrix-layout-row-major -shaderobj |
| 12 | +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -xslang -matrix-layout-row-major -shaderobj |
| 13 | + |
| 14 | +//TEST_INPUT:cbuffer(data=[1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 10.0 20.0 30.0 1.0]):name matrixBuffer |
| 15 | +ConstantBuffer<float4x4> matrixBuffer; |
| 16 | + |
| 17 | +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name rowOrderMatrixOutput |
| 18 | +RWStructuredBuffer<float> rowOrderMatrixOutput; |
| 19 | + |
| 20 | +void writeRow2(float4 v, int rowIndex) |
| 21 | +{ |
| 22 | + int baseIndex = rowIndex * 4; |
| 23 | + |
| 24 | + rowOrderMatrixOutput[baseIndex + 0] = v.x; |
| 25 | + rowOrderMatrixOutput[baseIndex + 1] = v.y; |
| 26 | + rowOrderMatrixOutput[baseIndex + 2] = v.z; |
| 27 | + rowOrderMatrixOutput[baseIndex + 3] = v.w; |
| 28 | +} |
| 29 | + |
| 30 | +// Just to test threading works through multiple levels of functions. |
| 31 | +void writeRow(float4 v, int rowIndex) |
| 32 | +{ |
| 33 | + writeRow2(v, rowIndex); |
| 34 | +} |
| 35 | + |
| 36 | +[numthreads(1, 1, 1)] |
| 37 | +void computeMain(uint3 tid : SV_DispatchThreadID) |
| 38 | +{ |
| 39 | + float4 v = float4(1, 2, 3, 1); |
| 40 | + |
| 41 | + float4x4 M = matrixBuffer; |
| 42 | + |
| 43 | + float4 r = mul(v, M); |
| 44 | + |
| 45 | + writeRow(M[0], 0); |
| 46 | + writeRow(M[1], 1); |
| 47 | + writeRow(M[2], 2); |
| 48 | + writeRow(M[3], 3); |
| 49 | +} |
0 commit comments