1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_VULKAN_EXTERNALMEMORY_SERVICE_H_ 16 #define DAWNNATIVE_VULKAN_EXTERNALMEMORY_SERVICE_H_ 17 18 #include "common/vulkan_platform.h" 19 #include "dawn_native/Error.h" 20 #include "dawn_native/VulkanBackend.h" 21 #include "dawn_native/vulkan/ExternalHandle.h" 22 23 namespace dawn_native { namespace vulkan { 24 class Device; 25 struct VulkanDeviceInfo; 26 }} // namespace dawn_native::vulkan 27 28 namespace dawn_native { namespace vulkan { namespace external_memory { 29 30 struct MemoryImportParams { 31 VkDeviceSize allocationSize; 32 uint32_t memoryTypeIndex; 33 }; 34 35 class Service { 36 public: 37 explicit Service(Device* device); 38 ~Service(); 39 40 static bool CheckSupport(const VulkanDeviceInfo& deviceInfo); 41 42 // True if the device reports it supports importing external memory. 43 bool SupportsImportMemory(VkFormat format, 44 VkImageType type, 45 VkImageTiling tiling, 46 VkImageUsageFlags usage, 47 VkImageCreateFlags flags); 48 49 // True if the device reports it supports creating VkImages from external memory. 50 bool SupportsCreateImage(const ExternalImageDescriptor* descriptor, 51 VkFormat format, 52 VkImageUsageFlags usage); 53 54 // Returns the parameters required for importing memory 55 ResultOrError<MemoryImportParams> GetMemoryImportParams( 56 const ExternalImageDescriptor* descriptor, 57 VkImage image); 58 59 // Given an external handle pointing to memory, import it into a VkDeviceMemory 60 ResultOrError<VkDeviceMemory> ImportMemory(ExternalMemoryHandle handle, 61 const MemoryImportParams& importParams, 62 VkImage image); 63 64 // Create a VkImage for the given handle type 65 ResultOrError<VkImage> CreateImage(const ExternalImageDescriptor* descriptor, 66 const VkImageCreateInfo& baseCreateInfo); 67 68 private: 69 Device* mDevice = nullptr; 70 71 // True if early checks pass that determine if the service is supported 72 bool mSupported = false; 73 }; 74 75 }}} // namespace dawn_native::vulkan::external_memory 76 77 #endif // DAWNNATIVE_VULKAN_EXTERNALMEMORY_SERVICE_H_ 78