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