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 CB State Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktDynamicStateCBTests.hpp"
27 #include "vktDynamicStateBaseClass.hpp"
28 #include "vktDynamicStateTestCaseUtil.hpp"
30 #include "vkImageUtil.hpp"
32 #include "tcuImageCompare.hpp"
33 #include "tcuTextureUtil.hpp"
34 #include "tcuRGBA.hpp"
38 namespace DynamicState
46 class BlendConstantsTestInstance : public DynamicStateBaseClass
49 BlendConstantsTestInstance (Context& context, ShaderMap shaders)
50 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT])
52 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
54 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
55 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
56 m_data.push_back(PositionColorVertex(tcu::Vec4(-1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
57 m_data.push_back(PositionColorVertex(tcu::Vec4(1.0f, -1.0f, 1.0f, 1.0f), tcu::RGBA::green().toVec()));
59 DynamicStateBaseClass::initialize();
62 virtual void initPipeline (const vk::VkDevice device)
64 const vk::Unique<vk::VkShaderModule> vs (createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_vertexShaderName), 0));
65 const vk::Unique<vk::VkShaderModule> fs (createShaderModule(m_vk, device, m_context.getBinaryCollection().get(m_fragmentShaderName), 0));
67 const vk::VkPipelineColorBlendAttachmentState VkPipelineColorBlendAttachmentState =
68 PipelineCreateInfo::ColorBlendState::Attachment(VK_TRUE,
69 vk::VK_BLEND_FACTOR_SRC_ALPHA, vk::VK_BLEND_FACTOR_CONSTANT_COLOR, vk::VK_BLEND_OP_ADD,
70 vk::VK_BLEND_FACTOR_SRC_ALPHA, vk::VK_BLEND_FACTOR_CONSTANT_ALPHA, vk::VK_BLEND_OP_ADD);
72 PipelineCreateInfo pipelineCreateInfo(*m_pipelineLayout, *m_renderPass, 0, 0);
73 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*vs, "main", vk::VK_SHADER_STAGE_VERTEX_BIT));
74 pipelineCreateInfo.addShader(PipelineCreateInfo::PipelineShaderStage(*fs, "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT));
75 pipelineCreateInfo.addState(PipelineCreateInfo::VertexInputState(m_vertexInputState));
76 pipelineCreateInfo.addState(PipelineCreateInfo::InputAssemblerState(m_topology));
77 pipelineCreateInfo.addState(PipelineCreateInfo::ColorBlendState(1, &VkPipelineColorBlendAttachmentState));
78 pipelineCreateInfo.addState(PipelineCreateInfo::ViewportState(1));
79 pipelineCreateInfo.addState(PipelineCreateInfo::DepthStencilState());
80 pipelineCreateInfo.addState(PipelineCreateInfo::RasterizerState());
81 pipelineCreateInfo.addState(PipelineCreateInfo::MultiSampleState());
82 pipelineCreateInfo.addState(PipelineCreateInfo::DynamicState());
84 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo);
87 virtual tcu::TestStatus iterate (void)
89 tcu::TestLog &log = m_context.getTestContext().getLog();
90 const vk::VkQueue queue = m_context.getUniversalQueue();
92 const vk::VkClearColorValue clearColor = { { 1.0f, 1.0f, 1.0f, 1.0f } };
93 beginRenderPassWithClearColor(clearColor);
96 setDynamicViewportState(WIDTH, HEIGHT);
97 setDynamicRasterizationState();
98 setDynamicDepthStencilState();
99 setDynamicBlendState(0.33f, 0.1f, 0.66f, 0.5f);
101 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
103 const vk::VkDeviceSize vertexBufferOffset = 0;
104 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object();
105 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset);
107 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0);
109 m_vk.cmdEndRenderPass(*m_cmdBuffer);
110 m_vk.endCommandBuffer(*m_cmdBuffer);
112 vk::VkSubmitInfo submitInfo =
114 vk::VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
115 DE_NULL, // const void* pNext;
116 0, // deUint32 waitSemaphoreCount;
117 DE_NULL, // const VkSemaphore* pWaitSemaphores;
118 (const vk::VkPipelineStageFlags*)DE_NULL,
119 1, // deUint32 commandBufferCount;
120 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
121 0, // deUint32 signalSemaphoreCount;
122 DE_NULL // const VkSemaphore* pSignalSemaphores;
124 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL);
125 VK_CHECK(m_vk.queueWaitIdle(queue));
129 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT));
130 referenceFrame.allocLevel(0);
132 const deInt32 frameWidth = referenceFrame.getWidth();
133 const deInt32 frameHeight = referenceFrame.getHeight();
135 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
137 for (int y = 0; y < frameHeight; y++)
139 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f;
141 for (int x = 0; x < frameWidth; x++)
143 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f;
145 if ((yCoord >= -1.0f && yCoord <= 1.0f && xCoord >= -1.0f && xCoord <= 1.0f))
146 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.33f, 1.0f, 0.66f, 1.0f), x, y);
150 const vk::VkOffset3D zeroOffset = { 0, 0, 0 };
151 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(),
152 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT);
154 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result",
155 referenceFrame.getLevel(0), renderedFrame, 0.05f,
156 tcu::COMPARE_LOG_RESULT))
158 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed");
161 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed");
168 DynamicStateCBTests::DynamicStateCBTests (tcu::TestContext& testCtx)
169 : TestCaseGroup (testCtx, "cb_state", "Tests for color blend state")
171 /* Left blank on purpose */
174 DynamicStateCBTests::~DynamicStateCBTests (void) {}
176 void DynamicStateCBTests::init (void)
178 ShaderMap shaderPaths;
179 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert";
180 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag";
181 addChild(new InstanceFactory<BlendConstantsTestInstance>(m_testCtx, "blend_constants", "Check if blend constants are working properly", shaderPaths));