Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
26
30
34
38
42
46
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
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
107void RenderPass::SetBaseVertex(uint64_t value) {
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
Describes the fixed function and programmable aspects of rendering and compute operations performed b...
Definition pipeline.h:49
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
RenderPass(std::shared_ptr< const Context > context, const RenderTarget &target)
std::vector< Command > commands_
const std::shared_ptr< const Context > context_
bool HasStencilAttachment() const
Whether the render target has an stencil attachment.
const Matrix orthographic_
void SetLabel(std::string label)
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_
ISize GetRenderTargetSize() const
static const uint8_t buffer[]
uint8_t value
GAsyncResult * result
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
Definition ref_ptr.h:256
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.
Definition command.cc:15
std::optional< IRect > scissor
Definition command.h:139
bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
Definition command.cc:25
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.
Metadata required to bind a buffer.
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146
#define VALIDATION_LOG
Definition validation.h:73