mirror of https://github.com/libsdl-org/SDL
vulkan: SDL_Vulkan_CreateSurface now accepts an app-provided allocator.
Fixes #3638.
This commit is contained in:
parent
c53843a961
commit
2f92807087
|
@ -1312,4 +1312,6 @@ SDL_Vulkan_GetInstanceExtensions() no longer takes a window parameter, and no lo
|
|||
|
||||
SDL_Vulkan_GetVkGetInstanceProcAddr() now returns `SDL_FunctionPointer` instead of `void *`, and should be cast to PFN_vkGetInstanceProcAddr.
|
||||
|
||||
SDL_Vulkan_CreateSurface() now takes a VkAllocationCallbacks pointer as its third parameter. If you don't have an allocator to supply, pass a NULL here to use the system default allocator (SDL2 always used the system default allocator here).
|
||||
|
||||
SDL_Vulkan_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be used in its place.
|
||||
|
|
|
@ -51,6 +51,7 @@ extern "C" {
|
|||
|
||||
VK_DEFINE_HANDLE(VkInstance)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
|
||||
struct VkAllocationCallbacks;
|
||||
|
||||
#endif /* !NO_SDL_VULKAN_TYPEDEFS */
|
||||
|
||||
|
@ -165,8 +166,13 @@ extern DECLSPEC char const* const* SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint
|
|||
* `instance` must have been created with extensions returned by
|
||||
* SDL_Vulkan_GetInstanceExtensions() enabled.
|
||||
*
|
||||
* If `allocator` is NULL, Vulkan will use the system default allocator.
|
||||
* This argument is passed directly to Vulkan and isn't used by SDL itself.
|
||||
*
|
||||
* \param window The window to which to attach the Vulkan surface
|
||||
* \param instance The Vulkan instance handle
|
||||
* \param allocator A VkAllocationCallbacks struct, which lets the app
|
||||
* set the allocator that creates the surface. Can be NULL.
|
||||
* \param surface A pointer to a VkSurfaceKHR handle to output the newly
|
||||
* created surface
|
||||
* \returns SDL_TRUE on success, SDL_FALSE on error.
|
||||
|
@ -177,6 +183,7 @@ extern DECLSPEC char const* const* SDLCALL SDL_Vulkan_GetInstanceExtensions(Uint
|
|||
*/
|
||||
extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR* surface);
|
||||
|
||||
/* @} *//* Vulkan support functions */
|
||||
|
|
|
@ -719,7 +719,7 @@ SDL_DYNAPI_PROC(int,SDL_UpdateTexture,(SDL_Texture *a, const SDL_Rect *b, const
|
|||
SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurface,(SDL_Window *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_UpdateYUVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f, const Uint8 *g, int h),(a,b,c,d,e,f,g,h),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, VkSurfaceKHR *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, const struct VkAllocationCallbacks *c, VkSurfaceKHR *d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(char const* const*,SDL_Vulkan_GetInstanceExtensions,(Uint32 *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_Vulkan_GetVkGetInstanceProcAddr,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_Vulkan_LoadLibrary,(const char *a),(a),return)
|
||||
|
|
|
@ -291,7 +291,7 @@ struct SDL_VideoDevice
|
|||
int (*Vulkan_LoadLibrary)(SDL_VideoDevice *_this, const char *path);
|
||||
void (*Vulkan_UnloadLibrary)(SDL_VideoDevice *_this);
|
||||
char const* const* (*Vulkan_GetInstanceExtensions)(SDL_VideoDevice *_this, Uint32 *count);
|
||||
SDL_bool (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface);
|
||||
SDL_bool (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
|
|
|
@ -5147,6 +5147,7 @@ char const* const* SDL_Vulkan_GetInstanceExtensions(Uint32 *count)
|
|||
|
||||
SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
CHECK_WINDOW_MAGIC(window, SDL_FALSE);
|
||||
|
@ -5166,7 +5167,7 @@ SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window,
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
return _this->Vulkan_CreateSurface(_this, window, instance, surface);
|
||||
return _this->Vulkan_CreateSurface(_this, window, instance, allocator, surface);
|
||||
}
|
||||
|
||||
SDL_MetalView SDL_Metal_CreateView(SDL_Window *window)
|
||||
|
|
|
@ -69,6 +69,7 @@ extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
|
|||
* extension. */
|
||||
extern SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
#else
|
||||
|
||||
|
|
|
@ -177,6 +177,7 @@ static const VkDisplayPlaneAlphaFlagBitsKHR alphaModes[4] = {
|
|||
|
||||
SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
|
@ -459,7 +460,7 @@ SDL_bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
|
|||
createInfo.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
|
||||
createInfo.globalAlpha = 1.0f;
|
||||
|
||||
result = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, NULL, surface);
|
||||
result = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
|
||||
return SDL_FALSE;
|
||||
|
|
|
@ -126,6 +126,7 @@ char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
SDL_WindowData *windowData = window->driverdata;
|
||||
|
@ -153,8 +154,7 @@ SDL_bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.pNext = NULL;
|
||||
createInfo.flags = 0;
|
||||
createInfo.window = windowData->native_window;
|
||||
result = vkCreateAndroidSurfaceKHR(instance, &createInfo,
|
||||
NULL, surface);
|
||||
result = vkCreateAndroidSurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s",
|
||||
SDL_Vulkan_GetResultString(result));
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -178,6 +178,7 @@ char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
static SDL_bool Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface,
|
||||
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT,
|
||||
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK)
|
||||
|
@ -195,7 +196,7 @@ static SDL_bool Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
|
|||
createInfo.flags = 0;
|
||||
createInfo.pLayer = (__bridge const CAMetalLayer *)
|
||||
Cocoa_Metal_GetLayer(_this, metalview);
|
||||
result = vkCreateMetalSurfaceEXT(instance, &createInfo, NULL, surface);
|
||||
result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
Cocoa_Metal_DestroyView(_this, metalview);
|
||||
SDL_SetError("vkCreateMetalSurfaceEXT failed: %s",
|
||||
|
@ -231,6 +232,7 @@ static SDL_bool Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
|
|||
SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
|
||||
|
@ -269,7 +271,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.pNext = NULL;
|
||||
createInfo.flags = 0;
|
||||
createInfo.pLayer = (CAMetalLayer *)data.sdlContentView.layer;
|
||||
result = vkCreateMetalSurfaceEXT(instance, &createInfo, NULL, surface);
|
||||
result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateMetalSurfaceEXT failed: %s",
|
||||
SDL_Vulkan_GetResultString(result));
|
||||
|
@ -282,7 +284,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.flags = 0;
|
||||
createInfo.pView = (__bridge const void *)data.sdlContentView;
|
||||
result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
|
||||
NULL, surface);
|
||||
allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s",
|
||||
SDL_Vulkan_GetResultString(result));
|
||||
|
@ -291,7 +293,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
return Cocoa_Vulkan_CreateSurfaceViaMetalView(_this, window, instance, surface, vkCreateMetalSurfaceEXT, vkCreateMacOSSurfaceMVK);
|
||||
return Cocoa_Vulkan_CreateSurfaceViaMetalView(_this, window, instance, allocator, surface, vkCreateMetalSurfaceEXT, vkCreateMacOSSurfaceMVK);
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
|
|
|
@ -163,6 +163,7 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
VkPhysicalDevice gpu = NULL;
|
||||
|
@ -476,7 +477,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
display_plane_surface_create_info.alphaMode = alpha_mode;
|
||||
result = vkCreateDisplayPlaneSurfaceKHR(instance,
|
||||
&display_plane_surface_create_info,
|
||||
NULL,
|
||||
allocator,
|
||||
surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s",
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* UIKit_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -133,13 +133,14 @@ char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
if (!_this->vulkan_config.loader_handle) {
|
||||
SDL_SetError("Vulkan is not loaded");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, surface);
|
||||
return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, allocator, surface);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,7 @@ char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -134,6 +134,7 @@ char const* const* Wayland_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
SDL_WindowData *windowData = window->driverdata;
|
||||
|
@ -162,8 +163,7 @@ SDL_bool Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.flags = 0;
|
||||
createInfo.display = windowData->waylandData->display;
|
||||
createInfo.surface = windowData->surface;
|
||||
result = vkCreateWaylandSurfaceKHR(instance, &createInfo,
|
||||
NULL, surface);
|
||||
result = vkCreateWaylandSurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s",
|
||||
SDL_Vulkan_GetResultString(result));
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* Wayland_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -125,6 +125,7 @@ char const* const* WIN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
SDL_WindowData *windowData = window->driverdata;
|
||||
|
@ -152,8 +153,7 @@ SDL_bool WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.flags = 0;
|
||||
createInfo.hinstance = windowData->hinstance;
|
||||
createInfo.hwnd = windowData->hwnd;
|
||||
result = vkCreateWin32SurfaceKHR(instance, &createInfo,
|
||||
NULL, surface);
|
||||
result = vkCreateWin32SurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateWin32SurfaceKHR failed: %s",
|
||||
SDL_Vulkan_GetResultString(result));
|
||||
|
|
|
@ -41,6 +41,7 @@ char const* const* WIN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -170,6 +170,7 @@ char const* const* X11_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface)
|
||||
{
|
||||
SDL_VideoData *videoData = _this->driverdata;
|
||||
|
@ -199,8 +200,7 @@ SDL_bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
return SDL_FALSE;
|
||||
}
|
||||
createInfo.window = (xcb_window_t)windowData->xwindow;
|
||||
result = vkCreateXcbSurfaceKHR(instance, &createInfo,
|
||||
NULL, surface);
|
||||
result = vkCreateXcbSurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateXcbSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
|
||||
return SDL_FALSE;
|
||||
|
@ -221,8 +221,7 @@ SDL_bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
|||
createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
|
||||
createInfo.dpy = videoData->display;
|
||||
createInfo.window = (xcb_window_t)windowData->xwindow;
|
||||
result = vkCreateXlibSurfaceKHR(instance, &createInfo,
|
||||
NULL, surface);
|
||||
result = vkCreateXlibSurfaceKHR(instance, &createInfo, allocator, surface);
|
||||
if (result != VK_SUCCESS) {
|
||||
SDL_SetError("vkCreateXlibSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
|
||||
return SDL_FALSE;
|
||||
|
|
|
@ -37,6 +37,7 @@ char const* const* X11_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
|
|||
SDL_bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this,
|
||||
SDL_Window *window,
|
||||
VkInstance instance,
|
||||
const struct VkAllocationCallbacks *allocator,
|
||||
VkSurfaceKHR *surface);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -261,6 +261,7 @@ static void createSurface(void)
|
|||
{
|
||||
if (!SDL_Vulkan_CreateSurface(vulkanContext->window,
|
||||
vulkanContext->instance,
|
||||
NULL,
|
||||
&vulkanContext->surface)) {
|
||||
vulkanContext->surface = VK_NULL_HANDLE;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError());
|
||||
|
|
Loading…
Reference in New Issue