SDL: d3d12: Move root sigs to D3D12_Shader_Common.hlsli, fix mismatch

From c74f273848b0259c4902c97213f5dc0760aecce9 Mon Sep 17 00:00:00 2001
From: Jade Macho <[EMAIL REDACTED]>
Date: Fri, 1 Mar 2024 18:21:27 +0100
Subject: [PATCH] d3d12: Move root sigs to D3D12_Shader_Common.hlsli, fix
 mismatch

---
 .../D3D12_PixelShader_Advanced.hlsl           | 15 +-------
 .../direct3d12/D3D12_PixelShader_Colors.hlsl  |  9 +----
 ...on.incl => D3D12_PixelShader_Common.hlsli} |  1 +
 .../D3D12_PixelShader_Textures.hlsl           | 11 +-----
 .../direct3d12/D3D12_Shader_Common.hlsli      | 37 ++++++++++++++++++
 src/render/direct3d12/D3D12_VertexShader.hlsl | 38 +------------------
 src/render/direct3d12/SDL_render_d3d12.c      |  2 +-
 7 files changed, 44 insertions(+), 69 deletions(-)
 rename src/render/direct3d12/{D3D12_PixelShader_Common.incl => D3D12_PixelShader_Common.hlsli} (99%)
 create mode 100644 src/render/direct3d12/D3D12_Shader_Common.hlsli

diff --git a/src/render/direct3d12/D3D12_PixelShader_Advanced.hlsl b/src/render/direct3d12/D3D12_PixelShader_Advanced.hlsl
index ac25bb02be453..1c869b85c21f0 100644
--- a/src/render/direct3d12/D3D12_PixelShader_Advanced.hlsl
+++ b/src/render/direct3d12/D3D12_PixelShader_Advanced.hlsl
@@ -1,18 +1,7 @@
 
-#include "D3D12_PixelShader_Common.incl"
+#include "D3D12_PixelShader_Common.hlsli"
 
-#define ADVANCEDRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=24, b1),"\
-    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
-
-[RootSignature(ADVANCEDRS)]
+[RootSignature(AdvancedRS)]
 float4 main(PixelShaderInput input) : SV_TARGET
 {
     return AdvancedPixelShader(input);
diff --git a/src/render/direct3d12/D3D12_PixelShader_Colors.hlsl b/src/render/direct3d12/D3D12_PixelShader_Colors.hlsl
index 4383011f0e3e5..834d6298f1afe 100644
--- a/src/render/direct3d12/D3D12_PixelShader_Colors.hlsl
+++ b/src/render/direct3d12/D3D12_PixelShader_Colors.hlsl
@@ -1,12 +1,5 @@
 
-#include "D3D12_PixelShader_Common.incl"
-
-#define ColorRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=24, b1)"
+#include "D3D12_PixelShader_Common.hlsli"
 
 [RootSignature(ColorRS)]
 float4 main(PixelShaderInput input) : SV_TARGET0
diff --git a/src/render/direct3d12/D3D12_PixelShader_Common.incl b/src/render/direct3d12/D3D12_PixelShader_Common.hlsli
similarity index 99%
rename from src/render/direct3d12/D3D12_PixelShader_Common.incl
rename to src/render/direct3d12/D3D12_PixelShader_Common.hlsli
index 1133c32d9df51..ba32e0c8332f7 100644
--- a/src/render/direct3d12/D3D12_PixelShader_Common.incl
+++ b/src/render/direct3d12/D3D12_PixelShader_Common.hlsli
@@ -1,3 +1,4 @@
+#include "D3D12_Shader_Common.hlsli"
 
 Texture2D texture0 : register(t0);
 Texture2D texture1 : register(t1);
diff --git a/src/render/direct3d12/D3D12_PixelShader_Textures.hlsl b/src/render/direct3d12/D3D12_PixelShader_Textures.hlsl
index 6625744f1aaea..f705742ead9f4 100644
--- a/src/render/direct3d12/D3D12_PixelShader_Textures.hlsl
+++ b/src/render/direct3d12/D3D12_PixelShader_Textures.hlsl
@@ -1,14 +1,5 @@
 
-#include "D3D12_PixelShader_Common.incl"
-
-#define TextureRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=24, b1),"\
-    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
+#include "D3D12_PixelShader_Common.hlsli"
 
 [RootSignature(TextureRS)]
 float4 main(PixelShaderInput input) : SV_TARGET
diff --git a/src/render/direct3d12/D3D12_Shader_Common.hlsli b/src/render/direct3d12/D3D12_Shader_Common.hlsli
new file mode 100644
index 0000000000000..4bf8074de5e38
--- /dev/null
+++ b/src/render/direct3d12/D3D12_Shader_Common.hlsli
@@ -0,0 +1,37 @@
+#pragma pack_matrix( row_major )
+
+cbuffer VertexShaderConstants : register(b0)
+{
+    matrix model;
+    matrix projectionAndView;
+};
+
+#define ColorRS \
+    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
+    "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
+    "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
+    "DENY_HULL_SHADER_ROOT_ACCESS )," \
+    "RootConstants(num32BitConstants=32, b0)," \
+    "RootConstants(num32BitConstants=24, b1)"\
+
+#define TextureRS \
+    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
+    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
+    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
+    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
+    "RootConstants(num32BitConstants=32, b0),"\
+    "RootConstants(num32BitConstants=24, b1),"\
+    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
+    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
+
+#define AdvancedRS \
+    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
+    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
+    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
+    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
+    "RootConstants(num32BitConstants=32, b0),"\
+    "RootConstants(num32BitConstants=24, b1),"\
+    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
+    "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
+    "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\
+    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
diff --git a/src/render/direct3d12/D3D12_VertexShader.hlsl b/src/render/direct3d12/D3D12_VertexShader.hlsl
index ad08992a08e97..c7d24335260fa 100644
--- a/src/render/direct3d12/D3D12_VertexShader.hlsl
+++ b/src/render/direct3d12/D3D12_VertexShader.hlsl
@@ -1,10 +1,4 @@
-#pragma pack_matrix( row_major )
-
-cbuffer VertexShaderConstants : register(b0)
-{
-    matrix model;
-    matrix projectionAndView;
-};
+#include "D3D12_Shader_Common.hlsli"
 
 struct VertexShaderInput
 {
@@ -20,36 +14,6 @@ struct VertexShaderOutput
     float4 color : COLOR0;
 };
 
-#define ColorRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=32, b0)," \
-    "RootConstants(num32BitConstants=20, b1)"\
-
-#define TextureRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=32, b0),"\
-    "RootConstants(num32BitConstants=20, b1),"\
-    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
-
-#define AdvancedRS \
-    "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
-    "            DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
-    "            DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
-    "            DENY_HULL_SHADER_ROOT_ACCESS )," \
-    "RootConstants(num32BitConstants=32, b0),"\
-    "RootConstants(num32BitConstants=20, b1),"\
-    "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\
-    "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
-
 [RootSignature(ColorRS)]
 VertexShaderOutput mainColor(VertexShaderInput input)
 {
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index ef7d7ce2b0ed8..aa9a4fc9da9db 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -90,7 +90,7 @@ typedef struct
     Float4X4 projectionAndView;
 } VertexShaderConstants;
 
-/* These should mirror the definitions in D3D12_PixelShader_Common.incl */
+/* These should mirror the definitions in D3D12_PixelShader_Common.hlsli */
 //static const float TONEMAP_NONE = 0;
 //static const float TONEMAP_LINEAR = 1;
 static const float TONEMAP_CHROME = 2;