18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 05:02:45 +01:00

feat(render): the geometry of the scenery models and the data of the textures streamed, on by default

The streaming of the geometry of EU07M models (modelstreaming) and the streaming of the textures (gfx.textures.streaming) are now
both on by default; either is turned off in eu07.ini with "no", and turned off the game does what it did before.

Geometry (modelstreaming yes, with modelformat eu07m):
- A scenery model (node ... model) of an .eu07m file of at least modelstreaming.minsize KiB (256), without skins, stars and texts of
  E3D and with BNDS, has only its structure read at the load: one read of the beginning of the file (eu07m::read_file() with
  read_options::streams false, validate_scope::structure). Vehicles, cabs, loads and every other model load whole, as before; a
  streamed model asked for by anything else gets its geometry loaded and kept (TModelsManager::GetModel(..., Streamable)).
- Its geometry bank keeps its chunks empty (gfx::residency). A bank without its data draws nothing and is asked of the streamer
  (rendering/geometrystreamer.h): threads read and unpack the streams and the GREF blocks, nearest first, and the main thread hands
  them to the banks, 64 MB or 3 ms a frame. A bank unused for modelstreaming.evictafter s (30) lets go of its data in memory and on
  the GPU; above modelstreaming.budget MB (0, no limit) sooner. Whatever reads the vertices (picking, editor, sky occlusion) gets
  them loaded at once. The walks kept by the GPU culling are made anew when a bank got its data.
- The nodes, materials, components, clips and channels stay loaded: the walk goes through an instance without its geometry as
  through any other (RaAnimate(), RaPrepare()), only its draws are left out, so animations, lights and the events at their ends
  keep their timing. The radius of a streamed model and the bounds of its branches come from BNDS instead of the vertices.
- rendering/common/modelprefetch.h goes through the cells within the draw range and 500 m, 32 a frame, and asks for the geometry
  of the streamed models ahead of their drawing.

Textures (gfx.textures.streaming yes):
- The same pass has the data of the textures of the instances, shapes and tracks in reach read ahead by the texture workers in the
  Vulkan renderer (the OpenGL renderer has its own pass); the read-ahead data not drawn for 5 minutes or left behind is dropped.
- The loading screen waits, two minutes at most, for the geometry and the textures around the start and, in Vulkan, for their
  images made on the GPU (vulkan14_texture::request_background(false), made()).

Measured on Tomaszewo, Vulkan, editor self-test flight start to Kaletnik, four runs on an idle machine, alternated:
- peak committed memory 11.0 GB without streaming, 7.0 GB with textures, 6.2 GB with both; working set 9.0 / 4.8 / 4.2 GB
  (the copies of the texture data were 4.5 GB, the geometry banks 1.55 GB);
- scenario load 104-145 s without, 95-97 s with;
- frame time over the flight the same (11.8-12.5 ms), draws without their texture at the start the same as without streaming and
  fewer in the flight (380 against 636); the prefetch costs the main thread 0.1-0.2 ms a frame.

Also: the self-test commands "modelstream evict|wait|stats" and "memory <label>" (rendering/common/memoryreport.h, a breakdown of
the memory of the process), file_parts (utilities/wholefile.h) for reads of parts of a file, and the docs in docs/eu07m-format.md
("Streaming of the geometry"). The format doesn't change and no asset change is needed. Unit tests: test_eu07m_streaming.cpp.
This commit is contained in:
maj00r
2026-11-29 20:22:15 +01:00
parent b03fff75df
commit 89405a6eaf
43 changed files with 2408 additions and 66 deletions
+140
View File
@@ -0,0 +1,140 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "rendering/common/memoryreport.h"
#include "audio/audiorenderer.h"
#include "model/AnimModel.h"
#include "model/MdlMngr.h"
#include "model/Texture.h"
#include "world/Track.h"
#include "rendering/geometrybank.h"
#include "rendering/geometrystreamer.h"
#include "scene/scene.h"
#include "simulation/simulation.h"
#include "utilities/memorystats.h"
#include <format>
namespace gfx {
namespace {
double megabytes( std::uint64_t const Bytes ) {
return static_cast<double>( Bytes ) / ( 1024.0 * 1024.0 );
}
// the world space vertices the shapes and the lines of the scenery keep, the transforms of the sleepers, the model instances
struct scenery_memory {
memory_count shapes;
memory_count lines;
memory_count sleepers;
std::uint64_t instances { 0 };
};
void count_cell( scene::basic_cell const &Cell, scenery_memory &Memory ) {
for( auto const *list : { &Cell.m_shapesopaque, &Cell.m_shapestranslucent } ) {
for( auto const &shape : *list ) {
++Memory.shapes.count;
Memory.shapes.bytes += memory_of( shape.data().vertices ) + memory_of( shape.data().userdata );
}
}
for( auto const &line : Cell.m_lines ) {
++Memory.lines.count;
Memory.lines.bytes += memory_of( line.data().vertices );
}
for( auto const *track : Cell.m_paths ) {
if( track->m_sleeper_local_transforms.empty() ) { continue; }
++Memory.sleepers.count;
Memory.sleepers.bytes += memory_of( track->m_sleeper_local_transforms );
}
Memory.instances += Cell.m_instancesopaque.size() + Cell.m_instancetranslucent.size();
}
scenery_memory count_scenery() {
scenery_memory memory;
if( simulation::Region == nullptr ) { return memory; }
for( auto const *section : simulation::Region->m_sections ) {
if( section == nullptr ) { continue; }
for( auto const &shape : section->m_shapes ) {
++memory.shapes.count;
memory.shapes.bytes += memory_of( shape.data().vertices ) + memory_of( shape.data().userdata );
}
for( auto const &cell : section->m_cells ) {
count_cell( cell, memory );
}
}
return memory;
}
void report_heap( std::uint64_t const Committed, std::vector<std::string> &Lines ) {
if( false == heap_counting() ) {
Lines.emplace_back( "heap: not counted (debug.memorystats yes)" );
return;
}
auto const heap { query_heap_memory() };
Lines.emplace_back( std::format( "heap: {:.1f} MB taken with new in {} blocks, the rest of the private memory {:.1f} MB (drivers, libraries)", megabytes( heap.bytes ), heap.blocks,
megabytes( Committed > heap.bytes ? Committed - heap.bytes : 0 ) ) );
auto const large { query_large_blocks() };
std::size_t constexpr shown { 20 };
for( std::size_t index = 0; ( index < large.sites.size() ) && ( index < shown ); ++index ) {
auto const &site { large.sites[ index ] };
Lines.emplace_back( std::format( " large blocks {:.1f} MB in {}: {}", megabytes( site.bytes ), site.blocks, site.place ) );
}
}
} // namespace
std::vector<std::string> memory_report( texture_bank const *Textures, geometrybank_manager const &Geometry ) {
std::vector<std::string> lines;
auto const process { query_process_memory() };
if( process.valid ) {
lines.emplace_back( std::format( "process: {:.1f} MB private, {:.1f} MB resident (peak {:.1f} MB)", megabytes( process.committed ), megabytes( process.resident ),
megabytes( process.peak ) ) );
}
std::uint64_t accounted { 0 };
if( Textures != nullptr ) {
auto const textures { Textures->memory() };
accounted += textures.cpu.bytes + textures.readahead.bytes;
lines.emplace_back( std::format( "textures: {} keep their data in ram, {:.1f} MB; {} on the card, ~{:.1f} MB; read ahead {} {:.1f} MB, {} being read, {} not read till needed",
textures.cpu.count, megabytes( textures.cpu.bytes ), textures.gpu.count, megabytes( textures.gpu.bytes ), textures.readahead.count, megabytes( textures.readahead.bytes ),
textures.reading, textures.waiting ) );
}
auto const geometry { Geometry.memory() };
accounted += geometry.vertices.bytes + geometry.indices.bytes + geometry.userdata.bytes;
lines.emplace_back( std::format( "geometry banks: {}, {} chunks: vertices {:.1f} MB, indices {:.1f} MB, user data {:.1f} MB", geometry.banks, geometry.vertices.count,
megabytes( geometry.vertices.bytes ), megabytes( geometry.indices.bytes ), megabytes( geometry.userdata.bytes ) ) );
auto const streamed { geometry_streamer::instance().stats() };
lines.emplace_back( std::format( " of them streamed: {} banks with their data, {:.1f} MB", streamed.resident, megabytes( streamed.bytes ) ) );
auto const models { TModelsManager::memory() };
accounted += models.submodels.bytes;
lines.emplace_back( std::format( "models: {}, {} submodels, their own geometry {:.1f} MB", models.models, models.submodels.count, megabytes( models.submodels.bytes ) ) );
auto const scenery { count_scenery() };
accounted += scenery.shapes.bytes + scenery.lines.bytes + scenery.sleepers.bytes + scenery.instances * sizeof( TAnimModel );
lines.emplace_back( std::format( "scenery: {} shapes {:.1f} MB, {} lines {:.1f} MB, sleepers of {} tracks {:.1f} MB, {} model instances {:.1f} MB", scenery.shapes.count,
megabytes( scenery.shapes.bytes ), scenery.lines.count, megabytes( scenery.lines.bytes ), scenery.sleepers.count, megabytes( scenery.sleepers.bytes ), scenery.instances,
megabytes( scenery.instances * sizeof( TAnimModel ) ) ) );
auto const sounds { audio::renderer.buffers_memory() };
accounted += sounds.bytes;
lines.emplace_back( std::format( "sounds: {} buffers {:.1f} MB", sounds.count, megabytes( sounds.bytes ) ) );
if( process.valid ) {
lines.emplace_back( std::format( "counted above: {:.1f} MB of {:.1f} MB private, the rest {:.1f} MB", megabytes( accounted ), megabytes( process.committed ),
megabytes( process.committed > accounted ? process.committed - accounted : 0 ) ) );
}
report_heap( process.committed, lines );
return lines;
}
} // namespace gfx