1 #ifndef _VKTDRAWUTIL_HPP
2 #define _VKTDRAWUTIL_HPP
3 /*-------------------------------------------------------------------------
7 * Copyright (c) 2016 The Khronos Group Inc.
8 * Copyright (c) 2016 Google Inc.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Utility for generating simple work
25 *//*--------------------------------------------------------------------*/
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"
45 vk::VkPrimitiveTopology topology;
46 vk::VkFormat colorFormat;
47 vk::VkFormat depthFormat;
48 tcu::UVec2 renderSize;
49 bool depthClampEnable;
51 bool depthWriteEnable;
52 rr::TestFunc compareOp;
53 bool depthBoundsTestEnable;
56 deUint32 numPatchControlPoints;
58 bool sampleShadingEnable;
60 DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
65 const std::vector<tcu::Vec4>& vertices;
67 DrawCallData (const std::vector<tcu::Vec4>& vertices_)
68 : vertices (vertices_)
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).
79 DrawContext (const DrawState& drawState,
80 const DrawCallData& drawCallData)
81 : m_drawState (drawState)
82 , m_drawCallData (drawCallData)
85 virtual ~DrawContext (void)
89 virtual void draw (void) = 0;
90 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const = 0;
92 const DrawState& m_drawState;
93 const DrawCallData& m_drawCallData;
96 class ReferenceDrawContext : public DrawContext
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)
108 virtual ~ReferenceDrawContext (void);
109 virtual void draw (void);
110 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
112 const rr::VertexShader& m_vertexShader;
113 const rr::FragmentShader& m_fragmentShader;
114 tcu::TextureLevel m_refImage;
119 vk::VkShaderStageFlagBits stage;
120 const vk::ProgramBinary* binary;
122 VulkanShader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_)
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;
136 VulkanProgram (const std::vector<VulkanShader>& shaders_)
139 , descriptorSetLayout (0)
145 , descriptorSetLayout (0)
150 class VulkanDrawContext : public DrawContext
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;
163 MAX_NUM_SHADER_MODULES = 5,
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;
181 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
186 #endif // _VKTDRAWUTIL_HPP