cleanup the buffer allocator

This commit is contained in:
Samuliak 2024-11-11 15:45:13 +01:00
parent a52095b40a
commit 326d3442cd
No known key found for this signature in database

View File

@ -144,6 +144,8 @@ public:
protected: protected:
class MetalRenderer* m_mtlr; class MetalRenderer* m_mtlr;
// TODO: make these template arguments
bool m_isCPUAccessible; bool m_isCPUAccessible;
MTL::ResourceOptions m_options; MTL::ResourceOptions m_options;
@ -153,8 +155,7 @@ protected:
{ {
auto& buffer = m_buffers[bufferIndex]; auto& buffer = m_buffers[bufferIndex];
buffer.m_freeRanges.clear(); buffer.m_freeRanges.clear();
buffer.m_freeRanges.reserve(1); buffer.m_freeRanges.push_back({0, buffer.m_buffer->length()});
buffer.m_freeRanges.push_back({0, m_buffers[bufferIndex].m_buffer->length()});
} }
}; };
@ -191,7 +192,6 @@ public:
buffer.m_data.m_lock--; buffer.m_data.m_lock--;
// TODO: is this really necessary?
// Release the buffer if it wasn't released due to the lock // Release the buffer if it wasn't released due to the lock
if (!buffer.m_data.IsLocked() && buffer.m_data.m_commandBufferCount == 0) if (!buffer.m_data.IsLocked() && buffer.m_data.m_commandBufferCount == 0)
FreeBuffer(bufferIndex); FreeBuffer(bufferIndex);
@ -206,7 +206,7 @@ public:
{ {
auto& buffer = m_buffers[i]; auto& buffer = m_buffers[i];
if (buffer.m_data.m_lock != 0) if (buffer.m_data.IsLocked())
{ {
if (buffer.m_data.m_commandBufferCount == 0) if (buffer.m_data.m_commandBufferCount == 0)
FreeBuffer(i); FreeBuffer(i);
@ -272,6 +272,7 @@ public:
auto& buffer = m_buffers[bufferIndex]; auto& buffer = m_buffers[bufferIndex];
buffer.m_data.m_commandBufferCount--; buffer.m_data.m_commandBufferCount--;
// TODO: is this neccessary?
if (!buffer.m_data.IsLocked() && buffer.m_data.m_commandBufferCount == 0) if (!buffer.m_data.IsLocked() && buffer.m_data.m_commandBufferCount == 0)
FreeBuffer(bufferIndex); FreeBuffer(bufferIndex);
} }