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::VkShaderStageFlagBits stage;
46 const vk::ProgramBinary* binary;
48 Shader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_)
57 const vk::VkPrimitiveTopology topology;
58 const vk::VkFormat colorFormat;
59 const vk::VkFormat depthFormat;
60 tcu::UVec2 renderSize;
61 bool depthClampEnable;
64 deUint32 numPatchControlPoints;
66 DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
71 const std::vector<tcu::Vec4>& vertices;
73 DrawCallData (const std::vector<tcu::Vec4>& vertices_)
74 : vertices (vertices_)
79 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
80 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
81 //! Clip coords (-1,-1) map to viewport coords (0, 0).
85 DrawContext (const DrawState& drawState,
86 const DrawCallData& drawCallData)
87 : m_drawState (drawState)
88 , m_drawCallData (drawCallData)
91 virtual ~DrawContext (void)
95 virtual void draw (void) = 0;
96 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const = 0;
98 const DrawState m_drawState;
99 const DrawCallData m_drawCallData;
102 class ReferenceDrawContext : public DrawContext
105 ReferenceDrawContext (const DrawState& drawState,
106 const DrawCallData& drawCallData,
107 const rr::VertexShader& vertexShader,
108 const rr::FragmentShader& fragmentShader)
109 : DrawContext (drawState, drawCallData)
110 , m_vertexShader (vertexShader)
111 , m_fragmentShader (fragmentShader)
114 virtual ~ReferenceDrawContext (void);
115 virtual void draw (void);
116 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
118 const rr::VertexShader& m_vertexShader;
119 const rr::FragmentShader& m_fragmentShader;
120 tcu::TextureLevel m_refImage;
125 const std::vector<Shader>& shaders;
127 VulkanProgram (const std::vector<Shader>& shaders_)
133 class VulkanDrawContext : public DrawContext
136 VulkanDrawContext (Context& context,
137 const DrawState& drawState,
138 const DrawCallData& drawCallData,
139 const VulkanProgram& vulkanProgram);
140 virtual ~VulkanDrawContext (void);
141 virtual void draw (void);
142 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
146 MAX_NUM_SHADER_MODULES = 5,
149 VulkanProgram m_program;
150 de::MovePtr<vk::ImageWithMemory> m_colorImage;
151 de::MovePtr<vk::ImageWithMemory> m_depthImage;
152 de::MovePtr<vk::BufferWithMemory> m_colorAttachmentBuffer;
153 vk::refdetails::Move<vk::VkImageView> m_colorImageView;
154 vk::refdetails::Move<vk::VkImageView> m_depthImageView;
155 vk::refdetails::Move<vk::VkRenderPass> m_renderPass;
156 vk::refdetails::Move<vk::VkFramebuffer> m_framebuffer;
157 vk::refdetails::Move<vk::VkPipelineLayout> m_pipelineLayout;
158 vk::refdetails::Move<vk::VkPipeline> m_pipeline;
159 vk::refdetails::Move<vk::VkCommandPool> m_cmdPool;
160 vk::refdetails::Move<vk::VkCommandBuffer> m_cmdBuffer;
161 vk::refdetails::Move<vk::VkShaderModule> m_shaderModules[MAX_NUM_SHADER_MODULES];
162 de::MovePtr<vk::BufferWithMemory> m_vertexBuffer;
165 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
170 #endif // _VKTDRAWUTIL_HPP