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::flushMappedMemoryRange(m_vk, device,
255 m_vertexBuffer->getBoundMemory().getMemory(),
256 m_vertexBuffer->getBoundMemory().getOffset(),
259 const CmdPoolCreateInfo cmdPoolCreateInfo(m_context.getUniversalQueueFamilyIndex());
260 m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo);
261 m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, *m_cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY);
264 virtual tcu::TestStatus iterate (void)
267 return tcu::TestStatus::fail("Should reimplement iterate() method");
270 void beginRenderPass (void)
272 const vk::VkClearColorValue clearColor = { { 0.0f, 0.0f, 0.0f, 1.0f } };
273 beginRenderPassWithClearColor(clearColor);
276 void beginRenderPassWithClearColor (const vk::VkClearColorValue &clearColor)
278 beginCommandBuffer(m_vk, *m_cmdBuffer, 0u);
280 initialTransitionColor2DImage(m_vk, *m_cmdBuffer, m_colorTargetImage->object(), vk::VK_IMAGE_LAYOUT_GENERAL,
281 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_PIPELINE_STAGE_TRANSFER_BIT);
282 initialTransitionDepthStencil2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
283 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_PIPELINE_STAGE_TRANSFER_BIT);
285 const ImageSubresourceRange subresourceRangeImage(vk::VK_IMAGE_ASPECT_COLOR_BIT);
286 m_vk.cmdClearColorImage(*m_cmdBuffer, m_colorTargetImage->object(),
287 vk::VK_IMAGE_LAYOUT_GENERAL, &clearColor, 1, &subresourceRangeImage);
289 const vk::VkClearDepthStencilValue depthStencilClearValue = { 0.0f, 0 };
291 const ImageSubresourceRange subresourceRangeDepthStencil[2] = { vk::VK_IMAGE_ASPECT_DEPTH_BIT, vk::VK_IMAGE_ASPECT_STENCIL_BIT };
293 m_vk.cmdClearDepthStencilImage(*m_cmdBuffer, m_depthStencilImage->object(),
294 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencilClearValue, 2, subresourceRangeDepthStencil);
296 const vk::VkMemoryBarrier memBarrier =
298 vk::VK_STRUCTURE_TYPE_MEMORY_BARRIER,
300 vk::VK_ACCESS_TRANSFER_WRITE_BIT,
301 vk::VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
302 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
305 m_vk.cmdPipelineBarrier(*m_cmdBuffer, vk::VK_PIPELINE_STAGE_TRANSFER_BIT,
306 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
307 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
308 0, 1, &memBarrier, 0, DE_NULL, 0, DE_NULL);
310 transition2DImage(m_vk, *m_cmdBuffer, m_depthStencilImage->object(), vk::VK_IMAGE_ASPECT_DEPTH_BIT | vk::VK_IMAGE_ASPECT_STENCIL_BIT,
311 vk::VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
312 vk::VK_ACCESS_TRANSFER_WRITE_BIT, vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
313 vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
315 vk::beginRenderPass(m_vk, *m_cmdBuffer, *m_renderPass, *m_framebuffer, vk::makeRect2D(0, 0, WIDTH, HEIGHT));
318 void setDynamicViewportState (const deUint32 width, const deUint32 height)
320 vk::VkViewport viewport = vk::makeViewport(tcu::UVec2(width, height));
321 m_vk.cmdSetViewport(*m_cmdBuffer, 0, 1, &viewport);
323 vk::VkRect2D scissor = vk::makeRect2D(tcu::UVec2(width, height));
324 m_vk.cmdSetScissor(*m_cmdBuffer, 0, 1, &scissor);
327 void setDynamicViewportState (const deUint32 viewportCount, const vk::VkViewport* pViewports, const vk::VkRect2D* pScissors)
329 m_vk.cmdSetViewport(*m_cmdBuffer, 0, viewportCount, pViewports);
330 m_vk.cmdSetScissor(*m_cmdBuffer, 0, viewportCount, pScissors);
333 void setDynamicRasterizationState (const float lineWidth = 1.0f,
334 const float depthBiasConstantFactor = 0.0f,
335 const float depthBiasClamp = 0.0f,
336 const float depthBiasSlopeFactor = 0.0f)
338 m_vk.cmdSetLineWidth(*m_cmdBuffer, lineWidth);
339 m_vk.cmdSetDepthBias(*m_cmdBuffer, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor);
342 void setDynamicBlendState (const float const1 = 0.0f, const float const2 = 0.0f,
343 const float const3 = 0.0f, const float const4 = 0.0f)
345 float blendConstantsants[4] = { const1, const2, const3, const4 };
346 m_vk.cmdSetBlendConstants(*m_cmdBuffer, blendConstantsants);
349 void setDynamicDepthStencilState (const float minDepthBounds = -1.0f, const float maxDepthBounds = 1.0f,
350 const deUint32 stencilFrontCompareMask = 0xffffffffu, const deUint32 stencilFrontWriteMask = 0xffffffffu,
351 const deUint32 stencilFrontReference = 0, const deUint32 stencilBackCompareMask = 0xffffffffu,
352 const deUint32 stencilBackWriteMask = 0xffffffffu, const deUint32 stencilBackReference = 0)
354 m_vk.cmdSetDepthBounds(*m_cmdBuffer, minDepthBounds, maxDepthBounds);
355 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontCompareMask);
356 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontWriteMask);
357 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_FRONT_BIT, stencilFrontReference);
358 m_vk.cmdSetStencilCompareMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackCompareMask);
359 m_vk.cmdSetStencilWriteMask(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackWriteMask);
360 m_vk.cmdSetStencilReference(*m_cmdBuffer, vk::VK_STENCIL_FACE_BACK_BIT, stencilBackReference);
364 class DepthBiasParamTestInstance : public DepthBiasBaseCase
367 DepthBiasParamTestInstance (Context& context, ShaderMap shaders)
368 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
370 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
371 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(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
373 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::blue().toVec()));
375 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
376 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(-0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
378 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
380 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
381 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
382 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
383 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.5f, 1.0f), tcu::RGBA::red().toVec()));
386 m_depthStencilState = PipelineCreateInfo::DepthStencilState(
387 VK_TRUE, VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
389 DepthBiasBaseCase::initialize();
392 virtual tcu::TestStatus iterate (void)
394 tcu::TestLog& log = m_context.getTestContext().getLog();
395 const vk::VkQueue queue = m_context.getUniversalQueue();
396 const vk::VkDevice device = m_context.getDevice();
401 setDynamicViewportState(WIDTH, HEIGHT);
402 setDynamicBlendState();
403 setDynamicDepthStencilState();
405 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
407 const vk::VkDeviceSize vertexBufferOffset = 0;
408 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
409 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
411 setDynamicRasterizationState(1.0f, 0.0f);
412 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
413 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
415 setDynamicRasterizationState(1.0f, -1.0f);
416 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 8, 0);
418 endRenderPass(m_vk, *m_cmdBuffer);
419 endCommandBuffer(m_vk, *m_cmdBuffer);
421 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
425 VK_CHECK(m_vk.queueWaitIdle(queue));
427 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
428 referenceFrame.allocLevel(0);
430 const deInt32 frameWidth = referenceFrame.getWidth();
431 const deInt32 frameHeight = referenceFrame.getHeight();
433 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
435 for (int y = 0; y < frameHeight; y++)
437 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
439 for (int x = 0; x < frameWidth; x++)
441 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
443 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
444 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
446 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
450 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
451 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
452 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
454 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
455 referenceFrame.getLevel(0), renderedFrame, 0.05f,
456 tcu::COMPARE_LOG_RESULT))
458 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
461 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
466 class DepthBiasClampParamTestInstance : public DepthBiasBaseCase
469 DepthBiasClampParamTestInstance (Context& context, ShaderMap shaders)
470 : DepthBiasBaseCase (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
472 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
473 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(-1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
475 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 0.0f, 1.0f), tcu::RGBA::blue().toVec()));
477 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
478 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, 0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
479 m_data.push_back(PositionColorVertex(tcu::Vec4(-0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
480 m_data.push_back(PositionColorVertex(tcu::Vec4(0.5f, -0.5f, 0.01f, 1.0f), tcu::RGBA::green().toVec()));
483 m_depthStencilState = PipelineCreateInfo::DepthStencilState(VK_TRUE, VK_TRUE, vk::VK_COMPARE_OP_GREATER_OR_EQUAL);
485 DepthBiasBaseCase::initialize();
488 virtual tcu::TestStatus iterate (void)
490 tcu::TestLog& log = m_context.getTestContext().getLog();
491 const vk::VkQueue queue = m_context.getUniversalQueue();
492 const vk::VkDevice device = m_context.getDevice();
497 setDynamicViewportState(WIDTH, HEIGHT);
498 setDynamicBlendState();
499 setDynamicDepthStencilState();
501 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
503 const vk::VkDeviceSize vertexBufferOffset = 0;
504 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
505 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
507 setDynamicRasterizationState(1.0f, 1000.0f, 0.005f);
508 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 0, 0);
510 setDynamicRasterizationState(1.0f, 0.0f);
511 m_vk.cmdDraw(*m_cmdBuffer, 4, 1, 4, 0);
513 endRenderPass(m_vk, *m_cmdBuffer);
514 endCommandBuffer(m_vk, *m_cmdBuffer);
516 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
520 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
521 referenceFrame.allocLevel(0);
523 const deInt32 frameWidth = referenceFrame.getWidth();
524 const deInt32 frameHeight = referenceFrame.getHeight();
526 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
528 for (int y = 0; y < frameHeight; y++)
530 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
532 for (int x = 0; x < frameWidth; x++)
534 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
536 if (xCoord >= -0.5f && xCoord <= 0.5f && yCoord >= -0.5f && yCoord <= 0.5f)
537 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
539 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f), x, y);
543 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
544 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
545 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
547 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
548 referenceFrame.getLevel(0), renderedFrame, 0.05f,
549 tcu::COMPARE_LOG_RESULT))
551 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
554 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
559 class LineWidthParamTestInstance : public DynamicStateBaseClass
562 LineWidthParamTestInstance (Context& context, ShaderMap shaders)
563 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
565 // Check if line width test is supported
567 const vk::VkPhysicalDeviceFeatures& deviceFeatures = m_context.getDeviceFeatures();
569 if (!deviceFeatures.wideLines)
570 throw tcu::NotSupportedError("Line width test is unsupported");
573 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
575 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
576 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), tcu::RGBA::green().toVec()));
578 DynamicStateBaseClass::initialize();
581 virtual tcu::TestStatus iterate (void)
583 tcu::TestLog& log = m_context.getTestContext().getLog();
584 const vk::VkQueue queue = m_context.getUniversalQueue();
585 const vk::VkDevice device = m_context.getDevice();
590 vk::VkPhysicalDeviceProperties deviceProperties;
591 m_context.getInstanceInterface().getPhysicalDeviceProperties(m_context.getPhysicalDevice(), &deviceProperties);
593 setDynamicViewportState(WIDTH, HEIGHT);
594 setDynamicBlendState();
595 setDynamicDepthStencilState();
596 setDynamicRasterizationState(deFloatFloor(deviceProperties.limits.lineWidthRange[1]));
598 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
600 const vk::VkDeviceSize vertexBufferOffset = 0;
601 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
602 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
604 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
606 endRenderPass(m_vk, *m_cmdBuffer);
607 endCommandBuffer(m_vk, *m_cmdBuffer);
609 submitCommandsAndWait(m_vk, device, queue, m_cmdBuffer.get());
613 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
614 referenceFrame.allocLevel(0);
616 const deInt32 frameWidth = referenceFrame.getWidth();
617 const deInt32 frameHeight = referenceFrame.getHeight();
619 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
621 for (int y = 0; y < frameHeight; y++)
623 float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
625 for (int x = 0; x < frameWidth; x++)
627 float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
628 float lineHalfWidth = (float)(deFloor(deviceProperties.limits.lineWidthRange[1]) / frameHeight);
630 if (xCoord >= -1.0f && xCoord <= 1.0f && yCoord >= -lineHalfWidth && yCoord <= lineHalfWidth)
631 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f), x, y);
635 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
636 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
637 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT,
638 vk::VK_IMAGE_ASPECT_COLOR_BIT);
640 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
641 referenceFrame.getLevel(0), renderedFrame, 0.05f,
642 tcu::COMPARE_LOG_RESULT))
644 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
647 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
654 DynamicStateRSTests::DynamicStateRSTests (tcu::TestContext& testCtx)
655 : TestCaseGroup (testCtx, "rs_state", "Tests for rasterizer state")
657 /* Left blank on purpose */
660 DynamicStateRSTests::~DynamicStateRSTests ()
664 void DynamicStateRSTests::init (void)
666 ShaderMap shaderPaths;
667 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
668 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
670 addChild(new InstanceFactory<DepthBiasParamTestInstance>(m_testCtx, "depth_bias", "Test depth bias functionality", shaderPaths));
671 addChild(new InstanceFactory<DepthBiasClampParamTestInstance>(m_testCtx, "depth_bias_clamp", "Test depth bias clamp functionality", shaderPaths));
672 addChild(new InstanceFactory<LineWidthParamTestInstance>(m_testCtx, "line_width", "Draw a line with width set to max defined by physical device", shaderPaths));