Docs / The project / Architecture
Memory
A 16 GB Mac shares its memory between the CPU and the GPU, so both count against the same budget.
Textures are kept compressed on the GPU (see FORMATS.md, "Textures on the GPU"): DXT files as blocks with their mip chains, other pictures compressed on the loader threads (
omsi-texture::bc, a PCA/least-squares BC1/BC3 encoder, about 1 µs a block) when the result stays close.Pictures read on the thread that draws go up as RGBA and are swapped for their compressed copy by
World::apply_texture_upgrades(the renderer rebuilds the bind groups of the materials using them).The timetable fleet: AI vehicle types are loaded without their CPU meshes (
VehicleType::load_ai; a mesh is read again when its set goes to the GPU).A tour keeps one vehicle and paint scheme all day, chosen from the tour, so the vehicles of the departures of the next 25 minutes are known: they are read on the workers and uploaded one at a time ahead of their departure (
Schedule::fleet), and a vehicle set nobody has drawn for 90 s and no coming departure wants leaves the GPU with the textures and meshes only it held (World::trim_vehicle_sets).An AI vehicle that goes gives its own instances, text and script textures and materials back to the free lists (
World::release_vehicle); they were only hidden before.Vehicle sets read ahead are made on the GPU by the worker too (meshes and textures: the device takes calls from any thread,
omsi_render::prepare_mesh/prepare_texture), so the upload on the thread that draws only puts them into the scene and makes the materials;materials made in one frame with the same textures and values share one bind group and uniform buffer (a C2 set: 965 materials, 60 ms before, about 4 ms now).
[matl_freetex]pictures (destination and line pictures, 1024×640 on the C2) are shared by all vehicles showing them and compressed like other late loads; an AI vehicle more than 50 m from the camera shows its script textures (1024×512 cockpit and passenger displays) as a texel of their mean colour, and gets them back within 40 m.OMSI's
[texmemlimit]: the scenery and vehicle textures have a budget (an eighth of the machine's memory;OMSI_TEXTURE_MEMORYfor tests).Once a second, while over it, the scenery textures that only tiles farther than 150 m use lose their finest mip level (a GPU copy into a smaller texture, farthest first, down to 64 texels a side); with a tenth of the budget free, those within 400 m are read again on a worker and swapped back.
Offscreen,
OMSI_BUDGET_FROM=x,y[,MB]meets the budget from another place first (and raises it) to check the way back.- The video memory: everything the game holds on the card - all textures, the meshes, and
the rest (render targets, shadow maps, buffers, the driver's own), which the driver counts
on DirectX 12, Vulkan (VK_EXT_memory_budget) and Metal, asked once a second
(
Renderer::gpu_memory; less the allocator's free room in its blocks, counted on a thread of its own; the rest is the least of the last three counts, as freed textures leave the driver's count late) and is worked out from the targets' sizes on OpenGL - stays within the "Video memory" setting (video_memory=,OMSI_VIDEO_MEMORY; nine tenths of a discrete card's memory when unset) and nine tenths of the driver's budget. What is over is taken from the textures in the same pass as their own budget. - Freed scene slots are handed out lowest first, and after unloads a free tail of the
scene's arrays is cut off (
World::compact_slots; a few live entries at the end keep the arrays long - moving live entries is not done). - Sound clips nobody holds (no sound set, no voice) and nobody asked for in a minute leave
the cache (
AudioEngine::trim_clips; 140 MB of every vehicle that ever came into earshot before) and are read again in the background; the map index hands its 345 000 object positions toWorld::object_positionsinstead of keeping a second copy. - A tile's surface raster (which texels roads and plates cover, at which heights, and the
terrain hole cutters) is kept in 16×16-texel blocks made when a surface first touches
them, and a finished tile drops the lowest and drivable height layers of a block where
they repeat the top surface (
TileSurface): 5 MB a tile before, about 0.6 MB now. macOS's allocator keeps freed large blocks dirty for reuse (more than half a gigabyte after a few tile loads, and
malloc_zone_pressure_reliefdoes not return them); the game restarts itself at once withMallocLargeCache=0(exec, same pid;OMSI_KEEP_ALLOCATOR=1skips it).The small-allocation zones are asked to give their free pages back on a thread of its own after tile loads and unloads and after the fleet shrinks.
OMSI_PROFILElogs, every ten seconds, the GPU memory by kind (scenery textures by format, vehicle textures, tiles' own, meshes, draw data) and the CPU side (object type meshes, staged tiles, surface rasters, wheel grids);OMSI_DEBUG_TEXTURESlists every vehicle texture uploaded and all textures by format and size.Ahlheim V5 main station with traffic 30, passengers and the timetable (window, 60 s): peak footprint (
/usr/bin/time -l) 8.75 GB before, 1.93 GB after, flat over the minute instead of growing by 700 MB; a flight over Ahlheim 8.54 → 2.05 GB (1.38 instead of 6.51 GB after flying back);Spandau with the EN92, traffic 30, passengers and the timetable 3.45 → 1.20 GB. Frames over 50 ms: 2 → 0, 3 → 0 and 0 → 0; average frame rate 51.7 → 57.6, 119 → 123 and 121 → 124 fps (1280×720 window, 1x MSAA).
Something wrong or missing? Fix it on GitHub or open an issue.