mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 01:32:43 +01:00
fix(render): texture streaming by default with Vulkan only, the streamer after a fallback, failed banks tried again
After review of #555: - gfx.textures.streaming is on by default with the Vulkan renderer only, the one it was measured with; with OpenGL it stays off as before. A value set in eu07.ini is kept for either renderer. A Vulkan renderer falling back to OpenGL as it starts goes without it. The default turned on is logged, as the settings are logged before the renderer is chosen. - The geometry streamer stopped by the shutdown of a Vulkan renderer that failed to start resumes for the OpenGL renderer made after it (geometry_streamer::resume()); before, every streamed model stayed undrawn for the session. - A bank whose load failed is tried again: 5 s after the first failure, twice as long after each one that follows, up to 5 min, by the streamer as it's drawn and by load_now(). Only the first failure in a row is logged. A transient read error no longer leaves the model undrawn till a restart.
This commit is contained in:
@@ -79,6 +79,18 @@ ui_layer uilayerstaticinitializer;
|
||||
|
||||
namespace
|
||||
{
|
||||
// gfx.textures.streaming not set in eu07.ini: the textures are streamed with the vulkan renderer, which was measured with it, and
|
||||
// read whole with opengl as before
|
||||
void default_texture_streaming()
|
||||
{
|
||||
if (Global.gfx_texture_streaming_set)
|
||||
return;
|
||||
Global.gfx_texture_streaming = (Global.GfxRenderer == "vulkan");
|
||||
// the settings were logged before the renderer was chosen
|
||||
if (Global.gfx_texture_streaming)
|
||||
WriteLog("gfx.textures.streaming yes: the default of the vulkan renderer");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// windows wakes a sleeping thread of a process which didn't ask for a finer timer in steps of up to ~15.6 ms.
|
||||
// the wait of fpslimit sleeps, so a 10 ms frame slot of fpslimit 100 ended ~15.6 ms later, the pacer made it up
|
||||
@@ -1615,6 +1627,7 @@ void eu07_application::select_gfx_backend()
|
||||
{
|
||||
m_gfxbackend = factory->backend("modern");
|
||||
}
|
||||
default_texture_streaming();
|
||||
|
||||
crashreport_add_info("gfxrenderer", Global.GfxRenderer);
|
||||
WriteLog("renderer: " + (m_gfxbackend != nullptr ? m_gfxbackend->name : std::string("none")));
|
||||
@@ -1697,6 +1710,7 @@ int eu07_application::fallback_to_opengl(std::string const &Reason)
|
||||
crashreport_add_info("gfxrenderer_fallback", Reason);
|
||||
Global.GfxRenderer = "default";
|
||||
m_gfxbackend = gfx_renderer_factory::get_instance()->backend("modern");
|
||||
default_texture_streaming();
|
||||
crashreport_add_info("gfxrenderer", Global.GfxRenderer);
|
||||
WriteLog("renderer: " + (m_gfxbackend != nullptr ? m_gfxbackend->name : std::string("none")));
|
||||
|
||||
@@ -1759,6 +1773,8 @@ int eu07_application::init_gfx()
|
||||
// the reason is in the log already
|
||||
GfxRenderer->Shutdown();
|
||||
GfxRenderer.reset();
|
||||
// the shutdown of the vulkan renderer stopped the streaming of the geometry; opengl streams it too
|
||||
gfx::geometry_streamer::instance().resume();
|
||||
if (fallback_to_opengl("the renderer failed to start") != 0)
|
||||
{
|
||||
return -1;
|
||||
|
||||
@@ -595,14 +595,41 @@ geometry_bank::touch( float const Priority ) {
|
||||
|
||||
if( false == streamed() ) { return; }
|
||||
m_lastused.store( geometry_streamer::now(), std::memory_order_relaxed );
|
||||
auto current { state() };
|
||||
// a bank whose load failed is asked for again once in a while: a read error that passes (an antivirus, a lock of the file)
|
||||
// doesn't leave the model undrawn till a restart
|
||||
if( ( current == residency::failed ) && retry_due_() ) {
|
||||
auto expected { residency::failed };
|
||||
if( m_residency.compare_exchange_strong( expected, residency::absent, std::memory_order_acq_rel ) ) {
|
||||
current = residency::absent;
|
||||
}
|
||||
}
|
||||
// a bank being loaded is asked for again only when it's wanted sooner, so the queue of the streamer isn't locked by every draw
|
||||
if( auto const current { state() };
|
||||
( current == residency::absent )
|
||||
if( ( current == residency::absent )
|
||||
|| ( ( current == residency::loading ) && ( Priority < requested_priority() ) ) ) {
|
||||
geometry_streamer::instance().request( *this, Priority );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
geometry_bank::note_failure_() {
|
||||
|
||||
m_failedat.store( geometry_streamer::now(), std::memory_order_relaxed );
|
||||
m_failures.fetch_add( 1, std::memory_order_relaxed );
|
||||
m_epoch.fetch_add( 1, std::memory_order_acq_rel );
|
||||
m_residency.store( residency::failed, std::memory_order_release );
|
||||
}
|
||||
|
||||
bool
|
||||
geometry_bank::retry_due_() const {
|
||||
|
||||
auto const failures { m_failures.load( std::memory_order_relaxed ) };
|
||||
auto const doublings { std::min<std::uint32_t>( failures > 0 ? failures - 1 : 0, 6 ) };
|
||||
auto const wait { std::min<std::uint32_t>( 5'000u << doublings, 300'000u ) };
|
||||
// the clock of the streamer counts milliseconds; the difference holds across its wrap
|
||||
return ( geometry_streamer::now() - m_failedat.load( std::memory_order_relaxed ) ) >= wait;
|
||||
}
|
||||
|
||||
// the streamer: a load begun for an absent bank
|
||||
bool
|
||||
geometry_bank::begin_load( float const Priority ) {
|
||||
@@ -629,6 +656,7 @@ geometry_bank::take_( bank_data &Data ) {
|
||||
}
|
||||
m_databytes.store( bytes, std::memory_order_relaxed );
|
||||
m_lastused.store( geometry_streamer::now(), std::memory_order_relaxed );
|
||||
m_failures.store( 0, std::memory_order_relaxed );
|
||||
// a load begun before is of no use now
|
||||
m_epoch.fetch_add( 1, std::memory_order_acq_rel );
|
||||
m_residency.store( residency::resident, std::memory_order_release );
|
||||
@@ -655,8 +683,7 @@ geometry_bank::fail_load( std::uint32_t const Epoch ) {
|
||||
|
||||
std::scoped_lock lock { m_buildmutex, m_decodemutex };
|
||||
if( ( epoch() != Epoch ) || ( state() != residency::loading ) ) { return false; }
|
||||
m_epoch.fetch_add( 1, std::memory_order_acq_rel );
|
||||
m_residency.store( residency::failed, std::memory_order_release );
|
||||
note_failure_();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -690,7 +717,8 @@ geometry_bank::load_now( bool const Pin ) const {
|
||||
if( Pin ) {
|
||||
bank.m_pinned.store( true, std::memory_order_relaxed );
|
||||
}
|
||||
if( auto const current { state() }; ( current == residency::resident ) || ( current == residency::failed ) ) { return; }
|
||||
// a failed bank is read again here as touch() would ask for it again: once in a while
|
||||
if( auto const current { state() }; ( current == residency::resident ) || ( ( current == residency::failed ) && ( false == retry_due_() ) ) ) { return; }
|
||||
bank_data data;
|
||||
std::string error;
|
||||
auto const loaded { m_source->load( data, plain_layout(), error ) };
|
||||
@@ -699,9 +727,10 @@ geometry_bank::load_now( bool const Pin ) const {
|
||||
std::scoped_lock lock { m_buildmutex, m_decodemutex };
|
||||
if( state() == residency::resident ) { return; }
|
||||
if( ( false == loaded ) || ( data.size() != m_chunks.size() ) ) {
|
||||
bank.m_epoch.fetch_add( 1, std::memory_order_acq_rel );
|
||||
bank.m_residency.store( residency::failed, std::memory_order_release );
|
||||
geometry_streamer::instance().report_failure( m_source->name(), loaded ? std::string { "its parts aren't those it had when it was loaded" } : error );
|
||||
bank.note_failure_();
|
||||
if( failures() == 1 ) {
|
||||
geometry_streamer::instance().report_failure( m_source->name(), loaded ? std::string { "its parts aren't those it had when it was loaded" } : error );
|
||||
}
|
||||
return;
|
||||
}
|
||||
bank.take_( data );
|
||||
|
||||
@@ -253,6 +253,9 @@ public:
|
||||
auto adopt( bank_data &Data, std::uint32_t const Epoch ) -> bool;
|
||||
// the streamer: the load begun at Epoch failed, the bank stays without its data
|
||||
auto fail_load( std::uint32_t const Epoch ) -> bool;
|
||||
// the loads failed one after another since the bank last had its data: the first one is logged, those trying again aren't
|
||||
auto failures() const -> std::uint32_t {
|
||||
return m_failures.load( std::memory_order_relaxed ); }
|
||||
// the data of a streamed bank let go of, unless it's kept for good. the bank is asked for again when it's drawn
|
||||
void evict();
|
||||
auto epoch() const -> std::uint32_t {
|
||||
@@ -331,10 +334,16 @@ private:
|
||||
virtual void adopted_() { release_(); }
|
||||
// whether the data of a streamed bank is to come in the compact layout, which the subclass keeps on the gpu as it is
|
||||
virtual auto compact_layout_() const -> bool { return false; }
|
||||
// a load of a streamed bank failed, with the locks held: the bank draws nothing and is tried again later (retry_due_())
|
||||
void note_failure_();
|
||||
// whether a failed bank is to be tried again: 5 s after its first failure, twice as long after each one that follows, up to 5 min
|
||||
auto retry_due_() const -> bool;
|
||||
|
||||
// members:
|
||||
std::shared_ptr<geometry_source const> m_source; // of a streamed bank
|
||||
std::atomic<gfx::residency> m_residency { gfx::residency::resident };
|
||||
std::atomic<std::uint32_t> m_failedat { 0 }; // geometry_streamer::now() the last load failed at
|
||||
std::atomic<std::uint32_t> m_failures { 0 }; // the loads failed one after another since the bank last had its data
|
||||
std::atomic<std::uint32_t> m_epoch { 0 }; // changed each time the data is taken or let go of
|
||||
std::atomic<float> m_priority { 0.f }; // the one it was asked for with
|
||||
std::atomic<std::uint32_t> m_lastused { 0 }; // geometry_streamer::now() it was drawn or touched last
|
||||
|
||||
@@ -120,7 +120,9 @@ geometry_streamer::hand_over_one( result &Result ) {
|
||||
return; // loaded meanwhile by the thread which read it
|
||||
}
|
||||
++m_failed;
|
||||
ErrorLog( std::format( "Bad model: the geometry of \"{}\" can't be loaded: {}", bank.source()->name(), Result.error ), logtype::model );
|
||||
if( bank.failures() == 1 ) {
|
||||
ErrorLog( std::format( "Bad model: the geometry of \"{}\" can't be loaded: {}", bank.source()->name(), Result.error ), logtype::model );
|
||||
}
|
||||
return;
|
||||
}
|
||||
if( false == bank.adopt( Result.data, Result.epoch ) ) {
|
||||
@@ -312,6 +314,13 @@ geometry_streamer::stop() {
|
||||
m_resident.clear();
|
||||
}
|
||||
|
||||
void
|
||||
geometry_streamer::resume() {
|
||||
|
||||
std::scoped_lock lock { m_mutex };
|
||||
m_stopped = false;
|
||||
}
|
||||
|
||||
geometry_streamer::statistics
|
||||
geometry_streamer::stats() const {
|
||||
|
||||
|
||||
@@ -63,6 +63,9 @@ public:
|
||||
void report_failure( std::string_view const Name, std::string_view const Error );
|
||||
// the threads ended and the loads dropped, before the banks go (the renderer is closed)
|
||||
void stop();
|
||||
// the loads taken again after stop(), by a renderer made after another one closed (vulkan falling back to opengl as it starts,
|
||||
// before any bank is made); the threads start with the first request
|
||||
void resume();
|
||||
// how many times banks were given their data. the walks kept by the gpu culling, made while a bank had none, are made anew when
|
||||
// it changes
|
||||
auto adoptions() const -> std::uint64_t {
|
||||
|
||||
@@ -1831,6 +1831,7 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token
|
||||
{
|
||||
Parser.getTokens();
|
||||
Parser >> gfx_texture_streaming;
|
||||
gfx_texture_streaming_set = true;
|
||||
}
|
||||
else if (Token == "gfx.textures.releasedistance")
|
||||
{
|
||||
|
||||
+3
-1
@@ -272,7 +272,9 @@ struct global_settings {
|
||||
float SmokeFidelity{ 1.f }; // determines amount of generated smoke particles
|
||||
bool ResourceSweep{ true }; // gfx resource garbage collection
|
||||
bool ResourceMove{ false }; // gfx resources are moved between cpu and gpu side instead of sending a copy
|
||||
bool gfx_texture_streaming{ true }; // data of dds textures is read by worker threads, the rest of the loading doesn't wait for it
|
||||
bool gfx_texture_streaming{ false }; // data of dds textures is read by worker threads, the rest of the loading doesn't wait for it
|
||||
// whether eu07.ini sets gfx.textures.streaming; when it doesn't, the textures are streamed with the vulkan renderer only
|
||||
bool gfx_texture_streaming_set{ false };
|
||||
float gfx_texture_releasedistance{ 0.f }; // gl textures of vehicles farther than this many draw ranges are released. 0 = off
|
||||
bool compress_tex{ true }; // all textures are compressed on gpu side
|
||||
std::string asSky{ "1" };
|
||||
|
||||
Reference in New Issue
Block a user