BabylonJS / BabylonJS/BabylonNative

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

Open
#1,385 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
919
Forks
162
Avg merge
1d 15h
Merged PRs (30d)
19

Description

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)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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.