Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
command_buffer.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_COMMAND_BUFFER_H_
6#define FLUTTER_IMPELLER_RENDERER_COMMAND_BUFFER_H_
7
8#include <functional>
9#include <memory>
10
13
14namespace impeller {
15
16class ComputePass;
17class Context;
18class RenderPass;
19class RenderTarget;
20class CommandQueue;
21
22namespace testing {
23class CommandBufferMock;
24}
25
26//------------------------------------------------------------------------------
27/// @brief A collection of encoded commands to be submitted to the GPU for
28/// execution. A command buffer is obtained from a graphics
29/// `Context`.
30///
31/// To submit commands to the GPU, acquire a `RenderPass` from the
32/// command buffer and record `Command`s into that pass. A
33/// `RenderPass` describes the configuration of the various
34/// attachments when the command is submitted.
35///
36/// A command buffer is only meant to be used on a single thread. If
37/// a frame workload needs to be encoded from multiple threads,
38/// set up and record into multiple command buffers. The order of
39/// submission of commands encoded in multiple command buffers can
40/// be controlled via either the order in which the command buffers
41/// were created, or, using the `ReserveSpotInQueue` command which
42/// allows for encoding commands for submission in an order that is
43/// different from the encoding order.
44///
47
48 public:
49 enum class Status {
51 kError,
53 };
54
55 using CompletionCallback = std::function<void(Status)>;
56
57 virtual ~CommandBuffer();
58
59 virtual bool IsValid() const = 0;
60
61 virtual void SetLabel(const std::string& label) const = 0;
62
63 //----------------------------------------------------------------------------
64 /// @brief Force execution of pending GPU commands.
65 ///
66 void WaitUntilScheduled();
67
68 //----------------------------------------------------------------------------
69 /// @brief Create a render pass to record render commands into.
70 ///
71 /// @param[in] render_target The description of the render target this pass
72 /// will target.
73 ///
74 /// @return A valid render pass or null.
75 ///
76 std::shared_ptr<RenderPass> CreateRenderPass(
77 const RenderTarget& render_target);
78
79 //----------------------------------------------------------------------------
80 /// @brief Create a blit pass to record blit commands into.
81 ///
82 /// @return A valid blit pass or null.
83 ///
84 std::shared_ptr<BlitPass> CreateBlitPass();
85
86 //----------------------------------------------------------------------------
87 /// @brief Create a compute pass to record compute commands into.
88 ///
89 /// @return A valid compute pass or null.
90 ///
91 std::shared_ptr<ComputePass> CreateComputePass();
92
93 protected:
94 std::weak_ptr<const Context> context_;
95
96 explicit CommandBuffer(std::weak_ptr<const Context> context);
97
98 virtual std::shared_ptr<RenderPass> OnCreateRenderPass(
99 RenderTarget render_target) = 0;
100
101 virtual std::shared_ptr<BlitPass> OnCreateBlitPass() = 0;
102
103 [[nodiscard]] virtual bool OnSubmitCommands(CompletionCallback callback) = 0;
104
105 virtual void OnWaitUntilScheduled() = 0;
106
107 virtual std::shared_ptr<ComputePass> OnCreateComputePass() = 0;
108
109 private:
110 friend class CommandQueue;
111
112 //----------------------------------------------------------------------------
113 /// @brief Schedule the command encoded by render passes within this
114 /// command buffer on the GPU. The encoding of these commnands is
115 /// performed immediately on the calling thread.
116 ///
117 /// A command buffer may only be committed once.
118 ///
119 /// @param[in] callback The completion callback.
120 ///
121 [[nodiscard]] bool SubmitCommands(const CompletionCallback& callback);
122
123 [[nodiscard]] bool SubmitCommands();
124
125 CommandBuffer(const CommandBuffer&) = delete;
126
127 CommandBuffer& operator=(const CommandBuffer&) = delete;
128};
129
130} // namespace impeller
131
132#endif // FLUTTER_IMPELLER_RENDERER_COMMAND_BUFFER_H_
A collection of encoded commands to be submitted to the GPU for execution. A command buffer is obtain...
std::shared_ptr< BlitPass > CreateBlitPass()
Create a blit pass to record blit commands into.
std::shared_ptr< ComputePass > CreateComputePass()
Create a compute pass to record compute commands into.
virtual std::shared_ptr< BlitPass > OnCreateBlitPass()=0
virtual void SetLabel(const std::string &label) const =0
virtual bool IsValid() const =0
virtual std::shared_ptr< ComputePass > OnCreateComputePass()=0
virtual bool OnSubmitCommands(CompletionCallback callback)=0
std::function< void(Status)> CompletionCallback
std::shared_ptr< RenderPass > CreateRenderPass(const RenderTarget &render_target)
Create a render pass to record render commands into.
virtual void OnWaitUntilScheduled()=0
std::weak_ptr< const Context > context_
void WaitUntilScheduled()
Force execution of pending GPU commands.
virtual std::shared_ptr< RenderPass > OnCreateRenderPass(RenderTarget render_target)=0
An interface for submitting command buffers to the GPU for encoding and execution.
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)