1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Dynamic State Depth Stencil Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktDynamicStateDSTests.hpp"
38 #include "vktTestCaseUtil.hpp"
39 #include "vktDynamicStateTestCaseUtil.hpp"
41 #include "tcuTestLog.hpp"
42 #include "tcuResource.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuCommandLine.hpp"
45 #include "tcuTextureUtil.hpp"
46 #include "tcuRGBA.hpp"
48 #include "vkRefUtil.hpp"
49 #include "vkImageUtil.hpp"
51 #include "vktDynamicStateCreateInfoUtil.hpp"
52 #include "vktDynamicStateImageObjectUtil.hpp"
53 #include "vktDynamicStateBufferObjectUtil.hpp"
54 #include "vkPrograms.hpp"
58 namespace DynamicState
64 class DepthStencilBaseCase : public TestInstance
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)
86 vk::VkFormat m_colorAttachmentFormat;
87 vk::VkFormat m_depthStencilAttachmentFormat;
89 vk::VkPrimitiveTopology m_topology;
91 const vk::DeviceInterface& m_vk;
93 vk::Move<vk::VkPipeline> m_pipeline_1;
94 vk::Move<vk::VkPipeline> m_pipeline_2;
95 vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
97 de::SharedPtr<Image> m_colorTargetImage;
98 vk::Move<vk::VkImageView> m_colorTargetView;
100 de::SharedPtr<Image> m_depthStencilImage;
101 vk::Move<vk::VkImageView> m_attachmentView;
103 PipelineCreateInfo::VertexInputState m_vertexInputState;
104 de::SharedPtr<Buffer> m_vertexBuffer;
106 vk::Move<vk::VkCommandPool> m_cmdPool;
107 vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
109 vk::Move<vk::VkFramebuffer> m_framebuffer;
110 vk::Move<vk::VkRenderPass> m_renderPass;
112 const std::string m_vertexShaderName;
113 const std::string m_fragmentShaderName;
115 std::vector<PositionColorVertex> m_data;
117 PipelineCreateInfo::DepthStencilState m_depthStencilState_1;
118 PipelineCreateInfo::DepthStencilState m_depthStencilState_2;
120 void initialize (void)
122 const vk::VkDevice device = m_context.getDevice();
124 const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
125 m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo);
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));
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);
134 m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator());
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);
140 m_depthStencilImage = Image::createAndAlloc(m_vk, device, depthStencilImageCreateInfo, m_context.getDefaultAllocator());
142 const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
143 m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo);
145 const ImageViewCreateInfo attachmentViewInfo(m_depthStencilImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_depthStencilAttachmentFormat);
146 m_attachmentView = vk::createImageView(m_vk, device, &attachmentViewInfo);
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));
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));
167 const vk::VkAttachmentReference colorAttachmentReference =
170 vk::VK_IMAGE_LAYOUT_GENERAL
173 const vk::VkAttachmentReference depthAttachmentReference =
176 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
179 renderPassCreateInfo.addSubpass(SubpassDescription(
180 vk::VK_PIPELINE_BIND_POINT_GRAPHICS,
185 &colorAttachmentReference,
187 depthAttachmentReference,
191 m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo);
193 const vk::VkVertexInputBindingDescription vertexInputBindingDescription =
196 (deUint32)sizeof(tcu::Vec4) * 2,
197 vk::VK_VERTEX_INPUT_RATE_VERTEX,
200 const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
205 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
211 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
212 (deUint32)(sizeof(float)* 4),
216 m_vertexInputState = PipelineCreateInfo::VertexInputState(
218 &vertexInputBindingDescription,
220 vertexInputAttributeDescriptions);
222 const PipelineCreateInfo::ColorBlendState::Attachment vkCbAttachmentState;
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());
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());
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);
251 std::vector<vk::VkImageView> attachments(2);
252 attachments[0] = *m_colorTargetView;
253 attachments[1] = *m_attachmentView;
255 const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
257 m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo);
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);
263 deUint8* ptr = reinterpret_cast<unsigned char *>(m_vertexBuffer->getBoundMemory().getHostPtr());
264 deMemcpy(ptr, &m_data[0], (size_t)dataSize);
266 vk::flushMappedMemoryRange(m_vk, device,
267 m_vertexBuffer->getBoundMemory().getMemory(),
268 m_vertexBuffer->getBoundMemory().getOffset(),
271 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
272 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
274 const vk::VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
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;
282 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, &cmdBufferAllocateInfo);
285 virtual tcu::TestStatus iterate (void)
288 return tcu::TestStatus::fail("Implement iterate() method!");
291 void beginRenderPass (void)
293 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
294 beginRenderPassWithClearColor(clearColor);
297 void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
299 const CmdBufferBeginInfo beginInfo;
300 m_vk.beginCommandBuffer(*m_cmdBuffer, &beginInfo);
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);
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);
309 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
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);
315 const vk::VkRect2D renderArea = { { 0, 0 }, { WIDTH, HEIGHT } };
316 const RenderPassBeginInfo renderPassBegin(*m_renderPass, *m_framebuffer, renderArea);
318 m_vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBegin, vk::VK_SUBPASS_CONTENTS_INLINE);
321 void setDynamicViewportState (const deUint32 width, const deUint32 height)
323 vk::VkViewport viewport;
326 viewport.width = static_cast<float>(width);
327 viewport.height = static_cast<float>(height);
328 viewport.minDepth = 0.0f;
329 viewport.maxDepth = 1.0f;
331 m_vk.cmdSetViewport(*m_cmdBuffer, 1, &viewport);
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);
341 void setDynamicViewportState(const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
343 m_vk.cmdSetViewport(*m_cmdBuffer, viewportCount, pViewports);
344 m_vk.cmdSetScissor(*m_cmdBuffer, viewportCount, pScissors);
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)
352 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
353 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
356 void setDynamicBlendState(const float const1 = 0.0f, const float const2 = 0.0f,
357 const float const3 = 0.0f, const float const4 = 0.0f)
359 float blendConstantsants[4] = { const1, const2, const3, const4 };
360 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
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)
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);
382 class DepthBoundsParamTestInstance : public DepthStencilBaseCase
385 DepthBoundsParamTestInstance (Context &context, ShaderMap shaders)
386 : DepthStencilBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
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()));
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()));
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()));
403 m_depthStencilState_1 = PipelineCreateInfo::DepthStencilState(
404 vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_ALWAYS, vk::VK_FALSE);
407 // Check if depth bounds test is supported
409 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
411 if (!deviceFeatures.depthBounds)
412 throw tcu::NotSupportedError("Depth bounds test is unsupported");
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);
419 DepthStencilBaseCase::initialize();
422 virtual tcu::TestStatus iterate (void)
424 tcu::TestLog &log = m_context.getTestContext().getLog();
425 const vk::VkQueue queue = m_context.getUniversalQueue();
430 setDynamicViewportState(WIDTH, HEIGHT);
431 setDynamicRasterizationState();
432 setDynamicBlendState();
433 setDynamicDepthStencilState(0.5f, 0.75f);
435 const vk::VkDeviceSize vertexBufferOffset = 0;
436 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
437 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
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);
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);
446 m_vk.cmdEndRenderPass(*m_cmdBuffer);
447 m_vk.endCommandBuffer(*m_cmdBuffer);
449 vk::VkSubmitInfo submitInfo =
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;
460 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
464 VK_CHECK(m_vk.queueWaitIdle(queue));
466 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
467 referenceFrame.allocLevel(0);
469 const deInt32 frameWidth = referenceFrame.getWidth();
470 const deInt32 frameHeight = referenceFrame.getHeight();
472 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
474 for (int y = 0; y < frameHeight; y++)
476 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
478 for (int x = 0; x < frameWidth; x++)
480 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
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);
485 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
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);
493 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
494 referenceFrame.getLevel(0), renderedFrame, 0.05f,
495 tcu::COMPARE_LOG_RESULT))
497 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
500 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
505 class StencilParamsBasicTestInstance : public DepthStencilBaseCase
508 deUint32 m_writeMask;
510 deUint32 m_expectedValue;
511 tcu::Vec4 m_expectedColor;
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)
520 m_writeMask = writeMask;
521 m_readMask = readMask;
522 m_expectedValue = expectedValue;
523 m_expectedColor = expectedColor;
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()));
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()));
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);
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);
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);
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);
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);
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);
570 DepthStencilBaseCase::initialize();
573 virtual tcu::TestStatus iterate (void)
575 tcu::TestLog &log = m_context.getTestContext().getLog();
576 const vk::VkQueue queue = m_context.getUniversalQueue();
581 setDynamicViewportState(WIDTH, HEIGHT);
582 setDynamicRasterizationState();
583 setDynamicBlendState();
585 const vk::VkDeviceSize vertexBufferOffset = 0;
586 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
587 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
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);
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);
597 m_vk.cmdEndRenderPass(*m_cmdBuffer);
598 m_vk.endCommandBuffer(*m_cmdBuffer);
600 vk::VkSubmitInfo submitInfo =
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;
611 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
615 VK_CHECK(m_vk.queueWaitIdle(queue));
617 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
618 referenceFrame.allocLevel(0);
620 const deInt32 frameWidth = referenceFrame.getWidth();
621 const deInt32 frameHeight = referenceFrame.getHeight();
623 for (int y = 0; y < frameHeight; y++)
625 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
627 for (int x = 0; x < frameWidth; x++)
629 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
631 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -1.0f && yCoord <= 1.0f)
632 referenceFrame.getLevel(0).setPixel(m_expectedColor, x, y);
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);
640 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
641 referenceFrame.getLevel(0), renderedFrame, 0.05f,
642 tcu::COMPARE_LOG_RESULT))
644 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
647 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
652 class StencilParamsBasicTestCase : public TestCase
655 TestInstance* createInstance(Context& context) const
657 return new StencilParamsBasicTestInstance(context, "VertexFetch.vert", "VertexFetch.frag",
658 m_writeMask, m_readMask, m_expectedValue, m_expectedColor);
661 virtual void initPrograms(vk::SourceCollections& programCollection) const
663 programCollection.glslSources.add("VertexFetch.vert") <<
664 glu::VertexSource(ShaderSourceProvider::getSource(m_testCtx.getArchive(), "vulkan/dynamic_state/VertexFetch.vert"));
666 programCollection.glslSources.add("VertexFetch.frag") <<
667 glu::FragmentSource(ShaderSourceProvider::getSource(m_testCtx.getArchive(), "vulkan/dynamic_state/VertexFetch.frag"));
670 deUint32 m_writeMask;
672 deUint32 m_expectedValue;
673 tcu::Vec4 m_expectedColor;
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)
688 class StencilParamsAdvancedTestInstance : public DepthStencilBaseCase
691 StencilParamsAdvancedTestInstance (Context& context, ShaderMap shaders)
692 : DepthStencilBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
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()));
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()));
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);
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);
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);
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);
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);
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);
739 DepthStencilBaseCase::initialize();
742 virtual tcu::TestStatus iterate (void)
744 tcu::TestLog &log = m_context.getTestContext().getLog();
745 const vk::VkQueue queue = m_context.getUniversalQueue();
750 setDynamicViewportState(WIDTH, HEIGHT);
751 setDynamicRasterizationState();
752 setDynamicBlendState();
754 const vk::VkDeviceSize vertexBufferOffset = 0;
755 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
756 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
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);
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);
766 m_vk.cmdEndRenderPass(*m_cmdBuffer);
767 m_vk.endCommandBuffer(*m_cmdBuffer);
769 vk::VkSubmitInfo submitInfo =
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;
780 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
784 VK_CHECK(m_vk.queueWaitIdle(queue));
786 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
787 referenceFrame.allocLevel(0);
789 const deInt32 frameWidth = referenceFrame.getWidth();
790 const deInt32 frameHeight = referenceFrame.getHeight();
792 for (int y = 0; y < frameHeight; y++)
794 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
796 for (int x = 0; x < frameWidth; x++)
798 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
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);
803 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
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);
811 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
812 referenceFrame.getLevel(0), renderedFrame, 0.05f,
813 tcu::COMPARE_LOG_RESULT))
815 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
818 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
825 DynamicStateDSTests::DynamicStateDSTests (tcu::TestContext& testCtx)
826 : TestCaseGroup (testCtx, "ds_state", "Tests for depth stencil state")
828 /* Left blank on purpose */
831 DynamicStateDSTests::~DynamicStateDSTests ()
835 void DynamicStateDSTests::init (void)
837 ShaderMap shaderPaths;
838 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
839 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
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));