Modify GPU timer API;

- lovr.graphics.tock returns the latest value of the timer, or 0.
- Timers are not in the stats table anymore.

This is to prepare for an upcoming internal change that affects timers.
This commit is contained in:
bjorn 2019-09-18 18:21:38 -07:00
parent e96c541244
commit 1902787b1b
3 changed files with 8 additions and 25 deletions

View File

@ -412,8 +412,8 @@ static int l_lovrGraphicsTick(lua_State* L) {
static int l_lovrGraphicsTock(lua_State* L) {
lovrGraphicsFlush();
const char* label = luaL_checkstring(L, 1);
lovrGraphicsTock(label);
return 0;
lua_pushnumber(L, lovrGraphicsTock(label));
return 1;
}
static int l_lovrGraphicsGetFeatures(lua_State* L) {
@ -464,13 +464,6 @@ static int l_lovrGraphicsGetStats(lua_State* L) {
lua_setfield(L, 1, "drawcalls");
lua_pushinteger(L, stats->shaderSwitches);
lua_setfield(L, 1, "shaderswitches");
lua_createtable(L, 0, (int) stats->timers.length);
for (size_t i = 0; i < stats->timers.length; i++) {
lua_pushstring(L, stats->timers.data[i].label);
lua_pushnumber(L, stats->timers.data[i].time);
lua_settable(L, -3);
}
lua_setfield(L, 1, "timers");
return 1;
}

View File

@ -1,6 +1,5 @@
#include "graphics/font.h"
#include "data/modelData.h"
#include "core/arr.h"
#include "core/maf.h"
#include "util.h"
#include "platform.h"
@ -195,15 +194,9 @@ typedef struct {
int blockAlign;
} GpuLimits;
typedef struct {
const char* label;
double time;
} GpuTimer;
typedef struct {
int shaderSwitches;
int drawCalls;
arr_t(GpuTimer) timers;
} GpuStats;
typedef struct {
@ -227,7 +220,7 @@ void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback call
void lovrGpuPresent(void);
void lovrGpuDirtyTexture(void);
void lovrGpuTick(const char* label);
void lovrGpuTock(const char* label);
double lovrGpuTock(const char* label);
const GpuFeatures* lovrGpuGetFeatures(void);
const GpuLimits* lovrGpuGetLimits(void);
const GpuStats* lovrGpuGetStats(void);

View File

@ -1091,8 +1091,6 @@ void lovrGpuInit(getProcAddressProc getProcAddress) {
arr_init(&state.incoherents[i]);
}
arr_init(&state.stats.timers);
TextureData* textureData = lovrTextureDataCreate(1, 1, 0xff, FORMAT_RGBA);
state.defaultTexture = lovrTextureCreate(TEXTURE_2D, &textureData, 1, true, false, 0);
lovrTextureSetFilter(state.defaultTexture, (TextureFilter) { .mode = FILTER_NEAREST });
@ -1111,7 +1109,6 @@ void lovrGpuDestroy() {
for (int i = 0; i < MAX_BARRIERS; i++) {
arr_free(&state.incoherents[i]);
}
arr_free(&state.stats.timers);
memset(&state, 0, sizeof(state));
}
@ -1222,8 +1219,7 @@ void lovrGpuDraw(DrawCommand* draw) {
}
void lovrGpuPresent() {
state.stats.drawCalls = state.stats.shaderSwitches = 0;
arr_clear(&state.stats.timers);
memset(&state.stats, 0, sizeof(state.stats));
}
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata) {
@ -1282,10 +1278,10 @@ void lovrGpuTick(const char* label) {
#endif
}
void lovrGpuTock(const char* label) {
double lovrGpuTock(const char* label) {
#ifndef LOVR_WEBGL
TimerList* timer = map_get(&state.timers, label);
if (!timer) return;
if (!timer) return 0.;
glEndQuery(GL_TIME_ELAPSED);
@ -1297,9 +1293,10 @@ void lovrGpuTock(const char* label) {
}
glGetQueryObjectui64v(timer->timers[timer->oldest], GL_QUERY_RESULT, &timer->ns);
arr_push(&state.stats.timers, ((GpuTimer) { .label = label, .time = timer->ns / 1e9 }));
timer->oldest = (timer->oldest + 1) % 4;
}
return timer->ns / 1e9;
#endif
}