1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Dynamic CB State Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktDynamicStateCBTests.hpp"
38 #include "vktDynamicStateBaseClass.hpp"
39 #include "vktDynamicStateTestCaseUtil.hpp"
41 #include "vkImageUtil.hpp"
43 #include "tcuImageCompare.hpp"
44 #include "tcuTextureUtil.hpp"
45 #include "tcuRGBA.hpp"
49 namespace DynamicState
54 class BlendConstantsTestInstance : public DynamicStateBaseClass
57 BlendConstantsTestInstance (Context& context, ShaderMap shaders)
58 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
60 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
62 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
63 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
64 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
65 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
67 DynamicStateBaseClass::initialize();
70 virtual void initPipeline (const vk::VkDevice device)
72 const vk::Unique<vk::VkShaderModule> vs (createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
73 const vk::Unique<vk::VkShaderModule> fs (createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
75 const vk::VkPipelineColorBlendAttachmentState VkPipelineColorBlendAttachmentState =
76 PipelineCreateInfo::ColorBlendState::Attachment(vk::VK_TRUE,
77 vk::VK_BLEND_FACTOR_SRC_ALPHA, vk::VK_BLEND_FACTOR_CONSTANT_COLOR, vk::VK_BLEND_OP_ADD,
78 vk::VK_BLEND_FACTOR_SRC_ALPHA, vk::VK_BLEND_FACTOR_CONSTANT_ALPHA, vk::VK_BLEND_OP_ADD);
80 PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, 0);
81 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
82 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
83 pipelineCreateInfo.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
84 pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
85 pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &VkPipelineColorBlendAttachmentState));
86 pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1));
87 pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
88 pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
89 pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
90 pipelineCreateInfo.addState(PipelineCreateInfo::DynamicState());
92 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo);
95 virtual tcu::TestStatus iterate (void)
97 tcu::TestLog &log = m_context.getTestContext().getLog();
98 const vk::VkQueue queue = m_context.getUniversalQueue();
100 const vk::VkClearColorValue clearColor = { { 1.0f, 1.0f, 1.0f, 1.0f } };
101 beginRenderPassWithClearColor(clearColor);
104 setDynamicViewportState(WIDTH, HEIGHT);
105 setDynamicRasterizationState();
106 setDynamicDepthStencilState();
107 setDynamicBlendState(0.33f, 0.1f, 0.66f, 0.5f);
109 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
111 const vk::VkDeviceSize vertexBufferOffset = 0;
112 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
113 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
115 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
117 m_vk.cmdEndRenderPass(*m_cmdBuffer);
118 m_vk.endCommandBuffer(*m_cmdBuffer);
120 vk::VkSubmitInfo submitInfo =
122 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
123 DE_NULL, // const void* pNext;
124 0, // deUint32 waitSemaphoreCount;
125 DE_NULL, // const VkSemaphore* pWaitSemaphores;
126 (const vk::VkPipelineStageFlags*)DE_NULL,
127 1, // deUint32 commandBufferCount;
128 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
129 0, // deUint32 signalSemaphoreCount;
130 DE_NULL // const VkSemaphore* pSignalSemaphores;
132 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
133 VK_CHECK(m_vk.queueWaitIdle(queue));
137 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
138 referenceFrame.allocLevel(0);
140 const deInt32 frameWidth = referenceFrame.getWidth();
141 const deInt32 frameHeight = referenceFrame.getHeight();
143 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
145 for (int y = 0; y < frameHeight; y++)
147 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
149 for (int x = 0; x < frameWidth; x++)
151 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
153 if ((yCoord >= -1.0f && yCoord <= 1.0f && xCoord >= -1.0f && xCoord <= 1.0f))
154 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.33f, 1.0f, 0.66f, 1.0f), x, y);
158 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
159 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
160 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
162 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
163 referenceFrame.getLevel(0), renderedFrame, 0.05f,
164 tcu::COMPARE_LOG_RESULT))
166 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
169 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
176 DynamicStateCBTests::DynamicStateCBTests (tcu::TestContext& testCtx)
177 : TestCaseGroup (testCtx, "cb_state", "Tests for color blend state")
179 /* Left blank on purpose */
182 DynamicStateCBTests::~DynamicStateCBTests (void) {}
184 void DynamicStateCBTests::init (void)
186 ShaderMap shaderPaths;
187 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
188 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
189 addChild(new InstanceFactory<BlendConstantsTestInstance>(m_testCtx, "blend_constants", "Check if blend constants are working properly", shaderPaths));