|
@@ -95,37 +95,6 @@ static VkPresentModeKHR SDLToVK_PresentMode[] = {
|
|
|
VK_PRESENT_MODE_MAILBOX_KHR
|
|
VK_PRESENT_MODE_MAILBOX_KHR
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-// NOTE: this is behind an ifdef guard because without, it would trigger an "unused variable" error when OpenXR support is disabled
|
|
|
|
|
-#ifdef HAVE_GPU_OPENXR
|
|
|
|
|
-typedef struct TextureFormatPair {
|
|
|
|
|
- VkFormat vk;
|
|
|
|
|
- SDL_GPUTextureFormat sdl;
|
|
|
|
|
-} TextureFormatPair;
|
|
|
|
|
-
|
|
|
|
|
-static TextureFormatPair SDLToVK_TextureFormat_SrgbOnly[] = {
|
|
|
|
|
- {VK_FORMAT_R8G8B8A8_SRGB, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_B8G8R8A8_SRGB, SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_BC1_RGBA_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_BC2_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_BC3_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_BC7_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_4x4_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_5x4_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_5x5_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_6x5_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_6x6_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_8x5_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_8x6_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_8x8_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_10x5_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_10x6_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_10x8_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_10x10_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_12x10_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM_SRGB},
|
|
|
|
|
- {VK_FORMAT_ASTC_12x12_SRGB_BLOCK, SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM_SRGB},
|
|
|
|
|
-};
|
|
|
|
|
-#endif // HAVE_GPU_OPENXR
|
|
|
|
|
-
|
|
|
|
|
static VkFormat SDLToVK_TextureFormat[] = {
|
|
static VkFormat SDLToVK_TextureFormat[] = {
|
|
|
VK_FORMAT_UNDEFINED, // INVALID
|
|
VK_FORMAT_UNDEFINED, // INVALID
|
|
|
VK_FORMAT_R8_UNORM, // A8_UNORM
|
|
VK_FORMAT_R8_UNORM, // A8_UNORM
|
|
@@ -13126,23 +13095,6 @@ static XrResult VULKAN_DestroyXRSwapchain(
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#ifdef HAVE_GPU_OPENXR
|
|
|
|
|
-static bool VULKAN_INTERNAL_FindXRSrgbSwapchain(int64_t *supportedFormats, Uint32 numFormats, SDL_GPUTextureFormat *sdlFormat, int64_t *vkFormat)
|
|
|
|
|
-{
|
|
|
|
|
- for (Uint32 i = 0; i < SDL_arraysize(SDLToVK_TextureFormat_SrgbOnly); i++) {
|
|
|
|
|
- for (Uint32 j = 0; j < numFormats; j++) {
|
|
|
|
|
- if (SDLToVK_TextureFormat_SrgbOnly[i].vk == supportedFormats[j]) {
|
|
|
|
|
- *sdlFormat = SDLToVK_TextureFormat_SrgbOnly[i].sdl;
|
|
|
|
|
- *vkFormat = SDLToVK_TextureFormat_SrgbOnly[i].vk;
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
-#endif // HAVE_GPU_OPENXR
|
|
|
|
|
-
|
|
|
|
|
static SDL_GPUTextureFormat* VULKAN_GetXRSwapchainFormats(
|
|
static SDL_GPUTextureFormat* VULKAN_GetXRSwapchainFormats(
|
|
|
SDL_GPURenderer *driverData,
|
|
SDL_GPURenderer *driverData,
|
|
|
XrSession session,
|
|
XrSession session,
|
|
@@ -13163,38 +13115,37 @@ static SDL_GPUTextureFormat* VULKAN_GetXRSwapchainFormats(
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // FIXME: For now we're just searching for the optimal format, not all supported formats.
|
|
|
|
|
- // FIXME: Expand this search for all SDL_GPU formats!
|
|
|
|
|
-
|
|
|
|
|
- SDL_GPUTextureFormat sdlFormat = SDL_GPU_TEXTUREFORMAT_INVALID;
|
|
|
|
|
- int64_t vkFormat = VK_FORMAT_UNDEFINED;
|
|
|
|
|
- // The OpenXR spec recommends applications not submit linear data, so let's try to explicitly find an sRGB swapchain before we search the whole list
|
|
|
|
|
- if (!VULKAN_INTERNAL_FindXRSrgbSwapchain(supported_formats, num_supported_formats, &sdlFormat, &vkFormat)) {
|
|
|
|
|
- // Iterate over all formats the runtime supports
|
|
|
|
|
- for (i = 0; i < num_supported_formats && vkFormat == VK_FORMAT_UNDEFINED; i++) {
|
|
|
|
|
- // Iterate over all formats we support
|
|
|
|
|
- for (j = 0; j < SDL_arraysize(SDLToVK_TextureFormat); j++) {
|
|
|
|
|
- // Pick the first format the runtime wants that we also support, the runtime should return these in order of preference
|
|
|
|
|
- if (SDLToVK_TextureFormat[j] == supported_formats[i]) {
|
|
|
|
|
- vkFormat = supported_formats[i];
|
|
|
|
|
- sdlFormat = j;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ SDL_GPUTextureFormat *sdl_formats = SDL_stack_alloc(SDL_GPUTextureFormat, num_supported_formats);
|
|
|
|
|
+ uint32_t num_found_formats = 0;
|
|
|
|
|
+
|
|
|
|
|
+ // Iterate over all formats the runtime supports
|
|
|
|
|
+ for (i = 0; i < num_supported_formats; i++) {
|
|
|
|
|
+ // Iterate over all formats we support
|
|
|
|
|
+ for (j = 0; j < SDL_arraysize(SDLToVK_TextureFormat); j++) {
|
|
|
|
|
+ if (SDLToVK_TextureFormat[j] == supported_formats[i]) {
|
|
|
|
|
+ // Add the format match we found, linearly. The output order should match the order of the runtime.
|
|
|
|
|
+ sdl_formats[num_found_formats++] = j;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SDL_stack_free(supported_formats);
|
|
SDL_stack_free(supported_formats);
|
|
|
|
|
|
|
|
- if (vkFormat == VK_FORMAT_UNDEFINED) {
|
|
|
|
|
|
|
+ if (num_found_formats == 0) {
|
|
|
SDL_SetError("Failed to find a swapchain format supported by both OpenXR and SDL");
|
|
SDL_SetError("Failed to find a swapchain format supported by both OpenXR and SDL");
|
|
|
|
|
+ SDL_stack_free(sdl_formats);
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SDL_GPUTextureFormat *retval = (SDL_GPUTextureFormat*) SDL_malloc(sizeof(SDL_GPUTextureFormat) * 2);
|
|
|
|
|
- retval[0] = sdlFormat;
|
|
|
|
|
- retval[1] = SDL_GPU_TEXTUREFORMAT_INVALID;
|
|
|
|
|
- *num_formats = 1;
|
|
|
|
|
|
|
+ SDL_GPUTextureFormat *retval = (SDL_GPUTextureFormat *)SDL_calloc((size_t)num_found_formats + 1, sizeof(SDL_GPUTextureFormat));
|
|
|
|
|
+ SDL_memcpy(retval, sdl_formats, sizeof(SDL_GPUTextureFormat) * num_found_formats); // Copy the translated formats
|
|
|
|
|
+ retval[num_found_formats] = SDL_GPU_TEXTUREFORMAT_INVALID; // Add a termination for good measure
|
|
|
|
|
+
|
|
|
|
|
+ *num_formats = num_found_formats;
|
|
|
|
|
+
|
|
|
|
|
+ SDL_stack_free(supported_formats);
|
|
|
|
|
+
|
|
|
return retval;
|
|
return retval;
|
|
|
#else
|
|
#else
|
|
|
SDL_SetError("SDL not built with OpenXR support");
|
|
SDL_SetError("SDL not built with OpenXR support");
|