Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -4080,6 +4080,16 @@ extern "C" {
*/
#define SDL_HINT_VULKAN_LIBRARY "SDL_VULKAN_LIBRARY"

/**
* Specify the Vulkan API minor version to create the instance with.
*
* 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...
}

*
* \since This hint is available since SDL 3.xx.
*/
#define SDL_HINT_VULKAN_REQUEST_API_MINOR_VERSION "SDL_VULKAN_REQUEST_API_MINOR_VERSION"

/**
* A variable controlling how the fact chunk affects the loading of a WAVE
* file.
Expand Down
29 changes: 29 additions & 0 deletions src/gpu/vulkan/SDL_gpu_vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -11206,6 +11206,35 @@ static Uint8 VULKAN_INTERNAL_CreateInstance(VulkanRenderer *renderer)
appInfo.engineVersion = SDL_VERSION;
appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0);

// Handle application requesting a specific Vulkan API minor version
const char *hint = SDL_GetHint(SDL_HINT_VULKAN_REQUEST_API_MINOR_VERSION);
if (hint) {
size_t len = SDL_strnlen(hint, 16);
if (len > 0) {
char *endptr = NULL;
long minor = SDL_strtol(hint, &endptr, 10);
if (minor >= 0 && endptr == hint + len) {
appInfo.apiVersion = VK_MAKE_VERSION(1, minor, 0);
} else {
SDL_LogError(
SDL_LOG_CATEGORY_GPU,
"VULKAN_INTERNAL_CreateInstance: Failed to parse requested API minor version. Expected positive integer. Got '%s'.",
hint);
SDL_SetError(
"VULKAN_INTERNAL_CreateInstance: Failed to parse requested API minor version. Expected positive integer. Got '%s'.",
hint);
return 0;
}
} else {
SDL_LogError(
SDL_LOG_CATEGORY_GPU,
"VULKAN_INTERNAL_CreateInstance: Requested API minor version was empty.");
SDL_SetError(
"VULKAN_INTERNAL_CreateInstance: Requested API minor version was empty.");
return 0;
}
}

createFlags = 0;

originalInstanceExtensionNames = SDL_Vulkan_GetInstanceExtensions(&instanceExtensionCount);
Expand Down
Loading