From f87e28fbcc4a66f3968429de0fea83c73ec8ef52 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 20 Mar 2025 22:28:19 -0400 Subject: [PATCH] Main func signature Signed-off-by: Isaac Marovitz --- XenosRecomp/shader_recompiler.cpp | 48 +++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/XenosRecomp/shader_recompiler.cpp b/XenosRecomp/shader_recompiler.cpp index b4c6a6c..bb2a45f 100644 --- a/XenosRecomp/shader_recompiler.cpp +++ b/XenosRecomp/shader_recompiler.cpp @@ -1358,7 +1358,22 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi const auto shader = reinterpret_cast(shaderData + shaderContainer->shaderOffset); - out += "#ifndef __spirv__\n"; + out += "#if __air__\n"; + + out += "struct StageIn\n"; + out += "{\n"; + + for (auto& [usage, usageIndex] : INTERPOLATORS) + println("\tfloat4 i{}{};", USAGE_VARIABLES[uint32_t(usage)], usageIndex); + + out += "};\n"; + + if (isPixelShader) + out += "[[fragment]]\n"; + else + out += "[[vertex]]\n"; + + out += "#elifndef __spirv__\n"; if (isPixelShader) out += "[shader(\"pixel\")]\n"; @@ -1367,10 +1382,36 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi out += "#endif\n"; - out += "void main(\n"; + out += "void shaderMain(\n"; if (isPixelShader) { + out += "#ifdef __air__\n"; + + out += "\tStageIn iStageIn [[stage_in]],\n"; + out += "\tfloat4 iPos [[position]],\n"; + out += "\tbool iFace [[front_facing]],\n"; + + auto pixelShader = reinterpret_cast(shader); + if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0) + out += "\tfloat4 oC0 [[color(0)]],\n"; + if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1) + out += "\tfloat4 oC1 [[color(1)]],\n"; + if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR2) + out += "\tfloat4 oC2 [[color(2)]],\n"; + if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR3) + out += "\tfloat4 oC3 [[color(3)]],\n"; + if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH) + out += "\tfloat oDepth [[depth(any)]],\n"; + + out += "\tconstant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]],\n"; + out += "\tconstant Texture3DDescriptorHeap& g_Texture3DDescriptorHeap [[buffer(1)]],\n"; + out += "\tconstant TextureCubeDescriptorHeap& g_TextureCubeDescriptorHeap [[buffer(2)]],\n"; + out += "\tconstant SamplerDescriptorHeap& g_SamplerDescriptorHeap [[buffer(3)]],\n"; + out += "\tconstant PushConstants& g_PushConstants [[buffer(4)]]\n"; + + out += "#else\n"; + out += "\tin float4 iPos : SV_Position,\n"; for (auto& [usage, usageIndex] : INTERPOLATORS) @@ -1382,7 +1423,6 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi out += "\tin uint iFace : SV_IsFrontFace\n"; out += "#endif\n"; - auto pixelShader = reinterpret_cast(shader); if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0) out += ",\n\tout float4 oC0 : SV_Target0"; if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1) @@ -1393,6 +1433,8 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi out += ",\n\tout float4 oC3 : SV_Target3"; if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH) out += ",\n\tout float oDepth : SV_Depth"; + + out += "#endif\n"; } else {