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 108 // Similar to Context, but allows test instance to decide which resources are used by the operation. 109 // E.g. this is needed when we want operation to work on a particular queue instead of the universal queue. 110 class OperationContext 111 { 112 public: 113 OperationContext (Context& context, 114 PipelineCacheData& pipelineCacheData); 115 116 OperationContext (Context& context, 117 PipelineCacheData& pipelineCacheData, 118 const vk::DeviceInterface& vk, 119 const vk::VkDevice device, 120 vk::Allocator& allocator); 121 122 OperationContext (const vk::InstanceInterface& vki, 123 const vk::DeviceInterface& vkd, 124 vk::VkPhysicalDevice physicalDevice, 125 vk::VkDevice device, 126 vk::Allocator& allocator, 127 const std::vector<std::string>& deviceExtensions, 128 vk::ProgramCollection<vk::ProgramBinary>& programCollection, 129 PipelineCacheData& pipelineCacheData); 130 131 const vk::InstanceInterface& getInstanceInterface (void) const { return m_vki; } 132 const vk::DeviceInterface& getDeviceInterface (void) const { return m_vk; } 133 vk::VkPhysicalDevice getPhysicalDevice (void) const { return m_physicalDevice; } 134 vk::VkDevice getDevice (void) const { return m_device; } 135 vk::Allocator& getAllocator (void) const { return m_allocator; } 136 vk::ProgramCollection<vk::ProgramBinary>& getBinaryCollection (void) const { return m_progCollection; } 137 PipelineCacheData& getPipelineCacheData (void) const { return m_pipelineCacheData; } 138 const std::vector<std::string>& getDeviceExtensions (void) const { return m_deviceExtensions;} 139 140 private: 141 const vk::InstanceInterface& m_vki; 142 const vk::DeviceInterface& m_vk; 143 const vk::VkPhysicalDevice m_physicalDevice; 144 const vk::VkDevice m_device; 145 vk::Allocator& m_allocator; 146 vk::ProgramCollection<vk::ProgramBinary>& m_progCollection; 147 PipelineCacheData& m_pipelineCacheData; 148 const std::vector<std::string>& m_deviceExtensions; 149 150 // Disabled 151 OperationContext (const OperationContext&); 152 OperationContext& operator= (const OperationContext&); 153 }; 154 155 // Common interface to images and buffers used by operations. 156 class Resource 157 { 158 public: 159 Resource (OperationContext& context, 160 const ResourceDescription& desc, 161 const deUint32 usage, 162 const vk::VkSharingMode sharingMode = vk::VK_SHARING_MODE_EXCLUSIVE, 163 const std::vector<deUint32>& queueFamilyIndex = std::vector<deUint32>()); 164 165 Resource (ResourceType type, 166 vk::Move<vk::VkBuffer> buffer, 167 de::MovePtr<vk::Allocation> allocation, 168 vk::VkDeviceSize offset, 169 vk::VkDeviceSize size); 170 171 Resource (vk::Move<vk::VkImage> image, 172 de::MovePtr<vk::Allocation> allocation, 173 const vk::VkExtent3D& extent, 174 vk::VkImageType imageType, 175 vk::VkFormat format, 176 vk::VkImageSubresourceRange subresourceRange, 177 vk::VkImageSubresourceLayers subresourceLayers); 178 179 ResourceType getType (void) const { return m_type; } 180 const BufferResource& getBuffer (void) const { return m_bufferData; } 181 const ImageResource& getImage (void) const { return m_imageData; } 182 183 vk::VkDeviceMemory getMemory (void) const; 184 185 private: 186 const ResourceType m_type; 187 de::MovePtr<Buffer> m_buffer; 188 BufferResource m_bufferData; 189 de::MovePtr<Image> m_image; 190 ImageResource m_imageData; 191 }; 192 193 // \note Meaning of image layout is different for read and write types of operations: 194 // read - the layout image must be in before being passed to the read operation 195 // write - the layout image will be in after the write operation has finished 196 struct SyncInfo 197 { 198 vk::VkPipelineStageFlags stageMask; // pipeline stage where read/write takes place 199 vk::VkAccessFlags accessMask; // type of access that is performed 200 vk::VkImageLayout imageLayout; // src (for reads) or dst (for writes) image layout 201 }; 202 203 struct Data 204 { 205 std::size_t size; 206 const deUint8* data; 207 }; 208 209 // Abstract operation on a resource 210 // \note Meaning of getData is different for read and write operations: 211 // read - data actually read by the operation 212 // write - expected data that operation was supposed to write 213 // \note It's assumed that recordCommands is called only once (i.e. no multiple command buffers are using these commands). 214 class Operation 215 { 216 public: 217 Operation (void) {} 218 virtual ~Operation (void) {} 219 220 virtual void recordCommands (const vk::VkCommandBuffer cmdBuffer) = 0; // commands that carry out this operation 221 virtual SyncInfo getSyncInfo (void) const = 0; // data required to properly synchronize this operation 222 virtual Data getData (void) const = 0; // get raw data that was written to or read from actual resource 223 224 private: 225 Operation (const Operation&); 226 Operation& operator= (const Operation&); 227 }; 228 229 // A helper class to init programs and create the operation when context becomes available. 230 // Throws OperationInvalidResourceError when resource and operation combination is not possible (e.g. buffer-specific op on an image). 231 class OperationSupport 232 { 233 public: 234 OperationSupport (void) {} 235 virtual ~OperationSupport (void) {} 236 237 virtual deUint32 getResourceUsageFlags (void) const = 0; 238 virtual vk::VkQueueFlags getQueueFlags (const OperationContext& context) const = 0; 239 virtual void initPrograms (vk::SourceCollections&) const {} //!< empty by default 240 241 virtual de::MovePtr<Operation> build (OperationContext& context, Resource& resource) const = 0; 242 243 private: 244 OperationSupport (const OperationSupport&); 245 OperationSupport& operator= (const OperationSupport&); 246 }; 247 248 bool isResourceSupported (const OperationName opName, const ResourceDescription& resourceDesc); 249 de::MovePtr<OperationSupport> makeOperationSupport (const OperationName opName, const ResourceDescription& resourceDesc); 250 std::string getOperationName (const OperationName opName); 251 252 } // synchronization 253 } // vkt 254 255 #endif // _VKTSYNCHRONIZATIONOPERATION_HPP 256