Merge pull request #23887 from ibrahn/dirty-material-list-lifetime

Moved dirty material lists from static to lifetime controlled by main.
This commit is contained in:
Rémi Verschelde 2018-12-11 18:05:19 +01:00 committed by GitHub
commit 3f9c054163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 18 deletions

View File

@ -42,7 +42,7 @@
#include "servers/visual_server.h" #include "servers/visual_server.h"
Mutex *CanvasItemMaterial::material_mutex = NULL; Mutex *CanvasItemMaterial::material_mutex = NULL;
SelfList<CanvasItemMaterial>::List CanvasItemMaterial::dirty_materials; SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = NULL;
Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map;
CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL;
@ -52,6 +52,8 @@ void CanvasItemMaterial::init_shaders() {
material_mutex = Mutex::create(); material_mutex = Mutex::create();
#endif #endif
dirty_materials = memnew(SelfList<CanvasItemMaterial>::List);
shader_names = memnew(ShaderNames); shader_names = memnew(ShaderNames);
shader_names->particles_anim_h_frames = "particles_anim_h_frames"; shader_names->particles_anim_h_frames = "particles_anim_h_frames";
@ -61,6 +63,9 @@ void CanvasItemMaterial::init_shaders() {
void CanvasItemMaterial::finish_shaders() { void CanvasItemMaterial::finish_shaders() {
memdelete(dirty_materials);
dirty_materials = NULL;
#ifndef NO_THREADS #ifndef NO_THREADS
memdelete(material_mutex); memdelete(material_mutex);
#endif #endif
@ -68,7 +73,7 @@ void CanvasItemMaterial::finish_shaders() {
void CanvasItemMaterial::_update_shader() { void CanvasItemMaterial::_update_shader() {
dirty_materials.remove(&element); dirty_materials->remove(&element);
MaterialKey mk = _compute_key(); MaterialKey mk = _compute_key();
if (mk.key == current_key.key) if (mk.key == current_key.key)
@ -157,9 +162,9 @@ void CanvasItemMaterial::flush_changes() {
if (material_mutex) if (material_mutex)
material_mutex->lock(); material_mutex->lock();
while (dirty_materials.first()) { while (dirty_materials->first()) {
dirty_materials.first()->self()->_update_shader(); dirty_materials->first()->self()->_update_shader();
} }
if (material_mutex) if (material_mutex)
@ -172,7 +177,7 @@ void CanvasItemMaterial::_queue_shader_change() {
material_mutex->lock(); material_mutex->lock();
if (!element.in_list()) { if (!element.in_list()) {
dirty_materials.add(&element); dirty_materials->add(&element);
} }
if (material_mutex) if (material_mutex)

View File

@ -109,7 +109,7 @@ private:
} }
static Mutex *material_mutex; static Mutex *material_mutex;
static SelfList<CanvasItemMaterial>::List dirty_materials; static SelfList<CanvasItemMaterial>::List *dirty_materials;
SelfList<CanvasItemMaterial> element; SelfList<CanvasItemMaterial> element;
void _update_shader(); void _update_shader();

View File

@ -258,7 +258,7 @@ ShaderMaterial::~ShaderMaterial() {
///////////////////////////////// /////////////////////////////////
Mutex *SpatialMaterial::material_mutex = NULL; Mutex *SpatialMaterial::material_mutex = NULL;
SelfList<SpatialMaterial>::List SpatialMaterial::dirty_materials; SelfList<SpatialMaterial>::List *SpatialMaterial::dirty_materials = NULL;
Map<SpatialMaterial::MaterialKey, SpatialMaterial::ShaderData> SpatialMaterial::shader_map; Map<SpatialMaterial::MaterialKey, SpatialMaterial::ShaderData> SpatialMaterial::shader_map;
SpatialMaterial::ShaderNames *SpatialMaterial::shader_names = NULL; SpatialMaterial::ShaderNames *SpatialMaterial::shader_names = NULL;
@ -268,6 +268,8 @@ void SpatialMaterial::init_shaders() {
material_mutex = Mutex::create(); material_mutex = Mutex::create();
#endif #endif
dirty_materials = memnew(SelfList<SpatialMaterial>::List);
shader_names = memnew(ShaderNames); shader_names = memnew(ShaderNames);
shader_names->albedo = "albedo"; shader_names->albedo = "albedo";
@ -348,12 +350,15 @@ void SpatialMaterial::finish_shaders() {
memdelete(material_mutex); memdelete(material_mutex);
#endif #endif
memdelete(dirty_materials);
dirty_materials = NULL;
memdelete(shader_names); memdelete(shader_names);
} }
void SpatialMaterial::_update_shader() { void SpatialMaterial::_update_shader() {
dirty_materials.remove(&element); dirty_materials->remove(&element);
MaterialKey mk = _compute_key(); MaterialKey mk = _compute_key();
if (mk.key == current_key.key) if (mk.key == current_key.key)
@ -1002,9 +1007,9 @@ void SpatialMaterial::flush_changes() {
if (material_mutex) if (material_mutex)
material_mutex->lock(); material_mutex->lock();
while (dirty_materials.first()) { while (dirty_materials->first()) {
dirty_materials.first()->self()->_update_shader(); dirty_materials->first()->self()->_update_shader();
} }
if (material_mutex) if (material_mutex)
@ -1017,7 +1022,7 @@ void SpatialMaterial::_queue_shader_change() {
material_mutex->lock(); material_mutex->lock();
if (!element.in_list()) { if (!element.in_list()) {
dirty_materials.add(&element); dirty_materials->add(&element);
} }
if (material_mutex) if (material_mutex)

View File

@ -360,7 +360,7 @@ private:
}; };
static Mutex *material_mutex; static Mutex *material_mutex;
static SelfList<SpatialMaterial>::List dirty_materials; static SelfList<SpatialMaterial>::List *dirty_materials;
static ShaderNames *shader_names; static ShaderNames *shader_names;
SelfList<SpatialMaterial> element; SelfList<SpatialMaterial> element;

View File

@ -31,7 +31,7 @@
#include "particles_material.h" #include "particles_material.h"
Mutex *ParticlesMaterial::material_mutex = NULL; Mutex *ParticlesMaterial::material_mutex = NULL;
SelfList<ParticlesMaterial>::List ParticlesMaterial::dirty_materials; SelfList<ParticlesMaterial>::List *ParticlesMaterial::dirty_materials = NULL;
Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMaterial::shader_map; Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMaterial::shader_map;
ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = NULL; ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = NULL;
@ -41,6 +41,8 @@ void ParticlesMaterial::init_shaders() {
material_mutex = Mutex::create(); material_mutex = Mutex::create();
#endif #endif
dirty_materials = memnew(SelfList<ParticlesMaterial>::List);
shader_names = memnew(ShaderNames); shader_names = memnew(ShaderNames);
shader_names->spread = "spread"; shader_names->spread = "spread";
@ -106,12 +108,15 @@ void ParticlesMaterial::finish_shaders() {
memdelete(material_mutex); memdelete(material_mutex);
#endif #endif
memdelete(dirty_materials);
dirty_materials = NULL;
memdelete(shader_names); memdelete(shader_names);
} }
void ParticlesMaterial::_update_shader() { void ParticlesMaterial::_update_shader() {
dirty_materials.remove(&element); dirty_materials->remove(&element);
MaterialKey mk = _compute_key(); MaterialKey mk = _compute_key();
if (mk.key == current_key.key) if (mk.key == current_key.key)
@ -584,9 +589,9 @@ void ParticlesMaterial::flush_changes() {
if (material_mutex) if (material_mutex)
material_mutex->lock(); material_mutex->lock();
while (dirty_materials.first()) { while (dirty_materials->first()) {
dirty_materials.first()->self()->_update_shader(); dirty_materials->first()->self()->_update_shader();
} }
if (material_mutex) if (material_mutex)
@ -599,7 +604,7 @@ void ParticlesMaterial::_queue_shader_change() {
material_mutex->lock(); material_mutex->lock();
if (!element.in_list()) { if (!element.in_list()) {
dirty_materials.add(&element); dirty_materials->add(&element);
} }
if (material_mutex) if (material_mutex)

View File

@ -126,7 +126,7 @@ private:
} }
static Mutex *material_mutex; static Mutex *material_mutex;
static SelfList<ParticlesMaterial>::List dirty_materials; static SelfList<ParticlesMaterial>::List *dirty_materials;
struct ShaderNames { struct ShaderNames {
StringName spread; StringName spread;