Port ref_vk to SDL3.

* Makefile support for SDL3.
* Change API to match SDL3.
* Bump renderer API to version 7 and communicate SDL version to client.

61be37b183
This commit is contained in:
Yamagi 2024-04-06 11:55:09 +02:00 committed by Denis Pauk
parent 4bd19bf982
commit 4fedab5914
3 changed files with 46 additions and 0 deletions

View file

@ -31,6 +31,10 @@
#include <stdio.h>
#include <math.h>
#ifdef USE_SDL3
#include <SDL3/SDL.h>
#include <SDL3/SDL_vulkan.h>
#else
#if defined(__APPLE__)
#include <SDL.h>
#include <SDL_vulkan.h>
@ -38,6 +42,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#endif
#endif
#include "../../ref_shared.h"

View file

@ -1680,7 +1680,11 @@ void QVk_SetWindow(SDL_Window *window)
*/
void QVk_GetDrawableSize(int *width, int *height)
{
#ifdef USE_SDL3
SDL_GetWindowSizeInPixels(vk_window, width, height);
#else
SDL_GL_GetDrawableSize(vk_window, width, height);
#endif
}
void QVk_WaitAndShutdownAll (void)
@ -1770,7 +1774,11 @@ qboolean QVk_Init(void)
vk_config.triangle_index_max_usage = 0;
vk_config.triangle_index_count = TRIANGLE_INDEX_CNT;
#ifdef USE_SDL3
if (!SDL_Vulkan_GetInstanceExtensions(&extCount))
#else
if (!SDL_Vulkan_GetInstanceExtensions(vk_window, &extCount, NULL))
#endif
{
R_Printf(PRINT_ALL, "%s() SDL_Vulkan_GetInstanceExtensions failed: %s",
__func__, SDL_GetError());
@ -1785,6 +1793,14 @@ qboolean QVk_Init(void)
extCount++;
#endif
#ifdef USE_SDL3
if ((wantedExtensions = (char **)SDL_Vulkan_GetInstanceExtensions(&extCount)) == NULL)
{
R_Printf(PRINT_ALL, "%s() SDL_Vulkan_GetInstanceExtensions failed: %s",
__func__, SDL_GetError());
return false;
}
#else
wantedExtensions = malloc(extCount * sizeof(char *));
if (!SDL_Vulkan_GetInstanceExtensions(vk_window, &extCount, (const char **)wantedExtensions))
{
@ -1793,6 +1809,7 @@ qboolean QVk_Init(void)
free(wantedExtensions);
return false;
}
#endif
// restore extensions count
if (r_validation->value > 0)
@ -1908,7 +1925,9 @@ qboolean QVk_Init(void)
res = vkCreateInstance(&createInfo, NULL, &vk_instance);
}
#ifndef USE_SDL3
free(wantedExtensions);
#endif
if (res != VK_SUCCESS)
{

View file

@ -1575,7 +1575,11 @@ RE_InitContext(void *win)
#if SDL_VERSION_ATLEAST(2, 26, 0)
// Figure out if we are high dpi aware.
int flags = SDL_GetWindowFlags(window);
#ifdef USE_SDL3
RE_IsHighDPIaware = (flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) ? true : false;
#else
RE_IsHighDPIaware = (flags & SDL_WINDOW_ALLOW_HIGHDPI) ? true : false;
#endif
if (RE_IsHighDPIaware)
{
R_Printf(PRINT_ALL, "%s() - HighDPI is enabled\n", __func__);
@ -1595,7 +1599,11 @@ RE_InitContext(void *win)
qboolean Vkimp_CreateSurface(SDL_Window *window)
{
#ifdef USE_SDL3
if (!SDL_Vulkan_CreateSurface(window, vk_instance, NULL, &vk_surface))
#else
if (!SDL_Vulkan_CreateSurface(window, vk_instance, &vk_surface))
#endif
{
R_Printf(PRINT_ALL, "%s() SDL_Vulkan_CreateSurface failed: %s",
__func__, SDL_GetError());
@ -1667,7 +1675,12 @@ static int RE_PrepareForWindow(void)
R_Printf(PRINT_ALL, "%s() Loader import failed: %s", __func__, SDL_GetError());
}
#ifdef USE_SDL3
volkInitializeCustom((void *)SDL_Vulkan_GetVkGetInstanceProcAddr());
#else
volkInitializeCustom(SDL_Vulkan_GetVkGetInstanceProcAddr());
#endif
#if defined(__APPLE__)
void *molten = dlopen("libMoltenVK.dylib", RTLD_LOCAL | RTLD_NOW);
if (!molten)
@ -1696,9 +1709,18 @@ GetRefAPI(refimport_t imp)
{
refexport_t refexport = {0};
// Need to communicate the SDL major version to the client.
#ifdef USE_SDL3
SDL_Version ver;
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
ri = imp;
refexport.api_version = API_VERSION;
refexport.framework_version = ver.major;
refexport.BeginRegistration = RE_BeginRegistration;
refexport.RegisterModel = RE_RegisterModel;