Support retrieving available GPU memory size
This commit is contained in:
parent
19d8637f7a
commit
5f3b07573e
2 changed files with 40 additions and 0 deletions
11
libs/gfx/include/psemek/gfx/memory.hpp
Normal file
11
libs/gfx/include/psemek/gfx/memory.hpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
std::optional<std::size_t> available_memory();
|
||||
|
||||
}
|
||||
29
libs/gfx/source/memory.cpp
Normal file
29
libs/gfx/source/memory.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <psemek/gfx/memory.hpp>
|
||||
#include <psemek/gfx/gl.hpp>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
std::optional<std::size_t> available_memory()
|
||||
{
|
||||
static bool const nvx = gl::sys::has_extension("GL_NVX_gpu_memory_info");
|
||||
static bool const ati = gl::sys::has_extension("GL_ATI_meminfo");
|
||||
|
||||
if (nvx)
|
||||
{
|
||||
GLint value = 0;
|
||||
gl::GetIntegerv(0x9049, &value);
|
||||
return static_cast<std::size_t>(value) * 1024;
|
||||
}
|
||||
|
||||
if (ati)
|
||||
{
|
||||
GLint values[4]{};
|
||||
gl::GetIntegerv(0x87FC, values);
|
||||
return static_cast<std::size_t>(values[0]) * 1024;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue