#include "dawn/native/vulkan/SharedTextureMemoryVk.h"
#include <algorithm>
#include <utility>
#include <vector>
#include "dawn/native/ChainUtils.h"
#include "dawn/native/Instance.h"
#include "dawn/native/SystemHandle.h"
#include "dawn/native/vulkan/DeviceVk.h"
#include "dawn/native/vulkan/FencedDeleter.h"
#include "dawn/native/vulkan/PhysicalDeviceVk.h"
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
#include "dawn/native/vulkan/SharedFenceVk.h"
#include "dawn/native/vulkan/TextureVk.h"
#include "dawn/native/vulkan/UtilsVulkan.h"
#include "dawn/native/vulkan/VulkanError.h"
#if DAWN_PLATFORM_IS(ANDROID)
#include <android/hardware_buffer.h>
#include "dawn/native/AHBFunctions.h"
#endif
namespace dawn::native::vulkan {
namespace {
#if DAWN_PLATFORM_IS(LINUX)
constexpr uint32_t DrmFourccCode(uint32_t a, uint32_t b, uint32_t c, uint32_t d) { … }
constexpr uint32_t DrmFourccCode(char a, char b, char c, char d) { … }
constexpr auto kDrmFormatR8 = …;
constexpr auto kDrmFormatGR88 = …;
constexpr auto kDrmFormatXRGB8888 = …;
constexpr auto kDrmFormatXBGR8888 = …;
constexpr auto kDrmFormatARGB8888 = …;
constexpr auto kDrmFormatABGR8888 = …;
constexpr auto kDrmFormatABGR2101010 = …;
constexpr auto kDrmFormatABGR16161616F = …;
constexpr auto kDrmFormatNV12 = …;
ResultOrError<wgpu::TextureFormat> FormatFromDrmFormat(uint32_t drmFormat) { … }
#endif
template <typename... AdditionalChains>
ResultOrError<VkImage> CreateExternalVkImage(
Device* device,
const SharedTextureMemoryProperties& properties,
const VkPhysicalDeviceImageFormatInfo2& imageFormatInfo,
VkExternalMemoryHandleTypeFlagBits externalMemoryHandleTypeFlagBits,
AdditionalChains*... additionalChains) { … }
template <typename... AdditionalChains>
MaybeError CheckExternalImageFormatSupport(
Device* device,
const SharedTextureMemoryProperties& properties,
VkPhysicalDeviceImageFormatInfo2* imageFormatInfo,
VkExternalMemoryHandleTypeFlagBits externalMemoryHandleTypeFlagBits,
AdditionalChains*... additionalChains) { … }
template <typename... AdditionalChains>
ResultOrError<VkDeviceMemory> AllocateDeviceMemory(Device* device,
VkMemoryAllocateInfo* memoryAllocateInfo,
AdditionalChains*... additionalChains) { … }
}
ResultOrError<Ref<SharedTextureMemory>> SharedTextureMemory::Create(
Device* device,
const char* label,
const SharedTextureMemoryDmaBufDescriptor* descriptor) { … }
ResultOrError<Ref<SharedTextureMemory>> SharedTextureMemory::Create(
Device* device,
const char* label,
const SharedTextureMemoryAHardwareBufferDescriptor* descriptor) { … }
ResultOrError<Ref<SharedTextureMemory>> SharedTextureMemory::Create(
Device* device,
const char* label,
const SharedTextureMemoryOpaqueFDDescriptor* descriptor) { … }
Ref<SharedTextureMemory> SharedTextureMemory::Create(
Device* device,
const char* label,
const SharedTextureMemoryProperties& properties,
uint32_t queueFamilyIndex) { … }
SharedTextureMemory::SharedTextureMemory(Device* device,
const char* label,
const SharedTextureMemoryProperties& properties,
uint32_t queueFamilyIndex)
: … { … }
RefCountedVkHandle<VkDeviceMemory>* SharedTextureMemory::GetVkDeviceMemory() const { … }
RefCountedVkHandle<VkImage>* SharedTextureMemory::GetVkImage() const { … }
uint32_t SharedTextureMemory::GetQueueFamilyIndex() const { … }
void SharedTextureMemory::DestroyImpl() { … }
ResultOrError<Ref<TextureBase>> SharedTextureMemory::CreateTextureImpl(
const UnpackedPtr<TextureDescriptor>& descriptor) { … }
MaybeError SharedTextureMemory::BeginAccessImpl(
TextureBase* texture,
const UnpackedPtr<BeginAccessDescriptor>& descriptor) { … }
#if DAWN_PLATFORM_IS(FUCHSIA) || DAWN_PLATFORM_IS(LINUX)
ResultOrError<FenceAndSignalValue> SharedTextureMemory::EndAccessImpl(
TextureBase* texture,
ExecutionSerial lastUsageSerial,
UnpackedPtr<EndAccessState>& state) { … }
#else
ResultOrError<FenceAndSignalValue> SharedTextureMemory::EndAccessImpl(
TextureBase* texture,
ExecutionSerial lastUsageSerial,
UnpackedPtr<EndAccessState>& state) {
return DAWN_VALIDATION_ERROR("No shared fence features supported.");
}
#endif
MaybeError SharedTextureMemory::GetChainedProperties(
UnpackedPtr<SharedTextureMemoryProperties>& properties) const { … }
}