Is there a plan to support AsyncGPUReadBack in OpenGl ?

It’s such an awesome feature and I feel kind of bad that most android device that uses opengles won’t get to use this feature.

Try this one: GitHub - kidapu/AsyncGPUReadbackPlugin: Unity plugin that provide AsyncGPUReadback for OpenGL

3 Likes

this plugin seems to only work with linux? from what I read in the readme
edit- ohhh I found the android branch. gonna try it tmr, thanks!

At the moment it’s not on our roadmap.

After poking around and rebuilding the .so for ARM64, I managed to get this working in our Android build, except it only works in Gamma colour space. In Linear, it throws a GL_INVALID_OPERATION error. I don’t know nearly enough about OpenGL to understand why this might be, but I bet somebody else on the forums does…

UPDATE: When I pass in a RenderTexture with sRGB conversions off, it works.

/// This works ///

var rtDesc = new RenderTextureDescriptor(width, height);
rtDesc.sRGB = false;
var rTex = RenderTexture.GetTemporary(rtDesc);

var req = AsyncGPUReadbackPlugin.Request(rTex);

/// This doesn't work ///

var rtDesc = new RenderTextureDescriptor(width, height);
rtDesc.sRGB = true;
var rTex = RenderTexture.GetTemporary(rtDesc);

var req = AsyncGPUReadbackPlugin.Request(rTex);

Hi Florian – thanks for the reply. I’m curious as to why not? Is it a technical limitation?

This is becoming an increasingly critical feature (e.g. for screen recording, bringing GPU-side texture ops back to the CPU side, saving user-created textures) in many use-cases, and it’s a shame that one of largest hardware platforms that Unity relies on is left out on this one in particular… :frowning:

It’s important enough that there are a bunch of people building their own custom solutions to the problem. For example: https://discussions.unity.com/t/683160 page-70#post-6568930

Any visibility on this from the Unity side would be great! :slight_smile:

4 Likes

could you please share how you make this work on android? thanks you!

2 Likes

It’s not a technical limitation. It should be possible to implement this inside Unity using OpenGL ES PBOs similar to the github plugin above.
We discussed adding GLES support when it was requested in this thread.
Because the earliest Unity version where this could have landed was 2021.2 the decision was not to add GLES support for async readback.

Are there still issues with the AsyncGPUReadbackPlugin on github with linear rendering?

That reasoning explains why you’ve shipped AyncGpuReadback without Android support initially, but I hope this feature is still considered for 2021.2 or the 2022 release cycle?

According to @Yiliu 's updated post this seems to work.

We are working on it. It’s not clear yet if it will be ready for 2021.2, but there is a good chance.

5 Likes

That’s awesome news :slight_smile:
Thanks for the confirmation.

async readback for OpenGL is now available in Unity 2021.2a19.

9 Likes

THANK YOU. I just tested my project on that version and gain a massive performance increase in Android getting rid of ReadPixel code.

1 Like

While we would love to update to 2021 for this new feature, we are currently stuck in 2019 LTS, and it doesn’t make sense for us to upgrade to an alpha or beta build of Unity.

Does anyone know how we can get AsyncGPUReadback working correctly for Compute Buffers on OpenGL ES? The github repo linked here only supports async readback from a texture.

Also does the built in AsyncGPUReadback have support for Vulkan?

@florianpenzkofer any help here would be much appreciated!

If you use Vulkan, async readback worked on 2019. OpenGles support require the beta 2021 build. I wish they could backport this feature. But normally, features are not backported unless we are vocal enough.

It should be possible to extend the github project to support Unity’s ComputeBuffer.
You would pass the GLuint of the ComputeBuffer (ComputeBuffer.GetNativeBufferPtr) to the plugin.
The plugin can then use glCopyBufferSubData to a staging SSBO. The rest is similar to textures after glReadPixels: sync with a fence and then map the SSBO and read the data once the fence is signaled.

Vulkan supports Unity’s builtin async readback in 2019.4.

3 Likes

Still getting the error on Unity 2021.3.5:

2022/07/05 10:07:54.642 15242 15353 Error Unity OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state

Trying to read a HDR cubemap of the passthrough environment generated by ARCore. Possibly HDR textures are still not supported?

Is this an error from AsyncGPUReadbackPlugin or some other plugin related to ARCore?
What is the format (GraphicsFormat/RenderTextureFormat) of the HDR texture?

Is it possible to read RenderTexture with sRGB sampling in Linear color space on Android? Found this error “OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state” in AsyncGPUReadbackPlugin when trying to read from render texture with such parameters, thinking about switching to 2021.2a19 to fix this issue without using the plugin.

Sorry, didn’t see the reply. Iirc this was native Unity, no 3rd party plugins. I unfortunately cannot remember what the format of the texture was, but it would be the format that iOS uses for runtime-generated environment cubemaps. Should be easy to check by creating a new AR Foundation project.