Skip to content

[Flutter GPU] Discovery: Is Flutter GPU's rasterization workflow safe? #150816

Open

Description

@bdero

For this discovery, document whether it's possible for a renderer written against Flutter GPU to perform unsafe behavior.

"Safe" in this context means:

  • No crashes.
  • No memory corruption.
  • No Metal/Vulkan validation failures.

Example of valid API usage which is not considered "unsafe":

  • The user creates a new Flutter GPU Texture and draws it to the screen without first clearing it, causing uninitialized garbage to display.

Currently, Flutter GPU's usage flow for rasterization works like this:

  1. Get the GPU context.
  2. Create a CommandBuffer with GpuContext.createCommandBuffer.
  3. Create a RenderPass with CommandBuffer.createRenderPass.
  4. Set state/pipelines and bind resources with various RenderPass methods.
  5. Append draw commands with RenderPass.draw.
  6. Submit the CommandBuffer with CommandBuffer.submit (async). All RenderPasses are encoded in the order with which they were created.

Things to check:

  • Is accessing the Flutter GPU context from a separate isolate currently safe? Should we detect/restrict this?
  • RenderPasses are currently always enqueued in the same order with which they were created, but CommandBuffers may be explicitly submitted in any order. Verify that differing the CommandBuffer submission order from the CommandBuffer creation order results in predictable and safe behavior.

Activity

  1. self-assigned this
    on Jun 26, 2024
  2. converted this from a draft issue on Jun 26, 2024
  3. jonahwilliams commented on Jun 26, 2024

    @jonahwilliams
    Contributor

    I don't believe that APIs like HostBuffer are thread safe. For isolate usage, I'd wonder if you could even send the native objects across isolates. For example, maybe I have a worker spin up to encode some work that renders to a texture. But then if I can't get that texture object back to the main thread, I have no way to actually present it. If there are restrictions like that, then preventing usage in other isolates is more of a matter of frustration prevention.

  4. bdero commented on Jun 26, 2024

    @bdero
    MemberAuthor

    I don't believe that APIs like HostBuffer are thread safe.

    I don't think there would be any way for a user to reference the same shared buffer or Texture resources across different isolates (unless I missed something obvious w/ how isolates work 🤣).

    But then if I can't get that texture object back to the main thread, I have no way to actually present it. If there are restrictions like that, then preventing usage in other isolates is more of a matter of frustration prevention.

    Yeah I'm not sure how useful it would be to even support running it in multiple isolates right now... Theoretically you could e.g. myTexture.asImage().toByteData() and pass the bytes back, but not yet sure if that's safe.

  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    engineflutter/engine related. See also e: labels.
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Mar 3, 2026
  6. mbcorona commented on Mar 4, 2026

    @mbcorona
    Member

    Since the PR #150828 is closed, should this issue be closed as well?

  7. added
    P3Issues that are less important to the Flutter project
    on Mar 9, 2026
  8. moved this from ⚙️ In Progress to 💬 Discussion in Flutter GPUon May 1, 2026
  9. bdero commented on May 1, 2026

    @bdero
    MemberAuthor

    I think we should still get around to checking the couple of things I listed here. We're in the process of reviving Flutter GPU and will keep this open as a discussion thread for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectengineflutter/engine related. See also e: labels.flutter-gputeam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

  • Status
    💬 Discussion

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions