| Flutter Impeller |

command_buffer_vk.h
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 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_BUFFER_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_BUFFER_VK_H_
7
8 #include "fml/status_or.h"
9 #include "impeller/base/backend_cast.h"
10 #include "impeller/renderer/backend/vulkan/command_queue_vk.h"
11 #include "impeller/renderer/backend/vulkan/device_holder_vk.h"
12 #include "impeller/renderer/backend/vulkan/texture_source_vk.h"
13 #include "impeller/renderer/backend/vulkan/tracked_objects_vk.h"
14 #include "impeller/renderer/backend/vulkan/vk.h"
15 #include "impeller/renderer/command_buffer.h"
16
17 namespace impeller {
18
19 class ContextVK;
20 class CommandEncoderFactoryVK;
21 class CommandEncoderVK;
22
23 class CommandBufferVK final
24 : public CommandBuffer,
25 public BackendCast<CommandBufferVK, CommandBuffer>,
26 public std::enable_shared_from_this<CommandBufferVK> {
27 public:
28 // |CommandBuffer|
29 ~CommandBufferVK() override;
30
31 // Encoder Functionality
32
33 /// @brief Ensure that [object] is kept alive until this command buffer
34 /// completes execution.
35 bool Track(std::shared_ptr<SharedObjectVK> object);
36
37 /// @brief Ensure that [buffer] is kept alive until this command buffer
38 /// completes execution.
39 bool Track(const std::shared_ptr<const DeviceBuffer>& buffer);
40
41 /// @brief Ensure that [texture] is kept alive until this command buffer
42 /// completes execution.
43 bool Track(const std::shared_ptr<const Texture>& texture);
44
45 /// @brief Ensure that [texture] is kept alive until this command buffer
46 /// completes execution.
47 bool Track(std::shared_ptr<const TextureSourceVK> texture);
48
49 /// @brief Retrieve the native command buffer from this object.
50 vk::CommandBuffer GetCommandBuffer() const;
51
52 /// @brief Push a debug group.
53 ///
54 /// This label is only visible in debuggers like RenderDoc. This function is
55 /// ignored in release builds.
56 void PushDebugGroup(std::string_view label) const;
57
58 /// @brief Pop the previous debug group.
59 ///
60 /// This label is only visible in debuggers like RenderDoc. This function is
61 /// ignored in release builds.
62 void PopDebugGroup() const;
63
64 /// @brief Insert a new debug marker.
65 ///
66 /// This label is only visible in debuggers like RenderDoc. This function is
67 /// ignored in release builds.
68 void InsertDebugMarker(std::string_view label) const;
69
70 /// @brief End recording of the current command buffer.
71 bool EndCommandBuffer() const;
72
73 /// @brief Allocate a new descriptor set for the given [layout].
74 fml::StatusOr<vk::DescriptorSet> AllocateDescriptorSets(
75 const vk::DescriptorSetLayout& layout,
76 const ContextVK& context);
77
78 // Visible for testing.
79 bool IsTracking(const std::shared_ptr<const DeviceBuffer>& texture) const;
80
81 // Visible for testing.
82 bool IsTracking(const std::shared_ptr<const Texture>& texture) const;
83
84 private:
85 friend class ContextVK;
86 friend class CommandQueueVK;
87
88 std::weak_ptr<const DeviceHolderVK> device_holder_;
89 std::shared_ptr<TrackedObjectsVK> tracked_objects_;
90 std::shared_ptr<FenceWaiterVK> fence_waiter_;
91
92 CommandBufferVK(std::weak_ptr<const Context> context,
93 std::weak_ptr<const DeviceHolderVK> device_holder,
94 std::shared_ptr<TrackedObjectsVK> tracked_objects,
95 std::shared_ptr<FenceWaiterVK> fence_waiter);
96
97 // |CommandBuffer|
98 void SetLabel(const std::string& label) const override;
99
100 // |CommandBuffer|
101 bool IsValid() const override;
102
103 // |CommandBuffer|
104 bool OnSubmitCommands(CompletionCallback callback) override;
105
106 // |CommandBuffer|
107 void OnWaitUntilScheduled() override;
108
109 // |CommandBuffer|
110 std::shared_ptr<RenderPass> OnCreateRenderPass(RenderTarget target) override;
111
112 // |CommandBuffer|
113 std::shared_ptr<BlitPass> OnCreateBlitPass() override;
114
115 // |CommandBuffer|
116 std::shared_ptr<ComputePass> OnCreateComputePass() override;
117
118 CommandBufferVK(const CommandBufferVK&) = delete;
119
120 CommandBufferVK& operator=(const CommandBufferVK&) = delete;
121 };
122
123 } // namespace impeller
124
125 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_BUFFER_VK_H_
impeller::CommandBufferVK::InsertDebugMarker
void InsertDebugMarker(std::string_view label) const
Insert a new debug marker.
Definition: command_buffer_vk.cc:202
tracked_objects_vk.h
texture_source_vk.h
impeller::CommandBufferVK::Track
bool Track(std::shared_ptr< SharedObjectVK > object)
Ensure that [object] is kept alive until this command buffer completes execution.
Definition: command_buffer_vk.cc:119
impeller::CommandBufferVK::IsTracking
bool IsTracking(const std::shared_ptr< const DeviceBuffer > &texture) const
Definition: command_buffer_vk.cc:135
impeller::CommandBuffer::CompletionCallback
std::function< void(Status)> CompletionCallback
Definition: command_buffer.h:55
vk.h
device_holder_vk.h
impeller::CommandBufferVK::GetCommandBuffer
vk::CommandBuffer GetCommandBuffer() const
Retrieve the native command buffer from this object.
Definition: command_buffer_vk.cc:112
impeller::CommandBufferVK::~CommandBufferVK
~CommandBufferVK() override
impeller::CommandBufferVK::EndCommandBuffer
bool EndCommandBuffer() const
End recording of the current command buffer.
Definition: command_buffer_vk.cc:98
backend_cast.h
impeller::CommandBufferVK::AllocateDescriptorSets
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, const ContextVK &context)
Allocate a new descriptor set for the given [layout].
Definition: command_buffer_vk.cc:171
impeller::RenderTarget
Definition: render_target.h:38
impeller::CommandQueueVK
Definition: command_queue_vk.h:14
impeller::CommandBufferVK
Definition: command_buffer_vk.h:23
impeller::ContextVK
Definition: context_vk.h:42
command_buffer.h
impeller::CommandBufferVK::PopDebugGroup
void PopDebugGroup() const
Pop the previous debug group.
Definition: command_buffer_vk.cc:193
impeller::BackendCast
Definition: backend_cast.h:11
command_queue_vk.h
impeller
Definition: allocation.cc:12
impeller::CommandBuffer
A collection of encoded commands to be submitted to the GPU for execution. A command buffer is obtain...
Definition: command_buffer.h:45
impeller::CommandBufferVK::PushDebugGroup
void PushDebugGroup(std::string_view label) const
Push a debug group.
Definition: command_buffer_vk.cc:182