don't set verticesPerInstance twice

This commit is contained in:
Samuliak 2024-10-01 19:07:19 +02:00
parent 6dc8f9a019
commit 2fb4d83a5f
3 changed files with 5 additions and 12 deletions

View File

@ -4075,8 +4075,8 @@ void LatteDecompiler_emitMSLShader(LatteDecompilerShaderContext* shaderContext,
{ {
// Calculate the imaginary vertex id // Calculate the imaginary vertex id
src->add("uint vid = tig * VERTICES_PER_VERTEX_PRIMITIVE + tid;" _CRLF); src->add("uint vid = tig * VERTICES_PER_VERTEX_PRIMITIVE + tid;" _CRLF);
src->add("uint iid = vid / verticesPerInstance;" _CRLF); src->add("uint iid = vid / supportBuffer.verticesPerInstance;" _CRLF);
src->add("vid %= verticesPerInstance;" _CRLF); src->add("vid %= supportBuffer.verticesPerInstance;" _CRLF);
// Fetch the input // Fetch the input
src->add("VertexIn in = fetchVertex(vid, iid, indexBuffer, indexType VERTEX_BUFFERS);" _CRLF); src->add("VertexIn in = fetchVertex(vid, iid, indexBuffer, indexType VERTEX_BUFFERS);" _CRLF);

View File

@ -85,8 +85,7 @@ namespace LatteDecompiler
uniformCurrentOffset += 8; uniformCurrentOffset += 8;
} }
// define verticesPerInstance + streamoutBufferBaseX // define verticesPerInstance + streamoutBufferBaseX
if ((shader->shaderType == LatteConst::ShaderType::Vertex && !decompilerContext->options->usesGeometryShader) || if (shader->shaderType == LatteConst::ShaderType::Vertex || shader->shaderType == LatteConst::ShaderType::Geometry)
(shader->shaderType == LatteConst::ShaderType::Geometry))
{ {
src->add("int verticesPerInstance;" _CRLF); src->add("int verticesPerInstance;" _CRLF);
uniformOffsets.offset_verticesPerInstance = uniformCurrentOffset; uniformOffsets.offset_verticesPerInstance = uniformCurrentOffset;
@ -484,9 +483,7 @@ namespace LatteDecompiler
src->add(", mesh_grid_properties meshGridProperties"); src->add(", mesh_grid_properties meshGridProperties");
src->add(", uint tig [[threadgroup_position_in_grid]]"); src->add(", uint tig [[threadgroup_position_in_grid]]");
src->add(", uint tid [[thread_index_in_threadgroup]]"); src->add(", uint tid [[thread_index_in_threadgroup]]");
// TODO: put into the support buffer? // TODO: only include index buffer if needed
src->addFmt(", constant uint& verticesPerInstance [[buffer({})]]", decompilerContext->output->resourceMappingMTL.verticesPerInstanceBinding);
// TODO: inly include index buffer if needed
src->addFmt(", device uint* indexBuffer [[buffer({})]]", decompilerContext->output->resourceMappingMTL.indexBufferBinding); src->addFmt(", device uint* indexBuffer [[buffer({})]]", decompilerContext->output->resourceMappingMTL.indexBufferBinding);
// TODO: put into the support buffer? // TODO: put into the support buffer?
src->addFmt(", constant uchar& indexType [[buffer({})]]", decompilerContext->output->resourceMappingMTL.indexTypeBinding); src->addFmt(", constant uchar& indexType [[buffer({})]]", decompilerContext->output->resourceMappingMTL.indexTypeBinding);

View File

@ -1247,13 +1247,9 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
// We have already retrieved the buffer, no need for it to be locked anymore // We have already retrieved the buffer, no need for it to be locked anymore
bufferAllocator.UnlockBuffer(indexBufferIndex); bufferAllocator.UnlockBuffer(indexBufferIndex);
} }
if (usesGeometryShader) if (usesGeometryShader)
{ {
uint32 verticesPerInstance = count / instanceCount;
// TODO: make a helper function for this
renderCommandEncoder->setObjectBytes(&verticesPerInstance, sizeof(verticesPerInstance), vertexShader->resourceMapping.verticesPerInstanceBinding);
encoderState.m_buffers[METAL_SHADER_TYPE_OBJECT][vertexShader->resourceMapping.verticesPerInstanceBinding] = {nullptr};
if (indexBuffer) if (indexBuffer)
SetBuffer(renderCommandEncoder, METAL_SHADER_TYPE_OBJECT, indexBuffer, indexBufferOffset, vertexShader->resourceMapping.indexBufferBinding); SetBuffer(renderCommandEncoder, METAL_SHADER_TYPE_OBJECT, indexBuffer, indexBufferOffset, vertexShader->resourceMapping.indexBufferBinding);