-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing on metal-macos causes metal validation errors when high_dpi is enabled in sokol_app #872
Comments
Hmm, I've seen this exact same problem after updating to macOS 13.x around the end of 2022: ...but this issue was fixed by this MR: I'll try to reproduce the problem in the evening (it's strange because my Mac is my main development platform, and I should have noticed such an obvious issue). In the meantime, can you check if the problem still happens when you change the ...to:
(so that it looks like in the line below where the separate |
I'm on an M1 14" MBP with macOS Ventura 13.4.1 (c) (22F770820d), Xcode version is 14.2 PS: do you compile with ARC enabled or disabled? (it shouldn't matter but since it is some sort of lifetime issue it could be related) |
...let me update to the latest xcode version... |
Ok, I finally got the error too... took a long while of wildly resizing though, and I can't seem to reproduce it reliably. I also updated to the latest Xcode version, but it's probably not related. I'll try to investigate later today. I was hoping that just doing the present call in a separate command buffer with retained references would be enough to fix the issue, but looks like that's not enough. It's also complicated by the fact the resource in question is created and managed by MTKView, which I don't have access to. Worst case would be to do all rendering in a command buffer with retained references, but maybe there's another solution (e.g. maybe I can extract the depth-stencil-surface from the MTLRenderPassDescriptor I'm getting from MTKView, and add a manual retain/release call somewhere in sokol-gfx - but that doesn't sound like a robust solution, I would expect that MTKView takes care of the lifetimes of the objects is manages).
|
See #872 This does away with the separate retained-reference command buffer for the present call, and instead uses the regular 'deferred release queue' for the default pass MTLRenderPassDescriptor. Since the render-pass-descriptor holds a strong-ref to swapchain surfaces this should make sure that those surfaces outlive their command buffer when they are released by MTKView because of a window resize. This means there's a memory spike during window resize, but I guess there's no way around that.
Can you give the attempted fix in the branch See this change: master...issue872-metal-validation-error This means there's no refcounting overhead (because the command buffer is stil created with unretained-references), but slightly increases memory usage during window resize (but that's expected to happen, because swapchain resources which had been released by MTKView during the window resize need to stick around a few frames before it's safe to delete them). |
That seems to fix it for me, too. Thank you! |
Ok, I think I'll merge the fix into master some time over the weekend (or latest on Monday). Will close this issue when the fix is merged. |
Closing this because PR #873 has been merged. Thanks for the bug report! |
Hi, thanks for the excellent graphics library!
I noticed that when using the xcode metal debugging tools, my program was crashing on resize. Here's the most minimal reproduction I could find (basically the triangle example with extra stuff removed and high_dpi=true in sokol_main):
with this shader code:
Running this with MTL_DEBUG_LAYER=1 set and then resizing the window results in a crash with the following text printed out:
sokol headers used were from sokol commit
47d92ff86298fc96b3b84d93d0ee8c8533d3a2d2
, which is the tip of master at the time of postingThe text was updated successfully, but these errors were encountered: