2015-06-21 17:33:46 +02:00
|
|
|
/*
|
|
|
|
|
Simple DirectMedia Layer
|
2025-01-01 07:45:41 -08:00
|
|
|
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
appreciated but is not required.
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
2016-11-20 21:34:54 -08:00
|
|
|
#ifndef SDL_internal_h_
|
|
|
|
|
#define SDL_internal_h_
|
2015-06-21 17:33:46 +02:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Many of SDL's features require _GNU_SOURCE on various platforms
|
2016-11-11 13:14:00 -08:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Need this so Linux systems define fseek64o, ftell64o and off64_t
|
2022-11-29 18:34:15 -08:00
|
|
|
#ifndef _LARGEFILE64_SOURCE
|
2023-01-11 08:22:49 -05:00
|
|
|
#define _LARGEFILE64_SOURCE 1
|
2022-11-29 18:34:15 -08:00
|
|
|
#endif
|
|
|
|
|
|
2016-12-06 02:20:58 -05:00
|
|
|
/* This is for a variable-length array at the end of a struct:
|
|
|
|
|
struct x { int y; char z[SDL_VARIABLE_LENGTH_ARRAY]; };
|
|
|
|
|
Use this because GCC 2 needs different magic than other compilers. */
|
2017-12-06 12:24:32 -05:00
|
|
|
#if (defined(__GNUC__) && (__GNUC__ <= 2)) || defined(__CC_ARM) || defined(__cplusplus)
|
2016-12-06 02:20:58 -05:00
|
|
|
#define SDL_VARIABLE_LENGTH_ARRAY 1
|
|
|
|
|
#else
|
|
|
|
|
#define SDL_VARIABLE_LENGTH_ARRAY
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-11-23 11:33:20 +03:00
|
|
|
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))) || defined(__clang__)
|
|
|
|
|
#define HAVE_GCC_DIAGNOSTIC_PRAGMA 1
|
|
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#ifdef _MSC_VER // We use constant comparison for generated code
|
2023-12-04 20:54:11 -08:00
|
|
|
#pragma warning(disable : 6326)
|
|
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#ifdef _MSC_VER // SDL_MAX_SMALL_ALLOC_STACKSIZE is smaller than _ALLOCA_S_THRESHOLD and should be generally safe
|
2023-12-04 20:15:42 -08:00
|
|
|
#pragma warning(disable : 6255)
|
|
|
|
|
#endif
|
2022-11-30 12:51:59 -08:00
|
|
|
#define SDL_MAX_SMALL_ALLOC_STACKSIZE 128
|
|
|
|
|
#define SDL_small_alloc(type, count, pisstack) ((*(pisstack) = ((sizeof(type) * (count)) < SDL_MAX_SMALL_ALLOC_STACKSIZE)), (*(pisstack) ? SDL_stack_alloc(type, count) : (type *)SDL_malloc(sizeof(type) * (count))))
|
|
|
|
|
#define SDL_small_free(ptr, isstack) \
|
|
|
|
|
if ((isstack)) { \
|
|
|
|
|
SDL_stack_free(ptr); \
|
|
|
|
|
} else { \
|
|
|
|
|
SDL_free(ptr); \
|
|
|
|
|
}
|
2018-10-22 20:50:32 -04:00
|
|
|
|
2024-08-22 18:52:00 +02:00
|
|
|
#include "SDL_build_config.h"
|
2023-01-08 00:40:09 +01:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "dynapi/SDL_dynapi.h"
|
|
|
|
|
|
|
|
|
|
#if SDL_DYNAMIC_API
|
|
|
|
|
#include "dynapi/SDL_dynapi_overrides.h"
|
2024-05-17 16:52:36 -07:00
|
|
|
/* force SDL_DECLSPEC off...it's all internal symbols now.
|
2015-06-21 17:33:46 +02:00
|
|
|
These will have actual #defines during SDL_dynapi.c only */
|
2024-05-17 16:52:36 -07:00
|
|
|
#ifdef SDL_DECLSPEC
|
|
|
|
|
#undef SDL_DECLSPEC
|
2023-01-08 00:40:09 +01:00
|
|
|
#endif
|
2024-05-17 16:52:36 -07:00
|
|
|
#define SDL_DECLSPEC
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
2024-01-24 02:40:51 +01:00
|
|
|
#ifdef SDL_PLATFORM_APPLE
|
2022-11-26 01:41:46 -08:00
|
|
|
#ifndef _DARWIN_C_SOURCE
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#define _DARWIN_C_SOURCE 1 // for memset_pattern4()
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
2025-01-14 09:19:39 -08:00
|
|
|
#include <Availability.h>
|
|
|
|
|
|
|
|
|
|
#ifndef __IPHONE_OS_VERSION_MAX_ALLOWED
|
|
|
|
|
#define __IPHONE_OS_VERSION_MAX_ALLOWED 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef __APPLETV_OS_VERSION_MAX_ALLOWED
|
|
|
|
|
#define __APPLETV_OS_VERSION_MAX_ALLOWED 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef __MAC_OS_X_VERSION_MAX_ALLOWED
|
|
|
|
|
#define __MAC_OS_X_VERSION_MAX_ALLOWED 0
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
2025-01-14 09:19:39 -08:00
|
|
|
#endif // SDL_PLATFORM_APPLE
|
2022-11-26 01:41:46 -08:00
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#endif
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef HAVE_STDLIB_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <stdlib.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#elif defined(HAVE_MALLOC_H)
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <malloc.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef HAVE_STDDEF_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <stddef.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef HAVE_STDARG_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <stdarg.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_STRING_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#ifdef HAVE_MEMORY_H
|
|
|
|
|
#include <memory.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <string.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <strings.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_WCHAR_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <wchar.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <inttypes.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#elif defined(HAVE_STDINT_H)
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <stdint.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_MATH_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <math.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_FLOAT_H
|
2022-11-30 12:51:59 -08:00
|
|
|
#include <float.h>
|
2022-11-26 01:41:46 -08:00
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// If you run into a warning that O_CLOEXEC is redefined, update the SDL configuration header for your platform to add HAVE_O_CLOEXEC
|
2021-12-14 12:42:39 -08:00
|
|
|
#ifndef HAVE_O_CLOEXEC
|
2022-11-30 12:51:59 -08:00
|
|
|
#define O_CLOEXEC 0
|
2021-11-27 19:10:10 +03:00
|
|
|
#endif
|
|
|
|
|
|
2022-11-21 20:28:58 -08:00
|
|
|
/* A few #defines to reduce SDL footprint.
|
2024-11-03 10:54:49 +01:00
|
|
|
Only effective when library is statically linked. */
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_0.c'
|
2024-02-11 08:03:26 -08:00
|
|
|
- blit with source bits_per_pixel < 8, palette */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_0) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_0 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_1.c'
|
2024-02-11 08:03:26 -08:00
|
|
|
- blit with source bytes_per_pixel == 1, palette */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_1) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_1 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_A.c'
|
|
|
|
|
- blit with 'SDL_BLENDMODE_BLEND' blending mode */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_A) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_A 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_N.c'
|
|
|
|
|
- blit with COLORKEY mode, or nothing */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_N) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_N 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_N.c'
|
|
|
|
|
- RGB565 conversion with Lookup tables */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_N_RGB565) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_N_RGB565 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Optimized functions from 'SDL_blit_AUTO.c'
|
|
|
|
|
- blit with modulate color, modulate alpha, any blending mode
|
|
|
|
|
- scaling or not */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_BLIT_AUTO) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_BLIT_AUTO 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Run-Length-Encoding
|
2022-12-27 06:36:39 -08:00
|
|
|
- SDL_SetSurfaceColorKey() called with SDL_RLEACCEL flag */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_RLE) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_RLE 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* Software SDL_Renderer
|
|
|
|
|
- creation of software renderer
|
|
|
|
|
- *not* general blitting functions
|
|
|
|
|
- {blend,draw}{fillrect,line,point} internal functions */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_VIDEO_RENDER_SW) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_VIDEO_RENDER_SW 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-22 15:23:44 +01:00
|
|
|
|
|
|
|
|
/* YUV formats
|
|
|
|
|
- handling of YUV surfaces
|
|
|
|
|
- blitting and conversion functions */
|
2024-11-03 10:51:33 +01:00
|
|
|
#if !defined(SDL_HAVE_YUV) && !defined(SDL_LEAN_AND_MEAN)
|
|
|
|
|
#define SDL_HAVE_YUV 1
|
2020-01-23 01:00:52 -08:00
|
|
|
#endif
|
2020-01-21 21:33:40 +01:00
|
|
|
|
2024-09-05 06:37:20 -07:00
|
|
|
#ifdef SDL_RENDER_DISABLED
|
2024-02-15 20:55:02 +03:00
|
|
|
#undef SDL_VIDEO_RENDER_SW
|
|
|
|
|
#undef SDL_VIDEO_RENDER_D3D
|
|
|
|
|
#undef SDL_VIDEO_RENDER_D3D11
|
|
|
|
|
#undef SDL_VIDEO_RENDER_D3D12
|
2024-09-05 06:37:20 -07:00
|
|
|
#undef SDL_VIDEO_RENDER_GPU
|
2024-02-15 20:55:02 +03:00
|
|
|
#undef SDL_VIDEO_RENDER_METAL
|
|
|
|
|
#undef SDL_VIDEO_RENDER_OGL
|
|
|
|
|
#undef SDL_VIDEO_RENDER_OGL_ES2
|
|
|
|
|
#undef SDL_VIDEO_RENDER_PS2
|
|
|
|
|
#undef SDL_VIDEO_RENDER_PSP
|
|
|
|
|
#undef SDL_VIDEO_RENDER_VITA_GXM
|
Vulkan Renderer (#9114)
This pull request adds an implementation of a Vulkan Render backend to SDL. I have so far tested this primarily on Windows, but also smoke tested on Linux and macOS (MoltenVK). I have not tried it yet on Android, but it should be usable there as well (sans any bugs I missed). This began as a port of the SDL Direct3D12 Renderer, which is the closest thing to Vulkan as existed in the SDL codebase. The shaders are more or less identical (with the only differences being in descriptor bindings vs root descriptors). The shaders are built using the HLSL frontend of glslang.
Everything in the code is pure Vulkan 1.0 (no extensions), with the exception of HDR support which requires the Vulkan instance extension `VK_EXT_swapchain_colorspace`. The code could have been simplified considerably if I used dynamic rendering, push descriptors, extended dynamic state, and other modern Vulkan-isms, but I felt it was more important to make the code as vanilla Vulkan as possible so that it would run on any Vulkan implementation.
The main differences with the Direct3D12 renderer are:
* Having to manage renderpasses for performing clears. There is likely some optimization that would still remain for more efficient use of TBDR hardware where there might be some unnecessary load/stores, but it does attempt to do clears using renderpasses.
* Constant buffer data couldn't be directly updated in the command buffer since I didn't want to rely on push descriptors, so there is a persistently mapped buffer with increasing offset per swapchain image where CB data gets written.
* Many more resources are dependent on the swapchain resizing due to i.e. Vulkan requiring the VkFramebuffer to reference the VkImageView of the swapchain, so there is a bit more code around handling that than was necessary in D3D12.
* For NV12/NV21 textures, rather than there being plane data in the texture itself, the UV data is placed in a separate `VkImage`/`VkImageView`.
I've verified that `testcolorspace` works with both sRGB and HDR linear. I've tested `testoverlay` works with the various YUV/NV12/NV21 formats. I've tested `testsprite`. I've checked that window resizing and swapchain out-of-date handling when minimizing are working. I've run through `testautomation` with the render tests. I also have run several of the tests with Vulkan validation and synchronization validation. Surely I will have missed some things, but I think it's in a good state to be merged and build out from here.
2024-02-22 17:58:11 -05:00
|
|
|
#undef SDL_VIDEO_RENDER_VULKAN
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#endif // SDL_RENDER_DISABLED
|
2024-02-15 20:55:02 +03:00
|
|
|
|
2024-09-05 06:37:20 -07:00
|
|
|
#ifdef SDL_GPU_DISABLED
|
|
|
|
|
#undef SDL_GPU_D3D12
|
|
|
|
|
#undef SDL_GPU_METAL
|
|
|
|
|
#undef SDL_GPU_VULKAN
|
|
|
|
|
#undef SDL_VIDEO_RENDER_GPU
|
|
|
|
|
#endif // SDL_GPU_DISABLED
|
2024-02-15 20:55:04 +03:00
|
|
|
|
2024-05-22 20:45:57 -04:00
|
|
|
#if !defined(HAVE_LIBC)
|
|
|
|
|
// If not using _any_ C runtime, these have to be defined before SDL_thread.h
|
2024-05-22 20:53:42 -04:00
|
|
|
// gets included, so internal SDL_CreateThread calls will not try to reference
|
|
|
|
|
// the (unavailable and unneeded) _beginthreadex/_endthreadex functions.
|
2024-05-22 20:45:57 -04:00
|
|
|
#define SDL_BeginThreadFunction NULL
|
|
|
|
|
#define SDL_EndThreadFunction NULL
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-01-09 02:46:19 +01:00
|
|
|
#ifdef SDL_NOLONGLONG
|
|
|
|
|
#error We cannot build a valid SDL3 library without long long support
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-09-30 20:40:54 -07:00
|
|
|
/* Enable internal definitions in SDL API headers */
|
|
|
|
|
#define SDL_INTERNAL
|
|
|
|
|
|
2022-11-26 20:43:38 -08:00
|
|
|
#include <SDL3/SDL.h>
|
2023-01-10 15:50:35 -08:00
|
|
|
#include <SDL3/SDL_intrin.h>
|
2023-02-25 00:21:15 +01:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#define SDL_MAIN_NOIMPL // don't drag in header-only implementation of SDL_main
|
Implement SDL_main as header-only lib for Win32
(remaining platforms will follow)
SDL_main.h is *not* included by SDL.h anymore, users are supposed to
include it directly now, usually only in the file they implement main() in.
If they need the header elsewhere or don't want SDL_main to implement
main() (but only call SDL_SetMainReady() or whatever), they
can #define SDL_MAIN_HANDLED first, same as before.
For SDL-internal usage, I added _SDL_MAIN_NOIMPL, which *also* skips the
implementation and `#define main SDL_main`, but still defines
SDL_MAIN_AVAILABLE and SDL_MAIN_NEEDED in SDL_main.h, as before.
To make the implementaion in the header shorter and avoid including windows.h,
I moved most of the Win32 SDL_main code into SDL3.dll via SDL_Win32RunApp(),
so the header-only part is just the different main functions calling
SDL_Win32RunApp(SDL_main, NULL)
Note that I changed changed the return value and type of OutOfMemory()
to return -1 instead of FALSE, so main() (or WinMain() or whatever)
returns -1 instead of 0 in case of an out-of-memory error
Compared to original Win32 SDL_main, I tweaked the part of the
implementation in SDL_main_impl.h a bit to avoid linker warnings
and conflicts with stuff from windows.h:
- replaced windows.h with own define of WINAPI
and typedef-ing HINSTANCE and LPSTR.
This prevents conflicts between all the generically-named #defines and
types in windows.h and user code (like DrawState in some SDL tests)
- only using one of main() or wmain() gets rid of a MSVC linker error
("warning LNK4067: ambiguous entry point")
If this still causes problems, we might try getting rid of wmain(),
seemed to me like MSVC can use regular main() in UNICODE mode as well
- simplified the UNICODE logic for that - while this is not exactly
equivalent to the old, it should make sense and Works For Me
2022-12-04 03:29:22 +01:00
|
|
|
#include <SDL3/SDL_main.h>
|
2020-04-07 09:38:57 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Set up for C function definitions, even when using C++
|
2022-12-02 08:29:46 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-07-26 18:57:18 -07:00
|
|
|
#include "SDL_utils_c.h"
|
2024-09-30 22:15:38 -07:00
|
|
|
#include "SDL_hashtable.h"
|
2024-07-26 18:57:18 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Do any initialization that needs to happen before threads are started
|
2024-07-12 08:50:15 -07:00
|
|
|
extern void SDL_InitMainThread(void);
|
|
|
|
|
|
2024-07-26 18:57:18 -07:00
|
|
|
/* The internal implementations of these functions have up to nanosecond precision.
|
|
|
|
|
We can expose these functions as part of the API if we want to later.
|
|
|
|
|
*/
|
2024-09-18 07:52:28 -07:00
|
|
|
extern bool SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS);
|
|
|
|
|
extern bool SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS);
|
|
|
|
|
extern bool SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS);
|
2022-12-02 08:29:46 -08:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Ends C function definitions when using C++
|
2022-12-02 08:29:46 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
#endif // SDL_internal_h_
|