15 std::shared_ptr<TextureSourceVK>
source)
17 context_(
std::move(context)),
22void TextureVK::SetLabel(std::string_view label) {
23 auto context = context_.lock();
32bool TextureVK::OnSetContents(
const uint8_t* contents,
35 if (!IsValid() || !contents) {
42 if (
length !=
desc.GetByteSizeOfBaseMipLevel()) {
47 auto context = context_.lock();
49 VALIDATION_LOG <<
"Context died before setting contents on texture.";
54 context->GetResourceAllocator()->CreateBufferWithCopy(contents,
length);
56 if (!staging_buffer) {
61 auto cmd_buffer = context->CreateCommandBuffer();
73 const auto& vk_cmd_buffer =
encoder->GetCommandBuffer();
76 barrier.cmd_buffer = vk_cmd_buffer;
77 barrier.new_layout = vk::ImageLayout::eTransferDstOptimal;
78 barrier.src_access = {};
79 barrier.src_stage = vk::PipelineStageFlagBits::eTopOfPipe;
80 barrier.dst_access = vk::AccessFlagBits::eTransferWrite;
81 barrier.dst_stage = vk::PipelineStageFlagBits::eTransfer;
87 vk::BufferImageCopy
copy;
88 copy.bufferOffset = 0u;
89 copy.bufferRowLength = 0u;
90 copy.bufferImageHeight = 0u;
91 copy.imageOffset.x = 0u;
92 copy.imageOffset.y = 0u;
93 copy.imageOffset.z = 0u;
94 copy.imageExtent.width =
desc.size.width;
95 copy.imageExtent.height =
desc.size.height;
96 copy.imageExtent.depth = 1u;
97 copy.imageSubresource.aspectMask =
99 copy.imageSubresource.mipLevel = 0u;
100 copy.imageSubresource.baseArrayLayer = slice;
101 copy.imageSubresource.layerCount = 1u;
103 vk_cmd_buffer.copyBufferToImage(
114 barrier.cmd_buffer = vk_cmd_buffer;
115 barrier.src_access = vk::AccessFlagBits::eColorAttachmentWrite |
116 vk::AccessFlagBits::eTransferWrite;
117 barrier.src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput |
118 vk::PipelineStageFlagBits::eTransfer;
119 barrier.dst_access = vk::AccessFlagBits::eShaderRead;
120 barrier.dst_stage = vk::PipelineStageFlagBits::eFragmentShader;
122 barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal;
129 return context->GetCommandQueue()->Submit({cmd_buffer}).
ok();
132bool TextureVK::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
136 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
139bool TextureVK::IsValid()
const {
148 return source_->GetImage();
152 return source_->GetImageView();
160 return source_ ? source_->SetLayout(barrier).ok() :
false;
164 vk::ImageLayout layout)
const {
165 return source_ ? source_->SetLayoutWithoutEncoding(layout)
166 : vk::ImageLayout::eUndefined;
170 return source_ ? source_->GetLayout() : vk::ImageLayout::eUndefined;
174 return source_->GetRenderTargetView();
179 source_->SetCachedFramebuffer(framebuffer);
184 source_->SetCachedRenderPass(render_pass);
188 return source_->GetCachedFramebuffer();
192 return source_->GetCachedRenderPass();
200 return source_->IsSwapchainImage();
208 auto conversion = source_->GetYUVConversion();
static bool ok(int result)
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
static ContextVK & Cast(Context &base)
const std::shared_ptr< CommandEncoderVK > & GetEncoder()
bool SetDebugName(T handle, std::string_view label) const
vk::Buffer GetBuffer() const
std::shared_ptr< SamplerVK > CreateVariantForConversion(std::shared_ptr< YUVConversionVK > conversion) const
vk::ImageView GetImageView() const
std::shared_ptr< const TextureSourceVK > GetTextureSource() const
bool IsSwapchainImage() const
vk::ImageView GetRenderTargetView() const
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
void SetMipMapGenerated()
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
std::shared_ptr< SamplerVK > GetImmutableSamplerVariant(const SamplerVK &sampler) const
ISize GetSize() const override
TextureVK(std::weak_ptr< Context > context, std::shared_ptr< TextureSourceVK > source)
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
bool SetLayout(const BarrierVK &barrier) const
vk::ImageLayout GetLayout() const
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
vk::Image GetImage() const
const TextureDescriptor & GetTextureDescriptor() const
uint32_t uint32_t * format
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Defines an operations and memory access barrier on a resource.