| Flutter Impeller |

render_pass_gles.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
5 #include "impeller/renderer/backend/gles/render_pass_gles.h"
6
7 #include <cstdint>
8
9 #include "flutter/fml/trace_event.h"
10 #include "fml/closure.h"
11 #include "fml/logging.h"
12 #include "impeller/base/validation.h"
13 #include "impeller/core/buffer_view.h"
14 #include "impeller/core/formats.h"
15 #include "impeller/renderer/backend/gles/buffer_bindings_gles.h"
16 #include "impeller/renderer/backend/gles/context_gles.h"
17 #include "impeller/renderer/backend/gles/device_buffer_gles.h"
18 #include "impeller/renderer/backend/gles/formats_gles.h"
19 #include "impeller/renderer/backend/gles/gpu_tracer_gles.h"
20 #include "impeller/renderer/backend/gles/pipeline_gles.h"
21 #include "impeller/renderer/backend/gles/texture_gles.h"
22 #include "impeller/renderer/command.h"
23
24 namespace impeller {
25
26 RenderPassGLES::RenderPassGLES(std::shared_ptr<const Context> context,
27 const RenderTarget& target,
28 std::shared_ptr<ReactorGLES> reactor)
29 : RenderPass(std::move(context), target),
30 reactor_(std::move(reactor)),
31 is_valid_(reactor_ && reactor_->IsValid()) {}
32
33 // |RenderPass|
34 RenderPassGLES::~RenderPassGLES() = default;
35
36 // |RenderPass|
37 bool RenderPassGLES::IsValid() const {
38 return is_valid_;
39 }
40
41 // |RenderPass|
42 void RenderPassGLES::OnSetLabel(std::string_view label) {
43 label_ = label;
44 }
45
46 void ConfigureBlending(const ProcTableGLES& gl,
47 const ColorAttachmentDescriptor* color) {
48 if (color->blending_enabled) {
49 gl.Enable(GL_BLEND);
50 gl.BlendFuncSeparate(
51 ToBlendFactor(color->src_color_blend_factor), // src color
52 ToBlendFactor(color->dst_color_blend_factor), // dst color
53 ToBlendFactor(color->src_alpha_blend_factor), // src alpha
54 ToBlendFactor(color->dst_alpha_blend_factor) // dst alpha
55 );
56 gl.BlendEquationSeparate(
57 ToBlendOperation(color->color_blend_op), // mode color
58 ToBlendOperation(color->alpha_blend_op) // mode alpha
59 );
60 } else {
61 gl.Disable(GL_BLEND);
62 }
63
64 {
65 const auto is_set = [](ColorWriteMask mask,
66 ColorWriteMask check) -> GLboolean {
67 return (mask & check) ? GL_TRUE : GL_FALSE;
68 };
69
70 gl.ColorMask(
71 is_set(color->write_mask, ColorWriteMaskBits::kRed), // red
72 is_set(color->write_mask, ColorWriteMaskBits::kGreen), // green
73 is_set(color->write_mask, ColorWriteMaskBits::kBlue), // blue
74 is_set(color->write_mask, ColorWriteMaskBits::kAlpha) // alpha
75 );
76 }
77 }
78
79 void ConfigureStencil(GLenum face,
80 const ProcTableGLES& gl,
81 const StencilAttachmentDescriptor& stencil,
82 uint32_t stencil_reference) {
83 gl.StencilOpSeparate(
84 face, // face
85 ToStencilOp(stencil.stencil_failure), // stencil fail
86 ToStencilOp(stencil.depth_failure), // depth fail
87 ToStencilOp(stencil.depth_stencil_pass) // depth stencil pass
88 );
89 gl.StencilFuncSeparate(face, // face
90 ToCompareFunction(stencil.stencil_compare), // func
91 stencil_reference, // ref
92 stencil.read_mask // mask
93 );
94 gl.StencilMaskSeparate(face, stencil.write_mask);
95 }
96
97 void ConfigureStencil(const ProcTableGLES& gl,
98 const PipelineDescriptor& pipeline,
99 uint32_t stencil_reference) {
100 if (!pipeline.HasStencilAttachmentDescriptors()) {
101 gl.Disable(GL_STENCIL_TEST);
102 return;
103 }
104
105 gl.Enable(GL_STENCIL_TEST);
106 const auto& front = pipeline.GetFrontStencilAttachmentDescriptor();
107 const auto& back = pipeline.GetBackStencilAttachmentDescriptor();
108
109 if (front.has_value() && back.has_value() && front == back) {
110 ConfigureStencil(GL_FRONT_AND_BACK, gl, *front, stencil_reference);
111 return;
112 }
113 if (front.has_value()) {
114 ConfigureStencil(GL_FRONT, gl, *front, stencil_reference);
115 }
116 if (back.has_value()) {
117 ConfigureStencil(GL_BACK, gl, *back, stencil_reference);
118 }
119 }
120
121 //------------------------------------------------------------------------------
122 /// @brief Encapsulates data that will be needed in the reactor for the
123 /// encoding of commands for this render pass.
124 ///
125 struct RenderPassData {
126 Viewport viewport;
127
128 Color clear_color;
129 uint32_t clear_stencil = 0u;
130 Scalar clear_depth = 1.0;
131
132 std::shared_ptr<Texture> color_attachment;
133 std::shared_ptr<Texture> resolve_attachment;
134 std::shared_ptr<Texture> depth_attachment;
135 std::shared_ptr<Texture> stencil_attachment;
136
137 bool clear_color_attachment = true;
138 bool clear_depth_attachment = true;
139 bool clear_stencil_attachment = true;
140
141 bool discard_color_attachment = true;
142 bool discard_depth_attachment = true;
143 bool discard_stencil_attachment = true;
144
145 std::string label;
146 };
147
148 static bool BindVertexBuffer(const ProcTableGLES& gl,
149 BufferBindingsGLES* vertex_desc_gles,
150 const BufferView& vertex_buffer_view,
151 size_t buffer_index) {
152 if (!vertex_buffer_view) {
153 return false;
154 }
155
156 const DeviceBuffer* vertex_buffer = vertex_buffer_view.GetBuffer();
157
158 if (!vertex_buffer) {
159 return false;
160 }
161
162 const auto& vertex_buffer_gles = DeviceBufferGLES::Cast(*vertex_buffer);
163 if (!vertex_buffer_gles.BindAndUploadDataIfNecessary(
164 DeviceBufferGLES::BindingType::kArrayBuffer)) {
165 return false;
166 }
167
168 //--------------------------------------------------------------------------
169 /// Bind the vertex attributes associated with vertex buffer.
170 ///
171 if (!vertex_desc_gles->BindVertexAttributes(
172 gl, buffer_index, vertex_buffer_view.GetRange().offset)) {
173 return false;
174 }
175
176 return true;
177 }
178
179 void RenderPassGLES::ResetGLState(const ProcTableGLES& gl) {
180 gl.Disable(GL_SCISSOR_TEST);
181 gl.Disable(GL_DEPTH_TEST);
182 gl.Disable(GL_STENCIL_TEST);
183 gl.Disable(GL_CULL_FACE);
184 gl.Disable(GL_BLEND);
185 gl.Disable(GL_DITHER);
186 gl.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
187 gl.DepthMask(GL_TRUE);
188 gl.StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF);
189 gl.StencilMaskSeparate(GL_BACK, 0xFFFFFFFF);
190 }
191
192 [[nodiscard]] bool EncodeCommandsInReactor(
193 const RenderPassData& pass_data,
194 const ReactorGLES& reactor,
195 const std::vector<Command>& commands,
196 const std::vector<BufferView>& vertex_buffers,
197 const std::vector<TextureAndSampler>& bound_textures,
198 const std::vector<BufferResource>& bound_buffers,
199 const std::shared_ptr<GPUTracerGLES>& tracer) {
200 TRACE_EVENT0("impeller", "RenderPassGLES::EncodeCommandsInReactor");
201
202 const auto& gl = reactor.GetProcTable();
203 #ifdef IMPELLER_DEBUG
204 tracer->MarkFrameStart(gl);
205
206 fml::ScopedCleanupClosure pop_pass_debug_marker(
207 [&gl]() { gl.PopDebugGroup(); });
208 if (!pass_data.label.empty()) {
209 gl.PushDebugGroup(pass_data.label);
210 } else {
211 pop_pass_debug_marker.Release();
212 }
213 #endif // IMPELLER_DEBUG
214
215 TextureGLES& color_gles = TextureGLES::Cast(*pass_data.color_attachment);
216 const bool is_default_fbo = color_gles.IsWrapped();
217
218 std::optional<GLuint> fbo = 0;
219 if (is_default_fbo) {
220 if (color_gles.GetFBO().has_value()) {
221 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
222 gl.BindFramebuffer(GL_FRAMEBUFFER, *color_gles.GetFBO());
223 }
224 } else {
225 // Create and bind an offscreen FBO.
226 if (!color_gles.GetCachedFBO().IsDead()) {
227 fbo = reactor.GetGLHandle(color_gles.GetCachedFBO());
228 if (!fbo.has_value()) {
229 return false;
230 }
231 gl.BindFramebuffer(GL_FRAMEBUFFER, fbo.value());
232 } else {
233 HandleGLES cached_fbo =
234 reactor.CreateUntrackedHandle(HandleType::kFrameBuffer);
235 color_gles.SetCachedFBO(cached_fbo);
236 fbo = reactor.GetGLHandle(cached_fbo);
237 if (!fbo.has_value()) {
238 return false;
239 }
240 gl.BindFramebuffer(GL_FRAMEBUFFER, fbo.value());
241
242 if (!color_gles.SetAsFramebufferAttachment(
243 GL_FRAMEBUFFER, TextureGLES::AttachmentType::kColor0)) {
244 return false;
245 }
246
247 if (auto depth = TextureGLES::Cast(pass_data.depth_attachment.get())) {
248 if (!depth->SetAsFramebufferAttachment(
249 GL_FRAMEBUFFER, TextureGLES::AttachmentType::kDepth)) {
250 return false;
251 }
252 }
253 if (auto stencil =
254 TextureGLES::Cast(pass_data.stencil_attachment.get())) {
255 if (!stencil->SetAsFramebufferAttachment(
256 GL_FRAMEBUFFER, TextureGLES::AttachmentType::kStencil)) {
257 return false;
258 }
259 }
260
261 auto status = gl.CheckFramebufferStatus(GL_FRAMEBUFFER);
262 if (status != GL_FRAMEBUFFER_COMPLETE) {
263 VALIDATION_LOG << "Could not create a complete framebuffer: "
264 << DebugToFramebufferError(status);
265 return false;
266 }
267 }
268 }
269
270 gl.ClearColor(pass_data.clear_color.red, // red
271 pass_data.clear_color.green, // green
272 pass_data.clear_color.blue, // blue
273 pass_data.clear_color.alpha // alpha
274 );
275 if (pass_data.depth_attachment) {
276 if (gl.DepthRangef.IsAvailable()) {
277 gl.ClearDepthf(pass_data.clear_depth);
278 } else {
279 gl.ClearDepth(pass_data.clear_depth);
280 }
281 }
282 if (pass_data.stencil_attachment) {
283 gl.ClearStencil(pass_data.clear_stencil);
284 }
285
286 GLenum clear_bits = 0u;
287 if (pass_data.clear_color_attachment) {
288 clear_bits |= GL_COLOR_BUFFER_BIT;
289 }
290 if (pass_data.clear_depth_attachment) {
291 clear_bits |= GL_DEPTH_BUFFER_BIT;
292 }
293 if (pass_data.clear_stencil_attachment) {
294 clear_bits |= GL_STENCIL_BUFFER_BIT;
295 }
296
297 RenderPassGLES::ResetGLState(gl);
298
299 gl.Clear(clear_bits);
300
301 // Both the viewport and scissor are specified in framebuffer coordinates.
302 // Impeller's framebuffer coordinate system is top left origin, but OpenGL's
303 // is bottom left origin, so we convert the coordinates here.
304 ISize target_size = pass_data.color_attachment->GetSize();
305
306 //--------------------------------------------------------------------------
307 /// Setup the viewport.
308 ///
309 const auto& viewport = pass_data.viewport;
310 gl.Viewport(viewport.rect.GetX(), // x
311 target_size.height - viewport.rect.GetY() -
312 viewport.rect.GetHeight(), // y
313 viewport.rect.GetWidth(), // width
314 viewport.rect.GetHeight() // height
315 );
316 if (pass_data.depth_attachment) {
317 if (gl.DepthRangef.IsAvailable()) {
318 gl.DepthRangef(viewport.depth_range.z_near, viewport.depth_range.z_far);
319 } else {
320 gl.DepthRange(viewport.depth_range.z_near, viewport.depth_range.z_far);
321 }
322 }
323
324 CullMode current_cull_mode = CullMode::kNone;
325 WindingOrder current_winding_order = WindingOrder::kClockwise;
326 gl.FrontFace(GL_CW);
327
328 for (const auto& command : commands) {
329 #ifdef IMPELLER_DEBUG
330 fml::ScopedCleanupClosure pop_cmd_debug_marker(
331 [&gl]() { gl.PopDebugGroup(); });
332 if (!command.label.empty()) {
333 gl.PushDebugGroup(command.label);
334 } else {
335 pop_cmd_debug_marker.Release();
336 }
337 #endif // IMPELLER_DEBUG
338
339 const auto& pipeline = PipelineGLES::Cast(*command.pipeline);
340
341 const auto* color_attachment =
342 pipeline.GetDescriptor().GetLegacyCompatibleColorAttachment();
343 if (!color_attachment) {
344 VALIDATION_LOG
345 << "Color attachment is too complicated for a legacy renderer.";
346 return false;
347 }
348
349 //--------------------------------------------------------------------------
350 /// Configure blending.
351 ///
352 ConfigureBlending(gl, color_attachment);
353
354 //--------------------------------------------------------------------------
355 /// Setup stencil.
356 ///
357 ConfigureStencil(gl, pipeline.GetDescriptor(), command.stencil_reference);
358
359 //--------------------------------------------------------------------------
360 /// Configure depth.
361 ///
362 if (auto depth =
363 pipeline.GetDescriptor().GetDepthStencilAttachmentDescriptor();
364 depth.has_value()) {
365 gl.Enable(GL_DEPTH_TEST);
366 gl.DepthFunc(ToCompareFunction(depth->depth_compare));
367 gl.DepthMask(depth->depth_write_enabled ? GL_TRUE : GL_FALSE);
368 } else {
369 gl.Disable(GL_DEPTH_TEST);
370 }
371
372 //--------------------------------------------------------------------------
373 /// Setup the viewport.
374 ///
375 if (command.viewport.has_value()) {
376 gl.Viewport(viewport.rect.GetX(), // x
377 target_size.height - viewport.rect.GetY() -
378 viewport.rect.GetHeight(), // y
379 viewport.rect.GetWidth(), // width
380 viewport.rect.GetHeight() // height
381 );
382 if (pass_data.depth_attachment) {
383 if (gl.DepthRangef.IsAvailable()) {
384 gl.DepthRangef(viewport.depth_range.z_near,
385 viewport.depth_range.z_far);
386 } else {
387 gl.DepthRange(viewport.depth_range.z_near,
388 viewport.depth_range.z_far);
389 }
390 }
391 }
392
393 //--------------------------------------------------------------------------
394 /// Setup the scissor rect.
395 ///
396 if (command.scissor.has_value()) {
397 const auto& scissor = command.scissor.value();
398 gl.Enable(GL_SCISSOR_TEST);
399 gl.Scissor(
400 scissor.GetX(), // x
401 target_size.height - scissor.GetY() - scissor.GetHeight(), // y
402 scissor.GetWidth(), // width
403 scissor.GetHeight() // height
404 );
405 }
406
407 //--------------------------------------------------------------------------
408 /// Setup culling.
409 ///
410 CullMode pipeline_cull_mode = pipeline.GetDescriptor().GetCullMode();
411 if (current_cull_mode != pipeline_cull_mode) {
412 switch (pipeline_cull_mode) {
413 case CullMode::kNone:
414 gl.Disable(GL_CULL_FACE);
415 break;
416 case CullMode::kFrontFace:
417 gl.Enable(GL_CULL_FACE);
418 gl.CullFace(GL_FRONT);
419 break;
420 case CullMode::kBackFace:
421 gl.Enable(GL_CULL_FACE);
422 gl.CullFace(GL_BACK);
423 break;
424 }
425 current_cull_mode = pipeline_cull_mode;
426 }
427
428 //--------------------------------------------------------------------------
429 /// Setup winding order.
430 ///
431 WindingOrder pipeline_winding_order =
432 pipeline.GetDescriptor().GetWindingOrder();
433 if (current_winding_order != pipeline_winding_order) {
434 switch (pipeline.GetDescriptor().GetWindingOrder()) {
435 case WindingOrder::kClockwise:
436 gl.FrontFace(GL_CW);
437 break;
438 case WindingOrder::kCounterClockwise:
439 gl.FrontFace(GL_CCW);
440 break;
441 }
442 current_winding_order = pipeline_winding_order;
443 }
444
445 BufferBindingsGLES* vertex_desc_gles = pipeline.GetBufferBindings();
446
447 //--------------------------------------------------------------------------
448 /// Bind vertex buffers.
449 ///
450 /// Note: There is no need to run `RenderPass::ValidateVertexBuffers` or
451 /// `RenderPass::ValidateIndexBuffer` here, as validation already runs
452 /// when the vertex/index buffers are set on the command.
453 ///
454 for (size_t i = 0; i < command.vertex_buffers.length; i++) {
455 if (!BindVertexBuffer(gl, vertex_desc_gles,
456 vertex_buffers[i + command.vertex_buffers.offset],
457 i)) {
458 return false;
459 }
460 }
461
462 //--------------------------------------------------------------------------
463 /// Bind the pipeline program.
464 ///
465 if (!pipeline.BindProgram()) {
466 return false;
467 }
468
469 //--------------------------------------------------------------------------
470 /// Bind uniform data.
471 ///
472 if (!vertex_desc_gles->BindUniformData(
473 gl, //
474 bound_textures, //
475 bound_buffers, //
476 /*texture_range=*/command.bound_textures, //
477 /*buffer_range=*/command.bound_buffers //
478 )) {
479 return false;
480 }
481
482 //--------------------------------------------------------------------------
483 /// Determine the primitive type.
484 ///
485 // GLES doesn't support setting the fill mode, so override the primitive
486 // with GL_LINE_STRIP to somewhat emulate PolygonMode::kLine. This isn't
487 // correct; full triangle outlines won't be drawn and disconnected
488 // geometry may appear connected. However this can still be useful for
489 // wireframe debug views.
490 GLenum mode =
491 pipeline.GetDescriptor().GetPolygonMode() == PolygonMode::kLine
492 ? GL_LINE_STRIP
493 : ToMode(pipeline.GetDescriptor().GetPrimitiveType());
494
495 //--------------------------------------------------------------------------
496 /// Finally! Invoke the draw call.
497 ///
498 if (command.index_type == IndexType::kNone) {
499 gl.DrawArrays(mode, command.base_vertex, command.element_count);
500 } else {
501 // Bind the index buffer if necessary.
502 auto index_buffer_view = command.index_buffer;
503 const DeviceBuffer* index_buffer = index_buffer_view.GetBuffer();
504 const auto& index_buffer_gles = DeviceBufferGLES::Cast(*index_buffer);
505 if (!index_buffer_gles.BindAndUploadDataIfNecessary(
506 DeviceBufferGLES::BindingType::kElementArrayBuffer)) {
507 return false;
508 }
509 gl.DrawElements(mode, // mode
510 command.element_count, // count
511 ToIndexType(command.index_type), // type
512 reinterpret_cast<const GLvoid*>(static_cast<GLsizei>(
513 index_buffer_view.GetRange().offset)) // indices
514 );
515 }
516
517 //--------------------------------------------------------------------------
518 /// Unbind vertex attribs.
519 ///
520 if (!vertex_desc_gles->UnbindVertexAttributes(gl)) {
521 return false;
522 }
523 }
524
525 if (pass_data.resolve_attachment &&
526 !gl.GetCapabilities()->SupportsImplicitResolvingMSAA() &&
527 !is_default_fbo) {
528 FML_DCHECK(pass_data.resolve_attachment != pass_data.color_attachment);
529 // Perform multisample resolve via blit.
530 // Create and bind a resolve FBO.
531 GLuint resolve_fbo;
532 gl.GenFramebuffers(1u, &resolve_fbo);
533 gl.BindFramebuffer(GL_FRAMEBUFFER, resolve_fbo);
534
535 if (!TextureGLES::Cast(*pass_data.resolve_attachment)
536 .SetAsFramebufferAttachment(
537 GL_FRAMEBUFFER, TextureGLES::AttachmentType::kColor0)) {
538 return false;
539 }
540
541 auto status = gl.CheckFramebufferStatus(GL_FRAMEBUFFER);
542 if (gl.CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
543 VALIDATION_LOG << "Could not create a complete frambuffer: "
544 << DebugToFramebufferError(status);
545 return false;
546 }
547
548 // Bind MSAA renderbuffer to read framebuffer.
549 gl.BindFramebuffer(GL_READ_FRAMEBUFFER, fbo.value());
550 gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo);
551
552 RenderPassGLES::ResetGLState(gl);
553 auto size = pass_data.color_attachment->GetSize();
554
555 gl.BlitFramebuffer(/*srcX0=*/0,
556 /*srcY0=*/0,
557 /*srcX1=*/size.width,
558 /*srcY1=*/size.height,
559 /*dstX0=*/0,
560 /*dstY0=*/0,
561 /*dstX1=*/size.width,
562 /*dstY1=*/size.height,
563 /*mask=*/GL_COLOR_BUFFER_BIT,
564 /*filter=*/GL_NEAREST);
565
566 gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, GL_NONE);
567 gl.BindFramebuffer(GL_READ_FRAMEBUFFER, GL_NONE);
568 gl.DeleteFramebuffers(1u, &resolve_fbo);
569 // Rebind the original FBO so that we can discard it below.
570 gl.BindFramebuffer(GL_FRAMEBUFFER, fbo.value());
571 }
572
573 if (gl.DiscardFramebufferEXT.IsAvailable()) {
574 std::array<GLenum, 3> attachments;
575 size_t attachment_count = 0;
576
577 // TODO(130048): discarding stencil or depth on the default fbo causes Angle
578 // to discard the entire render target. Until we know the reason, default to
579 // storing.
580 bool angle_safe = gl.GetCapabilities()->IsANGLE() ? !is_default_fbo : true;
581
582 if (pass_data.discard_color_attachment) {
583 attachments[attachment_count++] =
584 (is_default_fbo ? GL_COLOR_EXT : GL_COLOR_ATTACHMENT0);
585 }
586 if (pass_data.discard_depth_attachment && angle_safe) {
587 attachments[attachment_count++] =
588 (is_default_fbo ? GL_DEPTH_EXT : GL_DEPTH_ATTACHMENT);
589 }
590
591 if (pass_data.discard_stencil_attachment && angle_safe) {
592 attachments[attachment_count++] =
593 (is_default_fbo ? GL_STENCIL_EXT : GL_STENCIL_ATTACHMENT);
594 }
595 gl.DiscardFramebufferEXT(GL_FRAMEBUFFER, // target
596 attachment_count, // attachments to discard
597 attachments.data() // size
598 );
599 }
600
601 #ifdef IMPELLER_DEBUG
602 if (is_default_fbo) {
603 tracer->MarkFrameEnd(gl);
604 }
605 #endif // IMPELLER_DEBUG
606
607 return true;
608 }
609
610 // |RenderPass|
611 bool RenderPassGLES::OnEncodeCommands(const Context& context) const {
612 if (!IsValid()) {
613 return false;
614 }
615 const auto& render_target = GetRenderTarget();
616 if (!render_target.HasColorAttachment(0u)) {
617 return false;
618 }
619 const ColorAttachment& color0 = render_target.GetColorAttachment(0);
620 const std::optional<DepthAttachment>& depth0 =
621 render_target.GetDepthAttachment();
622 const std::optional<StencilAttachment>& stencil0 =
623 render_target.GetStencilAttachment();
624
625 auto pass_data = std::make_shared<RenderPassData>();
626 pass_data->label = label_;
627 pass_data->viewport.rect = Rect::MakeSize(GetRenderTargetSize());
628
629 //----------------------------------------------------------------------------
630 /// Setup color data.
631 ///
632 pass_data->color_attachment = color0.texture;
633 pass_data->resolve_attachment = color0.resolve_texture;
634 pass_data->clear_color = color0.clear_color;
635 pass_data->clear_color_attachment = CanClearAttachment(color0.load_action);
636 pass_data->discard_color_attachment =
637 CanDiscardAttachmentWhenDone(color0.store_action);
638
639 // When we are using EXT_multisampled_render_to_texture, it is implicitly
640 // resolved when we bind the texture to the framebuffer. We don't need to
641 // discard the attachment when we are done. If not using
642 // EXT_multisampled_render_to_texture but still using MSAA we discard the
643 // attachment as normal.
644 if (color0.resolve_texture) {
645 pass_data->discard_color_attachment =
646 pass_data->discard_color_attachment &&
647 !context.GetCapabilities()->SupportsImplicitResolvingMSAA();
648 }
649
650 //----------------------------------------------------------------------------
651 /// Setup depth data.
652 ///
653 if (depth0.has_value()) {
654 pass_data->depth_attachment = depth0->texture;
655 pass_data->clear_depth = depth0->clear_depth;
656 pass_data->clear_depth_attachment = CanClearAttachment(depth0->load_action);
657 pass_data->discard_depth_attachment =
658 CanDiscardAttachmentWhenDone(depth0->store_action);
659 }
660
661 //----------------------------------------------------------------------------
662 /// Setup stencil data.
663 ///
664 if (stencil0.has_value()) {
665 pass_data->stencil_attachment = stencil0->texture;
666 pass_data->clear_stencil = stencil0->clear_stencil;
667 pass_data->clear_stencil_attachment =
668 CanClearAttachment(stencil0->load_action);
669 pass_data->discard_stencil_attachment =
670 CanDiscardAttachmentWhenDone(stencil0->store_action);
671 }
672
673 return reactor_->AddOperation(
674 [pass_data = std::move(pass_data), render_pass = shared_from_this(),
675 tracer =
676 ContextGLES::Cast(context).GetGPUTracer()](const auto& reactor) {
677 auto result = EncodeCommandsInReactor(
678 /*pass_data=*/*pass_data, //
679 /*reactor=*/reactor, //
680 /*commands=*/render_pass->commands_, //
681 /*vertex_buffers=*/render_pass->vertex_buffers_, //
682 /*bound_textures=*/render_pass->bound_textures_, //
683 /*bound_buffers=*/render_pass->bound_buffers_, //
684 /*tracer=*/tracer //
685 );
686 FML_CHECK(result)
687 << "Must be able to encode GL commands without error.";
688 },
689 /*defer=*/true);
690 }
691
692 } // namespace impeller
buffer_bindings_gles.h
buffer_view.h
impeller::BufferBindingsGLES
Sets up stage bindings for single draw call in the OpenGLES backend.
Definition: buffer_bindings_gles.h:28
impeller::BufferBindingsGLES::BindVertexAttributes
bool BindVertexAttributes(const ProcTableGLES &gl, size_t binding, size_t vertex_offset)
Definition: buffer_bindings_gles.cc:194
impeller::BufferBindingsGLES::UnbindVertexAttributes
bool UnbindVertexAttributes(const ProcTableGLES &gl)
Definition: buffer_bindings_gles.cc:247
impeller::BufferBindingsGLES::BindUniformData
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
Definition: buffer_bindings_gles.cc:222
impeller::DeviceBuffer
Definition: device_buffer.h:18
impeller::HandleGLES
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition: handle_gles.h:37
impeller::HandleGLES::IsDead
constexpr bool IsDead() const
Determines if the handle is dead.
Definition: handle_gles.h:53
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::PipelineDescriptor::GetBackStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetBackStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:243
impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:202
impeller::PipelineDescriptor::HasStencilAttachmentDescriptors
bool HasStencilAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:247
impeller::ProcTableGLES
Definition: proc_table_gles.h:282
impeller::ProcTableGLES::PushDebugGroup
void PushDebugGroup(const std::string &string) const
Definition: proc_table_gles.cc:398
impeller::ReactorGLES
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:57
impeller::ReactorGLES::GetGLHandle
std::optional< GLuint > GetGLHandle(const HandleGLES &handle) const
Returns the OpenGL handle for a reactor handle if one is available. This is typically only safe to ca...
Definition: reactor_gles.cc:151
impeller::ReactorGLES::CreateUntrackedHandle
HandleGLES CreateUntrackedHandle(HandleType type) const
Create a handle that is not managed by ReactorGLES.
Definition: reactor_gles.cc:203
impeller::ReactorGLES::GetProcTable
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
Definition: reactor_gles.cc:122
impeller::TextureGLES
Definition: texture_gles.h:19
impeller::TextureGLES::GetCachedFBO
const HandleGLES & GetCachedFBO() const
Retrieve the cached FBO object, or a dead handle if there is no object.
Definition: texture_gles.cc:692
impeller::TextureGLES::SetCachedFBO
void SetCachedFBO(HandleGLES fbo)
Definition: texture_gles.cc:688
impeller::TextureGLES::SetAsFramebufferAttachment
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
Definition: texture_gles.cc:613
impeller::TextureGLES::GetFBO
std::optional< GLuint > GetFBO() const
Definition: texture_gles.cc:674
impeller::TextureGLES::IsWrapped
bool IsWrapped() const
Definition: texture_gles.cc:670
command.h
formats.h
device_buffer_gles.h
formats_gles.h
gpu_tracer_gles.h
impeller
Definition: allocation.cc:12
impeller::CanClearAttachment
constexpr bool CanClearAttachment(LoadAction action)
Definition: formats.h:239
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::ToIndexType
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:35
impeller::ToCompareFunction
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:70
impeller::DebugToFramebufferError
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
impeller::CullMode
CullMode
Definition: formats.h:337
impeller::EncodeCommandsInReactor
bool EncodeCommandsInReactor(const RenderPassData &pass_data, const ReactorGLES &reactor, const std::vector< Command > &commands, const std::vector< BufferView > &vertex_buffers, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, const std::shared_ptr< GPUTracerGLES > &tracer)
Definition: render_pass_gles.cc:192
impeller::ToStencilOp
constexpr GLenum ToStencilOp(StencilOperation op)
Definition: formats_gles.h:48
impeller::ToMode
constexpr GLenum ToMode(PrimitiveType primitive_type)
Definition: formats_gles.h:17
impeller::WindingOrder
WindingOrder
Definition: formats.h:22
impeller::ConfigureBlending
void ConfigureBlending(const ProcTableGLES &gl, const ColorAttachmentDescriptor *color)
Definition: render_pass_gles.cc:46
impeller::ConfigureStencil
void ConfigureStencil(const ProcTableGLES &gl, const PipelineDescriptor &pipeline, uint32_t stencil_reference)
Definition: render_pass_gles.cc:97
impeller::BindVertexBuffer
static bool BindVertexBuffer(const ProcTableGLES &gl, BufferBindingsGLES *vertex_desc_gles, const BufferView &vertex_buffer_view, size_t buffer_index)
Definition: render_pass_gles.cc:148
impeller::ToBlendFactor
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:92
impeller::ToBlendOperation
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:128
impeller::CanDiscardAttachmentWhenDone
constexpr bool CanDiscardAttachmentWhenDone(StoreAction action)
Definition: formats.h:250
std
Definition: comparable.h:95
pipeline_gles.h
render_pass_gles.h
context_gles.h
impeller::BufferView
Definition: buffer_view.h:19
impeller::BufferView::GetRange
Range GetRange() const
Definition: buffer_view.h:27
impeller::BufferView::GetBuffer
const DeviceBuffer * GetBuffer() const
Definition: buffer_view.cc:17
impeller::ColorAttachmentDescriptor
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:518
impeller::ColorAttachmentDescriptor::blending_enabled
bool blending_enabled
Definition: formats.h:520
impeller::ColorAttachmentDescriptor::color_blend_op
BlendOperation color_blend_op
Definition: formats.h:523
impeller::ColorAttachmentDescriptor::dst_color_blend_factor
BlendFactor dst_color_blend_factor
Definition: formats.h:524
impeller::ColorAttachmentDescriptor::write_mask
ColorWriteMask write_mask
Definition: formats.h:530
impeller::ColorAttachmentDescriptor::src_alpha_blend_factor
BlendFactor src_alpha_blend_factor
Definition: formats.h:526
impeller::ColorAttachmentDescriptor::alpha_blend_op
BlendOperation alpha_blend_op
Definition: formats.h:527
impeller::ColorAttachmentDescriptor::src_color_blend_factor
BlendFactor src_color_blend_factor
Definition: formats.h:522
impeller::ColorAttachmentDescriptor::dst_alpha_blend_factor
BlendFactor dst_alpha_blend_factor
Definition: formats.h:528
impeller::Color
Definition: color.h:124
impeller::Color::blue
Scalar blue
Definition: color.h:138
impeller::Color::alpha
Scalar alpha
Definition: color.h:143
impeller::Color::red
Scalar red
Definition: color.h:128
impeller::Color::green
Scalar green
Definition: color.h:133
impeller::Mask< ColorWriteMaskBits >
impeller::Range::offset
size_t offset
Definition: range.h:14
impeller::RenderPassData
Encapsulates data that will be needed in the reactor for the encoding of commands for this render pas...
Definition: render_pass_gles.cc:125
impeller::RenderPassData::clear_color_attachment
bool clear_color_attachment
Definition: render_pass_gles.cc:137
impeller::RenderPassData::clear_depth
Scalar clear_depth
Definition: render_pass_gles.cc:130
impeller::RenderPassData::viewport
Viewport viewport
Definition: render_pass_gles.cc:126
impeller::RenderPassData::depth_attachment
std::shared_ptr< Texture > depth_attachment
Definition: render_pass_gles.cc:134
impeller::RenderPassData::label
std::string label
Definition: render_pass_gles.cc:145
impeller::RenderPassData::discard_color_attachment
bool discard_color_attachment
Definition: render_pass_gles.cc:141
impeller::RenderPassData::clear_color
Color clear_color
Definition: render_pass_gles.cc:128
impeller::RenderPassData::clear_stencil_attachment
bool clear_stencil_attachment
Definition: render_pass_gles.cc:139
impeller::RenderPassData::color_attachment
std::shared_ptr< Texture > color_attachment
Definition: render_pass_gles.cc:132
impeller::RenderPassData::discard_depth_attachment
bool discard_depth_attachment
Definition: render_pass_gles.cc:142
impeller::RenderPassData::stencil_attachment
std::shared_ptr< Texture > stencil_attachment
Definition: render_pass_gles.cc:135
impeller::RenderPassData::discard_stencil_attachment
bool discard_stencil_attachment
Definition: render_pass_gles.cc:143
impeller::RenderPassData::clear_stencil
uint32_t clear_stencil
Definition: render_pass_gles.cc:129
impeller::RenderPassData::resolve_attachment
std::shared_ptr< Texture > resolve_attachment
Definition: render_pass_gles.cc:133
impeller::RenderPassData::clear_depth_attachment
bool clear_depth_attachment
Definition: render_pass_gles.cc:138
impeller::StencilAttachmentDescriptor
Definition: formats.h:610
impeller::StencilAttachmentDescriptor::stencil_failure
StencilOperation stencil_failure
Definition: formats.h:620
impeller::StencilAttachmentDescriptor::write_mask
uint32_t write_mask
Definition: formats.h:640
impeller::StencilAttachmentDescriptor::stencil_compare
CompareFunction stencil_compare
Definition: formats.h:616
impeller::StencilAttachmentDescriptor::depth_failure
StencilOperation depth_failure
Definition: formats.h:625
impeller::StencilAttachmentDescriptor::depth_stencil_pass
StencilOperation depth_stencil_pass
Definition: formats.h:629
impeller::StencilAttachmentDescriptor::read_mask
uint32_t read_mask
Definition: formats.h:635
impeller::TSize
Definition: size.h:25
impeller::TSize::height
Type height
Definition: size.h:29
impeller::Viewport
Definition: formats.h:403
texture_gles.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91