Skip to content

Conversation

dvolynets
Copy link

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.

* 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"
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Author

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.

@andreasgrabher
Copy link

andreasgrabher commented Sep 27, 2025

Thank you for this PR! I am looking forward to this. It sounds like it might finally fix my issue #11725.

@slouken slouken added this to the 3.4.0 milestone Sep 27, 2025
- (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)) {
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants