Occasional pink frame in Metal on macOS Ventura (M2 Pro)

I am developing a macOS app which has a metal-backed view, based on CAMetalLayer.

It worked fine on macOS Monterey, but after I switched to a M2 Pro machine and upgraded my macOS to Ventura (tried both 13.3 and 13.4), the view would randomly display a blank pink screen - as if the Metal is indicating an error or empty state. I don't get any log messages in the Console though.

Particularly, the pink screen appears after I select the app's "Enter Full Screen" command. It appears only in ~1 of 10 attempts, and doesn't appear in 9 of 10 attempts. The pink screen goes away after the view renders its next frame (e.g. on mouse move).

It's worth mentioning that the CAMetalLayer-backed view in question is hosted in the toolbar, so the issue is probably related to the fact that when an app switches to the full screen mode, macOS detaches the toolbar from the main window and attaches it to the separate toolbar window.

I have tried to profile the app and catch the pink frame - particularly using -[MTLCaptureManager startCaptureWithDescriptor:error:], however when I analyze the trace, everything seems to be fine - all vertexes, textures and commands are being transmitted to the GPU correctly. However, on the screen, I still get the occasional pink screen.

I wonder if anyone could give me hints as of why this might be happening and what other tools I can use to track down the problem? Or maybe it's a macOS Ventura bug?

P.S. For brevity, I'm not attaching the code, which is too large and spread over multiple files to fit here. I'm interested in general advice.

Replies

First thing I'd check is the Load/Store actions set in the MTLRenderPassDescriptor used with the drawable. Perhaps one is set to DontCare?