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