Skip to content

No way to read pixels from an external texture for Apple textures #1385

Open

Description

@Allan121

There is currently no way to wait for the underlying texture to synchronise and be ready for reading.

I've implemented a workaround that effectively allows us to wait for the internal command buffer to complete with the following:

deviceUpdate->Finish();
device->FinishRenderingCurrentFrame();
auto buffer = ((__bridge id<MTLCommandQueue>)device->GetPlatformInfo().CommandQueue).commandBuffer;
[buffer commit];
[buffer waitUntilCompleted];
device->StartRenderingCurrentFrame();
deviceUpdate->Start();

By creating and enqueueing another buffer, and waiting for it to complete, we can essentially ensure that all previous buffers have also completed, in turn ensuring that any textures that were involved in the rendered frame would also be ready to read from.

Ideally, we should have something similar exposed to allow safe reading of pixels from external textures.

Relevant docs for reading pixels from MTLTexture (note the reference of needing synchronise prior to reading):
https://developer.apple.com/documentation/metal/mtltexture/1516318-getbytes

Activity

  1. modified the milestone: 8.0 on Jun 3, 2024
  2. modified the milestones: 8.0, 9.0, Future on Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions