Flutter Engine
The Flutter Engine
render_pass.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
6#include "fml/status.h"
7
8namespace impeller {
9
10RenderPass::RenderPass(std::shared_ptr<const Context> context,
11 const RenderTarget& target)
12 : context_(std::move(context)),
13 sample_count_(target.GetSampleCount()),
14 pixel_format_(target.GetRenderTargetPixelFormat()),
15 has_depth_attachment_(target.GetDepthAttachment().has_value()),
16 has_stencil_attachment_(target.GetStencilAttachment().has_value()),
17 render_target_size_(target.GetRenderTargetSize()),
18 render_target_(target),
19 orthographic_(Matrix::MakeOrthographic(render_target_size_)) {}
20
22
24 return sample_count_;
25}
26
28 return pixel_format_;
29}
30
33}
34
37}
38
40 return render_target_;
41}
42
45}
46
48 return orthographic_;
49}
50
51void RenderPass::SetLabel(std::string label) {
52 if (label.empty()) {
53 return;
54 }
55 OnSetLabel(std::move(label));
56}
57
59 if (!command.IsValid()) {
60 VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
61 return false;
62 }
63
64 if (command.scissor.has_value()) {
66 if (!target_rect.Contains(command.scissor.value())) {
67 VALIDATION_LOG << "Cannot apply a scissor that lies outside the bounds "
68 "of the render target.";
69 return false;
70 }
71 }
72
73 if (command.vertex_buffer.vertex_count == 0u ||
74 command.instance_count == 0u) {
75 // Essentially a no-op. Don't record the command but this is not necessary
76 // an error either.
77 return true;
78 }
79
80 commands_.emplace_back(std::move(command));
81 return true;
82}
83
86}
87
88const std::shared_ptr<const Context>& RenderPass::GetContext() const {
89 return context_;
90}
91
93 const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline) {
94 pending_.pipeline = pipeline;
95}
96
97void RenderPass::SetCommandLabel(std::string_view label) {
98#ifdef IMPELLER_DEBUG
99 pending_.label = std::string(label);
100#endif // IMPELLER_DEBUG
101}
102
104 pending_.stencil_reference = value;
105}
106
108 pending_.base_vertex = value;
109}
110
112 pending_.viewport = viewport;
113}
114
116 pending_.scissor = scissor;
117}
118
120 pending_.instance_count = count;
121}
122
124 return pending_.BindVertices(std::move(buffer));
125}
126
128 auto result = AddCommand(std::move(pending_));
129 pending_ = Command{};
130 if (result) {
131 return fml::Status();
132 }
134 "Failed to encode command");
135}
136
137// |ResourceBinder|
140 const ShaderUniformSlot& slot,
141 const ShaderMetadata& metadata,
142 BufferView view) {
143 return pending_.BindResource(stage, type, slot, metadata, view);
144}
145
147 ShaderStage stage,
149 const ShaderUniformSlot& slot,
150 const std::shared_ptr<const ShaderMetadata>& metadata,
151 BufferView view) {
152 return pending_.BindResource(stage, type, slot, metadata, std::move(view));
153}
154
155// |ResourceBinder|
158 const SampledImageSlot& slot,
159 const ShaderMetadata& metadata,
160 std::shared_ptr<const Texture> texture,
161 const std::unique_ptr<const Sampler>& sampler) {
162 return pending_.BindResource(stage, type, slot, metadata, std::move(texture),
163 sampler);
164}
165
166} // namespace impeller
int count
Definition: FontMgrTest.cpp:50
GLenum type
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
const std::shared_ptr< const Context > context_
Definition: render_pass.h:168
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
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
ISize GetRenderTargetSize() const
uint8_t value
GAsyncResult * result
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
Task::Status Status
Definition: TaskList.cpp:15
Definition: ref_ptr.h:256
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
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:96
uint64_t base_vertex
Definition: command.h:126
uint32_t stencil_reference
Definition: command.h:122
std::optional< Viewport > viewport
Definition: command.h:133
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
std::optional< IRect > scissor
Definition: command.h:139
bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
size_t instance_count
Definition: command.h:147
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
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
static constexpr TRect MakeSize(const TSize< U > &size)
Definition: rect.h:146
#define VALIDATION_LOG
Definition: validation.h:73