-
Notifications
You must be signed in to change notification settings - Fork 2.4k
MacOS: Added hint to control update of the metal layer's drawable size #14053
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
base: main
Are you sure you want to change the base?
MacOS: Added hint to control update of the metal layer's drawable size #14053
Conversation
include/SDL3/SDL_hints.h
Outdated
* This hint should be set before SDL_Metal_CreateView called. | ||
* | ||
* \since This hint is available since SDL 3.4.0. */ | ||
#define SDL_HINT_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER "SDL_VIDEO_MAC_ENABLE_METAL_VIEW_WATCHER" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to name it more clearly for the functionality it's changing. Maybe something like SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The watcher is just an implementation detail and doesn't need to be reference in the documentation, instead we should talk about the behavior and how it's modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree, this name is much better, thank you. I'll make the changes.
Thank you for this PR! I am looking forward to this. It sounds like it might finally fix my issue #11725. |
- (void)dealloc | ||
{ | ||
SDL_RemoveWindowEventWatch(SDL_WINDOW_EVENT_WATCH_EARLY, SDL_MetalViewEventWatch, (__bridge void *)(self)); | ||
if (SDL_GetHintBoolean(SDL_HINT_VIDEO_METAL_AUTO_RESIZE_DRAWABLE, true)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't check the hint here, we should either remember that we added the watcher or just call SDL_RemoveWindowEventWatch() unconditionally, in case someone changes the hint at runtime.
Motivation
This PR adds a hint to control the metal layer drawable size update.
In the codebase I'm working on, metal layer creation is performed using SDL_Metal_CreateView on the main thread. A custom renderer (not SDL) runs on a dedicated thread, and this thread is responsible for metal layer drawable size update. When resizing the window and enabled Metal API validation, I receive the following assertion:
-[MTLDebugRenderCommandEncoder setScissorRect:]:4053: failed assertion Set Scissor Rect Validation
To avoid this assertion, I need to disable drawable size updates on the main thread and update them on the render thread. To achieve this behaviour, I propose this hint.
As far as I understand, you previously received the same assertion link.