Remove dead members from synchronization OperationContext
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / synchronization / vktSynchronizationOperation.hpp
1 #ifndef _VKTSYNCHRONIZATIONOPERATION_HPP
2 #define _VKTSYNCHRONIZATIONOPERATION_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 Synchronization operation abstraction
24  *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "vkDefs.hpp"
28 #include "vkPrograms.hpp"
29 #include "vktTestCase.hpp"
30 #include "vktSynchronizationUtil.hpp"
31 #include "tcuVector.hpp"
32 #include "deUniquePtr.hpp"
33 #include <string>
34
35 namespace vkt
36 {
37 namespace synchronization
38 {
39
40 enum OperationName
41 {
42         // Write operations
43         OPERATION_NAME_WRITE_FILL_BUFFER,
44         OPERATION_NAME_WRITE_UPDATE_BUFFER,
45         OPERATION_NAME_WRITE_COPY_BUFFER,
46         OPERATION_NAME_WRITE_COPY_BUFFER_TO_IMAGE,
47         OPERATION_NAME_WRITE_COPY_IMAGE_TO_BUFFER,
48         OPERATION_NAME_WRITE_COPY_IMAGE,
49         OPERATION_NAME_WRITE_BLIT_IMAGE,
50         OPERATION_NAME_WRITE_SSBO_VERTEX,
51         OPERATION_NAME_WRITE_SSBO_TESSELLATION_CONTROL,
52         OPERATION_NAME_WRITE_SSBO_TESSELLATION_EVALUATION,
53         OPERATION_NAME_WRITE_SSBO_GEOMETRY,
54         OPERATION_NAME_WRITE_SSBO_FRAGMENT,
55         OPERATION_NAME_WRITE_SSBO_COMPUTE,
56         OPERATION_NAME_WRITE_SSBO_COMPUTE_INDIRECT,
57         OPERATION_NAME_WRITE_IMAGE_VERTEX,
58         OPERATION_NAME_WRITE_IMAGE_TESSELLATION_CONTROL,
59         OPERATION_NAME_WRITE_IMAGE_TESSELLATION_EVALUATION,
60         OPERATION_NAME_WRITE_IMAGE_GEOMETRY,
61         OPERATION_NAME_WRITE_IMAGE_FRAGMENT,
62         OPERATION_NAME_WRITE_IMAGE_COMPUTE,
63         OPERATION_NAME_WRITE_IMAGE_COMPUTE_INDIRECT,
64         OPERATION_NAME_WRITE_CLEAR_COLOR_IMAGE,
65         OPERATION_NAME_WRITE_CLEAR_DEPTH_STENCIL_IMAGE,
66         OPERATION_NAME_WRITE_DRAW,
67         OPERATION_NAME_WRITE_DRAW_INDEXED,
68         OPERATION_NAME_WRITE_DRAW_INDIRECT,
69         OPERATION_NAME_WRITE_DRAW_INDEXED_INDIRECT,
70         OPERATION_NAME_WRITE_CLEAR_ATTACHMENTS,
71         OPERATION_NAME_WRITE_INDIRECT_BUFFER_DRAW,
72         OPERATION_NAME_WRITE_INDIRECT_BUFFER_DRAW_INDEXED,
73         OPERATION_NAME_WRITE_INDIRECT_BUFFER_DISPATCH,
74
75         // Read operations
76         OPERATION_NAME_READ_COPY_BUFFER,
77         OPERATION_NAME_READ_COPY_BUFFER_TO_IMAGE,
78         OPERATION_NAME_READ_COPY_IMAGE_TO_BUFFER,
79         OPERATION_NAME_READ_COPY_IMAGE,
80         OPERATION_NAME_READ_BLIT_IMAGE,
81         OPERATION_NAME_READ_UBO_VERTEX,
82         OPERATION_NAME_READ_UBO_TESSELLATION_CONTROL,
83         OPERATION_NAME_READ_UBO_TESSELLATION_EVALUATION,
84         OPERATION_NAME_READ_UBO_GEOMETRY,
85         OPERATION_NAME_READ_UBO_FRAGMENT,
86         OPERATION_NAME_READ_UBO_COMPUTE,
87         OPERATION_NAME_READ_UBO_COMPUTE_INDIRECT,
88         OPERATION_NAME_READ_SSBO_VERTEX,
89         OPERATION_NAME_READ_SSBO_TESSELLATION_CONTROL,
90         OPERATION_NAME_READ_SSBO_TESSELLATION_EVALUATION,
91         OPERATION_NAME_READ_SSBO_GEOMETRY,
92         OPERATION_NAME_READ_SSBO_FRAGMENT,
93         OPERATION_NAME_READ_SSBO_COMPUTE,
94         OPERATION_NAME_READ_SSBO_COMPUTE_INDIRECT,
95         OPERATION_NAME_READ_IMAGE_VERTEX,
96         OPERATION_NAME_READ_IMAGE_TESSELLATION_CONTROL,
97         OPERATION_NAME_READ_IMAGE_TESSELLATION_EVALUATION,
98         OPERATION_NAME_READ_IMAGE_GEOMETRY,
99         OPERATION_NAME_READ_IMAGE_FRAGMENT,
100         OPERATION_NAME_READ_IMAGE_COMPUTE,
101         OPERATION_NAME_READ_IMAGE_COMPUTE_INDIRECT,
102         OPERATION_NAME_READ_INDIRECT_BUFFER_DRAW,
103         OPERATION_NAME_READ_INDIRECT_BUFFER_DRAW_INDEXED,
104         OPERATION_NAME_READ_INDIRECT_BUFFER_DISPATCH,
105         OPERATION_NAME_READ_VERTEX_INPUT,
106
107         // Copy operations
108         OPERATION_NAME_COPY_BUFFER,
109         OPERATION_NAME_COPY_IMAGE,
110         OPERATION_NAME_BLIT_IMAGE,
111         OPERATION_NAME_COPY_SSBO_VERTEX,
112         OPERATION_NAME_COPY_SSBO_TESSELLATION_CONTROL,
113         OPERATION_NAME_COPY_SSBO_TESSELLATION_EVALUATION,
114         OPERATION_NAME_COPY_SSBO_GEOMETRY,
115         OPERATION_NAME_COPY_SSBO_FRAGMENT,
116         OPERATION_NAME_COPY_SSBO_COMPUTE,
117         OPERATION_NAME_COPY_SSBO_COMPUTE_INDIRECT,
118         OPERATION_NAME_COPY_IMAGE_VERTEX,
119         OPERATION_NAME_COPY_IMAGE_TESSELLATION_CONTROL,
120         OPERATION_NAME_COPY_IMAGE_TESSELLATION_EVALUATION,
121         OPERATION_NAME_COPY_IMAGE_GEOMETRY,
122         OPERATION_NAME_COPY_IMAGE_FRAGMENT,
123         OPERATION_NAME_COPY_IMAGE_COMPUTE,
124         OPERATION_NAME_COPY_IMAGE_COMPUTE_INDIRECT,
125 };
126
127 // Similar to Context, but allows test instance to decide which resources are used by the operation.
128 // E.g. this is needed when we want operation to work on a particular queue instead of the universal queue.
129 class OperationContext
130 {
131 public:
132                                                                         OperationContext                (Context&                       context,
133                                                                                                                          PipelineCacheData&     pipelineCacheData);
134
135                                                                         OperationContext                (Context&                                       context,
136                                                                                                                          PipelineCacheData&                     pipelineCacheData,
137                                                                                                                          const vk::DeviceInterface&     vk,
138                                                                                                                          const vk::VkDevice                     device,
139                                                                                                                          vk::Allocator&                         allocator);
140
141                                                                         OperationContext                (Context&                                                       context,
142                                                                                                                          const vk::InstanceInterface&           vki,
143                                                                                                                          const vk::DeviceInterface&                     vkd,
144                                                                                                                          vk::VkPhysicalDevice                           physicalDevice,
145                                                                                                                          vk::VkDevice                                           device,
146                                                                                                                          vk::Allocator&                                         allocator,
147                                                                                                                          vk::BinaryCollection&                          programCollection,
148                                                                                                                          PipelineCacheData&                                     pipelineCacheData);
149
150         const vk::InstanceInterface&    getInstanceInterface    (void) const { return m_vki; }
151         const vk::DeviceInterface&              getDeviceInterface              (void) const { return m_vk; }
152         vk::VkPhysicalDevice                    getPhysicalDevice               (void) const { return m_physicalDevice; }
153         vk::VkDevice                                    getDevice                               (void) const { return m_device; }
154         vk::Allocator&                                  getAllocator                    (void) const { return m_allocator; }
155         vk::BinaryCollection&                   getBinaryCollection             (void) const { return m_progCollection; }
156         PipelineCacheData&                              getPipelineCacheData    (void) const { return m_pipelineCacheData; }
157
158         bool isDeviceFunctionalitySupported(const std::string& extension) const
159         {
160                 return m_context.isDeviceFunctionalitySupported(extension);
161         }
162
163 private:
164         const vkt::Context&                             m_context;
165         const vk::InstanceInterface&    m_vki;
166         const vk::DeviceInterface&              m_vk;
167         const vk::VkPhysicalDevice              m_physicalDevice;
168         const vk::VkDevice                              m_device;
169         vk::Allocator&                                  m_allocator;
170         vk::BinaryCollection&                   m_progCollection;
171         PipelineCacheData&                              m_pipelineCacheData;
172
173         // Disabled
174                                                                         OperationContext                (const OperationContext&);
175         OperationContext&                               operator=                               (const OperationContext&);
176 };
177
178 // Common interface to images and buffers used by operations.
179 class Resource
180 {
181 public:
182                                                         Resource        (OperationContext&                              context,
183                                                                                  const ResourceDescription&             desc,
184                                                                                  const deUint32                                 usage,
185                                                                                  const vk::VkSharingMode                sharingMode = vk::VK_SHARING_MODE_EXCLUSIVE,
186                                                                                  const std::vector<deUint32>&   queueFamilyIndex = std::vector<deUint32>());
187
188                                                         Resource        (ResourceType                                   type,
189                                                                                  vk::Move<vk::VkBuffer>                 buffer,
190                                                                                  de::MovePtr<vk::Allocation>    allocation,
191                                                                                  vk::VkDeviceSize                               offset,
192                                                                                  vk::VkDeviceSize                               size);
193
194                                                         Resource        (vk::Move<vk::VkImage>                  image,
195                                                                                  de::MovePtr<vk::Allocation>    allocation,
196                                                                                  const vk::VkExtent3D&                  extent,
197                                                                                  vk::VkImageType                                imageType,
198                                                                                  vk::VkFormat                                   format,
199                                                                                  vk::VkImageSubresourceRange    subresourceRange,
200                                                                                  vk::VkImageSubresourceLayers   subresourceLayers);
201
202         ResourceType                    getType         (void) const { return m_type; }
203         const BufferResource&   getBuffer       (void) const { return m_bufferData; }
204         const ImageResource&    getImage        (void) const { return m_imageData; }
205
206         vk::VkDeviceMemory              getMemory       (void) const;
207
208 private:
209         const ResourceType              m_type;
210         de::MovePtr<Buffer>             m_buffer;
211         BufferResource                  m_bufferData;
212         de::MovePtr<Image>              m_image;
213         ImageResource                   m_imageData;
214 };
215
216 // \note Meaning of image layout is different for read and write types of operations:
217 //       read  - the layout image must be in before being passed to the read operation
218 //       write - the layout image will be in after the write operation has finished
219 struct SyncInfo
220 {
221         vk::VkPipelineStageFlags        stageMask;              // pipeline stage where read/write takes place
222         vk::VkAccessFlags                       accessMask;             // type of access that is performed
223         vk::VkImageLayout                       imageLayout;    // src (for reads) or dst (for writes) image layout
224 };
225
226 struct Data
227 {
228         std::size_t                                     size;
229         const deUint8*                          data;
230 };
231
232 // Abstract operation on a resource
233 // \note Meaning of getData is different for read and write operations:
234 //       read  - data actually read by the operation
235 //       write - expected data that operation was supposed to write
236 // \note It's assumed that recordCommands is called only once (i.e. no multiple command buffers are using these commands).
237 class Operation
238 {
239 public:
240                                                 Operation               (void) {}
241         virtual                         ~Operation              (void) {}
242
243         virtual void            recordCommands  (const vk::VkCommandBuffer cmdBuffer) = 0;      // commands that carry out this operation
244         virtual SyncInfo        getInSyncInfo   (void) const = 0;                                                       // data required to properly synchronize this operation
245         virtual SyncInfo        getOutSyncInfo  (void) const = 0;                                                       // data required to properly synchronize this operation
246         virtual Data            getData                 (void) const = 0;                                                       // get raw data that was written to or read from actual resource
247         virtual void            setData                 (const Data& data) = 0;                                         // set raw data to be read from actual resource
248
249 private:
250                                                 Operation               (const Operation&);
251         Operation&                      operator=               (const Operation&);
252 };
253
254 // A helper class to init programs and create the operation when context becomes available.
255 // Throws OperationInvalidResourceError when resource and operation combination is not possible (e.g. buffer-specific op on an image).
256 class OperationSupport
257 {
258 public:
259                                                                         OperationSupport                        (void) {}
260         virtual                                                 ~OperationSupport                       (void) {}
261
262         virtual deUint32                                getInResourceUsageFlags         (void) const = 0;
263         virtual deUint32                                getOutResourceUsageFlags        (void) const = 0;
264         virtual vk::VkQueueFlags                getQueueFlags                           (const OperationContext& context) const = 0;
265         virtual void                                    initPrograms                            (vk::SourceCollections&) const {}       //!< empty by default
266
267         virtual de::MovePtr<Operation>  build                                           (OperationContext& context, Resource& resource) const = 0;
268         virtual de::MovePtr<Operation>  build                                           (OperationContext& context, Resource& inResource, Resource& outResource) const = 0;
269
270 private:
271                                                                         OperationSupport                        (const OperationSupport&);
272         OperationSupport&                               operator=                                       (const OperationSupport&);
273 };
274
275 bool                                                    isResourceSupported             (const OperationName opName, const ResourceDescription& resourceDesc);
276 de::MovePtr<OperationSupport>   makeOperationSupport    (const OperationName opName, const ResourceDescription& resourceDesc);
277 std::string                                             getOperationName                (const OperationName opName);
278
279 } // synchronization
280 } // vkt
281
282 #endif // _VKTSYNCHRONIZATIONOPERATION_HPP