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
53 bool Begin(flutter::gpu::CommandBuffer& command_buffer);
54
56
57 void ClearBindings();
58
59 bool Draw();
60
65
67 std::unordered_map<const flutter::gpu::Shader::UniformBinding*,
70 std::unordered_map<const flutter::gpu::Shader::TextureBinding*,
72
77
78 // Vertex buffers indexed by binding slot. Mirrors
79 // `impeller::kMaxVertexBuffers`; Impeller's HAL caps vertex buffer
80 // bindings at 16 per draw, and index `i` here corresponds to the binding
81 // declared at slot `i` in the active VertexLayout. On the OpenGL ES
82 // backend the per-pipeline limit on the *total attribute count* across
83 // all bound buffers is `GL_MAX_VERTEX_ATTRIBS` (spec minimum 8 on GLES
84 // 2.0, 16 on GLES 3.0+), enforced by the driver.
85 static constexpr size_t kMaxVertexBufferSlots = 16;
86 std::array<impeller::BufferView, kMaxVertexBufferSlots> vertex_buffers;
87 // Highest slot index that has been bound on this pass (plus one).
91 size_t element_count = 0;
92
93 uint32_t stencil_reference = 0;
94 std::optional<impeller::IRect32> scissor;
95 std::optional<impeller::Viewport> viewport;
96
97 // Helper flag to determine whether the vertex_count should override the
98 // element count. The index count takes precedent.
99 bool has_index_buffer = false;
100
101 private:
102 /// Lookup an Impeller pipeline by building a descriptor based on the current
103 /// command state.
104 std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>>
105 GetOrCreatePipeline();
106
107 impeller::RenderTarget render_target_;
108 std::shared_ptr<impeller::RenderPass> render_pass_;
109
110 // Command encoding state.
111 fml::RefPtr<RenderPipeline> render_pipeline_;
112 impeller::PipelineDescriptor pipeline_descriptor_;
113
114 // Pipeline descriptor layout state. We always keep track of this state,
115 // but we'll only apply it as necessary to match the RenderTarget.
116 std::map<size_t, impeller::ColorAttachmentDescriptor> color_descriptors_;
117 impeller::StencilAttachmentDescriptor stencil_front_desc_;
118 impeller::StencilAttachmentDescriptor stencil_back_desc_;
120
122};
123
124} // namespace gpu
125} // namespace flutter
126
127//----------------------------------------------------------------------------
128/// Exports
129///
130
131extern "C" {
132
134extern void InternalFlutterGpu_RenderPass_Initialize(Dart_Handle wrapper);
135
139 flutter::gpu::Context* context,
140 int color_attachment_index,
141 int load_action,
142 int store_action,
143 float clear_color_r,
144 float clear_color_g,
145 float clear_color_b,
146 float clear_color_a,
148 Dart_Handle resolve_texture_wrapper);
149
153 int depth_load_action,
154 int depth_store_action,
155 float depth_clear_value,
156 int stencil_load_action,
157 int stencil_store_action,
158 int stencil_clear_value,
160
162extern Dart_Handle InternalFlutterGpu_RenderPass_Begin(
164 flutter::gpu::CommandBuffer* command_buffer);
165
170
174 flutter::gpu::DeviceBuffer* device_buffer,
175 int offset_in_bytes,
176 int length_in_bytes,
177 int vertex_count,
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 int index_count);
188
192 flutter::gpu::Shader* shader,
193 Dart_Handle uniform_name_handle,
194 flutter::gpu::DeviceBuffer* device_buffer,
195 int offset_in_bytes,
196 int length_in_bytes);
197
201 flutter::gpu::Shader* shader,
202 Dart_Handle uniform_name_handle,
204 int min_filter,
205 int mag_filter,
206 int mip_filter,
207 int width_address_mode,
208 int height_address_mode);
209
212 flutter::gpu::RenderPass* wrapper);
213
217 int color_attachment_index,
218 bool enable);
219
223 int color_attachment_index,
224 int color_blend_operation,
225 int source_color_blend_factor,
226 int destination_color_blend_factor,
227 int alpha_blend_operation,
228 int source_alpha_blend_factor,
229 int destination_alpha_blend_factor);
230
234 bool enable);
235
239 int compare_operation);
240
244 int stencil_reference);
245
249 int stencil_compare_operation,
250 int stencil_fail_operation,
251 int depth_fail_operation,
252 int depth_stencil_pass_operation,
253 int read_mask,
254 int write_mask,
255 int target);
256
260 int x,
261 int y,
262 int width,
263 int height);
264
268 int x,
269 int y,
270 int width,
271 int height,
272 float z_near,
273 float z_far);
274
278 int cull_mode);
279
283 int primitive_type);
284
288 int winding_order);
289
293 int polygon_mode);
294
297 flutter::gpu::RenderPass* wrapper);
298
299} // extern "C"
300
301#endif // FLUTTER_LIB_GPU_RENDER_PASS_H_
std::optional< impeller::Viewport > viewport
Definition render_pass.h:95
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:68
static constexpr size_t kMaxVertexBufferSlots
Definition render_pass.h:85
impeller::DepthAttachmentDescriptor & GetDepthAttachmentDescriptor()
std::unordered_map< const flutter::gpu::Shader::TextureBinding *, impeller::TextureAndSampler > TextureUniformMap
Definition render_pass.h:71
std::optional< impeller::IRect32 > scissor
Definition render_pass.h:94
TextureUniformMap fragment_texture_bindings
Definition render_pass.h:76
BufferUniformMap fragment_uniform_bindings
Definition render_pass.h:75
TextureUniformMap vertex_texture_bindings
Definition render_pass.h:74
BufferUniformMap vertex_uniform_bindings
Definition render_pass.h:73
impeller::IndexType index_buffer_type
Definition render_pass.h:90
std::array< impeller::BufferView, kMaxVertexBufferSlots > vertex_buffers
Definition render_pass.h:86
impeller::StencilAttachmentDescriptor & GetStencilFrontAttachmentDescriptor()
impeller::ColorAttachmentDescriptor & GetColorAttachmentDescriptor(size_t color_attachment_index)
impeller::PipelineDescriptor & GetPipelineDescriptor()
const std::shared_ptr< const impeller::Context > & GetContext() const
impeller::BufferView index_buffer
Definition render_pass.h:89
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 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_BindVertexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int vertex_count, int slot)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_BindPipeline(flutter::gpu::RenderPass *wrapper, flutter::gpu::RenderPipeline *pipeline)
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_BindIndexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int index_type, int index_count)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetScissor(flutter::gpu::RenderPass *wrapper, int x, int y, int width, int height)
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 bool InternalFlutterGpu_RenderPass_Draw(flutter::gpu::RenderPass *wrapper)
FLUTTER_GPU_EXPORT void InternalFlutterGpu_RenderPass_SetWindingOrder(flutter::gpu::RenderPass *wrapper, int winding_order)
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 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)
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 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)
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)
int32_t height
int32_t width
Describe the color attachment that will be used with this pipeline.
Definition formats.h:522
Metadata required to bind a buffer.
combines the texture, sampler and sampler slot information.
Definition command.h:59