1 #ifndef _VKTDRAWUTIL_HPP 2 #define _VKTDRAWUTIL_HPP 3 /*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2016 The Khronos Group Inc. 8 * Copyright (c) 2016 Google Inc. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Utility for generating simple work 25 *//*--------------------------------------------------------------------*/ 26 27 #include "vkDefs.hpp" 28 29 #include "deUniquePtr.hpp" 30 #include "vkBufferWithMemory.hpp" 31 #include "vkImageWithMemory.hpp" 32 #include "vkImageUtil.hpp" 33 #include "vkPrograms.hpp" 34 #include "vktTestCase.hpp" 35 #include "vkTypeUtil.hpp" 36 #include "rrRenderer.hpp" 37 38 namespace vkt 39 { 40 namespace drawutil 41 { 42 43 struct DrawState 44 { 45 vk::VkPrimitiveTopology topology; 46 vk::VkFormat colorFormat; 47 vk::VkFormat depthFormat; 48 tcu::UVec2 renderSize; 49 bool depthClampEnable; 50 bool depthTestEnable; 51 bool depthWriteEnable; 52 rr::TestFunc compareOp; 53 bool depthBoundsTestEnable; 54 bool blendEnable; 55 float lineWidth; 56 deUint32 numPatchControlPoints; 57 deUint32 numSamples; 58 bool sampleShadingEnable; 59 60 DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_); 61 }; 62 63 struct DrawCallData 64 { 65 const std::vector<tcu::Vec4>& vertices; 66 DrawCallDatavkt::drawutil::DrawCallData67 DrawCallData (const std::vector<tcu::Vec4>& vertices_) 68 : vertices (vertices_) 69 { 70 } 71 }; 72 73 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments. 74 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1] 75 //! Clip coords (-1,-1) map to viewport coords (0, 0). 76 class DrawContext 77 { 78 public: DrawContext(const DrawState & drawState,const DrawCallData & drawCallData)79 DrawContext (const DrawState& drawState, 80 const DrawCallData& drawCallData) 81 : m_drawState (drawState) 82 , m_drawCallData (drawCallData) 83 { 84 } ~DrawContext(void)85 virtual ~DrawContext (void) 86 { 87 } 88 89 virtual void draw (void) = 0; 90 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const = 0; 91 protected: 92 const DrawState& m_drawState; 93 const DrawCallData& m_drawCallData; 94 }; 95 96 class ReferenceDrawContext : public DrawContext 97 { 98 public: ReferenceDrawContext(const DrawState & drawState,const DrawCallData & drawCallData,const rr::VertexShader & vertexShader,const rr::FragmentShader & fragmentShader)99 ReferenceDrawContext (const DrawState& drawState, 100 const DrawCallData& drawCallData, 101 const rr::VertexShader& vertexShader, 102 const rr::FragmentShader& fragmentShader) 103 : DrawContext (drawState, drawCallData) 104 , m_vertexShader (vertexShader) 105 , m_fragmentShader (fragmentShader) 106 { 107 } 108 virtual ~ReferenceDrawContext (void); 109 virtual void draw (void); 110 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const; 111 private: 112 const rr::VertexShader& m_vertexShader; 113 const rr::FragmentShader& m_fragmentShader; 114 tcu::TextureLevel m_refImage; 115 }; 116 117 struct VulkanShader 118 { 119 vk::VkShaderStageFlagBits stage; 120 const vk::ProgramBinary* binary; 121 VulkanShadervkt::drawutil::VulkanShader122 VulkanShader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_) 123 : stage (stage_) 124 , binary (&binary_) 125 { 126 } 127 }; 128 129 struct VulkanProgram 130 { 131 std::vector<VulkanShader> shaders; 132 vk::VkImageView depthImageView; // \todo [2017-06-06 pyry] This shouldn't be here? Doesn't logically belong to program 133 vk::VkDescriptorSetLayout descriptorSetLayout; 134 vk::VkDescriptorSet descriptorSet; 135 VulkanProgramvkt::drawutil::VulkanProgram136 VulkanProgram (const std::vector<VulkanShader>& shaders_) 137 : shaders (shaders_) 138 , depthImageView (0) 139 , descriptorSetLayout (0) 140 , descriptorSet (0) 141 {} 142 VulkanProgramvkt::drawutil::VulkanProgram143 VulkanProgram (void) 144 : depthImageView (0) 145 , descriptorSetLayout (0) 146 , descriptorSet (0) 147 {} 148 }; 149 150 class VulkanDrawContext : public DrawContext 151 { 152 public: 153 VulkanDrawContext (Context& context, 154 const DrawState& drawState, 155 const DrawCallData& drawCallData, 156 const VulkanProgram& vulkanProgram); 157 virtual ~VulkanDrawContext (void); 158 virtual void draw (void); 159 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const; 160 private: 161 enum VulkanContants 162 { 163 MAX_NUM_SHADER_MODULES = 5, 164 }; 165 Context& m_context; 166 const VulkanProgram& m_program; 167 de::MovePtr<vk::ImageWithMemory> m_colorImage; 168 de::MovePtr<vk::ImageWithMemory> m_resolveImage; 169 de::MovePtr<vk::BufferWithMemory> m_colorAttachmentBuffer; 170 vk::refdetails::Move<vk::VkImageView> m_colorImageView; 171 vk::refdetails::Move<vk::VkRenderPass> m_renderPass; 172 vk::refdetails::Move<vk::VkFramebuffer> m_framebuffer; 173 vk::refdetails::Move<vk::VkPipelineLayout> m_pipelineLayout; 174 vk::refdetails::Move<vk::VkPipeline> m_pipeline; 175 vk::refdetails::Move<vk::VkCommandPool> m_cmdPool; 176 vk::refdetails::Move<vk::VkCommandBuffer> m_cmdBuffer; 177 vk::refdetails::Move<vk::VkShaderModule> m_shaderModules[MAX_NUM_SHADER_MODULES]; 178 de::MovePtr<vk::BufferWithMemory> m_vertexBuffer; 179 }; 180 181 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology); 182 183 } // drwwutil 184 } // vkt 185 186 #endif // _VKTDRAWUTIL_HPP 187