mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-26 04:32:35 +01:00
vulkan: Optimize memory allocation
This commit is contained in:
parent
b74cdcde00
commit
9ee21af524
@ -114,4 +114,17 @@ public:
|
||||
m_largest_allocated_pool = 0;
|
||||
m_get_pos = get_current_put_pos_minus_one();
|
||||
}
|
||||
|
||||
// Updates the current_allocated_size metrics
|
||||
void notify()
|
||||
{
|
||||
if (m_get_pos == UINT64_MAX)
|
||||
m_current_allocated_size = 0;
|
||||
else if (m_get_pos < m_put_pos)
|
||||
m_current_allocated_size = (m_put_pos - m_get_pos - 1);
|
||||
else if (m_get_pos > m_put_pos)
|
||||
m_current_allocated_size = (m_put_pos + (m_size - m_get_pos - 1));
|
||||
else
|
||||
fmt::throw_exception("m_put_pos == m_get_pos!" HERE);
|
||||
}
|
||||
};
|
||||
|
@ -878,14 +878,41 @@ void VKGSRender::begin()
|
||||
{
|
||||
std::chrono::time_point<steady_clock> submit_start = steady_clock::now();
|
||||
|
||||
flush_command_queue(true);
|
||||
m_vertex_cache->purge();
|
||||
frame_context_t *target_frame = nullptr;
|
||||
u64 earliest_sync_time = UINT64_MAX;
|
||||
for (s32 i = 0; i < VK_MAX_ASYNC_FRAMES; ++i)
|
||||
{
|
||||
auto ctx = &frame_context_storage[i];
|
||||
if (ctx->swap_command_buffer)
|
||||
{
|
||||
if (ctx->last_frame_sync_time > m_last_heap_sync_time &&
|
||||
ctx->last_frame_sync_time < earliest_sync_time)
|
||||
target_frame = ctx;
|
||||
}
|
||||
}
|
||||
|
||||
m_index_buffer_ring_info.reset_allocation_stats();
|
||||
m_uniform_buffer_ring_info.reset_allocation_stats();
|
||||
m_attrib_ring_info.reset_allocation_stats();
|
||||
m_texture_upload_buffer_ring_info.reset_allocation_stats();
|
||||
m_current_frame->reset_heap_ptrs();
|
||||
if (target_frame == nullptr)
|
||||
{
|
||||
flush_command_queue(true);
|
||||
m_vertex_cache->purge();
|
||||
|
||||
m_index_buffer_ring_info.reset_allocation_stats();
|
||||
m_uniform_buffer_ring_info.reset_allocation_stats();
|
||||
m_attrib_ring_info.reset_allocation_stats();
|
||||
m_texture_upload_buffer_ring_info.reset_allocation_stats();
|
||||
m_current_frame->reset_heap_ptrs();
|
||||
}
|
||||
else
|
||||
{
|
||||
target_frame->swap_command_buffer->poke();
|
||||
while (target_frame->swap_command_buffer->pending)
|
||||
{
|
||||
if (!target_frame->swap_command_buffer->poke())
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
process_swap_request(target_frame, true);
|
||||
}
|
||||
|
||||
std::chrono::time_point<steady_clock> submit_end = steady_clock::now();
|
||||
m_flip_time += std::chrono::duration_cast<std::chrono::microseconds>(submit_end - submit_start).count();
|
||||
@ -1641,6 +1668,11 @@ void VKGSRender::process_swap_request(frame_context_t *ctx, bool free_resources)
|
||||
m_uniform_buffer_ring_info.m_get_pos = ctx->ubo_heap_ptr;
|
||||
m_index_buffer_ring_info.m_get_pos = ctx->index_heap_ptr;
|
||||
m_texture_upload_buffer_ring_info.m_get_pos = ctx->texture_upload_heap_ptr;
|
||||
|
||||
m_attrib_ring_info.notify();
|
||||
m_uniform_buffer_ring_info.notify();
|
||||
m_index_buffer_ring_info.notify();
|
||||
m_texture_upload_buffer_ring_info.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,15 @@ struct command_buffer_chunk: public vk::command_buffer
|
||||
vkResetCommandBuffer(commands, 0);
|
||||
}
|
||||
|
||||
void poke()
|
||||
bool poke()
|
||||
{
|
||||
if (vkGetFenceStatus(m_device, submit_fence) == VK_SUCCESS)
|
||||
{
|
||||
vkResetFences(m_device, 1, &submit_fence);
|
||||
pending = false;
|
||||
}
|
||||
|
||||
return !pending;
|
||||
}
|
||||
|
||||
void wait()
|
||||
|
Loading…
Reference in New Issue
Block a user