Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
This commit is contained in:
Isaac Marovitz 2025-03-16 15:38:37 -04:00
parent f328cbbec8
commit 6153094d1f
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
2 changed files with 29 additions and 45 deletions

View file

@ -161,6 +161,30 @@ float2 getWeights2D(uint resourceDescriptorIndex, uint samplerDescriptorIndex, f
#endif #endif
#ifdef __air__
#define selectWrapper(a, b, c) select(c, b, a)
#else
#define selectWrapper(a, b, c) select(a, b, c)
#endif
#ifdef __air__
#define frac(X) fract(X)
template<typename T>
void clip(T a)
{
if (a < 0.0) {
discard_fragment();
}
}
template<typename T>
void rcp(T a)
{
return 1.0 / a;
}
#endif
float w0(float a) float w0(float a)
{ {
return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f); return (1.0f / 6.0f) * (a * (a * (-a + 3.0f) - 3.0f) + 1.0f);

View file

@ -556,38 +556,22 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
{ {
case AluVectorOpcode::KillEq: case AluVectorOpcode::KillEq:
indent(); indent();
#ifdef XENOS_RECOMP_AIR
println("if (any({} == {})) discard_fragment();", op(VECTOR_0), op(VECTOR_1));
#else
println("clip(any({} == {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1)); println("clip(any({} == {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1));
#endif
break; break;
case AluVectorOpcode::KillGt: case AluVectorOpcode::KillGt:
indent(); indent();
#ifdef XENOS_RECOMP_AIR
println("if (any({} > {})) discard_fragment();", op(VECTOR_0), op(VECTOR_1));
#else
println("clip(any({} > {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1)); println("clip(any({} > {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1));
#endif
break; break;
case AluVectorOpcode::KillGe: case AluVectorOpcode::KillGe:
indent(); indent();
#ifdef XENOS_RECOMP_AIR
println("if (any({} >= {})) discard_fragment();", op(VECTOR_0), op(VECTOR_1));
#else
println("clip(any({} >= {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1)); println("clip(any({} >= {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1));
#endif
break; break;
case AluVectorOpcode::KillNe: case AluVectorOpcode::KillNe:
indent(); indent();
#ifdef XENOS_RECOMP_AIR
println("if (any({} != {})) discard_fragment();", op(VECTOR_0), op(VECTOR_1));
#else
println("clip(any({} != {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1)); println("clip(any({} != {}) ? -1 : 1);", op(VECTOR_0), op(VECTOR_1));
#endif
break; break;
} }
@ -743,11 +727,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
break; break;
case AluVectorOpcode::Frc: case AluVectorOpcode::Frc:
#ifdef XENOS_RECOMP_AIR
print("fract({})", op(VECTOR_0));
#else
print("frac({})", op(VECTOR_0)); print("frac({})", op(VECTOR_0));
#endif
break; break;
case AluVectorOpcode::Trunc: case AluVectorOpcode::Trunc:
@ -763,15 +743,15 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
break; break;
case AluVectorOpcode::CndEq: case AluVectorOpcode::CndEq:
print("select({} == 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2)); print("selectWrapper({} == 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2));
break; break;
case AluVectorOpcode::CndGe: case AluVectorOpcode::CndGe:
print("select({} >= 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2)); print("selectWrapper({} >= 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2));
break; break;
case AluVectorOpcode::CndGt: case AluVectorOpcode::CndGt:
print("select({} > 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2)); print("selectWrapper({} > 0.0, {}, {})", op(VECTOR_0), op(VECTOR_1), op(VECTOR_2));
break; break;
case AluVectorOpcode::Dp4: case AluVectorOpcode::Dp4:
@ -815,11 +795,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
break; break;
case AluVectorOpcode::Dst: case AluVectorOpcode::Dst:
#ifdef XENOS_RECOMP_AIR
print("distance({}, {})", op(VECTOR_0), op(VECTOR_1));
#else
print("dst({}, {})", op(VECTOR_0), op(VECTOR_1)); print("dst({}, {})", op(VECTOR_0), op(VECTOR_1));
#endif
break; break;
} }
@ -925,11 +901,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
break; break;
case AluScalarOpcode::Frcs: case AluScalarOpcode::Frcs:
#ifdef XENOS_RECOMP_AIR
print("fract({})", op(SCALAR_0));
#else
print("frac({})", op(SCALAR_0)); print("frac({})", op(SCALAR_0));
#endif
break; break;
case AluScalarOpcode::Truncs: case AluScalarOpcode::Truncs:
@ -952,11 +924,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
case AluScalarOpcode::Rcpc: case AluScalarOpcode::Rcpc:
case AluScalarOpcode::Rcpf: case AluScalarOpcode::Rcpf:
case AluScalarOpcode::Rcp: case AluScalarOpcode::Rcp:
#ifdef XENOS_RECOMP_AIR
print("clamp((1.0 / {}), FLT_MIN, FLT_MAX)", op(SCALAR_0));
#else
print("clamp(rcp({}), FLT_MIN, FLT_MAX)", op(SCALAR_0)); print("clamp(rcp({}), FLT_MIN, FLT_MAX)", op(SCALAR_0));
#endif
break; break;
case AluScalarOpcode::Rsqc: case AluScalarOpcode::Rsqc:
@ -1112,11 +1080,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr)
if (instr.scalarOpcode >= AluScalarOpcode::KillsEq && instr.scalarOpcode <= AluScalarOpcode::KillsOne) if (instr.scalarOpcode >= AluScalarOpcode::KillsEq && instr.scalarOpcode <= AluScalarOpcode::KillsOne)
{ {
indent(); indent();
#ifdef XENOS_RECOMP_AIR
out += "if (ps != 0.0) discard_fragment();\n";
#else
out += "clip(ps != 0.0 ? -1 : 1);\n"; out += "clip(ps != 0.0 ? -1 : 1);\n";
#endif
} }
if (closeIfBracket) if (closeIfBracket)
@ -1190,7 +1154,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
{ {
uint32_t tailCount = (isPixelShader ? 224 : 256) - constantInfo->registerIndex; uint32_t tailCount = (isPixelShader ? 224 : 256) - constantInfo->registerIndex;
println("#define {}(INDEX) select((INDEX) < {}, vk::RawBufferLoad<float4>(g_PushConstants.{}ShaderConstants + ({} + min(INDEX, {})) * 16, 0x10), 0.0)", println("#define {}(INDEX) selectWrapper((INDEX) < {}, vk::RawBufferLoad<float4>(g_PushConstants.{}ShaderConstants + ({} + min(INDEX, {})) * 16, 0x10), 0.0)",
constantName, tailCount, shaderName, constantInfo->registerIndex.get(), tailCount - 1); constantName, tailCount, shaderName, constantInfo->registerIndex.get(), tailCount - 1);
} }
else else
@ -1247,7 +1211,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
if (constantInfo->registerCount > 1) if (constantInfo->registerCount > 1)
{ {
uint32_t tailCount = (isPixelShader ? 224 : 256) - constantInfo->registerIndex; uint32_t tailCount = (isPixelShader ? 224 : 256) - constantInfo->registerIndex;
println("#define {0}(INDEX) select((INDEX) < {1}, {0}[min(INDEX, {2})], 0.0)", constantName, tailCount, tailCount - 1); println("#define {0}(INDEX) selectWrapper((INDEX) < {1}, {0}[min(INDEX, {2})], 0.0)", constantName, tailCount, tailCount - 1);
} }
} }
} }
@ -1848,11 +1812,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData, const std::string_vi
indent(); indent();
#ifdef XENOS_RECOMP_AIR
out += "\tif ((oC0.w - g_AlphaThreshold) < 0.0) discard_fragment();\n";
#else
out += "\tclip(oC0.w - g_AlphaThreshold);\n"; out += "\tclip(oC0.w - g_AlphaThreshold);\n";
#endif
indent(); indent();
out += "}"; out += "}";