1 /*------------------------------------------------------------------------
2 * OpenGL Conformance Tests
3 * ------------------------
5 * Copyright (c) 2017-2019 The Khronos Group Inc.
6 * Copyright (c) 2017 Codeplay Software Ltd.
7 * Copyright (c) 2019 NVIDIA Corporation.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Subgroups Tests
24 */ /*--------------------------------------------------------------------*/
26 #include "glcSubgroupsShapeTests.hpp"
27 #include "glcSubgroupsTestsUtils.hpp"
41 static bool checkVertexPipelineStages(std::vector<const void*> datas,
42 deUint32 width, deUint32)
44 return glc::subgroups::check(datas, width, 1);
47 static bool checkComputeStage(std::vector<const void*> datas,
48 const deUint32 numWorkgroups[3], const deUint32 localSize[3],
51 return glc::subgroups::checkCompute(datas, numWorkgroups, localSize, 1);
61 std::string getOpTypeName(int opType)
66 DE_FATAL("Unsupported op type");
68 case OPTYPE_CLUSTERED:
78 ShaderStageFlags shaderStage;
81 void initFrameBufferPrograms (SourceCollections& programCollection, CaseDefinition caseDef)
83 std::ostringstream bdy;
84 std::string extension = (OPTYPE_CLUSTERED == caseDef.opType) ?
85 "#extension GL_KHR_shader_subgroup_clustered: enable\n" :
86 "#extension GL_KHR_shader_subgroup_quad: enable\n";
88 subgroups::setFragmentShaderFrameBuffer(programCollection);
90 if (SHADER_STAGE_VERTEX_BIT != caseDef.shaderStage)
91 subgroups::setVertexShaderFrameBuffer(programCollection);
93 extension += "#extension GL_KHR_shader_subgroup_ballot: enable\n";
95 bdy << " uint tempResult = 0x1;\n"
96 << " uvec4 mask = subgroupBallot(true);\n";
98 if (OPTYPE_CLUSTERED == caseDef.opType)
100 for (deUint32 i = 1; i <= subgroups::maxSupportedSubgroupSize(); i *= 2)
102 bdy << " if (gl_SubgroupSize >= " << i << ")\n"
104 << " uvec4 contribution = uvec4(0);\n"
105 << " const uint modID = gl_SubgroupInvocationID % 32;\n"
106 << " switch (gl_SubgroupInvocationID / 32)\n"
108 << " case 0: contribution.x = 1 << modID; break;\n"
109 << " case 1: contribution.y = 1 << modID; break;\n"
110 << " case 2: contribution.z = 1 << modID; break;\n"
111 << " case 3: contribution.w = 1 << modID; break;\n"
113 << " uvec4 result = subgroupClusteredOr(contribution, " << i << ");\n"
114 << " uint rootID = gl_SubgroupInvocationID & ~(" << i - 1 << ");\n"
115 << " for (uint i = 0; i < " << i << "; i++)\n"
117 << " uint nextID = rootID + i;\n"
118 << " if (subgroupBallotBitExtract(mask, nextID) ^^ subgroupBallotBitExtract(result, nextID))\n"
120 << " tempResult = 0;\n"
128 bdy << " uint cluster[4] =\n"
130 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 0),\n"
131 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 1),\n"
132 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 2),\n"
133 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 3)\n"
135 << " uint rootID = gl_SubgroupInvocationID & ~0x3;\n"
136 << " for (uint i = 0; i < 4; i++)\n"
138 << " uint nextID = rootID + i;\n"
139 << " if (subgroupBallotBitExtract(mask, nextID) && (cluster[i] != nextID))\n"
141 << " tempResult = mask.x;\n"
146 if (SHADER_STAGE_VERTEX_BIT == caseDef.shaderStage)
148 std::ostringstream vertexSrc;
149 vertexSrc << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
151 << "layout(location = 0) in highp vec4 in_position;\n"
152 << "layout(location = 0) out float result;\n"
154 << "void main (void)\n"
157 << " result = float(tempResult);\n"
158 << " gl_Position = in_position;\n"
159 << " gl_PointSize = 1.0f;\n"
161 programCollection.add("vert") << glu::VertexSource(vertexSrc.str());
163 else if (SHADER_STAGE_GEOMETRY_BIT == caseDef.shaderStage)
165 std::ostringstream geometry;
167 geometry << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
169 << "layout(points) in;\n"
170 << "layout(points, max_vertices = 1) out;\n"
171 << "layout(location = 0) out float out_color;\n"
173 << "void main (void)\n"
176 << " out_color = float(tempResult);\n"
177 << " gl_Position = gl_in[0].gl_Position;\n"
178 << " EmitVertex();\n"
179 << " EndPrimitive();\n"
182 programCollection.add("geometry") << glu::GeometrySource(geometry.str());
184 else if (SHADER_STAGE_TESS_CONTROL_BIT == caseDef.shaderStage)
186 std::ostringstream controlSource;
188 controlSource << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
190 << "layout(vertices = 2) out;\n"
191 << "layout(location = 0) out float out_color[];\n"
193 << "void main (void)\n"
195 << " if (gl_InvocationID == 0)\n"
197 << " gl_TessLevelOuter[0] = 1.0f;\n"
198 << " gl_TessLevelOuter[1] = 1.0f;\n"
201 << " out_color[gl_InvocationID] = float(tempResult);\n"
202 << " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
205 programCollection.add("tesc") << glu::TessellationControlSource(controlSource.str());
206 subgroups::setTesEvalShaderFrameBuffer(programCollection);
208 else if (SHADER_STAGE_TESS_EVALUATION_BIT == caseDef.shaderStage)
210 std::ostringstream evaluationSource;
212 evaluationSource << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
214 << "layout(isolines, equal_spacing, ccw ) in;\n"
215 << "layout(location = 0) out float out_color;\n"
216 << "void main (void)\n"
219 << " out_color = float(tempResult);\n"
220 << " gl_Position = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);\n"
223 subgroups::setTesCtrlShaderFrameBuffer(programCollection);
224 programCollection.add("tese") << glu::TessellationEvaluationSource(evaluationSource.str());
228 DE_FATAL("Unsupported shader stage");
232 void initPrograms(SourceCollections& programCollection, CaseDefinition caseDef)
234 std::string extension = (OPTYPE_CLUSTERED == caseDef.opType) ?
235 "#extension GL_KHR_shader_subgroup_clustered: enable\n" :
236 "#extension GL_KHR_shader_subgroup_quad: enable\n";
238 extension += "#extension GL_KHR_shader_subgroup_ballot: enable\n";
240 std::ostringstream bdy;
242 bdy << " uint tempResult = 0x1;\n"
243 << " uvec4 mask = subgroupBallot(true);\n";
245 if (OPTYPE_CLUSTERED == caseDef.opType)
247 for (deUint32 i = 1; i <= subgroups::maxSupportedSubgroupSize(); i *= 2)
249 bdy << " if (gl_SubgroupSize >= " << i << ")\n"
251 << " uvec4 contribution = uvec4(0);\n"
252 << " const uint modID = gl_SubgroupInvocationID % 32;\n"
253 << " switch (gl_SubgroupInvocationID / 32)\n"
255 << " case 0: contribution.x = 1 << modID; break;\n"
256 << " case 1: contribution.y = 1 << modID; break;\n"
257 << " case 2: contribution.z = 1 << modID; break;\n"
258 << " case 3: contribution.w = 1 << modID; break;\n"
260 << " uvec4 result = subgroupClusteredOr(contribution, " << i << ");\n"
261 << " uint rootID = gl_SubgroupInvocationID & ~(" << i - 1 << ");\n"
262 << " for (uint i = 0; i < " << i << "; i++)\n"
264 << " uint nextID = rootID + i;\n"
265 << " if (subgroupBallotBitExtract(mask, nextID) ^^ subgroupBallotBitExtract(result, nextID))\n"
267 << " tempResult = 0;\n"
275 bdy << " uint cluster[4] =\n"
277 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 0),\n"
278 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 1),\n"
279 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 2),\n"
280 << " subgroupQuadBroadcast(gl_SubgroupInvocationID, 3)\n"
282 << " uint rootID = gl_SubgroupInvocationID & ~0x3;\n"
283 << " for (uint i = 0; i < 4; i++)\n"
285 << " uint nextID = rootID + i;\n"
286 << " if (subgroupBallotBitExtract(mask, nextID) && (cluster[i] != nextID))\n"
288 << " tempResult = mask.x;\n"
293 if (SHADER_STAGE_COMPUTE_BIT == caseDef.shaderStage)
295 std::ostringstream src;
297 src << "#version 450\n"
299 << "layout (${LOCAL_SIZE_X}, ${LOCAL_SIZE_Y}, ${LOCAL_SIZE_Z}) in;\n"
300 << "layout(binding = 0, std430) buffer Buffer0\n"
302 << " uint result[];\n"
305 << "void main (void)\n"
307 << " uvec3 globalSize = gl_NumWorkGroups * gl_WorkGroupSize;\n"
308 << " highp uint offset = globalSize.x * ((globalSize.y * "
309 "gl_GlobalInvocationID.z) + gl_GlobalInvocationID.y) + "
310 "gl_GlobalInvocationID.x;\n"
312 << " result[offset] = tempResult;\n"
315 programCollection.add("comp") << glu::ComputeSource(src.str());
320 const string vertex =
323 "layout(binding = 0, std430) buffer Buffer0\n"
331 " b0.result[gl_VertexID] = tempResult;\n"
332 " float pixelSize = 2.0f/1024.0f;\n"
333 " float pixelPosition = pixelSize/2.0f - 1.0f;\n"
334 " gl_Position = vec4(float(gl_VertexID) * pixelSize + pixelPosition, 0.0f, 0.0f, 1.0f);\n"
337 programCollection.add("vert") << glu::VertexSource(vertex);
344 "layout(vertices=1) out;\n"
345 "layout(binding = 1, std430) buffer Buffer1\n"
353 " b1.result[gl_PrimitiveID] = 1;\n"
354 " if (gl_InvocationID == 0)\n"
356 " gl_TessLevelOuter[0] = 1.0f;\n"
357 " gl_TessLevelOuter[1] = 1.0f;\n"
359 " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
362 programCollection.add("tesc") << glu::TessellationControlSource(tesc);
369 "layout(isolines) in;\n"
370 "layout(binding = 2, std430) buffer Buffer2\n"
378 " b2.result[gl_PrimitiveID * 2 + uint(gl_TessCoord.x + 0.5)] = 1;\n"
379 " float pixelSize = 2.0f/1024.0f;\n"
380 " gl_Position = gl_in[0].gl_Position + gl_TessCoord.x * pixelSize / 2.0f;\n"
383 programCollection.add("tese") << glu::TessellationEvaluationSource(tese);
387 const string geometry =
390 "layout(${TOPOLOGY}) in;\n"
391 "layout(points, max_vertices = 1) out;\n"
392 "layout(binding = 3, std430) buffer Buffer3\n"
400 " b3.result[gl_PrimitiveIDIn] = tempResult;\n"
401 " gl_Position = gl_in[0].gl_Position;\n"
406 subgroups::addGeometryShadersFromTemplate(geometry, programCollection);
410 const string fragment =
413 "layout(location = 0) out uint result;\n"
417 " result = tempResult;\n"
420 programCollection.add("fragment") << glu::FragmentSource(fragment);
422 subgroups::addNoSubgroupShader(programCollection);
426 void supportedCheck (Context& context, CaseDefinition caseDef)
428 if (!subgroups::isSubgroupSupported(context))
429 TCU_THROW(NotSupportedError, "Subgroup operations are not supported");
431 if (!subgroups::isSubgroupFeatureSupportedForDevice(context, SUBGROUP_FEATURE_BALLOT_BIT))
433 TCU_THROW(NotSupportedError, "Device does not support subgroup ballot operations");
436 if (OPTYPE_CLUSTERED == caseDef.opType)
438 if (!subgroups::isSubgroupFeatureSupportedForDevice(context, SUBGROUP_FEATURE_CLUSTERED_BIT))
440 TCU_THROW(NotSupportedError, "Subgroup shape tests require that clustered operations are supported!");
444 if (OPTYPE_QUAD == caseDef.opType)
446 if (!subgroups::isSubgroupFeatureSupportedForDevice(context, SUBGROUP_FEATURE_QUAD_BIT))
448 TCU_THROW(NotSupportedError, "Subgroup shape tests require that quad operations are supported!");
453 tcu::TestStatus noSSBOtest (Context& context, const CaseDefinition caseDef)
455 if (!subgroups::areSubgroupOperationsSupportedForStage(
456 context, caseDef.shaderStage))
458 if (subgroups::areSubgroupOperationsRequiredForStage(
459 caseDef.shaderStage))
461 return tcu::TestStatus::fail(
463 subgroups::getShaderStageName(caseDef.shaderStage) +
464 " is required to support subgroup operations!");
468 TCU_THROW(NotSupportedError, "Device does not support subgroup operations for this stage");
472 if (SHADER_STAGE_VERTEX_BIT == caseDef.shaderStage)
473 return subgroups::makeVertexFrameBufferTest(context, FORMAT_R32_UINT, DE_NULL, 0, checkVertexPipelineStages);
474 else if (SHADER_STAGE_GEOMETRY_BIT == caseDef.shaderStage)
475 return subgroups::makeGeometryFrameBufferTest(context, FORMAT_R32_UINT, DE_NULL, 0, checkVertexPipelineStages);
476 else if (SHADER_STAGE_TESS_CONTROL_BIT == caseDef.shaderStage)
477 return subgroups::makeTessellationEvaluationFrameBufferTest(context, FORMAT_R32_UINT, DE_NULL, 0, checkVertexPipelineStages, SHADER_STAGE_TESS_CONTROL_BIT);
478 else if (SHADER_STAGE_TESS_EVALUATION_BIT == caseDef.shaderStage)
479 return subgroups::makeTessellationEvaluationFrameBufferTest(context, FORMAT_R32_UINT, DE_NULL, 0, checkVertexPipelineStages, SHADER_STAGE_TESS_EVALUATION_BIT);
481 TCU_THROW(InternalError, "Unhandled shader stage");
485 tcu::TestStatus test(Context& context, const CaseDefinition caseDef)
487 if (!subgroups::isSubgroupFeatureSupportedForDevice(context, SUBGROUP_FEATURE_BASIC_BIT))
489 return tcu::TestStatus::fail(
490 "Subgroup feature " +
491 subgroups::getSubgroupFeatureName(SUBGROUP_FEATURE_BASIC_BIT) +
492 " is a required capability!");
495 if (SHADER_STAGE_COMPUTE_BIT == caseDef.shaderStage)
497 if (!subgroups::areSubgroupOperationsSupportedForStage(context, caseDef.shaderStage))
499 return tcu::TestStatus::fail(
501 subgroups::getShaderStageName(caseDef.shaderStage) +
502 " is required to support subgroup operations!");
504 return subgroups::makeComputeTest(context, FORMAT_R32_UINT, DE_NULL, 0, checkComputeStage);
508 int supportedStages = context.getDeqpContext().getContextInfo().getInt(GL_SUBGROUP_SUPPORTED_STAGES_KHR);
510 ShaderStageFlags stages = (ShaderStageFlags)(caseDef.shaderStage & supportedStages);
512 if (SHADER_STAGE_FRAGMENT_BIT != stages && !subgroups::isVertexSSBOSupportedForDevice(context))
514 if ( (stages & SHADER_STAGE_FRAGMENT_BIT) == 0)
515 TCU_THROW(NotSupportedError, "Device does not support vertex stage SSBO writes");
517 stages = SHADER_STAGE_FRAGMENT_BIT;
520 if ((ShaderStageFlags)0u == stages)
521 TCU_THROW(NotSupportedError, "Subgroup operations are not supported for any graphic shader");
523 return subgroups::allStages(context, FORMAT_R32_UINT, DE_NULL, 0, checkVertexPipelineStages, stages);
528 deqp::TestCaseGroup* createSubgroupsShapeTests(deqp::Context& testCtx)
530 de::MovePtr<deqp::TestCaseGroup> graphicGroup(new deqp::TestCaseGroup(
531 testCtx, "graphics", "Subgroup shape category tests: graphics"));
532 de::MovePtr<deqp::TestCaseGroup> computeGroup(new deqp::TestCaseGroup(
533 testCtx, "compute", "Subgroup shape category tests: compute"));
534 de::MovePtr<deqp::TestCaseGroup> framebufferGroup(new deqp::TestCaseGroup(
535 testCtx, "framebuffer", "Subgroup shape category tests: framebuffer"));
537 const ShaderStageFlags stages[] =
539 SHADER_STAGE_VERTEX_BIT,
540 SHADER_STAGE_TESS_EVALUATION_BIT,
541 SHADER_STAGE_TESS_CONTROL_BIT,
542 SHADER_STAGE_GEOMETRY_BIT,
545 for (int opTypeIndex = 0; opTypeIndex < OPTYPE_LAST; ++opTypeIndex)
547 const std::string op = de::toLower(getOpTypeName(opTypeIndex));
550 const CaseDefinition caseDef = {opTypeIndex, SHADER_STAGE_COMPUTE_BIT};
551 SubgroupFactory<CaseDefinition>::addFunctionCaseWithPrograms(computeGroup.get(), op, "", supportedCheck, initPrograms, test, caseDef);
556 const CaseDefinition caseDef =
559 SHADER_STAGE_ALL_GRAPHICS
561 SubgroupFactory<CaseDefinition>::addFunctionCaseWithPrograms(graphicGroup.get(),
563 supportedCheck, initPrograms, test, caseDef);
566 for (int stageIndex = 0; stageIndex < DE_LENGTH_OF_ARRAY(stages); ++stageIndex)
568 const CaseDefinition caseDef = {opTypeIndex, stages[stageIndex]};
569 SubgroupFactory<CaseDefinition>::addFunctionCaseWithPrograms(framebufferGroup.get(),op + "_" + getShaderStageName(caseDef.shaderStage), "",
570 supportedCheck, initFrameBufferPrograms, noSSBOtest, caseDef);
574 de::MovePtr<deqp::TestCaseGroup> group(new deqp::TestCaseGroup(
575 testCtx, "shape", "Subgroup shape category tests"));
577 group->addChild(graphicGroup.release());
578 group->addChild(computeGroup.release());
579 group->addChild(framebufferGroup.release());
581 return group.release();