Flutter Engine
The Flutter Engine
render_pass.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_RENDER_PASS_H_
6#define FLUTTER_IMPELLER_RENDERER_RENDER_PASS_H_
7
8#include <string>
9
10#include "fml/status.h"
18
19namespace impeller {
20
21class HostBuffer;
22class Allocator;
23
24//------------------------------------------------------------------------------
25/// @brief Render passes encode render commands directed as one specific
26/// render target into an underlying command buffer.
27///
28/// Render passes can be obtained from the command buffer in which
29/// the pass is meant to encode commands into.
30///
31/// @see `CommandBuffer`
32///
33class RenderPass : public ResourceBinder {
34 public:
35 virtual ~RenderPass();
36
37 const std::shared_ptr<const Context>& GetContext() const;
38
39 const RenderTarget& GetRenderTarget() const;
40
42
43 const Matrix& GetOrthographicTransform() const;
44
45 virtual bool IsValid() const = 0;
46
47 void SetLabel(std::string label);
48
49 /// @brief Reserve [command_count] commands in the HAL command buffer.
50 ///
51 /// Note: this is not the native command buffer.
52 virtual void ReserveCommands(size_t command_count) {
53 commands_.reserve(command_count);
54 }
55
56 //----------------------------------------------------------------------------
57 /// The pipeline to use for this command.
58 virtual void SetPipeline(
59 const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline);
60
61 //----------------------------------------------------------------------------
62 /// The debugging label to use for the command.
63 virtual void SetCommandLabel(std::string_view label);
64
65 //----------------------------------------------------------------------------
66 /// The reference value to use in stenciling operations. Stencil configuration
67 /// is part of pipeline setup and can be read from the pipelines descriptor.
68 ///
69 /// @see `Pipeline`
70 /// @see `PipelineDescriptor`
71 ///
72 virtual void SetStencilReference(uint32_t value);
73
74 virtual void SetBaseVertex(uint64_t value);
75
76 //----------------------------------------------------------------------------
77 /// The viewport coordinates that the rasterizer linearly maps normalized
78 /// device coordinates to.
79 /// If unset, the viewport is the size of the render target with a zero
80 /// origin, znear=0, and zfar=1.
81 ///
82 virtual void SetViewport(Viewport viewport);
83
84 //----------------------------------------------------------------------------
85 /// The scissor rect to use for clipping writes to the render target. The
86 /// scissor rect must lie entirely within the render target.
87 /// If unset, no scissor is applied.
88 ///
89 virtual void SetScissor(IRect scissor);
90
91 //----------------------------------------------------------------------------
92 /// The number of instances of the given set of vertices to render. Not all
93 /// backends support rendering more than one instance at a time.
94 ///
95 /// @warning Setting this to more than one will limit the availability of
96 /// backends to use with this command.
97 ///
98 virtual void SetInstanceCount(size_t count);
99
100 //----------------------------------------------------------------------------
101 /// @brief Specify the vertex and index buffer to use for this command.
102 ///
103 /// @param[in] buffer The vertex and index buffer definition. If possible,
104 /// this value should be moved and not copied.
105 ///
106 /// @return returns if the binding was updated.
107 ///
108 virtual bool SetVertexBuffer(VertexBuffer buffer);
109
110 /// Record the currently pending command.
111 virtual fml::Status Draw();
112
113 // |ResourceBinder|
114 virtual bool BindResource(ShaderStage stage,
116 const ShaderUniformSlot& slot,
117 const ShaderMetadata& metadata,
118 BufferView view) override;
119
120 virtual bool BindResource(
121 ShaderStage stage,
123 const ShaderUniformSlot& slot,
124 const std::shared_ptr<const ShaderMetadata>& metadata,
125 BufferView view);
126
127 // |ResourceBinder|
128 virtual bool BindResource(
129 ShaderStage stage,
131 const SampledImageSlot& slot,
132 const ShaderMetadata& metadata,
133 std::shared_ptr<const Texture> texture,
134 const std::unique_ptr<const Sampler>& sampler) override;
135
136 //----------------------------------------------------------------------------
137 /// @brief Encode the recorded commands to the underlying command buffer.
138 ///
139 /// @return If the commands were encoded to the underlying command
140 /// buffer.
141 ///
142 bool EncodeCommands() const;
143
144 //----------------------------------------------------------------------------
145 /// @brief Accessor for the current Commands.
146 ///
147 /// @details Visible for testing.
148 ///
149 virtual const std::vector<Command>& GetCommands() const { return commands_; }
150
151 //----------------------------------------------------------------------------
152 /// @brief The sample count of the attached render target.
154
155 //----------------------------------------------------------------------------
156 /// @brief The pixel format of the attached render target.
158
159 //----------------------------------------------------------------------------
160 /// @brief Whether the render target has a depth attachment.
161 bool HasDepthAttachment() const;
162
163 //----------------------------------------------------------------------------
164 /// @brief Whether the render target has an stencil attachment.
165 bool HasStencilAttachment() const;
166
167 protected:
168 const std::shared_ptr<const Context> context_;
169 // The following properties: sample_count, pixel_format,
170 // has_stencil_attachment, and render_target_size are cached on the
171 // RenderTarget to speed up numerous lookups during rendering. This is safe as
172 // the RenderTarget itself is copied into the RenderTarget and only exposed as
173 // a const reference.
180 std::vector<Command> commands_;
182
183 //----------------------------------------------------------------------------
184 /// @brief Record a command for subsequent encoding to the underlying
185 /// command buffer. No work is encoded into the command buffer at
186 /// this time.
187 ///
188 /// @param[in] command The command
189 ///
190 /// @return If the command was valid for subsequent commitment.
191 ///
192 bool AddCommand(Command&& command);
193
194 RenderPass(std::shared_ptr<const Context> context,
195 const RenderTarget& target);
196
197 virtual void OnSetLabel(std::string label) = 0;
198
199 virtual bool OnEncodeCommands(const Context& context) const = 0;
200
201 private:
202 RenderPass(const RenderPass&) = delete;
203
204 RenderPass& operator=(const RenderPass&) = delete;
205
206 Command pending_;
207};
208
209} // namespace impeller
210
211#endif // FLUTTER_IMPELLER_RENDERER_RENDER_PASS_H_
int count
Definition: FontMgrTest.cpp:50
GLenum type
To do anything rendering related with Impeller, you need a context.
Definition: context.h:45
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
virtual bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
Definition: render_pass.cc:138
const bool has_depth_attachment_
Definition: render_pass.h:176
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: render_pass.cc:123
const bool has_stencil_attachment_
Definition: render_pass.h:177
virtual void SetStencilReference(uint32_t value)
Definition: render_pass.cc:103
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
Definition: render_pass.cc:92
const RenderTarget & GetRenderTarget() const
Definition: render_pass.cc:39
SampleCount GetSampleCount() const
The sample count of the attached render target.
Definition: render_pass.cc:23
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
Definition: render_pass.cc:58
const SampleCount sample_count_
Definition: render_pass.h:174
virtual void OnSetLabel(std::string label)=0
virtual bool OnEncodeCommands(const Context &context) const =0
virtual void SetScissor(IRect scissor)
Definition: render_pass.cc:115
PixelFormat GetRenderTargetPixelFormat() const
The pixel format of the attached render target.
Definition: render_pass.cc:27
const Matrix & GetOrthographicTransform() const
Definition: render_pass.cc:47
RenderPass(std::shared_ptr< const Context > context, const RenderTarget &target)
Definition: render_pass.cc:10
std::vector< Command > commands_
Definition: render_pass.h:180
virtual const std::vector< Command > & GetCommands() const
Accessor for the current Commands.
Definition: render_pass.h:149
const std::shared_ptr< const Context > context_
Definition: render_pass.h:168
virtual void ReserveCommands(size_t command_count)
Reserve [command_count] commands in the HAL command buffer.
Definition: render_pass.h:52
bool HasStencilAttachment() const
Whether the render target has an stencil attachment.
Definition: render_pass.cc:35
const Matrix orthographic_
Definition: render_pass.h:181
void SetLabel(std::string label)
Definition: render_pass.cc:51
virtual bool IsValid() const =0
const ISize render_target_size_
Definition: render_pass.h:178
ISize GetRenderTargetSize() const
Definition: render_pass.cc:43
virtual void SetInstanceCount(size_t count)
Definition: render_pass.cc:119
virtual fml::Status Draw()
Record the currently pending command.
Definition: render_pass.cc:127
bool HasDepthAttachment() const
Whether the render target has a depth attachment.
Definition: render_pass.cc:31
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
Definition: render_pass.cc:97
bool EncodeCommands() const
Encode the recorded commands to the underlying command buffer.
Definition: render_pass.cc:84
const std::shared_ptr< const Context > & GetContext() const
Definition: render_pass.cc:88
virtual void SetBaseVertex(uint64_t value)
Definition: render_pass.cc:107
virtual void SetViewport(Viewport viewport)
Definition: render_pass.cc:111
const RenderTarget render_target_
Definition: render_pass.h:179
const PixelFormat pixel_format_
Definition: render_pass.h:175
uint8_t value
uint32_t * target
FlTexture * texture
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
SampleCount
Definition: formats.h:295
list command
Definition: valgrind.py:24
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition: command.h:92
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
An interface for binding resources. This is implemented by |Command| and |ComputeCommand| to make GPU...
Metadata required to bind a combined texture and sampler.
Definition: shader_types.h:98
Metadata required to bind a buffer.
Definition: shader_types.h:81