diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 0a8b9174d4..1e6bceb82d 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -712,31 +712,28 @@ source_set("sources") { "vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp", "vulkan/external_semaphore/SemaphoreServiceImplementationFD.h", ] + if (is_android) { + sources += [ + "vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp", + "vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h", + ] + } else if (is_linux || is_chromeos) { + sources += [ + "vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp", + "vulkan/external_memory/MemoryServiceImplementationDmaBuf.h", + "vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp", + "vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h", + ] + } } else if (is_fuchsia) { sources += [ + "vulkan/external_memory/MemoryServiceImplementationZicronHandle.cpp", + "vulkan/external_memory/MemoryServiceImplementationZicronHandle.h", "vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.cpp", "vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.h", ] } - if (is_chromeos) { - sources += - [ "vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp" ] - } else if (is_linux) { - sources += - [ "vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp" ] - } else if (is_fuchsia) { - sources += [ - "vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp", - ] - } else if (is_android) { - sources += [ - "vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp", - ] - } else { - sources += [ "vulkan/external_memory/MemoryServiceNull.cpp" ] - } - if (build_with_chromium && is_fuchsia) { # Necessary to ensure that the Vulkan libraries will be in the # final Fuchsia package. diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index fe39ea4454..9b8fc632b6 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -585,14 +585,13 @@ if (DAWN_ENABLE_VULKAN) if (UNIX AND NOT APPLE) target_sources(dawn_native PRIVATE + "vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp" + "vulkan/external_memory/MemoryServiceImplementationDmaBuf.h" "vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp" + "vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h" "vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp" "vulkan/external_semaphore/SemaphoreServiceImplementationFD.h" ) - else() - target_sources(dawn_native PRIVATE - "vulkan/external_memory/MemoryServiceNull.cpp" - ) endif() endif() diff --git a/src/dawn/native/vulkan/DeviceVk.cpp b/src/dawn/native/vulkan/DeviceVk.cpp index 907ca38f41..822e155626 100644 --- a/src/dawn/native/vulkan/DeviceVk.cpp +++ b/src/dawn/native/vulkan/DeviceVk.cpp @@ -853,8 +853,8 @@ MaybeError Device::ImportExternalImage(const ExternalImageDescriptorVk* descript "External semaphore usage not supported"); DAWN_INVALID_IF(!mExternalMemoryService->SupportsImportMemory( - VulkanImageFormat(this, textureDescriptor->format), VK_IMAGE_TYPE_2D, - VK_IMAGE_TILING_OPTIMAL, + descriptor->GetType(), VulkanImageFormat(this, textureDescriptor->format), + VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, VulkanImageUsage(usage, GetValidInternalFormat(textureDescriptor->format)), VK_IMAGE_CREATE_ALIAS_BIT_KHR), "External memory usage not supported"); @@ -862,8 +862,8 @@ MaybeError Device::ImportExternalImage(const ExternalImageDescriptorVk* descript // Import the external image's memory external_memory::MemoryImportParams importParams; DAWN_TRY_ASSIGN(importParams, mExternalMemoryService->GetMemoryImportParams(descriptor, image)); - DAWN_TRY_ASSIGN(*outAllocation, - mExternalMemoryService->ImportMemory(memoryHandle, importParams, image)); + DAWN_TRY_ASSIGN(*outAllocation, mExternalMemoryService->ImportMemory( + descriptor->GetType(), memoryHandle, importParams, image)); // Import semaphores we have to wait on before using the texture for (const ExternalSemaphoreHandle& handle : waitHandles) { diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp index 1f7a9a90a7..b916a8c1c4 100644 --- a/src/dawn/native/vulkan/TextureVk.cpp +++ b/src/dawn/native/vulkan/TextureVk.cpp @@ -794,7 +794,7 @@ MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptorVk* desc ASSERT(!GetFormat().IsMultiPlanar() || mCombinedAspect == Aspect::Color); mExternalState = ExternalState::PendingAcquire; - mExportQueueFamilyIndex = externalMemoryService->GetQueueFamilyIndex(); + mExportQueueFamilyIndex = externalMemoryService->GetQueueFamilyIndex(descriptor->GetType()); mPendingAcquireOldLayout = descriptor->releasedOldLayout; mPendingAcquireNewLayout = descriptor->releasedNewLayout; diff --git a/src/dawn/native/vulkan/external_memory/MemoryService.cpp b/src/dawn/native/vulkan/external_memory/MemoryService.cpp index 1f74778098..f751d75164 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryService.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryService.cpp @@ -12,47 +12,126 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include "dawn/native/vulkan/DeviceVk.h" #include "dawn/native/vulkan/external_memory/MemoryService.h" -#include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" + +#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h" +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h" +#endif // DAWN_PLATFORM_IS(LINUX) + +#if DAWN_PLATFORM_IS(ANDROID) +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h" +#endif // DAWN_PLATFORM_IS(ANDROID) + +#if DAWN_PLATFORM_IS(FUCHSIA) +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h" +#endif // DAWN_PLATFORM_IS(FUCHSIA) namespace dawn::native::vulkan::external_memory { +// static +bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { +#if DAWN_PLATFORM_IS(ANDROID) + return CheckAHardwareBufferSupport(deviceInfo); +#elif DAWN_PLATFORM_IS(FUCHSIA) + return CheckZirconHandleSupport(deviceInfo); +#elif DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) + return CheckOpaqueFDSupport(deviceInfo) || CheckDmaBufSupport(deviceInfo); +#else + return false; +#endif +} + +Service::Service(Device* device) { +#if DAWN_PLATFORM_IS(FUCHSIA) + if (CheckZirconHandleSupport(device->GetDeviceInfo())) { + mServiceImpls[ExternalImageType::OpaqueFD] = CreateZirconHandleService(device); + } +#endif // DAWN_PLATFORM_IS(FUCHSIA) + +#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) + if (CheckOpaqueFDSupport(device->GetDeviceInfo())) { + mServiceImpls[ExternalImageType::OpaqueFD] = CreateOpaqueFDService(device); + } + + if (CheckDmaBufSupport(device->GetDeviceInfo())) { + mServiceImpls[ExternalImageType::DmaBuf] = CreateDmaBufService(device); + } +#endif // DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) + +#if DAWN_PLATFORM_IS(ANDROID) + if (CheckAHardwareBufferSupport(device->GetDeviceInfo())) { + mServiceImpls[ExternalImageType::AHardwareBuffer] = CreateAHardwareBufferService(device); + } +#endif // DAWN_PLATFORM_IS(ANDROID) +} Service::~Service() = default; -bool Service::SupportsImportMemory(VkFormat format, +bool Service::SupportsImportMemory(ExternalImageType externalImageType, + VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags) { - return mImpl->SupportsImportMemory(format, type, tiling, usage, flags); + ServiceImplementation* serviceImpl = GetServiceImplementation(externalImageType); + ASSERT(serviceImpl); + + return serviceImpl->SupportsImportMemory(format, type, tiling, usage, flags); } bool Service::SupportsCreateImage(const ExternalImageDescriptor* descriptor, VkFormat format, VkImageUsageFlags usage, bool* supportsDisjoint) { - return mImpl->SupportsCreateImage(descriptor, format, usage, supportsDisjoint); + ServiceImplementation* serviceImpl = GetServiceImplementation(descriptor->GetType()); + ASSERT(serviceImpl); + + return serviceImpl->SupportsCreateImage(descriptor, format, usage, supportsDisjoint); } ResultOrError Service::GetMemoryImportParams( const ExternalImageDescriptor* descriptor, VkImage image) { - return mImpl->GetMemoryImportParams(descriptor, image); + ServiceImplementation* serviceImpl = GetServiceImplementation(descriptor->GetType()); + ASSERT(serviceImpl); + + return serviceImpl->GetMemoryImportParams(descriptor, image); } -uint32_t Service::GetQueueFamilyIndex() { - return mImpl->GetQueueFamilyIndex(); +uint32_t Service::GetQueueFamilyIndex(ExternalImageType externalImageType) { + ServiceImplementation* serviceImpl = GetServiceImplementation(externalImageType); + ASSERT(serviceImpl); + + return serviceImpl->GetQueueFamilyIndex(); } -ResultOrError Service::ImportMemory(ExternalMemoryHandle handle, +ResultOrError Service::ImportMemory(ExternalImageType externalImageType, + ExternalMemoryHandle handle, const MemoryImportParams& importParams, VkImage image) { - return mImpl->ImportMemory(handle, importParams, image); + ServiceImplementation* serviceImpl = GetServiceImplementation(externalImageType); + ASSERT(serviceImpl); + + return serviceImpl->ImportMemory(handle, importParams, image); } ResultOrError Service::CreateImage(const ExternalImageDescriptor* descriptor, const VkImageCreateInfo& baseCreateInfo) { - return mImpl->CreateImage(descriptor, baseCreateInfo); + ServiceImplementation* serviceImpl = GetServiceImplementation(descriptor->GetType()); + ASSERT(serviceImpl); + + return serviceImpl->CreateImage(descriptor, baseCreateInfo); +} + +ServiceImplementation* Service::GetServiceImplementation(ExternalImageType externalImageType) { + if (!mServiceImpls[externalImageType]) { + return nullptr; + } + + return mServiceImpls[externalImageType].get(); } } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryService.h b/src/dawn/native/vulkan/external_memory/MemoryService.h index adafd40dae..e7e05f00e8 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryService.h +++ b/src/dawn/native/vulkan/external_memory/MemoryService.h @@ -17,9 +17,11 @@ #include +#include "dawn/common/ityp_array.h" #include "dawn/native/Error.h" #include "dawn/native/vulkan/ExternalHandle.h" #include "dawn/native/vulkan/external_memory/MemoryImportParams.h" +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" namespace dawn::native::vulkan { class Device; @@ -28,8 +30,6 @@ struct VulkanDeviceInfo; namespace dawn::native::vulkan::external_memory { -class ServiceImplementation; - class Service { public: explicit Service(Device* device); @@ -38,7 +38,8 @@ class Service { static bool CheckSupport(const VulkanDeviceInfo& deviceInfo); // True if the device reports it supports importing external memory. - bool SupportsImportMemory(VkFormat format, + bool SupportsImportMemory(ExternalImageType externalImageType, + VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, @@ -56,10 +57,11 @@ class Service { VkImage image); // Returns the index of the queue memory from this services should be exported with. - uint32_t GetQueueFamilyIndex(); + uint32_t GetQueueFamilyIndex(ExternalImageType externalImageType); // Given an external handle pointing to memory, import it into a VkDeviceMemory - ResultOrError ImportMemory(ExternalMemoryHandle handle, + ResultOrError ImportMemory(ExternalImageType externalImageType, + ExternalMemoryHandle handle, const MemoryImportParams& importParams, VkImage image); @@ -68,7 +70,10 @@ class Service { const VkImageCreateInfo& baseCreateInfo); private: - std::unique_ptr mImpl; + ServiceImplementation* GetServiceImplementation(ExternalImageType externalImageType); + + // ExternalImageType has 6 types. Vulkan backend uses 3 of them. + ityp::array, 6> mServiceImpls = {}; }; } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp index 2ecd4ee61a..8087c97ba7 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.cpp @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h" #include "dawn/common/Assert.h" #include "dawn/native/vulkan/AdapterVk.h" #include "dawn/native/vulkan/BackendVk.h" @@ -21,7 +20,6 @@ #include "dawn/native/vulkan/TextureVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" -#include "dawn/native/vulkan/external_memory/MemoryService.h" #include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" namespace dawn::native::vulkan::external_memory { @@ -203,13 +201,12 @@ class ServiceImplementationAHardwareBuffer : public ServiceImplementation { bool mSupported = false; }; -Service::Service(Device* device) { - mImpl = std::make_unique(device); +bool CheckAHardwareBufferSupport(const VulkanDeviceInfo& deviceInfo) { + return ServiceImplementationAHardwareBuffer::CheckSupport(deviceInfo); } -// static -bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { - return deviceInfo.HasExt(DeviceExt::ExternalMemoryAndroidHardwareBuffer); +std::unique_ptr CreateAHardwareBufferService(Device* device) { + return std::make_unique(device); } } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h new file mode 100644 index 0000000000..0d6aaae940 --- /dev/null +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h @@ -0,0 +1,33 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONAHARDWAREBUFFER_H_ +#define SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONAHARDWAREBUFFER_H_ + +#include + +namespace dawn::native::vulkan { +class Device; +struct VulkanDeviceInfo; +} // namespace dawn::native::vulkan + +namespace dawn::native::vulkan::external_memory { +class ServiceImplementation; + +bool CheckAHardwareBufferSupport(const VulkanDeviceInfo& deviceInfo); +std::unique_ptr CreateAHardwareBufferService(Device* device); + +} // namespace dawn::native::vulkan::external_memory + +#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONAHARDWAREBUFFER_H_ diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp index f46106067c..2682c46c33 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp @@ -1,4 +1,4 @@ -// Copyright 2019 The Dawn Authors +// Copyright 2023 The Dawn Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include "dawn/common/Assert.h" @@ -22,8 +21,8 @@ #include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" -#include "dawn/native/vulkan/external_memory/MemoryService.h" #include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h" namespace dawn::native::vulkan::external_memory { @@ -358,14 +357,12 @@ class ServiceImplementationDmaBuf : public ServiceImplementation { bool mSupported = false; }; -Service::Service(Device* device) { - mImpl = std::make_unique(device); +bool CheckDmaBufSupport(const VulkanDeviceInfo& deviceInfo) { + return ServiceImplementationDmaBuf::CheckSupport(deviceInfo); } -// static -bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { - return deviceInfo.HasExt(DeviceExt::ExternalMemoryFD) && - deviceInfo.HasExt(DeviceExt::ImageDrmFormatModifier); +std::unique_ptr CreateDmaBufService(Device* device) { + return std::make_unique(device); } } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h new file mode 100644 index 0000000000..58a1f7832f --- /dev/null +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h @@ -0,0 +1,33 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONDMABUF_H_ +#define SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONDMABUF_H_ + +#include + +namespace dawn::native::vulkan { +class Device; +struct VulkanDeviceInfo; +} // namespace dawn::native::vulkan + +namespace dawn::native::vulkan::external_memory { +class ServiceImplementation; + +bool CheckDmaBufSupport(const VulkanDeviceInfo& deviceInfo); +std::unique_ptr CreateDmaBufService(Device* device); + +} // namespace dawn::native::vulkan::external_memory + +#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONDMABUF_H_ diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp index 9eb13ebf8c..e4f5340a24 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp @@ -1,4 +1,4 @@ -// Copyright 2019 The Dawn Authors +// Copyright 2023 The Dawn Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h" #include "dawn/common/Assert.h" #include "dawn/native/vulkan/AdapterVk.h" #include "dawn/native/vulkan/BackendVk.h" @@ -21,7 +20,6 @@ #include "dawn/native/vulkan/TextureVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" -#include "dawn/native/vulkan/external_memory/MemoryService.h" #include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" namespace dawn::native::vulkan::external_memory { @@ -176,13 +174,11 @@ class ServiceImplementationOpaqueFD : public ServiceImplementation { bool mSupported = false; }; -Service::Service(Device* device) { - mImpl = std::make_unique(device); +bool CheckOpaqueFDSupport(const VulkanDeviceInfo& deviceInfo) { + return ServiceImplementationOpaqueFD::CheckSupport(deviceInfo); } - -// static -bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { - return deviceInfo.HasExt(DeviceExt::ExternalMemoryFD); +std::unique_ptr CreateOpaqueFDService(Device* device) { + return std::make_unique(device); } } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h new file mode 100644 index 0000000000..25b0a9f26c --- /dev/null +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h @@ -0,0 +1,33 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONOPAQUEFD_H_ +#define SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONOPAQUEFD_H_ + +#include + +namespace dawn::native::vulkan { +class Device; +struct VulkanDeviceInfo; +} // namespace dawn::native::vulkan + +namespace dawn::native::vulkan::external_memory { +class ServiceImplementation; + +bool CheckOpaqueFDSupport(const VulkanDeviceInfo& deviceInfo); +std::unique_ptr CreateOpaqueFDService(Device* device); + +} // namespace dawn::native::vulkan::external_memory + +#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONOPAQUEFD_H_ diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp index 383b96af03..b909b68b60 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.cpp @@ -1,4 +1,4 @@ -// Copyright 2019 The Dawn Authors +// Copyright 2023 The Dawn Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h" #include "dawn/common/Assert.h" #include "dawn/native/vulkan/AdapterVk.h" #include "dawn/native/vulkan/BackendVk.h" @@ -21,7 +20,6 @@ #include "dawn/native/vulkan/TextureVk.h" #include "dawn/native/vulkan/UtilsVulkan.h" #include "dawn/native/vulkan/VulkanError.h" -#include "dawn/native/vulkan/external_memory/MemoryService.h" #include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" namespace dawn::native::vulkan::external_memory { @@ -180,13 +178,12 @@ class ServiceImplementationZicronHandle : public ServiceImplementation { bool mSupported = false; }; -Service::Service(Device* device) { - mImpl = std::make_unique(device); +bool CheckZirconHandleSupport(const VulkanDeviceInfo& deviceInfo) { + return ServiceImplementationZicronHandle::CheckSupport(deviceInfo); } -// static -bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { - return deviceInfo.HasExt(DeviceExt::ExternalMemoryZirconHandle); +std::unique_ptr CreateZirconHandleService(Device* device) { + return std::make_unique(device); } } // namespace dawn::native::vulkan::external_memory diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h new file mode 100644 index 0000000000..705f38c7f9 --- /dev/null +++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h @@ -0,0 +1,32 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONZIRCONHANDLE_H_ +#define SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONZIRCONHANDLE_H_ + +#include + +namespace dawn::native::vulkan { +class Device; +struct VulkanDeviceInfo; +} // namespace dawn::native::vulkan + +namespace dawn::native::vulkan::external_memory { +class ServiceImplementation; + +bool CheckZirconHandleSupport(const VulkanDeviceInfo& deviceInfo); +std::unique_ptr CreateZirconHandleService(Device* device); +} // namespace dawn::native::vulkan::external_memory + +#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONZIRCONHANDLE_H_ diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceNull.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceNull.cpp deleted file mode 100644 index 5f7de1e27b..0000000000 --- a/src/dawn/native/vulkan/external_memory/MemoryServiceNull.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2019 The Dawn Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "dawn/native/vulkan/DeviceVk.h" -#include "dawn/native/vulkan/external_memory/MemoryService.h" -#include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h" - -namespace dawn::native::vulkan::external_memory { - -class ServiceImplementationNull : public ServiceImplementation { - public: - explicit ServiceImplementationNull(Device* device) - : ServiceImplementation(device), mSupported(CheckSupport(device->GetDeviceInfo())) {} - ~ServiceImplementationNull() override = default; - - static bool CheckSupport(const VulkanDeviceInfo& deviceInfo) { return false; } - - bool SupportsImportMemory(VkFormat format, - VkImageType type, - VkImageTiling tiling, - VkImageUsageFlags usage, - VkImageCreateFlags flags) override { - return false; - } - - bool SupportsCreateImage(const ExternalImageDescriptor* descriptor, - VkFormat format, - VkImageUsageFlags usage, - bool* supportsDisjoint) override { - *supportsDisjoint = false; - return false; - } - - ResultOrError GetMemoryImportParams( - const ExternalImageDescriptor* descriptor, - VkImage image) override { - return DAWN_UNIMPLEMENTED_ERROR("Using null memory service to interop inside Vulkan"); - } - - uint32_t GetQueueFamilyIndex() override { return VK_QUEUE_FAMILY_EXTERNAL_KHR; } - - ResultOrError ImportMemory(ExternalMemoryHandle handle, - const MemoryImportParams& importParams, - VkImage image) override { - return DAWN_UNIMPLEMENTED_ERROR("Using null memory service to interop inside Vulkan"); - } - - ResultOrError CreateImage(const ExternalImageDescriptor* descriptor, - const VkImageCreateInfo& baseCreateInfo) override { - return DAWN_UNIMPLEMENTED_ERROR("Using null memory service to interop inside Vulkan"); - } - - bool Supported() const override { return false; } - - private: - bool mSupported = false; -}; - -Service::Service(Device* device) { - mImpl = std::make_unique(device); -} - -// static -bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { - return false; -} - -} // namespace dawn::native::vulkan::external_memory