Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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_LIB_GPU_RENDER_PASS_H_
6#define FLUTTER_LIB_GPU_RENDER_PASS_H_
7
8#include <array>
9#include <cstdint>
10#include <map>
11#include <memory>
15#include "fml/memory/ref_ptr.h"
23#include "lib/gpu/texture.h"
24
25namespace flutter {
26namespace gpu {
27
28class RenderPass : public RefCountedDartWrappable<RenderPass> {
29 DEFINE_WRAPPERTYPEINFO();
31
32 public:
34
35 ~RenderPass() override;
36
37 const std::shared_ptr<const impeller::Context>& GetContext() const;
38
41
43 size_t color_attachment_index);
44
46
48
50
52
54
56
57 void ClearBindings();
58
59 /// Append a draw to the underlying render pass. [element_count] is the
60 /// vertex count for a non-indexed draw, or the index count when
61 /// [indexed] is true. [instance_count] is the number of instances to draw.
62 bool Draw(size_t element_count, size_t instance_count, bool indexed);
63
68
70 std::unordered_map<const flutter::gpu::Shader::UniformBinding*,
73 std::unordered_map<const flutter::gpu::Shader::TextureBinding*,
75
80
81 // Vertex buffers indexed by binding slot. Mirrors
82 // `impeller::kMaxVertexBuffers`; Impeller's HAL caps vertex buffer
83 // bindings at 16 per draw, and index `i` here corresponds to the binding
84 // declared at slot `i` in the active VertexLayout. Devices may impose a
85 // lower per-pipeline limit on the total attribute count across all bound
86 // buffers.
87 static constexpr size_t kMaxVertexBufferSlots = 16;
88 std::array<impeller::BufferView, kMaxVertexBufferSlots> vertex_buffers;
89 // Highest slot index that has been bound on this pass (plus one).
93
94 uint32_t stencil_reference = 0;
95 std::optional<impeller::IRect32> scissor;
96 std::optional<impeller::Viewport> viewport;
97
98 private:
99 /// Lookup an Impeller pipeline by building a descriptor based on the current
100 /// command state.
101 std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>>
102 GetOrCreatePipeline();
103
104 impeller::RenderTarget render_target_;
105 std::shared_ptr<impeller::RenderPass> render_pass_;
106
107 // Command encoding state.
108 fml::RefPtr<RenderPipeline> render_pipeline_;
109 impeller::PipelineDescriptor pipeline_descriptor_;
110
111 // Pipeline descriptor layout state. We always keep track of this state,
112 // but we'll only apply it as necessary to match the RenderTarget.
113 std::map<size_t, impeller::ColorAttachmentDescriptor> color_descriptors_;
114 impeller::StencilAttachmentDescriptor stencil_front_desc_;
115 impeller::StencilAttachmentDescriptor stencil_back_desc_;
117
119};
120
121} // namespace gpu
122} // namespace flutter
123
124//----------------------------------------------------------------------------
125/// Exports
126///
127
128extern "C" {
129
131extern void InternalFlutterGpu_RenderPass_Initialize(Dart_Handle wrapper);
132
137 int color_attachment_index,
138 int load_action,
139 int store_action,
140 float clear_color_r,
141 float clear_color_g,
142 float clear_color_b,
143 float clear_color_a,
145 Dart_Handle resolve_texture_wrapper,
146 int mip_level,
147 int slice);
148
152 int depth_load_action,
153 int depth_store_action,
154 float depth_clear_value,
155 int stencil_load_action,
156 int stencil_store_action,
157 int stencil_clear_value,
159 int mip_level,
160 int slice);
161
163extern Dart_Handle InternalFlutterGpu_RenderPass_Begin(
166
171
175 flutter::gpu::DeviceBuffer* device_buffer,
176 int offset_in_bytes,
177 int length_in_bytes,
178 int slot);
179
183 flutter::gpu::DeviceBuffer* device_buffer,
184 int offset_in_bytes,
185 int length_in_bytes,
186 int index_type);
187
191 flutter::gpu::Shader* shader,
192 Dart_Handle uniform_name_handle,
193 flutter::gpu::DeviceBuffer* device_buffer,
194 int offset_in_bytes,
195 int length_in_bytes);
196
200 flutter::gpu::Shader* shader,
201 Dart_Handle uniform_name_handle,
203 int min_filter,
204 int mag_filter,
205 int mip_filter,
206 int width_address_mode,
207 int height_address_mode);
208
211 flutter::gpu::RenderPass* wrapper);
212
216 int color_attachment_index,
217 bool enable);
218
222 int color_attachment_index,
223 int color_blend_operation,
224 int source_color_blend_factor,
225 int destination_color_blend_factor,
226 int alpha_blend_operation,
227 int source_alpha_blend_factor,
228 int destination_alpha_blend_factor);
229
233 bool enable);
234
238 int compare_operation);
239
243 int stencil_reference);
244
248 int stencil_compare_operation,
249 int stencil_fail_operation,
250 int depth_fail_operation,
251 int depth_stencil_pass_operation,
252 int read_mask,
253 int write_mask,
254 int target);
255
259 int x,
260 int y,
261 int width,
262 int height);
263
267 int x,
268 int y,
269 int width,
270 int height,
271 float z_near,
272 float z_far);
273
277 int cull_mode);
278
282 int primitive_type);
283
287 int winding_order);
288
292 int polygon_mode);
293
297 int vertex_count,
298 int instance_count);
299
303 int index_count,
304 int instance_count);
305
306} // extern "C"
307
308#endif // FLUTTER_LIB_GPU_RENDER_PASS_H_
std::optional< impeller::Viewport > viewport
Definition render_pass.h:96
impeller::StencilAttachmentDescriptor & GetStencilBackAttachmentDescriptor()
void SetPipeline(fml::RefPtr< RenderPipeline > pipeline)
impeller::RenderTarget & GetRenderTarget()
bool Begin(flutter::gpu::CommandBuffer &command_buffer)
std::unordered_map< const flutter::gpu::Shader::UniformBinding *, BufferAndUniformSlot > BufferUniformMap
Definition render_pass.h:71
static constexpr size_t kMaxVertexBufferSlots
Definition render_pass.h:87
impeller::DepthAttachmentDescriptor & GetDepthAttachmentDescriptor()
std::unordered_map< const flutter::gpu::Shader::TextureBinding *, impeller::TextureAndSampler > TextureUniformMap
Definition render_pass.h:74
std::optional< impeller::IRect32 > scissor
Definition render_pass.h:95
TextureUniformMap fragment_texture_bindings
Definition render_pass.h:79
BufferUniformMap fragment_uniform_bindings
Definition render_pass.h:78
TextureUniformMap vertex_texture_bindings
Definition render_pass.h:77
BufferUniformMap vertex_uniform_bindings
Definition render_pass.h:76
impeller::IndexType index_buffer_type
Definition render_pass.h:92
std::array< impeller::BufferView, kMaxVertexBufferSlots > vertex_buffers
Definition render_pass.h:88
impeller::StencilAttachmentDescriptor & GetStencilFrontAttachmentDescriptor()
impeller::ColorAttachmentDescriptor & GetColorAttachmentDescriptor(size_t color_attachment_index)
bool Draw(size_t element_count, size_t instance_count, bool indexed)
impeller::PipelineDescriptor & GetPipelineDescriptor()
const std::shared_ptr< const impeller::Context > & GetContext() const
impeller::BufferView index_buffer
Definition render_pass.h:91
An immutable collection of shaders loaded from a shader bundle asset.
Definition shader.h:23
int32_t x
uint32_t * target
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
#define FLUTTER_GPU_EXPORT
Definition export.h:13
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_RenderPass_Draw(flutter::gpu::RenderPass *wrapper, int vertex_count, int instance_count)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetColorBlendEquation(flutter::gpu::RenderPass *wrapper, int color_attachment_index, int color_blend_operation, int source_color_blend_factor, int destination_color_blend_factor, int alpha_blend_operation, int source_alpha_blend_factor, int destination_alpha_blend_factor)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetDepthCompareOperation(flutter::gpu::RenderPass *wrapper, int compare_operation)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_BindPipeline(flutter::gpu::RenderPass *wrapper, flutter::gpu::RenderPipeline *pipeline)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_BindVertexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int slot)
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_RenderPass_BindTexture(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, flutter::gpu::Texture *texture, int min_filter, int mag_filter, int mip_filter, int width_address_mode, int height_address_mode)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetStencilConfig(flutter::gpu::RenderPass *wrapper, int stencil_compare_operation, int stencil_fail_operation, int depth_fail_operation, int depth_stencil_pass_operation, int read_mask, int write_mask, int target)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetPolygonMode(flutter::gpu::RenderPass *wrapper, int polygon_mode)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetScissor(flutter::gpu::RenderPass *wrapper, int x, int y, int width, int height)
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_RenderPass_SetColorAttachment(flutter::gpu::RenderPass *wrapper, flutter::gpu::Context *context, int color_attachment_index, int load_action, int store_action, float clear_color_r, float clear_color_g, float clear_color_b, float clear_color_a, flutter::gpu::Texture *texture, Dart_Handle resolve_texture_wrapper, int mip_level, int slice)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_Initialize(Dart_Handle wrapper)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetViewport(flutter::gpu::RenderPass *wrapper, int x, int y, int width, int height, float z_near, float z_far)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetWindingOrder(flutter::gpu::RenderPass *wrapper, int winding_order)
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_RenderPass_SetDepthStencilAttachment(flutter::gpu::RenderPass *wrapper, int depth_load_action, int depth_store_action, float depth_clear_value, int stencil_load_action, int stencil_store_action, int stencil_clear_value, flutter::gpu::Texture *texture, int mip_level, int slice)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetDepthWriteEnable(flutter::gpu::RenderPass *wrapper, bool enable)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_ClearBindings(flutter::gpu::RenderPass *wrapper)
FLUTTER_GPU_EXPORT Dart_Handle InternalFlutterGpu_RenderPass_Begin(flutter::gpu::RenderPass *wrapper, flutter::gpu::CommandBuffer *command_buffer)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_BindIndexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int index_type)
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_RenderPass_DrawIndexed(flutter::gpu::RenderPass *wrapper, int index_count, int instance_count)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetCullMode(flutter::gpu::RenderPass *wrapper, int cull_mode)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetStencilReference(flutter::gpu::RenderPass *wrapper, int stencil_reference)
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_RenderPass_BindUniformDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetColorBlendEnable(flutter::gpu::RenderPass *wrapper, int color_attachment_index, bool enable)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetPrimitiveType(flutter::gpu::RenderPass *wrapper, int primitive_type)
FlTexture * texture
double y
@ kNone
Does not use the index buffer.
#define FML_FRIEND_MAKE_REF_COUNTED(T)
std::shared_ptr< ContextGLES > context
std::shared_ptr< PipelineGLES > pipeline
std::shared_ptr< CommandBuffer > command_buffer
int32_t height
int32_t width
Describe the color attachment that will be used with this pipeline.
Definition formats.h:770
Metadata required to bind a buffer.
combines the texture, sampler and sampler slot information.
Definition command.h:59