| Flutter Impeller |

texture_source_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/texture_source_vk.h"
6
7 namespace impeller {
8
9 TextureSourceVK::TextureSourceVK(TextureDescriptor desc) : desc_(desc) {}
10
11 TextureSourceVK::~TextureSourceVK() = default;
12
13 const TextureDescriptor& TextureSourceVK::GetTextureDescriptor() const {
14 return desc_;
15 }
16
17 std::shared_ptr<YUVConversionVK> TextureSourceVK::GetYUVConversion() const {
18 return nullptr;
19 }
20
21 vk::ImageLayout TextureSourceVK::GetLayout() const {
22 return layout_;
23 }
24
25 vk::ImageLayout TextureSourceVK::SetLayoutWithoutEncoding(
26 vk::ImageLayout layout) const {
27 const auto old_layout = layout_;
28 layout_ = layout;
29 return old_layout;
30 }
31
32 fml::Status TextureSourceVK::SetLayout(const BarrierVK& barrier) const {
33 const vk::ImageLayout old_layout =
34 SetLayoutWithoutEncoding(barrier.new_layout);
35 vk::ImageMemoryBarrier image_barrier;
36 image_barrier.srcAccessMask = barrier.src_access;
37 image_barrier.dstAccessMask = barrier.dst_access;
38 image_barrier.oldLayout = old_layout;
39 image_barrier.newLayout = barrier.new_layout;
40 image_barrier.image = GetImage();
41 image_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
42 image_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
43 image_barrier.subresourceRange.aspectMask = ToImageAspectFlags(desc_.format);
44 image_barrier.subresourceRange.baseMipLevel = barrier.base_mip_level;
45 image_barrier.subresourceRange.levelCount =
46 desc_.mip_count - barrier.base_mip_level;
47 image_barrier.subresourceRange.baseArrayLayer = 0u;
48 image_barrier.subresourceRange.layerCount = ToArrayLayerCount(desc_.type);
49
50 barrier.cmd_buffer.pipelineBarrier(barrier.src_stage, // src stage
51 barrier.dst_stage, // dst stage
52 {}, // dependency flags
53 nullptr, // memory barriers
54 nullptr, // buffer barriers
55 image_barrier // image barriers
56 );
57
58 return {};
59 }
60
61 void TextureSourceVK::SetCachedFrameData(const FramebufferAndRenderPass& data,
62 SampleCount sample_count) {
63 frame_data_[static_cast<int>(sample_count) / 4] = data;
64 }
65
66 const FramebufferAndRenderPass& TextureSourceVK::GetCachedFrameData(
67 SampleCount sample_count) const {
68 return frame_data_[static_cast<int>(sample_count) / 4];
69 }
70
71 } // namespace impeller
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::TextureSourceVK::GetYUVConversion
virtual std::shared_ptr< YUVConversionVK > GetYUVConversion() const
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
Definition: texture_source_vk.cc:17
impeller::TextureSourceVK::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Gets the texture descriptor for this image source.
Definition: texture_source_vk.cc:13
impeller::TextureSourceVK::GetCachedFrameData
const FramebufferAndRenderPass & GetCachedFrameData(SampleCount sample_count) const
Definition: texture_source_vk.cc:66
impeller::TextureSourceVK::GetImage
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
impeller::TextureSourceVK::SetCachedFrameData
void SetCachedFrameData(const FramebufferAndRenderPass &data, SampleCount sample_count)
Definition: texture_source_vk.cc:61
impeller::TextureSourceVK::~TextureSourceVK
virtual ~TextureSourceVK()
impeller::TextureSourceVK::GetLayout
vk::ImageLayout GetLayout() const
Get the last layout assigned to the TextureSourceVK.
Definition: texture_source_vk.cc:21
impeller::TextureSourceVK::SetLayoutWithoutEncoding
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
Store the layout of the image.
Definition: texture_source_vk.cc:25
impeller::TextureSourceVK::desc_
const TextureDescriptor desc_
Definition: texture_source_vk.h:152
impeller::TextureSourceVK::SetLayout
fml::Status SetLayout(const BarrierVK &barrier) const
Encodes the layout transition barrier to barrier.cmd_buffer for the image.
Definition: texture_source_vk.cc:32
desc_
std::optional< PipelineDescriptor > desc_
Definition: content_context.cc:77
impeller
Definition: allocation.cc:12
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:543
impeller::ToImageAspectFlags
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:590
impeller::SampleCount
SampleCount
Definition: formats.h:298
impeller::BarrierVK
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:27
impeller::BarrierVK::cmd_buffer
vk::CommandBuffer cmd_buffer
Definition: barrier_vk.h:28
impeller::BarrierVK::src_access
vk::AccessFlags src_access
Definition: barrier_vk.h:39
impeller::BarrierVK::dst_stage
vk::PipelineStageFlags dst_stage
Definition: barrier_vk.h:44
impeller::BarrierVK::new_layout
vk::ImageLayout new_layout
Definition: barrier_vk.h:29
impeller::BarrierVK::src_stage
vk::PipelineStageFlags src_stage
Definition: barrier_vk.h:34
impeller::BarrierVK::base_mip_level
uint32_t base_mip_level
The base mip level to apply the barrier to in the subresource range.
Definition: barrier_vk.h:52
impeller::BarrierVK::dst_access
vk::AccessFlags dst_access
Definition: barrier_vk.h:49
impeller::FramebufferAndRenderPass
Definition: texture_source_vk.h:20
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:40
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:43
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:69
texture_source_vk.h