1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Dynamic Raster State Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktDynamicStateRSTests.hpp"
27 #include "vktDynamicStateBaseClass.hpp"
28 #include "vktDynamicStateTestCaseUtil.hpp"
30 #include "vkImageUtil.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "tcuImageCompare.hpp"
34 #include "tcuRGBA.hpp"
40 namespace DynamicState
45 class DepthBiasBaseCase : public TestInstance
48 DepthBiasBaseCase (Context& context, const char* vertexShaderName, const char* fragmentShaderName)
49 : TestInstance (context)
50 , m_colorAttachmentFormat (vk::VK_FORMAT_R8G8B8A8_UNORM)
51 , m_topology (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)
52 , m_vk (context.getDeviceInterface())
53 , m_vertexShaderName (vertexShaderName)
54 , m_fragmentShaderName (fragmentShaderName)
66 vk::VkFormat m_colorAttachmentFormat;
67 vk::VkFormat m_depthStencilAttachmentFormat;
69 vk::VkPrimitiveTopology m_topology;
71 const vk::DeviceInterface& m_vk;
73 vk::Move<vk::VkPipeline> m_pipeline;
74 vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
76 de::SharedPtr<Image> m_colorTargetImage;
77 vk::Move<vk::VkImageView> m_colorTargetView;
79 de::SharedPtr<Image> m_depthStencilImage;
80 vk::Move<vk::VkImageView> m_attachmentView;
82 PipelineCreateInfo::VertexInputState m_vertexInputState;
83 de::SharedPtr<Buffer> m_vertexBuffer;
85 vk::Move<vk::VkCommandPool> m_cmdPool;
86 vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
88 vk::Move<vk::VkFramebuffer> m_framebuffer;
89 vk::Move<vk::VkRenderPass> m_renderPass;
91 std::string m_vertexShaderName;
92 std::string m_fragmentShaderName;
94 std::vector<PositionColorVertex> m_data;
96 PipelineCreateInfo::DepthStencilState m_depthStencilState;
98 void initialize (void)
100 const vk::VkDevice device = m_context.getDevice();
102 vk::VkFormatProperties formatProperties;
103 // check for VK_FORMAT_D24_UNORM_S8_UINT support
104 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D24_UNORM_S8_UINT, &formatProperties);
105 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
107 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D24_UNORM_S8_UINT;
111 // check for VK_FORMAT_D32_SFLOAT_S8_UINT support
112 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D32_SFLOAT_S8_UINT, &formatProperties);
113 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
115 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D32_SFLOAT_S8_UINT;
118 throw tcu::NotSupportedError("No valid depth stencil attachment available");
121 const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
122 m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo);
124 const vk::Unique<vk::VkShaderModule> vs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
125 const vk::Unique<vk::VkShaderModule> fs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
127 const vk::VkExtent3D imageExtent = { WIDTH, HEIGHT, 1 };
128 ImageCreateInfo targetImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
129 vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_SRC_BIT | vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT);
131 m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator());
133 const ImageCreateInfo depthStencilImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_depthStencilAttachmentFormat, imageExtent,
134 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
135 vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT);
137 m_depthStencilImage = Image::createAndAlloc(m_vk, device, depthStencilImageCreateInfo, m_context.getDefaultAllocator());
139 const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
140 m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo);
142 const ImageViewCreateInfo attachmentViewInfo(m_depthStencilImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_depthStencilAttachmentFormat);
143 m_attachmentView = vk::createImageView(m_vk, device, &attachmentViewInfo);
145 RenderPassCreateInfo renderPassCreateInfo;
146 renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,
147 vk::VK_SAMPLE_COUNT_1_BIT,
148 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
149 vk::VK_ATTACHMENT_STORE_OP_STORE,
150 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
151 vk::VK_ATTACHMENT_STORE_OP_STORE,
152 vk::VK_IMAGE_LAYOUT_GENERAL,
153 vk::VK_IMAGE_LAYOUT_GENERAL));
155 renderPassCreateInfo.addAttachment(AttachmentDescription(m_depthStencilAttachmentFormat,
156 vk::VK_SAMPLE_COUNT_1_BIT,
157 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
158 vk::VK_ATTACHMENT_STORE_OP_STORE,
159 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
160 vk::VK_ATTACHMENT_STORE_OP_STORE,
161 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
162 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
164 const vk::VkAttachmentReference colorAttachmentReference =
167 vk::VK_IMAGE_LAYOUT_GENERAL
170 const vk::VkAttachmentReference depthAttachmentReference =
173 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
176 renderPassCreateInfo.addSubpass(SubpassDescription(vk::VK_PIPELINE_BIND_POINT_GRAPHICS,
181 &colorAttachmentReference,
183 depthAttachmentReference,
187 m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo);
189 const vk::VkVertexInputBindingDescription vertexInputBindingDescription =
192 (deUint32)sizeof(tcu::Vec4) * 2,
193 vk::VK_VERTEX_INPUT_RATE_VERTEX,
196 const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
201 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
207 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
208 (deUint32)(sizeof(float)* 4),
212 m_vertexInputState = PipelineCreateInfo::VertexInputState(1,
213 &vertexInputBindingDescription,
215 vertexInputAttributeDescriptions);
217 const PipelineCreateInfo::ColorBlendState::Attachment vkCbAttachmentState;
219 PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, 0);
220 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
221 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
222 pipelineCreateInfo.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
223 pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
224 pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &vkCbAttachmentState));
225 pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1));
226 pipelineCreateInfo.addState(m_depthStencilState);
227 pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
228 pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
229 pipelineCreateInfo.addState(PipelineCreateInfo::DynamicState());
231 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo);
233 std::vector<vk::VkImageView> attachments(2);
234 attachments[0] = *m_colorTargetView;
235 attachments[1] = *m_attachmentView;
237 const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
239 m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo);
241 const vk::VkDeviceSize dataSize = m_data.size() * sizeof(PositionColorVertex);
242 m_vertexBuffer = Buffer::createAndAlloc(m_vk, device, BufferCreateInfo(dataSize,
243 vk::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT),
244 m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
246 deUint8* ptr = reinterpret_cast<unsigned char *>(m_vertexBuffer->getBoundMemory().getHostPtr());
247 deMemcpy(ptr, &m_data[0], static_cast<size_t>(dataSize));
249 vk::flushMappedMemoryRange(m_vk, device,
250 m_vertexBuffer->getBoundMemory().getMemory(),
251 m_vertexBuffer->getBoundMemory().getOffset(),
254 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
255 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
257 const vk::VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
259 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
260 DE_NULL, // const void* pNext;
261 *m_cmdPool, // VkCommandPool commandPool;
262 vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
263 1u, // deUint32 bufferCount;
265 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, &cmdBufferAllocateInfo);
268 virtual tcu::TestStatus iterate (void)
271 return tcu::TestStatus::fail("Should reimplement iterate() method");
274 void beginRenderPass (void)
276 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
277 beginRenderPassWithClearColor(clearColor);
280 void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
282 const CmdBufferBeginInfo beginInfo;
283 m_vk.beginCommandBuffer(*m_cmdBuffer, &beginInfo);
285 initialTransitionColor2DImage(m_vk, *m_cmdBuffer, m_colorTargetImage->object(), vk::VK_IMAGE_LAYOUT_GENERAL);
286 initialTransitionDepthStencil2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
288 const ImageSubresourceRange subresourceRangeImage(vk::VK_IMAGE_ASPECT_COLOR_BIT);
289 m_vk.cmdClearColorImage(*m_cmdBuffer, m_colorTargetImage->object(),
290 vk::VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &subresourceRangeImage);
292 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
294 const ImageSubresourceRange subresourceRangeDepthStencil[2] = { vk::VK_IMAGE_ASPECT_DEPTH_BIT, vk::VK_IMAGE_ASPECT_STENCIL_BIT };
295 m_vk.cmdClearDepthStencilImage(*m_cmdBuffer, m_depthStencilImage->object(),
296 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilClearValue, 2, subresourceRangeDepthStencil);
298 const vk::VkRect2D renderArea = { { 0, 0 }, { WIDTH, HEIGHT } };
299 const RenderPassBeginInfo renderPassBegin(*m_renderPass, *m_framebuffer, renderArea);
301 m_vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBegin, vk::VK_SUBPASS_CONTENTS_INLINE);
304 void setDynamicViewportState (const deUint32 width, const deUint32 height)
306 vk::VkViewport viewport;
309 viewport.width = static_cast<float>(width);
310 viewport.height = static_cast<float>(height);
311 viewport.minDepth = 0.0f;
312 viewport.maxDepth = 1.0f;
314 m_vk.cmdSetViewport(*m_cmdBuffer, 0, 1, &viewport);
316 vk::VkRect2D scissor;
317 scissor.offset.x = 0;
318 scissor.offset.y = 0;
319 scissor.extent.width = width;
320 scissor.extent.height = height;
321 m_vk.cmdSetScissor(*m_cmdBuffer, 0, 1, &scissor);
324 void setDynamicViewportState (const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
326 m_vk.cmdSetViewport(*m_cmdBuffer, 0, viewportCount, pViewports);
327 m_vk.cmdSetScissor(*m_cmdBuffer, 0, viewportCount, pScissors);
330 void setDynamicRasterizationState (const float lineWidth = 1.0f,
331 const float depthBiasConstantFactor = 0.0f,
332 const float depthBiasClamp = 0.0f,
333 const float depthBiasSlopeFactor = 0.0f)
335 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
336 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
339 void setDynamicBlendState (const float const1 = 0.0f, const float const2 = 0.0f,
340 const float const3 = 0.0f, const float const4 = 0.0f)
342 float blendConstantsants[4] = { const1, const2, const3, const4 };
343 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
346 void setDynamicDepthStencilState (const float minDepthBounds = -1.0f, const float maxDepthBounds = 1.0f,
347 const deUint32 stencilFrontCompareMask = 0xffffffffu, const deUint32 stencilFrontWriteMask = 0xffffffffu,
348 const deUint32 stencilFrontReference = 0, const deUint32 stencilBackCompareMask = 0xffffffffu,
349 const deUint32 stencilBackWriteMask = 0xffffffffu, const deUint32 stencilBackReference = 0)
351 m_vk.cmdSetDepthBounds(*m_cmdBuffer, minDepthBounds, maxDepthBounds);
352 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontCompareMask);
353 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontWriteMask);
354 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontReference);
355 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackCompareMask);
356 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackWriteMask);
357 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackReference);
361 class DepthBiasParamTestInstance : public DepthBiasBaseCase
364 DepthBiasParamTestInstance (Context& context, ShaderMap shaders)
365 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
367 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
368 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
369 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
370 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
372 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
373 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
374 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
375 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
377 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
378 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
379 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
380 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
383 m_depthStencilState = PipelineCreateInfo::DepthStencilState(
384 vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
386 DepthBiasBaseCase::initialize();
389 virtual tcu::TestStatus iterate (void)
391 tcu::TestLog &log = m_context.getTestContext().getLog();
392 const vk::VkQueue queue = m_context.getUniversalQueue();
397 setDynamicViewportState(WIDTH, HEIGHT);
398 setDynamicBlendState();
399 setDynamicDepthStencilState();
401 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
403 const vk::VkDeviceSize vertexBufferOffset = 0;
404 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
405 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
407 setDynamicRasterizationState(1.0f, 0.0f);
408 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
409 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
411 setDynamicRasterizationState(1.0f, -1.0f);
412 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
414 m_vk.cmdEndRenderPass(*m_cmdBuffer);
415 m_vk.endCommandBuffer(*m_cmdBuffer);
417 vk::VkSubmitInfo submitInfo =
419 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
420 DE_NULL, // const void* pNext;
421 0, // deUint32 waitSemaphoreCount;
422 DE_NULL, // const VkSemaphore* pWaitSemaphores;
423 (const vk::VkPipelineStageFlags*)DE_NULL,
424 1, // deUint32 commandBufferCount;
425 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
426 0, // deUint32 signalSemaphoreCount;
427 DE_NULL // const VkSemaphore* pSignalSemaphores;
429 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
433 VK_CHECK(m_vk.queueWaitIdle(queue));
435 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
436 referenceFrame.allocLevel(0);
438 const deInt32 frameWidth = referenceFrame.getWidth();
439 const deInt32 frameHeight = referenceFrame.getHeight();
441 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
443 for (int y = 0; y < frameHeight; y++)
445 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
447 for (int x = 0; x < frameWidth; x++)
449 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
451 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
452 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
454 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
458 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
459 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
460 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
462 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
463 referenceFrame.getLevel(0), renderedFrame, 0.05f,
464 tcu::COMPARE_LOG_RESULT))
466 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
469 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
474 class DepthBiasClampParamTestInstance : public DepthBiasBaseCase
477 DepthBiasClampParamTestInstance (Context& context, ShaderMap shaders)
478 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
480 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
481 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
482 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
483 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
485 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
486 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
487 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
488 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
491 m_depthStencilState = PipelineCreateInfo::DepthStencilState(vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
493 DepthBiasBaseCase::initialize();
496 virtual tcu::TestStatus iterate (void)
498 tcu::TestLog &log = m_context.getTestContext().getLog();
499 const vk::VkQueue queue = m_context.getUniversalQueue();
504 setDynamicViewportState(WIDTH, HEIGHT);
505 setDynamicBlendState();
506 setDynamicDepthStencilState();
508 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
510 const vk::VkDeviceSize vertexBufferOffset = 0;
511 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
512 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
514 setDynamicRasterizationState(1.0f, 1000.0f, 0.005f);
515 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
517 setDynamicRasterizationState(1.0f, 0.0f);
518 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
520 m_vk.cmdEndRenderPass(*m_cmdBuffer);
521 m_vk.endCommandBuffer(*m_cmdBuffer);
523 vk::VkSubmitInfo submitInfo =
525 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
526 DE_NULL, // const void* pNext;
527 0, // deUint32 waitSemaphoreCount;
528 DE_NULL, // const VkSemaphore* pWaitSemaphores;
529 (const vk::VkPipelineStageFlags*)DE_NULL,
530 1, // deUint32 commandBufferCount;
531 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
532 0, // deUint32 signalSemaphoreCount;
533 DE_NULL // const VkSemaphore* pSignalSemaphores;
535 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
539 VK_CHECK(m_vk.queueWaitIdle(queue));
541 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
542 referenceFrame.allocLevel(0);
544 const deInt32 frameWidth = referenceFrame.getWidth();
545 const deInt32 frameHeight = referenceFrame.getHeight();
547 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
549 for (int y = 0; y < frameHeight; y++)
551 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
553 for (int x = 0; x < frameWidth; x++)
555 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
557 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
558 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
560 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
564 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
565 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
566 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
568 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
569 referenceFrame.getLevel(0), renderedFrame, 0.05f,
570 tcu::COMPARE_LOG_RESULT))
572 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
575 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
580 class LineWidthParamTestInstance : public DynamicStateBaseClass
583 LineWidthParamTestInstance (Context& context, ShaderMap shaders)
584 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
586 // Check if line width test is supported
588 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
590 if (!deviceFeatures.wideLines)
591 throw tcu::NotSupportedError("Line width test is unsupported");
594 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
596 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
597 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
599 DynamicStateBaseClass::initialize();
602 virtual tcu::TestStatus iterate (void)
604 tcu::TestLog &log = m_context.getTestContext().getLog();
605 const vk::VkQueue queue = m_context.getUniversalQueue();
610 vk::VkPhysicalDeviceProperties deviceProperties;
611 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
613 setDynamicViewportState(WIDTH, HEIGHT);
614 setDynamicBlendState();
615 setDynamicDepthStencilState();
616 setDynamicRasterizationState(deFloatFloor(deviceProperties.limits.lineWidthRange[1]));
618 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
620 const vk::VkDeviceSize vertexBufferOffset = 0;
621 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
622 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
624 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
626 m_vk.cmdEndRenderPass(*m_cmdBuffer);
627 m_vk.endCommandBuffer(*m_cmdBuffer);
629 vk::VkSubmitInfo submitInfo =
631 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
632 DE_NULL, // const void* pNext;
633 0, // deUint32 waitSemaphoreCount;
634 DE_NULL, // const VkSemaphore* pWaitSemaphores;
635 (const vk::VkPipelineStageFlags*)DE_NULL,
636 1, // deUint32 commandBufferCount;
637 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
638 0, // deUint32 signalSemaphoreCount;
639 DE_NULL // const VkSemaphore* pSignalSemaphores;
641 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
645 VK_CHECK(m_vk.queueWaitIdle(queue));
647 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
648 referenceFrame.allocLevel(0);
650 const deInt32 frameWidth = referenceFrame.getWidth();
651 const deInt32 frameHeight = referenceFrame.getHeight();
653 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
655 for (int y = 0; y < frameHeight; y++)
657 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
659 for (int x = 0; x < frameWidth; x++)
661 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
662 float lineHalfWidth = (float)(deFloor(deviceProperties.limits.lineWidthRange[1]) / frameHeight);
664 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -lineHalfWidth && yCoord <= lineHalfWidth)
665 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
669 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
670 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
671 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT,
672 vk::VK_IMAGE_ASPECT_COLOR_BIT);
674 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
675 referenceFrame.getLevel(0), renderedFrame, 0.05f,
676 tcu::COMPARE_LOG_RESULT))
678 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
681 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
688 DynamicStateRSTests::DynamicStateRSTests (tcu::TestContext& testCtx)
689 : TestCaseGroup (testCtx, "rs_state", "Tests for rasterizer state")
691 /* Left blank on purpose */
694 DynamicStateRSTests::~DynamicStateRSTests ()
698 void DynamicStateRSTests::init (void)
700 ShaderMap shaderPaths;
701 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
702 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
704 addChild(new InstanceFactory<DepthBiasParamTestInstance>(m_testCtx, "depth_bias", "Test depth bias functionality", shaderPaths));
705 addChild(new InstanceFactory<DepthBiasClampParamTestInstance>(m_testCtx, "depth_bias_clamp", "Test depth bias clamp functionality", shaderPaths));
706 addChild(new InstanceFactory<LineWidthParamTestInstance>(m_testCtx, "line_width", "Draw a line with width set to max defined by physical device", shaderPaths));