mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-03 13:31:18 +12:00
shader-decompiler: fix disabled rasterization errors
This commit is contained in:
parent
bddf3159ee
commit
b59d134e03
2 changed files with 21 additions and 35 deletions
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#define _CRLF "\r\n"
|
#define _CRLF "\r\n"
|
||||||
|
|
||||||
static bool rasterizationEnabled;
|
|
||||||
|
|
||||||
void LatteDecompiler_emitAttributeDecodeMSL(LatteDecompilerShader* shaderContext, StringBuf* src, LatteParsedFetchShaderAttribute_t* attrib);
|
void LatteDecompiler_emitAttributeDecodeMSL(LatteDecompilerShader* shaderContext, StringBuf* src, LatteParsedFetchShaderAttribute_t* attrib);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3182,9 +3180,6 @@ static void _emitExportGPRReadCode(LatteDecompilerShaderContext* shaderContext,
|
||||||
|
|
||||||
static void _emitExportCode(LatteDecompilerShaderContext* shaderContext, LatteDecompilerCFInstruction* cfInstruction)
|
static void _emitExportCode(LatteDecompilerShaderContext* shaderContext, LatteDecompilerCFInstruction* cfInstruction)
|
||||||
{
|
{
|
||||||
if (!rasterizationEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
StringBuf* src = shaderContext->shaderSource;
|
StringBuf* src = shaderContext->shaderSource;
|
||||||
src->add("// export" _CRLF);
|
src->add("// export" _CRLF);
|
||||||
if(shaderContext->shaderType == LatteConst::ShaderType::Vertex )
|
if(shaderContext->shaderType == LatteConst::ShaderType::Vertex )
|
||||||
|
@ -3412,9 +3407,6 @@ static void _emitCFRingWriteCode(LatteDecompilerShaderContext* shaderContext, La
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rasterizationEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (shaderContext->shaderType == LatteConst::ShaderType::Vertex)
|
if (shaderContext->shaderType == LatteConst::ShaderType::Vertex)
|
||||||
{
|
{
|
||||||
if (cfInstruction->memWriteElemSize != 3)
|
if (cfInstruction->memWriteElemSize != 3)
|
||||||
|
@ -3937,9 +3929,6 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
bool usesGeometryShader = UseGeometryShader(*shaderContext->contextRegistersNew, shaderContext->options->usesGeometryShader);
|
bool usesGeometryShader = UseGeometryShader(*shaderContext->contextRegistersNew, shaderContext->options->usesGeometryShader);
|
||||||
bool fetchVertexManually = (usesGeometryShader || (shaderContext->fetchShader && shaderContext->fetchShader->mtlFetchVertexManually));
|
bool fetchVertexManually = (usesGeometryShader || (shaderContext->fetchShader && shaderContext->fetchShader->mtlFetchVertexManually));
|
||||||
|
|
||||||
// Rasterization
|
|
||||||
rasterizationEnabled = shaderContext->contextRegistersNew->IsRasterizationEnabled();
|
|
||||||
|
|
||||||
StringBuf* src = new StringBuf(1024*1024*12); // reserve 12MB for generated source (we resize-to-fit at the end)
|
StringBuf* src = new StringBuf(1024*1024*12); // reserve 12MB for generated source (we resize-to-fit at the end)
|
||||||
shaderContext->shaderSource = src;
|
shaderContext->shaderSource = src;
|
||||||
|
|
||||||
|
@ -3953,7 +3942,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
src->add("#include <metal_stdlib>" _CRLF);
|
src->add("#include <metal_stdlib>" _CRLF);
|
||||||
src->add("using namespace metal;" _CRLF);
|
src->add("using namespace metal;" _CRLF);
|
||||||
// header part (definitions for inputs and outputs)
|
// header part (definitions for inputs and outputs)
|
||||||
LatteDecompiler::emitHeader(shaderContext, isRectVertexShader, usesGeometryShader, fetchVertexManually, rasterizationEnabled);
|
LatteDecompiler::emitHeader(shaderContext, isRectVertexShader, usesGeometryShader, fetchVertexManually);
|
||||||
// helper functions
|
// helper functions
|
||||||
LatteDecompiler_emitHelperFunctions(shaderContext, src);
|
LatteDecompiler_emitHelperFunctions(shaderContext, src);
|
||||||
const char* functionType = "";
|
const char* functionType = "";
|
||||||
|
@ -4114,8 +4103,8 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
functionType = "vertex";
|
functionType = "vertex";
|
||||||
if (rasterizationEnabled)
|
if (shaderContext->contextRegistersNew->IsRasterizationEnabled())
|
||||||
outputTypeName = "VertexOut";
|
outputTypeName = "Out";
|
||||||
else
|
else
|
||||||
outputTypeName = "void";
|
outputTypeName = "void";
|
||||||
}
|
}
|
||||||
|
@ -4126,7 +4115,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
break;
|
break;
|
||||||
case LatteConst::ShaderType::Pixel:
|
case LatteConst::ShaderType::Pixel:
|
||||||
functionType = "fragment";
|
functionType = "fragment";
|
||||||
outputTypeName = "FragmentOut";
|
outputTypeName = "Out";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// start of main
|
// start of main
|
||||||
|
@ -4152,28 +4141,25 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
src->add("VertexIn in = fetchVertex(vid, iid, indexBuffer, indexType VERTEX_BUFFERS);" _CRLF);
|
src->add("VertexIn in = fetchVertex(vid, iid, indexBuffer, indexType VERTEX_BUFFERS);" _CRLF);
|
||||||
|
|
||||||
// Output is defined as object payload
|
// Output is defined as object payload
|
||||||
src->add("object_data VertexOut& out = objectPayload.vertexOut[tid];" _CRLF);
|
src->add("object_data Out& out = objectPayload.vertexOut[tid];" _CRLF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Fetch the input
|
// Fetch the input
|
||||||
src->add("VertexIn in = fetchVertex(vid, iid VERTEX_BUFFERS);" _CRLF);
|
src->add("VertexIn in = fetchVertex(vid, iid VERTEX_BUFFERS);" _CRLF);
|
||||||
|
src->add("Out out;" _CRLF);
|
||||||
if (rasterizationEnabled)
|
|
||||||
src->add("VertexOut out;" _CRLF);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (shader->shaderType == LatteConst::ShaderType::Geometry)
|
else if (shader->shaderType == LatteConst::ShaderType::Geometry)
|
||||||
{
|
{
|
||||||
src->add("GeometryOut out;" _CRLF);
|
src->add("Out out;" _CRLF);
|
||||||
// The index of the current vertex that is being emitted
|
// The index of the current vertex that is being emitted
|
||||||
src->add("uint vertexIndex = 0;" _CRLF);
|
src->add("uint vertexIndex = 0;" _CRLF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (rasterizationEnabled)
|
src->addFmt("Out out;" _CRLF);
|
||||||
src->addFmt("{} out;" _CRLF, outputTypeName);
|
|
||||||
}
|
}
|
||||||
// variable definition
|
// variable definition
|
||||||
if (shaderContext->typeTracker.useArrayGPRs == false)
|
if (shaderContext->typeTracker.useArrayGPRs == false)
|
||||||
|
@ -4397,7 +4383,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
// vertex shader should write renderstate point size at the end if required but not modified by shader
|
// vertex shader should write renderstate point size at the end if required but not modified by shader
|
||||||
if (shaderContext->analyzer.outputPointSize && !shaderContext->analyzer.writesPointSize)
|
if (shaderContext->analyzer.outputPointSize && !shaderContext->analyzer.writesPointSize)
|
||||||
{
|
{
|
||||||
if (shader->shaderType == LatteConst::ShaderType::Vertex && !shaderContext->options->usesGeometryShader && rasterizationEnabled)
|
if (shader->shaderType == LatteConst::ShaderType::Vertex && !shaderContext->options->usesGeometryShader)
|
||||||
src->add("out.pointSize = supportBuffer.pointSize;" _CRLF);
|
src->add("out.pointSize = supportBuffer.pointSize;" _CRLF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4435,7 +4421,7 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rasterizationEnabled && (!usesGeometryShader || shader->shaderType == LatteConst::ShaderType::Pixel))
|
if (shader->shaderType == LatteConst::ShaderType::Pixel || (shaderContext->contextRegistersNew->IsRasterizationEnabled() && !usesGeometryShader))
|
||||||
{
|
{
|
||||||
// Return
|
// Return
|
||||||
src->add("return out;" _CRLF);
|
src->add("return out;" _CRLF);
|
||||||
|
|
|
@ -179,7 +179,7 @@ namespace LatteDecompiler
|
||||||
{
|
{
|
||||||
auto* src = shaderContext->shaderSource;
|
auto* src = shaderContext->shaderSource;
|
||||||
|
|
||||||
src->add("struct VertexOut {" _CRLF);
|
src->add("struct Out {" _CRLF);
|
||||||
src->add("float4 position [[position]] [[invariant]];" _CRLF);
|
src->add("float4 position [[position]] [[invariant]];" _CRLF);
|
||||||
if (shaderContext->analyzer.outputPointSize)
|
if (shaderContext->analyzer.outputPointSize)
|
||||||
src->add("float pointSize [[point_size]];" _CRLF);
|
src->add("float pointSize [[point_size]];" _CRLF);
|
||||||
|
@ -239,7 +239,7 @@ namespace LatteDecompiler
|
||||||
if (isRectVertexShader)
|
if (isRectVertexShader)
|
||||||
{
|
{
|
||||||
src->add("struct ObjectPayload {" _CRLF);
|
src->add("struct ObjectPayload {" _CRLF);
|
||||||
src->add("VertexOut vertexOut[VERTICES_PER_VERTEX_PRIMITIVE];" _CRLF);
|
src->add("Out vertexOut[VERTICES_PER_VERTEX_PRIMITIVE];" _CRLF);
|
||||||
src->add("};" _CRLF _CRLF);
|
src->add("};" _CRLF _CRLF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ namespace LatteDecompiler
|
||||||
src->add("};" _CRLF _CRLF);
|
src->add("};" _CRLF _CRLF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _emitInputsAndOutputs(LatteDecompilerShaderContext* decompilerContext, bool isRectVertexShader, bool usesGeometryShader, bool fetchVertexManually, bool rasterizationEnabled)
|
static void _emitInputsAndOutputs(LatteDecompilerShaderContext* decompilerContext, bool isRectVertexShader, bool usesGeometryShader, bool fetchVertexManually)
|
||||||
{
|
{
|
||||||
auto src = decompilerContext->shaderSource;
|
auto src = decompilerContext->shaderSource;
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ namespace LatteDecompiler
|
||||||
{
|
{
|
||||||
_emitPSInputs(decompilerContext);
|
_emitPSInputs(decompilerContext);
|
||||||
|
|
||||||
src->add("struct FragmentOut {" _CRLF);
|
src->add("struct Out {" _CRLF);
|
||||||
|
|
||||||
// generate pixel outputs for pixel shader
|
// generate pixel outputs for pixel shader
|
||||||
for (uint32 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
|
for (uint32 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
|
||||||
|
@ -306,14 +306,14 @@ namespace LatteDecompiler
|
||||||
|
|
||||||
if (!usesGeometryShader || isRectVertexShader)
|
if (!usesGeometryShader || isRectVertexShader)
|
||||||
{
|
{
|
||||||
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex && rasterizationEnabled)
|
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex)
|
||||||
_emitVSOutputs(decompilerContext, isRectVertexShader);
|
_emitVSOutputs(decompilerContext, isRectVertexShader);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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 Out {" _CRLF);
|
||||||
uint32 ringParameterCountVS2GS = 0;
|
uint32 ringParameterCountVS2GS = 0;
|
||||||
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex)
|
if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex)
|
||||||
{
|
{
|
||||||
|
@ -327,7 +327,7 @@ namespace LatteDecompiler
|
||||||
src->addFmt("int4 passParameterSem{};" _CRLF, f);
|
src->addFmt("int4 passParameterSem{};" _CRLF, f);
|
||||||
src->add("};" _CRLF _CRLF);
|
src->add("};" _CRLF _CRLF);
|
||||||
src->add("struct ObjectPayload {" _CRLF);
|
src->add("struct ObjectPayload {" _CRLF);
|
||||||
src->add("VertexOut vertexOut[VERTICES_PER_VERTEX_PRIMITIVE];" _CRLF);
|
src->add("Out vertexOut[VERTICES_PER_VERTEX_PRIMITIVE];" _CRLF);
|
||||||
src->add("};" _CRLF _CRLF);
|
src->add("};" _CRLF _CRLF);
|
||||||
}
|
}
|
||||||
if (decompilerContext->shaderType == LatteConst::ShaderType::Geometry)
|
if (decompilerContext->shaderType == LatteConst::ShaderType::Geometry)
|
||||||
|
@ -339,7 +339,7 @@ namespace LatteDecompiler
|
||||||
if (((decompilerContext->contextRegisters[mmSQ_GSVS_RING_ITEMSIZE] & 0x7FFF) & 0xF) != 0)
|
if (((decompilerContext->contextRegisters[mmSQ_GSVS_RING_ITEMSIZE] & 0x7FFF) & 0xF) != 0)
|
||||||
debugBreakpoint();
|
debugBreakpoint();
|
||||||
|
|
||||||
src->add("struct GeometryOut {" _CRLF);
|
src->add("struct Out {" _CRLF);
|
||||||
src->add("float4 position [[position]];" _CRLF);
|
src->add("float4 position [[position]];" _CRLF);
|
||||||
for (sint32 p = 0; p < decompilerContext->parsedGSCopyShader->numParam; p++)
|
for (sint32 p = 0; p < decompilerContext->parsedGSCopyShader->numParam; p++)
|
||||||
{
|
{
|
||||||
|
@ -352,12 +352,12 @@ namespace LatteDecompiler
|
||||||
const uint32 MAX_VERTEX_COUNT = 32;
|
const uint32 MAX_VERTEX_COUNT = 32;
|
||||||
|
|
||||||
// Define the mesh shader output type
|
// Define the mesh shader output type
|
||||||
src->addFmt("using MeshType = mesh<GeometryOut, void, {}, GET_PRIMITIVE_COUNT({}), topology::MTL_PRIMITIVE_TYPE>;" _CRLF, MAX_VERTEX_COUNT, MAX_VERTEX_COUNT);
|
src->addFmt("using MeshType = mesh<Out, void, {}, GET_PRIMITIVE_COUNT({}), topology::MTL_PRIMITIVE_TYPE>;" _CRLF, MAX_VERTEX_COUNT, MAX_VERTEX_COUNT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emitHeader(LatteDecompilerShaderContext* decompilerContext, bool isRectVertexShader, bool usesGeometryShader, bool fetchVertexManually, bool rasterizationEnabled)
|
static void emitHeader(LatteDecompilerShaderContext* decompilerContext, bool isRectVertexShader, bool usesGeometryShader, bool fetchVertexManually)
|
||||||
{
|
{
|
||||||
auto src = decompilerContext->shaderSource;
|
auto src = decompilerContext->shaderSource;
|
||||||
|
|
||||||
|
@ -403,7 +403,7 @@ namespace LatteDecompiler
|
||||||
// uniform buffers
|
// uniform buffers
|
||||||
_emitUniformBuffers(decompilerContext);
|
_emitUniformBuffers(decompilerContext);
|
||||||
// inputs and outputs
|
// inputs and outputs
|
||||||
_emitInputsAndOutputs(decompilerContext, isRectVertexShader, usesGeometryShader, fetchVertexManually, rasterizationEnabled);
|
_emitInputsAndOutputs(decompilerContext, isRectVertexShader, usesGeometryShader, fetchVertexManually);
|
||||||
|
|
||||||
if (dump_shaders_enabled)
|
if (dump_shaders_enabled)
|
||||||
decompilerContext->shaderSource->add("// end of shader inputs/outputs" _CRLF);
|
decompilerContext->shaderSource->add("// end of shader inputs/outputs" _CRLF);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue