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 vk::VkPrimitiveTopology topology;
58 vk::VkFormat colorFormat;
59 vk::VkFormat depthFormat;
60 tcu::UVec2 renderSize;
61 bool depthClampEnable;
63 bool depthWriteEnable;
64 rr::TestFunc compareOp;
67 deUint32 numPatchControlPoints;
69 bool sampleShadingEnable;
71 DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
76 const std::vector<tcu::Vec4>& vertices;
78 DrawCallData (const std::vector<tcu::Vec4>& vertices_)
79 : vertices (vertices_)
84 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
85 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
86 //! Clip coords (-1,-1) map to viewport coords (0, 0).
90 DrawContext (const DrawState& drawState,
91 const DrawCallData& drawCallData)
92 : m_drawState (drawState)
93 , m_drawCallData (drawCallData)
96 virtual ~DrawContext (void)
100 virtual void draw (void) = 0;
101 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const = 0;
103 const DrawState& m_drawState;
104 const DrawCallData& m_drawCallData;
107 class ReferenceDrawContext : public DrawContext
110 ReferenceDrawContext (const DrawState& drawState,
111 const DrawCallData& drawCallData,
112 const rr::VertexShader& vertexShader,
113 const rr::FragmentShader& fragmentShader)
114 : DrawContext (drawState, drawCallData)
115 , m_vertexShader (vertexShader)
116 , m_fragmentShader (fragmentShader)
119 virtual ~ReferenceDrawContext (void);
120 virtual void draw (void);
121 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
123 const rr::VertexShader& m_vertexShader;
124 const rr::FragmentShader& m_fragmentShader;
125 tcu::TextureLevel m_refImage;
130 const std::vector<Shader>& shaders;
131 vk::Move<vk::VkImageView> depthImageView;
132 vk::Move<vk::VkDescriptorSetLayout> descriptorSetLayout;
133 vk::Move<vk::VkDescriptorSet> descriptorSet;
135 VulkanProgram (const std::vector<Shader>& shaders_)
141 class VulkanDrawContext : public DrawContext
144 VulkanDrawContext (Context& context,
145 const DrawState& drawState,
146 const DrawCallData& drawCallData,
147 VulkanProgram& vulkanProgram);
148 virtual ~VulkanDrawContext (void);
149 virtual void draw (void);
150 virtual tcu::ConstPixelBufferAccess getColorPixels (void) const;
154 MAX_NUM_SHADER_MODULES = 5,
157 VulkanProgram& m_program;
158 de::MovePtr<vk::ImageWithMemory> m_colorImage;
159 de::MovePtr<vk::ImageWithMemory> m_resolveImage;
160 de::MovePtr<vk::BufferWithMemory> m_colorAttachmentBuffer;
161 vk::refdetails::Move<vk::VkImageView> m_colorImageView;
162 vk::refdetails::Move<vk::VkRenderPass> m_renderPass;
163 vk::refdetails::Move<vk::VkFramebuffer> m_framebuffer;
164 vk::refdetails::Move<vk::VkPipelineLayout> m_pipelineLayout;
165 vk::refdetails::Move<vk::VkPipeline> m_pipeline;
166 vk::refdetails::Move<vk::VkCommandPool> m_cmdPool;
167 vk::refdetails::Move<vk::VkCommandBuffer> m_cmdBuffer;
168 vk::refdetails::Move<vk::VkShaderModule> m_shaderModules[MAX_NUM_SHADER_MODULES];
169 de::MovePtr<vk::BufferWithMemory> m_vertexBuffer;
172 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
177 #endif // _VKTDRAWUTIL_HPP