Main func signature

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
This commit is contained in:
Isaac Marovitz 2025-03-20 22:28:19 -04:00
parent 347fee997c
commit f87e28fbcc
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1

View file

@ -1358,7 +1358,22 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
const auto shader = reinterpret_cast<const Shader*>(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<const PixelShader*>(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<const PixelShader*>(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
{