Add buffer stats to love.graphics.getStats.

- Add 'buffers' field, to count the total number of graphics buffer objects.
- Add 'buffermemory' field, to estimate the total number of bytes of graphics memory used by all buffers.
This commit is contained in:
Sasha Szpakowski
2023-12-25 23:25:46 +01:00
parent 9c6417776f
commit e42019c59e
5 changed files with 23 additions and 2 deletions
+8
View File
@@ -29,6 +29,9 @@ namespace graphics
love::Type Buffer::type("GraphicsBuffer", &Object::type);
int Buffer::bufferCount = 0;
int64 Buffer::totalGraphicsMemory = 0;
Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDeclaration> &bufferformat, size_t size, size_t arraylength)
: arrayLength(0)
, arrayStride(0)
@@ -240,10 +243,15 @@ Buffer::Buffer(Graphics *gfx, const Settings &settings, const std::vector<DataDe
if (texelbuffer && arraylength * dataMembers.size() > caps.limits[Graphics::LIMIT_TEXEL_BUFFER_SIZE])
throw love::Exception("Cannot create texel buffer: total number of values in the buffer (%d * %d) is too large for this system (maximum %d).",
(int) dataMembers.size(), (int) arraylength, caps.limits[Graphics::LIMIT_TEXEL_BUFFER_SIZE]);
++bufferCount;
totalGraphicsMemory += size;
}
Buffer::~Buffer()
{
totalGraphicsMemory -= size;
--bufferCount;
}
int Buffer::getDataMemberIndex(const std::string &name) const
+3
View File
@@ -49,6 +49,9 @@ public:
static love::Type type;
static int bufferCount;
static int64 totalGraphicsMemory;
static const size_t SHADER_STORAGE_BUFFER_MAX_STRIDE = 2048;
enum MapType
+3 -1
View File
@@ -2422,8 +2422,10 @@ Graphics::Stats Graphics::getStats() const
stats.drawCallsBatched = drawCallsBatched;
stats.textures = Texture::textureCount;
stats.fonts = Font::fontCount;
stats.buffers = Buffer::bufferCount;
stats.textureMemory = Texture::totalGraphicsMemory;
stats.bufferMemory = Buffer::totalGraphicsMemory;
return stats;
}
+2
View File
@@ -230,7 +230,9 @@ public:
int shaderSwitches;
int textures;
int fonts;
int buffers;
int64 textureMemory;
int64 bufferMemory;
};
struct DrawCommand
+7 -1
View File
@@ -3005,9 +3005,15 @@ int w_getStats(lua_State *L)
lua_pushinteger(L, stats.fonts);
lua_setfield(L, -2, "fonts");
lua_pushinteger(L, stats.textureMemory);
lua_pushinteger(L, stats.buffers);
lua_setfield(L, -2, "buffers");
lua_pushnumber(L, (lua_Number) stats.textureMemory);
lua_setfield(L, -2, "texturememory");
lua_pushnumber(L, (lua_Number) stats.bufferMemory);
lua_setfield(L, -2, "buffermemory");
return 1;
}