diff options
| -rw-r--r-- | prelude/slang-cpp-types.h | 4 | ||||
| -rw-r--r-- | tests/compute/unbounded-array-of-array-syntax.slang | 4 | ||||
| -rw-r--r-- | tests/compute/unbounded-array-of-array-syntax.slang.glsl | 40 | ||||
| -rw-r--r-- | tests/compute/unbounded-array-of-array-syntax.slang.hlsl | 40 | ||||
| -rw-r--r-- | tests/compute/unbounded-array-of-array.slang | 2 |
5 files changed, 88 insertions, 2 deletions
diff --git a/prelude/slang-cpp-types.h b/prelude/slang-cpp-types.h index c8f6357a2..67db607f6 100644 --- a/prelude/slang-cpp-types.h +++ b/prelude/slang-cpp-types.h @@ -85,6 +85,10 @@ struct Matrix Vector<T, COLS> rows[ROWS]; }; +// We can just map `NonUniformResourceIndex` type directly to the index type on CPU, as CPU does not require +// any special handling around such accesses. +typedef size_t NonUniformResourceIndex; + // ----------------------------- ResourceType ----------------------------------------- // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-structuredbuffer-getdimensions diff --git a/tests/compute/unbounded-array-of-array-syntax.slang b/tests/compute/unbounded-array-of-array-syntax.slang index fdc04c95e..df1074896 100644 --- a/tests/compute/unbounded-array-of-array-syntax.slang +++ b/tests/compute/unbounded-array-of-array-syntax.slang @@ -1,5 +1,7 @@ //DISABLE_TEST:CPU_REFLECTION: -profile cs_5_0 -entry computeMain -target cpp //TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute +//TEST:CROSS_COMPILE:-target dxbc-assembly -entry computeMain -profile cs_5_1 +//TEST:CROSS_COMPILE:-target spirv-assembly -entry computeMain -profile cs_5_1 //TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):dxbinding(0),glbinding(0),out,name outputBuffer RWStructuredBuffer<int> outputBuffer; @@ -18,7 +20,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) int baseIndex = index >> 2; int innerIndex = index & 3; - RWStructuredBuffer<int> buffer = g_aoa[baseIndex]; + RWStructuredBuffer<int> buffer = g_aoa[NonUniformResourceIndex(baseIndex)]; // Get the size uint bufferCount, bufferStride; diff --git a/tests/compute/unbounded-array-of-array-syntax.slang.glsl b/tests/compute/unbounded-array-of-array-syntax.slang.glsl new file mode 100644 index 000000000..675d00718 --- /dev/null +++ b/tests/compute/unbounded-array-of-array-syntax.slang.glsl @@ -0,0 +1,40 @@ +//TEST_IGNORE_FILE: + +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; +#extension GL_EXT_nonuniform_qualifier : require + +layout(std430, binding = 1) buffer _S1 { + int _data[]; +} g_aoa_0[]; +layout(std430, binding = 0) buffer _S2 { + int _data[]; +} outputBuffer_0; + +layout(local_size_x = 8, local_size_y = 1, local_size_z = 1) in; +void main() +{ + int innerIndex_0; + + int index_0 = int(gl_GlobalInvocationID.x); + + int innerIndex_1 = index_0 & 3; + + uint _S3; + uint _S4; + (_S3) = (g_aoa_0[nonuniformEXT(index_0 >> 2)])._data.length(); (_S4) = 0; + uint bufferCount_0 = _S3; + + if(uint(innerIndex_1) >= bufferCount_0) + { + innerIndex_0 = int(bufferCount_0 - uint(1)); + } + else + { + innerIndex_0 = innerIndex_1; + } + uint _S5 = uint(innerIndex_0); + ((outputBuffer_0)._data[(uint(index_0))]) = ((g_aoa_0[nonuniformEXT(index_0 >> 2)])._data[(_S5)]); + return; +} diff --git a/tests/compute/unbounded-array-of-array-syntax.slang.hlsl b/tests/compute/unbounded-array-of-array-syntax.slang.hlsl new file mode 100644 index 000000000..3fd9ee8ea --- /dev/null +++ b/tests/compute/unbounded-array-of-array-syntax.slang.hlsl @@ -0,0 +1,40 @@ +//TEST_IGNORE_FILE: + +#pragma pack_matrix(column_major) + +RWStructuredBuffer<int > g_aoa_0[] : register(u0, space1); + +RWStructuredBuffer<int > outputBuffer_0 : register(u0); + +[numthreads(8, 1, 1)] +void computeMain(vector<uint,3> dispatchThreadID_0 : SV_DISPATCHTHREADID) +{ + int innerIndex_0; + + int index_0 = (int) dispatchThreadID_0.x; + + int innerIndex_1 = index_0 & 3; + + RWStructuredBuffer<int > buffer_0 = g_aoa_0[NonUniformResourceIndex(index_0 >> 2)]; + + uint _S1; + uint _S2; + + buffer_0.GetDimensions(_S1, _S2); + + uint bufferCount_0 = _S1; + + if((uint) innerIndex_1 >= bufferCount_0) + { + innerIndex_0 = (int) (bufferCount_0 - (uint) 1); + } + else + { + innerIndex_0 = innerIndex_1; + } + + uint _S3 = (uint) innerIndex_0; + outputBuffer_0[(uint) index_0] = buffer_0[_S3]; + return; +} + diff --git a/tests/compute/unbounded-array-of-array.slang b/tests/compute/unbounded-array-of-array.slang index 760740282..079808710 100644 --- a/tests/compute/unbounded-array-of-array.slang +++ b/tests/compute/unbounded-array-of-array.slang @@ -20,7 +20,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) int baseIndex = index >> 2; int innerIndex = index & 3; - RWStructuredBuffer<int> buffer = g_aoa.array[baseIndex]; + RWStructuredBuffer<int> buffer = g_aoa.array[NonUniformResourceIndex(baseIndex)]; // Get the size uint bufferCount, bufferStride; |
