| 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 auto old_layout = SetLayoutWithoutEncoding(barrier.new_layout);
34 vk::ImageMemoryBarrier image_barrier;
35 image_barrier.srcAccessMask = barrier.src_access;
36 image_barrier.dstAccessMask = barrier.dst_access;
37 image_barrier.oldLayout = old_layout;
38 image_barrier.newLayout = barrier.new_layout;
39 image_barrier.image = GetImage();
40 image_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
41 image_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
42 image_barrier.subresourceRange.aspectMask = ToImageAspectFlags(desc_.format);
43 image_barrier.subresourceRange.baseMipLevel = 0u;
44 image_barrier.subresourceRange.levelCount = desc_.mip_count;
45 image_barrier.subresourceRange.baseArrayLayer = 0u;
46 image_barrier.subresourceRange.layerCount = ToArrayLayerCount(desc_.type);
47
48 barrier.cmd_buffer.pipelineBarrier(barrier.src_stage, // src stage
49 barrier.dst_stage, // dst stage
50 {}, // dependency flags
51 nullptr, // memory barriers
52 nullptr, // buffer barriers
53 image_barrier // image barriers
54 );
55
56 return {};
57 }
58
59 void TextureSourceVK::SetCachedFramebuffer(
60 const SharedHandleVK<vk::Framebuffer>& framebuffer) {
61 framebuffer_ = framebuffer;
62 }
63
64 void TextureSourceVK::SetCachedRenderPass(
65 const SharedHandleVK<vk::RenderPass>& render_pass) {
66 render_pass_ = render_pass;
67 }
68
69 SharedHandleVK<vk::Framebuffer> TextureSourceVK::GetCachedFramebuffer() const {
70 return framebuffer_;
71 }
72
73 SharedHandleVK<vk::RenderPass> TextureSourceVK::GetCachedRenderPass() const {
74 return render_pass_;
75 }
76
77 } // namespace impeller
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::TextureSourceVK::SetCachedRenderPass
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
Definition: texture_source_vk.cc:64
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::GetCachedFramebuffer
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
Definition: texture_source_vk.cc:69
impeller::TextureSourceVK::GetImage
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
impeller::TextureSourceVK::SetCachedFramebuffer
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
Definition: texture_source_vk.cc:59
impeller::TextureSourceVK::~TextureSourceVK
virtual ~TextureSourceVK()
impeller::TextureSourceVK::GetCachedRenderPass
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
Definition: texture_source_vk.cc:73
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:153
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
impeller
Definition: allocation.cc:12
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:53
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:539
impeller::ToImageAspectFlags
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:586
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::dst_access
vk::AccessFlags dst_access
Definition: barrier_vk.h:49
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
texture_source_vk.h