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"
31 #include "vkTypeUtil.hpp"
32 #include "vkCmdUtil.hpp"
34 #include "tcuTextureUtil.hpp"
35 #include "tcuImageCompare.hpp"
36 #include "tcuRGBA.hpp"
42 namespace DynamicState
50 class DepthBiasBaseCase : public TestInstance
53 DepthBiasBaseCase (Context& context, const char* vertexShaderName, const char* fragmentShaderName)
54 : TestInstance (context)
55 , m_colorAttachmentFormat (vk::VK_FORMAT_R8G8B8A8_UNORM)
56 , m_topology (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP)
57 , m_vk (context.getDeviceInterface())
58 , m_vertexShaderName (vertexShaderName)
59 , m_fragmentShaderName (fragmentShaderName)
71 vk::VkFormat m_colorAttachmentFormat;
72 vk::VkFormat m_depthStencilAttachmentFormat;
74 vk::VkPrimitiveTopology m_topology;
76 const vk::DeviceInterface& m_vk;
78 vk::Move<vk::VkPipeline> m_pipeline;
79 vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
81 de::SharedPtr<Image> m_colorTargetImage;
82 vk::Move<vk::VkImageView> m_colorTargetView;
84 de::SharedPtr<Image> m_depthStencilImage;
85 vk::Move<vk::VkImageView> m_attachmentView;
87 PipelineCreateInfo::VertexInputState m_vertexInputState;
88 de::SharedPtr<Buffer> m_vertexBuffer;
90 vk::Move<vk::VkCommandPool> m_cmdPool;
91 vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
93 vk::Move<vk::VkFramebuffer> m_framebuffer;
94 vk::Move<vk::VkRenderPass> m_renderPass;
96 std::string m_vertexShaderName;
97 std::string m_fragmentShaderName;
99 std::vector<PositionColorVertex> m_data;
101 PipelineCreateInfo::DepthStencilState m_depthStencilState;
103 void initialize (void)
105 const vk::VkDevice device = m_context.getDevice();
107 vk::VkFormatProperties formatProperties;
108 // check for VK_FORMAT_D24_UNORM_S8_UINT support
109 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D24_UNORM_S8_UINT, &formatProperties);
110 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
112 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D24_UNORM_S8_UINT;
116 // check for VK_FORMAT_D32_SFLOAT_S8_UINT support
117 m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), vk::VK_FORMAT_D32_SFLOAT_S8_UINT, &formatProperties);
118 if (formatProperties.optimalTilingFeatures & vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
120 m_depthStencilAttachmentFormat = vk::VK_FORMAT_D32_SFLOAT_S8_UINT;
123 throw tcu::NotSupportedError("No valid depth stencil attachment available");
126 const PipelineLayoutCreateInfo pipelineLayoutCreateInfo;
127 m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo);
129 const vk::Unique<vk::VkShaderModule> vs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
130 const vk::Unique<vk::VkShaderModule> fs(createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
132 const vk::VkExtent3D imageExtent = { WIDTH, HEIGHT, 1 };
133 ImageCreateInfo targetImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, imageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
134 vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_SRC_BIT | vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT);
136 m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
138 const ImageCreateInfo depthStencilImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_depthStencilAttachmentFormat, imageExtent,
139 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL,
140 vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT);
142 m_depthStencilImage = Image::createAndAlloc(m_vk, device, depthStencilImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
144 const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat);
145 m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo);
147 const ImageViewCreateInfo attachmentViewInfo(m_depthStencilImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_depthStencilAttachmentFormat);
148 m_attachmentView = vk::createImageView(m_vk, device, &attachmentViewInfo);
150 RenderPassCreateInfo renderPassCreateInfo;
151 renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat,
152 vk::VK_SAMPLE_COUNT_1_BIT,
153 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
154 vk::VK_ATTACHMENT_STORE_OP_STORE,
155 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
156 vk::VK_ATTACHMENT_STORE_OP_STORE,
157 vk::VK_IMAGE_LAYOUT_GENERAL,
158 vk::VK_IMAGE_LAYOUT_GENERAL));
160 renderPassCreateInfo.addAttachment(AttachmentDescription(m_depthStencilAttachmentFormat,
161 vk::VK_SAMPLE_COUNT_1_BIT,
162 vk::VK_ATTACHMENT_LOAD_OP_LOAD,
163 vk::VK_ATTACHMENT_STORE_OP_STORE,
164 vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE,
165 vk::VK_ATTACHMENT_STORE_OP_STORE,
166 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
167 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
169 const vk::VkAttachmentReference colorAttachmentReference =
172 vk::VK_IMAGE_LAYOUT_GENERAL
175 const vk::VkAttachmentReference depthAttachmentReference =
178 vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
181 renderPassCreateInfo.addSubpass(SubpassDescription(vk::VK_PIPELINE_BIND_POINT_GRAPHICS,
186 &colorAttachmentReference,
188 depthAttachmentReference,
192 m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo);
194 const vk::VkVertexInputBindingDescription vertexInputBindingDescription =
197 (deUint32)sizeof(tcu::Vec4) * 2,
198 vk::VK_VERTEX_INPUT_RATE_VERTEX,
201 const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[2] =
206 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
212 vk::VK_FORMAT_R32G32B32A32_SFLOAT,
213 (deUint32)(sizeof(float)* 4),
217 m_vertexInputState = PipelineCreateInfo::VertexInputState(1,
218 &vertexInputBindingDescription,
220 vertexInputAttributeDescriptions);
222 const PipelineCreateInfo::ColorBlendState::Attachment vkCbAttachmentState;
224 PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, 0);
225 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
226 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
227 pipelineCreateInfo.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
228 pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
229 pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &vkCbAttachmentState));
230 pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1));
231 pipelineCreateInfo.addState(m_depthStencilState);
232 pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
233 pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
234 pipelineCreateInfo.addState(PipelineCreateInfo::DynamicState());
236 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo);
238 std::vector<vk::VkImageView> attachments(2);
239 attachments[0] = *m_colorTargetView;
240 attachments[1] = *m_attachmentView;
242 const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, attachments, WIDTH, HEIGHT, 1);
244 m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo);
246 const vk::VkDeviceSize dataSize = m_data.size() * sizeof(PositionColorVertex);
247 m_vertexBuffer = Buffer::createAndAlloc(m_vk, device, BufferCreateInfo(dataSize,
248 vk::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT),
249 m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible);
251 deUint8* ptr = reinterpret_cast<unsigned char *>(m_vertexBuffer->getBoundMemory().getHostPtr());
252 deMemcpy(ptr, &m_data[0], static_cast<size_t>(dataSize));
254 vk::flushAlloc(m_vk, device, m_vertexBuffer->getBoundMemory());
256 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
257 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
258 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, *m_cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY);
261 virtual tcu::TestStatus iterate (void)
264 return tcu::TestStatus::fail("Should reimplement iterate() method");
267 void beginRenderPass (void)
269 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
270 beginRenderPassWithClearColor(clearColor);
273 void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
275 beginCommandBuffer(m_vk, *m_cmdBuffer, 0u);
277 initialTransitionColor2DImage(m_vk, *m_cmdBuffer, m_colorTargetImage->object(), vk::VK_IMAGE_LAYOUT_GENERAL,
278 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_PIPELINE_STAGE_TRANSFER_BIT);
279 initialTransitionDepthStencil2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
280 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_PIPELINE_STAGE_TRANSFER_BIT);
282 const ImageSubresourceRange subresourceRangeImage(vk::VK_IMAGE_ASPECT_COLOR_BIT);
283 m_vk.cmdClearColorImage(*m_cmdBuffer, m_colorTargetImage->object(),
284 vk::VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &subresourceRangeImage);
286 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
288 const ImageSubresourceRange subresourceRangeDepthStencil[2] = { vk::VK_IMAGE_ASPECT_DEPTH_BIT, vk::VK_IMAGE_ASPECT_STENCIL_BIT };
290 m_vk.cmdClearDepthStencilImage(*m_cmdBuffer, m_depthStencilImage->object(),
291 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilClearValue, 2, subresourceRangeDepthStencil);
293 const vk::VkMemoryBarrier memBarrier =
295 vk::VK_STRUCTURE_TYPE_MEMORY_BARRIER,
297 vk::VK_ACCESS_TRANSFER_WRITE_BIT,
298 vk::VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
299 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
302 m_vk.cmdPipelineBarrier(*m_cmdBuffer, vk::VK_PIPELINE_STAGE_TRANSFER_BIT,
303 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
304 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
305 0, 1, &memBarrier, 0, DE_NULL, 0, DE_NULL);
307 transition2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_ASPECT_DEPTH_BIT | vk::VK_IMAGE_ASPECT_STENCIL_BIT,
308 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
309 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
310 vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
312 vk::beginRenderPass(m_vk, *m_cmdBuffer, *m_renderPass, *m_framebuffer, vk::makeRect2D(0, 0, WIDTH, HEIGHT));
315 void setDynamicViewportState (const deUint32 width, const deUint32 height)
317 vk::VkViewport viewport = vk::makeViewport(tcu::UVec2(width, height));
318 m_vk.cmdSetViewport(*m_cmdBuffer, 0, 1, &viewport);
320 vk::VkRect2D scissor = vk::makeRect2D(tcu::UVec2(width, 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_TRUE, 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();
393 const vk::VkDevice device = m_context.getDevice();
398 setDynamicViewportState(WIDTH, HEIGHT);
399 setDynamicBlendState();
400 setDynamicDepthStencilState();
402 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
404 const vk::VkDeviceSize vertexBufferOffset = 0;
405 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
406 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
408 setDynamicRasterizationState(1.0f, 0.0f);
409 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
410 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
412 setDynamicRasterizationState(1.0f, -1.0f);
413 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
415 endRenderPass(m_vk, *m_cmdBuffer);
416 endCommandBuffer(m_vk, *m_cmdBuffer);
418 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
422 VK_CHECK(m_vk.queueWaitIdle(queue));
424 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
425 referenceFrame.allocLevel(0);
427 const deInt32 frameWidth = referenceFrame.getWidth();
428 const deInt32 frameHeight = referenceFrame.getHeight();
430 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
432 for (int y = 0; y < frameHeight; y++)
434 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
436 for (int x = 0; x < frameWidth; x++)
438 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
440 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
441 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
443 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
447 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
448 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
449 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
451 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
452 referenceFrame.getLevel(0), renderedFrame, 0.05f,
453 tcu::COMPARE_LOG_RESULT))
455 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
458 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
463 class DepthBiasClampParamTestInstance : public DepthBiasBaseCase
466 DepthBiasClampParamTestInstance (Context& context, ShaderMap shaders)
467 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
469 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
470 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
471 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
472 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
474 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
475 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
476 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
477 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
480 m_depthStencilState = PipelineCreateInfo::DepthStencilState(VK_TRUE, VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
482 DepthBiasBaseCase::initialize();
485 virtual tcu::TestStatus iterate (void)
487 tcu::TestLog& log = m_context.getTestContext().getLog();
488 const vk::VkQueue queue = m_context.getUniversalQueue();
489 const vk::VkDevice device = m_context.getDevice();
494 setDynamicViewportState(WIDTH, HEIGHT);
495 setDynamicBlendState();
496 setDynamicDepthStencilState();
498 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
500 const vk::VkDeviceSize vertexBufferOffset = 0;
501 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
502 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
504 setDynamicRasterizationState(1.0f, 1000.0f, 0.005f);
505 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
507 setDynamicRasterizationState(1.0f, 0.0f);
508 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
510 endRenderPass(m_vk, *m_cmdBuffer);
511 endCommandBuffer(m_vk, *m_cmdBuffer);
513 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
517 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
518 referenceFrame.allocLevel(0);
520 const deInt32 frameWidth = referenceFrame.getWidth();
521 const deInt32 frameHeight = referenceFrame.getHeight();
523 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
525 for (int y = 0; y < frameHeight; y++)
527 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
529 for (int x = 0; x < frameWidth; x++)
531 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
533 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
534 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
536 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
540 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
541 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
542 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
544 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
545 referenceFrame.getLevel(0), renderedFrame, 0.05f,
546 tcu::COMPARE_LOG_RESULT))
548 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
551 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
556 class LineWidthParamTestInstance : public DynamicStateBaseClass
559 LineWidthParamTestInstance (Context& context, ShaderMap shaders)
560 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
562 // Check if line width test is supported
564 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
566 if (!deviceFeatures.wideLines)
567 throw tcu::NotSupportedError("Line width test is unsupported");
570 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
572 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
573 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
575 DynamicStateBaseClass::initialize();
578 virtual tcu::TestStatus iterate (void)
580 tcu::TestLog& log = m_context.getTestContext().getLog();
581 const vk::VkQueue queue = m_context.getUniversalQueue();
582 const vk::VkDevice device = m_context.getDevice();
587 vk::VkPhysicalDeviceProperties deviceProperties;
588 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
590 setDynamicViewportState(WIDTH, HEIGHT);
591 setDynamicBlendState();
592 setDynamicDepthStencilState();
593 setDynamicRasterizationState(deFloatFloor(deviceProperties.limits.lineWidthRange[1]));
595 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
597 const vk::VkDeviceSize vertexBufferOffset = 0;
598 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
599 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
601 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
603 endRenderPass(m_vk, *m_cmdBuffer);
604 endCommandBuffer(m_vk, *m_cmdBuffer);
606 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
610 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
611 referenceFrame.allocLevel(0);
613 const deInt32 frameWidth = referenceFrame.getWidth();
614 const deInt32 frameHeight = referenceFrame.getHeight();
616 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
618 for (int y = 0; y < frameHeight; y++)
620 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
622 for (int x = 0; x < frameWidth; x++)
624 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
625 float lineHalfWidth = (float)(deFloor(deviceProperties.limits.lineWidthRange[1]) / frameHeight);
627 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -lineHalfWidth && yCoord <= lineHalfWidth)
628 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
632 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
633 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
634 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT,
635 vk::VK_IMAGE_ASPECT_COLOR_BIT);
637 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
638 referenceFrame.getLevel(0), renderedFrame, 0.05f,
639 tcu::COMPARE_LOG_RESULT))
641 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
644 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
651 DynamicStateRSTests::DynamicStateRSTests (tcu::TestContext& testCtx)
652 : TestCaseGroup (testCtx, "rs_state", "Tests for rasterizer state")
654 /* Left blank on purpose */
657 DynamicStateRSTests::~DynamicStateRSTests ()
661 void DynamicStateRSTests::init (void)
663 ShaderMap shaderPaths;
664 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
665 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
667 addChild(new InstanceFactory<DepthBiasParamTestInstance>(m_testCtx, "depth_bias", "Test depth bias functionality", shaderPaths));
668 addChild(new InstanceFactory<DepthBiasClampParamTestInstance>(m_testCtx, "depth_bias_clamp", "Test depth bias clamp functionality", shaderPaths));
669 addChild(new InstanceFactory<LineWidthParamTestInstance>(m_testCtx, "line_width", "Draw a line with width set to max defined by physical device", shaderPaths));