sync between command buffers

This commit is contained in:
Samuliak 2024-11-10 20:09:24 +01:00
parent ed32feb3d9
commit a52095b40a
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,8 @@
#include "imgui/imgui_extension.h" #include "imgui/imgui_extension.h"
#include "imgui/imgui_impl_metal.h" #include "imgui/imgui_impl_metal.h"
#define EVENT_VALUE_WRAP 4096
extern bool hasValidFramebufferAttached; extern bool hasValidFramebufferAttached;
float supportBufferData[512 * 4]; float supportBufferData[512 * 4];
@ -48,6 +50,9 @@ MetalRenderer::MetalRenderer()
CheckForPixelFormatSupport(m_pixelFormatSupport); CheckForPixelFormatSupport(m_pixelFormatSupport);
// Synchronization resources
m_event = m_device->newEvent();
// Resources // Resources
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init(); MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
#ifdef CEMU_DEBUG_ASSERT #ifdef CEMU_DEBUG_ASSERT
@ -161,6 +166,8 @@ MetalRenderer::~MetalRenderer()
m_occlusionQuery.m_resultBuffer->release(); m_occlusionQuery.m_resultBuffer->release();
m_event->release();
m_commandQueue->release(); m_commandQueue->release();
m_device->release(); m_device->release();
} }
@ -1509,6 +1516,10 @@ MTL::CommandBuffer* MetalRenderer::GetCommandBuffer()
MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer(); MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer();
m_currentCommandBuffer = {mtlCommandBuffer}; m_currentCommandBuffer = {mtlCommandBuffer};
// Wait for the previous command buffer
if (m_eventValue != -1)
mtlCommandBuffer->encodeWait(m_event, m_eventValue);
m_recordedDrawcalls = 0; m_recordedDrawcalls = 0;
m_commitTreshold = m_defaultCommitTreshlod; m_commitTreshold = m_defaultCommitTreshlod;
@ -1682,6 +1693,10 @@ void MetalRenderer::CommitCommandBuffer()
// m_memoryManager->GetTemporaryBufferAllocator().CommandBufferFinished(commandBuffer.m_commandBuffer); // m_memoryManager->GetTemporaryBufferAllocator().CommandBufferFinished(commandBuffer.m_commandBuffer);
//}); //});
// Signal event
m_eventValue = (m_eventValue + 1) % EVENT_VALUE_WRAP;
m_currentCommandBuffer.m_commandBuffer->encodeSignalEvent(m_event, m_eventValue);
m_currentCommandBuffer.m_commandBuffer->commit(); m_currentCommandBuffer.m_commandBuffer->commit();
m_currentCommandBuffer.m_commandBuffer->release(); m_currentCommandBuffer.m_commandBuffer->release();
m_currentCommandBuffer.m_commited = true; m_currentCommandBuffer.m_commited = true;

View File

@ -6,6 +6,7 @@
#include "Cafe/HW/Latte/Renderer/Metal/MetalPerformanceMonitor.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalPerformanceMonitor.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalOutputShaderCache.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalOutputShaderCache.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalAttachmentsInfo.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalAttachmentsInfo.h"
#include <cstdint>
struct MetalBufferAllocation struct MetalBufferAllocation
{ {
@ -459,6 +460,10 @@ private:
// Void vertex pipelines // Void vertex pipelines
class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline; class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline;
// Synchronization resources
MTL::Event* m_event;
int32_t m_eventValue = -1;
// Resources // Resources
MTL::SamplerState* m_nearestSampler; MTL::SamplerState* m_nearestSampler;
MTL::SamplerState* m_linearSampler; MTL::SamplerState* m_linearSampler;