xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/draw/vktDrawBaseClass.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTDRAWBASECLASS_HPP
2 #define _VKTDRAWBASECLASS_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Intel Corporation
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 Command draw Tests - Base Class
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vkDefs.hpp"
28 #include "vktTestCase.hpp"
29 #include "vktDrawGroupParams.hpp"
30 
31 #include "tcuTestLog.hpp"
32 #include "tcuResource.hpp"
33 #include "tcuImageCompare.hpp"
34 #include "tcuCommandLine.hpp"
35 
36 #include "vkRefUtil.hpp"
37 #include "vkImageUtil.hpp"
38 
39 #include "deSharedPtr.hpp"
40 
41 #include "vkPrograms.hpp"
42 
43 #include "vktDrawCreateInfoUtil.hpp"
44 #include "vktDrawImageObjectUtil.hpp"
45 #include "vktDrawBufferObjectUtil.hpp"
46 
47 namespace vkt
48 {
49 namespace Draw
50 {
51 
52 struct PositionColorVertex
53 {
PositionColorVertexvkt::Draw::PositionColorVertex54     PositionColorVertex(tcu::Vec4 position_, tcu::Vec4 color_) : position(position_), color(color_)
55     {
56     }
57 
58     tcu::Vec4 position;
59     tcu::Vec4 color;
60 };
61 
62 struct VertexElementData : public PositionColorVertex
63 {
VertexElementDatavkt::Draw::VertexElementData64     VertexElementData(tcu::Vec4 position_, tcu::Vec4 color_, uint32_t refVertexIndex_)
65         : PositionColorVertex(position_, color_)
66         , refVertexIndex(refVertexIndex_)
67     {
68     }
69 
70     uint32_t refVertexIndex;
71 };
72 
73 struct ReferenceImageCoordinates
74 {
ReferenceImageCoordinatesvkt::Draw::ReferenceImageCoordinates75     ReferenceImageCoordinates(void) : left(-0.3), right(0.3), top(0.3), bottom(-0.3)
76     {
77     }
78 
79     double left;
80     double right;
81     double top;
82     double bottom;
83 };
84 
85 struct ReferenceImageInstancedCoordinates
86 {
ReferenceImageInstancedCoordinatesvkt::Draw::ReferenceImageInstancedCoordinates87     ReferenceImageInstancedCoordinates(void) : left(-0.3), right(0.6), top(0.3), bottom(-0.6)
88     {
89     }
90 
91     double left;
92     double right;
93     double top;
94     double bottom;
95 };
96 
97 class DrawTestsBaseClass : public TestInstance
98 {
99 public:
100     DrawTestsBaseClass(Context &context, const char *vertexShaderName, const char *fragmentShaderName,
101                        const SharedGroupParams groupParams,
102                        vk::VkPrimitiveTopology topology = vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
103                        const uint32_t layers            = 1u);
104 
105 protected:
106     void initialize(void);
107     virtual void initPipeline(const vk::VkDevice device);
108     void preRenderBarriers(void);
109     void beginLegacyRender(vk::VkCommandBuffer cmdBuffer,
110                            const vk::VkSubpassContents content = vk::VK_SUBPASS_CONTENTS_INLINE);
111     void endLegacyRender(vk::VkCommandBuffer cmdBuffer);
iterate(void)112     virtual tcu::TestStatus iterate(void)
113     {
114         TCU_FAIL("Implement iterate() method!");
115     }
116 
117 #ifndef CTS_USES_VULKANSC
118     void beginSecondaryCmdBuffer(const vk::DeviceInterface &vk, const vk::VkRenderingFlagsKHR renderingFlags = 0u);
119     void beginDynamicRender(vk::VkCommandBuffer cmdBuffer, const vk::VkRenderingFlagsKHR renderingFlags = 0u);
120     void endDynamicRender(vk::VkCommandBuffer cmdBuffer);
121 #endif // CTS_USES_VULKANSC
122     virtual uint32_t getDefaultViewMask(void) const;
123 
124     enum
125     {
126         WIDTH  = 256,
127         HEIGHT = 256
128     };
129 
130     vk::VkFormat m_colorAttachmentFormat;
131 
132     const SharedGroupParams m_groupParams;
133     const vk::VkPrimitiveTopology m_topology;
134     const uint32_t m_layers; // For multiview.
135 
136     const vk::DeviceInterface &m_vk;
137 
138     vk::Move<vk::VkPipeline> m_pipeline;
139     vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
140 
141     de::SharedPtr<Image> m_colorTargetImage;
142     vk::Move<vk::VkImageView> m_colorTargetView;
143 
144     // vertex buffer for vertex colors & position
145     de::SharedPtr<Buffer> m_vertexBuffer;
146 
147     // vertex buffer with reference data used in VS
148     de::SharedPtr<Buffer> m_vertexRefDataBuffer;
149 
150     PipelineCreateInfo::VertexInputState m_vertexInputState;
151 
152     vk::Move<vk::VkCommandPool> m_cmdPool;
153     vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
154     vk::Move<vk::VkCommandBuffer> m_secCmdBuffer;
155 
156     vk::Move<vk::VkFramebuffer> m_framebuffer;
157     vk::Move<vk::VkRenderPass> m_renderPass;
158 
159     const std::string m_vertexShaderName;
160     const std::string m_fragmentShaderName;
161 
162     std::vector<VertexElementData> m_data;
163 };
164 
165 } // namespace Draw
166 } // namespace vkt
167 
168 #endif // _VKTDRAWBASECLASS_HPP
169