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::VkMemoryBarrier memBarrier =
300 vk::VK_STRUCTURE_TYPE_MEMORY_BARRIER,
302 vk::VK_ACCESS_TRANSFER_WRITE_BIT,
303 vk::VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
304 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
307 m_vk.cmdPipelineBarrier(*m_cmdBuffer, vk::VK_PIPELINE_STAGE_TRANSFER_BIT,
308 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
309 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
310 0, 1, &memBarrier, 0, DE_NULL, 0, DE_NULL);
312 const vk::VkRect2D renderArea = { { 0, 0 }, { WIDTH, HEIGHT } };
313 const RenderPassBeginInfo renderPassBegin(*m_renderPass, *m_framebuffer, renderArea);
315 m_vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBegin, vk::VK_SUBPASS_CONTENTS_INLINE);
318 void setDynamicViewportState (const deUint32 width, const deUint32 height)
320 vk::VkViewport viewport;
323 viewport.width = static_cast<float>(width);
324 viewport.height = static_cast<float>(height);
325 viewport.minDepth = 0.0f;
326 viewport.maxDepth = 1.0f;
328 m_vk.cmdSetViewport(*m_cmdBuffer, 0, 1, &viewport);
330 vk::VkRect2D scissor;
331 scissor.offset.x = 0;
332 scissor.offset.y = 0;
333 scissor.extent.width = width;
334 scissor.extent.height = height;
335 m_vk.cmdSetScissor(*m_cmdBuffer, 0, 1, &scissor);
338 void setDynamicViewportState (const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
340 m_vk.cmdSetViewport(*m_cmdBuffer, 0, viewportCount, pViewports);
341 m_vk.cmdSetScissor(*m_cmdBuffer, 0, viewportCount, pScissors);
344 void setDynamicRasterizationState (const float lineWidth = 1.0f,
345 const float depthBiasConstantFactor = 0.0f,
346 const float depthBiasClamp = 0.0f,
347 const float depthBiasSlopeFactor = 0.0f)
349 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
350 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
353 void setDynamicBlendState (const float const1 = 0.0f, const float const2 = 0.0f,
354 const float const3 = 0.0f, const float const4 = 0.0f)
356 float blendConstantsants[4] = { const1, const2, const3, const4 };
357 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
360 void setDynamicDepthStencilState (const float minDepthBounds = -1.0f, const float maxDepthBounds = 1.0f,
361 const deUint32 stencilFrontCompareMask = 0xffffffffu, const deUint32 stencilFrontWriteMask = 0xffffffffu,
362 const deUint32 stencilFrontReference = 0, const deUint32 stencilBackCompareMask = 0xffffffffu,
363 const deUint32 stencilBackWriteMask = 0xffffffffu, const deUint32 stencilBackReference = 0)
365 m_vk.cmdSetDepthBounds(*m_cmdBuffer, minDepthBounds, maxDepthBounds);
366 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontCompareMask);
367 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontWriteMask);
368 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontReference);
369 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackCompareMask);
370 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackWriteMask);
371 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackReference);
375 class DepthBiasParamTestInstance : public DepthBiasBaseCase
378 DepthBiasParamTestInstance (Context& context, ShaderMap shaders)
379 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
381 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
382 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(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
384 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
386 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
387 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(-0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
389 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
391 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
392 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
393 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
394 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
397 m_depthStencilState = PipelineCreateInfo::DepthStencilState(
398 vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
400 DepthBiasBaseCase::initialize();
403 virtual tcu::TestStatus iterate (void)
405 tcu::TestLog &log = m_context.getTestContext().getLog();
406 const vk::VkQueue queue = m_context.getUniversalQueue();
411 setDynamicViewportState(WIDTH, HEIGHT);
412 setDynamicBlendState();
413 setDynamicDepthStencilState();
415 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
417 const vk::VkDeviceSize vertexBufferOffset = 0;
418 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
419 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
421 setDynamicRasterizationState(1.0f, 0.0f);
422 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
423 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
425 setDynamicRasterizationState(1.0f, -1.0f);
426 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
428 m_vk.cmdEndRenderPass(*m_cmdBuffer);
429 m_vk.endCommandBuffer(*m_cmdBuffer);
431 vk::VkSubmitInfo submitInfo =
433 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
434 DE_NULL, // const void* pNext;
435 0, // deUint32 waitSemaphoreCount;
436 DE_NULL, // const VkSemaphore* pWaitSemaphores;
437 (const vk::VkPipelineStageFlags*)DE_NULL,
438 1, // deUint32 commandBufferCount;
439 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
440 0, // deUint32 signalSemaphoreCount;
441 DE_NULL // const VkSemaphore* pSignalSemaphores;
443 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
447 VK_CHECK(m_vk.queueWaitIdle(queue));
449 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
450 referenceFrame.allocLevel(0);
452 const deInt32 frameWidth = referenceFrame.getWidth();
453 const deInt32 frameHeight = referenceFrame.getHeight();
455 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
457 for (int y = 0; y < frameHeight; y++)
459 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
461 for (int x = 0; x < frameWidth; x++)
463 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
465 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
466 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
468 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
472 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
473 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
474 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
476 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
477 referenceFrame.getLevel(0), renderedFrame, 0.05f,
478 tcu::COMPARE_LOG_RESULT))
480 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
483 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
488 class DepthBiasClampParamTestInstance : public DepthBiasBaseCase
491 DepthBiasClampParamTestInstance (Context& context, ShaderMap shaders)
492 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
494 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
495 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(-1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
497 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
499 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
500 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
501 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
502 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
505 m_depthStencilState = PipelineCreateInfo::DepthStencilState(vk::VK_TRUE, vk::VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
507 DepthBiasBaseCase::initialize();
510 virtual tcu::TestStatus iterate (void)
512 tcu::TestLog &log = m_context.getTestContext().getLog();
513 const vk::VkQueue queue = m_context.getUniversalQueue();
518 setDynamicViewportState(WIDTH, HEIGHT);
519 setDynamicBlendState();
520 setDynamicDepthStencilState();
522 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
524 const vk::VkDeviceSize vertexBufferOffset = 0;
525 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
526 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
528 setDynamicRasterizationState(1.0f, 1000.0f, 0.005f);
529 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
531 setDynamicRasterizationState(1.0f, 0.0f);
532 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
534 m_vk.cmdEndRenderPass(*m_cmdBuffer);
535 m_vk.endCommandBuffer(*m_cmdBuffer);
537 vk::VkSubmitInfo submitInfo =
539 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
540 DE_NULL, // const void* pNext;
541 0, // deUint32 waitSemaphoreCount;
542 DE_NULL, // const VkSemaphore* pWaitSemaphores;
543 (const vk::VkPipelineStageFlags*)DE_NULL,
544 1, // deUint32 commandBufferCount;
545 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
546 0, // deUint32 signalSemaphoreCount;
547 DE_NULL // const VkSemaphore* pSignalSemaphores;
549 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
553 VK_CHECK(m_vk.queueWaitIdle(queue));
555 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
556 referenceFrame.allocLevel(0);
558 const deInt32 frameWidth = referenceFrame.getWidth();
559 const deInt32 frameHeight = referenceFrame.getHeight();
561 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
563 for (int y = 0; y < frameHeight; y++)
565 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
567 for (int x = 0; x < frameWidth; x++)
569 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
571 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
572 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
574 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
578 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
579 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
580 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
582 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
583 referenceFrame.getLevel(0), renderedFrame, 0.05f,
584 tcu::COMPARE_LOG_RESULT))
586 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
589 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
594 class LineWidthParamTestInstance : public DynamicStateBaseClass
597 LineWidthParamTestInstance (Context& context, ShaderMap shaders)
598 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
600 // Check if line width test is supported
602 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
604 if (!deviceFeatures.wideLines)
605 throw tcu::NotSupportedError("Line width test is unsupported");
608 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
610 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
611 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
613 DynamicStateBaseClass::initialize();
616 virtual tcu::TestStatus iterate (void)
618 tcu::TestLog &log = m_context.getTestContext().getLog();
619 const vk::VkQueue queue = m_context.getUniversalQueue();
624 vk::VkPhysicalDeviceProperties deviceProperties;
625 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
627 setDynamicViewportState(WIDTH, HEIGHT);
628 setDynamicBlendState();
629 setDynamicDepthStencilState();
630 setDynamicRasterizationState(deFloatFloor(deviceProperties.limits.lineWidthRange[1]));
632 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
634 const vk::VkDeviceSize vertexBufferOffset = 0;
635 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
636 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
638 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
640 m_vk.cmdEndRenderPass(*m_cmdBuffer);
641 m_vk.endCommandBuffer(*m_cmdBuffer);
643 vk::VkSubmitInfo submitInfo =
645 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
646 DE_NULL, // const void* pNext;
647 0, // deUint32 waitSemaphoreCount;
648 DE_NULL, // const VkSemaphore* pWaitSemaphores;
649 (const vk::VkPipelineStageFlags*)DE_NULL,
650 1, // deUint32 commandBufferCount;
651 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
652 0, // deUint32 signalSemaphoreCount;
653 DE_NULL // const VkSemaphore* pSignalSemaphores;
655 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
659 VK_CHECK(m_vk.queueWaitIdle(queue));
661 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
662 referenceFrame.allocLevel(0);
664 const deInt32 frameWidth = referenceFrame.getWidth();
665 const deInt32 frameHeight = referenceFrame.getHeight();
667 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
669 for (int y = 0; y < frameHeight; y++)
671 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
673 for (int x = 0; x < frameWidth; x++)
675 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
676 float lineHalfWidth = (float)(deFloor(deviceProperties.limits.lineWidthRange[1]) / frameHeight);
678 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -lineHalfWidth && yCoord <= lineHalfWidth)
679 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
683 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
684 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
685 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT,
686 vk::VK_IMAGE_ASPECT_COLOR_BIT);
688 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
689 referenceFrame.getLevel(0), renderedFrame, 0.05f,
690 tcu::COMPARE_LOG_RESULT))
692 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
695 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
702 DynamicStateRSTests::DynamicStateRSTests (tcu::TestContext& testCtx)
703 : TestCaseGroup (testCtx, "rs_state", "Tests for rasterizer state")
705 /* Left blank on purpose */
708 DynamicStateRSTests::~DynamicStateRSTests ()
712 void DynamicStateRSTests::init (void)
714 ShaderMap shaderPaths;
715 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
716 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
718 addChild(new InstanceFactory<DepthBiasParamTestInstance>(m_testCtx, "depth_bias", "Test depth bias functionality", shaderPaths));
719 addChild(new InstanceFactory<DepthBiasClampParamTestInstance>(m_testCtx, "depth_bias_clamp", "Test depth bias clamp functionality", shaderPaths));
720 addChild(new InstanceFactory<LineWidthParamTestInstance>(m_testCtx, "line_width", "Draw a line with width set to max defined by physical device", shaderPaths));