Cleanup: DRW: Replace DRW_stats with GPU_debug

The former is not useful anymore and is being replaced
by the later.

Pull Request: https://projects.blender.org/blender/blender/pulls/134455
This commit is contained in:
Clément Foucault
2025-02-12 17:14:48 +01:00
committed by Clément Foucault
parent c31f396d91
commit 15437344ef
15 changed files with 56 additions and 475 deletions

View File

@@ -76,7 +76,6 @@ set(SRC
intern/draw_instance_data.cc
intern/draw_manager.cc
intern/draw_manager_c.cc
intern/draw_manager_profiling.cc
intern/draw_manager_shader.cc
intern/draw_manager_text.cc
intern/draw_pbvh.cc
@@ -178,7 +177,6 @@ set(SRC
intern/draw_instance_data.hh
intern/draw_manager.hh
intern/draw_manager_c.hh
intern/draw_manager_profiling.hh
intern/draw_manager_testing.hh
intern/draw_manager_text.hh
intern/draw_pass.hh

View File

@@ -25,7 +25,7 @@
#include "GPU_platform.hh"
#include "GPU_texture.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_camera.hh"
#include "eevee_instance.hh"
@@ -573,7 +573,7 @@ void DepthOfField::render(View &view,
GPU_flush();
}
DRW_stats_group_start("Depth of Field");
GPU_debug_group_begin("Depth of Field");
Manager &drw = *inst_.manager;
@@ -582,7 +582,7 @@ void DepthOfField::render(View &view,
constexpr eGPUTextureUsage usage_readwrite_attach = usage_readwrite |
GPU_TEXTURE_USAGE_ATTACHMENT;
{
DRW_stats_group_start("Setup");
GPU_debug_group_begin("Setup");
{
bokeh_gather_lut_tx_.acquire(int2(DOF_BOKEH_LUT_SIZE), GPU_RG16F);
bokeh_scatter_lut_tx_.acquire(int2(DOF_BOKEH_LUT_SIZE), GPU_R16F);
@@ -621,7 +621,7 @@ void DepthOfField::render(View &view,
setup_color_tx_.release();
}
{
DRW_stats_group_start("Tile Prepare");
GPU_debug_group_begin("Tile Prepare");
/* WARNING: If format changes, make sure dof_tile_* GLSL constants are properly encoded. */
tiles_fg_tx_.previous().acquire(tile_res, GPU_R11F_G11F_B10F, usage_readwrite);
@@ -665,7 +665,7 @@ void DepthOfField::render(View &view,
tiles_fg_tx_.previous().release();
tiles_bg_tx_.previous().release();
DRW_stats_group_end();
GPU_debug_group_end();
}
downsample_tx_.acquire(quarter_res, GPU_RGBA16F, usage_readwrite);
@@ -680,11 +680,11 @@ void DepthOfField::render(View &view,
/* Used by reduce pass. */
downsample_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
for (int is_background = 0; is_background < 2; is_background++) {
DRW_stats_group_start(is_background ? "Background Convolution" : "Foreground Convolution");
GPU_debug_group_begin(is_background ? "Background Convolution" : "Foreground Convolution");
SwapChain<TextureFromPool, 2> &color_tx = is_background ? color_bg_tx_ : color_fg_tx_;
SwapChain<TextureFromPool, 2> &weight_tx = is_background ? weight_bg_tx_ : weight_fg_tx_;
@@ -723,10 +723,10 @@ void DepthOfField::render(View &view,
/* Used by scatter pass. */
occlusion_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
{
DRW_stats_group_start("Hole Fill");
GPU_debug_group_begin("Hole Fill");
bokeh_gather_lut_tx_.release();
bokeh_scatter_lut_tx_.release();
@@ -738,10 +738,10 @@ void DepthOfField::render(View &view,
/* NOTE: We do not filter the hole-fill pass as effect is likely to not be noticeable. */
DRW_stats_group_end();
GPU_debug_group_end();
}
{
DRW_stats_group_start("Resolve");
GPU_debug_group_begin("Resolve");
resolve_stable_color_tx_ = dof_buffer.stabilize_history_tx_;
@@ -757,10 +757,10 @@ void DepthOfField::render(View &view,
hole_fill_weight_tx_.release();
bokeh_resolve_lut_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
DRW_stats_group_end();
GPU_debug_group_end();
/* Swap buffers so that next effect has the right input. */
std::swap(*input_tx, *output_tx);

View File

@@ -9,7 +9,7 @@
#include "GPU_capabilities.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_instance.hh"
@@ -949,7 +949,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
validity_tx_.clear(float4(0.0f));
virtual_offset_tx_.clear(float4(0.0f));
DRW_stats_group_start("IrradianceBake.SceneBounds");
GPU_debug_group_begin("IrradianceBake.SceneBounds");
{
draw::Manager &manager = *inst_.manager;
@@ -1006,7 +1006,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
scene_max += epsilon;
surfel_raster_views_sync(scene_min, scene_max, probe_object.object_to_world());
DRW_stats_group_end();
GPU_debug_group_end();
/* WORKAROUND: Sync camera with correct bounds for light culling. */
inst_.camera.sync();
@@ -1015,7 +1015,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
inst_.shadows.end_sync();
inst_.lights.end_sync();
DRW_stats_group_start("IrradianceBake.SurfelsCount");
GPU_debug_group_begin("IrradianceBake.SurfelsCount");
/* Raster the scene to query the number of surfel needed. */
capture_info_buf_.do_surfel_count = true;
@@ -1030,7 +1030,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
empty_raster_fb_.ensure(math::abs(transform_point(invert(basis_z_), grid_pixel_extent_).xy()));
inst_.pipelines.capture.render(view_z_);
DRW_stats_group_end();
GPU_debug_group_end();
/* Allocate surfel pool. */
GPU_memory_barrier(GPU_BARRIER_BUFFER_UPDATE);
@@ -1096,7 +1096,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
dispatch_per_surfel_.x = divide_ceil_u(surfels_buf_.size(), SURFEL_GROUP_SIZE);
DRW_stats_group_start("IrradianceBake.SurfelsCreate");
GPU_debug_group_begin("IrradianceBake.SurfelsCreate");
/* Raster the scene to generate the surfels. */
capture_info_buf_.do_surfel_count = true;
@@ -1116,7 +1116,7 @@ void IrradianceBake::surfels_create(const Object &probe_object)
/* Read back so that following push_update will contain correct surfel count. */
capture_info_buf_.read();
DRW_stats_group_end();
GPU_debug_group_end();
}
void IrradianceBake::surfels_lights_eval()

View File

@@ -10,7 +10,7 @@
#include "RE_engine.h"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_instance.hh"
#include "eevee_motion_blur.hh"
@@ -236,7 +236,7 @@ void MotionBlurModule::render(View &view, GPUTexture **input_tx, GPUTexture **ou
dispatch_dilate_size_ = int3(math::divide_ceil(tiles_extent, int2(MOTION_BLUR_GROUP_SIZE)), 1);
dispatch_gather_size_ = int3(math::divide_ceil(extent, int2(MOTION_BLUR_GROUP_SIZE)), 1);
DRW_stats_group_start("Motion Blur");
GPU_debug_group_begin("Motion Blur");
tiles_tx_.acquire(tiles_extent, GPU_RGBA16F);
@@ -246,7 +246,7 @@ void MotionBlurModule::render(View &view, GPUTexture **input_tx, GPUTexture **ou
tiles_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
/* Swap buffers so that next effect has the right input. */
*input_tx = output_color_tx_;

View File

@@ -17,7 +17,7 @@
#include "eevee_pipeline.hh"
#include "eevee_shadow.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "draw_common.hh"
@@ -437,7 +437,7 @@ void ForwardPipeline::render(View &view,
return;
}
DRW_stats_group_start("Forward.Opaque");
GPU_debug_group_begin("Forward.Opaque");
prepass_fb.bind();
inst_.manager->submit(prepass_ps_, view);
@@ -453,7 +453,7 @@ void ForwardPipeline::render(View &view,
inst_.manager->submit(opaque_ps_, view);
}
DRW_stats_group_end();
GPU_debug_group_end();
inst_.volume.draw_resolve(view);
@@ -982,7 +982,7 @@ void DeferredPipeline::render(View &main_view,
{
GPUTexture *feedback_tx = nullptr;
DRW_stats_group_start("Deferred.Opaque");
GPU_debug_group_begin("Deferred.Opaque");
feedback_tx = opaque_layer_.render(main_view,
render_view,
prepass_fb,
@@ -991,9 +991,9 @@ void DeferredPipeline::render(View &main_view,
extent,
rt_buffer_opaque_layer,
feedback_tx);
DRW_stats_group_end();
GPU_debug_group_end();
DRW_stats_group_start("Deferred.Refract");
GPU_debug_group_begin("Deferred.Refract");
feedback_tx = refraction_layer_.render(main_view,
render_view,
prepass_fb,
@@ -1002,7 +1002,7 @@ void DeferredPipeline::render(View &main_view,
extent,
rt_buffer_refract_layer,
feedback_tx);
DRW_stats_group_end();
GPU_debug_group_end();
}
/** \} */

View File

@@ -8,7 +8,7 @@
* The ray-tracing module class handles ray generation, scheduling, tracing and denoising.
*/
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_instance.hh"
@@ -417,7 +417,7 @@ RayTraceResult RayTraceModule::render(RayTraceBuffer &rt_buffer,
RayTraceResult result;
DRW_stats_group_start("Raytracing");
GPU_debug_group_begin("Raytracing");
const bool has_active_closure = active_closures != CLOSURE_NONE;
@@ -433,7 +433,7 @@ RayTraceResult RayTraceModule::render(RayTraceBuffer &rt_buffer,
if (has_active_closure) {
if (use_horizon_scan) {
DRW_stats_group_start("Horizon Scan");
GPU_debug_group_begin("Horizon Scan");
downsampled_in_radiance_tx_.acquire(tracing_res_horizon, RAYTRACE_RADIANCE_FORMAT, usage_rw);
downsampled_in_normal_tx_.acquire(tracing_res_horizon, GPU_RGB10_A2, usage_rw);
@@ -464,11 +464,11 @@ RayTraceResult RayTraceModule::render(RayTraceBuffer &rt_buffer,
downsampled_in_radiance_tx_.release();
downsampled_in_normal_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
}
DRW_stats_group_end();
GPU_debug_group_end();
rt_buffer.history_persmat = render_view.persmat();
@@ -512,7 +512,7 @@ RayTraceResultTexture RayTraceModule::trace(
eGPUTextureUsage usage_rw = GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE;
DRW_stats_group_start("Raytracing");
GPU_debug_group_begin("Raytracing");
data_.thickness = options.screen_trace_thickness;
data_.quality = 1.0f - 0.95f * options.screen_trace_quality;
@@ -633,7 +633,7 @@ RayTraceResultTexture RayTraceModule::trace(
denoise_variance_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
return result;
}

View File

@@ -13,9 +13,9 @@
#include "eevee_instance.hh"
#include "GPU_debug.hh"
#include "draw_cache.hh"
#include "draw_debug.hh"
#include "draw_manager_profiling.hh"
namespace blender::eevee {
@@ -1309,7 +1309,7 @@ void ShadowModule::set_view(View &view, int2 extent)
int loop_count = 0;
do {
DRW_stats_group_start("Shadow");
GPU_debug_group_begin("Shadow");
{
GPU_uniformbuf_clear_to_zero(shadow_multi_view_.matrices_ubo_get());
@@ -1376,7 +1376,7 @@ void ShadowModule::set_view(View &view, int2 extent)
GPU_memory_barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS | GPU_BARRIER_TEXTURE_FETCH);
}
DRW_stats_group_end();
GPU_debug_group_end();
loop_count++;

View File

@@ -17,7 +17,7 @@
#include "DRW_render.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_instance.hh"
@@ -81,7 +81,7 @@ void ShadingView::render()
update_view();
DRW_stats_group_start(name_);
GPU_debug_group_begin(name_);
/* Needs to be before planar_probes because it needs correct crypto-matte & render-pass buffers
* to reuse the same deferred shaders. */
@@ -162,7 +162,7 @@ void ShadingView::render()
rbufs.release();
postfx_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
void ShadingView::render_transparent_pass(RenderBuffers &rbufs)

View File

@@ -12,7 +12,7 @@
#include "GPU_capabilities.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
#include "eevee_instance.hh"
#include "eevee_pipeline.hh"
@@ -414,7 +414,7 @@ void VolumeModule::draw_prepass(View &main_view)
inst_.uniform_data.push_update();
DRW_stats_group_start("Volumes");
GPU_debug_group_begin("Volumes");
occupancy_fb_.bind();
inst_.pipelines.world_volume.render(main_view);
@@ -426,7 +426,7 @@ void VolumeModule::draw_prepass(View &main_view)
if (!current_objects_.is_empty()) {
inst_.pipelines.volume.render(volume_view, occupancy_tx_);
}
DRW_stats_group_end();
GPU_debug_group_end();
}
void VolumeModule::draw_compute(View &main_view, int2 extent)

View File

@@ -47,7 +47,7 @@
#include "ED_screen.hh"
#include "ED_view3d.hh"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
/* *********** FUNCTIONS *********** */
@@ -722,7 +722,7 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata,
* the masks already rendered in the buffer, and drawing only the layers not already drawn. */
bool cleared = false;
DRW_stats_group_start("GPencil Mask");
GPU_debug_group_begin("GPencil Mask");
GPU_framebuffer_bind(inst->mask_fb);
@@ -757,7 +757,7 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata,
manager->submit(inst->mask_invert_ps);
}
DRW_stats_group_end();
GPU_debug_group_end();
}
static void GPENCIL_draw_object(GPENCIL_Data *vedata,
@@ -769,7 +769,7 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata,
const float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
DRW_stats_group_start("GPencil Object");
GPU_debug_group_begin("GPencil Object");
GPUFrameBuffer *fb_object = (ob->vfx.first) ? inst->object_fb : inst->gpencil_fb;
@@ -814,7 +814,7 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata,
manager->submit(inst->merge_depth_ps, view);
}
DRW_stats_group_end();
GPU_debug_group_end();
}
static void GPENCIL_fast_draw_start(GPENCIL_Data *vedata)

View File

@@ -21,7 +21,7 @@
#include "BKE_camera.h"
#include "draw_manager_profiling.hh"
#include "GPU_debug.hh"
namespace blender::workbench {
/**
@@ -215,7 +215,7 @@ void DofPass::draw(Manager &manager, View &view, SceneResources &resources, int2
return;
}
DRW_stats_group_start("Depth Of Field");
GPU_debug_group_begin("Depth Of Field");
int2 half_res = {max_ii(resolution.x / 2, 1), max_ii(resolution.y / 2, 1)};
blur_tx_.acquire(
@@ -256,7 +256,7 @@ void DofPass::draw(Manager &manager, View &view, SceneResources &resources, int2
blur_tx_.release();
DRW_stats_group_end();
GPU_debug_group_end();
}
bool DofPass::is_enabled()

View File

@@ -165,10 +165,6 @@ DrawData *DRW_drawdata_ensure(ID *id,
size_t size,
DrawDataInitCb init_cb,
DrawDataFreeCb free_cb);
/**
* Return nullptr if not a dupli or a pointer of pointer to the engine data.
*/
void **DRW_duplidata_get(void *vedata);
/* Settings. */

View File

@@ -79,7 +79,6 @@
#include "draw_color_management.hh"
#include "draw_common_c.hh"
#include "draw_manager_c.hh"
#include "draw_manager_profiling.hh"
#ifdef WITH_GPU_DRAW_TESTS
# include "draw_manager_testing.hh"
#endif
@@ -613,16 +612,6 @@ static void drw_duplidata_free()
}
}
void **DRW_duplidata_get(void *vedata)
{
if (DST.dupli_source == nullptr) {
return nullptr;
}
ViewportEngineData *ved = (ViewportEngineData *)vedata;
DRWRegisteredDrawEngine *engine_type = ved->engine_type;
return &DST.dupli_datas[engine_type->index];
}
/** \} */
/* -------------------------------------------------------------------- */
@@ -962,13 +951,13 @@ static void drw_engines_draw_scene()
DRW_ENABLED_ENGINE_ITER (DST.view_data_active, engine, data) {
PROFILE_START(stime);
if (engine->draw_scene) {
DRW_stats_group_start(engine->idname);
GPU_debug_group_begin(engine->idname);
engine->draw_scene(data);
/* Restore for next engine */
if (DRW_state_is_fbo()) {
GPU_framebuffer_bind(DST.default_framebuffer);
}
DRW_stats_group_end();
GPU_debug_group_end();
}
PROFILE_END_UPDATE(data->render_time, stime);
}
@@ -1380,13 +1369,6 @@ void DRW_draw_callbacks_post_scene()
DRW_draw_gizmo_2d();
}
if (G.debug_value > 20 && G.debug_value < 30) {
GPU_depth_test(GPU_DEPTH_NONE);
/* local coordinate visible rect inside region, to accommodate overlapping ui */
const rcti *rect = ED_region_visible_rect(DST.draw_ctx.region);
DRW_stats_draw(rect);
}
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
}
else {
@@ -1584,8 +1566,6 @@ void DRW_draw_render_loop_ex(Depsgraph *depsgraph,
#endif
}
DRW_stats_begin();
GPU_framebuffer_bind(DST.default_framebuffer);
/* Start Drawing */
@@ -1607,8 +1587,6 @@ void DRW_draw_render_loop_ex(Depsgraph *depsgraph,
DRW_smoke_exit(DST.vmempool);
DRW_stats_reset();
DRW_draw_callbacks_post_scene();
if (WM_draw_region_get_bound_viewport(region)) {
@@ -2088,8 +2066,6 @@ void DRW_draw_render_loop_2d_ex(Depsgraph *depsgraph,
}
drw_task_graph_deinit();
DRW_stats_begin();
GPU_framebuffer_bind(DST.default_framebuffer);
/* Start Drawing */
@@ -2143,15 +2119,6 @@ void DRW_draw_render_loop_2d_ex(Depsgraph *depsgraph,
DRW_draw_gizmo_2d();
}
DRW_stats_reset();
if (G.debug_value > 20 && G.debug_value < 30) {
GPU_depth_test(GPU_DEPTH_NONE);
/* local coordinate visible rect inside region, to accommodate overlapping ui */
const rcti *rect = ED_region_visible_rect(DST.draw_ctx.region);
DRW_stats_draw(rect);
}
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
if (WM_draw_region_get_bound_viewport(region)) {
@@ -2930,7 +2897,6 @@ void DRW_engines_free()
DRW_curves_free();
DRW_volume_free();
DRW_shape_cache_free();
DRW_stats_free();
DRW_globals_free();
drw_debug_module_free(DST.debug);

View File

@@ -1,349 +0,0 @@
/* SPDX-FileCopyrightText: 2016 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup draw
*/
#include <algorithm>
#include "BLI_string.h"
#include "BKE_global.hh"
#include "BLF_api.hh"
#include "MEM_guardedalloc.h"
#include "draw_manager_c.hh"
#include "GPU_debug.hh"
#include "GPU_texture.hh"
#include "UI_resources.hh"
#include "draw_manager_profiling.hh"
#include "draw_view_data.hh"
#define MAX_TIMER_NAME 32
#define MAX_NESTED_TIMER 8
#define MIM_RANGE_LEN 8
#define GPU_TIMER_FALLOFF 0.1
struct DRWTimer {
uint32_t query[2];
uint64_t time_average;
char name[MAX_TIMER_NAME];
int lvl; /* Hierarchy level for nested timer. */
bool is_query; /* Does this timer actually perform queries or is it just a group. */
};
static struct DRWTimerPool {
DRWTimer *timers;
int chunk_count; /* Number of chunk allocated. */
int timer_count; /* chunk_count * CHUNK_SIZE */
int timer_increment; /* Keep track of where we are in the stack. */
int end_increment; /* Keep track of bad usage. */
bool is_recording; /* Are we in the render loop? */
bool is_querying; /* Keep track of bad usage. */
} DTP = {nullptr};
void DRW_stats_free()
{
if (DTP.timers != nullptr) {
// for (int i = 0; i < DTP.timer_count; i++) {
// DRWTimer *timer = &DTP.timers[i];
// glDeleteQueries(2, timer->query);
// }
MEM_freeN(DTP.timers);
DTP.timers = nullptr;
}
}
void DRW_stats_begin()
{
if (G.debug_value > 20 && G.debug_value < 30) {
DTP.is_recording = true;
}
if (DTP.is_recording && DTP.timers == nullptr) {
DTP.chunk_count = 1;
DTP.timer_count = DTP.chunk_count * MIM_RANGE_LEN;
DTP.timers = static_cast<DRWTimer *>(
MEM_callocN(sizeof(DRWTimer) * DTP.timer_count, "DRWTimer stack"));
}
else if (!DTP.is_recording && DTP.timers != nullptr) {
DRW_stats_free();
}
DTP.is_querying = false;
DTP.timer_increment = 0;
DTP.end_increment = 0;
}
static DRWTimer *drw_stats_timer_get()
{
if (UNLIKELY(DTP.timer_increment >= DTP.timer_count)) {
/* Resize the stack. */
DTP.chunk_count++;
DTP.timer_count = DTP.chunk_count * MIM_RANGE_LEN;
DTP.timers = static_cast<DRWTimer *>(
MEM_recallocN(DTP.timers, sizeof(DRWTimer) * DTP.timer_count));
}
return &DTP.timers[DTP.timer_increment++];
}
static void drw_stats_timer_start_ex(const char *name, const bool is_query)
{
if (DTP.is_recording) {
DRWTimer *timer = drw_stats_timer_get();
STRNCPY(timer->name, name);
timer->lvl = DTP.timer_increment - DTP.end_increment - 1;
timer->is_query = is_query;
/* Queries cannot be nested or interleaved. */
BLI_assert(!DTP.is_querying);
if (timer->is_query) {
if (timer->query[0] == 0) {
// glGenQueries(1, timer->query);
}
// glFinish();
/* Issue query for the next frame */
// glBeginQuery(GL_TIME_ELAPSED, timer->query[0]);
DTP.is_querying = true;
}
}
}
void DRW_stats_group_start(const char *name)
{
drw_stats_timer_start_ex(name, false);
GPU_debug_group_begin(name);
}
void DRW_stats_group_end()
{
GPU_debug_group_end();
if (DTP.is_recording) {
BLI_assert(!DTP.is_querying);
DTP.end_increment++;
}
}
void DRW_stats_query_start(const char *name)
{
GPU_debug_group_begin(name);
drw_stats_timer_start_ex(name, true);
}
void DRW_stats_query_end()
{
GPU_debug_group_end();
if (DTP.is_recording) {
DTP.end_increment++;
BLI_assert(DTP.is_querying);
// glEndQuery(GL_TIME_ELAPSED);
DTP.is_querying = false;
}
}
void DRW_stats_reset()
{
BLI_assert_msg((DTP.timer_increment - DTP.end_increment) <= 0,
"You forgot a DRW_stats_group/query_end somewhere!");
BLI_assert_msg((DTP.timer_increment - DTP.end_increment) >= 0,
"You forgot a DRW_stats_group/query_start somewhere!");
if (DTP.is_recording) {
uint64_t lvl_time[MAX_NESTED_TIMER] = {0};
/* Swap queries for the next frame and sum up each lvl time. */
for (int i = DTP.timer_increment - 1; i >= 0; i--) {
DRWTimer *timer = &DTP.timers[i];
std::swap(timer->query[0], timer->query[1]);
BLI_assert(timer->lvl < MAX_NESTED_TIMER);
if (timer->is_query) {
uint64_t time = 0;
if (timer->query[0] != 0) {
// glGetQueryObjectui64v(timer->query[0], GL_QUERY_RESULT, &time);
}
else {
time = 1000000000; /* 1ms default */
}
timer->time_average = timer->time_average * (1.0 - GPU_TIMER_FALLOFF) +
time * GPU_TIMER_FALLOFF;
timer->time_average = std::min(timer->time_average, uint64_t(1000000000));
}
else {
timer->time_average = lvl_time[timer->lvl + 1];
lvl_time[timer->lvl + 1] = 0;
}
lvl_time[timer->lvl] += timer->time_average;
}
DTP.is_recording = false;
}
}
static void draw_stat_5row(const rcti *rect, int u, int v, const char *txt, const int size)
{
BLF_draw_default(rect->xmin + (1 + u * 5) * U.widget_unit,
rect->ymax - (3 + v) * U.widget_unit,
0.0f,
txt,
size);
}
static void draw_stat(const rcti *rect, int u, int v, const char *txt, const int size)
{
BLF_draw_default(
rect->xmin + (1 + u) * U.widget_unit, rect->ymax - (3 + v) * U.widget_unit, 0.0f, txt, size);
}
void DRW_stats_draw(const rcti *rect)
{
char stat_string[64];
int lvl_index[MAX_NESTED_TIMER];
int v = 0, u = 0;
double init_tot_time = 0.0, background_tot_time = 0.0, render_tot_time = 0.0, tot_time = 0.0;
int fontid = BLF_default();
UI_FontThemeColor(fontid, TH_TEXT_HI);
BLF_batch_draw_begin();
/* ------------------------------------------ */
/* ---------------- CPU stats --------------- */
/* ------------------------------------------ */
/* Label row */
char col_label[32];
STRNCPY(col_label, "Engine");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
STRNCPY(col_label, "Init");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
STRNCPY(col_label, "Background");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
STRNCPY(col_label, "Render");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
STRNCPY(col_label, "Total (w/o cache)");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
v++;
/* Engines rows */
char time_to_txt[16];
DRW_ENABLED_ENGINE_ITER (DST.view_data_active, engine, data) {
u = 0;
draw_stat_5row(rect, u++, v, engine->idname, sizeof(engine->idname));
init_tot_time += data->init_time;
SNPRINTF(time_to_txt, "%.2fms", data->init_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
background_tot_time += data->background_time;
SNPRINTF(time_to_txt, "%.2fms", data->background_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
render_tot_time += data->render_time;
SNPRINTF(time_to_txt, "%.2fms", data->render_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
tot_time += data->init_time + data->background_time + data->render_time;
SNPRINTF(time_to_txt, "%.2fms", data->init_time + data->background_time + data->render_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
v++;
}
/* Totals row */
u = 0;
STRNCPY(col_label, "Sub Total");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
SNPRINTF(time_to_txt, "%.2fms", init_tot_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
SNPRINTF(time_to_txt, "%.2fms", background_tot_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
SNPRINTF(time_to_txt, "%.2fms", render_tot_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
SNPRINTF(time_to_txt, "%.2fms", tot_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
v += 2;
u = 0;
double *cache_time = DRW_view_data_cache_time_get(DST.view_data_active);
STRNCPY(col_label, "Cache Time");
draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
SNPRINTF(time_to_txt, "%.2fms", *cache_time);
draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
v += 2;
/* ------------------------------------------ */
/* ---------------- GPU stats --------------- */
/* ------------------------------------------ */
/* Memory Stats */
uint tex_mem = GPU_texture_memory_usage_get();
uint vbo_mem = GPU_vertbuf_get_memory_usage();
STRNCPY(stat_string, "GPU Memory");
draw_stat(rect, 0, v, stat_string, sizeof(stat_string));
SNPRINTF(stat_string, "%.2fMB", double(tex_mem + vbo_mem) / 1000000.0);
draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
STRNCPY(stat_string, "Textures");
draw_stat(rect, 1, v, stat_string, sizeof(stat_string));
SNPRINTF(stat_string, "%.2fMB", double(tex_mem) / 1000000.0);
draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
STRNCPY(stat_string, "Meshes");
draw_stat(rect, 1, v, stat_string, sizeof(stat_string));
SNPRINTF(stat_string, "%.2fMB", double(vbo_mem) / 1000000.0);
draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
v += 1;
/* GPU Timings */
STRNCPY(stat_string, "GPU Render Timings");
draw_stat(rect, 0, v++, stat_string, sizeof(stat_string));
for (int i = 0; i < DTP.timer_increment; i++) {
double time_ms, time_percent;
DRWTimer *timer = &DTP.timers[i];
DRWTimer *timer_parent = (timer->lvl > 0) ? &DTP.timers[lvl_index[timer->lvl - 1]] : nullptr;
/* Only display a number of lvl at a time */
if ((G.debug_value - 21) < timer->lvl) {
continue;
}
BLI_assert(timer->lvl < MAX_NESTED_TIMER);
lvl_index[timer->lvl] = i;
time_ms = timer->time_average / 1000000.0;
if (timer_parent != nullptr) {
time_percent = (double(timer->time_average) / double(timer_parent->time_average)) * 100.0;
}
else {
time_percent = 100.0;
}
/* avoid very long number */
time_ms = std::min(time_ms, 999.0);
time_percent = std::min(time_percent, 100.0);
SNPRINTF(stat_string, "%s", timer->name);
draw_stat(rect, 0 + timer->lvl, v, stat_string, sizeof(stat_string));
SNPRINTF(stat_string, "%.2fms", time_ms);
draw_stat(rect, 12 + timer->lvl, v, stat_string, sizeof(stat_string));
SNPRINTF(stat_string, "%.0f", time_percent);
draw_stat(rect, 16 + timer->lvl, v, stat_string, sizeof(stat_string));
v++;
}
BLF_batch_draw_end();
}

View File

@@ -1,30 +0,0 @@
/* SPDX-FileCopyrightText: 2016 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup draw
*/
#pragma once
struct rcti;
void DRW_stats_free();
void DRW_stats_begin();
void DRW_stats_reset();
/**
* Use this to group the queries. It does NOT keep track
* of the time, it only sum what the queries inside it.
*/
void DRW_stats_group_start(const char *name);
void DRW_stats_group_end();
/**
* \note Only call this when no sub timer will be called.
*/
void DRW_stats_query_start(const char *name);
void DRW_stats_query_end();
void DRW_stats_draw(const rcti *rect);