Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
To do anything rendering related with Impeller, you need a context.
Definition context.h:46
Describes the fixed function and programmable aspects of rendering and compute operations performed b...
Definition pipeline.h:49
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
const bool has_depth_attachment_
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
const bool has_stencil_attachment_
virtual void SetStencilReference(uint32_t value)
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
const RenderTarget & GetRenderTarget() const
SampleCount GetSampleCount() const
The sample count of the attached render target.
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
const SampleCount sample_count_
virtual void OnSetLabel(std::string label)=0
virtual bool OnEncodeCommands(const Context &context) const =0
virtual void SetScissor(IRect scissor)
PixelFormat GetRenderTargetPixelFormat() const
The pixel format of the attached render target.
const Matrix & GetOrthographicTransform() const
std::vector< Command > commands_
virtual const std::vector< Command > & GetCommands() const
Accessor for the current Commands.
const std::shared_ptr< const Context > context_
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.
const Matrix orthographic_
void SetLabel(std::string label)
virtual bool IsValid() const =0
const ISize render_target_size_
ISize GetRenderTargetSize() const
virtual void SetInstanceCount(size_t count)
virtual fml::Status Draw()
Record the currently pending command.
bool HasDepthAttachment() const
Whether the render target has a depth attachment.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
bool EncodeCommands() const
Encode the recorded commands to the underlying command buffer.
const std::shared_ptr< const Context > & GetContext() const
virtual void SetBaseVertex(uint64_t value)
virtual void SetViewport(Viewport viewport)
const RenderTarget render_target_
const PixelFormat pixel_format_
static const uint8_t buffer[]
uint32_t * target
FlTexture * texture
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
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.
Metadata required to bind a buffer.