diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-07 20:53:48 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-07 21:17:45 +0300 |
commit | 58353834f441b8b4ca91dcd4ec94ac49bbbf5ab0 (patch) | |
tree | 86d507e7ea388fde34cdc4ae7d874cc1c6f99d46 /source/blender | |
parent | c5c6b5ddb31c8a79667d6dcd689808efd3dadd8a (diff) |
GPUCapabilities: Isolate GL memory statistics
This is part of the Vulkan task T68990
This is a simple cleanup.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/intern/gpu_capabilities.cc | 30 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_capabilities_private.hh | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_context_private.hh | 1 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_backend.cc | 1 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_context.cc | 27 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_context.hh | 1 |
6 files changed, 36 insertions, 27 deletions
diff --git a/source/blender/gpu/intern/gpu_capabilities.cc b/source/blender/gpu/intern/gpu_capabilities.cc index 71bf479b4a8..0ee25ea2569 100644 --- a/source/blender/gpu/intern/gpu_capabilities.cc +++ b/source/blender/gpu/intern/gpu_capabilities.cc @@ -28,9 +28,9 @@ #include "GPU_capabilities.h" -#include "gpu_capabilities_private.hh" +#include "gpu_context_private.hh" -#include "gl_backend.hh" /* TODO remove */ +#include "gpu_capabilities_private.hh" namespace blender::gpu { @@ -110,34 +110,12 @@ bool GPU_crappy_amd_driver(void) bool GPU_mem_stats_supported(void) { -#ifndef GPU_STANDALONE - return (GLEW_NVX_gpu_memory_info || GLEW_ATI_meminfo); -#else - return false; -#endif + return GCaps.mem_stats_support; } void GPU_mem_stats_get(int *totalmem, int *freemem) { - /* TODO(merwin): use Apple's platform API to get this info */ - - if (GLEW_NVX_gpu_memory_info) { - /* returned value in Kb */ - glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, totalmem); - - glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, freemem); - } - else if (GLEW_ATI_meminfo) { - int stats[4]; - - glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, stats); - *freemem = stats[0]; - *totalmem = 0; - } - else { - *totalmem = 0; - *freemem = 0; - } + GPU_context_active_get()->memory_statistics_get(totalmem, freemem); } /* Return support for the active context + window. */ diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh index ec387555bfe..a51525fa932 100644 --- a/source/blender/gpu/intern/gpu_capabilities_private.hh +++ b/source/blender/gpu/intern/gpu_capabilities_private.hh @@ -41,12 +41,13 @@ struct GPUCapabilities { int max_textures_vert = 0; int max_textures_geom = 0; int max_textures_frag = 0; - + bool mem_stats_support = false; /* OpenGL related workarounds. */ bool mip_render_workaround = false; bool depth_blitting_workaround = false; bool use_main_context_workaround = false; bool broken_amd_driver = false; + /* Vulkan related workarounds. */ }; extern GPUCapabilities GCaps; diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh index 20e57c405ba..5643eec1aa6 100644 --- a/source/blender/gpu/intern/gpu_context_private.hh +++ b/source/blender/gpu/intern/gpu_context_private.hh @@ -76,6 +76,7 @@ struct GPUContext { virtual void activate(void) = 0; virtual void deactivate(void) = 0; + virtual void memory_statistics_get(int *total_mem, int *free_mem) = 0; bool is_active_on_thread(void); diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index fedc03f5787..3dfe0e1e412 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -339,6 +339,7 @@ void GLBackend::capabilities_init(void) glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &GCaps.max_textures_vert); glGetIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &GCaps.max_textures_geom); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &GCaps.max_textures); + GCaps.mem_stats_support = GLEW_NVX_gpu_memory_info || GLEW_ATI_meminfo; /* GL specific capabilities. */ glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &GLContext::max_texture_3d_size); glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &GLContext::max_cubemap_size); diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index ec6cc9e6159..ecf74a1993d 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -277,3 +277,30 @@ void GLContext::vao_cache_unregister(GLVaoCache *cache) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Memory statistics + * \{ */ + +void GLContext::memory_statistics_get(int *r_total_mem, int *r_free_mem) +{ + /* TODO(merwin): use Apple's platform API to get this info. */ + if (GLEW_NVX_gpu_memory_info) { + /* Teturned value in Kb. */ + glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, r_total_mem); + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, r_free_mem); + } + else if (GLEW_ATI_meminfo) { + int stats[4]; + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, stats); + + *r_total_mem = 0; + *r_free_mem = stats[0]; /* Total memory free in the pool. */ + } + else { + *r_total_mem = 0; + *r_free_mem = 0; + } +} + +/** \} */ diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index e2ae8bf24b2..06e59724f4a 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -97,6 +97,7 @@ class GLContext : public GPUContext { void activate(void) override; void deactivate(void) override; + void memory_statistics_get(int *total_mem, int *free_mem) override; static inline GLStateManager *state_manager_active_get() { |