From 99b92651106898c7ad21d5629f9ee5ae829dfa94 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Wed, 2 Dec 2026 15:15:11 +0100 Subject: [PATCH 1/2] fix(gl46): keep the storage buffer binding points under 16 for Intel graphics The drivers of integrated Intel graphics offer 16 shader storage buffer binding points (GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS). The OpenGL 4.6 renderer used 16 (the water of the windscreens), 17 (the spherical harmonics of the cab probe) and 18 (the cells of the rain). Every material shader includes light_common.glsl, which declares the cab probe block, so none of them compiled on Intel and the whole scenery was drawn pink ("shader storage buffer binding must be less than ... (16)"). - the sky light (sky_ubo) and the light of the cab probe (cab_probe_ubo) are uniform blocks now: 9 vec4 each, which every fragment reads the same of, and which std140 lays out as std430 did. cabprobe_sh.comp still writes the probe's buffer as a storage buffer, bound right before its dispatch (gl::ssbo::bind_uniform() binds the same buffer as the block) - the result of the atmosphere and the write of the cab probe share binding point 9 with the other compute passes, which bind theirs right before their dispatch; the sky no longer keeps the atmosphere result bound - the water of the windscreens takes point 5 and the rain cells point 7 - gl::MAX_SSBO_BINDINGS (16) with a static_assert over every point, and the log gives the points the driver offers at start, with an error when there are fewer No extra binds per draw: the cost on NVIDIA and AMD stays what it was. The SPIR-V binaries of shaders/ogl46bin/ compiled from the old common.glsl are out of date and the shaders are compiled from the sources until they are made again (shaders/compile_spirv.py). feat/gl46-migration has the same points (water 16, cab probe 17) and needs the same change. --- gl/glsl_common.cpp | 3 +- gl/ssbo.cpp | 5 +++ gl/ssbo.h | 3 ++ gl/ubo.h | 43 ++++++++++++++++++------- rendering/opengl46/opengl46cabprobe.cpp | 5 +-- rendering/opengl46/opengl46cabprobe.h | 3 +- rendering/opengl46/opengl46renderer.cpp | 9 ++++++ rendering/opengl46/opengl46sky.cpp | 10 +++--- rendering/opengl46/opengl46sky.h | 4 +-- shaders/ogl46/clouds_march.comp | 2 +- shaders/ogl46/common.glsl | 15 +++++---- shaders/ogl46/light_common.glsl | 4 +-- 12 files changed, 74 insertions(+), 32 deletions(-) diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp index bfe1a4716..5a4a30669 100644 --- a/gl/glsl_common.cpp +++ b/gl/glsl_common.cpp @@ -78,7 +78,7 @@ void gl::glsl_common_setup() "#define ENVMAP_GGX_LEVELS " + std::to_string(ENVMAP_GGX_LEVELS) + "\n" + "#define ENVMAP_GGX_ROUGHNESS_MIN " + std::to_string(ENVMAP_GGX_ROUGHNESS_MIN) + "\n" + "#define ENVMAP_GGX_GROUP_SIZE " + std::to_string(ENVMAP_GGX_GROUP_SIZE) + "\n" + - "#define SKY_SSBO_BINDING " + std::to_string(SKY_SSBO_BINDING) + "\n" + + "#define SKY_UBO_BINDING " + std::to_string(SKY_UBO_BINDING) + "\n" + "#define EXPOSURE_SSBO_BINDING " + std::to_string(EXPOSURE_SSBO_BINDING) + "\n" + "#define EXPOSURE_HISTOGRAM_BINS " + std::to_string(EXPOSURE_HISTOGRAM_BINS) + "\n" + "#define EXPOSURE_HISTOGRAM_GROUP_SIZE " + std::to_string(EXPOSURE_HISTOGRAM_GROUP_SIZE) + "\n" + @@ -115,6 +115,7 @@ void gl::glsl_common_setup() "#define CAB_PROBE_MASK_TEX " + std::to_string(CAB_PROBE_MASK_TEX) + "\n" + "#define SKY_OCCLUSION_HEIGHT_TEX " + std::to_string(SKY_OCCLUSION_HEIGHT_TEX) + "\n" + "#define SKY_OCCLUSION_TEX " + std::to_string(SKY_OCCLUSION_TEX) + "\n" + + "#define CAB_PROBE_UBO_BINDING " + std::to_string(CAB_PROBE_UBO_BINDING) + "\n" + "#define CAB_PROBE_SSBO_BINDING " + std::to_string(CAB_PROBE_SSBO_BINDING) + "\n" + "#define CAB_PROBE_SH_SIZE " + std::to_string(CAB_PROBE_SH_SIZE) + "\n" + "#define CAB_PROBE_SH_GROUP_SIZE " + std::to_string(CAB_PROBE_SH_GROUP_SIZE) + "\n" + diff --git a/gl/ssbo.cpp b/gl/ssbo.cpp index 387fddc69..9b9d8b419 100644 --- a/gl/ssbo.cpp +++ b/gl/ssbo.cpp @@ -24,6 +24,11 @@ void gl::ssbo::bind_base() const glBindBuffersBase(GL_SHADER_STORAGE_BUFFER, m_index, 1, *this); } +void gl::ssbo::bind_uniform(GLuint const Index) const +{ + glBindBuffersBase(GL_UNIFORM_BUFFER, Index, 1, *this); +} + void gl::ssbo::resize(GLsizeiptr size) { if (size == m_size) diff --git a/gl/ssbo.h b/gl/ssbo.h index f8e5f9645..14857634f 100644 --- a/gl/ssbo.h +++ b/gl/ssbo.h @@ -19,6 +19,9 @@ namespace gl ~ssbo(); void bind_base() const; + // the same buffer as the uniform block of Index, for data a compute pass writes and the shading reads uniformly + // (std140 and std430 lay it out alike, e.g. vec4 arrays). glBindBuffersBase, like bind_base() + void bind_uniform(GLuint Index) const; void resize(GLsizeiptr size); GLsizeiptr size() const { diff --git a/gl/ubo.h b/gl/ubo.h index 6ee7d5d9a..b37d20474 100644 --- a/gl/ubo.h +++ b/gl/ubo.h @@ -357,7 +357,7 @@ namespace gl // 1 if the shading takes the lights of a fragment from the list of its cluster (lights_count is not used then), 0 if not. // set per pass: the cluster grid exists only for the color pass of a perspective view uint32_t lights_clustered; - // scale of the directional part of the sky ambient light (sky_ssbo): the factor the ambient light of the object + // scale of the directional part of the sky ambient light (sky_ubo): the factor the ambient light of the object // is scaled with (tunnels), 0 where the ambient light is not the sky's (model previews) float sky_ambient_factor; // 1 if the shading reads rough reflections from the prefiltered environment map, 0 if from the mipmaps of the plain one @@ -466,10 +466,13 @@ namespace gl static_assert(offsetof(cluster_counters, index_count) == 0, "bad layout of cluster_counters"); static_assert(offsetof(cluster_counters, overflow_count) == 4, "bad layout of cluster_counters"); - // binding points of the sky, exposure and atmosphere buffers: layout(binding = ...) in glsl_common - const GLuint SKY_SSBO_BINDING = 5; + // binding points of the sky, exposure and atmosphere buffers: layout(binding = ...) in glsl_common. the sky is a uniform + // block: 9 vec4 every fragment reads the same of, which keeps a storage buffer point free (see MAX_SSBO_BINDINGS). the + // result of the atmosphere is written by one compute pass only, which binds it right before its dispatch, so it shares + // a point with the other compute passes + const GLuint SKY_UBO_BINDING = 3; const GLuint EXPOSURE_SSBO_BINDING = 6; - const GLuint ATMOSPHERE_RESULT_SSBO_BINDING = 7; + const GLuint ATMOSPHERE_RESULT_SSBO_BINDING = 9; const GLuint ATMOSPHERE_UBO_BINDING = 4; // binding point of the per-instance modelview matrices of instanced draws (glsl: instance_ssbo, mat4 per instance). @@ -479,7 +482,7 @@ namespace gl // number of coefficients of the spherical harmonics of order 2 (bands 0..2) const size_t SKY_SH_COEFFICIENTS = 9; - // layout std430: directional part of the sky ambient light (GLSL: sky_ssbo). the coefficients of the real spherical + // layout std140 and std430 alike: directional part of the sky ambient light (GLSL: sky_ubo). the coefficients of the real spherical // harmonics of the light a surface facing a world space direction gets, in units of light_data.ambient, without the // constant band (that one is light_data.ambient itself); rgb used, w is padding struct sky_data @@ -487,15 +490,18 @@ namespace gl glm::vec4 ambient_sh[SKY_SH_COEFFICIENTS]; }; - // layout std430: the light of the lamps the occupied cab reflects, which lights the cab again (GLSL: cab_probe_ssbo, written by - // cabprobe_sh.comp from the probe of the cab): the coefficients of the real spherical harmonics of the light a surface facing a + // layout std140 and std430 alike: the light of the lamps the occupied cab reflects, which lights the cab again (GLSL: + // cab_probe_ubo, written by cabprobe_sh.comp from the probe of the cab as cab_probe_result_ssbo): the coefficients of the real spherical harmonics of the light a surface facing a // direction of the space of the probe gets, bands 0..2, in units of light_data.ambient; rgb used, w is padding struct cab_probe_data { glm::vec4 bounce_sh[SKY_SH_COEFFICIENTS]; }; - // binding point of the opengl renderer, bound with the colour passes - const GLuint CAB_PROBE_SSBO_BINDING = 17; + // binding points of the opengl renderer: the shading reads the buffer as a uniform block, bound with the colour passes; + // cabprobe_sh.comp writes it as a storage buffer, bound right before its dispatch, so it shares that point with the other + // compute passes + const GLuint CAB_PROBE_UBO_BINDING = 7; + const GLuint CAB_PROBE_SSBO_BINDING = 9; // the face of the level of the probe the spherical harmonics are taken from, at most, and the work group of cabprobe_sh.comp const size_t CAB_PROBE_SH_SIZE = 16; // the face of the level of the probe CAB_PROBE_MASK_TEX is a copy of, at most @@ -743,10 +749,10 @@ namespace gl // the binding points of the opengl renderer: the storage of the water (read by the glasses, written by the passes), the block // of the step of the simulation (water_ubs) and the texture unit of the mask of the wipers the map is baked from. the storage // point is used by nothing else, bound with the colour passes - const GLuint WATER_SSBO_BINDING = 16; + const GLuint WATER_SSBO_BINDING = 5; // the drops and the rivulets of the cells of the glasses with rain (mat_rain_windscreen, rain_cells.comp, rain_cells.glsl): worked // out once a frame for every cell, so a glass only reads them. RAIN_CELLS_COUNT uvec4, as rain_cells.glsl lays them out - const GLuint RAIN_CELLS_SSBO_BINDING = 18; + const GLuint RAIN_CELLS_SSBO_BINDING = 7; const size_t RAIN_DROP_CELLS = 512; const size_t RAIN_RIV_CELLS = 128; const size_t RAIN_RIV_LAYERS = 5; @@ -927,5 +933,20 @@ namespace gl static_assert(offsetof(shadow_fit_data, bounds) == 48, "bad layout of shadow_fit_data"); static_assert(sizeof(shadow_fit_data) == 48 + 32 * MAX_CASCADES, "bad size of shadow_fit_data"); + // the storage buffer binding points the renderer may use: GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS of the drivers of integrated + // Intel graphics, which is 16. a shader with a point past it doesn't compile there, and the material falls back to pink. what + // the shading reads uniformly and is small goes into a uniform block instead (sky_ubo, cab_probe_ubo); a point a compute pass + // binds right before its dispatch is shared by such passes + const GLuint MAX_SSBO_BINDINGS = 16; + static_assert(std::max({LIGHT_SSBO_BINDING, CLUSTER_AABB_SSBO_BINDING, CLUSTER_RANGE_SSBO_BINDING, CLUSTER_INDEX_SSBO_BINDING, + CLUSTER_COUNTER_SSBO_BINDING, EXPOSURE_SSBO_BINDING, ATMOSPHERE_RESULT_SSBO_BINDING, INSTANCE_SSBO_BINDING, + CAB_PROBE_SSBO_BINDING, WEATHER_SCRATCH_SSBO_BINDING, INSTANCE_RECORD_SSBO_BINDING, INSTANCE_JOB_SSBO_BINDING, + INSTANCE_GROUP_SSBO_BINDING, INSTANCE_LOD_SSBO_BINDING, INSTANCE_COUNTER_SSBO_BINDING, INSTANCE_OUTPUT_SSBO_BINDING, + INSTANCE_COMMAND_SSBO_BINDING, MODEL_DRAW_SSBO_BINDING, SHADOW_FIT_SSBO_BINDING, PARTICLE_SSBO_BINDING, + PARTICLE_SOURCE_SSBO_BINDING, PARTICLE_OWNER_SSBO_BINDING, PARTICLE_OUTPUT_SSBO_BINDING, PARTICLE_COMMAND_SSBO_BINDING, + TIMBER_LOCAL_SSBO_BINDING, TIMBER_RANGE_SSBO_BINDING, TIMBER_OUTPUT_SSBO_BINDING, TIMBER_ORIGIN_SSBO_BINDING, + WATER_SSBO_BINDING, RAIN_CELLS_SSBO_BINDING}) < MAX_SSBO_BINDINGS, + "a storage buffer binding point past what integrated Intel graphics offer"); + #pragma pack(pop) } diff --git a/rendering/opengl46/opengl46cabprobe.cpp b/rendering/opengl46/opengl46cabprobe.cpp index 67148a31e..db059a812 100644 --- a/rendering/opengl46/opengl46cabprobe.cpp +++ b/rendering/opengl46/opengl46cabprobe.cpp @@ -97,7 +97,7 @@ void opengl46_cab_probe::bind() glBindTextureUnit(gl::CAB_PROBE_ALBEDO_TEX, (m_albedo != 0) ? m_albedo : m_empty); glBindTextureUnit(gl::CAB_PROBE_MASK_TEX, (m_mask != 0) ? m_mask : m_empty); if (m_sh) - m_sh->bind_base(); + m_sh->bind_uniform(gl::CAB_PROBE_UBO_BINDING); } bool opengl46_cab_probe::gpu_allocate(int const Size) @@ -174,7 +174,8 @@ void opengl46_cab_probe::gpu_end() glProgramUniform2i(*m_sh_program, SH_LEVEL_LOCATION, sh_level(), sh_size()); m_sh->bind_base(); m_sh_program->dispatch(1); - glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); + // the shading reads it as a uniform block + glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_UNIFORM_BARRIER_BIT); opengl_texture::reset_unit_cache(); m_timer.end(); } diff --git a/rendering/opengl46/opengl46cabprobe.h b/rendering/opengl46/opengl46cabprobe.h index c920b34de..bbf6da7d5 100644 --- a/rendering/opengl46/opengl46cabprobe.h +++ b/rendering/opengl46/opengl46cabprobe.h @@ -30,7 +30,8 @@ class opengl46_cab_probe : public gfx::cab_probe // doesn't compile) there is no probe: logged, and gfx.cabprobe switched off void init(); // puts the maps (or the stand-ins) on their texture units, gl::CAB_PROBE_TEX, gl::CAB_PROBE_ALBEDO_TEX and the mask on - // gl::CAB_PROBE_MASK_TEX, and the spherical harmonics on gl::CAB_PROBE_SSBO_BINDING. once per context and frame + // gl::CAB_PROBE_MASK_TEX, and the spherical harmonics on the uniform block of + // gl::CAB_PROBE_UBO_BINDING. once per context and frame void bind(); // program of the probe, of the alpha tested materials when Alpha gl::program &program(bool const Alpha) diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp index d7b1cb24f..ba76b6a21 100644 --- a/rendering/opengl46/opengl46renderer.cpp +++ b/rendering/opengl46/opengl46renderer.cpp @@ -7502,6 +7502,15 @@ bool opengl46_renderer::Init_caps() WriteLog("shadows map size capped at " + std::to_string(m_shadowbuffersize) + "p"); } + // the storage buffer binding points the shaders use (gl::MAX_SSBO_BINDINGS); with fewer, the materials don't compile + { + GLint ssbobindings{0}; + ::glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &ssbobindings); + WriteLog(std::format("shader storage buffer binding points: {}", ssbobindings)); + if (ssbobindings < static_cast(gl::MAX_SSBO_BINDINGS)) + ErrorLog(std::format("the shaders need {} shader storage buffer binding points, the driver offers {}", gl::MAX_SSBO_BINDINGS, ssbobindings)); + } + clamp_multisampling(); if (Global.iMultisampling) { diff --git a/rendering/opengl46/opengl46sky.cpp b/rendering/opengl46/opengl46sky.cpp index 9f87800a5..548d045d0 100644 --- a/rendering/opengl46/opengl46sky.cpp +++ b/rendering/opengl46/opengl46sky.cpp @@ -77,8 +77,8 @@ void opengl46_sky::init() Global.gfx_envmap_ggx = false; } - m_sky_ssbo = std::make_unique(sizeof(gl::sky_data), gl::SKY_SSBO_BINDING); - m_sky_ssbo->update(m_sky_data); + m_sky_ubo = std::make_unique(sizeof(gl::sky_data), gl::SKY_UBO_BINDING); + m_sky_ubo->update(m_sky_data); m_atmosphere_ubo = std::make_unique(sizeof(gl::atmosphere_ubs), gl::ATMOSPHERE_UBO_BINDING); m_atmosphere_result_ssbo = std::make_unique(sizeof(gl::atmosphere_result), gl::ATMOSPHERE_RESULT_SSBO_BINDING); @@ -92,9 +92,9 @@ void opengl46_sky::init() void opengl46_sky::bind() { - m_sky_ssbo->bind_base(); + m_sky_ubo->bind_uniform(); m_atmosphere_ubo->bind_uniform(); - m_atmosphere_result_ssbo->bind_base(); + // the result of the atmosphere is bound by its pass only (update_atmosphere()): its point is shared by the compute passes } void opengl46_sky::update_atmosphere(glm::vec3 const &Sundirection) @@ -159,7 +159,7 @@ void opengl46_sky::update(opengl46_light &Sunlight, glm::vec3 &Fogcolor, CSkyDom if (!m_sky_data_uploaded || std::memcmp(&skydata, &m_sky_data, sizeof(skydata)) != 0) { m_sky_data = skydata; - m_sky_ssbo->update(m_sky_data); + m_sky_ubo->update(m_sky_data); m_sky_data_uploaded = true; } } diff --git a/rendering/opengl46/opengl46sky.h b/rendering/opengl46/opengl46sky.h index c5fbba8c1..bbc1c63e3 100644 --- a/rendering/opengl46/opengl46sky.h +++ b/rendering/opengl46/opengl46sky.h @@ -26,7 +26,7 @@ http://mozilla.org/MPL/2.0/. class CSkyDome; // light of the sky for the opengl 4.6 renderer: -// - the directional part of the ambient light, as spherical harmonics in sky_ssbo, worked out from the colours of the sky +// - the directional part of the ambient light, as spherical harmonics in sky_ubo, worked out from the colours of the sky // dome or from the physical atmosphere. the shading adds it to the uniform ambient light (light_common.glsl), so the // average of the ambient light stays what the rest of the renderer sets // - the physical atmosphere (Hillaire 2020, atmosphere_*.comp): look-up tables made in compute passes, the sky drawn from @@ -104,7 +104,7 @@ class opengl46_sky static GLuint create_table(GLsizei Width, GLsizei Height); // buffers the shaders read - std::unique_ptr m_sky_ssbo; + std::unique_ptr m_sky_ubo; std::unique_ptr m_atmosphere_ubo; std::unique_ptr m_atmosphere_result_ssbo; gl::sky_data m_sky_data{}; diff --git a/shaders/ogl46/clouds_march.comp b/shaders/ogl46/clouds_march.comp index a2d85c24e..05ed1b1fa 100644 --- a/shaders/ogl46/clouds_march.comp +++ b/shaders/ogl46/clouds_march.comp @@ -71,7 +71,7 @@ float cloud_phase(float cosangle, float scale) } // the light of the sky a face looking straight up (Up 1) or down (-1) gets: the uniform ambient light and the directional part of -// the sky light (sky_ssbo, light_common.glsl: sky_ambient_directional) along the vertical. with the physical atmosphere it is bluer +// the sky light (sky_ubo, light_common.glsl: sky_ambient_directional) along the vertical. with the physical atmosphere it is bluer // and brighter from above than from the sides, so the shaded sides of the clouds take the colour of the sky above them vec3 cloud_sky_light(float up) { diff --git a/shaders/ogl46/common.glsl b/shaders/ogl46/common.glsl index 0e727e3a1..d09a15dbb 100644 --- a/shaders/ogl46/common.glsl +++ b/shaders/ogl46/common.glsl @@ -61,8 +61,8 @@ #define WATER_TRAIL 1024 #define WATER_MAP 256 #define WATER_GROUP_SIZE 64 -#define WATER_SSBO_BINDING 16 -#define RAIN_CELLS_SSBO_BINDING 18 +#define WATER_SSBO_BINDING 5 +#define RAIN_CELLS_SSBO_BINDING 7 #define WATER_UBO_BINDING 6 #define WATER_MASK_TEX 25 #define WATER_LAYER_TEXELS 2097152 @@ -87,12 +87,12 @@ #define ENVMAP_GGX_LEVELS 7 #define ENVMAP_GGX_ROUGHNESS_MIN 0.200000 #define ENVMAP_GGX_GROUP_SIZE 8 -#define SKY_SSBO_BINDING 5 +#define SKY_UBO_BINDING 3 #define EXPOSURE_SSBO_BINDING 6 #define EXPOSURE_HISTOGRAM_BINS 256 #define EXPOSURE_HISTOGRAM_GROUP_SIZE 16 #define ATMOSPHERE_UBO_BINDING 4 -#define ATMOSPHERE_RESULT_SSBO_BINDING 7 +#define ATMOSPHERE_RESULT_SSBO_BINDING 9 #define ATMOSPHERE_TRANSMITTANCE_WIDTH 256 #define ATMOSPHERE_TRANSMITTANCE_HEIGHT 64 #define ATMOSPHERE_MULTISCATTERING_SIZE 32 @@ -123,7 +123,8 @@ #define SKY_OCCLUSION_HEIGHT_TEX 29 #define SKY_OCCLUSION_TEX 30 #define CAB_PROBE_MASK_TEX 31 -#define CAB_PROBE_SSBO_BINDING 17 +#define CAB_PROBE_UBO_BINDING 7 +#define CAB_PROBE_SSBO_BINDING 9 #define CAB_PROBE_SH_SIZE 16 #define CAB_PROBE_SH_GROUP_SIZE 64 #define WEATHER_UBO_BINDING 5 @@ -197,7 +198,7 @@ layout(std430, binding = LIGHT_SSBO_BINDING) readonly buffer light_ssbo uint lights_count; // 1 if the shading takes the lights from the list of the cluster of a fragment, see cluster_ubo uint lights_clustered; - // scale of the directional part of the sky ambient light, see sky_ssbo + // scale of the directional part of the sky ambient light, see sky_ubo float sky_ambient_factor; // 1 if rough reflections come from the prefiltered environment map uint env_ggx; @@ -207,7 +208,7 @@ layout(std430, binding = LIGHT_SSBO_BINDING) readonly buffer light_ssbo // directional part of the sky ambient light: real spherical harmonics (bands 1 and 2, band 0 is ambient) of the light // a surface facing a world space direction gets, in units of ambient. see gl::sky_data -layout(std430, binding = SKY_SSBO_BINDING) readonly buffer sky_ssbo +layout(std140, binding = SKY_UBO_BINDING) uniform sky_ubo { vec4 sky_ambient_sh[9]; }; diff --git a/shaders/ogl46/light_common.glsl b/shaders/ogl46/light_common.glsl index a49006820..cfb10758a 100644 --- a/shaders/ogl46/light_common.glsl +++ b/shaders/ogl46/light_common.glsl @@ -15,7 +15,7 @@ layout(binding = SCENE_AO_TEX) uniform sampler2D scene_ao; // itself with again (gl::cab_probe_data) layout(binding = CAB_PROBE_TEX) uniform samplerCube cab_probe_light; layout(binding = CAB_PROBE_ALBEDO_TEX) uniform samplerCube cab_probe_albedo; -layout(std430, binding = CAB_PROBE_SSBO_BINDING) readonly buffer cab_probe_ssbo +layout(std140, binding = CAB_PROBE_UBO_BINDING) uniform cab_probe_ubo { vec4 cab_probe_sh[9]; }; @@ -725,7 +725,7 @@ vec3 material_diffuse() return (value > 0.0 ? diffusecolor * (param[1].x / value) : vec3(0.0)); } -// directional part of the sky ambient light (sky_ssbo, bands 1 and 2 of the spherical harmonics) for a world space direction +// directional part of the sky ambient light (sky_ubo, bands 1 and 2 of the spherical harmonics) for a world space direction vec3 sky_ambient_directional(vec3 n) { return sky_ambient_sh[1].rgb * (0.488603 * n.y) From ed8708c5e27762c55297ec709800091124074dc8 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 2 Dec 2026 15:40:25 +0100 Subject: [PATCH 2/2] feat(simulation): snapshots, save the state of a running scenery and load it back (stage A) (#420) * feat(simulation): text format of simulation snapshots A snapshot of a running simulation is a text file in the syntax of the scenery files: entries of the form ... end, the first one a header which names the scenery. This is the text alone: entries, writer, reader, the names of the things of a scenery, the plan of coupling changes and the command line switches (--load-snapshot, --snapshot-at), in the core library with unit tests. Nothing reads or writes a snapshot yet. * feat(simulation): snapshot of time, weather, cells, switches and events (L1) --snapshot-at writes a snapshot when the simulation has run that long, --load-snapshot puts one over the scenery once it has loaded, before the first frame. This layer keeps the clock and the simulation timer, the weather with the wind, the random engine, the memory cells, the switches, the tracks an event can change and the ones made on the run, the traction power sources, the event queue, the timers of the launchers and the lamps of the signals. While a snapshot is put back the event manager is suspended, so nothing in the scenery reacts to it. Existing classes only get accessors for what was private (the fraction of the second, launcher timers, the speed limit of a track, the wind, the state of a power source, the event queue). Without the switches nothing changes. * feat(simulation): state of a vehicle's physics for snapshots (L3, core) What TMoverParameters holds of a running vehicle, to and from an entry of a snapshot: speed, load, controls, switches and relays, pantographs, doors, engine and its cooling, the air of the pipes, of every reservoir of the brake valve (with the flow it has yet to take in) and of the chambers of the driver's valves, the vigilance device, the power circuits. In the core library, tested on the real vehicle definitions: a vehicle restored on a fresh one saves the same, and runs on next to the one it was saved from. The brake valves, the driver's valves and the vigilance device get accessors for their private state (reservoirs(), latches(), pressures(), state()), a reservoir one for the flow it has yet to take in; nothing else in the physics changes. This comes before the vehicles of the scenery (L2), whose speed and load are kept by it. * feat(simulation): snapshot of vehicles and consists (L2) Every vehicle is kept with the place of both its axles (track, distance, direction, path of a switch, events still to set off), the way it faces, its couplings with their flags, destination and, through its physics, speed and load. Loaded, the vehicles are put straight where they were (TTrackFollower::Place(), which trails no switch and fires no event), then parted and joined until they are coupled as saved, whatever trainsets the scenery made of them. A vehicle of the snapshot the scenery does not have is skipped and reported, one the snapshot does not know stays as the scenery made it, one which had left the simulation is taken out again. * feat(simulation): pantographs and passenger exchange in snapshots (L3) What a vehicle keeps of its machinery beside its physics: the arms of the pantographs as they stand under the wire, the time without voltage, the passengers getting on and off, the lighting of the compartments, the headlight toggles, the last force asked of the electrodynamic brake. * feat(simulation): snapshot of the drivers and of the player's vehicle (L4) A driver is kept with its orders and the one it is on, the name of its timetable and its place in it, the consist it has, what it holds to (speeds of signals and limits, the reason it stands, its timers and flags), its table of what is ahead on the track with the point limits it has latched, its tables of what the brake of the consist gives, and whether the AI drives. A driver who had moved to another vehicle of its train is moved there. A run loaded in ghost view (the test mode) is ready before its first frame, as the run it goes on from was. The snapshot also names the vehicle the player was in, which --load-snapshot starts in unless -v says otherwise. * feat(simulation): snapshotsave command, on [Ctrl]+[Shift]+[F9] Writes a snapshot of the simulation to snapshots/__