Cleaned up various type conversion issues

This makes sure SDL_PixelFormatEnum flows through the internal code correctly, as well as fixing a number of other minor issues.
This commit is contained in:
Sam Lantinga
2024-03-07 05:20:20 -08:00
parent f53bdc9531
commit 33eaddc565
85 changed files with 391 additions and 369 deletions

View File

@@ -368,7 +368,7 @@ static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer)
renderer->render_commands_pool = retval->next;
retval->next = NULL;
} else {
retval = SDL_calloc(1, sizeof(*retval));
retval = (SDL_RenderCommand *)SDL_calloc(1, sizeof(*retval));
if (!retval) {
return NULL;
}
@@ -897,8 +897,8 @@ static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Wind
SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
{
#ifndef SDL_RENDER_DISABLED
SDL_Window *window = SDL_GetProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, NULL);
SDL_Surface *surface = SDL_GetProperty(props, SDL_PROP_RENDERER_CREATE_SURFACE_POINTER, NULL);
SDL_Window *window = (SDL_Window *)SDL_GetProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, NULL);
SDL_Surface *surface = (SDL_Surface *)SDL_GetProperty(props, SDL_PROP_RENDERER_CREATE_SURFACE_POINTER, NULL);
const char *name = SDL_GetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, NULL);
SDL_Renderer *renderer = NULL;
const int n = SDL_GetNumRenderDrivers();
@@ -1238,7 +1238,7 @@ static Uint32 GetClosestSupportedFormat(SDL_Renderer *renderer, Uint32 format)
SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_PropertiesID props)
{
SDL_Texture *texture;
Uint32 format = (Uint32)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
SDL_PixelFormatEnum format = (SDL_PixelFormatEnum)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN);
int access = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_ACCESS_NUMBER, SDL_TEXTUREACCESS_STATIC);
int w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, 0);
int h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, 0);
@@ -1399,7 +1399,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
SDL_bool needAlpha;
SDL_bool direct_update;
int i;
Uint32 format = SDL_PIXELFORMAT_UNKNOWN;
SDL_PixelFormatEnum format = SDL_PIXELFORMAT_UNKNOWN;
SDL_Texture *texture;
SDL_PropertiesID surface_props, props;
SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN;
@@ -2359,7 +2359,7 @@ SDL_Texture *SDL_GetRenderTarget(SDL_Renderer *renderer)
if (renderer->target == renderer->logical_target) {
return NULL;
} else {
return SDL_GetProperty(SDL_GetTextureProperties(renderer->target), SDL_PROP_TEXTURE_PARENT_POINTER, renderer->target);
return (SDL_Texture *)SDL_GetProperty(SDL_GetTextureProperties(renderer->target), SDL_PROP_TEXTURE_PARENT_POINTER, renderer->target);
}
}
@@ -4084,7 +4084,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
s.h *= -1;
s.y -= s.h;
}
SDL_RenderTextureRotated(renderer, texture, &s, &d, 0, NULL, flags);
SDL_RenderTextureRotated(renderer, texture, &s, &d, 0, NULL, (SDL_FlipMode)flags);
}
#if DEBUG_SW_RENDER_GEOMETRY

View File

@@ -66,7 +66,7 @@ struct SDL_Texture
SDL_Colorspace colorspace; /**< The colorspace of the texture */
float SDR_white_point; /**< The SDR white point for this content */
float HDR_headroom; /**< The HDR headroom needed by this content */
Uint32 format; /**< The pixel format of the texture */
SDL_PixelFormatEnum format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */

View File

@@ -27,7 +27,7 @@
#include "SDL_yuv_sw_c.h"
#include "../video/SDL_yuv_c.h"
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormatEnum format, int w, int h)
{
SDL_SW_YUVTexture *swdata;
@@ -212,6 +212,8 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
}
}
}
default:
return SDL_SetError("Unsupported YUV format");
}
return 0;
}
@@ -316,6 +318,8 @@ int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
return SDL_SetError("YV12, IYUV, NV12, NV21 textures only support full surface locks");
}
break;
default:
return SDL_SetError("Unsupported YUV format");
}
if (rect) {
@@ -332,7 +336,7 @@ void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata)
}
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
Uint32 target_format, int w, int h, void *pixels,
SDL_PixelFormatEnum target_format, int w, int h, void *pixels,
int pitch)
{
int stretch;

View File

@@ -28,8 +28,8 @@
struct SDL_SW_YUVTexture
{
Uint32 format;
Uint32 target_format;
SDL_PixelFormatEnum format;
SDL_PixelFormatEnum target_format;
int w, h;
Uint8 *pixels;
@@ -44,7 +44,7 @@ struct SDL_SW_YUVTexture
typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture;
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h);
SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormatEnum format, int w, int h);
int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels,
int *pitch);
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
@@ -60,7 +60,7 @@ int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
void **pixels, int *pitch);
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata);
int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
Uint32 target_format, int w, int h, void *pixels,
SDL_PixelFormatEnum target_format, int w, int h, void *pixels,
int pitch);
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata);

View File

@@ -209,7 +209,7 @@ static D3DFORMAT PixelFormatToD3DFMT(Uint32 format)
}
}
static Uint32 D3DFMTToPixelFormat(D3DFORMAT format)
static SDL_PixelFormatEnum D3DFMTToPixelFormat(D3DFORMAT format)
{
switch (format) {
case D3DFMT_R5G6B5:
@@ -1552,7 +1552,7 @@ static int D3D_Reset(SDL_Renderer *renderer)
static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync)
{
D3D_RenderData *data = renderer->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
if (vsync) {
data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;

View File

@@ -242,7 +242,7 @@ static const GUID SDL_DXGI_DEBUG_ALL = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe
#pragma GCC diagnostic pop
#endif
Uint32 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
SDL_PixelFormatEnum D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat) {
case DXGI_FORMAT_B8G8R8A8_UNORM:

View File

@@ -303,12 +303,12 @@ static const GUID SDL_IID_ID3D12InfoQueue = { 0x0742a90b, 0xc387, 0x483f, { 0xb9
#pragma GCC diagnostic pop
#endif
UINT D3D12_Align(UINT location, UINT alignment)
static UINT D3D12_Align(UINT location, UINT alignment)
{
return (location + (alignment - 1)) & ~(alignment - 1);
}
Uint32 D3D12_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
static SDL_PixelFormatEnum D3D12_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
{
switch (dxgiFormat) {
case DXGI_FORMAT_B8G8R8A8_UNORM:

View File

@@ -281,7 +281,7 @@ static void APIENTRY GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id
if (type == GL_DEBUG_TYPE_ERROR_ARB) {
/* Record this error */
int errors = data->errors + 1;
char **error_messages = SDL_realloc(data->error_messages, errors * sizeof(*data->error_messages));
char **error_messages = (char **)SDL_realloc(data->error_messages, errors * sizeof(*data->error_messages));
if (error_messages) {
data->errors = errors;
data->error_messages = error_messages;
@@ -310,7 +310,7 @@ static GL_FBOList *GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h)
}
if (!result) {
result = SDL_malloc(sizeof(GL_FBOList));
result = (GL_FBOList *)SDL_malloc(sizeof(GL_FBOList));
if (result) {
result->w = w;
result->h = h;
@@ -1451,7 +1451,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
GL_RenderData *data = (GL_RenderData *)renderer->driverdata;
Uint32 format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
GLint internalFormat;
GLenum targetFormat, type;
int w, h;

View File

@@ -165,7 +165,7 @@ typedef struct
typedef struct GLES2_RenderData
{
SDL_GLContext *context;
SDL_GLContext context;
SDL_bool debug_enabled;
@@ -289,7 +289,7 @@ static GLES2_FBOList *GLES2_GetFBO(GLES2_RenderData *data, Uint32 w, Uint32 h)
result = result->next;
}
if (!result) {
result = SDL_malloc(sizeof(GLES2_FBOList));
result = (GLES2_FBOList *)SDL_malloc(sizeof(GLES2_FBOList));
result->w = w;
result->h = h;
data->glGenFramebuffers(1, &result->FBO);
@@ -1051,6 +1051,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
case SDL_PIXELFORMAT_BGRX32:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
default:
break;
}
break;
case SDL_PIXELFORMAT_RGBA32:
@@ -1062,6 +1064,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
case SDL_PIXELFORMAT_RGBX32:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
default:
break;
}
break;
case SDL_PIXELFORMAT_BGRX32:
@@ -1075,6 +1079,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
case SDL_PIXELFORMAT_RGBX32:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
default:
break;
}
break;
case SDL_PIXELFORMAT_RGBX32:
@@ -1088,6 +1094,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo
case SDL_PIXELFORMAT_BGRX32:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
default:
break;
}
break;
#if SDL_HAVE_YUV
@@ -1628,7 +1636,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER, data->texture_type);
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
data->fbo = GLES2_GetFBO(renderer->driverdata, texture->w, texture->h);
data->fbo = GLES2_GetFBO((GLES2_RenderData *)renderer->driverdata, texture->w, texture->h);
} else {
data->fbo = NULL;
}
@@ -1959,7 +1967,7 @@ static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
{
GLES2_RenderData *data = (GLES2_RenderData *)renderer->driverdata;
Uint32 format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
int w, h;
SDL_Surface *surface;

View File

@@ -112,20 +112,17 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
g = (Uint8)SDL_roundf(SDL_clamp(texture->color.g, 0.0f, 1.0f) * 255.0f);
b = (Uint8)SDL_roundf(SDL_clamp(texture->color.b, 0.0f, 1.0f) * 255.0f);
a = (Uint8)SDL_roundf(SDL_clamp(texture->color.a, 0.0f, 1.0f) * 255.0f);
SDL_SetSurfaceColorMod(texture->driverdata, r, g, b);
SDL_SetSurfaceAlphaMod(texture->driverdata, a);
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
SDL_SetSurfaceColorMod(surface, r, g, b);
SDL_SetSurfaceAlphaMod(surface, a);
SDL_SetSurfaceBlendMode(surface, texture->blendMode);
/* Only RLE encode textures without an alpha channel since the RLE coder
* discards the color values of pixels with an alpha value of zero.
*/
if (texture->access == SDL_TEXTUREACCESS_STATIC && !surface->format->Amask) {
SDL_SetSurfaceRLE(texture->driverdata, 1);
SDL_SetSurfaceRLE(surface, 1);
}
if (!texture->driverdata) {
return -1;
}
return 0;
}
@@ -1024,7 +1021,7 @@ static void SW_DestroyRenderer(SDL_Renderer *renderer)
SDL_free(renderer);
}
static void SW_SelectBestFormats(SDL_Renderer *renderer, Uint32 format)
static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormatEnum format)
{
/* Prefer the format used by the framebuffer by default. */
renderer->info.texture_formats[renderer->info.num_texture_formats++] = format;
@@ -1080,6 +1077,8 @@ static void SW_SelectBestFormats(SDL_Renderer *renderer, Uint32 format)
case SDL_PIXELFORMAT_BGRA8888:
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_BGRX8888;
break;
default:
break;
}
/* Ensure that we always have a SDL_PACKEDLAYOUT_8888 format. Having a matching component order increases the

View File

@@ -278,7 +278,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
if (blend != SDL_BLENDMODE_NONE) {
int format = dst->format->format;
SDL_PixelFormatEnum format = dst->format->format;
/* need an alpha format */
if (!dst->format->Amask) {
@@ -300,7 +300,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
SDL_SetSurfaceBlendMode(tmp, blend);
dstbpp = tmp->format->bytes_per_pixel;
dst_ptr = tmp->pixels;
dst_ptr = (Uint8 *)tmp->pixels;
dst_pitch = tmp->pitch;
} else {
@@ -465,7 +465,7 @@ int SDL_SW_BlitTriangle(
Uint8 *dst_ptr;
int dst_pitch;
int *src_ptr;
const int *src_ptr;
int src_pitch;
Sint64 area, tmp64;
@@ -583,7 +583,7 @@ int SDL_SW_BlitTriangle(
dst_pitch = dst->pitch;
/* Set source pointer */
src_ptr = src->pixels;
src_ptr = (const int *)src->pixels;
src_pitch = src->pitch;
is_clockwise = area > 0;

View File

@@ -365,7 +365,7 @@ typedef struct
SDL_bool issueBatch;
} VULKAN_RenderData;
Uint32 VULKAN_VkFormatToSDLPixelFormat(VkFormat vkFormat)
static SDL_PixelFormatEnum VULKAN_VkFormatToSDLPixelFormat(VkFormat vkFormat)
{
switch (vkFormat) {
case VK_FORMAT_B8G8R8A8_UNORM:
@@ -379,7 +379,7 @@ Uint32 VULKAN_VkFormatToSDLPixelFormat(VkFormat vkFormat)
}
}
Uint32 VULKAN_VkFormatGetNumPlanes(VkFormat vkFormat)
static int VULKAN_VkFormatGetNumPlanes(VkFormat vkFormat)
{
switch (vkFormat) {
case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
@@ -392,7 +392,7 @@ Uint32 VULKAN_VkFormatGetNumPlanes(VkFormat vkFormat)
}
}
VkDeviceSize VULKAN_GetBytesPerPixel(VkFormat vkFormat)
static VkDeviceSize VULKAN_GetBytesPerPixel(VkFormat vkFormat)
{
switch (vkFormat) {
case VK_FORMAT_R8_UNORM:
@@ -1482,7 +1482,7 @@ static VkResult VULKAN_FindPhysicalDevice(VULKAN_RenderData *rendererData)
if (deviceExtensionsAllocatedSize < deviceExtensionCount) {
SDL_free(deviceExtensions);
deviceExtensionsAllocatedSize = deviceExtensionCount;
deviceExtensions = SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize);
deviceExtensions = (VkExtensionProperties *)SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize);
if (!deviceExtensions) {
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
@@ -1573,7 +1573,7 @@ static SDL_bool VULKAN_DeviceExtensionsFound(VULKAN_RenderData *rendererData, in
return SDL_FALSE;
}
if (extensionCount > 0 ) {
VkExtensionProperties *extensionProperties = SDL_calloc(sizeof(VkExtensionProperties), extensionCount);
VkExtensionProperties *extensionProperties = (VkExtensionProperties *)SDL_calloc(sizeof(VkExtensionProperties), extensionCount);
result = vkEnumerateDeviceExtensionProperties(rendererData->physicalDevice, NULL, &extensionCount, extensionProperties);
if (result != VK_SUCCESS ) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkEnumerateDeviceExtensionProperties): %s.\n", SDL_Vulkan_GetResultString(result));
@@ -1606,7 +1606,7 @@ static SDL_bool VULKAN_InstanceExtensionFound(VULKAN_RenderData *rendererData, c
return SDL_FALSE;
}
if (extensionCount > 0 ) {
VkExtensionProperties *extensionProperties = SDL_calloc(extensionCount, sizeof(VkExtensionProperties));
VkExtensionProperties *extensionProperties = (VkExtensionProperties *)SDL_calloc(extensionCount, sizeof(VkExtensionProperties));
result = vkEnumerateInstanceExtensionProperties(NULL, &extensionCount, extensionProperties);
if (result != VK_SUCCESS ) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkEnumerateInstanceExtensionProperties( NULL, ... ): %s.\n", SDL_Vulkan_GetResultString(result));
@@ -1633,7 +1633,7 @@ static SDL_bool VULKAN_ValidationLayersFound()
vkEnumerateInstanceLayerProperties(&instanceLayerCount, NULL);
if (instanceLayerCount > 0) {
VkLayerProperties *instanceLayers = SDL_calloc(instanceLayerCount, sizeof(VkLayerProperties));
VkLayerProperties *instanceLayers = (VkLayerProperties *)SDL_calloc(instanceLayerCount, sizeof(VkLayerProperties));
vkEnumerateInstanceLayerProperties(&instanceLayerCount, instanceLayers);
for (i = 0; i < instanceLayerCount; i++) {
if (!SDL_strcmp(SDL_VULKAN_VALIDATION_LAYER_NAME, instanceLayers[i].layerName)) {
@@ -1690,7 +1690,8 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert
renderer->output_colorspace == SDL_COLORSPACE_HDR10) {
rendererData->supportsEXTSwapchainColorspace = VULKAN_InstanceExtensionFound(rendererData, VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME);
if (!rendererData->supportsEXTSwapchainColorspace) {
return SDL_SetError("[Vulkan] Using HDR output but %s not supported", VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME);
SDL_SetError("[Vulkan] Using HDR output but %s not supported", VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME);
return VK_ERROR_UNKNOWN;
}
}
@@ -1710,7 +1711,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert
instanceCreateInfo.pApplicationInfo = &appInfo;
char const *const *instanceExtensions = SDL_Vulkan_GetInstanceExtensions(&instanceCreateInfo.enabledExtensionCount);
const char **instanceExtensionsCopy = SDL_calloc(instanceCreateInfo.enabledExtensionCount + 2, sizeof(const char *));
const char **instanceExtensionsCopy = (const char **)SDL_calloc(instanceCreateInfo.enabledExtensionCount + 2, sizeof(const char *));
for (uint32_t i = 0; i < instanceCreateInfo.enabledExtensionCount; i++) {
instanceExtensionsCopy[i] = instanceExtensions[i];
}
@@ -1855,16 +1856,17 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert
/* Create shaders / layouts */
for (uint32_t i = 0; i < NUM_SHADERS; i++) {
VULKAN_Shader shader = (VULKAN_Shader)i;
VkShaderModuleCreateInfo shaderModuleCreateInfo = { 0 };
shaderModuleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
VULKAN_GetVertexShader(i, &shaderModuleCreateInfo.pCode, &shaderModuleCreateInfo.codeSize);
VULKAN_GetVertexShader(shader, &shaderModuleCreateInfo.pCode, &shaderModuleCreateInfo.codeSize);
result = vkCreateShaderModule(rendererData->device, &shaderModuleCreateInfo, NULL, &rendererData->vertexShaderModules[i]);
if (result != VK_SUCCESS) {
VULKAN_DestroyAll(renderer);
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkCreateShaderModule(): %s\n", SDL_Vulkan_GetResultString(result));
return result;
}
VULKAN_GetPixelShader(i, &shaderModuleCreateInfo.pCode, &shaderModuleCreateInfo.codeSize);
VULKAN_GetPixelShader(shader, &shaderModuleCreateInfo.pCode, &shaderModuleCreateInfo.codeSize);
result = vkCreateShaderModule(rendererData->device, &shaderModuleCreateInfo, NULL, &rendererData->fragmentShaderModules[i]);
if (result != VK_SUCCESS) {
VULKAN_DestroyAll(renderer);
@@ -1944,7 +1946,7 @@ static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer,
attachmentDescription.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescription.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescription.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescription.samples = 1;
attachmentDescription.samples = VK_SAMPLE_COUNT_1_BIT;
attachmentDescription.flags = 0;
VkAttachmentReference colorAttachmentReference = { 0 };
@@ -2084,7 +2086,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
return result;
}
if (presentModeCount > 0) {
VkPresentModeKHR *presentModes = SDL_calloc(presentModeCount, sizeof(VkPresentModeKHR));
VkPresentModeKHR *presentModes = (VkPresentModeKHR *)SDL_calloc(presentModeCount, sizeof(VkPresentModeKHR));
result = vkGetPhysicalDeviceSurfacePresentModesKHR(rendererData->physicalDevice, rendererData->surface, &presentModeCount, presentModes);
if (result != VK_SUCCESS) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkGetPhysicalDeviceSurfacePresentModesKHR(): %s\n", SDL_Vulkan_GetResultString(result));
@@ -2150,7 +2152,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
return result;
}
rendererData->swapchainImages = SDL_malloc(sizeof(VkImage) * rendererData->swapchainImageCount);
rendererData->swapchainImages = (VkImage *)SDL_malloc(sizeof(VkImage) * rendererData->swapchainImageCount);
result = vkGetSwapchainImagesKHR(rendererData->device,
rendererData->swapchain,
&rendererData->swapchainImageCount,
@@ -2185,9 +2187,9 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
}
SDL_free(rendererData->swapchainImageViews);
}
rendererData->swapchainImageViews = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkImageView));
rendererData->swapchainImageViews = (VkImageView *)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkImageView));
SDL_free(rendererData->swapchainImageLayouts);
rendererData->swapchainImageLayouts = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkImageLayout));
rendererData->swapchainImageLayouts = (VkImageLayout *)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkImageLayout));
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
imageViewCreateInfo.image = rendererData->swapchainImages[i];
result = vkCreateImageView(rendererData->device, &imageViewCreateInfo, NULL, &rendererData->swapchainImageViews[i]);
@@ -2212,7 +2214,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
rendererData->currentCommandBuffer = VK_NULL_HANDLE;
rendererData->currentCommandBufferIndex = 0;
}
rendererData->commandBuffers = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkCommandBuffer));
rendererData->commandBuffers = (VkCommandBuffer *)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkCommandBuffer));
result = vkAllocateCommandBuffers(rendererData->device, &commandBufferAllocateInfo, rendererData->commandBuffers);
if (result != VK_SUCCESS) {
VULKAN_DestroyAll(renderer);
@@ -2229,7 +2231,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
}
SDL_free(rendererData->fences);
}
rendererData->fences = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkFence));
rendererData->fences = (VkFence *)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkFence));
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
VkFenceCreateInfo fenceCreateInfo = { 0 };
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
@@ -2257,7 +2259,7 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
rendererData->renderPasses[i] = VK_NULL_HANDLE;
}
}
rendererData->framebuffers = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkFramebuffer));
rendererData->framebuffers = (VkFramebuffer *)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkFramebuffer));
result = VULKAN_CreateFramebuffersAndRenderPasses(renderer,
rendererData->swapchainSize.width,
rendererData->swapchainSize.height,
@@ -2286,12 +2288,12 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
SDL_free(rendererData->descriptorPools);
SDL_free(rendererData->numDescriptorPools);
}
rendererData->descriptorPools = SDL_calloc(rendererData->swapchainImageCount, sizeof(VkDescriptorPool*));
rendererData->numDescriptorPools = SDL_calloc(rendererData->swapchainImageCount, sizeof(uint32_t));
rendererData->descriptorPools = (VkDescriptorPool **)SDL_calloc(rendererData->swapchainImageCount, sizeof(VkDescriptorPool*));
rendererData->numDescriptorPools = (uint32_t *)SDL_calloc(rendererData->swapchainImageCount, sizeof(uint32_t));
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
/* Start by just allocating one pool, it will grow if needed */
rendererData->numDescriptorPools[i] = 1;
rendererData->descriptorPools[i] = SDL_calloc(1, sizeof(VkDescriptorPool));
rendererData->descriptorPools[i] = (VkDescriptorPool *)SDL_calloc(1, sizeof(VkDescriptorPool));
rendererData->descriptorPools[i][0] = VULKAN_AllocateDescriptorPool(rendererData);
if (result != VK_SUCCESS) {
VULKAN_DestroyAll(renderer);
@@ -2316,8 +2318,8 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
}
SDL_free(rendererData->renderingFinishedSemaphores);
}
rendererData->imageAvailableSemaphores = SDL_calloc(sizeof(VkSemaphore), rendererData->swapchainImageCount);
rendererData->renderingFinishedSemaphores = SDL_calloc(sizeof(VkSemaphore), rendererData->swapchainImageCount);
rendererData->imageAvailableSemaphores = (VkSemaphore *)SDL_calloc(sizeof(VkSemaphore), rendererData->swapchainImageCount);
rendererData->renderingFinishedSemaphores = (VkSemaphore *)SDL_calloc(sizeof(VkSemaphore), rendererData->swapchainImageCount);
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
rendererData->imageAvailableSemaphores[i] = VULKAN_CreateSemaphore(rendererData);
if (rendererData->imageAvailableSemaphores[i] == VK_NULL_HANDLE) {
@@ -2341,12 +2343,12 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
}
SDL_free(rendererData->uploadBuffers);
}
rendererData->uploadBuffers = SDL_calloc(rendererData->swapchainImageCount, sizeof(VULKAN_Buffer*));
rendererData->uploadBuffers = (VULKAN_Buffer **)SDL_calloc(rendererData->swapchainImageCount, sizeof(VULKAN_Buffer*));
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
rendererData->uploadBuffers[i] = SDL_calloc(SDL_VULKAN_NUM_UPLOAD_BUFFERS, sizeof(VULKAN_Buffer));
rendererData->uploadBuffers[i] = (VULKAN_Buffer *)SDL_calloc(SDL_VULKAN_NUM_UPLOAD_BUFFERS, sizeof(VULKAN_Buffer));
}
SDL_free(rendererData->currentUploadBuffer);
rendererData->currentUploadBuffer = SDL_calloc(rendererData->swapchainImageCount, sizeof(int));
rendererData->currentUploadBuffer = (int *)SDL_calloc(rendererData->swapchainImageCount, sizeof(int));
/* Constant buffers */
if (rendererData->constantBuffers) {
@@ -2361,12 +2363,12 @@ static VkResult VULKAN_CreateSwapChain(SDL_Renderer *renderer, int w, int h)
SDL_free(rendererData->numConstantBuffers);
rendererData->constantBuffers = NULL;
}
rendererData->constantBuffers = SDL_calloc(rendererData->swapchainImageCount, sizeof(VULKAN_Buffer*));
rendererData->numConstantBuffers = SDL_calloc(rendererData->swapchainImageCount, sizeof(VULKAN_Buffer*));
rendererData->constantBuffers = (VULKAN_Buffer **)SDL_calloc(rendererData->swapchainImageCount, sizeof(VULKAN_Buffer*));
rendererData->numConstantBuffers = (uint32_t *)SDL_calloc(rendererData->swapchainImageCount, sizeof(uint32_t));
for (uint32_t i = 0; i < rendererData->swapchainImageCount; i++) {
/* Start with just allocating one, will grow if needed */
rendererData->numConstantBuffers[i] = 1;
rendererData->constantBuffers[i] = SDL_calloc(1, sizeof(VULKAN_Buffer));
rendererData->constantBuffers[i] = (VULKAN_Buffer *)SDL_calloc(1, sizeof(VULKAN_Buffer));
result = VULKAN_AllocateBuffer(rendererData,
SDL_VULKAN_CONSTANT_BUFFER_DEFAULT_SIZE,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
@@ -2697,7 +2699,7 @@ static VkResult VULKAN_UpdateTextureInternal(VULKAN_RenderData *rendererData, Vk
const Uint8 *src;
Uint8 *dst;
VkResult result;
Uint32 planeCount = VULKAN_VkFormatGetNumPlanes(format);
int planeCount = VULKAN_VkFormatGetNumPlanes(format);
VULKAN_EnsureCommandBuffer(rendererData);
@@ -2715,7 +2717,7 @@ static VkResult VULKAN_UpdateTextureInternal(VULKAN_RenderData *rendererData, Vk
}
src = (const Uint8 *)pixels;
dst = uploadBuffer->mappedBufferPtr;
dst = (Uint8 *)uploadBuffer->mappedBufferPtr;
if (length == (VkDeviceSize)pitch) {
SDL_memcpy(dst, src, (size_t)length * h);
} else {
@@ -2778,7 +2780,7 @@ static VkResult VULKAN_UpdateTextureInternal(VULKAN_RenderData *rendererData, Vk
VULKAN_IssueBatch(rendererData);
}
return 0;
return VK_SUCCESS;
}
@@ -3381,7 +3383,7 @@ static VkDescriptorSet VULKAN_AllocateDescriptorSet(SDL_Renderer *renderer, VULK
return VK_NULL_HANDLE;
}
rendererData->numDescriptorPools[rendererData->currentCommandBufferIndex]++;
VkDescriptorPool *descriptorPools = SDL_realloc(rendererData->descriptorPools[rendererData->currentCommandBufferIndex],
VkDescriptorPool *descriptorPools = (VkDescriptorPool *)SDL_realloc(rendererData->descriptorPools[rendererData->currentCommandBufferIndex],
sizeof(VkDescriptorPool) * rendererData->numDescriptorPools[rendererData->currentCommandBufferIndex]);
descriptorPools[rendererData->numDescriptorPools[rendererData->currentCommandBufferIndex] - 1] = descriptorPool;
rendererData->descriptorPools[rendererData->currentCommandBufferIndex] = descriptorPools;
@@ -3550,7 +3552,7 @@ static SDL_bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderComm
}
rendererData->numConstantBuffers[rendererData->currentCommandBufferIndex]++;
VULKAN_Buffer *newConstantBuffers = SDL_realloc(rendererData->constantBuffers[rendererData->currentCommandBufferIndex],
VULKAN_Buffer *newConstantBuffers = (VULKAN_Buffer *)SDL_realloc(rendererData->constantBuffers[rendererData->currentCommandBufferIndex],
sizeof(VULKAN_Buffer) * rendererData->numConstantBuffers[rendererData->currentCommandBufferIndex]);
newConstantBuffers[rendererData->numConstantBuffers[rendererData->currentCommandBufferIndex] - 1] = newConstantBuffer;
rendererData->constantBuffers[rendererData->currentCommandBufferIndex] = newConstantBuffers;
@@ -3564,7 +3566,7 @@ static SDL_bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderComm
SDL_memcpy(&rendererData->currentPipelineState->shader_constants, shader_constants, sizeof(*shader_constants));
/* Upload constants to persistently mapped buffer */
uint8_t *dst = rendererData->constantBuffers[rendererData->currentCommandBufferIndex][rendererData->currentConstantBufferIndex].mappedBufferPtr;
uint8_t *dst = (uint8_t *)rendererData->constantBuffers[rendererData->currentCommandBufferIndex][rendererData->currentConstantBufferIndex].mappedBufferPtr;
dst += constantBufferOffset;
SDL_memcpy(dst, &rendererData->currentPipelineState->shader_constants, sizeof(PixelShaderConstants));
}

View File

@@ -47,13 +47,13 @@ static struct
void VULKAN_GetVertexShader(VULKAN_Shader shader, const uint32_t **outBytecode, size_t *outSize)
{
*outBytecode = VULKAN_shaders[shader].vs_shader_data;
*outBytecode = (const uint32_t *)VULKAN_shaders[shader].vs_shader_data;
*outSize = VULKAN_shaders[shader].vs_shader_size;
}
void VULKAN_GetPixelShader(VULKAN_Shader shader, const uint32_t **outBytecode, size_t *outSize)
{
*outBytecode = VULKAN_shaders[shader].ps_shader_data;
*outBytecode = (const uint32_t *)VULKAN_shaders[shader].ps_shader_data;
*outSize = VULKAN_shaders[shader].ps_shader_size;
}