1 /*------------------------------------------------------------------------ 2 * Vulkan Conformance Tests 3 * ------------------------ 4 * 5 * Copyright (c) 2014 The Android Open Source Project 6 * Copyright (c) 2016 The Khronos Group Inc. 7 * 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 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 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. 19 * 20 *//*! 21 * \file 22 * \brief Geometry Utilities 23 *//*--------------------------------------------------------------------*/ 24 25 #include "vktGeometryTestsUtil.hpp" 26 #include "vkTypeUtil.hpp" 27 #include "vkImageUtil.hpp" 28 #include "vkDefs.hpp" 29 #include "tcuImageCompare.hpp" 30 31 #include "tcuImageIO.hpp" 32 33 #include "deMath.h" 34 35 using namespace vk; 36 37 namespace vkt 38 { 39 namespace geometry 40 { 41 42 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setShader (const DeviceInterface& vk, 43 const VkDevice device, 44 const VkShaderStageFlagBits stage, 45 const ProgramBinary& binary, 46 const VkSpecializationInfo* specInfo) 47 { 48 VkShaderModule module; 49 switch (stage) 50 { 51 case (VK_SHADER_STAGE_VERTEX_BIT): 52 DE_ASSERT(m_vertexShaderModule.get() == DE_NULL); 53 m_vertexShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0); 54 module = *m_vertexShaderModule; 55 break; 56 57 case (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT): 58 DE_ASSERT(m_tessControlShaderModule.get() == DE_NULL); 59 m_tessControlShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0); 60 module = *m_tessControlShaderModule; 61 break; 62 63 case (VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT): 64 DE_ASSERT(m_tessEvaluationShaderModule.get() == DE_NULL); 65 m_tessEvaluationShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0); 66 module = *m_tessEvaluationShaderModule; 67 break; 68 69 case (VK_SHADER_STAGE_GEOMETRY_BIT): 70 DE_ASSERT(m_geometryShaderModule.get() == DE_NULL); 71 m_geometryShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0); 72 module = *m_geometryShaderModule; 73 break; 74 75 case (VK_SHADER_STAGE_FRAGMENT_BIT): 76 DE_ASSERT(m_fragmentShaderModule.get() == DE_NULL); 77 m_fragmentShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0); 78 module = *m_fragmentShaderModule; 79 break; 80 81 default: 82 DE_FATAL("Invalid shader stage"); 83 return *this; 84 } 85 86 const VkPipelineShaderStageCreateInfo pipelineShaderStageInfo = 87 { 88 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType; 89 DE_NULL, // const void* pNext; 90 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags; 91 stage, // VkShaderStageFlagBits stage; 92 module, // VkShaderModule module; 93 "main", // const char* pName; 94 specInfo, // const VkSpecializationInfo* pSpecializationInfo; 95 }; 96 97 m_shaderStageFlags |= stage; 98 m_shaderStages.push_back(pipelineShaderStageInfo); 99 100 return *this; 101 } 102 103 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setVertexInputSingleAttribute (const VkFormat vertexFormat, const deUint32 stride) 104 { 105 const VkVertexInputBindingDescription bindingDesc = 106 { 107 0u, // uint32_t binding; 108 stride, // uint32_t stride; 109 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate; 110 }; 111 const VkVertexInputAttributeDescription attributeDesc = 112 { 113 0u, // uint32_t location; 114 0u, // uint32_t binding; 115 vertexFormat, // VkFormat format; 116 0u, // uint32_t offset; 117 }; 118 119 m_vertexInputBindings.clear(); 120 m_vertexInputBindings.push_back(bindingDesc); 121 122 m_vertexInputAttributes.clear(); 123 m_vertexInputAttributes.push_back(attributeDesc); 124 125 return *this; 126 } 127 128 template<typename T> 129 inline const T* dataPointer (const std::vector<T>& vec) 130 { 131 return (vec.size() != 0 ? &vec[0] : DE_NULL); 132 } 133 134 Move<VkPipeline> GraphicsPipelineBuilder::build (const DeviceInterface& vk, 135 const VkDevice device, 136 const VkPipelineLayout pipelineLayout, 137 const VkRenderPass renderPass) 138 { 139 const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo = 140 { 141 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType; 142 DE_NULL, // const void* pNext; 143 (VkPipelineVertexInputStateCreateFlags)0, // VkPipelineVertexInputStateCreateFlags flags; 144 static_cast<deUint32>(m_vertexInputBindings.size()), // uint32_t vertexBindingDescriptionCount; 145 dataPointer(m_vertexInputBindings), // const VkVertexInputBindingDescription* pVertexBindingDescriptions; 146 static_cast<deUint32>(m_vertexInputAttributes.size()), // uint32_t vertexAttributeDescriptionCount; 147 dataPointer(m_vertexInputAttributes), // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions; 148 }; 149 150 const VkPrimitiveTopology topology = (m_shaderStageFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST 151 : m_primitiveTopology; 152 153 VkBool32 primitiveRestartEnable = VK_TRUE; 154 switch(m_primitiveTopology) 155 { 156 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: 157 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: 158 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: 159 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: 160 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: 161 case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: 162 primitiveRestartEnable = VK_FALSE; 163 break; 164 default: 165 break; 166 }; 167 168 const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo = 169 { 170 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType; 171 DE_NULL, // const void* pNext; 172 (VkPipelineInputAssemblyStateCreateFlags)0, // VkPipelineInputAssemblyStateCreateFlags flags; 173 topology, // VkPrimitiveTopology topology; 174 primitiveRestartEnable, // VkBool32 primitiveRestartEnable; 175 }; 176 177 const VkPipelineTessellationStateCreateInfo pipelineTessellationStateInfo = 178 { 179 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, // VkStructureType sType; 180 DE_NULL, // const void* pNext; 181 (VkPipelineTessellationStateCreateFlags)0, // VkPipelineTessellationStateCreateFlags flags; 182 m_patchControlPoints, // uint32_t patchControlPoints; 183 }; 184 185 const VkViewport viewport = makeViewport(m_renderSize); 186 const VkRect2D scissor = makeRect2D(m_renderSize); 187 188 const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo = 189 { 190 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType; 191 DE_NULL, // const void* pNext; 192 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags; 193 1u, // uint32_t viewportCount; 194 &viewport, // const VkViewport* pViewports; 195 1u, // uint32_t scissorCount; 196 &scissor, // const VkRect2D* pScissors; 197 }; 198 199 const bool isRasterizationDisabled = ((m_shaderStageFlags & VK_SHADER_STAGE_FRAGMENT_BIT) == 0); 200 const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo = 201 { 202 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType; 203 DE_NULL, // const void* pNext; 204 (VkPipelineRasterizationStateCreateFlags)0, // VkPipelineRasterizationStateCreateFlags flags; 205 VK_FALSE, // VkBool32 depthClampEnable; 206 isRasterizationDisabled, // VkBool32 rasterizerDiscardEnable; 207 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode; 208 m_cullModeFlags, // VkCullModeFlags cullMode; 209 m_frontFace, // VkFrontFace frontFace; 210 VK_FALSE, // VkBool32 depthBiasEnable; 211 0.0f, // float depthBiasConstantFactor; 212 0.0f, // float depthBiasClamp; 213 0.0f, // float depthBiasSlopeFactor; 214 1.0f, // float lineWidth; 215 }; 216 217 const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo = 218 { 219 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType; 220 DE_NULL, // const void* pNext; 221 (VkPipelineMultisampleStateCreateFlags)0, // VkPipelineMultisampleStateCreateFlags flags; 222 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples; 223 VK_FALSE, // VkBool32 sampleShadingEnable; 224 0.0f, // float minSampleShading; 225 DE_NULL, // const VkSampleMask* pSampleMask; 226 VK_FALSE, // VkBool32 alphaToCoverageEnable; 227 VK_FALSE // VkBool32 alphaToOneEnable; 228 }; 229 230 const VkStencilOpState stencilOpState = makeStencilOpState( 231 VK_STENCIL_OP_KEEP, // stencil fail 232 VK_STENCIL_OP_KEEP, // depth & stencil pass 233 VK_STENCIL_OP_KEEP, // depth only fail 234 VK_COMPARE_OP_NEVER, // compare op 235 0u, // compare mask 236 0u, // write mask 237 0u); // reference 238 239 const VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo = 240 { 241 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType; 242 DE_NULL, // const void* pNext; 243 (VkPipelineDepthStencilStateCreateFlags)0, // VkPipelineDepthStencilStateCreateFlags flags; 244 VK_FALSE, // VkBool32 depthTestEnable; 245 VK_FALSE, // VkBool32 depthWriteEnable; 246 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp; 247 VK_FALSE, // VkBool32 depthBoundsTestEnable; 248 VK_FALSE, // VkBool32 stencilTestEnable; 249 stencilOpState, // VkStencilOpState front; 250 stencilOpState, // VkStencilOpState back; 251 0.0f, // float minDepthBounds; 252 1.0f, // float maxDepthBounds; 253 }; 254 255 const VkColorComponentFlags colorComponentsAll = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; 256 const VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState = 257 { 258 m_blendEnable, // VkBool32 blendEnable; 259 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcColorBlendFactor; 260 VK_BLEND_FACTOR_ONE, // VkBlendFactor dstColorBlendFactor; 261 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp; 262 VK_BLEND_FACTOR_SRC_ALPHA, // VkBlendFactor srcAlphaBlendFactor; 263 VK_BLEND_FACTOR_ONE, // VkBlendFactor dstAlphaBlendFactor; 264 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp; 265 colorComponentsAll, // VkColorComponentFlags colorWriteMask; 266 }; 267 268 const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo = 269 { 270 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType; 271 DE_NULL, // const void* pNext; 272 (VkPipelineColorBlendStateCreateFlags)0, // VkPipelineColorBlendStateCreateFlags flags; 273 VK_FALSE, // VkBool32 logicOpEnable; 274 VK_LOGIC_OP_COPY, // VkLogicOp logicOp; 275 1u, // deUint32 attachmentCount; 276 &pipelineColorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments; 277 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConstants[4]; 278 }; 279 280 const VkGraphicsPipelineCreateInfo graphicsPipelineInfo = 281 { 282 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType; 283 DE_NULL, // const void* pNext; 284 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags; 285 static_cast<deUint32>(m_shaderStages.size()), // deUint32 stageCount; 286 &m_shaderStages[0], // const VkPipelineShaderStageCreateInfo* pStages; 287 &vertexInputStateInfo, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState; 288 &pipelineInputAssemblyStateInfo, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState; 289 (m_shaderStageFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT ? &pipelineTessellationStateInfo : DE_NULL), // const VkPipelineTessellationStateCreateInfo* pTessellationState; 290 (isRasterizationDisabled ? DE_NULL : &pipelineViewportStateInfo), // const VkPipelineViewportStateCreateInfo* pViewportState; 291 &pipelineRasterizationStateInfo, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState; 292 (isRasterizationDisabled ? DE_NULL : &pipelineMultisampleStateInfo), // const VkPipelineMultisampleStateCreateInfo* pMultisampleState; 293 (isRasterizationDisabled ? DE_NULL : &pipelineDepthStencilStateInfo), // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState; 294 (isRasterizationDisabled ? DE_NULL : &pipelineColorBlendStateInfo), // const VkPipelineColorBlendStateCreateInfo* pColorBlendState; 295 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState; 296 pipelineLayout, // VkPipelineLayout layout; 297 renderPass, // VkRenderPass renderPass; 298 0u, // deUint32 subpass; 299 DE_NULL, // VkPipeline basePipelineHandle; 300 0, // deInt32 basePipelineIndex; 301 }; 302 303 return createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo); 304 } 305 306 std::string inputTypeToGLString (const VkPrimitiveTopology& inputType) 307 { 308 switch (inputType) 309 { 310 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: 311 return "points"; 312 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: 313 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: 314 return "lines"; 315 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: 316 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: 317 return "lines_adjacency"; 318 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: 319 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: 320 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: 321 return "triangles"; 322 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: 323 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: 324 return "triangles_adjacency"; 325 default: 326 DE_ASSERT(DE_FALSE); 327 return "error"; 328 } 329 } 330 331 std::string outputTypeToGLString (const VkPrimitiveTopology& outputType) 332 { 333 switch (outputType) 334 { 335 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: 336 return "points"; 337 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: 338 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: 339 return "line_strip"; 340 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: 341 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: 342 return "triangle_strip"; 343 default: 344 DE_ASSERT(DE_FALSE); 345 return "error"; 346 } 347 } 348 349 size_t calcOutputVertices (const VkPrimitiveTopology& inputType) 350 { 351 switch (inputType) 352 { 353 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: 354 return 1 * 3; 355 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: 356 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: 357 return 2 * 3; 358 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: 359 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: 360 return 4 * 3; 361 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: 362 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: 363 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: 364 return 3 * 3; 365 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: 366 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: 367 return 6 * 3; 368 default: 369 DE_ASSERT(DE_FALSE); 370 return 0; 371 } 372 } 373 374 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize, 375 const VkBufferUsageFlags usage) 376 { 377 const VkBufferCreateInfo bufferCreateInfo = 378 { 379 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType; 380 DE_NULL, // const void* pNext; 381 (VkBufferCreateFlags)0, // VkBufferCreateFlags flags; 382 bufferSize, // VkDeviceSize size; 383 usage, // VkBufferUsageFlags usage; 384 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 385 0u, // deUint32 queueFamilyIndexCount; 386 DE_NULL, // const deUint32* pQueueFamilyIndices; 387 }; 388 return bufferCreateInfo; 389 } 390 391 VkImageCreateInfo makeImageCreateInfo (const tcu::IVec2& size, const VkFormat format, const VkImageUsageFlags usage, const deUint32 numArrayLayers) 392 { 393 const VkImageCreateInfo imageInfo = 394 { 395 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 396 DE_NULL, // const void* pNext; 397 (VkImageCreateFlags)0, // VkImageCreateFlags flags; 398 VK_IMAGE_TYPE_2D, // VkImageType imageType; 399 format, // VkFormat format; 400 makeExtent3D(size.x(), size.y(), 1), // VkExtent3D extent; 401 1u, // uint32_t mipLevels; 402 numArrayLayers, // uint32_t arrayLayers; 403 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 404 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 405 usage, // VkImageUsageFlags usage; 406 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 407 0u, // uint32_t queueFamilyIndexCount; 408 DE_NULL, // const uint32_t* pQueueFamilyIndices; 409 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 410 }; 411 return imageInfo; 412 } 413 414 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk, 415 const VkDevice device, 416 const VkDescriptorPool descriptorPool, 417 const VkDescriptorSetLayout setLayout) 418 { 419 const VkDescriptorSetAllocateInfo info = 420 { 421 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType; 422 DE_NULL, // const void* pNext; 423 descriptorPool, // VkDescriptorPool descriptorPool; 424 1u, // deUint32 descriptorSetCount; 425 &setLayout, // const VkDescriptorSetLayout* pSetLayouts; 426 }; 427 return allocateDescriptorSet(vk, device, &info); 428 } 429 430 Move<VkImageView> makeImageView (const DeviceInterface& vk, 431 const VkDevice vkDevice, 432 const VkImage image, 433 const VkImageViewType viewType, 434 const VkFormat format, 435 const VkImageSubresourceRange subresourceRange) 436 { 437 const VkImageViewCreateInfo imageViewParams = 438 { 439 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType; 440 DE_NULL, // const void* pNext; 441 (VkImageViewCreateFlags)0, // VkImageViewCreateFlags flags; 442 image, // VkImage image; 443 viewType, // VkImageViewType viewType; 444 format, // VkFormat format; 445 makeComponentMappingRGBA(), // VkComponentMapping components; 446 subresourceRange, // VkImageSubresourceRange subresourceRange; 447 }; 448 return createImageView(vk, vkDevice, &imageViewParams); 449 } 450 451 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent, 452 const VkImageSubresourceLayers subresourceLayers) 453 { 454 const VkBufferImageCopy copyParams = 455 { 456 0ull, // VkDeviceSize bufferOffset; 457 0u, // deUint32 bufferRowLength; 458 0u, // deUint32 bufferImageHeight; 459 subresourceLayers, // VkImageSubresourceLayers imageSubresource; 460 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset; 461 extent, // VkExtent3D imageExtent; 462 }; 463 return copyParams; 464 } 465 466 VkBufferImageCopy makeBufferImageCopy (const vk::VkDeviceSize& bufferOffset, 467 const vk::VkImageSubresourceLayers& imageSubresource, 468 const vk::VkOffset3D& imageOffset, 469 const vk::VkExtent3D& imageExtent) 470 { 471 const VkBufferImageCopy copyParams = 472 { 473 bufferOffset, // VkDeviceSize bufferOffset; 474 0u, // deUint32 bufferRowLength; 475 0u, // deUint32 bufferImageHeight; 476 imageSubresource, // VkImageSubresourceLayers imageSubresource; 477 imageOffset, // VkOffset3D imageOffset; 478 imageExtent, // VkExtent3D imageExtent; 479 }; 480 return copyParams; 481 } 482 483 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk, 484 const VkDevice device, 485 const VkDescriptorSetLayout descriptorSetLayout) 486 { 487 const VkPipelineLayoutCreateInfo info = 488 { 489 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType; 490 DE_NULL, // const void* pNext; 491 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags; 492 (descriptorSetLayout != DE_NULL ? 1u : 0u), // deUint32 setLayoutCount; 493 (descriptorSetLayout != DE_NULL ? &descriptorSetLayout : DE_NULL), // const VkDescriptorSetLayout* pSetLayouts; 494 0u, // deUint32 pushConstantRangeCount; 495 DE_NULL, // const VkPushConstantRange* pPushConstantRanges; 496 }; 497 return createPipelineLayout(vk, device, &info); 498 } 499 500 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk, 501 const VkDevice device, 502 const VkRenderPass renderPass, 503 const VkImageView colorAttachment, 504 const deUint32 width, 505 const deUint32 height, 506 const deUint32 layers) 507 { 508 const VkFramebufferCreateInfo framebufferInfo = { 509 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType; 510 DE_NULL, // const void* pNext; 511 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags; 512 renderPass, // VkRenderPass renderPass; 513 1u, // uint32_t attachmentCount; 514 &colorAttachment, // const VkImageView* pAttachments; 515 width, // uint32_t width; 516 height, // uint32_t height; 517 layers, // uint32_t layers; 518 }; 519 520 return createFramebuffer(vk, device, &framebufferInfo); 521 } 522 523 524 bool compareWithFileImage (Context& context, const tcu::ConstPixelBufferAccess& resultImage, std::string testName) 525 { 526 tcu::TextureLevel referenceImage; 527 std::string fileName="vulkan/data/geometry/"+testName+".png"; 528 tcu::ImageIO::loadPNG(referenceImage, context.getTestContext().getArchive(), fileName.c_str()); 529 530 if (tcu::fuzzyCompare(context.getTestContext().getLog(), "ImageComparison", "Image Comparison", 531 referenceImage.getAccess(), resultImage, 0.001f, tcu::COMPARE_LOG_RESULT)) 532 return tcu::intThresholdPositionDeviationCompare(context.getTestContext().getLog(), "ImageComparison", "Image Comparison", 533 referenceImage.getAccess(), resultImage, tcu::UVec4(1u, 1u, 1u, 1u), tcu::IVec3(2,2,2), false, tcu::COMPARE_LOG_RESULT); 534 else 535 return false; 536 } 537 538 de::MovePtr<Allocation> bindImage (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkImage image, const MemoryRequirement requirement) 539 { 540 de::MovePtr<Allocation> alloc = allocator.allocate(getImageMemoryRequirements(vk, device, image), requirement); 541 VK_CHECK(vk.bindImageMemory(device, image, alloc->getMemory(), alloc->getOffset())); 542 return alloc; 543 } 544 545 de::MovePtr<Allocation> bindBuffer (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkBuffer buffer, const MemoryRequirement requirement) 546 { 547 de::MovePtr<Allocation> alloc(allocator.allocate(getBufferMemoryRequirements(vk, device, buffer), requirement)); 548 VK_CHECK(vk.bindBufferMemory(device, buffer, alloc->getMemory(), alloc->getOffset())); 549 return alloc; 550 } 551 552 void zeroBuffer (const DeviceInterface& vk, const VkDevice device, const Allocation& alloc, const VkDeviceSize size) 553 { 554 deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(size)); 555 flushMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset(), size); 556 } 557 558 void fillBuffer (const DeviceInterface& vk, const VkDevice device, const Allocation& alloc, const VkDeviceSize offset, const VkDeviceSize size, const VkFormat format, const tcu::Vec4& color) 559 { 560 const tcu::TextureFormat textureFormat = mapVkFormat(format); 561 const deUint32 colorPixelSize = static_cast<deUint32>(tcu::getPixelSize(textureFormat)); 562 tcu::TextureLevel colorPixelBuffer (textureFormat, 1, 1); 563 tcu::PixelBufferAccess colorPixel (colorPixelBuffer); 564 565 colorPixel.setPixel(color, 0, 0); 566 567 const deUint8* src = static_cast<deUint8*>(colorPixel.getDataPtr()); 568 deUint8* dstBase = static_cast<deUint8*>(alloc.getHostPtr()); 569 deUint8* dst = &dstBase[offset]; 570 571 for (deUint32 pixelPos = 0; pixelPos < size; pixelPos += colorPixelSize) 572 deMemcpy(&dst[pixelPos], src, colorPixelSize); 573 574 flushMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset() + offset, size); 575 } 576 577 void fillBuffer (const DeviceInterface& vk, const VkDevice device, const Allocation& alloc, const VkDeviceSize offset, const VkDeviceSize size, const VkFormat format, const float depth) 578 { 579 const tcu::TextureFormat textureFormat = mapVkFormat(format); 580 const deUint32 colorPixelSize = static_cast<deUint32>(tcu::getPixelSize(textureFormat)); 581 tcu::TextureLevel colorPixelBuffer (textureFormat, 1, 1); 582 tcu::PixelBufferAccess colorPixel (colorPixelBuffer); 583 584 colorPixel.setPixDepth(depth, 0, 0); 585 586 const deUint8* src = static_cast<deUint8*>(colorPixel.getDataPtr()); 587 deUint8* dstBase = static_cast<deUint8*>(alloc.getHostPtr()); 588 deUint8* dst = &dstBase[offset]; 589 590 for (deUint32 pixelPos = 0; pixelPos < size; pixelPos += colorPixelSize) 591 deMemcpy(&dst[pixelPos], src, colorPixelSize); 592 593 flushMappedMemoryRange(vk, device, alloc.getMemory(), alloc.getOffset() + offset, size); 594 } 595 596 VkBool32 checkPointSize (const InstanceInterface& vki, const VkPhysicalDevice physDevice) 597 { 598 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures (vki, physDevice); 599 return features.shaderTessellationAndGeometryPointSize; 600 } 601 602 void checkGeometryShaderSupport (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const int numGeometryShaderInvocations) 603 { 604 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures (vki, physDevice); 605 const VkPhysicalDeviceLimits limits = getPhysicalDeviceProperties(vki, physDevice).limits; 606 607 if (!features.geometryShader) 608 TCU_THROW(NotSupportedError, "Missing feature: geometryShader"); 609 610 if (numGeometryShaderInvocations != 0 && limits.maxGeometryShaderInvocations < static_cast<deUint32>(numGeometryShaderInvocations)) 611 TCU_THROW(NotSupportedError, ("Unsupported limit: maxGeometryShaderInvocations < " + de::toString(numGeometryShaderInvocations)).c_str()); 612 } 613 614 } //geometry 615 } //vkt 616