commit 43668d1da8b20d86589d2898e17cab0d9cc1965f parent 1b343b694065eccb6fdfdfa2920acfb1f7d420cf Author: Michael Savage <mikejsavage@gmail.com> Date: Wed Dec 28 00:24:11 +0200 More profiling Diffstat:
gpubtt.cc | | | 47 | ++++++++++++++++++++++++++++------------------- |
hm.cc | | | 35 | +++++++++++++++++++---------------- |
mod_btt.cc | | | 17 | +++++++++++++---- |
terrain_manager.cc | | | 3 | ++- |
diff --git a/gpubtt.cc b/gpubtt.cc @@ -57,30 +57,39 @@ void gpubtt_init( const v2s32 tr( ohm->hm.width - 1, ohm->hm.height - 1 ); { - PROFILE_BLOCK( "gpubtt_build" ); + PROFILE_BLOCK( "Convert BTT to mesh" ); gpubtt_build( verts, &num_vertices, ohm, btts.left_root, bl, tl, tr ); gpubtt_build( verts, &num_vertices, ohm, btts.right_root, tr, br, bl ); ASSERT( num_leaves * 3 == num_vertices ); } - TextureConfig normals_config; - normals_config.width = ohm->hm.width; - normals_config.height = ohm->hm.height; - normals_config.format = TEXFMT_RGB_FLOAT; - normals_config.data = normals; - gpubtt->normal_map = renderer_new_texture( normals_config ); - - TextureConfig horizons_config; - horizons_config.width = ohm->hm.width; - horizons_config.height = ohm->hm.height; - horizons_config.format = TEXFMT_R_FLOAT; - horizons_config.data = horizons; - gpubtt->horizon_map = renderer_new_texture( horizons_config ); - - MeshConfig mesh_config; - mesh_config.positions = renderer_new_vb( verts, num_vertices * sizeof( v3 ) ); - mesh_config.num_vertices = num_vertices; - gpubtt->mesh = renderer_new_mesh( mesh_config ); + { + PROFILE_BLOCK( "Upload normal map" ); + TextureConfig normals_config; + normals_config.width = ohm->hm.width; + normals_config.height = ohm->hm.height; + normals_config.format = TEXFMT_RGB_FLOAT; + normals_config.data = normals; + gpubtt->normal_map = renderer_new_texture( normals_config ); + } + + { + PROFILE_BLOCK( "Upload horizon map" ); + TextureConfig horizons_config; + horizons_config.width = ohm->hm.width; + horizons_config.height = ohm->hm.height; + horizons_config.format = TEXFMT_R_FLOAT; + horizons_config.data = horizons; + gpubtt->horizon_map = renderer_new_texture( horizons_config ); + } + + { + PROFILE_BLOCK( "Upload mesh" ); + MeshConfig mesh_config; + mesh_config.positions = renderer_new_vb( verts, num_vertices * sizeof( v3 ) ); + mesh_config.num_vertices = num_vertices; + gpubtt->mesh = renderer_new_mesh( mesh_config ); + } } void gpubtt_destroy( GPUBTT * gpubtt ) { diff --git a/hm.cc b/hm.cc @@ -257,22 +257,25 @@ extern "C" GAME_FRAME( game_frame ) { static ImmediateTriangle asdf[ megabytes( 1 ) ]; immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); - for( Fireball * fireball : fireballs ) { - v3 new_pos = fireball->pos + fireball->velocity * dt; - - float t; - if( segment_vs_terrain( &game->tm, fireball->pos, new_pos, &t ) ) { - Explosion * explosion = explosions.acquire(); - explosion->pos = fireball->pos + t * ( new_pos - fireball->pos ); - explosion->created_at = current_time; - - fireballs.release( fireball ); - } - else { - const float gravity = 9.81f; - fireball->pos = new_pos; - fireball->velocity.z -= dt * gravity; - immediate_sphere( &imm, fireball->pos, 4, v4( 1, 0, 0, 1 ) ); + { + PROFILE_BLOCK( "Update fireballs" ); + for( Fireball * fireball : fireballs ) { + v3 new_pos = fireball->pos + fireball->velocity * dt; + + float t; + if( segment_vs_terrain( &game->tm, fireball->pos, new_pos, &t, NULL ) ) { + Explosion * explosion = explosions.acquire(); + explosion->pos = fireball->pos + t * ( new_pos - fireball->pos ); + explosion->created_at = current_time; + + fireballs.release( fireball ); + } + else { + const float gravity = 9.81f; + fireball->pos = new_pos; + fireball->velocity.z -= dt * gravity; + immediate_sphere( &imm, fireball->pos, 4, v4( 1, 0, 0, 1 ) ); + } } } diff --git a/mod_btt.cc b/mod_btt.cc @@ -2,6 +2,7 @@ #include "intrinsics.h" #include "immediate.h" #include "skybox.h" +#include "profiler.h" #include "stb_image.h" #include "linear_algebra.h" #include "lz4.h" @@ -150,6 +151,8 @@ static HeightmapQuadTree qt; static UB ub_fs, ub_vs; extern "C" GAME_INIT( game_init ) { + PROFILE_FUNCTION(); + game->pos = v3( 100, 200, 100 ); game->angles = radians( v3( -90, 45, 0 ) ); @@ -171,9 +174,12 @@ extern "C" GAME_INIT( game_init ) { u8 * pixels = stbi_load( "terrains/" TERRAIN_NAME, &w, &h, NULL, 1 ); heightmap_init( &game->hm, pixels, w, h ); - size_t num_nodes = heightmap_quadtree_max_nodes( &game->hm ); - array< HeightmapQuadTreeNode > nodes = memarena_push_array( &mem->persistent_arena, HeightmapQuadTreeNode, num_nodes ); - qt = heightmap_build_quadtree( &game->hm, nodes ); + { + PROFILE_BLOCK( "Build quadtree" ); + size_t num_nodes = heightmap_quadtree_max_nodes( &game->hm ); + array< HeightmapQuadTreeNode > nodes = memarena_push_array( &mem->persistent_arena, HeightmapQuadTreeNode, num_nodes ); + qt = heightmap_build_quadtree( &game->hm, nodes ); + } size_t horizons_size = ( w + 1 ) * ( h + 1 ) * sizeof( float ); horizons = ( float * ) malloc( horizons_size ); @@ -199,7 +205,10 @@ extern "C" GAME_INIT( game_init ) { compressed_normals_size, normals_size ); assert( ok_normals > 0 ); - game->btt = btt_from_heightmap( &game->hm, &mem->persistent_arena ); + { + PROFILE_BLOCK( "Build BTT" ); + game->btt = btt_from_heightmap( &game->hm, &mem->persistent_arena ); + } const OffsetHeightmap ohm = { game->hm, 0, 0 }; gpubtt_init( &mem->persistent_arena, &game->gpubtt, game->btt, &ohm, normals, horizons ); diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -414,7 +414,6 @@ void terrain_render( TerrainManager * tm, const m4 & V, const m4 & P, float sun, ReadyTile ready_tile; while( tm->ready_tiles.dequeue( &ready_tile ) ) { - PROFILE_BLOCK( "upload BTT" ); s32 tx = ready_tile.tx; s32 ty = ready_tile.ty; @@ -549,6 +548,8 @@ v3 terrain_normal( const TerrainManager * tm, v3 position ) { } bool segment_vs_terrain( const TerrainManager * tm, v3 seg_origin, v3 seg_end, float * t ) { + PROFILE_FUNCTION(); + float segment_length = length( seg_end - seg_origin ); v3 ray_direction = normalize( seg_end - seg_origin );