1 #ifndef _VKTSUBGROUPSTESTSUTILS_HPP 2 #define _VKTSUBGROUPSTESTSUTILS_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2017 The Khronos Group Inc. 8 * Copyright (c) 2017 Codeplay Software Ltd. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 */ /*! 23 * \file 24 * \brief Subgroups tests utility classes 25 */ /*--------------------------------------------------------------------*/ 26 27 #include "vkBuilderUtil.hpp" 28 #include "vkDefs.hpp" 29 #include "vkDeviceUtil.hpp" 30 #include "vkMemUtil.hpp" 31 #include "vkPlatform.hpp" 32 #include "vkPrograms.hpp" 33 #include "vkQueryUtil.hpp" 34 #include "vkRef.hpp" 35 #include "vkRefUtil.hpp" 36 #include "vkStrUtil.hpp" 37 #include "vkTypeUtil.hpp" 38 #include "vktTestCase.hpp" 39 #include "vktTestCaseUtil.hpp" 40 #include "vkRayTracingUtil.hpp" 41 42 #include "tcuFormatUtil.hpp" 43 #include "tcuTestLog.hpp" 44 #include "tcuVectorUtil.hpp" 45 46 #include "gluShaderUtil.hpp" 47 48 #include "deSharedPtr.hpp" 49 #include "deUniquePtr.hpp" 50 51 #include <string> 52 #include <vector> 53 54 namespace vkt 55 { 56 namespace subgroups 57 { 58 typedef bool (*CheckResult)(const void* internalData, std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize); 59 typedef bool (*CheckResultFragment)(const void* internalData, std::vector<const void*> datas, deUint32 width, deUint32 height, deUint32 subgroupSize); 60 typedef bool (*CheckResultCompute)(const void* internalData, std::vector<const void*> datas, const deUint32 numWorkgroups[3], const deUint32 localSize[3], deUint32 subgroupSize); 61 62 // A struct to represent input data to a shader 63 struct SSBOData 64 { 65 enum InputDataInitializeType 66 { 67 InitializeNone = 0, 68 InitializeNonZero, 69 InitializeZero, 70 }; 71 enum InputDataLayoutType 72 { 73 LayoutStd140 = 0, 74 LayoutStd430, 75 LayoutPacked 76 }; 77 78 enum BindingType 79 { 80 BindingSSBO, 81 BindingImage, 82 BindingUBO, 83 }; 84 SSBODatavkt::subgroups::SSBOData85 SSBOData() : 86 initializeType (InitializeNone), 87 layout (LayoutStd140), 88 format (vk::VK_FORMAT_UNDEFINED), 89 numElements (0), 90 bindingType (BindingSSBO), 91 binding (0u), 92 stages ((vk::VkShaderStageFlags)0u) 93 {} 94 SSBODatavkt::subgroups::SSBOData95 SSBOData (InputDataInitializeType initializeType_, 96 InputDataLayoutType layout_, 97 vk::VkFormat format_, 98 vk::VkDeviceSize numElements_, 99 BindingType bindingType_ = BindingSSBO, 100 deUint32 binding_ = 0u, 101 vk::VkShaderStageFlags stages_ = static_cast<vk::VkShaderStageFlags>(0u)) 102 : initializeType (initializeType_) 103 , layout (layout_) 104 , format (format_) 105 , numElements (numElements_) 106 , bindingType (bindingType_) 107 , binding (binding_) 108 , stages (stages_) 109 { 110 if (bindingType == BindingUBO) 111 DE_ASSERT(layout == LayoutStd140); 112 } 113 isImagevkt::subgroups::SSBOData114 bool isImage () const 115 { 116 return (bindingType == BindingImage); 117 } 118 isUBOvkt::subgroups::SSBOData119 bool isUBO () const 120 { 121 return (bindingType == BindingUBO); 122 } 123 124 InputDataInitializeType initializeType; 125 InputDataLayoutType layout; 126 vk::VkFormat format; 127 vk::VkDeviceSize numElements; 128 BindingType bindingType; 129 deUint32 binding; 130 vk::VkShaderStageFlags stages; 131 }; 132 133 deUint32 getStagesCount (vk::VkShaderStageFlags shaderStages); 134 135 std::string getSharedMemoryBallotHelper (); 136 137 std::string getSharedMemoryBallotHelperARB (); 138 139 deUint32 getSubgroupSize (Context& context); 140 141 deUint32 maxSupportedSubgroupSize (); 142 143 std::string getShaderStageName (vk::VkShaderStageFlags stage); 144 145 std::string getSubgroupFeatureName (vk::VkSubgroupFeatureFlagBits bit); 146 147 void addNoSubgroupShader (vk::SourceCollections& programCollection); 148 149 void initStdFrameBufferPrograms (vk::SourceCollections& programCollection, 150 const vk::ShaderBuildOptions& buildOptions, 151 vk::VkShaderStageFlags shaderStage, 152 vk::VkFormat format, 153 bool gsPointSize, 154 const std::string& extHeader, 155 const std::string& testSrc, 156 const std::string& helperStr, 157 const std::vector<std::string>& declarations = std::vector<std::string>()); 158 159 void initStdPrograms (vk::SourceCollections& programCollection, 160 const vk::ShaderBuildOptions& buildOptions, 161 vk::VkShaderStageFlags shaderStage, 162 vk::VkFormat format, 163 bool gsPointSize, 164 const std::string& extHeader, 165 const std::string& testSrc, 166 const std::string& helperStr, 167 const std::vector<std::string>& declarations = std::vector<std::string>(), 168 const bool avoidHelperInvocations = false, 169 const std::string& tempRes = " uint tempRes;\n"); 170 171 bool isSubgroupSupported (Context& context); 172 173 bool areSubgroupOperationsSupportedForStage (Context& context, vk::VkShaderStageFlags stage); 174 175 bool isSubgroupFeatureSupportedForDevice (Context& context, vk::VkSubgroupFeatureFlagBits bit); 176 177 bool areQuadOperationsSupportedForStages (Context& context, const vk::VkShaderStageFlags stages); 178 179 bool isFragmentSSBOSupportedForDevice (Context& context); 180 181 bool isVertexSSBOSupportedForDevice (Context& context); 182 183 bool isFormatSupportedForDevice (Context& context, vk::VkFormat format); 184 185 bool isInt64SupportedForDevice (Context& context); 186 187 bool isTessellationAndGeometryPointSizeSupported (Context& context); 188 189 bool is16BitUBOStorageSupported (Context& context); 190 191 bool is8BitUBOStorageSupported (Context& context); 192 193 bool isSubgroupBroadcastDynamicIdSupported (Context& context); 194 195 std::string getFormatNameForGLSL (vk::VkFormat format); 196 197 std::string getAdditionalExtensionForFormat (vk::VkFormat format); 198 199 const std::vector<vk::VkFormat> getAllFormats (); 200 201 bool isFormatSigned (vk::VkFormat format); 202 bool isFormatUnsigned (vk::VkFormat format); 203 bool isFormatFloat (vk::VkFormat format); 204 bool isFormatBool (vk::VkFormat format); 205 bool isFormat8bitTy (vk::VkFormat format); 206 bool isFormat16BitTy (vk::VkFormat format); 207 208 void addGeometryShadersFromTemplate (const std::string& glslTemplate, const vk::ShaderBuildOptions& options, vk::GlslSourceCollection& collection); 209 void addGeometryShadersFromTemplate (const std::string& spirvTemplate, const vk::SpirVAsmBuildOptions& options, vk::SpirVAsmCollection& collection); 210 211 void setVertexShaderFrameBuffer (vk::SourceCollections& programCollection); 212 213 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection); 214 215 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection); 216 217 void setTesCtrlShaderFrameBuffer (vk::SourceCollections& programCollection); 218 219 void setTesEvalShaderFrameBuffer (vk::SourceCollections& programCollection); 220 221 bool check (std::vector<const void*> datas, deUint32 width, deUint32 ref); 222 223 bool checkComputeOrMesh (std::vector<const void*> datas, 224 const deUint32 numWorkgroups[3], 225 const deUint32 localSize[3], 226 deUint32 ref); 227 228 tcu::TestStatus makeTessellationEvaluationFrameBufferTest (Context& context, 229 vk::VkFormat format, 230 const SSBOData* extraData, 231 deUint32 extraDataCount, 232 const void* internalData, 233 CheckResult checkResult, 234 const vk::VkShaderStageFlags shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS); 235 236 tcu::TestStatus makeGeometryFrameBufferTest (Context& context, 237 vk::VkFormat format, 238 const SSBOData* extraData, 239 deUint32 extraDataCount, 240 const void* internalData, 241 CheckResult checkResult); 242 243 // Allows using verification functions with or without the optional last boolean argument. 244 // If using a function that does not need the last argument, it will not be passed down to it. 245 class VerificationFunctor 246 { 247 public: 248 using NoLastArgVariant = bool(*)(const void*, std::vector<const void*>, deUint32, deUint32); 249 using AllArgsVariant = bool(*)(const void*, std::vector<const void*>, deUint32, deUint32, bool); 250 VerificationFunctor(NoLastArgVariant func)251 VerificationFunctor (NoLastArgVariant func) 252 : m_noLastArgFunc{func}, m_allArgsFunc{nullptr} 253 {} 254 VerificationFunctor(AllArgsVariant func)255 VerificationFunctor (AllArgsVariant func) 256 : m_noLastArgFunc{nullptr}, m_allArgsFunc{func} 257 {} 258 operator ()(const void * extraData,std::vector<const void * > datas,deUint32 width,deUint32 subgroupSize,bool multipleCallsPossible) const259 bool operator() (const void* extraData, std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize, bool multipleCallsPossible) const 260 { 261 if (m_allArgsFunc) 262 return m_allArgsFunc(extraData, datas, width, subgroupSize, multipleCallsPossible); 263 return m_noLastArgFunc(extraData, datas, width, subgroupSize); 264 } 265 266 private: 267 NoLastArgVariant m_noLastArgFunc; 268 AllArgsVariant m_allArgsFunc; 269 }; 270 271 vk::VkShaderStageFlags getPossibleGraphicsSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages); 272 273 tcu::TestStatus allStages (Context& context, 274 vk::VkFormat format, 275 const SSBOData* extraData, 276 deUint32 extraDataCount, 277 const void* internalData, 278 const VerificationFunctor& checkResult, 279 const vk::VkShaderStageFlags shaderStage); 280 281 tcu::TestStatus makeVertexFrameBufferTest (Context& context, 282 vk::VkFormat format, 283 const SSBOData* extraData, 284 deUint32 extraDataCount, 285 const void* internalData, 286 CheckResult checkResult); 287 288 tcu::TestStatus makeFragmentFrameBufferTest (Context& context, 289 vk::VkFormat format, 290 const SSBOData* extraData, 291 deUint32 extraDataCount, 292 const void* internalData, 293 CheckResultFragment checkResult); 294 295 tcu::TestStatus makeComputeTest (Context& context, 296 vk::VkFormat format, 297 const SSBOData* inputs, 298 deUint32 inputsCount, 299 const void* internalData, 300 CheckResultCompute checkResult, 301 deUint32 requiredSubgroupSize = 0u, 302 const deUint32 pipelineShaderStageCreateFlags = 0u); 303 304 tcu::TestStatus makeMeshTest (Context& context, 305 vk::VkFormat format, 306 const SSBOData* inputs, 307 deUint32 inputsCount, 308 const void* internalData, 309 CheckResultCompute checkResult, 310 deUint32 requiredSubgroupSize = 0u, 311 const deUint32 pipelineShaderStageCreateFlags = 0u); 312 313 /* Functions needed for VK_EXT_subgroup_size_control tests */ 314 tcu::TestStatus makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize (Context& context, 315 vk::VkFormat format, 316 const SSBOData* extraData, 317 deUint32 extraDataCount, 318 const void* internalData, 319 CheckResult checkResult, 320 const vk::VkShaderStageFlags shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS, 321 const deUint32 tessShaderStageCreateFlags = 0u, 322 const deUint32 requiredSubgroupSize = 0u); 323 324 tcu::TestStatus makeGeometryFrameBufferTestRequiredSubgroupSize (Context& context, 325 vk::VkFormat format, 326 const SSBOData* extraData, 327 deUint32 extraDataCount, 328 const void* internalData, 329 CheckResult checkResult, 330 const deUint32 geometryShaderStageCreateFlags = 0u, 331 const deUint32 requiredSubgroupSize = 0u); 332 333 tcu::TestStatus allStagesRequiredSubgroupSize (Context& context, 334 vk::VkFormat format, 335 const SSBOData* extraDatas, 336 deUint32 extraDatasCount, 337 const void* internalData, 338 const VerificationFunctor& checkResult, 339 const vk::VkShaderStageFlags shaderStageTested, 340 const deUint32 vertexShaderStageCreateFlags, 341 const deUint32 tessellationControlShaderStageCreateFlags, 342 const deUint32 tessellationEvalShaderStageCreateFlags, 343 const deUint32 geometryShaderStageCreateFlags, 344 const deUint32 fragmentShaderStageCreateFlags, 345 const deUint32 requiredSubgroupSize[5]); 346 347 tcu::TestStatus makeVertexFrameBufferTestRequiredSubgroupSize (Context& context, 348 vk::VkFormat format, 349 const SSBOData* extraData, 350 deUint32 extraDataCount, 351 const void* internalData, 352 CheckResult checkResult, 353 const deUint32 vertexShaderStageCreateFlags = 0u, 354 const deUint32 requiredSubgroupSize = 0u); 355 356 tcu::TestStatus makeFragmentFrameBufferTestRequiredSubgroupSize (Context& context, 357 vk::VkFormat format, 358 const SSBOData* extraData, 359 deUint32 extraDataCount, 360 const void* internalData, 361 CheckResultFragment checkResult, 362 const deUint32 fragmentShaderStageCreateFlags = 0u, 363 const deUint32 requiredSubgroupSize = 0u); 364 365 tcu::TestStatus makeComputeTestRequiredSubgroupSize (Context& context, 366 vk::VkFormat format, 367 const SSBOData* inputs, 368 deUint32 inputsCount, 369 const void* internalData, 370 CheckResultCompute checkResult, 371 const deUint32 pipelineShaderStageCreateFlags, 372 const deUint32 numWorkgroups[3], 373 const deBool isRequiredSubgroupSize, 374 const deUint32 subgroupSize, 375 const deUint32 localSizesToTest[][3], 376 const deUint32 localSizesToTestCount); 377 378 tcu::TestStatus makeMeshTestRequiredSubgroupSize (Context& context, 379 vk::VkFormat format, 380 const SSBOData* inputs, 381 deUint32 inputsCount, 382 const void* internalData, 383 CheckResultCompute checkResult, 384 const deUint32 pipelineShaderStageCreateFlags, 385 const deUint32 numWorkgroups[3], 386 const deBool isRequiredSubgroupSize, 387 const deUint32 subgroupSize, 388 const deUint32 localSizesToTest[][3], 389 const deUint32 localSizesToTestCount); 390 391 void supportedCheckShader (Context& context, const vk::VkShaderStageFlags shaderStage); 392 393 const std::vector<vk::VkFormat> getAllRayTracingFormats(); 394 395 void addRayTracingNoSubgroupShader (vk::SourceCollections& programCollection); 396 397 vk::VkShaderStageFlags getPossibleRayTracingSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages); 398 399 tcu::TestStatus allRayTracingStages (Context& context, 400 vk::VkFormat format, 401 const SSBOData* extraData, 402 deUint32 extraDataCount, 403 const void* internalData, 404 const VerificationFunctor& checkResult, 405 const vk::VkShaderStageFlags shaderStage); 406 407 tcu::TestStatus allRayTracingStagesRequiredSubgroupSize (Context& context, 408 vk::VkFormat format, 409 const SSBOData* extraDatas, 410 deUint32 extraDatasCount, 411 const void* internalData, 412 const VerificationFunctor& checkResult, 413 const vk::VkShaderStageFlags shaderStageTested, 414 const deUint32 shaderStageCreateFlags[6], 415 const deUint32 requiredSubgroupSize[6]); 416 } // subgroups 417 } // vkt 418 419 #endif // _VKTSUBGROUPSTESTSUTILS_HPP 420