Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Document how to do basic rendering in Impeller. #52703

Merged
merged 5 commits into from
May 10, 2024

Conversation

chinmaygarde
Copy link
Member

@chinmaygarde chinmaygarde commented May 9, 2024

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Let's create the data we will be giving our draw call. Remember, our vertex shader is a bit of slacker and doesn't do anything to the vertex information to convert it to normalized device coordinates. So we need to make sure the information is already in [normalized device coordinate](coordinate_system.md).

```c++
VertexBufferBuilder<VS::PerVertexData> vertex_buffer_builder;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly this class is definitely on my list of abstractions to remove. I was thinking about some kind of either template or list initalization that would avoid the secondary std::vec allocation.

No action needed, just a note for me to update the doc if I do that.


Unlike `malloc` buffers that can be resized via `realloc`, device buffers cannot be resized in Impeller. Also, it is bad form to create many small device buffers. For this reason, Impeller prefers to stage all data (uniform, vertex, or otherwise) into one large allocation. Then at draw time, each draw call references information at a specific offset and length into that larger allocation.

An easy to way to achieve this scheme is to use a `HostBuffer`. A host buffer is a buffer allocated on the heap (using `malloc` or similar) whose main usage is to grow as quickly as possible. Impeller stages all data for the frame in such a buffer. As the buffer is being constructed, views (offset and length) into this buffer are noted in the command stream. Just before the draw call is submitted, this information is uploaded to the GPU at which time with buffers being reused if necessary.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primarily this uses the driver's allocator, VMA, Metal allocator, or malloc on GLSL where there is no allocation API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was hand wavy about the implementation details since they're so different and we keep tinkering on them anyway.

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
@chinmaygarde chinmaygarde added the autosubmit Merge PR when tree becomes green via auto submit App label May 10, 2024
@chinmaygarde
Copy link
Member Author

autosub bot is down. Landing manually flutter/flutter#148092

@chinmaygarde chinmaygarde merged commit 6973af6 into flutter:main May 10, 2024
21 of 29 checks passed
@chinmaygarde chinmaygarde deleted the babys_first_triangle branch May 10, 2024 17:54

This guide details how to render a triangle using Impeller. We will use the lowest layer of the stack to do this and explore Impellers HAL and shader compilation machinery.

A complete code example of this tutorial is in [`renderer_unittests.cc`](../renderer/renderer_unittests.cc) in `RendererTest.BabysFirstTriangle`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example is a unit test in the impeller source base so it doesn't have the same requirements in terms of includes, linking, actually rendering to the screen, etc; is that worth calling out here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow. Like the unit-tests, the engine TUs that use Impeller have the same requirements. Maybe I am missing something? This guide was a logical successor to the "Setting up a Standalone Impeller in OpenGL ES" guide from last week.

chinmaygarde added a commit to chinmaygarde/flutter_engine that referenced this pull request May 10, 2024
@chinmaygarde
Copy link
Member Author

I addressed the feedback after this landed in #52718. PTAL.

auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 10, 2024
…148147)

flutter/engine@d4f705c...ba8e0d3

2024-05-10 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Clip before applying ColorFilter so it doesn't filter beyond child bounds (flutter/engine#52704)
2024-05-10 magder@google.com Migrate FlutterView, FlutterPlatformViews, FlutterOverlayView to ARC (flutter/engine#52535)
2024-05-10 matanlurey@users.noreply.github.com Infer `--rbe` based on the existence of `//flutter/build/rbe` (flutter/engine#52700)
2024-05-10 jonahwilliams@google.com [Impeller] Disable AHB swapchain. (flutter/engine#52713)
2024-05-10 skia-flutter-autoroll@skia.org Roll Skia from c7cd1e9690d1 to 11d892ce49b6 (25 revisions) (flutter/engine#52712)
2024-05-10 chinmaygarde@google.com [Impeller] Document how to do basic rendering in Impeller. (flutter/engine#52703)
2024-05-10 30870216+gaaclarke@users.noreply.github.com [impeller] adds experimental canvas docstring (flutter/engine#52710)
2024-05-10 daniel.l@hpcnt.com Roll third_party/freetype2 from 3bea27612 to af4c2d86d (2 revisions) (flutter/engine#52689)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants