gsdx ogl: memory management take 3

Add a factor 2 on the VRAM to get the quantity of available memory for the textures.
The driver is allowed to put some textures in RAM. Of course it is bad for performance
but it won't crash.

Due to the 4GB by process limit, I keep a (reasonable) maximum of 3.8GB.

In order to avoid a crash when memory is too low an exception will be risen
with no guarantee on rendering and big performance impact. In this situation
you ought to reduce upscaling/disable large framebuffer.
This commit is contained in:
Gregory Hainaut 2016-07-10 10:23:23 +02:00
parent a37cd40ce3
commit 85fb55a0e1
2 changed files with 12 additions and 10 deletions

View File

@ -501,9 +501,6 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
if (GLLoader::fglrx_buggy_driver) {
// Full vram, remove a small margin for others buffer
glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, vram);
if (vram[0] > 200000)
vram[0] -= 128 * 1024;
} else if (GLLoader::found_GL_NVX_gpu_memory_info) {
// GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX <= give full memory
// Available vram
@ -512,10 +509,13 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
fprintf(stdout, "No extenstion supported to get available memory. Use default value !\n");
}
if (vram[0] > 0)
GLState::available_vram = (int64)(vram[0]) * 1024ul;
// When VRAM is at least 2GB, we set the limit to the default i.e. 3.8 GB
// When VRAM is below 2GB, we add a factor 2 because RAM can be used. Potentially
// low VRAM gpu can go higher but perf will be bad anyway.
if (vram[0] > 0 && vram[0] < 1800000)
GLState::available_vram = (int64)(vram[0]) * 1024ul * 2ul;
fprintf(stdout, "Available VRAM:%lldMB\n", GLState::available_vram >> 20u);
fprintf(stdout, "Available VRAM/RAM:%lldMB for textures\n", GLState::available_vram >> 20u);
// ****************************************************************
// Finish window setup and backbuffer

View File

@ -240,11 +240,13 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read)
m_mem_usage = (m_size.x * m_size.y) << m_int_shift;
static int every_16 = 0;
static int every_512 = 0;
GLState::available_vram -= m_mem_usage;
if ((GLState::available_vram < 0) && (every_16 % 16 == 0)) {
fprintf(stderr, "Available VRAM is very low, a crash is expected ! Disable Larger framebuffer or reduce upscaling!");
every_16++;
if ((GLState::available_vram < 0) && (every_512 % 512 == 0)) {
fprintf(stderr, "Available VRAM is very low (%lld), a crash is expected ! Disable Larger framebuffer or reduce upscaling!\n", GLState::available_vram);
every_512++;
// Pull emergency break
throw GSDXErrorOOM();
}
// Generate & Allocate the buffer