SDL_shadercross: Add SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN to opt out of SPIRV roundtrip (#204)

From 1ca46e0ef7a9e50c706e7be6ef73ce467bac3b2e Mon Sep 17 00:00:00 2001
From: Liam <[EMAIL REDACTED]>
Date: Mon, 6 Apr 2026 19:24:14 -0400
Subject: [PATCH] Add SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN to
 opt out of SPIRV roundtrip (#204)

---
 include/SDL3_shadercross/SDL_shadercross.h | 5 ++++-
 src/SDL_shadercross.c                      | 7 ++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/SDL3_shadercross/SDL_shadercross.h b/include/SDL3_shadercross/SDL_shadercross.h
index e0d938d..1e3dc4c 100644
--- a/include/SDL3_shadercross/SDL_shadercross.h
+++ b/include/SDL3_shadercross/SDL_shadercross.h
@@ -113,6 +113,7 @@ typedef struct SDL_ShaderCross_SPIRV_Info
 
 #define SDL_SHADERCROSS_PROP_SPIRV_PSSL_COMPATIBILITY_BOOLEAN "SDL_shadercross.spirv.pssl.compatibility"
 #define SDL_SHADERCROSS_PROP_SPIRV_MSL_VERSION_STRING "SDL_shadercross.spirv.msl.version"
+#define SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN "SDL_shadercross.hlsl.skip_spirv_roundtrip"
 
 typedef struct SDL_ShaderCross_HLSL_Define
 {
@@ -290,8 +291,9 @@ extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_ShaderCross_GetHLSLShaderFor
  * These are the optional properties that can be used:
  *
  * - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
- * - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
+ * - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
  * - `SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN`: When true, indicates that the compiler should not cull unused shader resources. This behavior is disabled by default.
+ * - `SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN`: When true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.
  *
  * \param info a struct describing the shader to transpile.
  * \param size filled in with the bytecode buffer size.
@@ -313,6 +315,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_ShaderCross_CompileDXBCFromHLSL(
  * - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_ENABLE_BOOLEAN`: allows debug info to be emitted when relevant. Should only be used with debugging tools like Renderdoc.
  * - `SDL_SHADERCROSS_PROP_SHADER_DEBUG_NAME_STRING`: a UTF-8 name to be used with the shader. Relevant for use with debugging tools like Renderdoc.
  * - `SDL_SHADERCROSS_PROP_SHADER_CULL_UNUSED_BINDINGS_BOOLEAN`: when true, indicates that the compiler should not cull unused shader resources. This behavior is disabled by default.
+ * - `SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN`: when true, the SPIRV roundtrip is skipped. This behavior is disabled by default. Do not use this property if your shader uses Structured Buffers.
  *
  * \param info a struct describing the shader to transpile.
  * \param size filled in with the bytecode buffer size.
diff --git a/src/SDL_shadercross.c b/src/SDL_shadercross.c
index 40fe1cb..6bbe74f 100644
--- a/src/SDL_shadercross.c
+++ b/src/SDL_shadercross.c
@@ -583,6 +583,11 @@ void *SDL_ShaderCross_CompileDXILFromHLSL(
 #if SDL_PLATFORM_GDK
     return SDL_ShaderCross_INTERNAL_CompileUsingDXC(info, false, size);
 #else
+
+    if (SDL_GetBooleanProperty(info->props, SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN, false)) {
+        return SDL_ShaderCross_INTERNAL_CompileUsingDXC(info, false, size);
+    }
+
     // Roundtrip to SPIR-V to support things like Structured Buffers.
     size_t spirvSize;
     void *spirv = SDL_ShaderCross_CompileSPIRVFromHLSL(
@@ -840,7 +845,7 @@ void *SDL_ShaderCross_CompileDXBCFromHLSL(
 
     return SDL_ShaderCross_INTERNAL_CompileDXBCFromHLSL(
         info,
-        true,
+        !SDL_GetBooleanProperty(info->props, SDL_SHADERCROSS_PROP_HLSL_SKIP_SPIRV_ROUNDTRIP_BOOLEAN, false),
         size);
 }