#include "dawn/native/vulkan/TextureVk.h"
#include <utility>
#include "dawn/common/Assert.h"
#include "dawn/common/Math.h"
#include "dawn/native/ChainUtils.h"
#include "dawn/native/DynamicUploader.h"
#include "dawn/native/EnumMaskIterator.h"
#include "dawn/native/Error.h"
#include "dawn/native/VulkanBackend.h"
#include "dawn/native/vulkan/BufferVk.h"
#include "dawn/native/vulkan/CommandBufferVk.h"
#include "dawn/native/vulkan/CommandRecordingContext.h"
#include "dawn/native/vulkan/DeviceVk.h"
#include "dawn/native/vulkan/FencedDeleter.h"
#include "dawn/native/vulkan/PhysicalDeviceVk.h"
#include "dawn/native/vulkan/QueueVk.h"
#include "dawn/native/vulkan/ResourceHeapVk.h"
#include "dawn/native/vulkan/ResourceMemoryAllocatorVk.h"
#include "dawn/native/vulkan/UtilsVulkan.h"
#include "dawn/native/vulkan/VulkanError.h"
namespace dawn::native::vulkan {
namespace {
VkImageViewType VulkanImageViewType(wgpu::TextureViewDimension dimension) { … }
constexpr wgpu::TextureUsage kDepthReadOnlyStencilWritableAttachment = …;
constexpr wgpu::TextureUsage kDepthWritableStencilReadOnlyAttachment = …;
wgpu::TextureUsage MergeDepthStencilUsage(wgpu::TextureUsage depth, wgpu::TextureUsage stencil) { … }
VkAccessFlags VulkanAccessFlags(wgpu::TextureUsage usage, const Format& format) { … }
VkPipelineStageFlags VulkanPipelineStage(wgpu::TextureUsage usage,
wgpu::ShaderStage shaderStage,
const Format& format) { … }
VkImageMemoryBarrier BuildMemoryBarrier(const Texture* texture,
wgpu::TextureUsage lastUsage,
wgpu::TextureUsage usage,
const SubresourceRange& range) { … }
void FillVulkanCreateInfoSizesAndType(const Texture& texture, VkImageCreateInfo* info) { … }
Aspect ComputeCombinedAspect(Device* device, const Format& format) { … }
}
#define SIMPLE_FORMAT_MAPPING …
VkFormat VulkanImageFormat(const Device* device, wgpu::TextureFormat format) { … }
VkFormat ColorVulkanImageFormat(wgpu::TextureFormat format) { … }
ResultOrError<wgpu::TextureFormat> FormatFromVkFormat(const Device* device, VkFormat vkFormat) { … }
#undef SIMPLE_FORMAT_MAPPING
VkImageUsageFlags VulkanImageUsage(const DeviceBase* device,
wgpu::TextureUsage usage,
const Format& format) { … }
VkImageLayout VulkanImageLayout(const Format& format, wgpu::TextureUsage usage) { … }
VkImageLayout VulkanImageLayoutForDepthStencilAttachment(const Format& format,
bool depthReadOnly,
bool stencilReadOnly) { … }
VkSampleCountFlagBits VulkanSampleCount(uint32_t sampleCount) { … }
MaybeError ValidateVulkanImageCanBeWrapped(const DeviceBase*,
const UnpackedPtr<TextureDescriptor>& descriptor) { … }
bool IsSampleCountSupported(const dawn::native::vulkan::Device* device,
const VkImageCreateInfo& imageCreateInfo) { … }
ResultOrError<Ref<Texture>> Texture::Create(Device* device,
const UnpackedPtr<TextureDescriptor>& descriptor,
VkImageUsageFlags extraUsages) { … }
ResultOrError<Ref<Texture>> Texture::CreateFromExternal(
Device* device,
const ExternalImageDescriptorVk* descriptor,
const UnpackedPtr<TextureDescriptor>& textureDescriptor,
external_memory::Service* externalMemoryService) { … }
ResultOrError<Ref<Texture>> Texture::CreateFromSharedTextureMemory(
SharedTextureMemory* memory,
const UnpackedPtr<TextureDescriptor>& textureDescriptor) { … }
Ref<Texture> Texture::CreateForSwapChain(Device* device,
const UnpackedPtr<TextureDescriptor>& descriptor,
VkImage nativeImage) { … }
Texture::Texture(Device* device, const UnpackedPtr<TextureDescriptor>& descriptor)
: … { … }
MaybeError Texture::InitializeAsInternalTexture(VkImageUsageFlags extraUsages) { … }
MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptorVk* descriptor,
external_memory::Service* externalMemoryService) { … }
void Texture::InitializeForSwapChain(VkImage nativeImage) { … }
MaybeError Texture::BindExternalMemory(const ExternalImageDescriptorVk* descriptor,
VkDeviceMemory externalMemoryAllocation,
std::vector<VkSemaphore> waitSemaphores) { … }
void Texture::TransitionEagerlyForExport(CommandRecordingContext* recordingContext) { … }
std::vector<VkSemaphore> Texture::AcquireWaitRequirements() { … }
void Texture::SetPendingAcquire(VkImageLayout pendingAcquireOldLayout,
VkImageLayout pendingAcquireNewLayout) { … }
MaybeError Texture::EndAccess(ExternalSemaphoreHandle* handle,
VkImageLayout* releasedOldLayout,
VkImageLayout* releasedNewLayout) { … }
MaybeError Texture::ExportExternalTexture(VkImageLayout desiredLayout,
ExternalSemaphoreHandle* handle,
VkImageLayout* releasedOldLayout,
VkImageLayout* releasedNewLayout) { … }
Texture::~Texture() { … }
void Texture::SetLabelHelper(const char* prefix) { … }
void Texture::SetLabelImpl() { … }
void Texture::DestroyImpl() { … }
VkImage Texture::GetHandle() const { … }
void Texture::TweakTransitionForExternalUsage(CommandRecordingContext* recordingContext,
std::vector<VkImageMemoryBarrier>* barriers,
size_t transitionBarrierStart) { … }
bool Texture::CanReuseWithoutBarrier(wgpu::TextureUsage lastUsage,
wgpu::TextureUsage usage,
wgpu::ShaderStage lastShaderStage,
wgpu::ShaderStage shaderStage) { … }
void Texture::TransitionUsageForPass(CommandRecordingContext* recordingContext,
const TextureSubresourceSyncInfo& textureSyncInfos,
std::vector<VkImageMemoryBarrier>* imageBarriers,
VkPipelineStageFlags* srcStages,
VkPipelineStageFlags* dstStages) { … }
void Texture::TransitionUsageForPassImpl(
CommandRecordingContext* recordingContext,
const SubresourceStorage<TextureSyncInfo>& subresourceSyncInfos,
std::vector<VkImageMemoryBarrier>* imageBarriers,
VkPipelineStageFlags* srcStages,
VkPipelineStageFlags* dstStages) { … }
void Texture::TransitionUsageNow(CommandRecordingContext* recordingContext,
wgpu::TextureUsage usage,
wgpu::ShaderStage shaderStages,
const SubresourceRange& range) { … }
void Texture::UpdateUsage(wgpu::TextureUsage usage,
wgpu::ShaderStage shaderStages,
const SubresourceRange& range) { … }
void Texture::TransitionUsageAndGetResourceBarrier(wgpu::TextureUsage usage,
wgpu::ShaderStage shaderStages,
const SubresourceRange& range,
std::vector<VkImageMemoryBarrier>* imageBarriers,
VkPipelineStageFlags* srcStages,
VkPipelineStageFlags* dstStages) { … }
void Texture::TransitionUsageAndGetResourceBarrierImpl(
wgpu::TextureUsage usage,
wgpu::ShaderStage shaderStages,
const SubresourceRange& range,
std::vector<VkImageMemoryBarrier>* imageBarriers,
VkPipelineStageFlags* srcStages,
VkPipelineStageFlags* dstStages) { … }
MaybeError Texture::ClearTexture(CommandRecordingContext* recordingContext,
const SubresourceRange& range,
TextureBase::ClearValue clearValue) { … }
MaybeError Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* recordingContext,
const SubresourceRange& range) { … }
void Texture::UpdateExternalSemaphoreHandle(ExternalSemaphoreHandle handle) { … }
VkImageLayout Texture::GetCurrentLayoutForSwapChain() const { … }
bool Texture::UseCombinedAspects() const { … }
Aspect Texture::GetDisjointVulkanAspects() const { … }
ResultOrError<Ref<TextureView>> TextureView::Create(
TextureBase* texture,
const UnpackedPtr<TextureViewDescriptor>& descriptor) { … }
MaybeError TextureView::Initialize(const UnpackedPtr<TextureViewDescriptor>& descriptor) { … }
TextureView::~TextureView() { … }
void TextureView::DestroyImpl() { … }
VkImageView TextureView::GetHandle() const { … }
VkImageView TextureView::GetHandleForBGRA8UnormStorage() const { … }
VkImageViewCreateInfo TextureView::GetCreateInfo(wgpu::TextureFormat format,
wgpu::TextureViewDimension dimension,
uint32_t depthSlice) const { … }
ResultOrError<VkImageView> TextureView::GetOrCreate2DViewOn3D(uint32_t depthSlice) { … }
void TextureView::SetLabelImpl() { … }
}