Skip to content
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

SDL3, macOS: SDL_HINT_RENDER_DRIVER fallback does not work #11077

Closed
andreasgrabher opened this issue Oct 5, 2024 · 12 comments
Closed

SDL3, macOS: SDL_HINT_RENDER_DRIVER fallback does not work #11077

andreasgrabher opened this issue Oct 5, 2024 · 12 comments
Assignees
Milestone

Comments

@andreasgrabher
Copy link

andreasgrabher commented Oct 5, 2024

I tried setting SDL_HINT_RENDER_DRIVER to "direct3d" on macOS just to see if it will fall back to the default renderer. Unfortunately this seems to not work as described in the documentation:

If the application doesn't pick a specific renderer to use, this variable
specifies the name of the preferred renderer. If the preferred renderer
can't be initialized, the normal default renderer is used.

I get this error when calling SDL_CreateRenderer():

Couldn't find matching render driver!

@slouken
Copy link
Collaborator

slouken commented Oct 5, 2024

Oh, the documentation is wrong here. I'll fix that. It's intentional that it returns NULL if the preferred renderer isn't available, so that the application can try several, in order of preference.

@slouken slouken closed this as completed in b8e72b0 Oct 5, 2024
@andreasgrabher
Copy link
Author

I am not sure this makes sense. If I want to explicitly create a metal renderer I just call

SDL_CreateRenderer(sdlRenderer, "metal");

Why should someone call

SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
SDL_CreateRenderer(sdlRenderer, NULL);

instead? I think if the hint works this way it is pretty much useless.

@slouken
Copy link
Collaborator

slouken commented Oct 6, 2024

Because you can do this:

renderer = SDL_CreateRenderer("gpu");
if (!renderer) {
    renderer = SDL_CreateRenderer("opengles2");
}
if (!renderer) {
    renderer = "SDL_CreateRenderer("direct3d");
}

@andreasgrabher
Copy link
Author

Exactly, so why would I need that hint?

@slouken
Copy link
Collaborator

slouken commented Oct 6, 2024

Oh, you're right, I was conflating the two. Mmmm, I will reopen this for further thought.

@slouken slouken reopened this Oct 6, 2024
@slouken slouken added this to the 3.2.0 milestone Oct 6, 2024
@slouken slouken self-assigned this Oct 6, 2024
@madebr
Copy link
Contributor

madebr commented Oct 6, 2024

Isn't a hint useful for a user to try another renderer backend (through an environment variable), and the SDL_CreateRenderer a way to force a backend by the developer?

@andreasgrabher
Copy link
Author

andreasgrabher commented Oct 6, 2024

I think this hint would make sense if someone has one single preferred renderer but does not want things to fail if that one is not available.

I think if someone wants to make his own order of preference with multiple renderers this would be appropriate:

static const char* renderers[] = {
	"direct3d",
	"direct3d11",
	"direct3d12",
	"metal",
	"opengl",
	"opengles2",
	"opengles",
	"vulkan",
	"software"
};

SDL_Renderer* CreateRenderer(SDL_Window* sdlWindow)
{
	int i;
	SDL_Renderer* sdlRenderer;
	for (i = 0; i < SDL_arraysize(renderers); i++) {
		fprintf(stderr, "Trying to create %s renderer\n", renderers[i]);
		sdlRenderer = SDL_CreateRenderer(sdlWindow, renderers[i]);
		if (sdlRenderer) {
			fprintf(stderr, "Successfully created %s renderer\n", SDL_GetRendererName(sdlRenderer));
			return sdlRenderer;
		}
	}
	return NULL;
}

@slouken
Copy link
Collaborator

slouken commented Oct 6, 2024

Yep, that's what we do for video drivers, etc. I'll take a look.

@slouken slouken assigned icculus and unassigned slouken Oct 6, 2024
klukaszek pushed a commit to klukaszek/SDL that referenced this issue Nov 17, 2024
@icculus
Copy link
Collaborator

icculus commented Dec 4, 2024

(Just making a note that what we need to do here is make sure SDL_HINT_RENDER_DRIVER takes a comma-separated list, to match what audio and video subsystems already do.)

@slouken slouken modified the milestones: 3.2.0, 3.4.0 Dec 4, 2024
@andreasgrabher
Copy link
Author

I know that 3.2.0 should be released really soon, but I think this shoud be fixed before release. People might use this hint to set a specific renderer instead of using SDL_CreateRenderer() for that. Changing the hint to be treated as prefered renderer could then break someone's code.

@icculus icculus modified the milestones: 3.4.0, 3.2.0 Jan 21, 2025
@icculus
Copy link
Collaborator

icculus commented Jan 21, 2025

I snuck this in for 3.2.0.

The documentation in the original comment was updated at some point to reflect reality, but this now accepts a comma-separated list (both in SDL_CreateRenderer's name parameter and SDL_HINT_RENDER_DRIVER), matching what the video/audio/whatever subsystems already do.

@andreasgrabher
Copy link
Author

Fantastic! Thank you very much!

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

No branches or pull requests

4 participants