Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
command.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_H_
6#define FLUTTER_IMPELLER_RENDERER_COMMAND_H_
7
8#include <cstdint>
9#include <memory>
10#include <optional>
11#include <string>
12
22
23namespace impeller {
24
25#ifdef IMPELLER_DEBUG
26#define DEBUG_COMMAND_INFO(obj, arg) obj.label = arg;
27#else
28#define DEBUG_COMMAND_INFO(obj, arg)
29#endif // IMPELLER_DEBUG
30
31template <class T>
32struct Resource {
33 using ResourceType = T;
35
37
38 Resource(const ShaderMetadata* metadata, ResourceType p_resource)
39 : resource(p_resource), metadata_(metadata) {}
40
41 Resource(std::shared_ptr<const ShaderMetadata>& metadata,
42 ResourceType p_resource)
43 : resource(p_resource), dynamic_metadata_(metadata) {}
44
45 const ShaderMetadata* GetMetadata() const {
46 return dynamic_metadata_ ? dynamic_metadata_.get() : metadata_;
47 }
48
49 private:
50 // Static shader metadata (typically generated by ImpellerC).
51 const ShaderMetadata* metadata_ = nullptr;
52
53 // Dynamically generated shader metadata.
54 std::shared_ptr<const ShaderMetadata> dynamic_metadata_;
55};
56
59
60/// @brief combines the texture, sampler and sampler slot information.
64 const std::unique_ptr<const Sampler>& sampler;
65};
66
67/// @brief combines the buffer resource and its uniform slot information.
72
73struct Bindings {
74 std::vector<TextureAndSampler> sampled_images;
75 std::vector<BufferAndUniformSlot> buffers;
76};
77
78//------------------------------------------------------------------------------
79/// @brief An object used to specify work to the GPU along with references
80/// to resources the GPU will used when doing said work.
81///
82/// To construct a valid command, follow these steps:
83/// * Specify a valid pipeline.
84/// * Specify vertex information via a call `BindVertices`
85/// * Specify any stage bindings.
86/// * (Optional) Specify a debug label.
87///
88/// Command can be created frequently and on demand. The resources
89/// referenced in commands views into buffers managed by other
90/// allocators and resource managers.
91///
92struct Command : public ResourceBinder {
93 //----------------------------------------------------------------------------
94 /// The pipeline to use for this command.
95 ///
96 std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
97 //----------------------------------------------------------------------------
98 /// The buffer, texture, and sampler bindings used by the vertex pipeline
99 /// stage.
100 ///
102 //----------------------------------------------------------------------------
103 /// The buffer, texture, and sampler bindings used by the fragment pipeline
104 /// stage.
105 ///
107
108#ifdef IMPELLER_DEBUG
109 //----------------------------------------------------------------------------
110 /// The debugging label to use for the command.
111 ///
112 std::string label;
113#endif // IMPELLER_DEBUG
114
115 //----------------------------------------------------------------------------
116 /// The reference value to use in stenciling operations. Stencil configuration
117 /// is part of pipeline setup and can be read from the pipelines descriptor.
118 ///
119 /// @see `Pipeline`
120 /// @see `PipelineDescriptor`
121 ///
122 uint32_t stencil_reference = 0u;
123 //----------------------------------------------------------------------------
124 /// The offset used when indexing into the vertex buffer.
125 ///
126 uint64_t base_vertex = 0u;
127 //----------------------------------------------------------------------------
128 /// The viewport coordinates that the rasterizer linearly maps normalized
129 /// device coordinates to.
130 /// If unset, the viewport is the size of the render target with a zero
131 /// origin, znear=0, and zfar=1.
132 ///
133 std::optional<Viewport> viewport;
134 //----------------------------------------------------------------------------
135 /// The scissor rect to use for clipping writes to the render target. The
136 /// scissor rect must lie entirely within the render target.
137 /// If unset, no scissor is applied.
138 ///
139 std::optional<IRect> scissor;
140 //----------------------------------------------------------------------------
141 /// The number of instances of the given set of vertices to render. Not all
142 /// backends support rendering more than one instance at a time.
143 ///
144 /// @warning Setting this to more than one will limit the availability of
145 /// backends to use with this command.
146 ///
147 size_t instance_count = 1u;
148
149 //----------------------------------------------------------------------------
150 /// The bound per-vertex data and optional index buffer.
152
153 //----------------------------------------------------------------------------
154 /// @brief Specify the vertex and index buffer to use for this command.
155 ///
156 /// @param[in] buffer The vertex and index buffer definition. If possible,
157 /// this value should be moved and not copied.
158 ///
159 /// @return returns if the binding was updated.
160 ///
162
163 // |ResourceBinder|
164 bool BindResource(ShaderStage stage,
166 const ShaderUniformSlot& slot,
167 const ShaderMetadata& metadata,
168 BufferView view) override;
169
170 bool BindResource(ShaderStage stage,
172 const ShaderUniformSlot& slot,
173 const std::shared_ptr<const ShaderMetadata>& metadata,
174 BufferView view);
175
176 // |ResourceBinder|
177 bool BindResource(ShaderStage stage,
179 const SampledImageSlot& slot,
180 const ShaderMetadata& metadata,
181 std::shared_ptr<const Texture> texture,
182 const std::unique_ptr<const Sampler>& sampler) override;
183
184 bool IsValid() const { return pipeline && pipeline->IsValid(); }
185
186 private:
187 template <class T>
188 bool DoBindResource(ShaderStage stage,
189 const ShaderUniformSlot& slot,
190 T metadata,
191 BufferView view);
192};
193
194} // namespace impeller
195
196#endif // FLUTTER_IMPELLER_RENDERER_COMMAND_H_
static const uint8_t buffer[]
FlTexture * texture
#define T
std::vector< BufferAndUniformSlot > buffers
Definition command.h:75
std::vector< TextureAndSampler > sampled_images
Definition command.h:74
combines the buffer resource and its uniform slot information.
Definition command.h:68
ShaderUniformSlot slot
Definition command.h:69
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
Bindings fragment_bindings
Definition command.h:106
uint64_t base_vertex
Definition command.h:126
uint32_t stencil_reference
Definition command.h:122
std::optional< Viewport > viewport
Definition command.h:133
VertexBuffer vertex_buffer
The bound per-vertex data and optional index buffer.
Definition command.h:151
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition command.cc:15
Bindings vertex_bindings
Definition command.h:101
std::optional< IRect > scissor
Definition command.h:139
bool IsValid() const
Definition command.h:184
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
An interface for binding resources. This is implemented by |Command| and |ComputeCommand| to make GPU...
const ShaderMetadata * GetMetadata() const
Definition command.h:45
Resource(std::shared_ptr< const ShaderMetadata > &metadata, ResourceType p_resource)
Definition command.h:41
Resource(const ShaderMetadata *metadata, ResourceType p_resource)
Definition command.h:38
ResourceType resource
Definition command.h:34
Metadata required to bind a combined texture and sampler.
Metadata required to bind a buffer.
combines the texture, sampler and sampler slot information.
Definition command.h:61
const std::unique_ptr< const Sampler > & sampler
Definition command.h:64
SampledImageSlot slot
Definition command.h:62
TextureResource texture
Definition command.h:63