fix: mesh shader errors

This commit is contained in:
Samuliak 2024-08-20 09:52:54 +02:00
parent b10bcd422e
commit 46269c0069
2 changed files with 30 additions and 18 deletions

View File

@ -2822,13 +2822,12 @@ static void _emitGSReadInputVFetchCode(LatteDecompilerShaderContext* shaderConte
src->add(" = "); src->add(" = ");
_emitTypeConversionPrefixMSL(shaderContext, LATTE_DECOMPILER_DTYPE_SIGNED_INT, shaderContext->typeTracker.defaultDataType); _emitTypeConversionPrefixMSL(shaderContext, LATTE_DECOMPILER_DTYPE_SIGNED_INT, shaderContext->typeTracker.defaultDataType);
src->add("(objectPayload["); src->add("(in[");
if (texInstruction->textureFetch.srcSel[0] >= 4) if (texInstruction->textureFetch.srcSel[0] >= 4)
cemu_assert_unimplemented(); cemu_assert_unimplemented();
if (texInstruction->textureFetch.srcSel[1] >= 4) if (texInstruction->textureFetch.srcSel[1] >= 4)
cemu_assert_unimplemented(); cemu_assert_unimplemented();
// todo: Index type src->add("vertexIndex");
src->add("0");
src->addFmt("].passParameterSem{}.", texInstruction->textureFetch.offset/16); src->addFmt("].passParameterSem{}.", texInstruction->textureFetch.offset/16);
@ -3588,9 +3587,10 @@ 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);
// emit vertex // Emit vertex (if the vertex index matches thread id)
src->add("mesh.set_vertex(out);" _CRLF); src->add("mesh.set_vertex(vertexIndex, out);" _CRLF);
src->add("mesh.set_index(tid, tid);" _CRLF); src->add("mesh.set_index(vertexIndex, vertexIndex);" _CRLF);
src->add("vertexIndex++;" _CRLF);
// increment transform feedback pointer // increment transform feedback pointer
for (sint32 i = 0; i < LATTE_NUM_STREAMOUT_BUFFER; i++) for (sint32 i = 0; i < LATTE_NUM_STREAMOUT_BUFFER; i++)
{ {
@ -3859,7 +3859,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
} }
break; break;
case LatteConst::ShaderType::Geometry: case LatteConst::ShaderType::Geometry:
functionType = "[[mesh, max_total_threads_per_threadgroup(MAX_THREADS_PER_THREADGROUP)]]"; functionType = "[[mesh, max_total_threads_per_threadgroup(1)]]";
outputTypeName = "void"; outputTypeName = "void";
break; break;
case LatteConst::ShaderType::Pixel: case LatteConst::ShaderType::Pixel:
@ -3886,7 +3886,11 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
} }
else else
{ {
// Input is defined as object payload
src->add("object_data VertexOut* in = objectPayload.vertexOut;" _CRLF);
src->add("GeometryOut out;" _CRLF); src->add("GeometryOut out;" _CRLF);
// The index of the current vertex that is being emitted
src->add("uint vertexIndex = 0;" _CRLF);
} }
} }
else else
@ -4132,20 +4136,29 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
if (shader->shaderType == LatteConst::ShaderType::Vertex && shaderContext->options->usesGeometryShader == false) if (shader->shaderType == LatteConst::ShaderType::Vertex && shaderContext->options->usesGeometryShader == false)
src->add("out.pointSize = supportBuffer.pointSize;" _CRLF); src->add("out.pointSize = supportBuffer.pointSize;" _CRLF);
} }
// TODO: this should be handled outside of the shader, because clipping currently wouldn't work (or would it?)
if (shader->shaderType == LatteConst::ShaderType::Vertex)
src->add("out.position.z = (out.position.z + out.position.w) / 2.0;" _CRLF);
if (shader->shaderType == LatteConst::ShaderType::Vertex && shaderContext->options->usesGeometryShader) if (shaderContext->options->usesGeometryShader)
{
if (shader->shaderType == LatteConst::ShaderType::Vertex)
{ {
src->add("if (tid == 0) {" _CRLF); src->add("if (tid == 0) {" _CRLF);
src->add("meshGridProperties.set_threadgroups_per_grid(uint3(1, 1, 1));" _CRLF); src->add("meshGridProperties.set_threadgroups_per_grid(uint3(1, 1, 1));" _CRLF);
src->add("}" _CRLF); src->add("}" _CRLF);
} }
}
else
{
if (shader->shaderType == LatteConst::ShaderType::Vertex)
{
// TODO: this should be handled outside of the shader, because clipping currently wouldn't work (or would it?)
if (shader->shaderType == LatteConst::ShaderType::Vertex)
src->add("out.position.z = (out.position.z + out.position.w) / 2.0;" _CRLF);
}
// return // Return
if (!shaderContext->options->usesGeometryShader)
src->add("return out;" _CRLF); src->add("return out;" _CRLF);
}
// end of shader main // end of shader main
src->add("}" _CRLF); src->add("}" _CRLF);
src->shrink_to_fit(); src->shrink_to_fit();

View File

@ -290,7 +290,6 @@ namespace LatteDecompiler
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex || decompilerContext->shaderType == LatteConst::ShaderType::Geometry) if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex || decompilerContext->shaderType == LatteConst::ShaderType::Geometry)
{ {
src->add("struct VertexOut {" _CRLF); src->add("struct VertexOut {" _CRLF);
src->add("float4 position [[position]];" _CRLF);
uint32 ringParameterCountVS2GS = 0; uint32 ringParameterCountVS2GS = 0;
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex) if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex)
{ {