vktDynamicStateCBTests.cpp revision db4efd02b79d71e0d0b1122d01d1a20b37760527
1/*------------------------------------------------------------------------ 2 * Vulkan Conformance Tests 3 * ------------------------ 4 * 5 * Copyright (c) 2015 The Khronos Group Inc. 6 * Copyright (c) 2015 Intel Corporation 7 * 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: 15 * 16 * The above copyright notice(s) and this permission notice shall be included 17 * in all copies or substantial portions of the Materials. 18 * 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. 22 * 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. 30 * 31 *//*! 32 * \file 33 * \brief Dynamic CB State Tests 34 *//*--------------------------------------------------------------------*/ 35 36#include "vktDynamicStateCBTests.hpp" 37 38#include "vktDynamicStateBaseClass.hpp" 39#include "vktDynamicStateTestCaseUtil.hpp" 40 41#include "vkImageUtil.hpp" 42 43#include "tcuImageCompare.hpp" 44#include "tcuTextureUtil.hpp" 45#include "tcuRGBA.hpp" 46 47namespace vkt 48{ 49namespace DynamicState 50{ 51namespace 52{ 53 54class BlendConstantsTestInstance : public DynamicStateBaseClass 55{ 56public: 57 BlendConstantsTestInstance (Context& context, ShaderMap shaders) 58 : DynamicStateBaseClass (context, shaders[glu::SHADERTYPE_VERTEX], shaders[glu::SHADERTYPE_FRAGMENT]) 59 { 60 m_topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; 61 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())); 66 67 DynamicStateBaseClass::initialize(); 68 } 69 70 virtual void initPipeline (const vk::VkDevice device) 71 { 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)); 74 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); 79 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()); 91 92 m_pipeline = vk::createGraphicsPipeline(m_vk, device, DE_NULL, &pipelineCreateInfo); 93 } 94 95 virtual tcu::TestStatus iterate (void) 96 { 97 tcu::TestLog &log = m_context.getTestContext().getLog(); 98 const vk::VkQueue queue = m_context.getUniversalQueue(); 99 100 const vk::VkClearColorValue clearColor = { { 1.0f, 1.0f, 1.0f, 1.0f } }; 101 beginRenderPassWithClearColor(clearColor); 102 103 // bind states here 104 setDynamicViewportState(WIDTH, HEIGHT); 105 setDynamicRasterizationState(); 106 setDynamicDepthStencilState(); 107 setDynamicBlendState(0.33f, 0.1f, 0.66f, 0.5f); 108 109 m_vk.cmdBindPipeline(*m_cmdBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline); 110 111 const vk::VkDeviceSize vertexBufferOffset = 0; 112 const vk::VkBuffer vertexBuffer = m_vertexBuffer->object(); 113 m_vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer, &vertexBufferOffset); 114 115 m_vk.cmdDraw(*m_cmdBuffer, static_cast<deUint32>(m_data.size()), 1, 0, 0); 116 117 m_vk.cmdEndRenderPass(*m_cmdBuffer); 118 m_vk.endCommandBuffer(*m_cmdBuffer); 119 120 vk::VkSubmitInfo submitInfo = 121 { 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 1, // deUint32 commandBufferCount; 127 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers; 128 0, // deUint32 signalSemaphoreCount; 129 DE_NULL // const VkSemaphore* pSignalSemaphores; 130 }; 131 m_vk.queueSubmit(queue, 1, &submitInfo, DE_NULL); 132 VK_CHECK(m_vk.queueWaitIdle(queue)); 133 134 //validation 135 { 136 tcu::Texture2D referenceFrame(vk::mapVkFormat(m_colorAttachmentFormat), (int)(0.5 + WIDTH), (int)(0.5 + HEIGHT)); 137 referenceFrame.allocLevel(0); 138 139 const deInt32 frameWidth = referenceFrame.getWidth(); 140 const deInt32 frameHeight = referenceFrame.getHeight(); 141 142 tcu::clear(referenceFrame.getLevel(0), tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); 143 144 for (int y = 0; y < frameHeight; y++) 145 { 146 const float yCoord = (float)(y / (0.5*frameHeight)) - 1.0f; 147 148 for (int x = 0; x < frameWidth; x++) 149 { 150 const float xCoord = (float)(x / (0.5*frameWidth)) - 1.0f; 151 152 if ((yCoord >= -1.0f && yCoord <= 1.0f && xCoord >= -1.0f && xCoord <= 1.0f)) 153 referenceFrame.getLevel(0).setPixel(tcu::Vec4(0.33f, 1.0f, 0.66f, 1.0f), x, y); 154 } 155 } 156 157 const vk::VkOffset3D zeroOffset = { 0, 0, 0 }; 158 const tcu::ConstPixelBufferAccess renderedFrame = m_colorTargetImage->readSurface(queue, m_context.getDefaultAllocator(), 159 vk::VK_IMAGE_LAYOUT_GENERAL, zeroOffset, WIDTH, HEIGHT, vk::VK_IMAGE_ASPECT_COLOR_BIT); 160 161 if (!tcu::fuzzyCompare(log, "Result", "Image comparison result", 162 referenceFrame.getLevel(0), renderedFrame, 0.05f, 163 tcu::COMPARE_LOG_RESULT)) 164 { 165 return tcu::TestStatus(QP_TEST_RESULT_FAIL, "Image verification failed"); 166 } 167 168 return tcu::TestStatus(QP_TEST_RESULT_PASS, "Image verification passed"); 169 } 170 } 171}; 172 173} //anonymous 174 175DynamicStateCBTests::DynamicStateCBTests (tcu::TestContext& testCtx) 176 : TestCaseGroup (testCtx, "cb_state", "Tests for color blend state") 177{ 178 /* Left blank on purpose */ 179} 180 181DynamicStateCBTests::~DynamicStateCBTests (void) {} 182 183void DynamicStateCBTests::init (void) 184{ 185 ShaderMap shaderPaths; 186 shaderPaths[glu::SHADERTYPE_VERTEX] = "vulkan/dynamic_state/VertexFetch.vert"; 187 shaderPaths[glu::SHADERTYPE_FRAGMENT] = "vulkan/dynamic_state/VertexFetch.frag"; 188 addChild(new InstanceFactory<BlendConstantsTestInstance>(m_testCtx, "blend_constants", "Check if blend constants are working properly", shaderPaths)); 189} 190 191} // DynamicState 192} // vkt 193