Skip to content

Commit

Permalink
Merge pull request #886 from pbdot/ec-new-render-metrics
Browse files Browse the repository at this point in the history
Adding new profiler metrics for debug_fps 3
  • Loading branch information
pbdot authored Feb 11, 2025
2 parents 6e7f612 + 22ca01f commit 8a812d4
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 65 deletions.
8 changes: 0 additions & 8 deletions libraries/tracy/edge_profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ struct ECFrameStats
int draw_planes;
int draw_wall_parts;
int draw_things;
int draw_light_iterator;
int draw_sector_glow_iterator;
int draw_state_change;
int draw_texture_change;

void Clear()
{
draw_render_units = 0;
draw_wall_parts = 0;
draw_planes = 0;
draw_things = 0;
draw_light_iterator = 0;
draw_sector_glow_iterator = 0;
draw_state_change = 0;
draw_texture_change = 0;
}
};

Expand Down
68 changes: 62 additions & 6 deletions source_files/edge/con_con.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "i_system.h"
#include "m_argv.h"
#include "n_network.h"
#include "r_backend.h"
#include "r_draw.h"
#include "r_image.h"
#include "r_modes.h"
Expand Down Expand Up @@ -860,9 +861,8 @@ void ConsoleDrawer(void)

if (console_wipe_active)
{
y = (int)((float)y - CON_GFX_HT *
HMM_Lerp(old_console_wipe_position, fractional_tic, console_wipe_position) /
kConsoleWipeTics);
y = (int)((float)y - CON_GFX_HT * HMM_Lerp(old_console_wipe_position, fractional_tic, console_wipe_position) /
kConsoleWipeTics);
}
else
y = y - CON_GFX_HT;
Expand Down Expand Up @@ -1612,6 +1612,24 @@ void ConsoleStart(void)
StartupProgressMessage("Starting console...");
}

static char *GetHumanSize(uint32_t bytes, char *hrbytes)
{
char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
char length = sizeof(suffix) / sizeof(suffix[0]);
int i;

for (i = 0; i < length; i++)
{
if (bytes < 1024)
break;

bytes >>= 10;
}

snprintf(hrbytes, 128, "%lu %s", bytes, suffix[i]);
return (hrbytes);
}

void ConsoleShowFPS(void)
{
if (debug_fps.d_ == 0)
Expand Down Expand Up @@ -1656,14 +1674,19 @@ void ConsoleShowFPS(void)
}
}

int x = current_screen_width - XMUL * 16;
int x = current_screen_width - XMUL * 20;
int y = current_screen_height - FNSZ * 2;

if (abs(debug_fps.d_) >= 2)
y -= FNSZ;

if (abs(debug_fps.d_) >= 3)
{
y -= (FNSZ * 4);
#ifdef EDGE_SOKOL
y -= (FNSZ * 7);
#endif
}

SolidBox(x, y, current_screen_width, current_screen_height, kRGBABlack, 0.5);

Expand Down Expand Up @@ -1712,11 +1735,44 @@ void ConsoleShowFPS(void)
stbsp_sprintf(textbuf, "%i thing", ec_frame_stats.draw_things);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;
stbsp_sprintf(textbuf, "%i state", ec_frame_stats.draw_state_change);

#ifdef EDGE_SOKOL

FrameStats stats;
render_backend->GetFrameStats(stats);

stbsp_sprintf(textbuf, "%i draw", stats.num_draw_);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;
stbsp_sprintf(textbuf, "%i texture", ec_frame_stats.draw_texture_change);

stbsp_sprintf(textbuf, "%i pipelines", stats.num_apply_pipeline_);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;

stbsp_sprintf(textbuf, "%i bindings", stats.num_apply_bindings_);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;

stbsp_sprintf(textbuf, "%i uniforms", stats.num_apply_uniforms_);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;

stbsp_sprintf(textbuf, "%i buffers", stats.num_update_buffer_);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;

char hrbytes[128];

GetHumanSize(stats.size_apply_uniforms_, hrbytes);
stbsp_sprintf(textbuf, "%s uniform size", hrbytes);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;
GetHumanSize(stats.size_update_buffer_, hrbytes);
stbsp_sprintf(textbuf, "%s buffer size", hrbytes);
DrawText(x, y, textbuf, kRGBAWebGray);
y -= FNSZ;

#endif
}

FinishUnitBatch();
Expand Down
2 changes: 0 additions & 2 deletions source_files/edge/p_blockmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ void DynamicLightIterator(float x1, float y1, float z1, float x2, float y2, floa
void *data)
{
EDGE_ZoneScoped;
ec_frame_stats.draw_light_iterator++;

int lx = LightmapGetX(x1) - 1;
int ly = LightmapGetY(y1) - 1;
Expand Down Expand Up @@ -877,7 +876,6 @@ void SectorGlowIterator(Sector *sec, float x1, float y1, float z1, float x2, flo
EPI_UNUSED(y2);
EPI_UNUSED(z2);
EDGE_ZoneScoped;
ec_frame_stats.draw_sector_glow_iterator++;

for (MapObject *mo = sec->glow_things; mo; mo = mo->dynamic_light_next_)
{
Expand Down
15 changes: 15 additions & 0 deletions source_files/edge/r_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ enum RenderLayer

typedef std::function<void()> FrameFinishedCallback;

struct FrameStats {
uint32_t num_apply_pipeline_;
uint32_t num_apply_bindings_;
uint32_t num_apply_uniforms_;
uint32_t num_draw_;
uint32_t num_update_buffer_;
uint32_t num_update_image_;

uint32_t size_apply_uniforms_;
uint32_t size_update_buffer_;
uint32_t size_append_buffer_;
};

class RenderBackend
{
public:
Expand Down Expand Up @@ -81,6 +94,8 @@ class RenderBackend

virtual void CaptureScreen(int32_t width, int32_t height, int32_t stride, uint8_t *dest) = 0;

virtual void GetFrameStats(FrameStats& stats) = 0;

int64_t GetFrameNumber()
{
return frame_number_;
Expand Down
6 changes: 6 additions & 0 deletions source_files/edge/render/gl/gl_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ class GLRenderBackend : public RenderBackend

void Flush(int32_t commands, int32_t vertices)
{

}

void GetFrameStats(FrameStats& stats)
{

}
};

Expand Down
Loading

0 comments on commit 8a812d4

Please sign in to comment.