Skip to content

Conversation

TheSniperFan
Copy link

Currently SDL_gpu_vulkan.c hardcodes API version 1.0 when creating the Vulkan instance for the program. This creates a problem for my use-case.

I'd like to use Slang for shader development, but SPIR-V 1.0 support is experimental. I tried two solutions and both work:

  1. Slang's experimental compiler flags which make Slang transpile to GLSL first and then to SPIR-V, rather than compiling directly to SPIR-V.
  2. Add a hint to SDL to allow creating instances with higher API versions.

I looked at the Vulkan documentation (specifically this and this). It says "Deprecated items will still work in current Vulkan implementations", which makes me prefer option 2. A Vulkan application requesting 1.3, but using only 1.0 features should work just fine. And using a hint doesn't change SDL's default behavior.

Since I don't know why this was hardcoded, I figured I'd first ask if there's any chance of this merge request going anywhere. Before I waste time cleaning something up that's not going to be merged for reasons I didn't know of.

This adds SDL_HINT_VULKAN_REQUEST_API_VERSION to allow requesting a
specific API version when SDL creates the Vulkan instance.
The patch version shouldn't be relevant to the API and a new major
version will likely require an entirely new renderer anyway.
The benefit of this approach is that it massively simplifies parsing of
the hint.
@thatcosmonaut
Copy link
Collaborator

We hardcode to 1.0 to provide maximum driver compatibility. I'm totally fine with allowing an opt-in to higher versions.

@slouken slouken added this to the 3.4.0 milestone Oct 10, 2025
Comment on lines 4086 to 4087
* This hint should be set before creating a Vulkan window. Expects a positive
* integer. E.g. 3 for Vulkan 1.3.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable to allow specifying the full version and will be more intuitive for users. This is easily implemented with, e.g.

if (SDL_sscanf(hint, "%d.%d", &major, &minor) == 2) {
    ...
} else {
    // Parse error...
}

@TheSniperFan
Copy link
Author

This needs a bit more time in the oven, I think.
Setting the API version during instance creation does allow Slang-compiled shaders to be loaded without the validation layer complaining. However, Slang might emit SPIR-V that relies on physical device features that would have to be specified during device creation.
I'll see if there's a sane, non-intrusive way to implement that tomorrow.

* Specify the Vulkan API version to create the instance with.
*
* This hint should be set before creating a Vulkan window. Expects a
* version string delimited by underscores. E.g. 1_0_0 or 1_3_0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string should be delimited by . so it looks like a natural version number.

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.

4 participants