@@ -612,26 +612,29 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
612612 bool closeIfBracket = false ;
613613
614614 std::string_view exportRegister;
615+ bool vectorRegister = true ;
616+
615617 if (instr.exportData )
616618 {
617619 if (isPixelShader)
618620 {
619621 switch (ExportRegister (instr.vectorDest ))
620622 {
621623 case ExportRegister::PSColor0:
622- exportRegister = " oC0" ;
624+ exportRegister = " output. oC0" ;
623625 break ;
624626 case ExportRegister::PSColor1:
625- exportRegister = " oC1" ;
627+ exportRegister = " output. oC1" ;
626628 break ;
627629 case ExportRegister::PSColor2:
628- exportRegister = " oC2" ;
630+ exportRegister = " output. oC2" ;
629631 break ;
630632 case ExportRegister::PSColor3:
631- exportRegister = " oC3" ;
633+ exportRegister = " output. oC3" ;
632634 break ;
633635 case ExportRegister::PSDepth:
634- exportRegister = " oDepth" ;
636+ exportRegister = " output.oDepth" ;
637+ vectorRegister = false ;
635638 break ;
636639 }
637640 }
@@ -707,7 +710,8 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
707710 if (!exportRegister.empty ())
708711 {
709712 out += exportRegister;
710- out += ' .' ;
713+ if (vectorRegister)
714+ out += ' .' ;
711715 }
712716 else
713717 {
@@ -720,7 +724,8 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
720724 {
721725 if ((vectorWriteMask >> i) & 0x1 )
722726 {
723- out += SWIZZLES[i];
727+ if (vectorRegister)
728+ out += SWIZZLES[i];
724729 vectorWriteSize++;
725730 }
726731 }
@@ -1090,7 +1095,8 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
10901095 if (!exportRegister.empty ())
10911096 {
10921097 out += exportRegister;
1093- out += ' .' ;
1098+ if (vectorRegister)
1099+ out += ' .' ;
10941100 }
10951101 else
10961102 {
@@ -1099,7 +1105,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
10991105
11001106 for (size_t i = 0 ; i < 4 ; i++)
11011107 {
1102- if ((scalarWriteMask >> i) & 0x1 )
1108+ if ((( scalarWriteMask >> i) & 0x1 ) && vectorRegister )
11031109 out += SWIZZLES[i];
11041110 }
11051111
@@ -1484,11 +1490,42 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
14841490
14851491 out += " };\n " ;
14861492
1487- if (!isPixelShader)
1493+ println (" struct {}" , isPixelShader ? " PixelShaderOutput" : " Interpolators" );
1494+ out += " {\n " ;
1495+
1496+ if (isPixelShader)
14881497 {
1489- out += " struct Interpolators\n " ;
1490- out += " {\n " ;
1498+ out += " #if __air__\n " ;
14911499
1500+ auto pixelShader = reinterpret_cast <const PixelShader*>(shader);
1501+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0)
1502+ out += " \t float4 oC0 [[color(0)]];\n " ;
1503+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1)
1504+ out += " \t float4 oC1 [[color(1)]];\n " ;
1505+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR2)
1506+ out += " \t float4 oC2 [[color(2)]];\n " ;
1507+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR3)
1508+ out += " \t float4 oC3 [[color(3)]];\n " ;
1509+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH)
1510+ out += " \t float oDepth [[depth(any)]];\n " ;
1511+
1512+ out += " #else\n " ;
1513+
1514+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0)
1515+ out += " \t float4 oC0 : SV_Target0;\n " ;
1516+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1)
1517+ out += " \t float4 oC1 : SV_Target1;\n " ;
1518+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR2)
1519+ out += " \t float4 oC2 : SV_Target2;\n " ;
1520+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR3)
1521+ out += " \t float4 oC3 : SV_Target3;\n " ;
1522+ if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH)
1523+ out += " \t float oDepth : SV_Depth;\n " ;
1524+
1525+ out += " #endif\n " ;
1526+ }
1527+ else
1528+ {
14921529 out += " #if __air__\n " ;
14931530
14941531 out += " \t float4 oPos [[position]];\n " ;
@@ -1504,10 +1541,10 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
15041541 print (" \t float4 o{0}{1} : {2}{1};\n " , USAGE_VARIABLES[uint32_t (usage)], usageIndex, USAGE_SEMANTICS[uint32_t (usage)]);
15051542
15061543 out += " #endif\n " ;
1507-
1508- out += " };\n " ;
15091544 }
15101545
1546+ out += " };\n " ;
1547+
15111548 out += " #ifdef __air__\n " ;
15121549
15131550 if (isPixelShader)
@@ -1524,7 +1561,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
15241561
15251562 out += " #endif\n " ;
15261563
1527- println (" {} shaderMain(" , isPixelShader ? " void " : " Interpolators" );
1564+ println (" {} shaderMain(" , isPixelShader ? " PixelShaderOutput " : " Interpolators" );
15281565
15291566 if (isPixelShader)
15301567 {
@@ -1534,18 +1571,6 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
15341571 out += " \t float4 iPos [[position]],\n " ;
15351572 out += " \t bool iFace [[front_facing]],\n " ;
15361573
1537- auto pixelShader = reinterpret_cast <const PixelShader*>(shader);
1538- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0)
1539- out += " \t float4 oC0 [[color(0)]],\n " ;
1540- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1)
1541- out += " \t float4 oC1 [[color(1)]],\n " ;
1542- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR2)
1543- out += " \t float4 oC2 [[color(2)]],\n " ;
1544- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR3)
1545- out += " \t float4 oC3 [[color(3)]],\n " ;
1546- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH)
1547- out += " \t float oDepth [[depth(any)]],\n " ;
1548-
15491574 out += " \t constant Texture2DDescriptorHeap& g_Texture2DDescriptorHeap [[buffer(0)]],\n " ;
15501575 out += " \t constant Texture3DDescriptorHeap& g_Texture3DDescriptorHeap [[buffer(1)]],\n " ;
15511576 out += " \t constant TextureCubeDescriptorHeap& g_TextureCubeDescriptorHeap [[buffer(2)]],\n " ;
@@ -1563,17 +1588,6 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
15631588 out += " \t in uint iFace : SV_IsFrontFace\n " ;
15641589 out += " #endif\n " ;
15651590
1566- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR0)
1567- out += " ,\n\t out float4 oC0 : SV_Target0" ;
1568- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR1)
1569- out += " ,\n\t out float4 oC1 : SV_Target1" ;
1570- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR2)
1571- out += " ,\n\t out float4 oC2 : SV_Target2" ;
1572- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_COLOR3)
1573- out += " ,\n\t out float4 oC3 : SV_Target3" ;
1574- if (pixelShader->outputs & PIXEL_SHADER_OUTPUT_DEPTH)
1575- out += " ,\n\t out float oDepth : SV_Depth" ;
1576-
15771591 out += " \n #endif\n " ;
15781592 }
15791593 else
@@ -1605,14 +1619,13 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
16051619
16061620#ifdef UNLEASHED_RECOMP
16071621
1608- if (!isPixelShader)
1609- {
1610- out += " #ifdef __air__\n " ;
1611- out += " \t Interpolators output = Interpolators{};\n " ;
1612- out += " #else\n " ;
1613- out += " \t Interpolators output = (Interpolators)0;\n " ;
1614- out += " #endif\n " ;
1615- }
1622+ std::string outputName = isPixelShader ? " PixelShaderOutput" : " Interpolators" ;
1623+
1624+ out += " #ifdef __air__\n " ;
1625+ println (" \t {0} output = {0}{{}};" , outputName);
1626+ out += " #else\n " ;
1627+ println (" \t {0} output = ({0})0;" , outputName);
1628+ out += " #endif\n " ;
16161629
16171630 if (hasMtxProjection)
16181631 {
@@ -2070,7 +2083,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
20702083 out += " {\n " ;
20712084
20722085 indent ();
2073- out += " \t clip(oC0.w - g_AlphaThreshold);\n " ;
2086+ out += " \t clip(output. oC0.w - g_AlphaThreshold);\n " ;
20742087
20752088 indent ();
20762089 out += " }\n " ;
@@ -2084,9 +2097,9 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
20842097 out += " {\n " ;
20852098
20862099 indent ();
2087- out += " \t oC0 .w *= 1.0 + computeMipLevel(pixelCoord) * 0.25;\n " ;
2100+ out += " \t output.oC0 .w *= 1.0 + computeMipLevel(pixelCoord) * 0.25;\n " ;
20882101 indent ();
2089- out += " \t oC0. w = 0.5 + (oC0.w - g_AlphaThreshold) / max(fwidth(oC0.w), 1e-6);\n " ;
2102+ out += " \t output.oC0. w = 0.5 + (output. oC0.w - g_AlphaThreshold) / max(fwidth(output. oC0.w), 1e-6);\n " ;
20902103
20912104 indent ();
20922105 out += " }\n " ;
@@ -2104,10 +2117,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
21042117 else
21052118 #endif
21062119 {
2107- if (isPixelShader)
2108- out += " return;\n " ;
2109- else
2110- out += " return output;\n " ;
2120+ out += " return output;\n " ;
21112121 }
21122122 }
21132123 else
@@ -2141,8 +2151,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
21412151 out += " \t }\n " ;
21422152#endif
21432153
2144- if (!isPixelShader)
2145- out += " \t return output;\n " ;
2154+ out += " \t return output;\n " ;
21462155
21472156 out += " }" ;
21482157}
0 commit comments