fix: texture updates and buffer bindings

This commit is contained in:
Samuliak 2024-08-06 06:43:22 +02:00
parent f11526a244
commit d64e64e5ef
5 changed files with 46 additions and 30 deletions

View File

@ -352,6 +352,7 @@ void LatteTexture_CopySlice(LatteTexture* srcTexture, sint32 srcSlice, sint32 sr
if (srcTexture->isDepth != dstTexture->isDepth)
{
g_renderer->surfaceCopy_copySurfaceWithFormatConversion(srcTexture, srcMip, srcSlice, dstTexture, dstMip, dstSlice, width, height);
throw std::runtime_error("1");
return;
}
// rescale copy size
@ -384,6 +385,7 @@ void LatteTexture_CopySlice(LatteTexture* srcTexture, sint32 srcSlice, sint32 sr
cemuLog_log(LogType::Force, "Source: {:08x} origResolution {:4}/{:4} effectiveResolution {:4}/{:4} fmt {:04x} mipIndex {} ratioW/H: {:.4}/{:.4}", srcTexture->physAddress, srcTexture->width, srcTexture->height, effectiveWidth_src, effectiveHeight_src, (uint32)srcTexture->format, srcMip, ratioWidth_src, ratioHeight_src);
cemuLog_log(LogType::Force, "Destination: {:08x} origResolution {:4}/{:4} effectiveResolution {:4}/{:4} fmt {:04x} mipIndex {} ratioW/H: {:.4}/{:.4}", dstTexture->physAddress, dstTexture->width, dstTexture->height, effectiveWidth_dst, effectiveHeight_dst, (uint32)dstTexture->format, dstMip, ratioWidth_dst, ratioHeight_dst);
}
throw std::runtime_error("2");
//cemuLog_logDebug(LogType::Force, "If these textures are not meant to share data you can ignore this");
return;
}

View File

@ -261,7 +261,7 @@ namespace LatteDecompiler
// generate pixel outputs for pixel shader
for (uint32 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
{
if ((decompilerContext->shader->pixelColorOutputMask&(1 << i)) != 0)
if ((decompilerContext->shader->pixelColorOutputMask & (1 << i)) != 0)
{
src->addFmt("float4 passPixelColor{} [[color({})]];" _CRLF, i, i);
}

View File

@ -260,7 +260,8 @@ MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode)
case LattePrimitiveMode::TRIANGLE_STRIP:
return MTL::PrimitiveTypeTriangleStrip;
default:
printf("unimplemented primitive type %u\n", (uint32)mode);
// TODO: uncomment
//printf("unimplemented primitive type %u\n", (uint32)mode);
return MTL::PrimitiveTypeTriangle;
}
}

View File

@ -58,7 +58,6 @@ MTL::RenderPipelineState* MetalPipelineCache::GetPipelineState(const LatteFetchS
uint32 bufferIndex = bufferGroup.attributeBufferIndex;
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
// TODO: is LatteGPUState.contextNew correct?
uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
auto layout = vertexDescriptor->layouts()->object(GET_MTL_VERTEX_BUFFER_INDEX(bufferIndex));

View File

@ -561,7 +561,6 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
auto renderCommandEncoder = GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, depthRenderTarget);
// Shaders
LatteSHRC_UpdateActiveShaders();
LatteDecompilerShader* vertexShader = LatteSHRC_GetActiveVertexShader();
LatteDecompilerShader* pixelShader = LatteSHRC_GetActivePixelShader();
if (!vertexShader || !static_cast<RendererShaderMtl*>(vertexShader->shader)->GetFunction())
@ -627,7 +626,16 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
void MetalRenderer::draw_endSequence()
{
// TODO: do something?
LatteDecompilerShader* pixelShader = LatteSHRC_GetActivePixelShader();
// post-drawcall logic
if (pixelShader)
LatteRenderTarget_trackUpdates();
bool hasReadback = LatteTextureReadback_Update();
//m_recordedDrawcalls++;
//if (m_recordedDrawcalls >= m_submitThreshold || hasReadback)
//{
// SubmitCommandBuffer();
//}
}
void* MetalRenderer::indexData_reserveIndexMemory(uint32 size, uint32& offset, uint32& bufferIndex)
@ -1101,7 +1109,7 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
debug_printf("too big buffer index (%u), skipping binding\n", binding);
continue;
}
size_t offset = m_state.uniformBufferOffsets[(uint32)shader->shaderType][binding];
size_t offset = m_state.uniformBufferOffsets[(uint32)shader->shaderType][i];
if (offset != INVALID_OFFSET)
{
switch (shader->shaderType)
@ -1122,6 +1130,12 @@ void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandE
}
}
}
// Storage buffer
if (shader->resourceMapping.tfStorageBindingPoint >= 0)
{
debug_printf("storage buffer not implemented, index: %i\n", shader->resourceMapping.tfStorageBindingPoint);
}
}
void MetalRenderer::RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder)