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.
33 * \brief Stencil Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktPipelineStencilTests.hpp"
37 #include "vktPipelineClearUtil.hpp"
38 #include "vktPipelineImageUtil.hpp"
39 #include "vktPipelineVertexUtil.hpp"
40 #include "vktPipelineReferenceRenderer.hpp"
41 #include "vktPipelineUniqueRandomIterator.hpp"
42 #include "vktTestCase.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"
51 #include "deRandom.hpp"
52 #include "deStringUtil.hpp"
53 #include "deUniquePtr.hpp"
69 bool isSupportedDepthStencilFormat (const InstanceInterface& instanceInterface, VkPhysicalDevice device, VkFormat format)
71 VkFormatProperties formatProps;
73 instanceInterface.getPhysicalDeviceFormatProperties(device, format, &formatProps);
75 return (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0;
78 class StencilOpStateUniqueRandomIterator : public UniqueRandomIterator<VkStencilOpState>
81 StencilOpStateUniqueRandomIterator (int seed);
82 virtual ~StencilOpStateUniqueRandomIterator (void) {}
83 virtual VkStencilOpState getIndexedValue (deUint32 index);
86 const static VkStencilOp m_stencilOps[];
87 const static VkCompareOp m_compareOps[];
89 // Pre-calculated constants
90 const static deUint32 m_stencilOpsLength;
91 const static deUint32 m_stencilOpsLength2;
92 const static deUint32 m_stencilOpsLength3;
93 const static deUint32 m_compareOpsLength;
95 // Total number of cross-combinations of (stencilFailOp x stencilPassOp x stencilDepthFailOp x stencilCompareOp)
96 const static deUint32 m_totalStencilOpStates;
100 class StencilTest : public vkt::TestCase
108 struct StencilStateConfig
110 deUint32 frontReadMask;
111 deUint32 frontWriteMask;
114 deUint32 backReadMask;
115 deUint32 backWriteMask;
119 const static StencilStateConfig s_stencilStateConfigs[QUAD_COUNT];
120 const static float s_quadDepths[QUAD_COUNT];
123 StencilTest (tcu::TestContext& testContext,
124 const std::string& name,
125 const std::string& description,
126 VkFormat stencilFormat,
127 const VkStencilOpState& stencilOpStateFront,
128 const VkStencilOpState& stencilOpStateBack);
129 virtual ~StencilTest (void);
130 virtual void initPrograms (SourceCollections& sourceCollections) const;
131 virtual TestInstance* createInstance (Context& context) const;
134 VkFormat m_stencilFormat;
135 const VkStencilOpState m_stencilOpStateFront;
136 const VkStencilOpState m_stencilOpStateBack;
139 class StencilTestInstance : public vkt::TestInstance
142 StencilTestInstance (Context& context,
143 VkFormat stencilFormat,
144 const VkStencilOpState& stencilOpStatesFront,
145 const VkStencilOpState& stencilOpStatesBack);
146 virtual ~StencilTestInstance (void);
147 virtual tcu::TestStatus iterate (void);
150 tcu::TestStatus verifyImage (void);
152 VkStencilOpState m_stencilOpStateFront;
153 VkStencilOpState m_stencilOpStateBack;
154 const tcu::UVec2 m_renderSize;
155 const VkFormat m_colorFormat;
156 const VkFormat m_stencilFormat;
158 VkImageCreateInfo m_colorImageCreateInfo;
159 Move<VkImage> m_colorImage;
160 de::MovePtr<Allocation> m_colorImageAlloc;
161 Move<VkImage> m_stencilImage;
162 de::MovePtr<Allocation> m_stencilImageAlloc;
163 Move<VkImageView> m_colorAttachmentView;
164 Move<VkImageView> m_stencilAttachmentView;
165 Move<VkRenderPass> m_renderPass;
166 Move<VkFramebuffer> m_framebuffer;
168 Move<VkShaderModule> m_vertexShaderModule;
169 Move<VkShaderModule> m_fragmentShaderModule;
171 Move<VkBuffer> m_vertexBuffer;
172 std::vector<Vertex4RGBA> m_vertices;
173 de::MovePtr<Allocation> m_vertexBufferAlloc;
175 Move<VkPipelineLayout> m_pipelineLayout;
176 Move<VkPipeline> m_graphicsPipelines[StencilTest::QUAD_COUNT];
178 Move<VkCommandPool> m_cmdPool;
179 Move<VkCommandBuffer> m_cmdBuffer;
181 Move<VkFence> m_fence;
185 // StencilOpStateUniqueRandomIterator
187 const VkStencilOp StencilOpStateUniqueRandomIterator::m_stencilOps[] =
191 VK_STENCIL_OP_REPLACE,
192 VK_STENCIL_OP_INCREMENT_AND_CLAMP,
193 VK_STENCIL_OP_DECREMENT_AND_CLAMP,
194 VK_STENCIL_OP_INVERT,
195 VK_STENCIL_OP_INCREMENT_AND_WRAP,
196 VK_STENCIL_OP_DECREMENT_AND_WRAP
199 const VkCompareOp StencilOpStateUniqueRandomIterator::m_compareOps[] =
204 VK_COMPARE_OP_LESS_OR_EQUAL,
205 VK_COMPARE_OP_GREATER,
206 VK_COMPARE_OP_NOT_EQUAL,
207 VK_COMPARE_OP_GREATER_OR_EQUAL,
211 const deUint32 StencilOpStateUniqueRandomIterator::m_stencilOpsLength = DE_LENGTH_OF_ARRAY(m_stencilOps);
212 const deUint32 StencilOpStateUniqueRandomIterator::m_stencilOpsLength2 = m_stencilOpsLength * m_stencilOpsLength;
213 const deUint32 StencilOpStateUniqueRandomIterator::m_stencilOpsLength3 = m_stencilOpsLength2 * m_stencilOpsLength;
214 const deUint32 StencilOpStateUniqueRandomIterator::m_compareOpsLength = DE_LENGTH_OF_ARRAY(m_compareOps);
215 const deUint32 StencilOpStateUniqueRandomIterator::m_totalStencilOpStates = m_stencilOpsLength3 * m_compareOpsLength;
217 StencilOpStateUniqueRandomIterator::StencilOpStateUniqueRandomIterator (int seed)
218 : UniqueRandomIterator<VkStencilOpState>(m_totalStencilOpStates, m_totalStencilOpStates, seed)
222 VkStencilOpState StencilOpStateUniqueRandomIterator::getIndexedValue (deUint32 index)
224 const deUint32 stencilCompareOpIndex = index / m_stencilOpsLength3;
225 const deUint32 stencilCompareOpSeqIndex = stencilCompareOpIndex * m_stencilOpsLength3;
227 const deUint32 stencilDepthFailOpIndex = (index - stencilCompareOpSeqIndex) / m_stencilOpsLength2;
228 const deUint32 stencilDepthFailOpSeqIndex = stencilDepthFailOpIndex * m_stencilOpsLength2;
230 const deUint32 stencilPassOpIndex = (index - stencilCompareOpSeqIndex - stencilDepthFailOpSeqIndex) / m_stencilOpsLength;
231 const deUint32 stencilPassOpSeqIndex = stencilPassOpIndex * m_stencilOpsLength;
233 const deUint32 stencilFailOpIndex = index - stencilCompareOpSeqIndex - stencilDepthFailOpSeqIndex - stencilPassOpSeqIndex;
235 const VkStencilOpState stencilOpState =
237 m_stencilOps[stencilFailOpIndex], // VkStencilOp failOp;
238 m_stencilOps[stencilPassOpIndex], // VkStencilOp passOp;
239 m_stencilOps[stencilDepthFailOpIndex], // VkStencilOp depthFailOp;
240 m_compareOps[stencilCompareOpIndex], // VkCompareOp compareOp;
241 0x0, // deUint32 compareMask;
242 0x0, // deUint32 writeMask;
243 0x0 // deUint32 reference;
246 return stencilOpState;
252 const StencilTest::StencilStateConfig StencilTest::s_stencilStateConfigs[QUAD_COUNT] =
254 // frontReadMask frontWriteMask frontRef backReadMask backWriteMask backRef
255 { 0xFF, 0xFF, 0xAB, 0xF0, 0xFF, 0xFF },
256 { 0xFF, 0xF0, 0xCD, 0xF0, 0xF0, 0xEF },
257 { 0xF0, 0x0F, 0xEF, 0xFF, 0x0F, 0xCD },
258 { 0xF0, 0x01, 0xFF, 0xFF, 0x01, 0xAB }
261 const float StencilTest::s_quadDepths[QUAD_COUNT] =
269 StencilTest::StencilTest (tcu::TestContext& testContext,
270 const std::string& name,
271 const std::string& description,
272 VkFormat stencilFormat,
273 const VkStencilOpState& stencilOpStateFront,
274 const VkStencilOpState& stencilOpStateBack)
275 : vkt::TestCase (testContext, name, description)
276 , m_stencilFormat (stencilFormat)
277 , m_stencilOpStateFront (stencilOpStateFront)
278 , m_stencilOpStateBack (stencilOpStateBack)
282 StencilTest::~StencilTest (void)
286 TestInstance* StencilTest::createInstance (Context& context) const
288 return new StencilTestInstance(context, m_stencilFormat, m_stencilOpStateFront, m_stencilOpStateBack);
291 void StencilTest::initPrograms (SourceCollections& sourceCollections) const
293 sourceCollections.glslSources.add("color_vert") << glu::VertexSource(
295 "layout(location = 0) in vec4 position;\n"
296 "layout(location = 1) in vec4 color;\n"
297 "layout(location = 0) out highp vec4 vtxColor;\n"
300 " gl_Position = position;\n"
301 " vtxColor = color;\n"
304 sourceCollections.glslSources.add("color_frag") << glu::FragmentSource(
306 "layout(location = 0) in highp vec4 vtxColor;\n"
307 "layout(location = 0) out highp vec4 fragColor;\n"
310 " fragColor = vtxColor;\n"
315 // StencilTestInstance
317 StencilTestInstance::StencilTestInstance (Context& context,
318 VkFormat stencilFormat,
319 const VkStencilOpState& stencilOpStateFront,
320 const VkStencilOpState& stencilOpStateBack)
321 : vkt::TestInstance (context)
322 , m_stencilOpStateFront (stencilOpStateFront)
323 , m_stencilOpStateBack (stencilOpStateBack)
324 , m_renderSize (32, 32)
325 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
326 , m_stencilFormat (stencilFormat)
328 const DeviceInterface& vk = context.getDeviceInterface();
329 const VkDevice vkDevice = context.getDevice();
330 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
331 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
332 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
334 // Create color image
336 const VkImageCreateInfo colorImageParams =
338 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
339 DE_NULL, // const void* pNext;
340 0u, // VkImageCreateFlags flags;
341 VK_IMAGE_TYPE_2D, // VkImageType imageType;
342 m_colorFormat, // VkFormat format;
343 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
344 1u, // deUint32 mipLevels;
345 1u, // deUint32 arrayLayers;
346 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
347 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
348 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
349 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
350 1u, // deUint32 queueFamilyIndexCount;
351 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
352 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
355 m_colorImageCreateInfo = colorImageParams;
356 m_colorImage = createImage(vk, vkDevice, &m_colorImageCreateInfo);
358 // Allocate and bind color image memory
359 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
360 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
363 // Create stencil image
365 // Check format support
366 if (!isSupportedDepthStencilFormat(context.getInstanceInterface(), context.getPhysicalDevice(), m_stencilFormat))
367 throw tcu::NotSupportedError(std::string("Unsupported depth/stencil format: ") + getFormatName(m_stencilFormat));
369 const VkImageCreateInfo stencilImageParams =
371 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
372 DE_NULL, // const void* pNext;
373 0u, // VkImageCreateFlags flags;
374 VK_IMAGE_TYPE_2D, // VkImageType imageType;
375 m_stencilFormat, // VkFormat format;
376 { m_renderSize.x(), m_renderSize.y(), 1u }, // VkExtent3D extent;
377 1u, // deUint32 mipLevels;
378 1u, // deUint32 arrayLayers;
379 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
380 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
381 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, // VkImageUsageFlags usage;
382 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
383 1u, // deUint32 queueFamilyIndexCount;
384 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
385 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
388 m_stencilImage = createImage(vk, vkDevice, &stencilImageParams);
390 // Allocate and bind stencil image memory
391 m_stencilImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_stencilImage), MemoryRequirement::Any);
392 VK_CHECK(vk.bindImageMemory(vkDevice, *m_stencilImage, m_stencilImageAlloc->getMemory(), m_stencilImageAlloc->getOffset()));
395 // Create color attachment view
397 const VkImageViewCreateInfo colorAttachmentViewParams =
399 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
400 DE_NULL, // const void* pNext;
401 0u, // VkImageViewCreateFlags flags;
402 *m_colorImage, // VkImage image;
403 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
404 m_colorFormat, // VkFormat format;
405 componentMappingRGBA, // VkComponentMapping components;
406 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
409 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
412 // Create stencil attachment view
414 const VkImageViewCreateInfo stencilAttachmentViewParams =
416 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
417 DE_NULL, // const void* pNext;
418 0u, // VkImageViewCreateFlags flags;
419 *m_stencilImage, // VkImage image;
420 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
421 m_stencilFormat, // VkFormat format;
422 componentMappingRGBA, // VkComponentMapping components;
423 { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
426 m_stencilAttachmentView = createImageView(vk, vkDevice, &stencilAttachmentViewParams);
429 // Create render pass
431 const VkAttachmentDescription colorAttachmentDescription =
433 0u, // VkAttachmentDescriptionFlags flags;
434 m_colorFormat, // VkFormat format;
435 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
436 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
437 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
438 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
439 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
440 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
441 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
444 const VkAttachmentDescription stencilAttachmentDescription =
446 0u, // VkAttachmentDescriptionFlags flags;
447 m_stencilFormat, // VkFormat format;
448 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
449 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
450 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
451 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp stencilLoadOp;
452 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
453 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
454 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
457 const VkAttachmentDescription attachments[2] =
459 colorAttachmentDescription,
460 stencilAttachmentDescription
463 const VkAttachmentReference colorAttachmentReference =
465 0u, // deUint32 attachment;
466 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
469 const VkAttachmentReference stencilAttachmentReference =
471 1u, // deUint32 attachment;
472 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL // VkImageLayout layout;
475 const VkSubpassDescription subpassDescription =
477 0u, // VkSubpassDescriptionFlags flags;
478 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
479 0u, // deUint32 inputAttachmentCount;
480 DE_NULL, // const VkAttachmentReference* pInputAttachments;
481 1u, // deUint32 colorAttachmentCount;
482 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
483 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
484 &stencilAttachmentReference, // const VkAttachmentReference* pDepthStencilAttachment;
485 0u, // deUint32 preserveAttachmentCount;
486 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
489 const VkRenderPassCreateInfo renderPassParams =
491 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
492 DE_NULL, // const void* pNext;
493 0u, // VkRenderPassCreateFlags flags;
494 2u, // deUint32 attachmentCount;
495 attachments, // const VkAttachmentDescription* pAttachments;
496 1u, // deUint32 subpassCount;
497 &subpassDescription, // const VkSubpassDescription* pSubpasses;
498 0u, // deUint32 dependencyCount;
499 DE_NULL // const VkSubpassDependency* pDependencies;
502 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
505 // Create framebuffer
507 const VkImageView attachmentBindInfos[2] = { *m_colorAttachmentView, *m_stencilAttachmentView };
509 const VkFramebufferCreateInfo framebufferParams =
511 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
512 DE_NULL, // const void* pNext;
513 0u, // VkFramebufferCreateFlags flags;
514 *m_renderPass, // VkRenderPass renderPass;
515 2u, // deUint32 attachmentCount;
516 attachmentBindInfos, // const VkImageView* pAttachments;
517 (deUint32)m_renderSize.x(), // deUint32 width;
518 (deUint32)m_renderSize.y(), // deUint32 height;
519 1u // deUint32 layers;
522 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
525 // Create pipeline layout
527 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
529 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
530 DE_NULL, // const void* pNext;
531 0u, // VkPipelineLayoutCreateFlags flags;
532 0u, // deUint32 setLayoutCount;
533 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
534 0u, // deUint32 pushConstantRangeCount;
535 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
538 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
541 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_vert"), 0);
542 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("color_frag"), 0);
546 const VkPipelineShaderStageCreateInfo shaderStages[2] =
549 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
550 DE_NULL, // const void* pNext;
551 0u, // VkPipelineShaderStageCreateFlags flags;
552 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
553 *m_vertexShaderModule, // VkShaderModule module;
554 "main", // const char* pName;
555 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
558 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
559 DE_NULL, // const void* pNext;
560 0u, // VkPipelineShaderStageCreateFlags flags;
561 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
562 *m_fragmentShaderModule, // VkShaderModule module;
563 "main", // const char* pName;
564 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
568 const VkVertexInputBindingDescription vertexInputBindingDescription =
570 0u, // deUint32 binding;
571 sizeof(Vertex4RGBA), // deUint32 strideInBytes;
572 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate inputRate;
575 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
578 0u, // deUint32 location;
579 0u, // deUint32 binding;
580 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
581 0u // deUint32 offsetInBytes;
584 1u, // deUint32 location;
585 0u, // deUint32 binding;
586 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
587 DE_OFFSET_OF(Vertex4RGBA, color), // deUint32 offsetInBytes;
591 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
593 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
594 DE_NULL, // const void* pNext;
595 0u, // VkPipelineVertexInputStateCreateFlags flags;
596 1u, // deUint32 vertexBindingDescriptionCount;
597 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
598 2u, // deUint32 vertexAttributeDescriptionCount;
599 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
602 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
604 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
605 DE_NULL, // const void* pNext;
606 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
607 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
608 false // VkBool32 primitiveRestartEnable;
611 const VkViewport viewport =
615 (float)m_renderSize.x(), // float width;
616 (float)m_renderSize.y(), // float height;
617 0.0f, // float minDepth;
618 1.0f // float maxDepth;
621 const VkRect2D scissor = { { 0, 0 }, { m_renderSize.x(), m_renderSize.y() } };
623 const VkPipelineViewportStateCreateInfo viewportStateParams =
625 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
626 DE_NULL, // const void* pNext;
627 0u, // VkPipelineViewportStateCreateFlags flags;
628 1u, // deUint32 viewportCount;
629 &viewport, // const VkViewport* pViewports;
630 1u, // deUint32 scissorCount;
631 &scissor, // const VkRect2D* pScissors;
634 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
636 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
637 DE_NULL, // const void* pNext;
638 0u, // VkPipelineRasterizationStateCreateFlags flags;
639 false, // VkBool32 depthClampEnable;
640 false, // VkBool32 rasterizerDiscardEnable;
641 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
642 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
643 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
644 false, // VkBool32 depthBiasEnable;
645 0.0f, // float depthBiasConstantFactor;
646 0.0f, // float depthBiasClamp;
647 0.0f, // float depthBiasSlopeFactor;
648 1.0f // float lineWidth;
651 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
653 false, // VkBool32 blendEnable;
654 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
655 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
656 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
657 VK_BLEND_FACTOR_ONE, // VKBLENDFACTOR SRCALPHABLENDFACTOR;
658 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
659 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
660 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
661 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
664 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
666 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
667 DE_NULL, // const void* pNext;
668 0u, // VkPipelineColorBlendStateCreateFlags flags;
669 false, // VkBool32 logicOpEnable;
670 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
671 1u, // deUint32 attachmentCount;
672 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
673 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
676 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
678 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
679 DE_NULL, // const void* pNext;
680 0u, // VkPipelineMultisampleStateCreateFlags flags;
681 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
682 false, // VkBool32 sampleShadingEnable;
683 0.0f, // float minSampleShading;
684 DE_NULL, // const VkSampleMask* pSampleMask;
685 false, // VkBool32 alphaToCoverageEnable;
686 false // VkBool32 alphaToOneEnable;
689 const bool isDepthEnabled = (vk::mapVkFormat(m_stencilFormat).order != tcu::TextureFormat::S);
691 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
693 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
694 DE_NULL, // const void* pNext;
695 0u, // VkPipelineDepthStencilStateCreateFlags flags;
696 isDepthEnabled, // VkBool32 depthTestEnable;
697 isDepthEnabled, // VkBool32 depthWriteEnable;
698 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
699 false, // VkBool32 depthBoundsTestEnable;
700 true, // VkBool32 stencilTestEnable;
701 m_stencilOpStateFront, // VkStencilOpState front;
702 m_stencilOpStateBack, // VkStencilOpState back;
703 -1.0f, // float minDepthBounds;
704 +1.0f // float maxDepthBounds;
707 const VkPipelineDynamicStateCreateInfo dynamicStateParams =
709 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
710 DE_NULL, // const void* pNext;
711 0u, // VkPipelineDynamicStateCreateFlags flags;
712 0u, // deUint32 dynamicStateCount;
713 DE_NULL // const VkDynamicState* pDynamicStates;
716 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
718 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
719 DE_NULL, // const void* pNext;
720 0u, // VkPipelineCreateFlags flags;
721 2u, // deUint32 stageCount;
722 shaderStages, // const VkPipelineShaderStageCreateInfo* pStages;
723 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
724 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
725 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
726 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
727 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
728 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
729 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
730 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
731 &dynamicStateParams, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
732 *m_pipelineLayout, // VkPipelineLayout layout;
733 *m_renderPass, // VkRenderPass renderPass;
734 0u, // deUint32 subpass;
735 0u, // VkPipeline basePipelineHandle;
736 0u // deInt32 basePipelineIndex;
739 // Setup different stencil masks and refs in each quad
740 for (int quadNdx = 0; quadNdx < StencilTest::QUAD_COUNT; quadNdx++)
742 const StencilTest::StencilStateConfig& config = StencilTest::s_stencilStateConfigs[quadNdx];
743 VkStencilOpState& front = depthStencilStateParams.front;
744 VkStencilOpState& back = depthStencilStateParams.back;
746 front.compareMask = config.frontReadMask;
747 front.writeMask = config.frontWriteMask;
748 front.reference = config.frontRef;
750 back.compareMask = config.backReadMask;
751 back.writeMask = config.backWriteMask;
752 back.reference = config.backRef;
754 m_graphicsPipelines[quadNdx] = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
759 // Create vertex buffer
761 const VkBufferCreateInfo vertexBufferParams =
763 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
764 DE_NULL, // const void* pNext;
765 0u, // VkBufferCreateFlags flags;
766 1024u, // VkDeviceSize size;
767 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
768 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
769 1u, // deUint32 queueFamilyIndexCount;
770 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
773 m_vertices = createOverlappingQuads();
774 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
775 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
777 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
780 for (int quadNdx = 0; quadNdx < 4; quadNdx++)
781 for (int vertexNdx = 0; vertexNdx < 6; vertexNdx++)
782 m_vertices[quadNdx * 6 + vertexNdx].position.z() = StencilTest::s_quadDepths[quadNdx];
784 // Load vertices into vertex buffer
785 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), m_vertices.size() * sizeof(Vertex4RGBA));
787 const VkMappedMemoryRange flushRange =
789 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // VkStructureType sType;
790 DE_NULL, // const void* pNext;
791 m_vertexBufferAlloc->getMemory(), // VkDeviceMemory memory;
792 m_vertexBufferAlloc->getOffset(), // VkDeviceSize offset;
793 vertexBufferParams.size // VkDeviceSize size;
796 vk.flushMappedMemoryRanges(vkDevice, 1, &flushRange);
799 // Create command pool
801 const VkCommandPoolCreateInfo cmdPoolParams =
803 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
804 DE_NULL, // const void* pNext;
805 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
806 queueFamilyIndex, // deUint32 queueFamilyIndex;
809 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
812 // Create command buffer
814 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
816 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
817 DE_NULL, // const void* pNext;
818 *m_cmdPool, // VkCommandPool commandPool;
819 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
820 1u // deUint32 bufferCount;
823 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
825 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
826 DE_NULL, // const void* pNext;
827 0u, // VkCommandBufferUsageFlags flags;
828 (const VkCommandBufferInheritanceInfo*)DE_NULL,
831 const VkClearValue attachmentClearValues[2] =
833 defaultClearValue(m_colorFormat),
834 defaultClearValue(m_stencilFormat)
837 const VkRenderPassBeginInfo renderPassBeginInfo =
839 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
840 DE_NULL, // const void* pNext;
841 *m_renderPass, // VkRenderPass renderPass;
842 *m_framebuffer, // VkFramebuffer framebuffer;
843 { { 0, 0 } , { m_renderSize.x(), m_renderSize.y() } }, // VkRect2D renderArea;
844 2, // deUint32 clearValueCount;
845 attachmentClearValues // const VkClearValue* pClearValues;
848 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
850 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
851 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
853 const VkDeviceSize quadOffset = (m_vertices.size() / StencilTest::QUAD_COUNT) * sizeof(Vertex4RGBA);
855 for (int quadNdx = 0; quadNdx < StencilTest::QUAD_COUNT; quadNdx++)
857 VkDeviceSize vertexBufferOffset = quadOffset * quadNdx;
859 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines[quadNdx]);
860 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), &vertexBufferOffset);
861 vk.cmdDraw(*m_cmdBuffer, (deUint32)(m_vertices.size() / StencilTest::QUAD_COUNT), 1, 0, 0);
864 vk.cmdEndRenderPass(*m_cmdBuffer);
865 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
870 const VkFenceCreateInfo fenceParams =
872 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
873 DE_NULL, // const void* pNext;
874 0u // VkFenceCreateFlags flags;
877 m_fence = createFence(vk, vkDevice, &fenceParams);
881 StencilTestInstance::~StencilTestInstance (void)
885 tcu::TestStatus StencilTestInstance::iterate (void)
887 const DeviceInterface& vk = m_context.getDeviceInterface();
888 const VkDevice vkDevice = m_context.getDevice();
889 const VkQueue queue = m_context.getUniversalQueue();
890 const VkSubmitInfo submitInfo =
892 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
893 DE_NULL, // const void* pNext;
894 0u, // deUint32 waitSemaphoreCount;
895 DE_NULL, // const VkSemaphore* pWaitSemaphores;
896 (const VkPipelineStageFlags*)DE_NULL,
897 1u, // deUint32 commandBufferCount;
898 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
899 0u, // deUint32 signalSemaphoreCount;
900 DE_NULL // const VkSemaphore* pSignalSemaphores;
903 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
904 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
905 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity*/));
907 return verifyImage();
910 tcu::TestStatus StencilTestInstance::verifyImage (void)
912 const tcu::TextureFormat tcuColorFormat = mapVkFormat(m_colorFormat);
913 const tcu::TextureFormat tcuStencilFormat = mapVkFormat(m_stencilFormat);
914 const ColorVertexShader vertexShader;
915 const ColorFragmentShader fragmentShader (tcuColorFormat, tcuStencilFormat);
916 const rr::Program program (&vertexShader, &fragmentShader);
917 ReferenceRenderer refRenderer (m_renderSize.x(), m_renderSize.y(), 1, tcuColorFormat, tcuStencilFormat, &program);
918 bool compareOk = false;
920 // Render reference image
923 rr::RenderState renderState(refRenderer.getViewportState());
925 renderState.fragOps.depthTestEnabled = true;
926 renderState.fragOps.depthFunc = mapVkCompareOp(VK_COMPARE_OP_LESS);
927 renderState.fragOps.stencilTestEnabled = true;
929 rr::StencilState& refStencilFront = renderState.fragOps.stencilStates[rr::FACETYPE_FRONT];
930 rr::StencilState& refStencilBack = renderState.fragOps.stencilStates[rr::FACETYPE_BACK];
932 refStencilFront.sFail = mapVkStencilOp(m_stencilOpStateFront.failOp);
933 refStencilFront.dpFail = mapVkStencilOp(m_stencilOpStateFront.depthFailOp);
934 refStencilFront.dpPass = mapVkStencilOp(m_stencilOpStateFront.passOp);
935 refStencilFront.func = mapVkCompareOp(m_stencilOpStateFront.compareOp);
937 refStencilBack.sFail = mapVkStencilOp(m_stencilOpStateBack.failOp);
938 refStencilBack.dpFail = mapVkStencilOp(m_stencilOpStateBack.depthFailOp);
939 refStencilBack.dpPass = mapVkStencilOp(m_stencilOpStateBack.passOp);
940 refStencilBack.func = mapVkCompareOp(m_stencilOpStateBack.compareOp);
942 // Reverse winding of vertices, as Vulkan screen coordinates start at upper left
943 std::vector<Vertex4RGBA> cwVertices(m_vertices);
944 for (size_t vertexNdx = 0; vertexNdx < cwVertices.size() - 2; vertexNdx += 3)
946 const Vertex4RGBA cwVertex1 = cwVertices[vertexNdx + 1];
948 cwVertices[vertexNdx + 1] = cwVertices[vertexNdx + 2];
949 cwVertices[vertexNdx + 2] = cwVertex1;
952 for (int quadNdx = 0; quadNdx < StencilTest::QUAD_COUNT; quadNdx++)
954 refStencilFront.ref = (int)StencilTest::s_stencilStateConfigs[quadNdx].frontRef;
955 refStencilFront.compMask = StencilTest::s_stencilStateConfigs[quadNdx].frontReadMask;
956 refStencilFront.writeMask = StencilTest::s_stencilStateConfigs[quadNdx].frontWriteMask;
958 refStencilBack.ref = (int)StencilTest::s_stencilStateConfigs[quadNdx].backRef;
959 refStencilBack.compMask = StencilTest::s_stencilStateConfigs[quadNdx].backReadMask;
960 refStencilBack.writeMask = StencilTest::s_stencilStateConfigs[quadNdx].backWriteMask;
962 refRenderer.draw(renderState,
963 rr::PRIMITIVETYPE_TRIANGLES,
964 std::vector<Vertex4RGBA>(cwVertices.begin() + quadNdx * 6,
965 cwVertices.begin() + (quadNdx + 1) * 6));
969 // Compare result with reference image
971 const DeviceInterface& vk = m_context.getDeviceInterface();
972 const VkDevice vkDevice = m_context.getDevice();
973 const VkQueue queue = m_context.getUniversalQueue();
974 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
975 SimpleAllocator allocator (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
976 de::UniquePtr<tcu::TextureLevel> result (readColorAttachment(vk, vkDevice, queue, queueFamilyIndex, allocator, *m_colorImage, m_colorFormat, m_renderSize).release());
978 compareOk = tcu::intThresholdPositionDeviationCompare(m_context.getTestContext().getLog(),
981 refRenderer.getAccess(),
983 tcu::UVec4(2, 2, 2, 2),
986 tcu::COMPARE_LOG_RESULT);
990 return tcu::TestStatus::pass("Result image matches reference");
992 return tcu::TestStatus::fail("Image mismatch");
996 // Utilities for test names
998 std::string getShortName (VkCompareOp compareOp)
1000 const std::string fullName = getCompareOpName(compareOp);
1002 DE_ASSERT(de::beginsWith(fullName, "VK_COMPARE_OP_"));
1004 return de::toLower(fullName.substr(14));
1007 const char* getShortName (VkStencilOp stencilOp)
1011 case VK_STENCIL_OP_KEEP: return "keep";
1012 case VK_STENCIL_OP_ZERO: return "zero";
1013 case VK_STENCIL_OP_REPLACE: return "repl";
1014 case VK_STENCIL_OP_INCREMENT_AND_CLAMP: return "incc";
1015 case VK_STENCIL_OP_DECREMENT_AND_CLAMP: return "decc";
1016 case VK_STENCIL_OP_INVERT: return "inv";
1017 case VK_STENCIL_OP_INCREMENT_AND_WRAP: return "wrap";
1018 case VK_STENCIL_OP_DECREMENT_AND_WRAP: return "decw";
1021 DE_FATAL("Invalid VkStencilOpState value");
1026 std::string getStencilName(const VkStencilOpState& stencilOpState)
1028 std::ostringstream name;
1030 name << "fail_" << getShortName(stencilOpState.failOp)
1031 << "_pass_" << getShortName(stencilOpState.passOp)
1032 << "_dfail_" << getShortName(stencilOpState.depthFailOp)
1033 << "_comp_" << getShortName(stencilOpState.compareOp);
1038 std::string getStencilStateSetName(const VkStencilOpState& stencilOpStateFront,
1039 const VkStencilOpState& stencilOpStateBack)
1041 std::ostringstream name;
1043 name << "front_" << getStencilName(stencilOpStateFront)
1044 << "_back_" << getStencilName(stencilOpStateBack);
1049 std::string getStencilStateSetDescription(const VkStencilOpState& stencilOpStateFront,
1050 const VkStencilOpState& stencilOpStateBack)
1052 std::ostringstream desc;
1054 desc << "\nFront faces:\n" << stencilOpStateFront;
1055 desc << "Back faces:\n" << stencilOpStateBack;
1060 std::string getFormatCaseName (VkFormat format)
1062 const std::string fullName = getFormatName(format);
1064 DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
1066 return de::toLower(fullName.substr(10));
1071 tcu::TestCaseGroup* createStencilTests (tcu::TestContext& testCtx)
1073 const VkFormat stencilFormats[] =
1076 VK_FORMAT_D16_UNORM_S8_UINT,
1077 VK_FORMAT_D24_UNORM_S8_UINT,
1078 VK_FORMAT_D32_SFLOAT_S8_UINT
1081 de::MovePtr<tcu::TestCaseGroup> stencilTests (new tcu::TestCaseGroup(testCtx, "stencil", "Stencil tests"));
1082 de::MovePtr<tcu::TestCaseGroup> formatTests (new tcu::TestCaseGroup(testCtx, "format", "Uses different stencil formats"));
1083 StencilOpStateUniqueRandomIterator stencilOpItr (123);
1085 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(stencilFormats); formatNdx++)
1087 const VkFormat stencilFormat = stencilFormats[formatNdx];
1088 de::MovePtr<tcu::TestCaseGroup> formatTest (new tcu::TestCaseGroup(testCtx,
1089 getFormatCaseName(stencilFormat).c_str(),
1090 (std::string("Uses format ") + getFormatName(stencilFormat)).c_str()));
1092 de::MovePtr<tcu::TestCaseGroup> stencilStateTests;
1094 std::ostringstream desc;
1095 desc << "Draws 4 quads with the following depths and dynamic stencil states: ";
1096 for (int quadNdx = 0; quadNdx < StencilTest::QUAD_COUNT; quadNdx++)
1098 const StencilTest::StencilStateConfig& stencilConfig = StencilTest::s_stencilStateConfigs[quadNdx];
1100 desc << "(" << quadNdx << ") "
1101 << "z = " << StencilTest::s_quadDepths[quadNdx] << ", "
1102 << "frontReadMask = " << stencilConfig.frontReadMask << ", "
1103 << "frontWriteMask = " << stencilConfig.frontWriteMask << ", "
1104 << "frontRef = " << stencilConfig.frontRef << ", "
1105 << "backReadMask = " << stencilConfig.backReadMask << ", "
1106 << "backWriteMask = " << stencilConfig.backWriteMask << ", "
1107 << "backRef = " << stencilConfig.backRef;
1110 stencilStateTests = de::MovePtr<tcu::TestCaseGroup>(new tcu::TestCaseGroup(testCtx, "states", desc.str().c_str()));
1113 stencilOpItr.reset();
1115 VkStencilOpState prevStencilState = stencilOpItr.next();
1116 const VkStencilOpState firstStencilState = prevStencilState;
1118 while (stencilOpItr.hasNext())
1120 const VkStencilOpState stencilState = stencilOpItr.next();
1122 // Use current stencil state in front fraces and previous state in back faces
1123 stencilStateTests->addChild(new StencilTest(testCtx,
1124 getStencilStateSetName(stencilState, prevStencilState),
1125 getStencilStateSetDescription(stencilState, prevStencilState),
1130 prevStencilState = stencilState;
1133 // Use first stencil state with last stencil state. This would make the test suite cover all states in front and back faces.
1134 stencilStateTests->addChild(new StencilTest(testCtx,
1135 getStencilStateSetName(firstStencilState, prevStencilState),
1136 getStencilStateSetDescription(firstStencilState, prevStencilState),
1141 formatTest->addChild(stencilStateTests.release());
1142 formatTests->addChild(formatTest.release());
1144 stencilTests->addChild(formatTests.release());
1146 return stencilTests.release();