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;
55 deUint32 numPatchControlPoints;
57 bool sampleShadingEnable;
59 DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
64 const std::vector<tcu::Vec4>& vertices;
66 DrawCallData (const std::vector<tcu::Vec4>& vertices_)
67 : vertices (vertices_)
72 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
73 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
74 //! Clip coords (-1,-1) map to viewport coords (0, 0).
78 DrawContext (const DrawState& drawState,
79 const DrawCallData& drawCallData)
80 : m_drawState (drawState)
81 , m_drawCallData (drawCallData)
84 virtual ~DrawContext (void)
88 virtual void draw (void) = 0;
89 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const = 0;
91 const DrawState& m_drawState;
92 const DrawCallData& m_drawCallData;
95 class ReferenceDrawContext : public DrawContext
98 ReferenceDrawContext (const DrawState& drawState,
99 const DrawCallData& drawCallData,
100 const rr::VertexShader& vertexShader,
101 const rr::FragmentShader& fragmentShader)
102 : DrawContext (drawState, drawCallData)
103 , m_vertexShader (vertexShader)
104 , m_fragmentShader (fragmentShader)
107 virtual ~ReferenceDrawContext (void);
108 virtual void draw (void);
109 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
111 const rr::VertexShader& m_vertexShader;
112 const rr::FragmentShader& m_fragmentShader;
113 tcu::TextureLevel m_refImage;
118 vk::VkShaderStageFlagBits stage;
119 const vk::ProgramBinary* binary;
121 VulkanShader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_)
130 std::vector<VulkanShader> shaders;
131 vk::VkImageView depthImageView; // \todo [2017-06-06 pyry] This shouldn't be here? Doesn't logically belong to program
132 vk::VkDescriptorSetLayout descriptorSetLayout;
133 vk::VkDescriptorSet descriptorSet;
135 VulkanProgram (const std::vector<VulkanShader>& shaders_)
138 , descriptorSetLayout (0)
144 , descriptorSetLayout (0)
149 class VulkanDrawContext : public DrawContext
152 VulkanDrawContext (Context& context,
153 const DrawState& drawState,
154 const DrawCallData& drawCallData,
155 const VulkanProgram& vulkanProgram);
156 virtual ~VulkanDrawContext (void);
157 virtual void draw (void);
158 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
162 MAX_NUM_SHADER_MODULES = 5,
165 const VulkanProgram& m_program;
166 de::MovePtr<vk::ImageWithMemory> m_colorImage;
167 de::MovePtr<vk::ImageWithMemory> m_resolveImage;
168 de::MovePtr<vk::BufferWithMemory> m_colorAttachmentBuffer;
169 vk::refdetails::Move<vk::VkImageView> m_colorImageView;
170 vk::refdetails::Move<vk::VkRenderPass> m_renderPass;
171 vk::refdetails::Move<vk::VkFramebuffer> m_framebuffer;
172 vk::refdetails::Move<vk::VkPipelineLayout> m_pipelineLayout;
173 vk::refdetails::Move<vk::VkPipeline> m_pipeline;
174 vk::refdetails::Move<vk::VkCommandPool> m_cmdPool;
175 vk::refdetails::Move<vk::VkCommandBuffer> m_cmdBuffer;
176 vk::refdetails::Move<vk::VkShaderModule> m_shaderModules[MAX_NUM_SHADER_MODULES];
177 de::MovePtr<vk::BufferWithMemory> m_vertexBuffer;
180 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
185 #endif // _VKTDRAWUTIL_HPP