1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
34 *//*--------------------------------------------------------------------*/
36 #include "vktPipelineDepthTests.hpp"
37 #include "vktPipelineClearUtil.hpp"
38 #include "vktPipelineImageUtil.hpp"
39 #include "vktPipelineVertexUtil.hpp"
40 #include "vktPipelineReferenceRenderer.hpp"
41 #include "vktTestCase.hpp"
42 #include "vktTestCaseUtil.hpp"
43 #include "vkImageUtil.hpp"
44 #include "vkMemUtil.hpp"
45 #include "vkPrograms.hpp"
46 #include "vkQueryUtil.hpp"
48 #include "vkRefUtil.hpp"
49 #include "tcuImageCompare.hpp"
50 #include "deUniquePtr.hpp"
51 #include "deStringUtil.hpp"
67 bool isSupportedDepthStencilFormat (const InstanceInterface& instanceInterface, VkPhysicalDevice device, VkFormat format)
69 VkFormatProperties formatProps;
71 instanceInterface.getPhysicalDeviceFormatProperties(device, format, &formatProps);
73 return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0u;
76 tcu::TestStatus testSupportsDepthStencilFormat (Context& context, VkFormat format)
78 DE_ASSERT(vk::isDepthStencilFormat(format));
80 if (isSupportedDepthStencilFormat(context.getInstanceInterface(), context.getPhysicalDevice(), format))
81 return tcu::TestStatus::pass("Format can be used in depth/stencil attachment");
83 return tcu::TestStatus::fail("Unsupported depth/stencil attachment format");
86 tcu::TestStatus testSupportsAtLeastOneDepthStencilFormat (Context& context, const std::vector<VkFormat> formats)
88 std::ostringstream supportedFormatsMsg;
91 DE_ASSERT(!formats.empty());
93 for (size_t formatNdx = 0; formatNdx < formats.size(); formatNdx++)
95 const VkFormat format = formats[formatNdx];
97 DE_ASSERT(vk::isDepthStencilFormat(format));
99 if (isSupportedDepthStencilFormat(context.getInstanceInterface(), context.getPhysicalDevice(), format))
102 supportedFormatsMsg << vk::getFormatName(format);
104 if (formatNdx < formats.size() - 1)
105 supportedFormatsMsg << ", ";
110 return tcu::TestStatus::pass(std::string("Supported depth/stencil formats: ") + supportedFormatsMsg.str());
112 return tcu::TestStatus::fail("All depth/stencil formats are unsupported");
115 class DepthTest : public vkt::TestCase
123 static const float quadDepths[QUAD_COUNT];
125 DepthTest (tcu::TestContext& testContext,
126 const std::string& name,
127 const std::string& description,
128 const VkFormat depthFormat,
129 const VkCompareOp depthCompareOps[QUAD_COUNT]);
130 virtual ~DepthTest (void);
131 virtual void initPrograms (SourceCollections& programCollection) const;
132 virtual TestInstance* createInstance (Context& context) const;
135 const VkFormat m_depthFormat;
136 VkCompareOp m_depthCompareOps[QUAD_COUNT];
139 class DepthTestInstance : public vkt::TestInstance
142 DepthTestInstance (Context& context, const VkFormat depthFormat, const VkCompareOp depthCompareOps[DepthTest::QUAD_COUNT]);
143 virtual ~DepthTestInstance (void);
144 virtual tcu::TestStatus iterate (void);
147 tcu::TestStatus verifyImage (void);
150 VkCompareOp m_depthCompareOps[DepthTest::QUAD_COUNT];
151 const tcu::IVec2 m_renderSize;
152 const VkFormat m_colorFormat;
153 const VkFormat m_depthFormat;
155 Move<VkImage> m_colorImage;
156 de::MovePtr<Allocation> m_colorImageAlloc;
157 Move<VkImage> m_depthImage;
158 de::MovePtr<Allocation> m_depthImageAlloc;
159 Move<VkImageView> m_colorAttachmentView;
160 Move<VkImageView> m_depthAttachmentView;
161 Move<VkRenderPass> m_renderPass;
162 Move<VkFramebuffer> m_framebuffer;
164 Move<VkShaderModule> m_vertexShaderModule;
165 Move<VkShaderModule> m_fragmentShaderModule;
167 Move<VkBuffer> m_vertexBuffer;
168 std::vector<Vertex4RGBA> m_vertices;
169 de::MovePtr<Allocation> m_vertexBufferAlloc;
171 Move<VkPipelineLayout> m_pipelineLayout;
172 Move<VkPipeline> m_graphicsPipelines[DepthTest::QUAD_COUNT];
174 Move<VkCommandPool> m_cmdPool;
175 Move<VkCommandBuffer> m_cmdBuffer;
177 Move<VkFence> m_fence;
180 const float DepthTest::quadDepths[QUAD_COUNT] =
188 DepthTest::DepthTest (tcu::TestContext& testContext,
189 const std::string& name,
190 const std::string& description,
191 const VkFormat depthFormat,
192 const VkCompareOp depthCompareOps[QUAD_COUNT])
193 : vkt::TestCase (testContext, name, description)
194 , m_depthFormat (depthFormat)
196 deMemcpy(m_depthCompareOps, depthCompareOps, sizeof(VkCompareOp) * QUAD_COUNT);
199 DepthTest::~DepthTest (void)
203 TestInstance* DepthTest::createInstance (Context& context) const
205 return new DepthTestInstance(context, m_depthFormat, m_depthCompareOps);
208 void DepthTest::initPrograms (SourceCollections& programCollection) const
210 programCollection.glslSources.add("color_vert") << glu::VertexSource(
212 "layout(location = 0) in vec4 position;\n"
213 "layout(location = 1) in vec4 color;\n"
214 "layout(location = 0) out highp vec4 vtxColor;\n"
217 " gl_Position = position;\n"
218 " vtxColor = color;\n"
221 programCollection.glslSources.add("color_frag") << glu::FragmentSource(
223 "layout(location = 0) in highp vec4 vtxColor;\n"
224 "layout(location = 0) out highp vec4 fragColor;\n"
227 " fragColor = vtxColor;\n"
231 DepthTestInstance::DepthTestInstance (Context& context,
232 const VkFormat depthFormat,
233 const VkCompareOp depthCompareOps[DepthTest::QUAD_COUNT])
234 : vkt::TestInstance (context)
235 , m_renderSize (32, 32)
236 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
237 , m_depthFormat (depthFormat)
239 const DeviceInterface& vk = context.getDeviceInterface();
240 const VkDevice vkDevice = context.getDevice();
241 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
242 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
243 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
245 // Copy depth operators
246 deMemcpy(m_depthCompareOps, depthCompareOps, sizeof(VkCompareOp) * DepthTest::QUAD_COUNT);
248 // Create color image
250 const VkImageCreateInfo colorImageParams =
252 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
253 DE_NULL, // const void* pNext;
254 0u, // VkImageCreateFlags flags;
255 VK_IMAGE_TYPE_2D, // VkImageType imageType;
256 m_colorFormat, // VkFormat format;
257 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
258 1u, // deUint32 mipLevels;
259 1u, // deUint32 arrayLayers;
260 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
261 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
262 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
263 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
264 1u, // deUint32 queueFamilyIndexCount;
265 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
266 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
269 m_colorImage = createImage(vk, vkDevice, &colorImageParams);
271 // Allocate and bind color image memory
272 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
273 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
276 // Create depth image
278 // Check format support
279 if (!isSupportedDepthStencilFormat(context.getInstanceInterface(), context.getPhysicalDevice(), m_depthFormat))
280 throw tcu::NotSupportedError(std::string("Unsupported depth/stencil format: ") + getFormatName(m_depthFormat));
282 const VkImageCreateInfo depthImageParams =
284 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
285 DE_NULL, // const void* pNext;
286 0u, // VkImageCreateFlags flags;
287 VK_IMAGE_TYPE_2D, // VkImageType imageType;
288 m_depthFormat, // VkFormat format;
289 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
290 1u, // deUint32 mipLevels;
291 1u, // deUint32 arrayLayers;
292 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
293 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
294 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, // VkImageUsageFlags usage;
295 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
296 1u, // deUint32 queueFamilyIndexCount;
297 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
298 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
301 m_depthImage = createImage(vk, vkDevice, &depthImageParams);
303 // Allocate and bind depth image memory
304 m_depthImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_depthImage), MemoryRequirement::Any);
305 VK_CHECK(vk.bindImageMemory(vkDevice, *m_depthImage, m_depthImageAlloc->getMemory(), m_depthImageAlloc->getOffset()));
308 // Create color attachment view
310 const VkImageViewCreateInfo colorAttachmentViewParams =
312 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
313 DE_NULL, // const void* pNext;
314 0u, // VkImageViewCreateFlags flags;
315 *m_colorImage, // VkImage image;
316 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
317 m_colorFormat, // VkFormat format;
318 componentMappingRGBA, // VkComponentMapping components;
319 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
322 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
325 // Create depth attachment view
327 const VkImageViewCreateInfo depthAttachmentViewParams =
329 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
330 DE_NULL, // const void* pNext;
331 0u, // VkImageViewCreateFlags flags;
332 *m_depthImage, // VkImage image;
333 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
334 m_depthFormat, // VkFormat format;
335 componentMappingRGBA, // VkComponentMapping components;
336 { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
339 m_depthAttachmentView = createImageView(vk, vkDevice, &depthAttachmentViewParams);
342 // Create render pass
344 const VkAttachmentDescription colorAttachmentDescription =
346 0u, // VkAttachmentDescriptionFlags flags;
347 m_colorFormat, // VkFormat format;
348 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
349 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
350 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
351 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
352 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
353 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
354 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
357 const VkAttachmentDescription depthAttachmentDescription =
359 0u, // VkAttachmentDescriptionFlags flags;
360 m_depthFormat, // VkFormat format;
361 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
362 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
363 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
364 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
365 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
366 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
367 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
370 const VkAttachmentDescription attachments[2] =
372 colorAttachmentDescription,
373 depthAttachmentDescription
376 const VkAttachmentReference colorAttachmentReference =
378 0u, // deUint32 attachment;
379 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
382 const VkAttachmentReference depthAttachmentReference =
384 1u, // deUint32 attachment;
385 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
388 const VkSubpassDescription subpassDescription =
390 0u, // VkSubpassDescriptionFlags flags;
391 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
392 0u, // deUint32 inputAttachmentCount;
393 DE_NULL, // const VkAttachmentReference* pInputAttachments;
394 1u, // deUint32 colorAttachmentCount;
395 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
396 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
397 &depthAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment;
398 0u, // deUint32 preserveAttachmentCount;
399 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
402 const VkRenderPassCreateInfo renderPassParams =
404 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
405 DE_NULL, // const void* pNext;
406 0u, // VkRenderPassCreateFlags flags;
407 2u, // deUint32 attachmentCount;
408 attachments, // const VkAttachmentDescription* pAttachments;
409 1u, // deUint32 subpassCount;
410 &subpassDescription, // const VkSubpassDescription* pSubpasses;
411 0u, // deUint32 dependencyCount;
412 DE_NULL // const VkSubpassDependency* pDependencies;
415 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
418 // Create framebuffer
420 const VkImageView attachmentBindInfos[2] =
422 *m_colorAttachmentView,
423 *m_depthAttachmentView,
426 const VkFramebufferCreateInfo framebufferParams =
428 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
429 DE_NULL, // const void* pNext;
430 0u, // VkFramebufferCreateFlags flags;
431 *m_renderPass, // VkRenderPass renderPass;
432 2u, // deUint32 attachmentCount;
433 attachmentBindInfos, // const VkImageView* pAttachments;
434 (deUint32)m_renderSize.x(), // deUint32 width;
435 (deUint32)m_renderSize.y(), // deUint32 height;
436 1u // deUint32 layers;
439 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
442 // Create pipeline layout
444 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
446 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
447 DE_NULL, // const void* pNext;
448 0u, // VkPipelineLayoutCreateFlags flags;
449 0u, // deUint32 setLayoutCount;
450 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
451 0u, // deUint32 pushConstantRangeCount;
452 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
455 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
459 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
460 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
464 const VkPipelineShaderStageCreateInfo shaderStages[2] =
467 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
468 DE_NULL, // const void* pNext;
469 0u, // VkPipelineShaderStageCreateFlags flags;
470 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
471 *m_vertexShaderModule, // VkShaderModule module;
472 "main", // const char* pName;
473 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
476 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
477 DE_NULL, // const void* pNext;
478 0u, // VkPipelineShaderStageCreateFlags flags;
479 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
480 *m_fragmentShaderModule, // VkShaderModule module;
481 "main", // const char* pName;
482 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
486 const VkVertexInputBindingDescription vertexInputBindingDescription =
488 0u, // deUint32 binding;
489 sizeof(Vertex4RGBA), // deUint32 strideInBytes;
490 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate inputRate;
493 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
496 0u, // deUint32 location;
497 0u, // deUint32 binding;
498 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
499 0u // deUint32 offset;
502 1u, // deUint32 location;
503 0u, // deUint32 binding;
504 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
505 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offset;
509 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
511 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
512 DE_NULL, // const void* pNext;
513 0u, // VkPipelineVertexInputStateCreateFlags flags;
514 1u, // deUint32 vertexBindingDescriptionCount;
515 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
516 2u, // deUint32 vertexAttributeDescriptionCount;
517 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
520 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
522 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
523 DE_NULL, // const void* pNext;
524 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
525 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
526 false // VkBool32 primitiveRestartEnable;
529 const VkViewport viewport =
533 (float)m_renderSize.x(), // float width;
534 (float)m_renderSize.y(), // float height;
535 0.0f, // float minDepth;
536 1.0f // float maxDepth;
538 const VkRect2D scissor =
540 { 0, 0 }, // VkOffset2D offset;
541 { m_renderSize.x(), m_renderSize.y() } // VkExtent2D extent;
543 const VkPipelineViewportStateCreateInfo viewportStateParams =
545 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
546 DE_NULL, // const void* pNext;
547 0u, // VkPipelineViewportStateCreateFlags flags;
548 1u, // deUint32 viewportCount;
549 &viewport, // const VkViewport* pViewports;
550 1u, // deUint32 scissorCount;
551 &scissor // const VkRect2D* pScissors;
554 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
556 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
557 DE_NULL, // const void* pNext;
558 0u, // VkPipelineRasterizationStateCreateFlags flags;
559 false, // VkBool32 depthClampEnable;
560 false, // VkBool32 rasterizerDiscardEnable;
561 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
562 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
563 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
564 VK_FALSE, // VkBool32 depthBiasEnable;
565 0.0f, // float depthBiasConstantFactor;
566 0.0f, // float depthBiasClamp;
567 0.0f, // float depthBiasSlopeFactor;
568 1.0f, // float lineWidth;
571 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
573 false, // VkBool32 blendEnable;
574 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
575 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
576 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
577 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
578 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
579 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
580 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
581 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
584 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
586 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
587 DE_NULL, // const void* pNext;
588 0, // VkPipelineColorBlendStateCreateFlags flags;
589 false, // VkBool32 logicOpEnable;
590 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
591 1u, // deUint32 attachmentCount;
592 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
593 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConstants[4];
596 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
598 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
599 DE_NULL, // const void* pNext;
600 0u, // VkPipelineMultisampleStateCreateFlags flags;
601 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
602 false, // VkBool32 sampleShadingEnable;
603 0.0f, // float minSampleShading;
604 DE_NULL, // const VkSampleMask* pSampleMask;
605 false, // VkBool32 alphaToCoverageEnable;
606 false // VkBool32 alphaToOneEnable;
609 const VkPipelineDynamicStateCreateInfo dynamicStateParams =
611 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
612 DE_NULL, // const void* pNext;
613 0u, // VkPipelineDynamicStateCreateFlags flags;
614 0u, // deUint32 dynamicStateCount;
615 DE_NULL // const VkDynamicState* pDynamicStates;
618 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
620 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
621 DE_NULL, // const void* pNext;
622 0u, // VkPipelineDepthStencilStateCreateFlags flags;
623 true, // VkBool32 depthTestEnable;
624 true, // VkBool32 depthWriteEnable;
625 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
626 false, // VkBool32 depthBoundsTestEnable;
627 false, // VkBool32 stencilTestEnable;
628 // VkStencilOpState front;
630 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
631 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
632 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
633 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
634 0u, // deUint32 compareMask;
635 0u, // deUint32 writeMask;
636 0u, // deUint32 reference;
638 // VkStencilOpState back;
640 VK_STENCIL_OP_KEEP, // VkStencilOp failOp;
641 VK_STENCIL_OP_KEEP, // VkStencilOp passOp;
642 VK_STENCIL_OP_KEEP, // VkStencilOp depthFailOp;
643 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
644 0u, // deUint32 compareMask;
645 0u, // deUint32 writeMask;
646 0u, // deUint32 reference;
648 -1.0f, // float minDepthBounds;
649 +1.0f, // float maxDepthBounds;
652 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
654 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
655 DE_NULL, // const void* pNext;
656 0u, // VkPipelineCreateFlags flags;
657 2u, // deUint32 stageCount;
658 shaderStages, // const VkPipelineShaderStageCreateInfo* pStages;
659 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
660 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
661 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
662 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
663 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
664 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
665 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
666 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
667 &dynamicStateParams, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
668 *m_pipelineLayout, // VkPipelineLayout layout;
669 *m_renderPass, // VkRenderPass renderPass;
670 0u, // deUint32 subpass;
671 0u, // VkPipeline basePipelineHandle;
672 0u, // deInt32 basePipelineIndex;
675 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
677 depthStencilStateParams.depthCompareOp = depthCompareOps[quadNdx];
678 m_graphicsPipelines[quadNdx] = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
682 // Create vertex buffer
684 const VkBufferCreateInfo vertexBufferParams =
686 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
687 DE_NULL, // const void* pNext;
688 0u, // VkBufferCreateFlags flags;
689 1024u, // VkDeviceSize size;
690 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
691 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
692 1u, // deUint32 queueFamilyIndexCount;
693 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
696 m_vertices = createOverlappingQuads();
697 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
698 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
700 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
703 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
704 for (int vertexNdx = 0; vertexNdx < 6; vertexNdx++)
705 m_vertices[quadNdx * 6 + vertexNdx].position.z() = DepthTest::quadDepths[quadNdx];
707 // Load vertices into vertex buffer
708 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), m_vertices.size() * sizeof(Vertex4RGBA));
709 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexBufferParams.size);
712 // Create command pool
714 const VkCommandPoolCreateInfo cmdPoolParams =
716 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
717 DE_NULL, // const void* pNext;
718 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
719 queueFamilyIndex // deUint32 queueFamilyIndex;
722 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
725 // Create command buffer
727 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
729 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
730 DE_NULL, // const void* pNext;
731 *m_cmdPool, // VkCommandPool commandPool;
732 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
733 1u // deUint32 bufferCount;
736 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
738 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
739 DE_NULL, // const void* pNext;
740 0u, // VkCommandBufferUsageFlags flags;
741 DE_NULL, // VkRenderPass renderPass;
742 0u, // deUint32 subpass;
743 DE_NULL, // VkFramebuffer framebuffer;
744 false, // VkBool32 occlusionQueryEnable;
745 0u, // VkQueryControlFlags queryFlags;
746 0u // VkQueryPipelineStatisticFlags pipelineStatistics;
749 const VkClearValue attachmentClearValues[2] =
751 defaultClearValue(m_colorFormat),
752 defaultClearValue(m_depthFormat),
755 const VkRenderPassBeginInfo renderPassBeginInfo =
757 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
758 DE_NULL, // const void* pNext;
759 *m_renderPass, // VkRenderPass renderPass;
760 *m_framebuffer, // VkFramebuffer framebuffer;
761 { { 0, 0 }, { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
762 2, // deUint32 clearValueCount;
763 attachmentClearValues // const VkClearValue* pClearValues;
766 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
768 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
769 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
771 const VkDeviceSize quadOffset = (m_vertices.size() / DepthTest::QUAD_COUNT) * sizeof(Vertex4RGBA);
773 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
775 VkDeviceSize vertexBufferOffset = quadOffset * quadNdx;
777 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines[quadNdx]);
778 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
779 vk.cmdDraw(*m_cmdBuffer, (deUint32)(m_vertices.size() / DepthTest::QUAD_COUNT), 1, 0, 0);
782 vk.cmdEndRenderPass(*m_cmdBuffer);
783 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
788 const VkFenceCreateInfo fenceParams =
790 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
791 DE_NULL, // const void* pNext;
792 0u // VkFenceCreateFlags flags;
795 m_fence = createFence(vk, vkDevice, &fenceParams);
799 DepthTestInstance::~DepthTestInstance (void)
803 tcu::TestStatus DepthTestInstance::iterate (void)
805 const DeviceInterface& vk = m_context.getDeviceInterface();
806 const VkDevice vkDevice = m_context.getDevice();
807 const VkQueue queue = m_context.getUniversalQueue();
808 const VkSubmitInfo submitInfo =
810 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
811 DE_NULL, // const void* pNext;
812 0u, // deUint32 waitSemaphoreCount;
813 DE_NULL, // const VkSemaphore* pWaitSemaphores;
814 1u, // deUint32 commandBufferCount;
815 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
816 0u, // deUint32 signalSemaphoreCount;
817 DE_NULL // const VkSemaphore* pSignalSemaphores;
820 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
821 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
822 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
824 return verifyImage();
827 tcu::TestStatus DepthTestInstance::verifyImage (void)
829 const tcu::TextureFormat tcuColorFormat = mapVkFormat(m_colorFormat);
830 const tcu::TextureFormat tcuDepthFormat = mapVkFormat(m_depthFormat);
831 const ColorVertexShader vertexShader;
832 const ColorFragmentShader fragmentShader (tcuColorFormat, tcuDepthFormat);
833 const rr::Program program (&vertexShader, &fragmentShader);
834 ReferenceRenderer refRenderer (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuDepthFormat, &program);
835 bool compareOk = false;
837 // Render reference image
839 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
842 rr::RenderState renderState(refRenderer.getViewportState());
843 renderState.fragOps.depthTestEnabled = true;
844 renderState.fragOps.depthFunc = mapVkCompareOp(m_depthCompareOps[quadNdx]);
846 refRenderer.draw(renderState,
847 rr::PRIMITIVETYPE_TRIANGLES,
848 std::vector<Vertex4RGBA>(m_vertices.begin() + quadNdx * 6,
849 m_vertices.begin() + (quadNdx + 1) * 6));
853 // Compare result with reference image
855 const DeviceInterface& vk = m_context.getDeviceInterface();
856 const VkDevice vkDevice = m_context.getDevice();
857 const VkQueue queue = m_context.getUniversalQueue();
858 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
859 SimpleAllocator allocator (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
860 de::MovePtr<tcu::TextureLevel> result = readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_colorImage, m_colorFormat, m_renderSize);
862 compareOk = tcu::intThresholdPositionDeviationCompare(m_context.getTestContext().getLog(),
865 refRenderer.getAccess(),
867 tcu::UVec4(2, 2, 2, 2),
870 tcu::COMPARE_LOG_RESULT);
874 return tcu::TestStatus::pass("Result image matches reference");
876 return tcu::TestStatus::fail("Image mismatch");
879 std::string getFormatCaseName (const VkFormat format)
881 const std::string fullName = getFormatName(format);
883 DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
885 return de::toLower(fullName.substr(10));
888 std::string getCompareOpsName (const VkCompareOp quadDepthOps[DepthTest::QUAD_COUNT])
890 std::ostringstream name;
892 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
894 const std::string fullOpName = getCompareOpName(quadDepthOps[quadNdx]);
896 DE_ASSERT(de::beginsWith(fullOpName, "VK_COMPARE_OP_"));
898 name << de::toLower(fullOpName.substr(14));
900 if (quadNdx < DepthTest::QUAD_COUNT - 1)
907 std::string getCompareOpsDescription (const VkCompareOp quadDepthOps[DepthTest::QUAD_COUNT])
909 std::ostringstream desc;
910 desc << "Draws " << DepthTest::QUAD_COUNT << " quads with depth compare ops: ";
912 for (int quadNdx = 0; quadNdx < DepthTest::QUAD_COUNT; quadNdx++)
914 desc << getCompareOpName(quadDepthOps[quadNdx]) << " at depth " << DepthTest::quadDepths[quadNdx];
916 if (quadNdx < DepthTest::QUAD_COUNT - 1)
925 tcu::TestCaseGroup* createDepthTests (tcu::TestContext& testCtx)
927 const VkFormat depthFormats[] =
930 VK_FORMAT_X8_D24_UNORM_PACK32,
931 VK_FORMAT_D32_SFLOAT,
932 VK_FORMAT_D16_UNORM_S8_UINT,
933 VK_FORMAT_D24_UNORM_S8_UINT,
934 VK_FORMAT_D32_SFLOAT_S8_UINT
937 // Each entry configures the depth compare operators of QUAD_COUNT quads.
938 // All entries cover pair-wise combinations of compare operators.
939 const VkCompareOp depthOps[][DepthTest::QUAD_COUNT] =
941 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NOT_EQUAL },
942 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER },
943 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS_OR_EQUAL },
944 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL },
945 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_ALWAYS },
946 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS },
947 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NEVER },
948 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_EQUAL },
949 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS },
950 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL },
951 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER },
952 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS_OR_EQUAL },
953 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_EQUAL },
954 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_ALWAYS },
955 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL },
956 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS },
957 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS },
958 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER },
959 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL },
960 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER_OR_EQUAL },
961 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NEVER },
962 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER },
963 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS_OR_EQUAL },
964 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL },
965 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL },
966 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL },
967 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS },
968 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_EQUAL },
969 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS, VK_COMPARE_OP_NEVER },
970 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL },
971 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_EQUAL },
972 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS },
973 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_ALWAYS },
974 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL },
975 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NEVER },
976 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER_OR_EQUAL },
977 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS_OR_EQUAL },
978 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NEVER },
979 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_EQUAL },
980 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_LESS, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NOT_EQUAL },
981 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_ALWAYS },
982 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_ALWAYS },
983 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS },
984 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_EQUAL },
985 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER },
986 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_NOT_EQUAL },
987 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL },
988 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER_OR_EQUAL },
989 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NEVER },
990 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS },
991 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_LESS, VK_COMPARE_OP_ALWAYS },
992 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER },
993 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_EQUAL },
994 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NOT_EQUAL },
995 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_LESS },
996 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NEVER },
997 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS, VK_COMPARE_OP_NOT_EQUAL },
998 { VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_EQUAL },
999 { VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL },
1000 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER },
1001 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NEVER },
1002 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_GREATER },
1003 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_NOT_EQUAL },
1004 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_ALWAYS },
1005 { VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER },
1006 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER },
1007 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL },
1008 { VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL },
1009 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_LESS },
1010 { VK_COMPARE_OP_GREATER_OR_EQUAL, VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_NEVER },
1011 { VK_COMPARE_OP_LESS, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_EQUAL, VK_COMPARE_OP_EQUAL },
1012 { VK_COMPARE_OP_NEVER, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_ALWAYS, VK_COMPARE_OP_GREATER_OR_EQUAL },
1013 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER, VK_COMPARE_OP_ALWAYS },
1014 { VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_LESS_OR_EQUAL, VK_COMPARE_OP_NOT_EQUAL, VK_COMPARE_OP_GREATER }
1017 de::MovePtr<tcu::TestCaseGroup> depthTests (new tcu::TestCaseGroup(testCtx, "depth", "Depth tests"));
1019 // Tests for format features
1021 de::MovePtr<tcu::TestCaseGroup> formatFeaturesTests (new tcu::TestCaseGroup(testCtx, "format_features", "Checks depth format features"));
1023 // Formats that must be supported in all implementations
1024 addFunctionCase(formatFeaturesTests.get(),
1025 "support_d16_unorm",
1026 "Tests if VK_FORMAT_D16_UNORM is supported as depth/stencil attachment format",
1027 testSupportsDepthStencilFormat,
1028 VK_FORMAT_D16_UNORM);
1030 // Sets where at least one of the formats must be supported
1031 const VkFormat depthOnlyFormats[] = { VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D32_SFLOAT };
1032 const VkFormat depthStencilFormats[] = { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT };
1034 addFunctionCase(formatFeaturesTests.get(),
1035 "support_d24_unorm_or_d32_sfloat",
1036 "Tests if any of VK_FORMAT_D24_UNORM_X8 or VK_FORMAT_D32_SFLOAT are supported as depth/stencil attachment format",
1037 testSupportsAtLeastOneDepthStencilFormat,
1038 std::vector<VkFormat>(depthOnlyFormats, depthOnlyFormats + DE_LENGTH_OF_ARRAY(depthOnlyFormats)));
1040 addFunctionCase(formatFeaturesTests.get(),
1041 "support_d24_unorm_s8_uint_or_d32_sfloat_s8_uint",
1042 "Tests if any of VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT are supported as depth/stencil attachment format",
1043 testSupportsAtLeastOneDepthStencilFormat,
1044 std::vector<VkFormat>(depthStencilFormats, depthStencilFormats + DE_LENGTH_OF_ARRAY(depthStencilFormats)));
1046 depthTests->addChild(formatFeaturesTests.release());
1049 // Tests for format and compare operators
1051 de::MovePtr<tcu::TestCaseGroup> formatTests (new tcu::TestCaseGroup(testCtx, "format", "Uses different depth formats"));
1053 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(depthFormats); formatNdx++)
1055 de::MovePtr<tcu::TestCaseGroup> formatTest (new tcu::TestCaseGroup(testCtx,
1056 getFormatCaseName(depthFormats[formatNdx]).c_str(),
1057 (std::string("Uses format ") + getFormatName(depthFormats[formatNdx])).c_str()));
1058 de::MovePtr<tcu::TestCaseGroup> compareOpsTests (new tcu::TestCaseGroup(testCtx, "compare_ops", "Combines depth compare operators"));
1060 for (size_t opsNdx = 0; opsNdx < DE_LENGTH_OF_ARRAY(depthOps); opsNdx++)
1062 compareOpsTests->addChild(new DepthTest(testCtx,
1063 getCompareOpsName(depthOps[opsNdx]),
1064 getCompareOpsDescription(depthOps[opsNdx]),
1065 depthFormats[formatNdx],
1068 formatTest->addChild(compareOpsTests.release());
1069 formatTests->addChild(formatTest.release());
1071 depthTests->addChild(formatTests.release());
1074 return depthTests.release();