diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 9c2a040e..96956282 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -1232,7 +1232,7 @@ void MetalRenderer::draw_updateVertexBuffersDirectAccess() MPTR bufferAddress = LatteGPUState.contextRegister[bufferBaseRegisterIndex + 0]; if (bufferAddress == MPTR_NULL) [[unlikely]] - bufferAddress = 0x10000000; // TODO: really? + bufferAddress = m_memoryManager->GetImportedMemBaseAddress(); m_state.m_vertexBufferOffsets[bufferIndex] = bufferAddress - m_memoryManager->GetImportedMemBaseAddress(); } @@ -1317,7 +1317,9 @@ void MetalRenderer::occlusionQuery_destroy(LatteQueryObject* queryObj) { } void MetalRenderer::occlusionQuery_flush() { - // TODO: implement + // TODO: wait for all command buffers with occlusion queries? + if (m_occlusionQuery.m_lastCommandBuffer) + m_occlusionQuery.m_lastCommandBuffer->waitUntilCompleted(); } void MetalRenderer::occlusionQuery_updateState() { diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index ad45c326..baae288d 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -429,6 +429,12 @@ public: void EndOcclusionQuery() { m_occlusionQuery.m_active = false; + if (m_occlusionQuery.m_lastCommandBuffer) + m_occlusionQuery.m_lastCommandBuffer->release(); + if (IsCommandBufferActive()) + m_occlusionQuery.m_lastCommandBuffer = GetCurrentCommandBuffer()->retain(); + else + m_occlusionQuery.m_lastCommandBuffer = nullptr; } private: @@ -480,6 +486,7 @@ private: uint64* m_resultsPtr; uint32 m_currentIndex = 0; bool m_active = false; + MTL::CommandBuffer* m_lastCommandBuffer = nullptr; } m_occlusionQuery; // Active objects