diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.cpp index 0119209b..895bab22 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.cpp @@ -4,12 +4,16 @@ bool LatteQueryObjectMtl::getResult(uint64& numSamplesPassed) { + if (!m_commandBuffer) + { + numSamplesPassed = 0; + return true; + } + if (!CommandBufferCompleted(m_commandBuffer)) return false; numSamplesPassed = m_mtlr->GetOcclusionQueryResultsPtr()[m_queryIndex]; - printf("Num samples: %llu\n", numSamplesPassed); - return true; } @@ -28,7 +32,10 @@ void LatteQueryObjectMtl::begin() void LatteQueryObjectMtl::end() { m_mtlr->SetActiveOcclusionQueryIndex(INVALID_UINT32); - m_commandBuffer = m_mtlr->GetCurrentCommandBuffer(); - // TODO: request soon submit instead? - m_mtlr->CommitCommandBuffer(); + if (m_mtlr->IsCommandBufferActive()) + { + m_commandBuffer = m_mtlr->GetCurrentCommandBuffer(); + // TODO: request soon submit instead? + m_mtlr->CommitCommandBuffer(); + } } diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.h index 58b4e266..554cdace 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalQuery.h @@ -19,5 +19,5 @@ private: uint32 m_queryIndex = INVALID_UINT32; // TODO: make this a list of command buffers - MTL::CommandBuffer* m_commandBuffer; + MTL::CommandBuffer* m_commandBuffer = nullptr; }; diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index f46a4be3..0c7c78f5 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -279,6 +279,11 @@ public: // Helpers MetalPerformanceMonitor& GetPerformanceMonitor() { return m_performanceMonitor; } + bool IsCommandBufferActive() const + { + return (m_commandBuffers.size() != 0); + } + MTL::CommandBuffer* GetCurrentCommandBuffer() { cemu_assert_debug(m_commandBuffers.size() != 0);