Commit d5a992e6 authored by Rafael Cintron's avatar Rafael Cintron Committed by Commit Bot

Call IDXGIDevice3::Trim in GpuChannelManager::HandleMemoryPressure

Graphics drivers periodically allocate internal memory buffers in
order to speed up subsequent rendering requests. These memory allocations
in general lead to increased memory usage by the overall system.

Calling Trim discards internal memory buffers allocated for the app,
reducing its memory footprint.

Calling Trim method does not change the rendering state of the
graphics device and has no effect on rendering operations.

There is a brief performance hit when internal buffers are reallocated
during the first rendering operations after the Trim call, therefore
apps should only call Trim when going idle for a period of time or during
low memory conditions.

Bug: 1048920
Change-Id: Ic6a27fc5b05eb4084c85726fd3c4f82837f786a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037816
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738404}
parent 59c371df
......@@ -35,6 +35,9 @@
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "third_party/skia/include/core/SkGraphics.h"
#if defined(OS_WIN)
#include "ui/gl/gl_angle_util_win.h"
#endif
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_share_group.h"
#include "ui/gl/gl_version_info.h"
......@@ -50,6 +53,29 @@ const int kMaxGpuIdleTimeMs = 40;
// draw.
const int kMaxKeepAliveTimeMs = 200;
#endif
#if defined(OS_WIN)
void TrimD3DResources() {
// Graphics drivers periodically allocate internal memory buffers in
// order to speed up subsequent rendering requests. These memory allocations
// in general lead to increased memory usage by the overall system.
// Calling Trim discards internal memory buffers allocated for the app,
// reducing its memory footprint.
// Calling Trim method does not change the rendering state of the
// graphics device and has no effect on rendering operations.
// There is a brief performance hit when internal buffers are reallocated
// during the first rendering operations after the Trim call, therefore
// apps should only call Trim when going idle for a period of time or during
// low memory conditions.
Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device =
gl::QueryD3D11DeviceObjectFromANGLE();
if (d3d11_device) {
Microsoft::WRL::ComPtr<IDXGIDevice3> dxgi_device;
if (SUCCEEDED(d3d11_device.As(&dxgi_device))) {
dxgi_device->Trim();
}
}
}
#endif
}
GpuChannelManager::GpuPeakMemoryMonitor::GpuPeakMemoryMonitor()
......@@ -424,6 +450,9 @@ void GpuChannelManager::HandleMemoryPressure(
shared_context_state_->PurgeMemory(memory_pressure_level);
if (gr_shader_cache_)
gr_shader_cache_->PurgeMemory(memory_pressure_level);
#if defined(OS_WIN)
TrimD3DResources();
#endif
}
scoped_refptr<SharedContextState> GpuChannelManager::GetSharedContextState(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment