dEQP-VK.renderpass: Set IMAGE_USAGE_TRANSFER_SRC_BIT when needed
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / dynamic_state / vktDynamicStateDSTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Intel Corporation
7  *
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:
15  *
16  * The above copyright notice(s) and this permission notice shall be included
17  * in all copies or substantial portions of the Materials.
18  *
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.
22  *
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.
30  *
31  *//*!
32  * \file
33  * \brief Dynamic State Depth Stencil Tests
34  *//*--------------------------------------------------------------------*/
35
36 #include "vktDynamicStateDSTests.hpp"
37
38 #include "vktTestCaseUtil.hpp"
39 #include "vktDynamicStateTestCaseUtil.hpp"
40
41 #include "tcuTestLog.hpp"
42 #include "tcuResource.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuCommandLine.hpp"
45 #include "tcuTextureUtil.hpp"
46 #include "tcuRGBA.hpp"
47
48 #include "vkRefUtil.hpp"
49 #include "vkImageUtil.hpp"
50
51 #include "vktDynamicStateCreateInfoUtil.hpp"
52 #include "vktDynamicStateImageObjectUtil.hpp"
53 #include "vktDynamicStateBufferObjectUtil.hpp"
54 #include "vkPrograms.hpp"
55
56 namespace vkt
57 {
58 namespace DynamicState
59 {
60
61 namespace
62 {
63
64 class DepthStencilBaseCase : public TestInstance
65 {
66 public:
67         DepthStencilBaseCase (Context& context, const char* vertexShaderName, const char* fragmentShaderName)
68                 : TestInstance                                          (context)
69                 , m_colorAttachmentFormat                       (vk::VK_FORMAT_R8G8B8A8_UNORM)
70                 , m_depthStencilAttachmentFormat        (vk::VK_FORMAT_D24_UNORM_S8_UINT)
71                 , m_topology                                            (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)
72                 , m_vk                                                          (context.getDeviceInterface())
73                 , m_vertexShaderName                            (vertexShaderName)
74                 , m_fragmentShaderName                          (fragmentShaderName)
75         {
76         }
77
78 protected:
79
80         enum
81         {
82                 WIDTH   = 128,
83                 HEIGHT  = 128
84         };
85
86         vk::VkFormat                                                                    m_colorAttachmentFormat;
87         vk::VkFormat                                                                    m_depthStencilAttachmentFormat;
88
89         vk::VkPrimitiveTopology                                                 m_topology;
90
91         const vk::DeviceInterface&                                              m_vk;
92
93         vk::Move<vk::VkPipeline>                                                m_pipeline_1;
94         vk::Move<vk::VkPipeline>                                                m_pipeline_2;
95         vk::Move<vk::VkPipelineLayout>                                  m_pipelineLayout;
96
97         de::SharedPtr<Image>                                                    m_colorTargetImage;
98         vk::Move<vk::VkImageView>                                               m_colorTargetView;
99
100         de::SharedPtr<Image>                                                    m_depthStencilImage;
101         vk::Move<vk::VkImageView>                                               m_attachmentView;
102
103         PipelineCreateInfo::VertexInputState                    m_vertexInputState;
104         de::SharedPtr<Buffer>                                                   m_vertexBuffer;
105
106         vk::Move<vk::VkCommandPool>                                             m_cmdPool;
107         vk::Move<vk::VkCommandBuffer>                                   m_cmdBuffer;
108
109         vk::Move<vk::VkFramebuffer>                                             m_framebuffer;
110         vk::Move<vk::VkRenderPass>                                              m_renderPass;
111
112         const std::string                                                               m_vertexShaderName;
113         const std::string                                                               m_fragmentShaderName;
114
115         std::vector<PositionColorVertex>                                m_data;
116
117         PipelineCreateInfo::DepthStencilState                   m_depthStencilState_1;
118         PipelineCreateInfo::DepthStencilState                   m_depthStencilState_2;
119
120         void initialize (void)
121         {
122                 const vk::VkDevice device = m_context.getDevice();
123
124                 const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
125                 m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo);
126
127                 const vk::Unique<vk::VkShaderModule> vs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
128                 const vk::Unique<vk::VkShaderModule> fs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
129
130                 const vk::VkExtent3D imageExtent = { WIDTH, HEIGHT, 1 };
131                 const ImageCreateInfo targetImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT,
132                                                                                                         vk::VK_IMAGE_TILING_OPTIMAL, vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
133
134                 m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator());
135
136                 const ImageCreateInfo depthStencilImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_depthStencilAttachmentFormat, imageExtent,
137                                                                                                                   1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
138                                                                                                                   vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
139
140                 m_depthStencilImage = Image::createAndAlloc(m_vk, device, depthStencilImageCreateInfo, m_context.getDefaultAllocator());
141
142                 const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
143                 m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo);
144
145                 const ImageViewCreateInfo attachmentViewInfo(m_depthStencilImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_depthStencilAttachmentFormat);
146                 m_attachmentView = vk::createImageView(m_vk, device, &attachmentViewInfo);
147
148                 RenderPassCreateInfo renderPassCreateInfo;
149                 renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,
150                                                                                                                                  vk::VK_SAMPLE_COUNT_1_BIT,
151                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_LOAD,
152                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_STORE,
153                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
154                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_STORE,
155                                                                                                                                  vk::VK_IMAGE_LAYOUT_GENERAL,
156                                                                                                                                  vk::VK_IMAGE_LAYOUT_GENERAL));
157
158                 renderPassCreateInfo.addAttachment(AttachmentDescription(m_depthStencilAttachmentFormat,
159                                                                                                                                  vk::VK_SAMPLE_COUNT_1_BIT,
160                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_LOAD,
161                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_STORE,
162                                                                                                                                  vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
163                                                                                                                                  vk::VK_ATTACHMENT_STORE_OP_STORE,
164                                                                                                                                  vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
165                                                                                                                                  vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
166
167                 const vk::VkAttachmentReference colorAttachmentReference =
168                 {
169                         0,
170                         vk::VK_IMAGE_LAYOUT_GENERAL
171                 };
172
173                 const vk::VkAttachmentReference depthAttachmentReference =
174                 {
175                         1,
176                         vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
177                 };
178
179                 renderPassCreateInfo.addSubpass(SubpassDescription(
180                         vk::VK_PIPELINE_BIND_POINT_GRAPHICS,
181                         0,
182                         0,
183                         DE_NULL,
184                         1,
185                         &colorAttachmentReference,
186                         DE_NULL,
187                         depthAttachmentReference,
188                         0,
189                         DE_NULL));
190
191                 m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo);
192
193                 const vk::VkVertexInputBindingDescription vertexInputBindingDescription =
194                 {
195                         0,
196                         (deUint32)sizeof(tcu::Vec4) * 2,
197                         vk::VK_VERTEX_INPUT_RATE_VERTEX,
198                 };
199
200                 const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
201                 {
202                         {
203                                 0u,
204                                 0u,
205                                 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
206                                 0u
207                         },
208                         {
209                                 1u,
210                                 0u,
211                                 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
212                                 (deUint32)(sizeof(float)* 4),
213                         }
214                 };
215
216                 m_vertexInputState = PipelineCreateInfo::VertexInputState(
217                         1,
218                         &vertexInputBindingDescription,
219                         2,
220                         vertexInputAttributeDescriptions);
221
222                 const PipelineCreateInfo::ColorBlendState::Attachment vkCbAttachmentState;
223
224                 PipelineCreateInfo pipelineCreateInfo_1(*m_pipelineLayout, *m_renderPass, 0, 0);
225                 pipelineCreateInfo_1.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
226                 pipelineCreateInfo_1.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
227                 pipelineCreateInfo_1.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
228                 pipelineCreateInfo_1.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
229                 pipelineCreateInfo_1.addState(PipelineCreateInfo::ColorBlendState(1, &vkCbAttachmentState));
230                 pipelineCreateInfo_1.addState(PipelineCreateInfo::ViewportState(1));
231                 pipelineCreateInfo_1.addState(m_depthStencilState_1);
232                 pipelineCreateInfo_1.addState(PipelineCreateInfo::RasterizerState());
233                 pipelineCreateInfo_1.addState(PipelineCreateInfo::MultiSampleState());
234                 pipelineCreateInfo_1.addState(PipelineCreateInfo::DynamicState());
235
236                 PipelineCreateInfo pipelineCreateInfo_2(*m_pipelineLayout, *m_renderPass, 0, 0);
237                 pipelineCreateInfo_2.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
238                 pipelineCreateInfo_2.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
239                 pipelineCreateInfo_2.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
240                 pipelineCreateInfo_2.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
241                 pipelineCreateInfo_2.addState(PipelineCreateInfo::ColorBlendState(1, &vkCbAttachmentState));
242                 pipelineCreateInfo_2.addState(PipelineCreateInfo::ViewportState(1));
243                 pipelineCreateInfo_2.addState(m_depthStencilState_2);
244                 pipelineCreateInfo_2.addState(PipelineCreateInfo::RasterizerState());
245                 pipelineCreateInfo_2.addState(PipelineCreateInfo::MultiSampleState());
246                 pipelineCreateInfo_2.addState(PipelineCreateInfo::DynamicState());
247
248                 m_pipeline_1 = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo_1);
249                 m_pipeline_2 = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo_2);
250
251                 std::vector<vk::VkImageView> attachments(2);
252                 attachments[0] = *m_colorTargetView;
253                 attachments[1] = *m_attachmentView;
254
255                 const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
256
257                 m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo);
258
259                 const vk::VkDeviceSize dataSize = m_data.size() * sizeof(PositionColorVertex);
260                 m_vertexBuffer = Buffer::createAndAlloc(m_vk, device, BufferCreateInfo(dataSize, vk::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT),
261                                                                                                 m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
262
263                 deUint8* ptr = reinterpret_cast<unsigned char *>(m_vertexBuffer->getBoundMemory().getHostPtr());
264                 deMemcpy(ptr, &m_data[0], (size_t)dataSize);
265
266                 vk::flushMappedMemoryRange(m_vk, device,
267                         m_vertexBuffer->getBoundMemory().getMemory(),
268                         m_vertexBuffer->getBoundMemory().getOffset(),
269                         sizeof(dataSize));
270
271                 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
272                 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
273
274                 const vk::VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
275                 {
276                         vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,     // VkStructureType                      sType;
277                         DE_NULL,                                                                                        // const void*                          pNext;
278                         *m_cmdPool,                                                                                     // VkCommandPool                        commandPool;
279                         vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY,                            // VkCommandBufferLevel         level;
280                         1u,                                                                                                     // deUint32                                     bufferCount;
281                 };
282                 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, &cmdBufferAllocateInfo);
283         }
284
285         virtual tcu::TestStatus iterate (void)
286         {
287                 DE_ASSERT(false);
288                 return tcu::TestStatus::fail("Implement iterate() method!");
289         }
290
291         void beginRenderPass (void)
292         {
293                 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
294                 beginRenderPassWithClearColor(clearColor);
295         }
296
297         void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
298         {
299                 const CmdBufferBeginInfo beginInfo;
300                 m_vk.beginCommandBuffer(*m_cmdBuffer, &beginInfo);
301
302                 initialTransitionColor2DImage(m_vk, *m_cmdBuffer, m_colorTargetImage->object(), vk::VK_IMAGE_LAYOUT_GENERAL);
303                 initialTransitionDepthStencil2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
304
305                 const ImageSubresourceRange subresourceRangeImage(vk::VK_IMAGE_ASPECT_COLOR_BIT);
306                 m_vk.cmdClearColorImage(*m_cmdBuffer, m_colorTargetImage->object(),
307                         vk::VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &subresourceRangeImage);
308
309                 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
310
311                 const ImageSubresourceRange subresourceRangeDepthStencil[2] = { vk::VK_IMAGE_ASPECT_DEPTH_BIT, vk::VK_IMAGE_ASPECT_STENCIL_BIT };
312                 m_vk.cmdClearDepthStencilImage(*m_cmdBuffer, m_depthStencilImage->object(),
313                         vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilClearValue, 2, subresourceRangeDepthStencil);
314
315                 const vk::VkRect2D renderArea = { { 0, 0 }, { WIDTH, HEIGHT } };
316                 const RenderPassBeginInfo renderPassBegin(*m_renderPass, *m_framebuffer, renderArea);
317
318                 m_vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBegin, vk::VK_SUBPASS_CONTENTS_INLINE);
319         }
320
321         void setDynamicViewportState (const deUint32 width, const deUint32 height)
322         {
323                 vk::VkViewport viewport;
324                 viewport.x = 0;
325                 viewport.y = 0;
326                 viewport.width = static_cast<float>(width);
327                 viewport.height = static_cast<float>(height);
328                 viewport.minDepth = 0.0f;
329                 viewport.maxDepth = 1.0f;
330
331                 m_vk.cmdSetViewport(*m_cmdBuffer, 1, &viewport);
332
333                 vk::VkRect2D scissor;
334                 scissor.offset.x = 0;
335                 scissor.offset.y = 0;
336                 scissor.extent.width = width;
337                 scissor.extent.height = height;
338                 m_vk.cmdSetScissor(*m_cmdBuffer, 1, &scissor);
339         }
340
341         void setDynamicViewportState(const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
342         {
343                 m_vk.cmdSetViewport(*m_cmdBuffer, viewportCount, pViewports);
344                 m_vk.cmdSetScissor(*m_cmdBuffer, viewportCount, pScissors);
345         }
346
347         void setDynamicRasterizationState(const float lineWidth = 1.0f,
348                                                            const float depthBiasConstantFactor = 0.0f,
349                                                            const float depthBiasClamp = 0.0f,
350                                                            const float depthBiasSlopeFactor = 0.0f)
351         {
352                 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
353                 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
354         }
355
356         void setDynamicBlendState(const float const1 = 0.0f, const float const2 = 0.0f,
357                                                           const float const3 = 0.0f, const float const4 = 0.0f)
358         {
359                 float blendConstantsants[4] = { const1, const2, const3, const4 };
360                 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
361         }
362
363         void setDynamicDepthStencilState(const float minDepthBounds = -1.0f,
364                                                                          const float maxDepthBounds = 1.0f,
365                                                                          const deUint32 stencilFrontCompareMask = 0xffffffffu,
366                                                                          const deUint32 stencilFrontWriteMask = 0xffffffffu,
367                                                                          const deUint32 stencilFrontReference = 0,
368                                                                          const deUint32 stencilBackCompareMask = 0xffffffffu,
369                                                                          const deUint32 stencilBackWriteMask = 0xffffffffu,
370                                                                          const deUint32 stencilBackReference = 0)
371         {
372                 m_vk.cmdSetDepthBounds(*m_cmdBuffer, minDepthBounds, maxDepthBounds);
373                 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontCompareMask);
374                 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontWriteMask);
375                 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontReference);
376                 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackCompareMask);
377                 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackWriteMask);
378                 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackReference);
379         }
380 };
381
382 class DepthBoundsParamTestInstance : public DepthStencilBaseCase
383 {
384 public:
385         DepthBoundsParamTestInstance (Context &context, ShaderMap shaders)
386                 : DepthStencilBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
387         {
388                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.375f, 1.0f), tcu::RGBA::green().toVec()));
389                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.0f, 1.0f, 0.375f, 1.0f), tcu::RGBA::green().toVec()));
390                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.375f, 1.0f), tcu::RGBA::green().toVec()));
391                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.0f, -1.0f, 0.375f, 1.0f), tcu::RGBA::green().toVec()));
392
393                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.0f, 1.0f, 0.625f, 1.0f), tcu::RGBA::green().toVec()));
394                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.625f, 1.0f), tcu::RGBA::green().toVec()));
395                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.0f, -1.0f, 0.625f, 1.0f), tcu::RGBA::green().toVec()));
396                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.625f, 1.0f), tcu::RGBA::green().toVec()));
397
398                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
399                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
400                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
401                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
402
403                 m_depthStencilState_1 = PipelineCreateInfo::DepthStencilState(
404                         vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_ALWAYS, vk::VK_FALSE);
405
406
407                 // Check if depth bounds test is supported
408                 {
409                         const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
410
411                         if (!deviceFeatures.depthBounds)
412                                 throw tcu::NotSupportedError("Depth bounds test is unsupported");
413                 }
414
415                 // enable depth bounds test
416                 m_depthStencilState_2 = PipelineCreateInfo::DepthStencilState(
417                         vk::VK_FALSE, vk::VK_FALSE, vk::VK_COMPARE_OP_NEVER, vk::VK_TRUE);
418
419                 DepthStencilBaseCase::initialize();
420         }
421
422         virtual tcu::TestStatus iterate (void)
423         {
424                 tcu::TestLog &log = m_context.getTestContext().getLog();
425                 const vk::VkQueue queue = m_context.getUniversalQueue();
426
427                 beginRenderPass();
428
429                 // set states here
430                 setDynamicViewportState(WIDTH, HEIGHT);
431                 setDynamicRasterizationState();
432                 setDynamicBlendState();
433                 setDynamicDepthStencilState(0.5f, 0.75f);
434
435                 const vk::VkDeviceSize vertexBufferOffset = 0;
436                 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
437                 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
438
439                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_1);
440                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
441                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
442
443                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_2);
444                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
445
446                 m_vk.cmdEndRenderPass(*m_cmdBuffer);
447                 m_vk.endCommandBuffer(*m_cmdBuffer);
448
449                 vk::VkSubmitInfo submitInfo =
450                 {
451                         vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,      // VkStructureType                      sType;
452                         DE_NULL,                                                        // const void*                          pNext;
453                         0,                                                                      // deUint32                                     waitSemaphoreCount;
454                         DE_NULL,                                                        // const VkSemaphore*           pWaitSemaphores;
455                         1,                                                                      // deUint32                                     commandBufferCount;
456                         &m_cmdBuffer.get(),                                     // const VkCommandBuffer*       pCommandBuffers;
457                         0,                                                                      // deUint32                                     signalSemaphoreCount;
458                         DE_NULL                                                         // const VkSemaphore*           pSignalSemaphores;
459                 };
460                 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
461
462                 // validation
463                 {
464                         VK_CHECK(m_vk.queueWaitIdle(queue));
465
466                         tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
467                         referenceFrame.allocLevel(0);
468
469                         const deInt32 frameWidth = referenceFrame.getWidth();
470                         const deInt32 frameHeight = referenceFrame.getHeight();
471
472                         tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
473
474                         for (int y = 0; y < frameHeight; y++)
475                         {
476                                 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
477
478                                 for (int x = 0; x < frameWidth; x++)
479                                 {
480                                         const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
481
482                                         if (xCoord >= 0.0f && xCoord <= 1.0f && yCoord >= -1.0f && yCoord <= 1.0f)
483                                                 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
484                                         else
485                                                 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
486                                 }
487                         }
488
489                         const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
490                         const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
491                                 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
492
493                         if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
494                                 referenceFrame.getLevel(0), renderedFrame, 0.05f,
495                                 tcu::COMPARE_LOG_RESULT))
496                         {
497                                 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
498                         }
499
500                         return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
501                 }
502         }
503 };
504
505 class StencilParamsBasicTestInstance : public DepthStencilBaseCase
506 {
507 protected:
508         deUint32 m_writeMask;
509         deUint32 m_readMask;
510         deUint32 m_expectedValue;
511         tcu::Vec4 m_expectedColor;
512
513 public:
514         StencilParamsBasicTestInstance (Context& context, const char* vertexShaderName, const char* fragmentShaderName,
515                                                                         const deUint32 writeMask, const deUint32 readMask,
516                                                                         const deUint32 expectedValue, const tcu::Vec4 expectedColor)
517                 : DepthStencilBaseCase  (context, vertexShaderName, fragmentShaderName)
518                 , m_expectedColor               (1.0f, 1.0f, 1.0f, 1.0f)
519         {
520                 m_writeMask = writeMask;
521                 m_readMask = readMask;
522                 m_expectedValue = expectedValue;
523                 m_expectedColor = expectedColor;
524
525                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
526                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
527                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
528                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
529
530                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
531                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
532                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
533                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
534
535                 const PipelineCreateInfo::DepthStencilState::StencilOpState frontState_1 =
536                         PipelineCreateInfo::DepthStencilState::StencilOpState(
537                         vk::VK_STENCIL_OP_REPLACE,
538                         vk::VK_STENCIL_OP_REPLACE,
539                         vk::VK_STENCIL_OP_REPLACE,
540                         vk::VK_COMPARE_OP_ALWAYS);
541
542                 const PipelineCreateInfo::DepthStencilState::StencilOpState backState_1 =
543                         PipelineCreateInfo::DepthStencilState::StencilOpState(
544                         vk::VK_STENCIL_OP_REPLACE,
545                         vk::VK_STENCIL_OP_REPLACE,
546                         vk::VK_STENCIL_OP_REPLACE,
547                         vk::VK_COMPARE_OP_ALWAYS);
548
549                 const PipelineCreateInfo::DepthStencilState::StencilOpState frontState_2 =
550                         PipelineCreateInfo::DepthStencilState::StencilOpState(
551                         vk::VK_STENCIL_OP_REPLACE,
552                         vk::VK_STENCIL_OP_REPLACE,
553                         vk::VK_STENCIL_OP_REPLACE,
554                         vk::VK_COMPARE_OP_EQUAL);
555
556                 const PipelineCreateInfo::DepthStencilState::StencilOpState backState_2 =
557                         PipelineCreateInfo::DepthStencilState::StencilOpState(
558                         vk::VK_STENCIL_OP_REPLACE,
559                         vk::VK_STENCIL_OP_REPLACE,
560                         vk::VK_STENCIL_OP_REPLACE,
561                         vk::VK_COMPARE_OP_EQUAL);
562
563                 // enable stencil test
564                 m_depthStencilState_1 = PipelineCreateInfo::DepthStencilState(
565                         vk::VK_FALSE, vk::VK_FALSE, vk::VK_COMPARE_OP_NEVER, vk::VK_FALSE, vk::VK_TRUE, frontState_1, backState_1);
566
567                 m_depthStencilState_2 = PipelineCreateInfo::DepthStencilState(
568                         vk::VK_FALSE, vk::VK_FALSE, vk::VK_COMPARE_OP_NEVER, vk::VK_FALSE, vk::VK_TRUE, frontState_2, backState_2);
569
570                 DepthStencilBaseCase::initialize();
571         }
572
573         virtual tcu::TestStatus iterate (void)
574         {
575                 tcu::TestLog &log = m_context.getTestContext().getLog();
576                 const vk::VkQueue queue = m_context.getUniversalQueue();
577
578                 beginRenderPass();
579
580                 // set states here
581                 setDynamicViewportState(WIDTH, HEIGHT);
582                 setDynamicRasterizationState();
583                 setDynamicBlendState();
584
585                 const vk::VkDeviceSize vertexBufferOffset = 0;
586                 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
587                 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
588
589                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_1);
590                 setDynamicDepthStencilState(-1.0f, 1.0f, 0xFF, m_writeMask, 0x0F, 0xFF, m_writeMask, 0x0F);
591                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
592
593                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_2);
594                 setDynamicDepthStencilState(-1.0f, 1.0f, m_readMask, 0xFF, m_expectedValue, m_readMask, 0xFF, m_expectedValue);
595                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
596
597                 m_vk.cmdEndRenderPass(*m_cmdBuffer);
598                 m_vk.endCommandBuffer(*m_cmdBuffer);
599
600                 vk::VkSubmitInfo submitInfo =
601                 {
602                         vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,      // VkStructureType                      sType;
603                         DE_NULL,                                                        // const void*                          pNext;
604                         0,                                                                      // deUint32                                     waitSemaphoreCount;
605                         DE_NULL,                                                        // const VkSemaphore*           pWaitSemaphores;
606                         1,                                                                      // deUint32                                     commandBufferCount;
607                         &m_cmdBuffer.get(),                                     // const VkCommandBuffer*       pCommandBuffers;
608                         0,                                                                      // deUint32                                     signalSemaphoreCount;
609                         DE_NULL                                                         // const VkSemaphore*           pSignalSemaphores;
610                 };
611                 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
612
613                 // validation
614                 {
615                         VK_CHECK(m_vk.queueWaitIdle(queue));
616
617                         tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
618                         referenceFrame.allocLevel(0);
619
620                         const deInt32 frameWidth = referenceFrame.getWidth();
621                         const deInt32 frameHeight = referenceFrame.getHeight();
622
623                         for (int y = 0; y < frameHeight; y++)
624                         {
625                                 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
626
627                                 for (int x = 0; x < frameWidth; x++)
628                                 {
629                                         const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
630
631                                         if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -1.0f && yCoord <= 1.0f)
632                                                 referenceFrame.getLevel(0).setPixel(m_expectedColor, x, y);
633                                 }
634                         }
635
636                         const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
637                         const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
638                                 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
639
640                         if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
641                                 referenceFrame.getLevel(0), renderedFrame, 0.05f,
642                                 tcu::COMPARE_LOG_RESULT))
643                         {
644                                 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
645                         }
646
647                         return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
648                 }
649         }
650 };
651
652 class StencilParamsBasicTestCase : public TestCase
653 {
654 protected:
655         TestInstance* createInstance(Context& context) const
656         {
657                 return new StencilParamsBasicTestInstance(context, "VertexFetch.vert", "VertexFetch.frag",
658                         m_writeMask, m_readMask, m_expectedValue, m_expectedColor);
659         }
660
661         virtual void initPrograms(vk::SourceCollections& programCollection) const
662         {
663                 programCollection.glslSources.add("VertexFetch.vert") <<
664                         glu::VertexSource(ShaderSourceProvider::getSource(m_testCtx.getArchive(), "vulkan/dynamic_state/VertexFetch.vert"));
665
666                 programCollection.glslSources.add("VertexFetch.frag") <<
667                         glu::FragmentSource(ShaderSourceProvider::getSource(m_testCtx.getArchive(), "vulkan/dynamic_state/VertexFetch.frag"));
668         }
669
670         deUint32 m_writeMask;
671         deUint32 m_readMask;
672         deUint32 m_expectedValue;
673         tcu::Vec4 m_expectedColor;
674
675 public:
676         StencilParamsBasicTestCase (tcu::TestContext& context, const char *name, const char *description,
677                                                                 const deUint32 writeMask, const deUint32 readMask,
678                                                                 const deUint32 expectedValue, const tcu::Vec4 expectedColor)
679                 : TestCase                              (context, name, description)
680                 , m_writeMask                   (writeMask)
681                 , m_readMask                    (readMask)
682                 , m_expectedValue               (expectedValue)
683                 , m_expectedColor               (expectedColor)
684         {
685         }
686 };
687
688 class StencilParamsAdvancedTestInstance : public DepthStencilBaseCase
689 {
690 public:
691         StencilParamsAdvancedTestInstance (Context& context, ShaderMap shaders)
692                 : DepthStencilBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
693         {
694                 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
695                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
696                 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
697                 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
698
699                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
700                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
701                 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
702                 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::blue().toVec()));
703
704                 const PipelineCreateInfo::DepthStencilState::StencilOpState frontState_1 =
705                         PipelineCreateInfo::DepthStencilState::StencilOpState(
706                         vk::VK_STENCIL_OP_REPLACE,
707                         vk::VK_STENCIL_OP_REPLACE,
708                         vk::VK_STENCIL_OP_REPLACE,
709                         vk::VK_COMPARE_OP_ALWAYS);
710
711                 const PipelineCreateInfo::DepthStencilState::StencilOpState backState_1 =
712                         PipelineCreateInfo::DepthStencilState::StencilOpState(
713                         vk::VK_STENCIL_OP_REPLACE,
714                         vk::VK_STENCIL_OP_REPLACE,
715                         vk::VK_STENCIL_OP_REPLACE,
716                         vk::VK_COMPARE_OP_ALWAYS);
717
718                 const PipelineCreateInfo::DepthStencilState::StencilOpState frontState_2 =
719                         PipelineCreateInfo::DepthStencilState::StencilOpState(
720                         vk::VK_STENCIL_OP_REPLACE,
721                         vk::VK_STENCIL_OP_REPLACE,
722                         vk::VK_STENCIL_OP_REPLACE,
723                         vk::VK_COMPARE_OP_NOT_EQUAL);
724
725                 const PipelineCreateInfo::DepthStencilState::StencilOpState backState_2 =
726                         PipelineCreateInfo::DepthStencilState::StencilOpState(
727                         vk::VK_STENCIL_OP_REPLACE,
728                         vk::VK_STENCIL_OP_REPLACE,
729                         vk::VK_STENCIL_OP_REPLACE,
730                         vk::VK_COMPARE_OP_NOT_EQUAL);
731
732                 // enable stencil test
733                 m_depthStencilState_1 = PipelineCreateInfo::DepthStencilState(
734                         vk::VK_FALSE, vk::VK_FALSE, vk::VK_COMPARE_OP_NEVER, vk::VK_FALSE, vk::VK_TRUE, frontState_1, backState_1);
735
736                 m_depthStencilState_2 = PipelineCreateInfo::DepthStencilState(
737                         vk::VK_FALSE, vk::VK_FALSE, vk::VK_COMPARE_OP_NEVER, vk::VK_FALSE, vk::VK_TRUE, frontState_2, backState_2);
738
739                 DepthStencilBaseCase::initialize();
740         }
741
742         virtual tcu::TestStatus iterate (void)
743         {
744                 tcu::TestLog &log = m_context.getTestContext().getLog();
745                 const vk::VkQueue queue = m_context.getUniversalQueue();
746
747                 beginRenderPass();
748
749                 // set states here
750                 setDynamicViewportState(WIDTH, HEIGHT);
751                 setDynamicRasterizationState();
752                 setDynamicBlendState();
753
754                 const vk::VkDeviceSize vertexBufferOffset = 0;
755                 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
756                 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
757
758                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_1);
759                 setDynamicDepthStencilState(-1.0f, 1.0f, 0xFF, 0x0E, 0x0F, 0xFF, 0x0E, 0x0F);
760                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
761
762                 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline_2);
763                 setDynamicDepthStencilState(-1.0f, 1.0f, 0xFF, 0xFF, 0x0E, 0xFF, 0xFF, 0x0E);
764                 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
765
766                 m_vk.cmdEndRenderPass(*m_cmdBuffer);
767                 m_vk.endCommandBuffer(*m_cmdBuffer);
768
769                 vk::VkSubmitInfo submitInfo =
770                 {
771                         vk::VK_STRUCTURE_TYPE_SUBMIT_INFO,      // VkStructureType                      sType;
772                         DE_NULL,                                                        // const void*                          pNext;
773                         0,                                                                      // deUint32                                     waitSemaphoreCount;
774                         DE_NULL,                                                        // const VkSemaphore*           pWaitSemaphores;
775                         1,                                                                      // deUint32                                     commandBufferCount;
776                         &m_cmdBuffer.get(),                                     // const VkCommandBuffer*       pCommandBuffers;
777                         0,                                                                      // deUint32                                     signalSemaphoreCount;
778                         DE_NULL                                                         // const VkSemaphore*           pSignalSemaphores;
779                 };
780                 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
781
782                 // validation
783                 {
784                         VK_CHECK(m_vk.queueWaitIdle(queue));
785
786                         tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
787                         referenceFrame.allocLevel(0);
788
789                         const deInt32 frameWidth = referenceFrame.getWidth();
790                         const deInt32 frameHeight = referenceFrame.getHeight();
791
792                         for (int y = 0; y < frameHeight; y++)
793                         {
794                                 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
795
796                                 for (int x = 0; x < frameWidth; x++)
797                                 {
798                                         const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
799
800                                         if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
801                                                 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
802                                         else
803                                                 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
804                                 }
805                         }
806
807                         const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
808                         const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
809                                 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
810
811                         if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
812                                 referenceFrame.getLevel(0), renderedFrame, 0.05f,
813                                 tcu::COMPARE_LOG_RESULT))
814                         {
815                                 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
816                         }
817
818                         return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
819                 }
820         }
821 };
822
823 } //anonymous
824
825 DynamicStateDSTests::DynamicStateDSTests (tcu::TestContext& testCtx)
826         : TestCaseGroup (testCtx, "ds_state", "Tests for depth stencil state")
827 {
828         /* Left blank on purpose */
829 }
830
831 DynamicStateDSTests::~DynamicStateDSTests ()
832 {
833 }
834
835 void DynamicStateDSTests::init (void)
836 {
837         ShaderMap shaderPaths;
838         shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
839         shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
840
841         addChild(new InstanceFactory<DepthBoundsParamTestInstance>(m_testCtx, "depth_bounds", "Perform depth bounds test", shaderPaths));
842         addChild(new StencilParamsBasicTestCase(m_testCtx, "stencil_params_basic_1", "Perform basic stencil test 1", 0x0D, 0x06, 0x05, tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f)));
843         addChild(new StencilParamsBasicTestCase(m_testCtx, "stencil_params_basic_2", "Perform basic stencil test 2", 0x06, 0x02, 0x05, tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f)));
844         addChild(new InstanceFactory<StencilParamsAdvancedTestInstance>(m_testCtx, "stencil_params_advanced", "Perform advanced stencil test", shaderPaths));
845 }
846
847 } // DynamicState
848 } // vkt