mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-01-07 15:48:15 +01:00
fix: temporary buffer allocator
This commit is contained in:
parent
a693bf564f
commit
6c8947d0e5
@ -152,7 +152,7 @@ struct MetalSyncedBuffer
|
||||
class MetalTemporaryBufferAllocator : public MetalBufferAllocator<MetalSyncedBuffer>
|
||||
{
|
||||
public:
|
||||
MetalTemporaryBufferAllocator(class MetalRenderer* metalRenderer) : MetalBufferAllocator<MetalSyncedBuffer>(metalRenderer, metalRenderer->GetOptimalBufferStorageMode()) {}
|
||||
MetalTemporaryBufferAllocator(class MetalRenderer* metalRenderer) : MetalBufferAllocator<MetalSyncedBuffer>(metalRenderer, MTL::ResourceStorageModeShared) {}
|
||||
|
||||
void SetActiveCommandBuffer(MTL::CommandBuffer* commandBuffer)
|
||||
{
|
||||
@ -170,6 +170,16 @@ public:
|
||||
{
|
||||
if (buffer.m_commandBuffers.size() == 1)
|
||||
{
|
||||
// First remove any free ranges that use this buffer
|
||||
for (uint32 k = 0; k < m_freeBufferRanges.size(); k++)
|
||||
{
|
||||
if (m_freeBufferRanges[k].bufferIndex == i)
|
||||
{
|
||||
m_freeBufferRanges.erase(m_freeBufferRanges.begin() + k);
|
||||
k--;
|
||||
}
|
||||
}
|
||||
|
||||
// All command buffers using it have finished execution, we can use it again
|
||||
m_freeBufferRanges.push_back({i, 0, buffer.m_buffer->length()});
|
||||
|
||||
|
@ -509,8 +509,7 @@ void MetalRenderer::texture_loadSlice(LatteTexture* hostTexture, sint32 width, s
|
||||
auto blitCommandEncoder = GetBlitCommandEncoder();
|
||||
|
||||
// Allocate a temporary buffer
|
||||
// HACK: use the persistent buffer allocator so as to avoid any issues
|
||||
auto& bufferAllocator = m_memoryManager->GetBufferAllocator();
|
||||
auto& bufferAllocator = m_memoryManager->GetTemporaryBufferAllocator();
|
||||
auto allocation = bufferAllocator.GetBufferAllocation(compressedImageSize);
|
||||
auto buffer = bufferAllocator.GetBuffer(allocation.bufferIndex);
|
||||
|
||||
@ -1192,9 +1191,11 @@ void* MetalRenderer::indexData_reserveIndexMemory(uint32 size, uint32& offset, u
|
||||
|
||||
void MetalRenderer::indexData_uploadIndexMemory(uint32 bufferIndex, uint32 offset, uint32 size)
|
||||
{
|
||||
auto buffer = m_memoryManager->GetTemporaryBufferAllocator().GetBuffer(bufferIndex);
|
||||
if (!HasUnifiedMemory())
|
||||
{
|
||||
auto buffer = m_memoryManager->GetTemporaryBufferAllocator().GetBuffer(bufferIndex);
|
||||
buffer->didModifyRange(NS::Range(offset, size));
|
||||
}
|
||||
}
|
||||
|
||||
void MetalRenderer::SetBuffer(MTL::RenderCommandEncoder* renderCommandEncoder, MetalShaderType shaderType, MTL::Buffer* buffer, size_t offset, uint32 index)
|
||||
@ -1459,7 +1460,7 @@ void MetalRenderer::CommitCommandBuffer()
|
||||
auto& commandBuffer = m_commandBuffers.back();
|
||||
if (!commandBuffer.m_commited)
|
||||
{
|
||||
commandBuffer.m_commandBuffer->addCompletedHandler(^(MTL::CommandBuffer* cmd) {
|
||||
commandBuffer.m_commandBuffer->addCompletedHandler(^(MTL::CommandBuffer*) {
|
||||
m_memoryManager->GetTemporaryBufferAllocator().CommandBufferFinished(commandBuffer.m_commandBuffer);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user