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