SDL: Fixed building the Vulkan renderer on Windows with Visual Studio

From b9a00aa88e6fda40df3391c96bff2c37e7ec8e5d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 22 Feb 2024 17:18:46 -0800
Subject: [PATCH] Fixed building the Vulkan renderer on Windows with Visual
 Studio

---
 VisualC/SDL/SDL.vcxproj                       |  5 ++++-
 VisualC/SDL/SDL.vcxproj.filters               | 17 ++++++++++++++++-
 .../build_config/SDL_build_config_windows.h   |  4 ++++
 src/render/vulkan/SDL_render_vulkan.c         | 19 +++++++++----------
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj
index 1a07f3c2fb9e..f011b1f643f7 100644
--- a/VisualC/SDL/SDL.vcxproj
+++ b/VisualC/SDL/SDL.vcxproj
@@ -388,6 +388,7 @@
     <ClInclude Include="..\..\src\render\software\SDL_render_sw_c.h" />
     <ClInclude Include="..\..\src\render\software\SDL_rotate.h" />
     <ClInclude Include="..\..\src\render\software\SDL_triangle.h" />
+    <ClInclude Include="..\..\src\render\vulkan\SDL_shaders_vulkan.h" />
     <ClInclude Include="..\..\src\SDL_assert_c.h" />
     <ClInclude Include="..\..\src\SDL_error_c.h" />
     <ClCompile Include="..\..\src\core\windows\pch.c">
@@ -401,6 +402,8 @@
     <ClCompile Include="..\..\src\camera\SDL_camera.c" />
     <ClCompile Include="..\..\src\main\generic\SDL_sysmain_callbacks.c" />
     <ClCompile Include="..\..\src\main\SDL_main_callbacks.c" />
+    <ClCompile Include="..\..\src\render\vulkan\SDL_render_vulkan.c" />
+    <ClCompile Include="..\..\src\render\vulkan\SDL_shaders_vulkan.c" />
     <ClCompile Include="..\..\src\SDL_guid.c" />
     <ClInclude Include="..\..\src\SDL_hashtable.h" />
     <ClInclude Include="..\..\src\SDL_hints_c.h" />
@@ -690,4 +693,4 @@
   <ImportGroup Label="ExtensionTargets">
     <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters
index 7c0f5190f73a..4f292f1bfc8e 100644
--- a/VisualC/SDL/SDL.vcxproj.filters
+++ b/VisualC/SDL/SDL.vcxproj.filters
@@ -187,6 +187,9 @@
     <Filter Include="camera\mediafoundation">
       <UniqueIdentifier>{0000fbfe2d21e4f451142e7d0e870000}</UniqueIdentifier>
     </Filter>
+    <Filter Include="render\vulkan">
+      <UniqueIdentifier>{5115ba31-20f8-4eab-a8c5-6a572ab78ff7}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\include\SDL3\SDL_begin_code.h">
@@ -853,6 +856,9 @@
     <ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_lsx_func.h" />
     <ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_sse.h" />
     <ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb_std.h" />
+    <ClInclude Include="..\..\src\render\vulkan\SDL_shaders_vulkan.h">
+      <Filter>render\vulkan</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
@@ -1434,8 +1440,17 @@
     <ClCompile Include="..\..\src\video\yuv2rgb\yuv_rgb_lsx.c" />
     <ClCompile Include="..\..\src\video\yuv2rgb\yuv_rgb_sse.c" />
     <ClCompile Include="..\..\src\video\yuv2rgb\yuv_rgb_std.c" />
+    <ClCompile Include="..\..\src\render\vulkan\SDL_render_vulkan.c">
+      <Filter>render\vulkan</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\render\vulkan\SDL_shaders_vulkan.c">
+      <Filter>render\vulkan</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\..\src\core\windows\version.rc" />
   </ItemGroup>
-</Project>
+  <ItemGroup>
+    <MASM Include="..\..\src\stdlib\SDL_mslibc_x64.masm" />
+  </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/include/build_config/SDL_build_config_windows.h b/include/build_config/SDL_build_config_windows.h
index a8d2dc4fd49c..55f4f7c53d3e 100644
--- a/include/build_config/SDL_build_config_windows.h
+++ b/include/build_config/SDL_build_config_windows.h
@@ -305,6 +305,10 @@ typedef unsigned int uintptr_t;
 /* Enable Vulkan support */
 #define SDL_VIDEO_VULKAN 1
 
+#ifndef SDL_VIDEO_RENDER_VULKAN
+#define SDL_VIDEO_RENDER_VULKAN    1
+#endif
+
 /* Enable system power support */
 #define SDL_POWER_WINDOWS 1
 
diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c
index 9fcba37aa936..45808901ccbf 100644
--- a/src/render/vulkan/SDL_render_vulkan.c
+++ b/src/render/vulkan/SDL_render_vulkan.c
@@ -31,13 +31,12 @@
 
 
 #define VK_NO_PROTOTYPES
-#include "SDL_vulkan.h"
-#include "SDL_shaders_vulkan.h"
-#include <vulkan/vulkan.h>
+#include "../../video/SDL_vulkan_internal.h"
+#include "../../video/SDL_sysvideo.h"
 #include "../SDL_sysrender.h"
-#include "../SDL_sysvideo.h"
 #include "../SDL_d3dmath.h"
 #include "../../video/SDL_pixels_c.h"
+#include "SDL_shaders_vulkan.h"
 
 extern const char *SDL_Vulkan_GetResultString(VkResult result);
 
@@ -526,7 +525,7 @@ static void VULKAN_DestroyAll(SDL_Renderer *renderer)
             rendererData->pipelineLayouts[i] = VK_NULL_HANDLE;
         }
     }
-    for (uint32_t i = 0; i < rendererData->pipelineStateCount; i++) {
+    for (int i = 0; i < rendererData->pipelineStateCount; i++) {
         vkDestroyPipeline(rendererData->device, rendererData->pipelineStates[i].pipeline, NULL);
     }
     SDL_free(rendererData->pipelineStates);
@@ -534,7 +533,7 @@ static void VULKAN_DestroyAll(SDL_Renderer *renderer)
 
     if (rendererData->currentUploadBuffer) {
         for (uint32_t i = 0; i < rendererData->swapchainImageCount; ++i) {
-            for (uint32_t j = 0; j < rendererData->currentUploadBuffer[i]; ++j) {
+            for (int j = 0; j < rendererData->currentUploadBuffer[i]; ++j) {
                 VULKAN_DestroyBuffer(rendererData, &rendererData->uploadBuffers[i][j]);
             }
             SDL_free(rendererData->uploadBuffers[i]);
@@ -914,7 +913,7 @@ static void VULKAN_ResetCommandList(VULKAN_RenderData *rendererData)
     rendererData->currentConstantBufferOffset = -1;
 
     /* Release any upload buffers that were inflight */
-    for (uint32_t i = 0; i < rendererData->currentUploadBuffer[rendererData->currentCommandBufferIndex]; ++i) {
+    for (int i = 0; i < rendererData->currentUploadBuffer[rendererData->currentCommandBufferIndex]; ++i) {
         VULKAN_DestroyBuffer(rendererData, &rendererData->uploadBuffers[rendererData->currentCommandBufferIndex][i]);
     }
     rendererData->currentUploadBuffer[rendererData->currentCommandBufferIndex] = 0;
@@ -1843,7 +1842,7 @@ static VkResult VULKAN_CreateFramebuffersAndRenderPasses(SDL_Renderer *renderer,
     framebufferCreateInfo.height = rendererData->swapchainSize.height;
     framebufferCreateInfo.layers = 1;
 
-    for (uint32_t i = 0; i < imageViewCount; i++) {
+    for (int i = 0; i < imageViewCount; i++) {
         framebufferCreateInfo.pAttachments = &imageViews[i];
         result = vkCreateFramebuffer(rendererData->device, &framebufferCreateInfo, NULL, &framebuffers[i]);
         if (result != VK_SUCCESS) {
@@ -3107,7 +3106,7 @@ static SDL_bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderComm
             /* Align the next address to the minUniformBufferOffsetAlignment */
             VkDeviceSize alignment = rendererData->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment;
             SDL_assert(rendererData->currentConstantBufferOffset >= 0 );
-            rendererData->currentConstantBufferOffset += (sizeof(PixelShaderConstants) + alignment - 1) & ~(alignment - 1);
+            rendererData->currentConstantBufferOffset += (int32_t)(sizeof(PixelShaderConstants) + alignment - 1) & ~(alignment - 1);
             constantBufferOffset = rendererData->currentConstantBufferOffset;
         }
 
@@ -3303,7 +3302,7 @@ static SDL_bool VULKAN_SetCopyState(SDL_Renderer *renderer, const SDL_RenderComm
 static void VULKAN_DrawPrimitives(SDL_Renderer *renderer, VkPrimitiveTopology primitiveTopology, const size_t vertexStart, const size_t vertexCount)
 {
     VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->driverdata;
-    vkCmdDraw(rendererData->currentCommandBuffer, vertexCount, 1, vertexStart, 0);
+    vkCmdDraw(rendererData->currentCommandBuffer, (uint32_t)vertexCount, 1, (uint32_t)vertexStart, 0);
 }
 
 static void VULKAN_InvalidateCachedState(SDL_Renderer *renderer)