Avoid overflowing arrays in GLSL atomic tests
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 6 Jul 2021 09:10:04 +0000 (11:10 +0200)
committerRicardo Garcia <rgarcia@igalia.com>
Tue, 6 Jul 2021 10:09:37 +0000 (12:09 +0200)
Tilers may need to execute vertex pipeline stages more than once,
leading to additional shader invocations. This is a problem for atomic
tests, since their result depends on the number of shader invocations
executed.

This is already handled properly for vertex shaders but not for other
vertex pipeline stages.

Affected tests:
dEQP-VK.glsl.atomic_operations.*

Components: Vulkan
VK-GL-CTS issue: 2987

Co-authored-by: Ricardo Garcia <rgarcia@igalia.com>
Change-Id: Iab08e3fb2ef40fc29dcf073817e5fd5dd49e7875

external/vulkancts/modules/vulkan/shaderexecutor/vktAtomicOperationTests.cpp

index b45b561..4ac28b1 100644 (file)
@@ -1095,8 +1095,11 @@ void AtomicOperationCase::createShaderSpec (void)
        else
        {
                nonVertexShaderTemplateStream
-                       << "int idx = atomicAdd(buf.data.index, 1);\n"
-                       << "buf.data.outputValues[idx] = ${ATOMICOP}(buf.data.inoutValues[idx % (${N}/2)], ${COMPARE_ARG}buf.data.inputValues[idx]);\n"
+                       << "if (atomicAdd(buf.data.invocationHitCount[0], 1) < ${N})\n"
+                       << "{\n"
+                       << "    int idx = atomicAdd(buf.data.index, 1);\n"
+                       << "    buf.data.outputValues[idx] = ${ATOMICOP}(buf.data.inoutValues[idx % (${N}/2)], ${COMPARE_ARG}buf.data.inputValues[idx]);\n"
+                       << "}\n"
                        ;
        }