| 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 ReaderLock lock(layout_mutex_);
23 return layout_;
24 }
25
26 vk::ImageLayout TextureSourceVK::SetLayoutWithoutEncoding(
27 vk::ImageLayout layout) const {
28 WriterLock lock(layout_mutex_);
29 const auto old_layout = layout_;
30 layout_ = layout;
31 return old_layout;
32 }
33
34 fml::Status TextureSourceVK::SetLayout(const BarrierVK& barrier) const {
35 const auto old_layout = SetLayoutWithoutEncoding(barrier.new_layout);
36 if (barrier.new_layout == old_layout) {
37 return {};
38 }
39
40 vk::ImageMemoryBarrier image_barrier;
41 image_barrier.srcAccessMask = barrier.src_access;
42 image_barrier.dstAccessMask = barrier.dst_access;
43 image_barrier.oldLayout = old_layout;
44 image_barrier.newLayout = barrier.new_layout;
45 image_barrier.image = GetImage();
46 image_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
47 image_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
48 image_barrier.subresourceRange.aspectMask = ToImageAspectFlags(desc_.format);
49 image_barrier.subresourceRange.baseMipLevel = 0u;
50 image_barrier.subresourceRange.levelCount = desc_.mip_count;
51 image_barrier.subresourceRange.baseArrayLayer = 0u;
52 image_barrier.subresourceRange.layerCount = ToArrayLayerCount(desc_.type);
53
54 barrier.cmd_buffer.pipelineBarrier(barrier.src_stage, // src stage
55 barrier.dst_stage, // dst stage
56 {}, // dependency flags
57 nullptr, // memory barriers
58 nullptr, // buffer barriers
59 image_barrier // image barriers
60 );
61
62 return {};
63 }
64
65 void TextureSourceVK::SetCachedFramebuffer(
66 const SharedHandleVK<vk::Framebuffer>& framebuffer) {
67 framebuffer_ = framebuffer;
68 }
69
70 void TextureSourceVK::SetCachedRenderPass(
71 const SharedHandleVK<vk::RenderPass>& render_pass) {
72 render_pass_ = render_pass;
73 }
74
75 SharedHandleVK<vk::Framebuffer> TextureSourceVK::GetCachedFramebuffer() const {
76 return framebuffer_;
77 }
78
79 SharedHandleVK<vk::RenderPass> TextureSourceVK::GetCachedRenderPass() const {
80 return render_pass_;
81 }
82
83 } // namespace impeller
impeller::BarrierVK::dst_access
vk::AccessFlags dst_access
Definition: barrier_vk.h:50
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::BarrierVK::new_layout
vk::ImageLayout new_layout
Definition: barrier_vk.h:30
impeller::WriterLock
Definition: thread.h:116
texture_source_vk.h
impeller::BarrierVK::cmd_buffer
vk::CommandBuffer cmd_buffer
Definition: barrier_vk.h:29
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:517
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:42
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:39
impeller::TextureSourceVK::desc_
const TextureDescriptor desc_
Definition: texture_source_vk.h:155
impeller::TextureSourceVK::SetLayoutWithoutEncoding
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
Store the layout of the image.
Definition: texture_source_vk.cc:26
impeller::BarrierVK
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:28
impeller::TextureSourceVK::GetCachedRenderPass
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
Definition: texture_source_vk.cc:79
impeller::ReaderLock
Definition: thread.h:95
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::BarrierVK::src_access
vk::AccessFlags src_access
Definition: barrier_vk.h:40
impeller::TextureSourceVK::GetImage
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
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:34
impeller::BarrierVK::dst_stage
vk::PipelineStageFlags dst_stage
Definition: barrier_vk.h:45
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:52
impeller::TextureSourceVK::GetCachedFramebuffer
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
Definition: texture_source_vk.cc:75
impeller::TextureSourceVK::SetCachedRenderPass
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
Definition: texture_source_vk.cc:70
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
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::SetCachedFramebuffer
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
Definition: texture_source_vk.cc:65
impeller
Definition: aiks_blur_unittests.cc:20
impeller::BarrierVK::src_stage
vk::PipelineStageFlags src_stage
Definition: barrier_vk.h:35
impeller::ToImageAspectFlags
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:564