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