1 #ifndef _VKTDYNAMICSTATEBASECLASS_HPP
2 #define _VKTDYNAMICSTATEBASECLASS_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 The Khronos Group Inc.
8  * Copyright (c) 2015 Intel Corporation
9  * Copyright (c) 2023 LunarG, Inc.
10  * Copyright (c) 2023 Nintendo
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *      http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  *//*!
25 * \file
26 * \brief Dynamic State Tests - Base Class
27 *//*--------------------------------------------------------------------*/
28 
29 #include "tcuDefs.hpp"
30 #include "vktTestCase.hpp"
31 
32 #include "vktDynamicStateTestCaseUtil.hpp"
33 #include "vktDrawImageObjectUtil.hpp"
34 #include "vktDrawBufferObjectUtil.hpp"
35 #include "vktDrawCreateInfoUtil.hpp"
36 #include "vkPipelineConstructionUtil.hpp"
37 
38 namespace vkt
39 {
40 namespace DynamicState
41 {
42 
43 class DynamicStateBaseClass : public TestInstance
44 {
45 public:
46     DynamicStateBaseClass(Context &context, vk::PipelineConstructionType pipelineConstructionType,
47                           const char *vertexShaderName, const char *fragmentShaderName,
48                           const char *meshShaderName = nullptr);
49 
50 protected:
51     void initialize(void);
52 
53     virtual void initRenderPass(const vk::VkDevice device);
54     virtual void initFramebuffer(const vk::VkDevice device);
55     virtual void initPipeline(const vk::VkDevice device);
56 
57     virtual tcu::TestStatus iterate(void);
58 
59     void beginRenderPass(void);
60 
61     void beginRenderPassWithClearColor(const vk::VkClearColorValue &clearColor, const bool skipBeginCmdBuffer = false,
62                                        const bool previousTransfer = false);
63 
64     void setDynamicViewportState(const uint32_t width, const uint32_t height);
65 
66     void setDynamicViewportState(uint32_t viewportCount, const vk::VkViewport *pViewports,
67                                  const vk::VkRect2D *pScissors);
68 
69     void setDynamicRasterizationState(const float lineWidth = 1.0f, const float depthBiasConstantFactor = 0.0f,
70                                       const float depthBiasClamp = 0.0f, const float depthBiasSlopeFactor = 0.0f);
71 
72     void setDynamicBlendState(const float const1 = 0.0f, const float const2 = 0.0f, const float const3 = 0.0f,
73                               const float const4 = 0.0f);
74 
75     void setDynamicDepthStencilState(const float minDepthBounds = 0.0f, const float maxDepthBounds = 1.0f,
76                                      const uint32_t stencilFrontCompareMask = 0xffffffffu,
77                                      const uint32_t stencilFrontWriteMask   = 0xffffffffu,
78                                      const uint32_t stencilFrontReference   = 0,
79                                      const uint32_t stencilBackCompareMask  = 0xffffffffu,
80                                      const uint32_t stencilBackWriteMask    = 0xffffffffu,
81                                      const uint32_t stencilBackReference    = 0);
82 
83 #ifndef CTS_USES_VULKANSC
84     void pushVertexOffset(const uint32_t vertexOffset, const vk::VkPipelineLayout pipelineLayout,
85                           const vk::VkShaderStageFlags stageFlags = vk::VK_SHADER_STAGE_MESH_BIT_EXT);
86 #endif // CTS_USES_VULKANSC
87 
88     enum
89     {
90         WIDTH  = 128,
91         HEIGHT = 128
92     };
93 
94     vk::PipelineConstructionType m_pipelineConstructionType;
95     vk::VkFormat m_colorAttachmentFormat;
96 
97     vk::VkPrimitiveTopology m_topology;
98 
99     const vk::DeviceInterface &m_vk;
100 
101     vk::Move<vk::VkDescriptorPool> m_descriptorPool;
102     vk::Move<vk::VkDescriptorSetLayout> m_meshSetLayout;
103     vk::Move<vk::VkDescriptorSetLayout> m_otherSetLayout;
104     vk::PipelineLayoutWrapper m_pipelineLayout;
105     vk::Move<vk::VkDescriptorSet> m_descriptorSet;
106     vk::GraphicsPipelineWrapper m_pipeline;
107 
108     de::SharedPtr<Draw::Image> m_colorTargetImage;
109     vk::Move<vk::VkImageView> m_colorTargetView;
110 
111     Draw::PipelineCreateInfo::VertexInputState m_vertexInputState;
112     de::SharedPtr<Draw::Buffer> m_vertexBuffer;
113 
114     vk::Move<vk::VkCommandPool> m_cmdPool;
115     vk::Move<vk::VkCommandBuffer> m_cmdBuffer;
116 
117     vk::RenderPassWrapper m_renderPass;
118 
119     const std::string m_vertexShaderName;
120     const std::string m_fragmentShaderName;
121     const std::string m_meshShaderName;
122     std::vector<PositionColorVertex> m_data;
123     bool m_isMesh;
124 
125     Draw::PipelineCreateInfo::ColorBlendState::Attachment m_attachmentState;
126 };
127 
128 } // namespace DynamicState
129 } // namespace vkt
130 
131 #endif // _VKTDYNAMICSTATEBASECLASS_HPP
132