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 
6 
7 #include <cstdint>
8 
9 #include "flutter/fml/trace_event.h"
10 #include "fml/closure.h"
11 #include "fml/logging.h"
14 #include "impeller/core/formats.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 
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 
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 ///
127 
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) {
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
Sets up stage bindings for single draw call in the OpenGLES backend.
bool BindVertexAttributes(const ProcTableGLES &gl, size_t binding, size_t vertex_offset)
bool UnbindVertexAttributes(const ProcTableGLES &gl)
bool BindUniformData(const ProcTableGLES &gl, const std::vector< TextureAndSampler > &bound_textures, const std::vector< BufferResource > &bound_buffers, Range texture_range, Range buffer_range)
Represents a handle to an underlying OpenGL object. Unlike OpenGL object handles, these handles can b...
Definition: handle_gles.h:37
constexpr bool IsDead() const
Determines if the handle is dead.
Definition: handle_gles.h:53
std::optional< StencilAttachmentDescriptor > GetBackStencilAttachmentDescriptor() const
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
void PushDebugGroup(const std::string &string) const
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:57
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...
HandleGLES CreateUntrackedHandle(HandleType type) const
Create a handle that is not managed by ReactorGLES.
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
const HandleGLES & GetCachedFBO() const
Retrieve the cached FBO object, or a dead handle if there is no object.
void SetCachedFBO(HandleGLES fbo)
bool SetAsFramebufferAttachment(GLenum target, AttachmentType attachment_type) const
std::optional< GLuint > GetFBO() const
bool IsWrapped() const
constexpr bool CanClearAttachment(LoadAction action)
Definition: formats.h:239
float Scalar
Definition: scalar.h:19
constexpr GLenum ToIndexType(IndexType type)
Definition: formats_gles.h:35
constexpr GLenum ToCompareFunction(CompareFunction func)
Definition: formats_gles.h:70
std::string DebugToFramebufferError(int status)
Definition: formats_gles.cc:9
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)
constexpr GLenum ToStencilOp(StencilOperation op)
Definition: formats_gles.h:48
constexpr GLenum ToMode(PrimitiveType primitive_type)
Definition: formats_gles.h:17
WindingOrder
Definition: formats.h:22
void ConfigureBlending(const ProcTableGLES &gl, const ColorAttachmentDescriptor *color)
void ConfigureStencil(const ProcTableGLES &gl, const PipelineDescriptor &pipeline, uint32_t stencil_reference)
static bool BindVertexBuffer(const ProcTableGLES &gl, BufferBindingsGLES *vertex_desc_gles, const BufferView &vertex_buffer_view, size_t buffer_index)
constexpr GLenum ToBlendFactor(BlendFactor factor)
Definition: formats_gles.h:92
constexpr GLenum ToBlendOperation(BlendOperation op)
Definition: formats_gles.h:128
constexpr bool CanDiscardAttachmentWhenDone(StoreAction action)
Definition: formats.h:250
Definition: comparable.h:95
Range GetRange() const
Definition: buffer_view.h:27
const DeviceBuffer * GetBuffer() const
Definition: buffer_view.cc:17
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:518
Scalar blue
Definition: color.h:138
Scalar alpha
Definition: color.h:143
Scalar red
Definition: color.h:128
Scalar green
Definition: color.h:133
size_t offset
Definition: range.h:14
Encapsulates data that will be needed in the reactor for the encoding of commands for this render pas...
std::shared_ptr< Texture > depth_attachment
std::shared_ptr< Texture > color_attachment
std::shared_ptr< Texture > stencil_attachment
std::shared_ptr< Texture > resolve_attachment
StencilOperation depth_stencil_pass
Definition: formats.h:629
Type height
Definition: size.h:29
#define VALIDATION_LOG
Definition: validation.h:91