From 48b7fcb153d3941285cc5aea941d0a73fe91a273 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Fri, 8 Sep 2023 14:12:35 -0400 Subject: [PATCH 1/2] vk: add a bunch of profiler metrics Done as part of investigation for #555 --- ref/vk/vk_brush.c | 6 ++++++ ref/vk/vk_light.c | 2 ++ ref/vk/vk_ray_model.c | 13 +++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index fd225ba6..01a08e11 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -16,6 +16,7 @@ #include "r_speeds.h" #include "vk_staging.h" #include "vk_logs.h" +#include "profiler.h" #include "ref_params.h" #include "eiface.h" @@ -522,6 +523,7 @@ static qboolean brushCreateWaterModel(const model_t *mod, vk_brush_model_t *bmod } static void brushDrawWater(vk_brush_model_t *bmodel, const cl_entity_t *ent, int render_type, const vec4_t color, const matrix4x4 transform) { + APROF_SCOPE_DECLARE_BEGIN(brush_draw_water, __FUNCTION__); ASSERT(bmodel->water.surfaces_count > 0); fillWaterSurfaces(NULL, bmodel, bmodel->water.render_model.geometries); @@ -535,6 +537,8 @@ static void brushDrawWater(vk_brush_model_t *bmodel, const cl_entity_t *ent, int .transform = (const matrix4x4*)transform, .prev_transform = &bmodel->prev_transform, }); + + APROF_SCOPE_END(brush_draw_water); } // FIXME use this @@ -694,6 +698,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co geom->texture = tglob.whiteTexture; } } else { + APROF_SCOPE_DECLARE_BEGIN(brush_update_textures, "brush: update animated textures"); // Update animated textures int updated_textures_count = 0; for (int i = 0; i < bmodel->animated_indexes_count; ++i) { @@ -729,6 +734,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co if (updated_textures_count > 0) { R_RenderModelUpdateMaterials(&bmodel->render_model, g_brush.updated_textures, updated_textures_count); } + APROF_SCOPE_END(brush_update_textures); } R_RenderModelDraw(&bmodel->render_model, (r_model_draw_t){ diff --git a/ref/vk/vk_light.c b/ref/vk/vk_light.c index f944bda8..cd45d05c 100644 --- a/ref/vk/vk_light.c +++ b/ref/vk/vk_light.c @@ -1081,6 +1081,7 @@ int RT_LightAddPolygon(const rt_light_add_polygon_t *addpoly) { ASSERT(g_lights_.num_polygon_vertices + addpoly->num_vertices <= COUNTOF(g_lights_.polygon_vertices)); { + APROF_SCOPE_DECLARE_BEGIN(add_polygon, __FUNCTION__); rt_light_polygon_t *const poly = g_lights_.polygons + g_lights_.num_polygons; vec3_t *vertices = g_lights_.polygon_vertices + g_lights_.num_polygon_vertices; vec3_t normal; @@ -1143,6 +1144,7 @@ int RT_LightAddPolygon(const rt_light_add_polygon_t *addpoly) { } g_lights_.num_polygon_vertices += addpoly->num_vertices; + APROF_SCOPE_END(add_polygon); return g_lights_.num_polygons++; } } diff --git a/ref/vk/vk_ray_model.c b/ref/vk/vk_ray_model.c index b53ed231..0de8855a 100644 --- a/ref/vk/vk_ray_model.c +++ b/ref/vk/vk_ray_model.c @@ -10,6 +10,7 @@ #include "vk_math.h" #include "vk_combuf.h" #include "vk_logs.h" +#include "profiler.h" #include "eiface.h" #include "xash3d_mathlib.h" @@ -262,6 +263,8 @@ qboolean RT_ModelUpdateMaterials(struct rt_model_s *model, const struct vk_rende if (!geom_indices_count) return true; + APROF_SCOPE_DECLARE_BEGIN(update_materials, __FUNCTION__); + int begin = 0; for (int i = 1; i < geom_indices_count; ++i) { const int geom_index = geom_indices[i]; @@ -272,8 +275,10 @@ qboolean RT_ModelUpdateMaterials(struct rt_model_s *model, const struct vk_rende const int offset = geom_indices[begin]; const int count = i - begin; ASSERT(offset + count <= geometries_count); - if (!RT_KusochkiUpload(model->kusochki.offset + offset, geometries + offset, count, -1, NULL)) + if (!RT_KusochkiUpload(model->kusochki.offset + offset, geometries + offset, count, -1, NULL)) { + APROF_SCOPE_END(update_materials); return false; + } begin = i; } @@ -283,10 +288,14 @@ qboolean RT_ModelUpdateMaterials(struct rt_model_s *model, const struct vk_rende const int offset = geom_indices[begin]; const int count = geom_indices_count - begin; ASSERT(offset + count <= geometries_count); - if (!RT_KusochkiUpload(model->kusochki.offset + offset, geometries + offset, count, -1, NULL)) + if (!RT_KusochkiUpload(model->kusochki.offset + offset, geometries + offset, count, -1, NULL)) { + + APROF_SCOPE_END(update_materials); return false; + } } + APROF_SCOPE_END(update_materials); return true; } From 26a4fff4869bf504cb21b5eef47a8186e2791d8e Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Fri, 8 Sep 2023 14:21:00 -0400 Subject: [PATCH 2/2] vk: brush: improve animated surfaces detection Explicitly check that there are at least two different textures in an animation sequence. Fixes #555 --- ref/vk/vk_brush.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ref/vk/vk_brush.c b/ref/vk/vk_brush.c index 01a08e11..c2fa4ae0 100644 --- a/ref/vk/vk_brush.c +++ b/ref/vk/vk_brush.c @@ -417,7 +417,16 @@ static qboolean isSurfaceAnimated( const msurface_t *s, const struct texture_s * if( base->name[0] == '-' ) return false; - return true; + // It is not an animation if all textures are the same + const texture_t *prev = base; + base = base->anim_next; + while (base && base != prev) { + if (prev->gl_texturenum != base->gl_texturenum) + return true; + base = base->anim_next; + } + + return false; } typedef enum {