1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2019 The Khronos Group Inc.
6 * Copyright (c) 2019 Valve Corporation.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief VK_EXT_subgroup_size_control Tests
23 */ /*--------------------------------------------------------------------*/
25 #include "vktSubgroupsSizeControlTests.hpp"
26 #include "vktSubgroupsTestsUtils.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "tcuTestLog.hpp"
41 enum RequiredSubgroupSizeMode
43 REQUIRED_SUBGROUP_SIZE_NONE = 0,
44 REQUIRED_SUBGROUP_SIZE_MIN = 1,
45 REQUIRED_SUBGROUP_SIZE_MAX = 2,
50 deUint32 pipelineShaderStageCreateFlags;
51 VkShaderStageFlags shaderStage;
52 deBool requiresBallot;
53 deUint32 requiredSubgroupSizeMode;
54 de::SharedPtr<bool> geometryPointSizeSupported;
57 struct internalDataStruct
59 const Context* context;
60 struct CaseDefinition caseDef;
61 deUint32 requiredSubgroupSize;
64 // Find greatest common divisor for a and b
65 deUint32 gcd (deUint32 a, deUint32 b)
67 if ((0 != a) && (0 == b))
73 deUint32 greater = max(a, b);
74 deUint32 lesser = min(a, b);
76 return gcd(lesser, greater % lesser);
80 UVec3 getLocalSizes (const VkPhysicalDeviceProperties& physicalDeviceProperties,
81 deUint32 numWorkGroupInvocations)
83 DE_ASSERT(numWorkGroupInvocations <= physicalDeviceProperties.limits.maxComputeWorkGroupInvocations);
84 const deUint32 localSizeX = gcd(numWorkGroupInvocations, physicalDeviceProperties.limits.maxComputeWorkGroupSize[0]);
85 const deUint32 localSizeY = gcd(deMax32(numWorkGroupInvocations / localSizeX, 1u), physicalDeviceProperties.limits.maxComputeWorkGroupSize[1]);
86 const deUint32 localSizeZ = deMax32(numWorkGroupInvocations / (localSizeX * localSizeY), 1u);
88 return UVec3(localSizeX, localSizeY, localSizeZ);
91 deUint32 getRequiredSubgroupSizeFromMode (Context& context,
92 const CaseDefinition& caseDef,
93 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties)
95 switch (caseDef.requiredSubgroupSizeMode)
97 case REQUIRED_SUBGROUP_SIZE_MAX: return subgroupSizeControlProperties.maxSubgroupSize;
98 case REQUIRED_SUBGROUP_SIZE_MIN: return subgroupSizeControlProperties.minSubgroupSize;
99 case REQUIRED_SUBGROUP_SIZE_NONE: return subgroups::getSubgroupSize(context);
100 default: TCU_THROW(NotSupportedError, "Unsupported Subgroup size");
104 static bool checkVertexPipelineStages (const void* internalData,
105 vector<const void*> datas,
109 const struct internalDataStruct* checkInternalData = reinterpret_cast<const struct internalDataStruct *>(internalData);
110 const Context* context = checkInternalData->context;
111 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context->getSubgroupSizeControlPropertiesEXT();
112 TestLog& log = context->getTestContext().getLog();
113 const deUint32* data = reinterpret_cast<const deUint32*>(datas[0]);
115 for (deUint32 i = 0; i < width; i++)
117 if (data[i] > subgroupSizeControlProperties.maxSubgroupSize ||
118 data[i] < subgroupSizeControlProperties.minSubgroupSize)
120 log << TestLog::Message << "gl_SubgroupSize (" << data[i] << ") value is outside limits (" << subgroupSizeControlProperties.minSubgroupSize << ", " << subgroupSizeControlProperties.maxSubgroupSize << ")" << TestLog::EndMessage;
125 if (checkInternalData->caseDef.requiredSubgroupSizeMode != REQUIRED_SUBGROUP_SIZE_NONE && data[i] != checkInternalData->requiredSubgroupSize)
127 log << TestLog::Message << "gl_SubgroupSize (" << data[i] << ") is not equal to the required subgroup size value (" << checkInternalData->requiredSubgroupSize << ")" << TestLog::EndMessage;
136 static bool checkFragmentPipelineStages (const void* internalData,
137 vector<const void*> datas,
142 const struct internalDataStruct* checkInternalData = reinterpret_cast<const struct internalDataStruct *>(internalData);
143 const Context* context = checkInternalData->context;
144 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context->getSubgroupSizeControlPropertiesEXT();
145 TestLog& log = context->getTestContext().getLog();
146 const deUint32* data = reinterpret_cast<const deUint32*>(datas[0]);
148 for (deUint32 x = 0u; x < width; ++x)
150 for (deUint32 y = 0u; y < height; ++y)
152 const deUint32 ndx = (x * height + y);
154 if (data[ndx] > subgroupSizeControlProperties.maxSubgroupSize ||
155 data[ndx] < subgroupSizeControlProperties.minSubgroupSize)
157 log << TestLog::Message << "gl_SubgroupSize (" << data[ndx] << ") value is outside limits (" << subgroupSizeControlProperties.minSubgroupSize << ", " << subgroupSizeControlProperties.maxSubgroupSize << ")" << TestLog::EndMessage;
162 if (checkInternalData->caseDef.requiredSubgroupSizeMode != REQUIRED_SUBGROUP_SIZE_NONE &&
163 data[ndx] != checkInternalData->requiredSubgroupSize)
165 log << TestLog::Message << "gl_SubgroupSize (" << data[ndx] << ") is not equal to the required subgroup size value (" << checkInternalData->requiredSubgroupSize << ")" << TestLog::EndMessage;
174 static bool checkCompute (const void* internalData,
175 vector<const void*> datas,
176 const deUint32 numWorkgroups[3],
177 const deUint32 localSize[3],
180 const struct internalDataStruct* checkInternalData = reinterpret_cast<const struct internalDataStruct *>(internalData);
181 const Context* context = checkInternalData->context;
182 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context->getSubgroupSizeControlPropertiesEXT();
183 TestLog& log = context->getTestContext().getLog();
184 const deUint32 globalSizeX = numWorkgroups[0] * localSize[0];
185 const deUint32 globalSizeY = numWorkgroups[1] * localSize[1];
186 const deUint32 globalSizeZ = numWorkgroups[2] * localSize[2];
187 const deUint32 width = globalSizeX * globalSizeY * globalSizeZ;
188 const deUint32* data = reinterpret_cast<const deUint32*>(datas[0]);
190 for (deUint32 i = 0; i < width; i++)
192 if (data[i] > subgroupSizeControlProperties.maxSubgroupSize ||
193 data[i] < subgroupSizeControlProperties.minSubgroupSize)
195 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
196 << "gl_SubgroupSize (" << data[i] << ") value is outside limits (" << subgroupSizeControlProperties.minSubgroupSize << ", " << subgroupSizeControlProperties.maxSubgroupSize << ")" << TestLog::EndMessage;
201 if (checkInternalData->caseDef.requiredSubgroupSizeMode != REQUIRED_SUBGROUP_SIZE_NONE &&
202 data[i] != checkInternalData->requiredSubgroupSize)
204 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
205 << "gl_SubgroupSize (" << data[i] << ") is not equal to the required subgroup size value (" << checkInternalData->requiredSubgroupSize << ")" << TestLog::EndMessage;
214 static bool checkComputeRequireFull (const void* internalData,
215 vector<const void*> datas,
216 const deUint32 numWorkgroups[3],
217 const deUint32 localSize[3],
220 const struct internalDataStruct* checkInternalData = reinterpret_cast<const struct internalDataStruct *>(internalData);
221 const Context* context = checkInternalData->context;
222 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context->getSubgroupSizeControlPropertiesEXT();
223 TestLog& log = context->getTestContext().getLog();
224 const deUint32 globalSizeX = numWorkgroups[0] * localSize[0];
225 const deUint32 globalSizeY = numWorkgroups[1] * localSize[1];
226 const deUint32 globalSizeZ = numWorkgroups[2] * localSize[2];
227 const deUint32 width = globalSizeX * globalSizeY * globalSizeZ;
228 const UVec4* data = reinterpret_cast<const UVec4*>(datas[0]);
229 const deUint32 numSubgroups = (localSize[0] * localSize[1] * localSize[2]) / checkInternalData->requiredSubgroupSize;
231 for (deUint32 i = 0; i < width; i++)
233 if (data[i].x() > subgroupSizeControlProperties.maxSubgroupSize ||
234 data[i].x() < subgroupSizeControlProperties.minSubgroupSize)
236 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
237 << "gl_SubgroupSize value ( " << data[i].x() << ") is outside limits [" << subgroupSizeControlProperties.minSubgroupSize << ", " << subgroupSizeControlProperties.maxSubgroupSize << "]" << TestLog::EndMessage;
241 if (data[i].x() != data[i].y())
243 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
244 << "gl_SubgroupSize ( " << data[i].x() << ") does not match the active number of subgroup invocations (" << data[i].y() << ")" << TestLog::EndMessage;
248 if (checkInternalData->caseDef.pipelineShaderStageCreateFlags == VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT &&
249 data[i].x() != checkInternalData->requiredSubgroupSize)
251 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
252 << "expected subgroupSize (" << checkInternalData->requiredSubgroupSize << ") doesn't match gl_SubgroupSize ( " << data[i].x() << ")" << TestLog::EndMessage;
256 if (checkInternalData->caseDef.pipelineShaderStageCreateFlags == VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT && data[i].z() != numSubgroups)
258 log << TestLog::Message << "[" << localSize[0] << ", " << localSize[1] << ", " << localSize[2] << "] "
259 << "expected number of subgroups dispatched (" << numSubgroups << ") doesn't match gl_NumSubgroups (" << data[i].z() << ")" << TestLog::EndMessage;
267 void initFrameBufferPrograms (SourceCollections& programCollection, CaseDefinition caseDef)
269 const ShaderBuildOptions buildOptions (programCollection.usedVulkanVersion, SPIRV_VERSION_1_3, 0u);
271 if (VK_SHADER_STAGE_FRAGMENT_BIT != caseDef.shaderStage)
272 subgroups::setFragmentShaderFrameBuffer(programCollection);
274 if (VK_SHADER_STAGE_VERTEX_BIT != caseDef.shaderStage && VK_SHADER_STAGE_FRAGMENT_BIT != caseDef.shaderStage)
275 subgroups::setVertexShaderFrameBuffer(programCollection);
277 string bdyStr = "uint tempResult = gl_SubgroupSize;\n";
279 if (VK_SHADER_STAGE_VERTEX_BIT == caseDef.shaderStage)
281 ostringstream vertex;
283 vertex << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
284 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
285 << "layout(location = 0) in highp vec4 in_position;\n"
286 << "layout(location = 0) out float out_color;\n"
288 << "void main (void)\n"
291 << " out_color = float(tempResult);\n"
292 << " gl_Position = in_position;\n"
293 << " gl_PointSize = 1.0f;\n"
296 programCollection.glslSources.add("vert") << glu::VertexSource(vertex.str()) << buildOptions;
298 else if (VK_SHADER_STAGE_GEOMETRY_BIT == caseDef.shaderStage)
300 ostringstream geometry;
302 geometry << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
303 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
304 << "layout(points) in;\n"
305 << "layout(points, max_vertices = 1) out;\n"
306 << "layout(location = 0) out float out_color;\n"
307 << "void main (void)\n"
310 << " out_color = float(tempResult);\n"
311 << " gl_Position = gl_in[0].gl_Position;\n"
312 << " gl_PointSize = 1.0f;"
313 << " EmitVertex();\n"
314 << " EndPrimitive();\n"
317 programCollection.glslSources.add("geometry") << glu::GeometrySource(geometry.str()) << buildOptions;
319 else if (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT == caseDef.shaderStage)
321 ostringstream controlSource;
323 controlSource << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
324 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
325 << "layout(vertices = 2) out;\n"
326 << "layout(location = 0) out float out_color[];\n"
328 << "void main (void)\n"
330 << " if (gl_InvocationID == 0)\n"
332 << " gl_TessLevelOuter[0] = 1.0f;\n"
333 << " gl_TessLevelOuter[1] = 1.0f;\n"
336 << " out_color[gl_InvocationID ] = float(tempResult);\n"
337 << " gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;\n"
340 programCollection.glslSources.add("tesc") << glu::TessellationControlSource(controlSource.str()) << buildOptions;
341 subgroups::setTesEvalShaderFrameBuffer(programCollection);
343 else if (VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT == caseDef.shaderStage)
345 ostringstream evaluationSource;
346 evaluationSource << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
347 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
348 << "layout(isolines, equal_spacing, ccw ) in;\n"
349 << "layout(location = 0) out float out_color;\n"
350 << "void main (void)\n"
353 << " out_color = float(tempResult);\n"
354 << " gl_Position = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);\n"
357 subgroups::setTesCtrlShaderFrameBuffer(programCollection);
358 programCollection.glslSources.add("tese") << glu::TessellationEvaluationSource(evaluationSource.str()) << buildOptions;
360 else if (VK_SHADER_STAGE_FRAGMENT_BIT == caseDef.shaderStage)
362 const string vertex = string(glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)) + "\n"
365 " vec2 uv = vec2(float(gl_VertexIndex & 1), float((gl_VertexIndex >> 1) & 1));\n"
366 " gl_Position = vec4(uv * 4.0f -2.0f, 0.0f, 1.0f);\n"
367 " gl_PointSize = 1.0f;\n"
369 programCollection.glslSources.add("vert") << glu::VertexSource(vertex) << buildOptions;
371 ostringstream fragmentSource;
373 fragmentSource << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450)<<"\n"
374 << "precision highp int;\n"
375 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
376 << "layout(location = 0) out uint out_color;\n"
380 << " out_color = tempResult;\n"
383 programCollection.glslSources.add("fragment") << glu::FragmentSource(fragmentSource.str()) << buildOptions;
387 DE_FATAL("Unsupported shader stage");
391 string getExtHeader (const CaseDefinition&)
393 return "#extension GL_KHR_shader_subgroup_basic: enable\n";
396 vector<string> getPerStageHeadDeclarations (const CaseDefinition& caseDef)
398 const deUint32 stageCount = subgroups::getStagesCount(caseDef.shaderStage);
399 const bool fragment = (caseDef.shaderStage & VK_SHADER_STAGE_FRAGMENT_BIT) != 0;
400 vector<string> result (stageCount, string());
403 result.reserve(result.size() + 1);
405 for (size_t i = 0; i < result.size(); ++i)
408 "layout(set = 0, binding = " + de::toString(i) + ", std430) buffer Buffer1\n"
416 const string fragPart =
417 "layout(location = 0) out uint result;\n";
419 result.push_back(fragPart);
425 string getTestSource (const CaseDefinition&)
428 " uint tempResult = gl_SubgroupSize;\n"
429 " tempRes = tempResult;\n";
432 void initPrograms (SourceCollections& programCollection, CaseDefinition caseDef)
434 const SpirvVersion spirvVersion = isAllRayTracingStages(caseDef.shaderStage) ? SPIRV_VERSION_1_4 : SPIRV_VERSION_1_3;
435 const ShaderBuildOptions buildOptions (programCollection.usedVulkanVersion, spirvVersion, 0u);
436 const string extHeader = getExtHeader(caseDef);
437 const string testSrc = getTestSource(caseDef);
438 const vector<string> headDeclarations = getPerStageHeadDeclarations(caseDef);
440 subgroups::initStdPrograms(programCollection, buildOptions, caseDef.shaderStage, VK_FORMAT_R32_UINT, *caseDef.geometryPointSizeSupported, extHeader, testSrc, "", headDeclarations);
443 void initProgramsRequireFull (SourceCollections& programCollection, CaseDefinition caseDef)
445 if (VK_SHADER_STAGE_COMPUTE_BIT != caseDef.shaderStage)
446 DE_FATAL("Unsupported shader stage");
450 src << "#version 450\n"
451 << "#extension GL_KHR_shader_subgroup_basic: enable\n"
452 << "#extension GL_KHR_shader_subgroup_ballot: enable\n"
453 << "layout (local_size_x_id = 0, local_size_y_id = 1, "
454 "local_size_z_id = 2) in;\n"
455 << "layout(set = 0, binding = 0, std430) buffer Buffer1\n"
457 << " uvec4 result[];\n"
460 << "void main (void)\n"
462 << " uvec3 globalSize = gl_NumWorkGroups * gl_WorkGroupSize;\n"
463 << " highp uint offset = globalSize.x * ((globalSize.y * "
464 "gl_GlobalInvocationID.z) + gl_GlobalInvocationID.y) + "
465 "gl_GlobalInvocationID.x;\n"
466 << " result[offset].x = gl_SubgroupSize;" // save the subgroup size value
467 << " uint numActive = subgroupBallotBitCount(subgroupBallot(true));\n"
468 << " result[offset].y = numActive;\n" // save the number of active subgroup invocations
469 << " result[offset].z = gl_NumSubgroups;" // save the number of subgroups dispatched.
472 programCollection.glslSources.add("comp") << glu::ComputeSource(src.str()) << ShaderBuildOptions(programCollection.usedVulkanVersion, SPIRV_VERSION_1_3, 0u);
475 void supportedCheck (Context& context)
477 if (!subgroups::isSubgroupSupported(context))
478 TCU_THROW(NotSupportedError, "Subgroup operations are not supported");
480 context.requireDeviceFunctionality("VK_EXT_subgroup_size_control");
483 void supportedCheckFeatures (Context& context, CaseDefinition caseDef)
485 supportedCheck(context);
487 if (!subgroups::areSubgroupOperationsSupportedForStage(context, caseDef.shaderStage))
489 TCU_THROW(NotSupportedError, "Shader stage is required to support subgroup operations!");
492 if (caseDef.shaderStage == VK_SHADER_STAGE_ALL_GRAPHICS)
494 const VkPhysicalDeviceFeatures& features = context.getDeviceFeatures();
496 if (!features.tessellationShader || !features.geometryShader)
497 TCU_THROW(NotSupportedError, "Device does not support tessellation or geometry shaders");
500 if (caseDef.requiresBallot && !subgroups::isSubgroupFeatureSupportedForDevice(context, VK_SUBGROUP_FEATURE_BALLOT_BIT))
502 TCU_THROW(NotSupportedError, "Device does not support subgroup ballot operations");
505 if (caseDef.requiredSubgroupSizeMode != REQUIRED_SUBGROUP_SIZE_NONE ||
506 caseDef.pipelineShaderStageCreateFlags == VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT)
508 const VkPhysicalDeviceSubgroupSizeControlFeaturesEXT& subgroupSizeControlFeatures = context.getSubgroupSizeControlFeaturesEXT();
510 if (subgroupSizeControlFeatures.subgroupSizeControl == DE_FALSE)
511 TCU_THROW(NotSupportedError, "Device does not support varying subgroup sizes nor required subgroup size");
513 if (caseDef.requiredSubgroupSizeMode != REQUIRED_SUBGROUP_SIZE_NONE)
515 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
517 if ((subgroupSizeControlProperties.requiredSubgroupSizeStages & caseDef.shaderStage) != caseDef.shaderStage)
518 TCU_THROW(NotSupportedError, "Device does not support setting required subgroup size for the stages selected");
522 if (caseDef.pipelineShaderStageCreateFlags == VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT)
524 const VkPhysicalDeviceSubgroupSizeControlFeaturesEXT& subgroupSizeControlFeatures = context.getSubgroupSizeControlFeaturesEXT();
526 if (subgroupSizeControlFeatures.computeFullSubgroups == DE_FALSE)
527 TCU_THROW(NotSupportedError, "Device does not support full subgroups in compute shaders");
530 *caseDef.geometryPointSizeSupported = subgroups::isTessellationAndGeometryPointSizeSupported(context);
532 if (isAllRayTracingStages(caseDef.shaderStage))
534 context.requireDeviceFunctionality("VK_KHR_ray_tracing_pipeline");
538 void supportedCheckFeaturesShader (Context& context, CaseDefinition caseDef)
540 supportedCheckFeatures(context, caseDef);
542 subgroups::supportedCheckShader(context, caseDef.shaderStage);
545 TestStatus noSSBOtest (Context& context, const CaseDefinition caseDef)
547 const VkFormat format = VK_FORMAT_R32_UINT;
548 const deUint32& flags = caseDef.pipelineShaderStageCreateFlags;
549 const struct internalDataStruct internalData =
556 switch (caseDef.shaderStage)
558 case VK_SHADER_STAGE_VERTEX_BIT: return subgroups::makeVertexFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, flags, 0u);
559 case VK_SHADER_STAGE_GEOMETRY_BIT: return subgroups::makeGeometryFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, flags, 0u);
560 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: return subgroups::makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, caseDef.shaderStage, flags, 0u);
561 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: return subgroups::makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, caseDef.shaderStage, flags, 0u);
562 case VK_SHADER_STAGE_FRAGMENT_BIT: return subgroups::makeFragmentFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkFragmentPipelineStages, flags, 0u);
563 default: TCU_THROW(InternalError, "Unhandled shader stage");
567 TestStatus test (Context& context, const CaseDefinition caseDef)
569 if (isAllComputeStages(caseDef.shaderStage))
571 const deUint32 numWorkgroups[3] = {1, 1, 1};
572 const deUint32 subgroupSize = subgroups::getSubgroupSize(context);
573 const VkPhysicalDeviceProperties physicalDeviceProperties = context.getDeviceProperties();
574 // Calculate the local workgroup sizes to exercise the maximum supported by the driver
575 const UVec3 localSize = getLocalSizes(physicalDeviceProperties, physicalDeviceProperties.limits.maxComputeWorkGroupInvocations);
576 const deUint32 localSizesToTestCount = 16;
577 const deUint32 localSizesToTest[localSizesToTestCount][3] =
586 {subgroupSize, 1, 1},
587 {1, subgroupSize, 1},
588 {1, 1, subgroupSize},
593 {localSize.x(), localSize.y(), localSize.z()},
594 {1, 1, 1} // Isn't used, just here to make double buffering checks easier
596 const struct internalDataStruct internalData =
603 return subgroups::makeComputeTestRequiredSubgroupSize(context,
609 caseDef.pipelineShaderStageCreateFlags,
614 localSizesToTestCount);
616 else if (isAllGraphicsStages(caseDef.shaderStage))
618 const VkShaderStageFlags stages = subgroups::getPossibleGraphicsSubgroupStages(context, caseDef.shaderStage);
619 struct internalDataStruct internalData =
626 return subgroups::allStagesRequiredSubgroupSize(context,
631 checkVertexPipelineStages,
633 caseDef.pipelineShaderStageCreateFlags,
634 caseDef.pipelineShaderStageCreateFlags,
635 caseDef.pipelineShaderStageCreateFlags,
636 caseDef.pipelineShaderStageCreateFlags,
637 caseDef.pipelineShaderStageCreateFlags,
640 else if (isAllRayTracingStages(caseDef.shaderStage))
642 const VkShaderStageFlags stages = subgroups::getPossibleRayTracingSubgroupStages(context, caseDef.shaderStage);
643 const vector<deUint32> flags (6, caseDef.pipelineShaderStageCreateFlags);
644 const struct internalDataStruct internalData =
651 return subgroups::allRayTracingStagesRequiredSubgroupSize(context,
656 checkVertexPipelineStages,
662 TCU_THROW(InternalError, "Unknown stage or invalid stage set");
665 TestStatus testRequireFullSubgroups (Context& context, const CaseDefinition caseDef)
667 DE_ASSERT(VK_SHADER_STAGE_COMPUTE_BIT == caseDef.shaderStage);
668 DE_ASSERT(caseDef.requiredSubgroupSizeMode == REQUIRED_SUBGROUP_SIZE_NONE);
670 const deUint32 numWorkgroups[3] = {1, 1, 1};
671 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
672 const VkPhysicalDeviceProperties& physicalDeviceProperties = context.getDeviceProperties();
673 // Calculate the local workgroup sizes to exercise the maximum supported by the driver
674 const UVec3 localSize = getLocalSizes(physicalDeviceProperties, physicalDeviceProperties.limits.maxComputeWorkGroupInvocations);
675 const deUint32 subgroupSize = subgroups::getSubgroupSize(context);
676 // For full subgroups and allow varying subgroup size, localsize X must be a multiple of maxSubgroupSize.
677 // We set local size X for this test to the maximum, regardless if allow varying subgroup size is enabled or not.
678 const deUint32 localSizesToTestCount = 7;
679 const deUint32 localSizesToTest[localSizesToTestCount][3] =
681 {subgroupSizeControlProperties.maxSubgroupSize, 1, 1},
682 {subgroupSizeControlProperties.maxSubgroupSize, 4, 1},
683 {subgroupSizeControlProperties.maxSubgroupSize, 1, 4},
684 {subgroupSizeControlProperties.maxSubgroupSize * 2, 1, 2},
685 {subgroupSizeControlProperties.maxSubgroupSize * 4, 1, 1},
686 {localSize.x(), localSize.y(), localSize.z()},
687 {1, 1, 1} // Isn't used, just here to make double buffering checks easier
689 const struct internalDataStruct internalData =
696 return subgroups::makeComputeTestRequiredSubgroupSize(context,
697 VK_FORMAT_R32G32B32A32_UINT,
701 checkComputeRequireFull,
702 caseDef.pipelineShaderStageCreateFlags,
707 localSizesToTestCount);
710 TestStatus testRequireSubgroupSize (Context& context, const CaseDefinition caseDef)
712 if (isAllComputeStages(caseDef.shaderStage))
714 const deUint32 numWorkgroups[3] = {1, 1, 1};
715 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
716 const VkPhysicalDeviceProperties& physicalDeviceProperties = context.getDeviceProperties();
717 const deUint32 requiredSubgroupSize = getRequiredSubgroupSizeFromMode(context, caseDef, subgroupSizeControlProperties);
718 const deUint64 maxSubgroupLimitSize = (deUint64)requiredSubgroupSize * subgroupSizeControlProperties.maxComputeWorkgroupSubgroups;
719 const deUint32 maxTotalLocalSize = (deUint32)min<deUint64>(maxSubgroupLimitSize, physicalDeviceProperties.limits.maxComputeWorkGroupInvocations);
720 const UVec3 localSize = getLocalSizes(physicalDeviceProperties, maxTotalLocalSize);
721 const deUint32 localSizesToTest[5][3] =
723 {localSize.x(), localSize.y(), localSize.z()},
724 {requiredSubgroupSize, 1, 1},
725 {1, requiredSubgroupSize, 1},
726 {1, 1, requiredSubgroupSize},
727 {1, 1, 1} // Isn't used, just here to make double buffering checks easier
730 deUint32 localSizesToTestCount = 5;
731 if (caseDef.pipelineShaderStageCreateFlags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT)
732 localSizesToTestCount = 3;
734 struct internalDataStruct internalData =
736 &context, // const Context* context;
737 caseDef, // struct CaseDefinition caseDef;
738 requiredSubgroupSize, // deUint32 requiredSubgroupSize;
741 // Depending on the flag we need to run one verification function or another.
742 return subgroups::makeComputeTestRequiredSubgroupSize(context,
743 VK_FORMAT_R32G32B32A32_UINT,
747 caseDef.pipelineShaderStageCreateFlags == VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT ? checkComputeRequireFull : checkCompute,
748 caseDef.pipelineShaderStageCreateFlags,
751 requiredSubgroupSize,
753 localSizesToTestCount);
755 else if (isAllGraphicsStages(caseDef.shaderStage))
757 const VkShaderStageFlags stages = subgroups::getPossibleGraphicsSubgroupStages(context, caseDef.shaderStage);
758 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
759 const deUint32 requiredSubgroupSize = getRequiredSubgroupSizeFromMode(context, caseDef, subgroupSizeControlProperties);
760 const deUint32 requiredSubgroupSizes[5] = { requiredSubgroupSize, requiredSubgroupSize, requiredSubgroupSize, requiredSubgroupSize, requiredSubgroupSize};
761 const struct internalDataStruct internalData =
763 &context, // const Context* context;
764 caseDef, // struct CaseDefinition caseDef;
765 requiredSubgroupSize, // deUint32 requiredSubgroupSize;
768 return subgroups::allStagesRequiredSubgroupSize(context,
773 checkVertexPipelineStages,
775 caseDef.pipelineShaderStageCreateFlags,
776 caseDef.pipelineShaderStageCreateFlags,
777 caseDef.pipelineShaderStageCreateFlags,
778 caseDef.pipelineShaderStageCreateFlags,
779 caseDef.pipelineShaderStageCreateFlags,
780 requiredSubgroupSizes);
782 else if (isAllRayTracingStages(caseDef.shaderStage))
784 const VkShaderStageFlags stages = subgroups::getPossibleRayTracingSubgroupStages(context, caseDef.shaderStage);
785 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
786 const deUint32 requiredSubgroupSize = getRequiredSubgroupSizeFromMode(context, caseDef, subgroupSizeControlProperties);
787 const vector<deUint32> flags (6, caseDef.pipelineShaderStageCreateFlags);
788 const vector<deUint32> requiredSubgroupSizes (6, requiredSubgroupSize);
789 const struct internalDataStruct internalData =
791 &context, // const Context* context;
792 caseDef, // struct CaseDefinition caseDef;
793 requiredSubgroupSize, // deUint32 requiredSubgroupSize;
796 return subgroups::allRayTracingStagesRequiredSubgroupSize(context,
801 checkVertexPipelineStages,
804 requiredSubgroupSizes.data());
807 TCU_THROW(InternalError, "Unknown stage or invalid stage set");
810 TestStatus noSSBOtestRequireSubgroupSize (Context& context, const CaseDefinition caseDef)
812 const VkPhysicalDeviceSubgroupSizeControlPropertiesEXT& subgroupSizeControlProperties = context.getSubgroupSizeControlPropertiesEXT();
813 const deUint32 requiredSubgroupSize = getRequiredSubgroupSizeFromMode(context, caseDef, subgroupSizeControlProperties);
814 const VkFormat format = VK_FORMAT_R32_UINT;
815 const deUint32& flags = caseDef.pipelineShaderStageCreateFlags;
816 const deUint32& size = requiredSubgroupSize;
817 struct internalDataStruct internalData =
821 requiredSubgroupSize,
824 switch (caseDef.shaderStage)
826 case VK_SHADER_STAGE_VERTEX_BIT: return subgroups::makeVertexFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, flags, size);
827 case VK_SHADER_STAGE_GEOMETRY_BIT: return subgroups::makeGeometryFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, flags, size);
828 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: return subgroups::makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, caseDef.shaderStage, flags, size);
829 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: return subgroups::makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkVertexPipelineStages, caseDef.shaderStage, flags, size);
830 case VK_SHADER_STAGE_FRAGMENT_BIT: return subgroups::makeFragmentFrameBufferTestRequiredSubgroupSize(context, format, DE_NULL, 0, &internalData, checkFragmentPipelineStages, flags, size);
831 default: TCU_THROW(InternalError, "Unhandled shader stage");
835 TestStatus testSanitySubgroupSizeProperties (Context& context)
837 VkPhysicalDeviceSubgroupSizeControlPropertiesEXT subgroupSizeControlProperties;
838 subgroupSizeControlProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT;
839 subgroupSizeControlProperties.pNext = DE_NULL;
841 VkPhysicalDeviceSubgroupProperties subgroupProperties;
842 subgroupProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
843 subgroupProperties.pNext = &subgroupSizeControlProperties;
845 VkPhysicalDeviceProperties2 properties;
846 properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
847 properties.pNext = &subgroupProperties;
849 context.getInstanceInterface().getPhysicalDeviceProperties2(context.getPhysicalDevice(), &properties);
851 if (subgroupProperties.subgroupSize > subgroupSizeControlProperties.maxSubgroupSize ||
852 subgroupProperties.subgroupSize < subgroupSizeControlProperties.minSubgroupSize)
855 error << "subgroupSize (" << subgroupProperties.subgroupSize << ") is not between maxSubgroupSize (";
856 error << subgroupSizeControlProperties.maxSubgroupSize << ") and minSubgroupSize (";
857 error << subgroupSizeControlProperties.minSubgroupSize << ")";
859 return TestStatus::fail(error.str().c_str());
862 return TestStatus::pass("OK");
870 TestCaseGroup* createSubgroupsSizeControlTests (TestContext& testCtx)
872 de::MovePtr<TestCaseGroup> group (new TestCaseGroup(testCtx, "size_control", "VK_EXT_subgroup_size_control tests"));
873 de::MovePtr<TestCaseGroup> framebufferGroup (new TestCaseGroup(testCtx, "framebuffer", "Subgroup size control category tests: framebuffer"));
874 de::MovePtr<TestCaseGroup> computeGroup (new TestCaseGroup(testCtx, "compute", "Subgroup size control category tests: compute"));
875 de::MovePtr<TestCaseGroup> graphicsGroup (new TestCaseGroup(testCtx, "graphics", "Subgroup size control category tests: graphics"));
876 de::MovePtr<TestCaseGroup> raytracingGroup (new TestCaseGroup(testCtx, "ray_tracing", "Subgroup size control category tests: ray tracing"));
877 de::MovePtr<TestCaseGroup> genericGroup (new TestCaseGroup(testCtx, "generic", "Subgroup size control category tests: generic"));
878 const VkShaderStageFlags stages[] =
880 VK_SHADER_STAGE_VERTEX_BIT,
881 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
882 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
883 VK_SHADER_STAGE_GEOMETRY_BIT,
884 VK_SHADER_STAGE_FRAGMENT_BIT,
887 // Test sanity of the subgroup size properties.
889 addFunctionCase(genericGroup.get(), "subgroup_size_properties", "", supportedCheck, testSanitySubgroupSizeProperties);
892 // Allow varying subgroup case.
894 const CaseDefinition caseDefCompute = {VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, VK_SHADER_STAGE_COMPUTE_BIT, DE_FALSE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
895 addFunctionCaseWithPrograms(computeGroup.get(), "allow_varying_subgroup_size", "", supportedCheckFeatures, initPrograms, test, caseDefCompute);
896 const CaseDefinition caseDefAllGraphics = {VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, VK_SHADER_STAGE_ALL_GRAPHICS, DE_FALSE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
897 addFunctionCaseWithPrograms(graphicsGroup.get(), "allow_varying_subgroup_size", "", supportedCheckFeaturesShader, initPrograms, test, caseDefAllGraphics);
898 const CaseDefinition caseDefAllRaytracing = {VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, SHADER_STAGE_ALL_RAY_TRACING, DE_FALSE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
899 addFunctionCaseWithPrograms(raytracingGroup.get(), "allow_varying_subgroup_size", "", supportedCheckFeaturesShader, initPrograms, test, caseDefAllRaytracing);
901 for (int stageIndex = 0; stageIndex < DE_LENGTH_OF_ARRAY(stages); ++stageIndex)
903 const CaseDefinition caseDefStage = {VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, stages[stageIndex], DE_FALSE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
904 addFunctionCaseWithPrograms(framebufferGroup.get(), getShaderStageName(caseDefStage.shaderStage) + "_allow_varying_subgroup_size", "", supportedCheckFeaturesShader, initFrameBufferPrograms, noSSBOtest, caseDefStage);
908 // Require full subgroups case (only compute shaders).
910 const CaseDefinition caseDef = {VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT, VK_SHADER_STAGE_COMPUTE_BIT, DE_TRUE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
911 addFunctionCaseWithPrograms(computeGroup.get(), "require_full_subgroups", "", supportedCheckFeatures, initProgramsRequireFull, testRequireFullSubgroups, caseDef);
914 // Require full subgroups together with allow varying subgroup (only compute shaders).
916 deUint32 flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT | VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT;
917 const CaseDefinition caseDef = {flags, VK_SHADER_STAGE_COMPUTE_BIT, DE_TRUE, REQUIRED_SUBGROUP_SIZE_NONE, de::SharedPtr<bool>(new bool)};
918 addFunctionCaseWithPrograms(computeGroup.get(), "require_full_subgroups_allow_varying_subgroup_size", "", supportedCheckFeatures, initProgramsRequireFull, testRequireFullSubgroups, caseDef);
921 // Tests to check setting a required subgroup size value.
923 const CaseDefinition caseDefAllGraphicsMax = {0u, VK_SHADER_STAGE_ALL_GRAPHICS, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MAX, de::SharedPtr<bool>(new bool)};
924 addFunctionCaseWithPrograms(graphicsGroup.get(), "required_subgroup_size_max", "", supportedCheckFeaturesShader, initPrograms, testRequireSubgroupSize, caseDefAllGraphicsMax);
925 const CaseDefinition caseDefComputeMax = {0u, VK_SHADER_STAGE_COMPUTE_BIT, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MAX, de::SharedPtr<bool>(new bool)};
926 addFunctionCaseWithPrograms(computeGroup.get(), "required_subgroup_size_max", "", supportedCheckFeatures, initPrograms, testRequireSubgroupSize, caseDefComputeMax);
927 const CaseDefinition caseDefAllRaytracingMax = {0u, SHADER_STAGE_ALL_RAY_TRACING, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MAX, de::SharedPtr<bool>(new bool)};
928 addFunctionCaseWithPrograms(raytracingGroup.get(), "required_subgroup_size_max", "", supportedCheckFeaturesShader, initPrograms, testRequireSubgroupSize, caseDefAllRaytracingMax);
930 const CaseDefinition caseDefAllGraphicsMin = {0u, VK_SHADER_STAGE_ALL_GRAPHICS, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MIN, de::SharedPtr<bool>(new bool)};
931 addFunctionCaseWithPrograms(graphicsGroup.get(), "required_subgroup_size_min", "", supportedCheckFeaturesShader, initPrograms, testRequireSubgroupSize, caseDefAllGraphicsMin);
932 const CaseDefinition caseDefComputeMin = {0u, VK_SHADER_STAGE_COMPUTE_BIT, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MIN, de::SharedPtr<bool>(new bool)};
933 addFunctionCaseWithPrograms(computeGroup.get(), "required_subgroup_size_min", "", supportedCheckFeatures, initPrograms, testRequireSubgroupSize, caseDefComputeMin);
934 const CaseDefinition caseDefAllRaytracingMin = {0u, SHADER_STAGE_ALL_RAY_TRACING, DE_FALSE, REQUIRED_SUBGROUP_SIZE_MIN, de::SharedPtr<bool>(new bool)};
935 addFunctionCaseWithPrograms(raytracingGroup.get(), "required_subgroup_size_min", "", supportedCheckFeaturesShader, initPrograms, testRequireSubgroupSize, caseDefAllRaytracingMin);
936 for (int stageIndex = 0; stageIndex < DE_LENGTH_OF_ARRAY(stages); ++stageIndex)
938 const CaseDefinition caseDefStageMax = {0u, stages[stageIndex], DE_FALSE, REQUIRED_SUBGROUP_SIZE_MAX, de::SharedPtr<bool>(new bool)};
939 addFunctionCaseWithPrograms(framebufferGroup.get(), getShaderStageName(caseDefStageMax.shaderStage) + "_required_subgroup_size_max", "", supportedCheckFeaturesShader, initFrameBufferPrograms, noSSBOtestRequireSubgroupSize, caseDefStageMax);
940 const CaseDefinition caseDefStageMin = {0u, stages[stageIndex], DE_FALSE, REQUIRED_SUBGROUP_SIZE_MIN, de::SharedPtr<bool>(new bool)};
941 addFunctionCaseWithPrograms(framebufferGroup.get(), getShaderStageName(caseDefStageMin.shaderStage) + "_required_subgroup_size_min", "", supportedCheckFeaturesShader, initFrameBufferPrograms, noSSBOtestRequireSubgroupSize, caseDefStageMin);
945 // Tests to check setting a required subgroup size value, together with require full subgroups (only compute shaders).
947 deUint32 flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT;
948 const CaseDefinition caseDefMax = {flags, VK_SHADER_STAGE_COMPUTE_BIT, DE_TRUE, REQUIRED_SUBGROUP_SIZE_MAX, de::SharedPtr<bool>(new bool)};
949 addFunctionCaseWithPrograms(computeGroup.get(), "required_subgroup_size_max_require_full_subgroups", "", supportedCheckFeatures, initProgramsRequireFull, testRequireSubgroupSize, caseDefMax);
950 const CaseDefinition caseDefMin = {flags, VK_SHADER_STAGE_COMPUTE_BIT, DE_TRUE, REQUIRED_SUBGROUP_SIZE_MIN, de::SharedPtr<bool>(new bool)};
951 addFunctionCaseWithPrograms(computeGroup.get(), "required_subgroup_size_min_require_full_subgroups", "", supportedCheckFeatures, initProgramsRequireFull, testRequireSubgroupSize, caseDefMin);
954 group->addChild(genericGroup.release());
955 group->addChild(graphicsGroup.release());
956 group->addChild(computeGroup.release());
957 group->addChild(framebufferGroup.release());
958 group->addChild(raytracingGroup.release());
960 return group.release();