18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 09:15:01 +01:00

fix(editor): the images of the materials let go of with all their textures, the browser's Refresh a frame later

An image of a material read the material with all its textures, the normal and specular maps and the variants, and only the first one was let go of: those stayed in the memory for every material scrolled past. They are let go of together now (Unload_Material). texture_manager::unload also takes the textures read and not made yet, waiting for a worker still reading one, and deletes the gl texture itself: release() would read it back from the card with gfx.resource.move only for it to be dropped.

The Refresh of the texture browser let go of the images in the middle of the frame, while panels drawn before it could still refer to them; it now marks them, and they go at the start of the next frame.

Checked on td.scn by a scripted run: 8040 images of the picker read a batch every few frames end at 2.0 GB, against 2.3-2.6 GB before this and 1.1 GB at the start; a trackbed material picked from the folder is drawn on the track after its image was let go.
This commit is contained in:
maj00r
2026-11-16 02:10:59 +01:00
parent 4525023777
commit 0bbf07bf11
9 changed files with 82 additions and 22 deletions

View File

@@ -2575,6 +2575,18 @@ void opengl33_renderer::Unload_Texture(texture_handle const Texture)
m_textures.unload(Texture);
}
void opengl33_renderer::Unload_Material(material_handle const Material)
{
if (Material == null_handle)
return;
auto const &material{m_materials.material(Material)};
for (auto const texture : material.textures)
m_textures.unload(texture);
for (auto const &variant : material.texture_variants)
for (auto const texture : variant)
m_textures.unload(texture);
}
void opengl33_renderer::Update_AnimModel(TAnimModel *model)
{
model->RaAnimate(m_framestamp);

View File

@@ -112,6 +112,8 @@ class opengl33_renderer : public gfx_renderer {
Texture( texture_handle const Texture ) const override;
void
Unload_Texture( texture_handle const Texture ) override;
void
Unload_Material( material_handle const Material ) override;
// utility methods
void
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override;

View File

@@ -1928,6 +1928,21 @@ opengl_renderer::Unload_Texture( texture_handle const Texture ) {
m_textures.unload( Texture );
}
void
opengl_renderer::Unload_Material( material_handle const Material ) {
if( Material == null_handle ) { return; }
auto const &material { m_materials.material( Material ) };
for( auto const texture : material.textures ) {
m_textures.unload( texture );
}
for( auto const &variant : material.texture_variants ) {
for( auto const texture : variant ) {
m_textures.unload( texture );
}
}
}
void
opengl_renderer::Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) {

View File

@@ -97,6 +97,8 @@ public:
Texture( texture_handle const Texture ) const override;
void
Unload_Texture( texture_handle const Texture ) override;
void
Unload_Material( material_handle const Material ) override;
// utility methods
void
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override;

View File

@@ -105,6 +105,8 @@ public:
// a texture the scene has never drawn taken out of the gfx card and the memory, read again when it's used: the image of a
// texture picker scrolled past. backends which keep their textures otherwise leave it
virtual void Unload_Texture( texture_handle const Texture ) {}
// the same for all the textures of a material, those of its variants with them
virtual void Unload_Material( material_handle const Material ) {}
// utility methods
virtual void Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) = 0;
virtual void Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) = 0;