handle halfZ in the shader decompiler

This commit is contained in:
Samuliak 2024-11-15 17:01:21 +01:00
parent d732416569
commit 38cbd3e03a
No known key found for this signature in database
2 changed files with 11 additions and 11 deletions

View File

@ -3123,13 +3123,13 @@ static void _emitExportCode(LatteDecompilerShaderContext* shaderContext, LatteDe
_emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, 0); _emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, 0);
src->add(";" _CRLF); src->add(";" _CRLF);
src->add("finalPos.xy = finalPos.xy * supportBuffer.windowSpaceToClipSpaceTransform - float2(1.0,1.0);"); src->add("finalPos.xy = finalPos.xy * supportBuffer.windowSpaceToClipSpaceTransform - float2(1.0,1.0);");
src->add("out.position = finalPos;"); src->add("SET_POSITION(finalPos);");
} }
else else
{ {
src->add("out.position = "); src->add("SET_POSITION(");
_emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, 0); _emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, 0);
src->add(";" _CRLF); src->add(");" _CRLF);
} }
} }
else if (cfInstruction->exportType == 1 && cfInstruction->exportArrayBase == GPU7_DECOMPILER_CF_EXPORT_POINT_SIZE ) else if (cfInstruction->exportType == 1 && cfInstruction->exportArrayBase == GPU7_DECOMPILER_CF_EXPORT_POINT_SIZE )
@ -3371,7 +3371,7 @@ static void _emitCFRingWriteCode(LatteDecompilerShaderContext* shaderContext, La
src->addFmt(" = "); src->addFmt(" = ");
_emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, burstIndex); _emitExportGPRReadCode(shaderContext, cfInstruction, LATTE_DECOMPILER_DTYPE_FLOAT, burstIndex);
src->add(";" _CRLF); src->add(";" _CRLF);
src->add("out.position = pos;" _CRLF); src->add("SET_POSITION(pos);" _CRLF);
src->add("}" _CRLF); src->add("}" _CRLF);
} }
else if (parameterExportType == 2 && parameterExportBase < 16) else if (parameterExportType == 2 && parameterExportBase < 16)
@ -3609,7 +3609,6 @@ void LatteDecompiler_emitClauseCodeMSL(LatteDecompilerShaderContext* shaderConte
// write point size // write point size
if (shaderContext->analyzer.outputPointSize && shaderContext->analyzer.writesPointSize == false) if (shaderContext->analyzer.outputPointSize && shaderContext->analyzer.writesPointSize == false)
src->add("out.pointSize = supportBuffer.pointSize;" _CRLF); src->add("out.pointSize = supportBuffer.pointSize;" _CRLF);
//src->add("out.position.z = (out.position.z + out.position.w) / 2.0;" _CRLF);
src->add("mesh.set_vertex(vertexIndex, out);" _CRLF); src->add("mesh.set_vertex(vertexIndex, out);" _CRLF);
src->add("vertexIndex++;" _CRLF); src->add("vertexIndex++;" _CRLF);
// increment transform feedback pointer // increment transform feedback pointer
@ -4376,14 +4375,10 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
} }
} }
if (rasterizationEnabled) if (rasterizationEnabled && (!usesGeometryShader || shader->shaderType == LatteConst::ShaderType::Pixel))
{ {
//if (shader->shaderType == LatteConst::ShaderType::Vertex && !shaderContext->options->usesGeometryShader)
// src->add("out.position.z = (out.position.z + out.position.w) / 2.0;" _CRLF);
// Return // Return
if (!usesGeometryShader || shader->shaderType == LatteConst::ShaderType::Pixel) src->add("return out;" _CRLF);
src->add("return out;" _CRLF);
} }
// end of shader main // end of shader main

View File

@ -392,6 +392,11 @@ namespace LatteDecompiler
} }
} }
if (decompilerContext->contextRegistersNew->PA_CL_CLIP_CNTL.get_DX_CLIP_SPACE_DEF())
src->add("#define SET_POSITION(_v) out.position = _v" _CRLF);
else
src->add("#define SET_POSITION(_v) out.position = _v; out.position.z = (out.position.z + out.position.w) / 2.0" _CRLF);
const bool dump_shaders_enabled = ActiveSettings::DumpShadersEnabled(); const bool dump_shaders_enabled = ActiveSettings::DumpShadersEnabled();
if(dump_shaders_enabled) if(dump_shaders_enabled)
decompilerContext->shaderSource->add("// start of shader inputs/outputs, predetermined by Cemu. Do not touch" _CRLF); decompilerContext->shaderSource->add("// start of shader inputs/outputs, predetermined by Cemu. Do not touch" _CRLF);