SDL: Fixed build warnings (35dad)

From 35dadda3272d480a44464663f1d071b2bae112ea Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 2 Sep 2024 16:53:30 -0700
Subject: [PATCH] Fixed build warnings

---
 src/gpu/d3d11/SDL_gpu_d3d11.c        |  4 ++--
 src/gpu/d3d12/SDL_gpu_d3d12.c        | 20 ++++++++++----------
 src/gpu/vulkan/SDL_gpu_vulkan.c      |  7 ++++---
 src/render/sdlgpu/SDL_pipeline_gpu.c |  6 ++++--
 src/render/sdlgpu/SDL_render_gpu.c   | 12 ++++++++----
 5 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/gpu/d3d11/SDL_gpu_d3d11.c b/src/gpu/d3d11/SDL_gpu_d3d11.c
index f59630eab5632..ce1129ca8fe89 100644
--- a/src/gpu/d3d11/SDL_gpu_d3d11.c
+++ b/src/gpu/d3d11/SDL_gpu_d3d11.c
@@ -2061,7 +2061,7 @@ static D3D11Texture *D3D11_INTERNAL_CreateTexture(
                 desc2D.MipLevels = 1;
                 desc2D.MiscFlags = 0;
                 desc2D.SampleDesc.Count = SDLToD3D11_SampleCount[createInfo->sampleCount];
-                desc2D.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
+                desc2D.SampleDesc.Quality = (UINT)D3D11_STANDARD_MULTISAMPLE_PATTERN;
                 desc2D.Usage = D3D11_USAGE_DEFAULT;
 
                 res = ID3D11Device_CreateTexture2D(
@@ -5232,7 +5232,7 @@ static SDL_GPUTexture *D3D11_AcquireSwapchainTexture(
     IDXGISwapChain_GetDesc(windowData->swapchain, &swapchainDesc);
     SDL_GetWindowSize(window, &w, &h);
 
-    if (w != swapchainDesc.BufferDesc.Width || h != swapchainDesc.BufferDesc.Height) {
+    if ((UINT)w != swapchainDesc.BufferDesc.Width || (UINT)h != swapchainDesc.BufferDesc.Height) {
         res = D3D11_INTERNAL_ResizeSwapchain(
             renderer,
             windowData,
diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index fbd270b69298f..196cf8434dede 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -786,11 +786,11 @@ typedef struct D3D12ComputeRootSignature
 {
     ID3D12RootSignature *handle;
 
-    Uint32 readOnlyStorageTextureRootIndex;
-    Uint32 readOnlyStorageBufferRootIndex;
-    Uint32 writeOnlyStorageTextureRootIndex;
-    Uint32 writeOnlyStorageBufferRootIndex;
-    Uint32 uniformBufferRootIndex[MAX_UNIFORM_BUFFERS_PER_STAGE];
+    Sint32 readOnlyStorageTextureRootIndex;
+    Sint32 readOnlyStorageBufferRootIndex;
+    Sint32 writeOnlyStorageTextureRootIndex;
+    Sint32 writeOnlyStorageBufferRootIndex;
+    Sint32 uniformBufferRootIndex[MAX_UNIFORM_BUFFERS_PER_STAGE];
 } D3D12ComputeRootSignature;
 
 struct D3D12ComputePipeline
@@ -2745,8 +2745,8 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
         desc.Alignment = isSwapchainTexture ? 0 : D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
         desc.Width = textureCreateInfo->width;
         desc.Height = textureCreateInfo->height;
-        desc.DepthOrArraySize = textureCreateInfo->layerCountOrDepth;
-        desc.MipLevels = textureCreateInfo->levelCount;
+        desc.DepthOrArraySize = (UINT16)textureCreateInfo->layerCountOrDepth;
+        desc.MipLevels = (UINT16)textureCreateInfo->levelCount;
         desc.Format = SDLToD3D12_TextureFormat[textureCreateInfo->format];
         desc.SampleDesc.Count = 1;
         desc.SampleDesc.Quality = 0;
@@ -2757,8 +2757,8 @@ static D3D12Texture *D3D12_INTERNAL_CreateTexture(
         desc.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT;
         desc.Width = textureCreateInfo->width;
         desc.Height = textureCreateInfo->height;
-        desc.DepthOrArraySize = textureCreateInfo->layerCountOrDepth;
-        desc.MipLevels = textureCreateInfo->levelCount;
+        desc.DepthOrArraySize = (UINT16)textureCreateInfo->layerCountOrDepth;
+        desc.MipLevels = (UINT16)textureCreateInfo->levelCount;
         desc.Format = SDLToD3D12_TextureFormat[textureCreateInfo->format];
         desc.SampleDesc.Count = 1;
         desc.SampleDesc.Quality = 0;
@@ -6105,7 +6105,7 @@ static bool D3D12_INTERNAL_ResizeSwapchainIfNeeded(
     IDXGISwapChain_GetDesc(windowData->swapchain, &swapchainDesc);
     SDL_GetWindowSize(windowData->window, &w, &h);
 
-    if (w != swapchainDesc.BufferDesc.Width || h != swapchainDesc.BufferDesc.Height) {
+    if ((UINT)w != swapchainDesc.BufferDesc.Width || (UINT)h != swapchainDesc.BufferDesc.Height) {
         // Wait so we don't release in-flight views
         D3D12_Wait((SDL_GPURenderer *)renderer);
 
diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c
index de236b79ad5ed..3fb23be1a76b7 100644
--- a/src/gpu/vulkan/SDL_gpu_vulkan.c
+++ b/src/gpu/vulkan/SDL_gpu_vulkan.c
@@ -1514,7 +1514,7 @@ static void VULKAN_INTERNAL_NewMemoryFreeRegion(
         }
 
         // perform insertion sort
-        if (allocation->allocator->sortedFreeRegionCount > 0 && insertionIndex != allocation->allocator->sortedFreeRegionCount) {
+        if (allocation->allocator->sortedFreeRegionCount > 0 && (Uint32)insertionIndex != allocation->allocator->sortedFreeRegionCount) {
             for (Sint32 i = allocation->allocator->sortedFreeRegionCount; i > insertionIndex && i > 0; i -= 1) {
                 allocation->allocator->sortedFreeRegions[i] = allocation->allocator->sortedFreeRegions[i - 1];
                 allocation->allocator->sortedFreeRegions[i]->sortedIndex = i;
@@ -1955,7 +1955,7 @@ static Uint8 VULKAN_INTERNAL_BindResourceMemory(
     VulkanMemoryUsedRegion *usedRegion;
 
     VkDeviceSize requiredSize, allocationSize;
-    VkDeviceSize alignedOffset;
+    VkDeviceSize alignedOffset = 0;
     VkDeviceSize newRegionSize, newRegionOffset;
     Uint8 isHostVisible, smallAllocation, allocationResult;
     Sint32 i;
@@ -11272,7 +11272,8 @@ static Uint8 VULKAN_INTERNAL_DeterminePhysicalDevice(VulkanRenderer *renderer)
     VkResult vulkanResult;
     VkPhysicalDevice *physicalDevices;
     VulkanExtensions *physicalDeviceExtensions;
-    Uint32 physicalDeviceCount, i, suitableIndex;
+    Uint32 i, physicalDeviceCount;
+    Sint32 suitableIndex;
     Uint32 queueFamilyIndex, suitableQueueFamilyIndex;
     Uint8 deviceRank, highestRank;
 
diff --git a/src/render/sdlgpu/SDL_pipeline_gpu.c b/src/render/sdlgpu/SDL_pipeline_gpu.c
index a079aa18ed58b..03ed62b13db31 100644
--- a/src/render/sdlgpu/SDL_pipeline_gpu.c
+++ b/src/render/sdlgpu/SDL_pipeline_gpu.c
@@ -84,8 +84,10 @@ bool GPU_InitPipelineCache(GPU_PipelineCache *cache, SDL_GPUDevice *device)
 {
     // FIXME how many buckets do we need?
     cache->table = SDL_CreateHashTable(device, 32, HashPassthrough, MatchPipelineCacheKey, NukePipelineCacheEntry, true);
-
-    return (bool)cache->table;
+    if (!cache->table) {
+        return false;
+    }
+    return true;
 }
 
 void GPU_DestroyPipelineCache(GPU_PipelineCache *cache)
diff --git a/src/render/sdlgpu/SDL_render_gpu.c b/src/render/sdlgpu/SDL_render_gpu.c
index a67f1583212cc..737a63007f424 100644
--- a/src/render/sdlgpu/SDL_render_gpu.c
+++ b/src/render/sdlgpu/SDL_render_gpu.c
@@ -248,12 +248,16 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
     GPU_TextureData *data = (GPU_TextureData *)texture->internal;
     const Uint32 texturebpp = SDL_BYTESPERPIXEL(texture->format);
 
-    Uint32 row_size = texturebpp * rect->w;
-    Uint32 data_size = row_size * rect->h;
+    size_t row_size, data_size;
+
+    if (!SDL_size_mul_check_overflow(rect->w, texturebpp, &row_size) ||
+        !SDL_size_mul_check_overflow(rect->h, row_size, &data_size)) {
+        return SDL_SetError("update size overflow"); 
+    }
 
     SDL_GPUTransferBufferCreateInfo tbci;
     SDL_zero(tbci);
-    tbci.sizeInBytes = data_size;
+    tbci.sizeInBytes = (Uint32)data_size;
     tbci.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
 
     SDL_GPUTransferBuffer *tbuf = SDL_CreateGPUTransferBuffer(renderdata->device, &tbci);
@@ -264,7 +268,7 @@ static bool GPU_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
 
     Uint8 *output = SDL_MapGPUTransferBuffer(renderdata->device, tbuf, false);
 
-    if (pitch == row_size) {
+    if ((size_t)pitch == row_size) {
         memcpy(output, pixels, data_size);
     } else {
         // FIXME is negative pitch supposed to work?