diff --git a/libraries/tracy/edge_profiling.h b/libraries/tracy/edge_profiling.h index 44907fb97..c227c1188 100644 --- a/libraries/tracy/edge_profiling.h +++ b/libraries/tracy/edge_profiling.h @@ -9,10 +9,6 @@ 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() { @@ -20,10 +16,6 @@ struct ECFrameStats 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; } }; diff --git a/source_files/edge/con_con.cc b/source_files/edge/con_con.cc index 0cc01de35..b9da66e62 100644 --- a/source_files/edge/con_con.cc +++ b/source_files/edge/con_con.cc @@ -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" @@ -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; @@ -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) @@ -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); @@ -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(); diff --git a/source_files/edge/p_blockmap.cc b/source_files/edge/p_blockmap.cc index bf07eede6..90e47b6ad 100644 --- a/source_files/edge/p_blockmap.cc +++ b/source_files/edge/p_blockmap.cc @@ -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; @@ -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_) { diff --git a/source_files/edge/r_backend.h b/source_files/edge/r_backend.h index ce8a3e9c5..65229670b 100644 --- a/source_files/edge/r_backend.h +++ b/source_files/edge/r_backend.h @@ -25,6 +25,19 @@ enum RenderLayer typedef std::function 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: @@ -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_; diff --git a/source_files/edge/render/gl/gl_backend.cc b/source_files/edge/render/gl/gl_backend.cc index d82b4e1be..e2d150b44 100644 --- a/source_files/edge/render/gl/gl_backend.cc +++ b/source_files/edge/render/gl/gl_backend.cc @@ -166,6 +166,12 @@ class GLRenderBackend : public RenderBackend void Flush(int32_t commands, int32_t vertices) { + + } + + void GetFrameStats(FrameStats& stats) + { + } }; diff --git a/source_files/edge/render/gl/gl_state.cc b/source_files/edge/render/gl/gl_state.cc index aae4417f5..08e5efb4c 100644 --- a/source_files/edge/render/gl/gl_state.cc +++ b/source_files/edge/render/gl/gl_state.cc @@ -95,8 +95,6 @@ class GLRenderState : public RenderState { glDisable(cap); } - - ec_frame_stats.draw_state_change++; } void Disable(GLenum cap) @@ -113,7 +111,6 @@ class GLRenderState : public RenderState depth_mask_ = enable; glDepthMask(enable ? GL_TRUE : GL_FALSE); - ec_frame_stats.draw_state_change++; } void DepthFunction(GLenum func) @@ -126,7 +123,6 @@ class GLRenderState : public RenderState depth_function_ = func; glDepthFunc(depth_function_); - ec_frame_stats.draw_state_change++; } void CullFace(GLenum mode) @@ -138,7 +134,6 @@ class GLRenderState : public RenderState cull_face_ = mode; glCullFace(mode); - ec_frame_stats.draw_state_change++; } void AlphaFunction(GLenum func, GLfloat ref) @@ -152,7 +147,6 @@ class GLRenderState : public RenderState alpha_function_reference_ = ref; glAlphaFunc(alpha_function_, alpha_function_reference_); - ec_frame_stats.draw_state_change++; } void ActiveTexture(GLenum activeTexture) @@ -163,8 +157,7 @@ class GLRenderState : public RenderState } active_texture_ = activeTexture; - glActiveTexture(active_texture_); - ec_frame_stats.draw_state_change++; + glActiveTexture(active_texture_); } void BindTexture(GLuint textureid) @@ -176,9 +169,7 @@ class GLRenderState : public RenderState } bind_texture_2d_[index] = textureid; - glBindTexture(GL_TEXTURE_2D, textureid); - ec_frame_stats.draw_texture_change++; - ec_frame_stats.draw_state_change++; + glBindTexture(GL_TEXTURE_2D, textureid); } void Scissor(GLint x, GLint y, GLsizei width, GLsizei height) @@ -195,8 +186,7 @@ class GLRenderState : public RenderState polygon_offset_factor_ = factor; polygon_offset_units_ = units; - glPolygonOffset(polygon_offset_factor_, polygon_offset_units_); - ec_frame_stats.draw_state_change++; + glPolygonOffset(polygon_offset_factor_, polygon_offset_units_); } void Clear(GLbitfield mask) @@ -217,8 +207,7 @@ class GLRenderState : public RenderState clear_color_ = color; glClearColor(epi::GetRGBARed(clear_color_) / 255.0f, epi::GetRGBAGreen(clear_color_) / 255.0f, - epi::GetRGBABlue(clear_color_) / 255.0f, epi::GetRGBAAlpha(clear_color_) / 255.0f); - ec_frame_stats.draw_state_change++; + epi::GetRGBABlue(clear_color_) / 255.0f, epi::GetRGBAAlpha(clear_color_) / 255.0f); } void FogMode(GLint fogMode) @@ -229,8 +218,7 @@ class GLRenderState : public RenderState } fog_mode_ = fogMode; - glFogi(GL_FOG_MODE, fog_mode_); - ec_frame_stats.draw_state_change++; + glFogi(GL_FOG_MODE, fog_mode_); } void FogColor(RGBAColor color) @@ -244,8 +232,7 @@ class GLRenderState : public RenderState float gl_fc[4] = {epi::GetRGBARed(fog_color_) / 255.0f, epi::GetRGBAGreen(fog_color_) / 255.0f, epi::GetRGBABlue(fog_color_) / 255.0f, epi::GetRGBAAlpha(fog_color_) / 255.0f}; - glFogfv(GL_FOG_COLOR, gl_fc); - ec_frame_stats.draw_state_change++; + glFogfv(GL_FOG_COLOR, gl_fc); } void FogStart(GLfloat start) @@ -256,8 +243,7 @@ class GLRenderState : public RenderState } fog_start_ = start; - glFogf(GL_FOG_START, fog_start_); - ec_frame_stats.draw_state_change++; + glFogf(GL_FOG_START, fog_start_); } void FogEnd(GLfloat end) @@ -268,8 +254,7 @@ class GLRenderState : public RenderState } fog_end_ = end; - glFogf(GL_FOG_END, fog_end_); - ec_frame_stats.draw_state_change++; + glFogf(GL_FOG_END, fog_end_); } void FogDensity(GLfloat density) @@ -280,8 +265,7 @@ class GLRenderState : public RenderState } fog_density_ = density; - glFogf(GL_FOG_DENSITY, fog_density_); - ec_frame_stats.draw_state_change++; + glFogf(GL_FOG_DENSITY, fog_density_); } void GLColor(RGBAColor color) @@ -293,7 +277,6 @@ class GLRenderState : public RenderState gl_color_ = color; glColor4ub(epi::GetRGBARed(color), epi::GetRGBAGreen(color), epi::GetRGBABlue(color), epi::GetRGBAAlpha(color)); - ec_frame_stats.draw_state_change++; } void BlendFunction(GLenum sfactor, GLenum dfactor) @@ -306,7 +289,6 @@ class GLRenderState : public RenderState blend_source_factor_ = sfactor; blend_destination_factor_ = dfactor; glBlendFunc(blend_source_factor_, blend_destination_factor_); - ec_frame_stats.draw_state_change++; } void TextureEnvironmentMode(GLint param) @@ -319,8 +301,7 @@ class GLRenderState : public RenderState } texture_environment_mode_[index] = param; - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_environment_mode_[index]); - ec_frame_stats.draw_state_change++; + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_environment_mode_[index]); } void TextureEnvironmentCombineRGB(GLint param) @@ -334,7 +315,6 @@ class GLRenderState : public RenderState texture_environment_combine_rgb_[index] = param; glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, texture_environment_combine_rgb_[index]); - ec_frame_stats.draw_state_change++; } void TextureEnvironmentSource0RGB(GLint param) @@ -348,7 +328,6 @@ class GLRenderState : public RenderState texture_environment_source_0_rgb_[index] = param; glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, texture_environment_source_0_rgb_[index]); - ec_frame_stats.draw_state_change++; } void TextureMinFilter(GLint param) @@ -357,7 +336,6 @@ class GLRenderState : public RenderState texture_min_filter_[index] = param; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture_min_filter_[index]); - ec_frame_stats.draw_state_change++; } void TextureMagFilter(GLint param) @@ -366,7 +344,6 @@ class GLRenderState : public RenderState texture_mag_filter_[index] = param; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture_mag_filter_[index]); - ec_frame_stats.draw_state_change++; } void TextureWrapS(GLint param) @@ -378,7 +355,6 @@ class GLRenderState : public RenderState // know if a change needs to occur texture_wrap_s_[index] = param; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture_wrap_s_[index]); - ec_frame_stats.draw_state_change++; } void TextureWrapT(GLint param) @@ -390,7 +366,6 @@ class GLRenderState : public RenderState // know if a change needs to occur texture_wrap_t_[index] = param; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture_wrap_t_[index]); - ec_frame_stats.draw_state_change++; } void MultiTexCoord(GLuint tex, const HMM_Vec2 *coords) @@ -401,13 +376,11 @@ class GLRenderState : public RenderState glTexCoord2fv((GLfloat *)coords); else glMultiTexCoord2fv(tex, (GLfloat *)coords); - ec_frame_stats.draw_state_change++; } void Hint(GLenum target, GLenum mode) { glHint(target, mode); - ec_frame_stats.draw_state_change++; } void LineWidth(float width) @@ -418,7 +391,6 @@ class GLRenderState : public RenderState } line_width_ = width; glLineWidth(line_width_); - ec_frame_stats.draw_state_change++; } void DeleteTexture(const GLuint *tex_id) @@ -446,7 +418,6 @@ class GLRenderState : public RenderState front_face_ = wind; glFrontFace(wind); - ec_frame_stats.draw_state_change++; } void ShadeModel(GLenum model) @@ -458,7 +429,6 @@ class GLRenderState : public RenderState shade_model_ = model; glShadeModel(model); - ec_frame_stats.draw_state_change++; } void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) diff --git a/source_files/edge/render/sokol/sokol_backend.cc b/source_files/edge/render/sokol/sokol_backend.cc index d40b765ad..4b954e194 100644 --- a/source_files/edge/render/sokol/sokol_backend.cc +++ b/source_files/edge/render/sokol/sokol_backend.cc @@ -1,8 +1,6 @@ // clang-format off #include "../../r_backend.h" #include "sokol_local.h" -#include "sokol_imgui.h" -#include "sokol_gfx_imgui.h" #include "sokol_pipeline.h" #include "sokol_images.h" @@ -16,8 +14,10 @@ // clang-format on extern ConsoleVariable vsync; -void BSPStartThread(); -void BSPStopThread(); +extern ConsoleVariable debug_fps; + +void BSPStartThread(); +void BSPStopThread(); // from r_render.cc void RendererEndFrame(); @@ -102,6 +102,21 @@ class SokolRenderBackend : public RenderBackend { frame_number_++; + if (debug_fps.d_ >= 3) + { + if (!sg_frame_stats_enabled()) + { + sg_enable_frame_stats(); + } + } + else + { + if (sg_frame_stats_enabled()) + { + sg_disable_frame_stats(); + } + } + #ifdef SOKOL_D3D11 if (deferred_resize) { @@ -142,11 +157,13 @@ class SokolRenderBackend : public RenderBackend pass_.swapchain.d3d11.depth_stencil_view = sapp_d3d11_get_depth_stencil_view(); #endif + /* imgui_frame_desc_ = {0}; imgui_frame_desc_.width = width; imgui_frame_desc_.height = height; imgui_frame_desc_.delta_time = 100; imgui_frame_desc_.dpi_scale = 1; + */ EPI_CLEAR_MEMORY(world_state_, WorldState, kRenderWorldMax); @@ -195,20 +212,22 @@ class SokolRenderBackend : public RenderBackend void FinishFrame() { EDGE_ZoneNamedN(ZoneFinishFrame, "BackendFinishFrame", true); - + RendererEndFrame(); if (sgl_num_vertices()) { sgl_context_draw(context_pool_[current_context_]); } - + + /* { EDGE_ZoneNamedN(ZoneDrawImGui, "DrawImGui", true); sg_imgui_.caps_window.open = false; sg_imgui_.buffer_window.open = false; sg_imgui_.pipeline_window.open = false; sg_imgui_.attachments_window.open = false; + // NOTE: debug_fps controls stat gathering sg_imgui_.frame_stats_window.open = false; simgui_new_frame(&imgui_frame_desc_); @@ -216,6 +235,7 @@ class SokolRenderBackend : public RenderBackend simgui_render(); } + */ { EDGE_ZoneNamedN(ZoneDrawEndPass, "DrawEndPass", true); @@ -361,12 +381,14 @@ class SokolRenderBackend : public RenderBackend sgl_set_context(context_pool_[0]); // IMGUI + /* simgui_desc_t imgui_desc = {0}; imgui_desc.logger.func = slog_func; simgui_setup(&imgui_desc); const sgimgui_desc_t sg_imgui_desc = {0}; sgimgui_init(&sg_imgui_, &sg_imgui_desc); + */ InitPipelines(); InitImages(); @@ -408,17 +430,17 @@ class SokolRenderBackend : public RenderBackend if (sgl_num_vertices()) { sgl_context_draw(context_pool_[current_context_++]); - } + } sgl_set_context(sky_context_[render_state_.world_state_]); } if (layer != kRenderLayerSky && sgl_get_context().id == sky_context_[render_state_.world_state_].id) - { + { if (sgl_num_vertices()) { sgl_context_draw(sky_context_[render_state_.world_state_]); } - + sgl_set_context(context_pool_[current_context_]); matrix_mode_ = kMatrixModeUndefined; } @@ -500,6 +522,22 @@ class SokolRenderBackend : public RenderBackend SetRenderLayer(kRenderLayerHUD); } + void GetFrameStats(FrameStats &stats) + { + sg_frame_stats sg_stats = sg_query_frame_stats(); + + stats.num_apply_pipeline_ = sg_stats.num_apply_pipeline; + stats.num_apply_bindings_ = sg_stats.num_apply_bindings; + stats.num_apply_uniforms_ = sg_stats.num_apply_uniforms; + stats.num_draw_ = sg_stats.num_draw; + stats.num_update_buffer_ = sg_stats.num_update_buffer; + stats.num_update_image_ = sg_stats.num_update_image; + + stats.size_apply_uniforms_ = sg_stats.size_apply_uniforms; + stats.size_update_buffer_ = sg_stats.size_update_buffer; + stats.size_append_buffer_ = sg_stats.size_append_buffer; + } + private: enum MatrixMode { @@ -523,8 +561,10 @@ class SokolRenderBackend : public RenderBackend MatrixMode matrix_mode_; + /* simgui_frame_desc_t imgui_frame_desc_; sgimgui_t sg_imgui_; + */ RGBAColor clear_color_ = kRGBABlack; diff --git a/source_files/edge/render/sokol/sokol_units.cc b/source_files/edge/render/sokol/sokol_units.cc index 5a35d4877..e6952977f 100644 --- a/source_files/edge/render/sokol/sokol_units.cc +++ b/source_files/edge/render/sokol/sokol_units.cc @@ -246,6 +246,8 @@ static void RenderFlush() for (int32_t i = 0; i < current_render_unit; i++) { + ec_frame_stats.draw_render_units++; + RendererUnit *unit = &local_units[i]; // assume unit will require a command