request soon commit instead of committing directly

This commit is contained in:
Samuliak 2024-09-13 16:12:47 +02:00
parent 934b1f8b55
commit e89efed743
4 changed files with 17 additions and 8 deletions

View File

@ -25,6 +25,7 @@ void LatteTextureReadbackInfoMtl::StartTransfer()
blitCommandEncoder->copyFromTexture(baseTexture->GetTexture(), 0, 0, MTL::Origin{0, 0, 0}, MTL::Size{(uint32)baseTexture->width, (uint32)baseTexture->height, 1}, m_mtlr->GetTextureReadbackBuffer(), m_bufferOffset, bytesPerRow, bytesPerImage); blitCommandEncoder->copyFromTexture(baseTexture->GetTexture(), 0, 0, MTL::Origin{0, 0, 0}, MTL::Size{(uint32)baseTexture->width, (uint32)baseTexture->height, 1}, m_mtlr->GetTextureReadbackBuffer(), m_bufferOffset, bytesPerRow, bytesPerImage);
m_commandBuffer = m_mtlr->GetCurrentCommandBuffer(); m_commandBuffer = m_mtlr->GetCurrentCommandBuffer();
m_mtlr->RequestSoonCommit();
} }
bool LatteTextureReadbackInfoMtl::IsFinished() bool LatteTextureReadbackInfoMtl::IsFinished()

View File

@ -14,6 +14,7 @@ bool LatteQueryObjectMtl::getResult(uint64& numSamplesPassed)
return false; return false;
numSamplesPassed = m_mtlr->GetOcclusionQueryResultsPtr()[m_queryIndex]; numSamplesPassed = m_mtlr->GetOcclusionQueryResultsPtr()[m_queryIndex];
return true; return true;
} }
@ -35,7 +36,6 @@ void LatteQueryObjectMtl::end()
if (m_mtlr->IsCommandBufferActive()) if (m_mtlr->IsCommandBufferActive())
{ {
m_commandBuffer = m_mtlr->GetCurrentCommandBuffer(); m_commandBuffer = m_mtlr->GetCurrentCommandBuffer();
// TODO: request soon submit instead? m_mtlr->RequestSoonCommit();
m_mtlr->CommitCommandBuffer();
} }
} }

View File

@ -27,7 +27,7 @@
#include "imgui/imgui_extension.h" #include "imgui/imgui_extension.h"
#include "imgui/imgui_impl_metal.h" #include "imgui/imgui_impl_metal.h"
#define COMMIT_TRESHOLD 256 #define DEFAULT_COMMIT_TRESHOLD 256
#define OCCLUSION_QUERY_POOL_SIZE 1024 #define OCCLUSION_QUERY_POOL_SIZE 1024
extern bool hasValidFramebufferAttached; extern bool hasValidFramebufferAttached;
@ -1270,7 +1270,8 @@ void MetalRenderer::draw_endSequence()
bool hasReadback = LatteTextureReadback_Update(); bool hasReadback = LatteTextureReadback_Update();
m_recordedDrawcalls++; m_recordedDrawcalls++;
// The number of draw calls needs to twice as big, since we are interrupting the render pass // The number of draw calls needs to twice as big, since we are interrupting the render pass
if (m_recordedDrawcalls >= COMMIT_TRESHOLD * 2 || hasReadback) // TODO: ucomment?
if (m_recordedDrawcalls >= m_commitTreshold * 2/* || hasReadback*/)
{ {
CommitCommandBuffer(); CommitCommandBuffer();
@ -1409,6 +1410,9 @@ MTL::CommandBuffer* MetalRenderer::GetCommandBuffer()
MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer(); MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer();
m_commandBuffers.push_back({mtlCommandBuffer}); m_commandBuffers.push_back({mtlCommandBuffer});
m_recordedDrawcalls = 0;
m_commitTreshold = DEFAULT_COMMIT_TRESHOLD;
// Notify memory manager about the new command buffer // Notify memory manager about the new command buffer
m_memoryManager->GetTemporaryBufferAllocator().SetActiveCommandBuffer(mtlCommandBuffer); m_memoryManager->GetTemporaryBufferAllocator().SetActiveCommandBuffer(mtlCommandBuffer);
@ -1557,15 +1561,13 @@ void MetalRenderer::EndEncoding()
m_encoderType = MetalEncoderType::None; m_encoderType = MetalEncoderType::None;
// Commit the command buffer if enough draw calls have been recorded // Commit the command buffer if enough draw calls have been recorded
if (m_recordedDrawcalls >= COMMIT_TRESHOLD) if (m_recordedDrawcalls >= m_commitTreshold)
CommitCommandBuffer(); CommitCommandBuffer();
} }
} }
void MetalRenderer::CommitCommandBuffer() void MetalRenderer::CommitCommandBuffer()
{ {
m_recordedDrawcalls = 0;
if (m_commandBuffers.size() != 0) if (m_commandBuffers.size() != 0)
{ {
EndEncoding(); EndEncoding();

View File

@ -291,6 +291,11 @@ public:
return m_commandBuffers[m_commandBuffers.size() - 1].m_commandBuffer; return m_commandBuffers[m_commandBuffers.size() - 1].m_commandBuffer;
} }
void RequestSoonCommit()
{
m_commitTreshold = m_recordedDrawcalls + 8;
}
MTL::CommandEncoder* GetCommandEncoder() MTL::CommandEncoder* GetCommandEncoder()
{ {
return m_commandEncoder; return m_commandEncoder;
@ -475,7 +480,8 @@ private:
MetalEncoderType m_encoderType = MetalEncoderType::None; MetalEncoderType m_encoderType = MetalEncoderType::None;
MTL::CommandEncoder* m_commandEncoder = nullptr; MTL::CommandEncoder* m_commandEncoder = nullptr;
uint32 m_recordedDrawcalls = 0; uint32 m_recordedDrawcalls;
uint32 m_commitTreshold;
// State // State
MetalState m_state; MetalState m_state;