MemoryService Choose Implementation based on ExternalImageType
This CL add supports for MemoryService choosing implementation based on ExternalImageType in runtime instead of choosing in compile time. This CL also removes MemoryServiceNull.cpp. Bug: dawn:1593 Change-Id: Iddec1f5cf03a7d962ef12b8fd6293ffbb7dc064d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125900 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Shaobo Yan <shaobo.yan@intel.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
dbfa3aba12
commit
07b88f3aef
|
@ -712,31 +712,28 @@ source_set("sources") {
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp",
|
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp",
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.h",
|
"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) {
|
} else if (is_fuchsia) {
|
||||||
sources += [
|
sources += [
|
||||||
|
"vulkan/external_memory/MemoryServiceImplementationZicronHandle.cpp",
|
||||||
|
"vulkan/external_memory/MemoryServiceImplementationZicronHandle.h",
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.cpp",
|
"vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.cpp",
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationZirconHandle.h",
|
"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) {
|
if (build_with_chromium && is_fuchsia) {
|
||||||
# Necessary to ensure that the Vulkan libraries will be in the
|
# Necessary to ensure that the Vulkan libraries will be in the
|
||||||
# final Fuchsia package.
|
# final Fuchsia package.
|
||||||
|
|
|
@ -585,14 +585,13 @@ if (DAWN_ENABLE_VULKAN)
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
target_sources(dawn_native PRIVATE
|
target_sources(dawn_native PRIVATE
|
||||||
|
"vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp"
|
||||||
|
"vulkan/external_memory/MemoryServiceImplementationDmaBuf.h"
|
||||||
"vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp"
|
"vulkan/external_memory/MemoryServiceImplementationOpaqueFD.cpp"
|
||||||
|
"vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h"
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp"
|
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.cpp"
|
||||||
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.h"
|
"vulkan/external_semaphore/SemaphoreServiceImplementationFD.h"
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
target_sources(dawn_native PRIVATE
|
|
||||||
"vulkan/external_memory/MemoryServiceNull.cpp"
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -853,8 +853,8 @@ MaybeError Device::ImportExternalImage(const ExternalImageDescriptorVk* descript
|
||||||
"External semaphore usage not supported");
|
"External semaphore usage not supported");
|
||||||
|
|
||||||
DAWN_INVALID_IF(!mExternalMemoryService->SupportsImportMemory(
|
DAWN_INVALID_IF(!mExternalMemoryService->SupportsImportMemory(
|
||||||
VulkanImageFormat(this, textureDescriptor->format), VK_IMAGE_TYPE_2D,
|
descriptor->GetType(), VulkanImageFormat(this, textureDescriptor->format),
|
||||||
VK_IMAGE_TILING_OPTIMAL,
|
VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
|
||||||
VulkanImageUsage(usage, GetValidInternalFormat(textureDescriptor->format)),
|
VulkanImageUsage(usage, GetValidInternalFormat(textureDescriptor->format)),
|
||||||
VK_IMAGE_CREATE_ALIAS_BIT_KHR),
|
VK_IMAGE_CREATE_ALIAS_BIT_KHR),
|
||||||
"External memory usage not supported");
|
"External memory usage not supported");
|
||||||
|
@ -862,8 +862,8 @@ MaybeError Device::ImportExternalImage(const ExternalImageDescriptorVk* descript
|
||||||
// Import the external image's memory
|
// Import the external image's memory
|
||||||
external_memory::MemoryImportParams importParams;
|
external_memory::MemoryImportParams importParams;
|
||||||
DAWN_TRY_ASSIGN(importParams, mExternalMemoryService->GetMemoryImportParams(descriptor, image));
|
DAWN_TRY_ASSIGN(importParams, mExternalMemoryService->GetMemoryImportParams(descriptor, image));
|
||||||
DAWN_TRY_ASSIGN(*outAllocation,
|
DAWN_TRY_ASSIGN(*outAllocation, mExternalMemoryService->ImportMemory(
|
||||||
mExternalMemoryService->ImportMemory(memoryHandle, importParams, image));
|
descriptor->GetType(), memoryHandle, importParams, image));
|
||||||
|
|
||||||
// Import semaphores we have to wait on before using the texture
|
// Import semaphores we have to wait on before using the texture
|
||||||
for (const ExternalSemaphoreHandle& handle : waitHandles) {
|
for (const ExternalSemaphoreHandle& handle : waitHandles) {
|
||||||
|
|
|
@ -794,7 +794,7 @@ MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptorVk* desc
|
||||||
ASSERT(!GetFormat().IsMultiPlanar() || mCombinedAspect == Aspect::Color);
|
ASSERT(!GetFormat().IsMultiPlanar() || mCombinedAspect == Aspect::Color);
|
||||||
|
|
||||||
mExternalState = ExternalState::PendingAcquire;
|
mExternalState = ExternalState::PendingAcquire;
|
||||||
mExportQueueFamilyIndex = externalMemoryService->GetQueueFamilyIndex();
|
mExportQueueFamilyIndex = externalMemoryService->GetQueueFamilyIndex(descriptor->GetType());
|
||||||
|
|
||||||
mPendingAcquireOldLayout = descriptor->releasedOldLayout;
|
mPendingAcquireOldLayout = descriptor->releasedOldLayout;
|
||||||
mPendingAcquireNewLayout = descriptor->releasedNewLayout;
|
mPendingAcquireNewLayout = descriptor->releasedNewLayout;
|
||||||
|
|
|
@ -12,47 +12,126 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "dawn/native/vulkan/DeviceVk.h"
|
||||||
#include "dawn/native/vulkan/external_memory/MemoryService.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 {
|
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;
|
Service::~Service() = default;
|
||||||
|
|
||||||
bool Service::SupportsImportMemory(VkFormat format,
|
bool Service::SupportsImportMemory(ExternalImageType externalImageType,
|
||||||
|
VkFormat format,
|
||||||
VkImageType type,
|
VkImageType type,
|
||||||
VkImageTiling tiling,
|
VkImageTiling tiling,
|
||||||
VkImageUsageFlags usage,
|
VkImageUsageFlags usage,
|
||||||
VkImageCreateFlags flags) {
|
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,
|
bool Service::SupportsCreateImage(const ExternalImageDescriptor* descriptor,
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
VkImageUsageFlags usage,
|
VkImageUsageFlags usage,
|
||||||
bool* supportsDisjoint) {
|
bool* supportsDisjoint) {
|
||||||
return mImpl->SupportsCreateImage(descriptor, format, usage, supportsDisjoint);
|
ServiceImplementation* serviceImpl = GetServiceImplementation(descriptor->GetType());
|
||||||
|
ASSERT(serviceImpl);
|
||||||
|
|
||||||
|
return serviceImpl->SupportsCreateImage(descriptor, format, usage, supportsDisjoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<MemoryImportParams> Service::GetMemoryImportParams(
|
ResultOrError<MemoryImportParams> Service::GetMemoryImportParams(
|
||||||
const ExternalImageDescriptor* descriptor,
|
const ExternalImageDescriptor* descriptor,
|
||||||
VkImage image) {
|
VkImage image) {
|
||||||
return mImpl->GetMemoryImportParams(descriptor, image);
|
ServiceImplementation* serviceImpl = GetServiceImplementation(descriptor->GetType());
|
||||||
|
ASSERT(serviceImpl);
|
||||||
|
|
||||||
|
return serviceImpl->GetMemoryImportParams(descriptor, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Service::GetQueueFamilyIndex() {
|
uint32_t Service::GetQueueFamilyIndex(ExternalImageType externalImageType) {
|
||||||
return mImpl->GetQueueFamilyIndex();
|
ServiceImplementation* serviceImpl = GetServiceImplementation(externalImageType);
|
||||||
|
ASSERT(serviceImpl);
|
||||||
|
|
||||||
|
return serviceImpl->GetQueueFamilyIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<VkDeviceMemory> Service::ImportMemory(ExternalMemoryHandle handle,
|
ResultOrError<VkDeviceMemory> Service::ImportMemory(ExternalImageType externalImageType,
|
||||||
|
ExternalMemoryHandle handle,
|
||||||
const MemoryImportParams& importParams,
|
const MemoryImportParams& importParams,
|
||||||
VkImage image) {
|
VkImage image) {
|
||||||
return mImpl->ImportMemory(handle, importParams, image);
|
ServiceImplementation* serviceImpl = GetServiceImplementation(externalImageType);
|
||||||
|
ASSERT(serviceImpl);
|
||||||
|
|
||||||
|
return serviceImpl->ImportMemory(handle, importParams, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<VkImage> Service::CreateImage(const ExternalImageDescriptor* descriptor,
|
ResultOrError<VkImage> Service::CreateImage(const ExternalImageDescriptor* descriptor,
|
||||||
const VkImageCreateInfo& baseCreateInfo) {
|
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
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "dawn/common/ityp_array.h"
|
||||||
#include "dawn/native/Error.h"
|
#include "dawn/native/Error.h"
|
||||||
#include "dawn/native/vulkan/ExternalHandle.h"
|
#include "dawn/native/vulkan/ExternalHandle.h"
|
||||||
#include "dawn/native/vulkan/external_memory/MemoryImportParams.h"
|
#include "dawn/native/vulkan/external_memory/MemoryImportParams.h"
|
||||||
|
#include "dawn/native/vulkan/external_memory/MemoryServiceImplementation.h"
|
||||||
|
|
||||||
namespace dawn::native::vulkan {
|
namespace dawn::native::vulkan {
|
||||||
class Device;
|
class Device;
|
||||||
|
@ -28,8 +30,6 @@ struct VulkanDeviceInfo;
|
||||||
|
|
||||||
namespace dawn::native::vulkan::external_memory {
|
namespace dawn::native::vulkan::external_memory {
|
||||||
|
|
||||||
class ServiceImplementation;
|
|
||||||
|
|
||||||
class Service {
|
class Service {
|
||||||
public:
|
public:
|
||||||
explicit Service(Device* device);
|
explicit Service(Device* device);
|
||||||
|
@ -38,7 +38,8 @@ class Service {
|
||||||
static bool CheckSupport(const VulkanDeviceInfo& deviceInfo);
|
static bool CheckSupport(const VulkanDeviceInfo& deviceInfo);
|
||||||
|
|
||||||
// True if the device reports it supports importing external memory.
|
// True if the device reports it supports importing external memory.
|
||||||
bool SupportsImportMemory(VkFormat format,
|
bool SupportsImportMemory(ExternalImageType externalImageType,
|
||||||
|
VkFormat format,
|
||||||
VkImageType type,
|
VkImageType type,
|
||||||
VkImageTiling tiling,
|
VkImageTiling tiling,
|
||||||
VkImageUsageFlags usage,
|
VkImageUsageFlags usage,
|
||||||
|
@ -56,10 +57,11 @@ class Service {
|
||||||
VkImage image);
|
VkImage image);
|
||||||
|
|
||||||
// Returns the index of the queue memory from this services should be exported with.
|
// 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
|
// Given an external handle pointing to memory, import it into a VkDeviceMemory
|
||||||
ResultOrError<VkDeviceMemory> ImportMemory(ExternalMemoryHandle handle,
|
ResultOrError<VkDeviceMemory> ImportMemory(ExternalImageType externalImageType,
|
||||||
|
ExternalMemoryHandle handle,
|
||||||
const MemoryImportParams& importParams,
|
const MemoryImportParams& importParams,
|
||||||
VkImage image);
|
VkImage image);
|
||||||
|
|
||||||
|
@ -68,7 +70,10 @@ class Service {
|
||||||
const VkImageCreateInfo& baseCreateInfo);
|
const VkImageCreateInfo& baseCreateInfo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<ServiceImplementation> mImpl;
|
ServiceImplementation* GetServiceImplementation(ExternalImageType externalImageType);
|
||||||
|
|
||||||
|
// ExternalImageType has 6 types. Vulkan backend uses 3 of them.
|
||||||
|
ityp::array<ExternalImageType, std::unique_ptr<ServiceImplementation>, 6> mServiceImpls = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <memory>
|
#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h"
|
||||||
|
|
||||||
#include "dawn/common/Assert.h"
|
#include "dawn/common/Assert.h"
|
||||||
#include "dawn/native/vulkan/AdapterVk.h"
|
#include "dawn/native/vulkan/AdapterVk.h"
|
||||||
#include "dawn/native/vulkan/BackendVk.h"
|
#include "dawn/native/vulkan/BackendVk.h"
|
||||||
|
@ -21,7 +20,6 @@
|
||||||
#include "dawn/native/vulkan/TextureVk.h"
|
#include "dawn/native/vulkan/TextureVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.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/MemoryServiceImplementation.h"
|
||||||
|
|
||||||
namespace dawn::native::vulkan::external_memory {
|
namespace dawn::native::vulkan::external_memory {
|
||||||
|
@ -203,13 +201,12 @@ class ServiceImplementationAHardwareBuffer : public ServiceImplementation {
|
||||||
bool mSupported = false;
|
bool mSupported = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Service::Service(Device* device) {
|
bool CheckAHardwareBufferSupport(const VulkanDeviceInfo& deviceInfo) {
|
||||||
mImpl = std::make_unique<ServiceImplementationAHardwareBuffer>(device);
|
return ServiceImplementationAHardwareBuffer::CheckSupport(deviceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
std::unique_ptr<ServiceImplementation> CreateAHardwareBufferService(Device* device) {
|
||||||
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) {
|
return std::make_unique<ServiceImplementationAHardwareBuffer>(device);
|
||||||
return deviceInfo.HasExt(DeviceExt::ExternalMemoryAndroidHardwareBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -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 <memory>
|
||||||
|
|
||||||
|
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<ServiceImplementation> CreateAHardwareBufferService(Device* device);
|
||||||
|
|
||||||
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
||||||
|
#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONAHARDWAREBUFFER_H_
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2019 The Dawn Authors
|
// Copyright 2023 The Dawn Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with 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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "dawn/common/Assert.h"
|
#include "dawn/common/Assert.h"
|
||||||
|
@ -22,8 +21,8 @@
|
||||||
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.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/MemoryServiceImplementation.h"
|
||||||
|
#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h"
|
||||||
|
|
||||||
namespace dawn::native::vulkan::external_memory {
|
namespace dawn::native::vulkan::external_memory {
|
||||||
|
|
||||||
|
@ -358,14 +357,12 @@ class ServiceImplementationDmaBuf : public ServiceImplementation {
|
||||||
bool mSupported = false;
|
bool mSupported = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Service::Service(Device* device) {
|
bool CheckDmaBufSupport(const VulkanDeviceInfo& deviceInfo) {
|
||||||
mImpl = std::make_unique<ServiceImplementationDmaBuf>(device);
|
return ServiceImplementationDmaBuf::CheckSupport(deviceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
std::unique_ptr<ServiceImplementation> CreateDmaBufService(Device* device) {
|
||||||
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) {
|
return std::make_unique<ServiceImplementationDmaBuf>(device);
|
||||||
return deviceInfo.HasExt(DeviceExt::ExternalMemoryFD) &&
|
|
||||||
deviceInfo.HasExt(DeviceExt::ImageDrmFormatModifier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -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 <memory>
|
||||||
|
|
||||||
|
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<ServiceImplementation> CreateDmaBufService(Device* device);
|
||||||
|
|
||||||
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
||||||
|
#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONDMABUF_H_
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2019 The Dawn Authors
|
// Copyright 2023 The Dawn Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with 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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <memory>
|
#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h"
|
||||||
|
|
||||||
#include "dawn/common/Assert.h"
|
#include "dawn/common/Assert.h"
|
||||||
#include "dawn/native/vulkan/AdapterVk.h"
|
#include "dawn/native/vulkan/AdapterVk.h"
|
||||||
#include "dawn/native/vulkan/BackendVk.h"
|
#include "dawn/native/vulkan/BackendVk.h"
|
||||||
|
@ -21,7 +20,6 @@
|
||||||
#include "dawn/native/vulkan/TextureVk.h"
|
#include "dawn/native/vulkan/TextureVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.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/MemoryServiceImplementation.h"
|
||||||
|
|
||||||
namespace dawn::native::vulkan::external_memory {
|
namespace dawn::native::vulkan::external_memory {
|
||||||
|
@ -176,13 +174,11 @@ class ServiceImplementationOpaqueFD : public ServiceImplementation {
|
||||||
bool mSupported = false;
|
bool mSupported = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Service::Service(Device* device) {
|
bool CheckOpaqueFDSupport(const VulkanDeviceInfo& deviceInfo) {
|
||||||
mImpl = std::make_unique<ServiceImplementationOpaqueFD>(device);
|
return ServiceImplementationOpaqueFD::CheckSupport(deviceInfo);
|
||||||
}
|
}
|
||||||
|
std::unique_ptr<ServiceImplementation> CreateOpaqueFDService(Device* device) {
|
||||||
// static
|
return std::make_unique<ServiceImplementationOpaqueFD>(device);
|
||||||
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) {
|
|
||||||
return deviceInfo.HasExt(DeviceExt::ExternalMemoryFD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -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 <memory>
|
||||||
|
|
||||||
|
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<ServiceImplementation> CreateOpaqueFDService(Device* device);
|
||||||
|
|
||||||
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
||||||
|
#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONOPAQUEFD_H_
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2019 The Dawn Authors
|
// Copyright 2023 The Dawn Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with 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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <memory>
|
#include "dawn/native/vulkan/external_memory/MemoryServiceImplementationZirconHandle.h"
|
||||||
|
|
||||||
#include "dawn/common/Assert.h"
|
#include "dawn/common/Assert.h"
|
||||||
#include "dawn/native/vulkan/AdapterVk.h"
|
#include "dawn/native/vulkan/AdapterVk.h"
|
||||||
#include "dawn/native/vulkan/BackendVk.h"
|
#include "dawn/native/vulkan/BackendVk.h"
|
||||||
|
@ -21,7 +20,6 @@
|
||||||
#include "dawn/native/vulkan/TextureVk.h"
|
#include "dawn/native/vulkan/TextureVk.h"
|
||||||
#include "dawn/native/vulkan/UtilsVulkan.h"
|
#include "dawn/native/vulkan/UtilsVulkan.h"
|
||||||
#include "dawn/native/vulkan/VulkanError.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/MemoryServiceImplementation.h"
|
||||||
|
|
||||||
namespace dawn::native::vulkan::external_memory {
|
namespace dawn::native::vulkan::external_memory {
|
||||||
|
@ -180,13 +178,12 @@ class ServiceImplementationZicronHandle : public ServiceImplementation {
|
||||||
bool mSupported = false;
|
bool mSupported = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Service::Service(Device* device) {
|
bool CheckZirconHandleSupport(const VulkanDeviceInfo& deviceInfo) {
|
||||||
mImpl = std::make_unique<ServiceImplementationZicronHandle>(device);
|
return ServiceImplementationZicronHandle::CheckSupport(deviceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
std::unique_ptr<ServiceImplementation> CreateZirconHandleService(Device* device) {
|
||||||
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) {
|
return std::make_unique<ServiceImplementationZicronHandle>(device);
|
||||||
return deviceInfo.HasExt(DeviceExt::ExternalMemoryZirconHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
|
@ -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 <memory>
|
||||||
|
|
||||||
|
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<ServiceImplementation> CreateZirconHandleService(Device* device);
|
||||||
|
} // namespace dawn::native::vulkan::external_memory
|
||||||
|
|
||||||
|
#endif // SRC_DAWN_NATIVE_VULKAN_EXTERNAL_MEMORY_SERVICEIMPLEMENTATIONZIRCONHANDLE_H_
|
|
@ -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 <memory>
|
|
||||||
|
|
||||||
#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<MemoryImportParams> 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<VkDeviceMemory> ImportMemory(ExternalMemoryHandle handle,
|
|
||||||
const MemoryImportParams& importParams,
|
|
||||||
VkImage image) override {
|
|
||||||
return DAWN_UNIMPLEMENTED_ERROR("Using null memory service to interop inside Vulkan");
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultOrError<VkImage> 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<ServiceImplementationNull>(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace dawn::native::vulkan::external_memory
|
|
Loading…
Reference in New Issue