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 Raster State Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktDynamicStateRSTests.hpp"
38 #include "vktDynamicStateBaseClass.hpp"
39 #include "vktDynamicStateTestCaseUtil.hpp"
41 #include "vkImageUtil.hpp"
43 #include "tcuTextureUtil.hpp"
44 #include "tcuImageCompare.hpp"
45 #include "tcuRGBA.hpp"
51 namespace DynamicState
56 class DepthBiasBaseCase : public TestInstance
59 DepthBiasBaseCase (Context& context, const char* vertexShaderName, const char* fragmentShaderName)
60 : TestInstance (context)
61 , m_colorAttachmentFormat (vk::VK_FORMAT_R8G8B8A8_UNORM)
62 , m_topology (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)
63 , m_vk (context.getDeviceInterface())
64 , m_vertexShaderName (vertexShaderName)
65 , m_fragmentShaderName (fragmentShaderName)
77 vk::VkFormat m_colorAttachmentFormat;
78 vk::VkFormat m_depthStencilAttachmentFormat;
80 vk::VkPrimitiveTopology m_topology;
82 const vk::DeviceInterface& m_vk;
84 vk::Move<vk::VkPipeline> m_pipeline;
85 vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
87 de::SharedPtr<Image> m_colorTargetImage;
88 vk::Move<vk::VkImageView> m_colorTargetView;
90 de::SharedPtr<Image> m_depthStencilImage;
91 vk::Move<vk::VkImageView> m_attachmentView;
93 PipelineCreateInfo::VertexInputState m_vertexInputState;
94 de::SharedPtr<Buffer> m_vertexBuffer;
96 vk::Move<vk::VkCommandPool> m_cmdPool;
97 vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
99 vk::Move<vk::VkFramebuffer> m_framebuffer;
100 vk::Move<vk::VkRenderPass> m_renderPass;
102 std::string m_vertexShaderName;
103 std::string m_fragmentShaderName;
105 std::vector<PositionColorVertex> m_data;
107 PipelineCreateInfo::DepthStencilState m_depthStencilState;
109 void initialize (void)
111 const vk::VkDevice device = m_context.getDevice();
113 vk::VkFormatProperties formatProperties;
114 // check for VK_FORMAT_D24_UNORM_S8_UINT support
115 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D24_UNORM_S8_UINT, &formatProperties);
116 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
118 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D24_UNORM_S8_UINT;
122 // check for VK_FORMAT_D32_SFLOAT_S8_UINT support
123 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D32_SFLOAT_S8_UINT, &formatProperties);
124 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
126 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D32_SFLOAT_S8_UINT;
129 throw tcu::NotSupportedError("No valid depth stencil attachment available");
132 const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
133 m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo);
135 const vk::Unique<vk::VkShaderModule> vs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
136 const vk::Unique<vk::VkShaderModule> fs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
138 const vk::VkExtent3D imageExtent = { WIDTH, HEIGHT, 1 };
139 ImageCreateInfo targetImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
140 vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
142 m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator());
144 const ImageCreateInfo depthStencilImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_depthStencilAttachmentFormat, imageExtent,
145 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
146 vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
148 m_depthStencilImage = Image::createAndAlloc(m_vk, device, depthStencilImageCreateInfo, m_context.getDefaultAllocator());
150 const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
151 m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo);
153 const ImageViewCreateInfo attachmentViewInfo(m_depthStencilImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_depthStencilAttachmentFormat);
154 m_attachmentView = vk::createImageView(m_vk, device, &attachmentViewInfo);
156 RenderPassCreateInfo renderPassCreateInfo;
157 renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,
158 vk::VK_SAMPLE_COUNT_1_BIT,
159 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
160 vk::VK_ATTACHMENT_STORE_OP_STORE,
161 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
162 vk::VK_ATTACHMENT_STORE_OP_STORE,
163 vk::VK_IMAGE_LAYOUT_GENERAL,
164 vk::VK_IMAGE_LAYOUT_GENERAL));
166 renderPassCreateInfo.addAttachment(AttachmentDescription(m_depthStencilAttachmentFormat,
167 vk::VK_SAMPLE_COUNT_1_BIT,
168 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
169 vk::VK_ATTACHMENT_STORE_OP_STORE,
170 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
171 vk::VK_ATTACHMENT_STORE_OP_STORE,
172 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
173 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
175 const vk::VkAttachmentReference colorAttachmentReference =
178 vk::VK_IMAGE_LAYOUT_GENERAL
181 const vk::VkAttachmentReference depthAttachmentReference =
184 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
187 renderPassCreateInfo.addSubpass(SubpassDescription(vk::VK_PIPELINE_BIND_POINT_GRAPHICS,
192 &colorAttachmentReference,
194 depthAttachmentReference,
198 m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo);
200 const vk::VkVertexInputBindingDescription vertexInputBindingDescription =
203 (deUint32)sizeof(tcu::Vec4) * 2,
204 vk::VK_VERTEX_INPUT_RATE_VERTEX,
207 const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
212 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
218 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
219 (deUint32)(sizeof(float)* 4),
223 m_vertexInputState = PipelineCreateInfo::VertexInputState(1,
224 &vertexInputBindingDescription,
226 vertexInputAttributeDescriptions);
228 const PipelineCreateInfo::ColorBlendState::Attachment vkCbAttachmentState;
230 PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, 0);
231 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
232 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
233 pipelineCreateInfo.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
234 pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
235 pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &vkCbAttachmentState));
236 pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1));
237 pipelineCreateInfo.addState(m_depthStencilState);
238 pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
239 pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
240 pipelineCreateInfo.addState(PipelineCreateInfo::DynamicState());
242 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo);
244 std::vector<vk::VkImageView> attachments(2);
245 attachments[0] = *m_colorTargetView;
246 attachments[1] = *m_attachmentView;
248 const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
250 m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo);
252 const vk::VkDeviceSize dataSize = m_data.size() * sizeof(PositionColorVertex);
253 m_vertexBuffer = Buffer::createAndAlloc(m_vk, device, BufferCreateInfo(dataSize,
254 vk::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT),
255 m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
257 deUint8* ptr = reinterpret_cast<unsigned char *>(m_vertexBuffer->getBoundMemory().getHostPtr());
258 deMemcpy(ptr, &m_data[0], static_cast<size_t>(dataSize));
260 vk::flushMappedMemoryRange(m_vk, device,
261 m_vertexBuffer->getBoundMemory().getMemory(),
262 m_vertexBuffer->getBoundMemory().getOffset(),
265 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
266 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
268 const vk::VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
270 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
271 DE_NULL, // const void* pNext;
272 *m_cmdPool, // VkCommandPool commandPool;
273 vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
274 1u, // deUint32 bufferCount;
276 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, &cmdBufferAllocateInfo);
279 virtual tcu::TestStatus iterate (void)
282 return tcu::TestStatus::fail("Should reimplement iterate() method");
285 void beginRenderPass (void)
287 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
288 beginRenderPassWithClearColor(clearColor);
291 void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
293 const CmdBufferBeginInfo beginInfo;
294 m_vk.beginCommandBuffer(*m_cmdBuffer, &beginInfo);
296 initialTransitionColor2DImage(m_vk, *m_cmdBuffer, m_colorTargetImage->object(), vk::VK_IMAGE_LAYOUT_GENERAL);
297 initialTransitionDepthStencil2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
299 const ImageSubresourceRange subresourceRangeImage(vk::VK_IMAGE_ASPECT_COLOR_BIT);
300 m_vk.cmdClearColorImage(*m_cmdBuffer, m_colorTargetImage->object(),
301 vk::VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &subresourceRangeImage);
303 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
305 const ImageSubresourceRange subresourceRangeDepthStencil[2] = { vk::VK_IMAGE_ASPECT_DEPTH_BIT, vk::VK_IMAGE_ASPECT_STENCIL_BIT };
306 m_vk.cmdClearDepthStencilImage(*m_cmdBuffer, m_depthStencilImage->object(),
307 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilClearValue, 2, subresourceRangeDepthStencil);
309 const vk::VkRect2D renderArea = { { 0, 0 }, { WIDTH, HEIGHT } };
310 const RenderPassBeginInfo renderPassBegin(*m_renderPass, *m_framebuffer, renderArea);
312 m_vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBegin, vk::VK_SUBPASS_CONTENTS_INLINE);
315 void setDynamicViewportState (const deUint32 width, const deUint32 height)
317 vk::VkViewport viewport;
320 viewport.width = static_cast<float>(width);
321 viewport.height = static_cast<float>(height);
322 viewport.minDepth = 0.0f;
323 viewport.maxDepth = 1.0f;
325 m_vk.cmdSetViewport(*m_cmdBuffer, 0, 1, &viewport);
327 vk::VkRect2D scissor;
328 scissor.offset.x = 0;
329 scissor.offset.y = 0;
330 scissor.extent.width = width;
331 scissor.extent.height = height;
332 m_vk.cmdSetScissor(*m_cmdBuffer, 0, 1, &scissor);
335 void setDynamicViewportState (const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
337 m_vk.cmdSetViewport(*m_cmdBuffer, 0, viewportCount, pViewports);
338 m_vk.cmdSetScissor(*m_cmdBuffer, 0, viewportCount, pScissors);
341 void setDynamicRasterizationState (const float lineWidth = 1.0f,
342 const float depthBiasConstantFactor = 0.0f,
343 const float depthBiasClamp = 0.0f,
344 const float depthBiasSlopeFactor = 0.0f)
346 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
347 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
350 void setDynamicBlendState (const float const1 = 0.0f, const float const2 = 0.0f,
351 const float const3 = 0.0f, const float const4 = 0.0f)
353 float blendConstantsants[4] = { const1, const2, const3, const4 };
354 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
357 void setDynamicDepthStencilState (const float minDepthBounds = -1.0f, const float maxDepthBounds = 1.0f,
358 const deUint32 stencilFrontCompareMask = 0xffffffffu, const deUint32 stencilFrontWriteMask = 0xffffffffu,
359 const deUint32 stencilFrontReference = 0, const deUint32 stencilBackCompareMask = 0xffffffffu,
360 const deUint32 stencilBackWriteMask = 0xffffffffu, const deUint32 stencilBackReference = 0)
362 m_vk.cmdSetDepthBounds(*m_cmdBuffer, minDepthBounds, maxDepthBounds);
363 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontCompareMask);
364 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontWriteMask);
365 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontReference);
366 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackCompareMask);
367 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackWriteMask);
368 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackReference);
372 class DepthBiasParamTestInstance : public DepthBiasBaseCase
375 DepthBiasParamTestInstance (Context& context, ShaderMap shaders)
376 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
378 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
379 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
380 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
381 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
383 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
384 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
385 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
386 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
388 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
389 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
390 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
391 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
394 m_depthStencilState = PipelineCreateInfo::DepthStencilState(
395 vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
397 DepthBiasBaseCase::initialize();
400 virtual tcu::TestStatus iterate (void)
402 tcu::TestLog &log = m_context.getTestContext().getLog();
403 const vk::VkQueue queue = m_context.getUniversalQueue();
408 setDynamicViewportState(WIDTH, HEIGHT);
409 setDynamicBlendState();
410 setDynamicDepthStencilState();
412 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
414 const vk::VkDeviceSize vertexBufferOffset = 0;
415 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
416 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
418 setDynamicRasterizationState(1.0f, 0.0f);
419 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
420 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
422 setDynamicRasterizationState(1.0f, -1.0f);
423 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
425 m_vk.cmdEndRenderPass(*m_cmdBuffer);
426 m_vk.endCommandBuffer(*m_cmdBuffer);
428 vk::VkSubmitInfo submitInfo =
430 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
431 DE_NULL, // const void* pNext;
432 0, // deUint32 waitSemaphoreCount;
433 DE_NULL, // const VkSemaphore* pWaitSemaphores;
434 (const vk::VkPipelineStageFlags*)DE_NULL,
435 1, // deUint32 commandBufferCount;
436 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
437 0, // deUint32 signalSemaphoreCount;
438 DE_NULL // const VkSemaphore* pSignalSemaphores;
440 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
444 VK_CHECK(m_vk.queueWaitIdle(queue));
446 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
447 referenceFrame.allocLevel(0);
449 const deInt32 frameWidth = referenceFrame.getWidth();
450 const deInt32 frameHeight = referenceFrame.getHeight();
452 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
454 for (int y = 0; y < frameHeight; y++)
456 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
458 for (int x = 0; x < frameWidth; x++)
460 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
462 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
463 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
465 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
469 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
470 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
471 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
473 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
474 referenceFrame.getLevel(0), renderedFrame, 0.05f,
475 tcu::COMPARE_LOG_RESULT))
477 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
480 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
485 class DepthBiasClampParamTestInstance : public DepthBiasBaseCase
488 DepthBiasClampParamTestInstance (Context& context, ShaderMap shaders)
489 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
491 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
492 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
493 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
494 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
496 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
497 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
498 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
499 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
502 m_depthStencilState = PipelineCreateInfo::DepthStencilState(vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
504 DepthBiasBaseCase::initialize();
507 virtual tcu::TestStatus iterate (void)
509 tcu::TestLog &log = m_context.getTestContext().getLog();
510 const vk::VkQueue queue = m_context.getUniversalQueue();
515 setDynamicViewportState(WIDTH, HEIGHT);
516 setDynamicBlendState();
517 setDynamicDepthStencilState();
519 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
521 const vk::VkDeviceSize vertexBufferOffset = 0;
522 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
523 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
525 setDynamicRasterizationState(1.0f, 1000.0f, 0.005f);
526 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
528 setDynamicRasterizationState(1.0f, 0.0f);
529 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
531 m_vk.cmdEndRenderPass(*m_cmdBuffer);
532 m_vk.endCommandBuffer(*m_cmdBuffer);
534 vk::VkSubmitInfo submitInfo =
536 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
537 DE_NULL, // const void* pNext;
538 0, // deUint32 waitSemaphoreCount;
539 DE_NULL, // const VkSemaphore* pWaitSemaphores;
540 (const vk::VkPipelineStageFlags*)DE_NULL,
541 1, // deUint32 commandBufferCount;
542 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
543 0, // deUint32 signalSemaphoreCount;
544 DE_NULL // const VkSemaphore* pSignalSemaphores;
546 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
550 VK_CHECK(m_vk.queueWaitIdle(queue));
552 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
553 referenceFrame.allocLevel(0);
555 const deInt32 frameWidth = referenceFrame.getWidth();
556 const deInt32 frameHeight = referenceFrame.getHeight();
558 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
560 for (int y = 0; y < frameHeight; y++)
562 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
564 for (int x = 0; x < frameWidth; x++)
566 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
568 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
569 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
571 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
575 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
576 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
577 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
579 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
580 referenceFrame.getLevel(0), renderedFrame, 0.05f,
581 tcu::COMPARE_LOG_RESULT))
583 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
586 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
591 class LineWidthParamTestInstance : public DynamicStateBaseClass
594 LineWidthParamTestInstance (Context& context, ShaderMap shaders)
595 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
597 // Check if line width test is supported
599 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
601 if (!deviceFeatures.wideLines)
602 throw tcu::NotSupportedError("Line width test is unsupported");
605 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
607 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
608 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
610 DynamicStateBaseClass::initialize();
613 virtual tcu::TestStatus iterate (void)
615 tcu::TestLog &log = m_context.getTestContext().getLog();
616 const vk::VkQueue queue = m_context.getUniversalQueue();
621 vk::VkPhysicalDeviceProperties deviceProperties;
622 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
624 setDynamicViewportState(WIDTH, HEIGHT);
625 setDynamicBlendState();
626 setDynamicDepthStencilState();
627 setDynamicRasterizationState(deFloatFloor(deviceProperties.limits.lineWidthRange[1]));
629 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
631 const vk::VkDeviceSize vertexBufferOffset = 0;
632 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
633 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
635 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
637 m_vk.cmdEndRenderPass(*m_cmdBuffer);
638 m_vk.endCommandBuffer(*m_cmdBuffer);
640 vk::VkSubmitInfo submitInfo =
642 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
643 DE_NULL, // const void* pNext;
644 0, // deUint32 waitSemaphoreCount;
645 DE_NULL, // const VkSemaphore* pWaitSemaphores;
646 (const vk::VkPipelineStageFlags*)DE_NULL,
647 1, // deUint32 commandBufferCount;
648 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
649 0, // deUint32 signalSemaphoreCount;
650 DE_NULL // const VkSemaphore* pSignalSemaphores;
652 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
656 VK_CHECK(m_vk.queueWaitIdle(queue));
658 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
659 referenceFrame.allocLevel(0);
661 const deInt32 frameWidth = referenceFrame.getWidth();
662 const deInt32 frameHeight = referenceFrame.getHeight();
664 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
666 for (int y = 0; y < frameHeight; y++)
668 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
670 for (int x = 0; x < frameWidth; x++)
672 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
673 float lineHalfWidth = (float)(deFloor(deviceProperties.limits.lineWidthRange[1]) / frameHeight);
675 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -lineHalfWidth && yCoord <= lineHalfWidth)
676 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
680 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
681 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
682 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT,
683 vk::VK_IMAGE_ASPECT_COLOR_BIT);
685 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
686 referenceFrame.getLevel(0), renderedFrame, 0.05f,
687 tcu::COMPARE_LOG_RESULT))
689 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
692 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
699 DynamicStateRSTests::DynamicStateRSTests (tcu::TestContext& testCtx)
700 : TestCaseGroup (testCtx, "rs_state", "Tests for rasterizer state")
702 /* Left blank on purpose */
705 DynamicStateRSTests::~DynamicStateRSTests ()
709 void DynamicStateRSTests::init (void)
711 ShaderMap shaderPaths;
712 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
713 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
715 addChild(new InstanceFactory<DepthBiasParamTestInstance>(m_testCtx, "depth_bias", "Test depth bias functionality", shaderPaths));
716 addChild(new InstanceFactory<DepthBiasClampParamTestInstance>(m_testCtx, "depth_bias_clamp", "Test depth bias clamp functionality", shaderPaths));
717 addChild(new InstanceFactory<LineWidthParamTestInstance>(m_testCtx, "line_width", "Draw a line with width set to max defined by physical device", shaderPaths));