Merge gerrit/vulkan-cts-1.0.0 into gerrit/vulkan-cts-1.0.1
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / pipeline / vktPipelineSpecConstantUtil.hpp
1 #ifndef _VKTPIPELINESPECCONSTANTUTIL_HPP
2 #define _VKTPIPELINESPECCONSTANTUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Pipeline specialization constants test utilities
24  *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include "vkRef.hpp"
28 #include "vkPrograms.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkQueryUtil.hpp"
32
33 namespace vkt
34 {
35 namespace pipeline
36 {
37
38 class Buffer
39 {
40 public:
41                                                                                 Buffer                  (const vk::DeviceInterface&             vk,
42                                                                                                                  const vk::VkDevice                             device,
43                                                                                                                  vk::Allocator&                                 allocator,
44                                                                                                                  const vk::VkBufferCreateInfo&  bufferCreateInfo,
45                                                                                                                  const vk::MemoryRequirement    memoryRequirement)
46
47                                                                                         : m_buffer              (createBuffer(vk, device, &bufferCreateInfo))
48                                                                                         , m_allocation  (allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement))
49                                                                                 {
50                                                                                         VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
51                                                                                 }
52
53         const vk::VkBuffer&                                     get                             (void) const { return *m_buffer; }
54         const vk::VkBuffer&                                     operator*               (void) const { return get(); }
55         vk::Allocation&                                         getAllocation   (void) const { return *m_allocation; }
56
57 private:
58         const vk::Unique<vk::VkBuffer>          m_buffer;
59         const de::UniquePtr<vk::Allocation>     m_allocation;
60
61         // "deleted"
62                                                                                 Buffer                  (const Buffer&);
63         Buffer&                                                         operator=               (const Buffer&);
64 };
65
66 class Image
67 {
68 public:
69                                                                                 Image                   (const vk::DeviceInterface&             vk,
70                                                                                                                  const vk::VkDevice                             device,
71                                                                                                                  vk::Allocator&                                 allocator,
72                                                                                                                  const vk::VkImageCreateInfo&   imageCreateInfo,
73                                                                                                                  const vk::MemoryRequirement    memoryRequirement)
74
75                                                                                         : m_image               (createImage(vk, device, &imageCreateInfo))
76                                                                                         , m_allocation  (allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement))
77                                                                                 {
78                                                                                         VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
79                                                                                 }
80
81         const vk::VkImage&                                      get                             (void) const { return *m_image; }
82         const vk::VkImage&                                      operator*               (void) const { return get(); }
83         vk::Allocation&                                         getAllocation   (void) const { return *m_allocation; }
84
85 private:
86         const vk::Unique<vk::VkImage>           m_image;
87         const de::UniquePtr<vk::Allocation>     m_allocation;
88
89         // "deleted"
90                                                                                 Image                   (const Image&);
91         Image&                                                          operator=               (const Image&);
92 };
93
94 class GraphicsPipelineBuilder
95 {
96 public:
97                                                                                                                 GraphicsPipelineBuilder                 (void) : m_renderSize           (16, 16)
98                                                                                                                                                                                            , m_shaderStageFlags (0u) {}
99
100         GraphicsPipelineBuilder&                                                        setRenderSize                                   (const tcu::IVec2& size) { m_renderSize = size; return *this; }
101         GraphicsPipelineBuilder&                                                        setShader                                               (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo);
102         vk::Move<vk::VkPipeline>                                                        build                                                   (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
103
104 private:
105         tcu::IVec2                                                                                      m_renderSize;
106         vk::Move<vk::VkShaderModule>                                            m_vertexShaderModule;
107         vk::Move<vk::VkShaderModule>                                            m_fragmentShaderModule;
108         vk::Move<vk::VkShaderModule>                                            m_geometryShaderModule;
109         vk::Move<vk::VkShaderModule>                                            m_tessControlShaderModule;
110         vk::Move<vk::VkShaderModule>                                            m_tessEvaluationShaderModule;
111         std::vector<vk::VkPipelineShaderStageCreateInfo>        m_shaderStages;
112         vk::VkShaderStageFlags                                                          m_shaderStageFlags;
113
114                                                                                                                 GraphicsPipelineBuilder                 (const GraphicsPipelineBuilder&); // "deleted"
115         GraphicsPipelineBuilder&                                                        operator=                                               (const GraphicsPipelineBuilder&);
116 };
117
118 enum FeatureFlagBits
119 {
120         FEATURE_TESSELLATION_SHADER                                     = 1u << 0,
121         FEATURE_GEOMETRY_SHADER                                         = 1u << 1,
122         FEATURE_SHADER_FLOAT_64                                         = 1u << 2,
123         FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS      = 1u << 3,
124         FEATURE_FRAGMENT_STORES_AND_ATOMICS                     = 1u << 4,
125 };
126 typedef deUint32 FeatureFlags;
127
128 vk::VkBufferCreateInfo                  makeBufferCreateInfo    (const vk::VkDeviceSize bufferSize, const vk::VkBufferUsageFlags usage);
129 vk::VkImageCreateInfo                   makeImageCreateInfo             (const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage);
130 vk::Move<vk::VkCommandPool>             makeCommandPool                 (const vk::DeviceInterface& vk, const vk::VkDevice device, const deUint32 queueFamilyIndex);
131 vk::Move<vk::VkCommandBuffer>   makeCommandBuffer               (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkCommandPool commandPool);
132 vk::Move<vk::VkDescriptorSet>   makeDescriptorSet               (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout);
133 vk::Move<vk::VkPipelineLayout>  makePipelineLayout              (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorSetLayout descriptorSetLayout);
134 vk::Move<vk::VkPipeline>                makeComputePipeline             (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkShaderModule shaderModule, const vk::VkSpecializationInfo* specInfo);
135 vk::Move<vk::VkRenderPass>              makeRenderPass                  (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkFormat colorFormat);
136 vk::Move<vk::VkFramebuffer>             makeFramebuffer                 (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkRenderPass renderPass, const vk::VkImageView colorAttachment, const deUint32 width, const deUint32 height);
137 vk::Move<vk::VkImageView>               makeImageView                   (const vk::DeviceInterface& vk, const vk::VkDevice vkDevice, const vk::VkImage image, const vk::VkImageViewType viewType, const vk::VkFormat format);
138 vk::VkBufferMemoryBarrier               makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkBuffer buffer, const vk::VkDeviceSize offset, const vk::VkDeviceSize bufferSizeBytes);
139 vk::VkImageMemoryBarrier                makeImageMemoryBarrier  (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkImageLayout oldLayout, const vk::VkImageLayout newLayout, const vk::VkImage image, const vk::VkImageSubresourceRange subresourceRange);
140 void                                                    beginCommandBuffer              (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
141 void                                                    endCommandBuffer                (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
142 void                                                    submitCommandsAndWait   (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkQueue queue, const vk::VkCommandBuffer commandBuffer);
143 void                                                    beginRenderPass                 (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer, const vk::VkRenderPass renderPass, const vk::VkFramebuffer framebuffer, const vk::VkRect2D& renderArea, const tcu::Vec4& clearColor);
144 void                                                    endRenderPass                   (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
145 void                                                    requireFeatures                 (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice, const FeatureFlags flags);
146
147 // Ugly, brute-force replacement for the initializer list
148
149 template<typename T>
150 std::vector<T> makeVector (const T& o1)
151 {
152         std::vector<T> vec;
153         vec.reserve(1);
154         vec.push_back(o1);
155         return vec;
156 }
157
158 template<typename T>
159 std::vector<T> makeVector (const T& o1, const T& o2)
160 {
161         std::vector<T> vec;
162         vec.reserve(2);
163         vec.push_back(o1);
164         vec.push_back(o2);
165         return vec;
166 }
167
168 template<typename T>
169 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3)
170 {
171         std::vector<T> vec;
172         vec.reserve(3);
173         vec.push_back(o1);
174         vec.push_back(o2);
175         vec.push_back(o3);
176         return vec;
177 }
178
179 template<typename T>
180 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3, const T& o4)
181 {
182         std::vector<T> vec;
183         vec.reserve(4);
184         vec.push_back(o1);
185         vec.push_back(o2);
186         vec.push_back(o3);
187         vec.push_back(o4);
188         return vec;
189 }
190
191 } // pipeline
192 } // vkt
193
194 #endif // _VKTPIPELINESPECCONSTANTUTIL_HPP