mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-04 21:29:36 +00:00
[TEST] Keep tuning the drain/ memory allocation
This commit is contained in:
@@ -43,7 +43,7 @@ BufferCache<P>::~BufferCache() = default;
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
u64 BufferCache<P>::DeviceUsage(bool force_refresh) {
|
u64 BufferCache<P>::DeviceUsage(bool force_refresh) {
|
||||||
if (!runtime.CanReportMemoryUsage()) {
|
if (!runtime.CanReportAllocationUsage()) {
|
||||||
return total_used_memory;
|
return total_used_memory;
|
||||||
}
|
}
|
||||||
if (force_refresh || usage_refresh_countdown == 0) {
|
if (force_refresh || usage_refresh_countdown == 0) {
|
||||||
@@ -61,6 +61,9 @@ u64 BufferCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
in_reclaim = true;
|
in_reclaim = true;
|
||||||
|
const size_t sentenced_before = sentenced_buffers.Size();
|
||||||
|
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||||
|
const bool drained = sentenced_buffers.Size() != sentenced_before;
|
||||||
u64 freed = 0;
|
u64 freed = 0;
|
||||||
const auto clean_up = [&](BufferId buffer_id) {
|
const auto clean_up = [&](BufferId buffer_id) {
|
||||||
if (freed >= target_bytes) {
|
if (freed >= target_bytes) {
|
||||||
@@ -82,9 +85,10 @@ u64 BufferCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
|||||||
if (freed < target_bytes) {
|
if (freed < target_bytes) {
|
||||||
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, clean_up);
|
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, clean_up);
|
||||||
}
|
}
|
||||||
|
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||||
in_reclaim = false;
|
in_reclaim = false;
|
||||||
usage_refresh_countdown = 0;
|
usage_refresh_countdown = 0;
|
||||||
reclaim_stalled = freed == 0;
|
reclaim_stalled = freed == 0 && !drained;
|
||||||
return freed;
|
return freed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ public:
|
|||||||
return GetDeviceMemoryUsage();
|
return GetDeviceMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const {
|
||||||
|
return device.CanReportMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
void BindFastUniformBuffer(size_t stage, u32 binding_index, u32 size) {
|
void BindFastUniformBuffer(size_t stage, u32 binding_index, u32 size) {
|
||||||
const GLuint handle = fast_uniforms[stage][binding_index].handle;
|
const GLuint handle = fast_uniforms[stage][binding_index].handle;
|
||||||
const GLsizeiptr gl_size = static_cast<GLsizeiptr>(size);
|
const GLsizeiptr gl_size = static_cast<GLsizeiptr>(size);
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ public:
|
|||||||
return GetDeviceMemoryUsage();
|
return GetDeviceMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const {
|
||||||
|
return device.CanReportMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const {
|
bool CanReportMemoryUsage() const {
|
||||||
return device.CanReportMemoryUsage();
|
return device.CanReportMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ public:
|
|||||||
|
|
||||||
u64 GetDeviceAllocationUsage() const;
|
u64 GetDeviceAllocationUsage() const;
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const;
|
bool CanReportMemoryUsage() const;
|
||||||
|
|
||||||
u32 GetUniformBufferAlignment() const;
|
u32 GetUniformBufferAlignment() const;
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ public:
|
|||||||
|
|
||||||
u64 GetDeviceAllocationUsage() const;
|
u64 GetDeviceAllocationUsage() const;
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const;
|
bool CanReportMemoryUsage() const;
|
||||||
|
|
||||||
std::optional<size_t> GetSamplerHeapBudget() const;
|
std::optional<size_t> GetSamplerHeapBudget() const;
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ u64 TextureCache<P>::ImageSizeBytes(const ImageBase& image) {
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
u64 TextureCache<P>::DeviceUsage(bool force_refresh) {
|
u64 TextureCache<P>::DeviceUsage(bool force_refresh) {
|
||||||
if (!runtime.CanReportMemoryUsage()) {
|
if (!runtime.CanReportAllocationUsage()) {
|
||||||
return total_used_memory;
|
return total_used_memory;
|
||||||
}
|
}
|
||||||
if (force_refresh || usage_refresh_countdown == 0) {
|
if (force_refresh || usage_refresh_countdown == 0) {
|
||||||
@@ -171,6 +171,16 @@ u64 TextureCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
in_reclaim = true;
|
in_reclaim = true;
|
||||||
|
const u64 drain_point = runtime.CompletedSyncPoint();
|
||||||
|
const size_t sentenced_before = sentenced_images.Size() + sentenced_image_view.Size() +
|
||||||
|
sentenced_framebuffers.Size();
|
||||||
|
TickEvictionDownloads(drain_point);
|
||||||
|
sentenced_images.Reclaim(drain_point);
|
||||||
|
sentenced_image_view.Reclaim(drain_point);
|
||||||
|
sentenced_framebuffers.Reclaim(drain_point);
|
||||||
|
const bool drained = sentenced_images.Size() + sentenced_image_view.Size() +
|
||||||
|
sentenced_framebuffers.Size() !=
|
||||||
|
sentenced_before;
|
||||||
u64 freed = 0;
|
u64 freed = 0;
|
||||||
const auto evict = [&](ImageId image_id) {
|
const auto evict = [&](ImageId image_id) {
|
||||||
if (freed >= target_bytes) {
|
if (freed >= target_bytes) {
|
||||||
@@ -209,9 +219,13 @@ u64 TextureCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
|||||||
if (freed < target_bytes) {
|
if (freed < target_bytes) {
|
||||||
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, evict);
|
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, evict);
|
||||||
}
|
}
|
||||||
|
const u64 exit_point = runtime.CompletedSyncPoint();
|
||||||
|
sentenced_images.Reclaim(exit_point);
|
||||||
|
sentenced_image_view.Reclaim(exit_point);
|
||||||
|
sentenced_framebuffers.Reclaim(exit_point);
|
||||||
in_reclaim = false;
|
in_reclaim = false;
|
||||||
usage_refresh_countdown = 0;
|
usage_refresh_countdown = 0;
|
||||||
reclaim_stalled = freed == 0;
|
reclaim_stalled = freed == 0 && !drained;
|
||||||
return freed;
|
return freed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user