lightbox-viewer icon indicating copy to clipboard operation
lightbox-viewer copied to clipboard

Async GPU readback failed - Incompatibility with Metal on macOS

Open owlboy opened this issue 4 months ago • 11 comments

Lightbox-viewer installs and seems to be fine, until I press Activate LightBoxViewer. At this point the error shared below starts printing every frame to the console. When I deactivate the Viewer the log output stops.

The platform is macOS running Metal. Is it possible to offer an alternative codepath for that platform here? I don't often run into shader issues with common VRChat assets. So I have hope!

Image
'B8G8R8A8_SRGB' doesn't support ReadPixels usage on this platform. Async GPU readback failed.
UnityEngine.Rendering.AsyncGPUReadback:Request (UnityEngine.Texture,int,UnityEngine.TextureFormat,System.Action`1<UnityEngine.Rendering.AsyncGPUReadbackRequest>)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerGenerator:AsyncRenderTextureTo (UnityEngine.RenderTexture,UnityEngine.Texture2D) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerGenerator.cs:109)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerGenerator:RenderNoAnimator (UnityEngine.Texture2D,UnityEngine.GameObject,UnityEngine.RenderTexture,UnityEngine.Vector3,UnityEngine.Quaternion,single) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerGenerator.cs:79)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:TrueRender (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:817)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:Render (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:750)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:TryRender (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:706)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:Rerender () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:548)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:UpdateAny () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:535)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:Update () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:138)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions () (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:381)

Thanks!

owlboy avatar Aug 17 '25 06:08 owlboy

Pushed to the listing as 2.5.0-alpha.1, please refresh your packages list and try to upgrade to 2.5.0-alpha.1, let me know if it works

hai-vr avatar Aug 17 '25 07:08 hai-vr

There was no change in behavior that I could see. And the error appears to be the same, but it might have different additional details. Was there more than one instance of Async that needs to be addressed? Here it is:

'B8G8R8A8_SRGB' doesn't support ReadPixels usage on this platform. Async GPU readback failed.
UnityEngine.Rendering.AsyncGPUReadback:Request (UnityEngine.Texture,int,UnityEngine.TextureFormat,System.Action`1<UnityEngine.Rendering.AsyncGPUReadbackRequest>)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerGenerator:AsyncRenderTextureTo (UnityEngine.RenderTexture,UnityEngine.Texture2D) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerGenerator.cs:126)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerGenerator:RenderNoAnimator (UnityEngine.Texture2D,UnityEngine.GameObject,UnityEngine.RenderTexture,UnityEngine.Vector3,UnityEngine.Quaternion,single) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerGenerator.cs:91)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:TrueRender (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs:435)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:Render (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs:358)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:EditModeRender (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs:195)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerRenderQueue:TryRender (UnityEngine.GameObject) (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs:123)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:Rerender () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:572)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:UpdateAny () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:557)
Hai.LightboxViewer.Scripts.Editor.LightboxViewerEditorWindow:Update () (at ./Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerEditorWindow.cs:141)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions () (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:381)

Proof I have the right version installed. I used ALCOM to switch from 2.4.0 to 2.5.0-alpha.1.

Image

Thank you!

owlboy avatar Aug 18 '25 23:08 owlboy

There was no change in behavior that I could see. And the error appears to be the same, but it might have different additional details. Was there more than one instance of Async that needs to be addressed?

This was the only instance of Async readback. I'm starting to wonder if Metal actually reports as capable of supporting AsyncGPUReadback but just not some specific kinds of texture formats.

Can you add LIGHTBOX_VIEWER_DO_NOT_USE_ASYNC_READBACK to your scripting defines in Edit > Project Settings | Project > Player | Other Settings > Script Compilation > +, press Apply, and try again? This won't be a proper fix but at least it will confirm that the synchronous render texture read works at all on this platform with this texture format.

Image

hai-vr avatar Aug 19 '25 03:08 hai-vr

I have identified a possible optimization that might render all of this unnecessary, so you don't have to investigate this. I'll let you know when I have a usable fix.

hai-vr avatar Aug 19 '25 04:08 hai-vr

Could you please try updating to 2.5.0-alpha.2 ? I have completely removed both asynchronous and synchronous GPU readback, as copying pixels from the GPU to the CPU was never needed in the first place.

You may still have issue with other tools I made because I did use the same texture copying code in a bunch of other places like Animation Viewer and other stuff, although most of them don't use Async readback. I still don't know if the ReadPixels issue is limited to async readback.

hai-vr avatar Aug 19 '25 07:08 hai-vr

Hello!

So, I no longer get any errors when activating the Lightbox! 🎉 But, the Lightbox silently fails to work. 😦

Note that the views don't turn black now:

Image

Something I noticed upon project launch were these warnings. I'm not sure if they are important or not.

Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs(175,22): warning CS0162: Unreachable code detected

Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs(193,21): warning CS0162: Unreachable code detected

Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs(206,21): warning CS0162: Unreachable code detected

Packages/dev.hai-vr.lightbox-viewer/Scripts/Editor/LightboxViewerRenderQueue.cs(213,21): warning CS0162: Unreachable code detected

Would you like me to also test the LIGHTBOX_VIEWER_DO_NOT_USE_ASYNC_READBACK flag still?

owlboy avatar Aug 19 '25 16:08 owlboy

The LIGHTBOX_VIEWER_DO_NOT_USE_ASYNC_READBACK won't do anything on 2.5.0-alpha.2, it will only operate on 2.5.0-alpha.1. At this point, yes, you can try this.

The issue overall is flying completely over my head. If this doesn't work, then I don't know how to fix this proper.

hai-vr avatar Aug 19 '25 18:08 hai-vr

Would you like me to also test the LIGHTBOX_VIEWER_DO_NOT_USE_ASYNC_READBACK flag still?

It's been a week, when you can, try 2.5.0-alpha.1 with the LIGHTBOX_VIEWER_DO_NOT_USE_ASYNC_READBACK flag. This won't work on 2.5.0-alpha.2. There's no way I can test this

hai-vr avatar Aug 29 '25 03:08 hai-vr

Hello, sorry, there was a misunderstanding about if you needed it.

With the flag in place, 2.5.0-alpha.1 results in empty views with no errors or warnings in the console at all. I restarted Unity after applying the flag.

Image

owlboy avatar Aug 29 '25 14:08 owlboy

@owlboy What hardware do you use personally for macOS (model)? I'm considering the possibility of getting myself some second-hand hardware to debug this myself. I think it's unproductive to do back and forth because I have no idea what's going on here being completely unfamiliar with development on that systems.

hai-vr avatar Oct 03 '25 10:10 hai-vr

Hello!

That's an interesting idea!

I'm actually on an older iMac Pro from 2017. But I'm current on the latest macOS that it can run. And when I started this issue, it was current for both Intel and ARM macs.

I believe this is a Metal issue and not one related to the specific graphics card I'm using. So if you obtained a used M1 Mac, I do think that would give you the right test environment. I wouldn't obtain an Intel Mac.

owlboy avatar Oct 03 '25 15:10 owlboy