Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Dec 3, 2024
1 parent 9a845a8 commit e62b3cd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
2 changes: 2 additions & 0 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ Error ResourceLoaderBinary::load() {
resource->set_as_translation_remapped(translation_remapped);
error = OK;
return OK;
} else {
ResourceLoader::notify_subresource_parsed();
}
}

Expand Down
6 changes: 6 additions & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,12 @@ bool ResourceLoader::_ensure_load_progress() {
return true;
}

void ResourceLoader::notify_subresource_parsed() {
if (MessageQueue::get_singleton() != MessageQueue::get_main_singleton()) {
MessageQueue::get_singleton()->flush();
}
}

void ResourceLoader::resource_changed_connect(Resource *p_source, const Callable &p_callable, uint32_t p_flags) {
print_lt(vformat("%d\t%ud:%s\t" FUNCTION_STR "\t%d", Thread::get_caller_id(), p_source->get_instance_id(), p_source->get_class(), p_callable.get_object_id()));

Expand Down
1 change: 1 addition & 0 deletions core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class ResourceLoader {
static Ref<Resource> load_threaded_get(const String &p_path, Error *r_error = nullptr);

static bool is_within_load() { return load_nesting > 0; }
static void notify_subresource_parsed();

static void resource_changed_connect(Resource *p_source, const Callable &p_callable, uint32_t p_flags);
static void resource_changed_disconnect(Resource *p_source, const Callable &p_callable);
Expand Down
23 changes: 7 additions & 16 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) {
}
}

_ensure_material_rid();
RID material_rid = _get_material();
if (material_rid.is_valid()) {
RS::get_singleton()->material_set_shader(material_rid, rid);
Expand Down Expand Up @@ -486,8 +487,7 @@ void ShaderMaterial::_shader_changed() {
notify_property_list_changed(); //update all properties
}

void ShaderMaterial::_check_material_rid() const {
MutexLock lock(material_rid_mutex);
void ShaderMaterial::_ensure_material_rid() const {
if (_get_material().is_null()) {
RID shader_rid = shader.is_valid() ? shader->get_rid() : RID();
RID next_pass_rid;
Expand Down Expand Up @@ -553,11 +553,6 @@ Shader::Mode ShaderMaterial::get_shader_mode() const {
}
}

RID ShaderMaterial::get_rid() const {
_check_material_rid();
return Material::get_rid();
}

RID ShaderMaterial::get_shader_rid() const {
if (shader.is_valid()) {
return shader->get_rid();
Expand Down Expand Up @@ -696,9 +691,8 @@ void BaseMaterial3D::_update_shader() {
shader_rid = shader_map[mk].shader;
shader_map[mk].users++;

if (_get_material().is_valid()) {
RS::get_singleton()->material_set_shader(_get_material(), shader_rid);
}
_ensure_material_rid();
RS::get_singleton()->material_set_shader(_get_material(), shader_rid);

return;
}
Expand Down Expand Up @@ -1933,13 +1927,11 @@ void fragment() {)";
shader_map[mk] = shader_data;
shader_rid = shader_data.shader;

if (_get_material().is_valid()) {
RS::get_singleton()->material_set_shader(_get_material(), shader_rid);
}
_ensure_material_rid();
RS::get_singleton()->material_set_shader(_get_material(), shader_rid);
}

void BaseMaterial3D::_check_material_rid() {
MutexLock lock(material_rid_mutex);
void BaseMaterial3D::_ensure_material_rid() {
if (_get_material().is_null()) {
RID next_pass_rid;
if (get_next_pass().is_valid()) {
Expand Down Expand Up @@ -2931,7 +2923,6 @@ BaseMaterial3D::EmissionOperator BaseMaterial3D::get_emission_operator() const {
}

RID BaseMaterial3D::get_rid() const {
const_cast<BaseMaterial3D *>(this)->_check_material_rid();
return _get_material();
}

Expand Down
9 changes: 2 additions & 7 deletions scene/resources/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class ShaderMaterial : public Material {

mutable HashMap<StringName, StringName> remap_cache;
mutable HashMap<StringName, Variant> param_cache;
mutable Mutex material_rid_mutex;

protected:
bool _set(const StringName &p_name, const Variant &p_value);
Expand All @@ -117,7 +116,7 @@ class ShaderMaterial : public Material {
virtual bool _can_use_render_priority() const override;

void _shader_changed();
void _check_material_rid() const;
void _ensure_material_rid() const;

public:
void set_shader(const Ref<Shader> &p_shader);
Expand All @@ -128,7 +127,6 @@ class ShaderMaterial : public Material {

virtual Shader::Mode get_shader_mode() const override;

virtual RID get_rid() const override;
virtual RID get_shader_rid() const override;

ShaderMaterial();
Expand All @@ -140,9 +138,6 @@ class StandardMaterial3D;
class BaseMaterial3D : public Material {
GDCLASS(BaseMaterial3D, Material);

private:
mutable Mutex material_rid_mutex;

public:
enum TextureParam {
TEXTURE_ALBEDO,
Expand Down Expand Up @@ -475,7 +470,7 @@ class BaseMaterial3D : public Material {

void _update_shader();
_FORCE_INLINE_ void _queue_shader_change();
void _check_material_rid();
void _ensure_material_rid();
void _material_set_param(const StringName &p_name, const Variant &p_value);

bool orm;
Expand Down
2 changes: 2 additions & 0 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ Error ResourceLoaderText::load() {
if (!missing_resource_properties.is_empty()) {
res->set_meta(META_MISSING_RESOURCES, missing_resource_properties);
}

ResourceLoader::notify_subresource_parsed();
}

while (true) {
Expand Down
24 changes: 16 additions & 8 deletions servers/rendering/renderer_rd/pipeline_hash_map_rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ class PipelineHashMapRD {

// Retrieve a pipeline. It'll return an empty pipeline if it's not available yet, but it'll be guaranteed to succeed if 'wait for compilation' is true and stall as necessary. Source is just an optional number to aid debugging.
RID get_pipeline(const Key &p_key, uint32_t p_key_hash, bool p_wait_for_compilation, RS::PipelineSource p_source) {
RBMap<uint32_t, RID>::Element *e = hash_map.find(p_key_hash);
RBMap<uint32_t, RID>::Element *e = nullptr;
{
MutexLock lock(compiled_queue_mutex);
e = hash_map.find(p_key_hash);
}

if (e == nullptr) {
// Check if there's any new pipelines that need to be added and try again. This method triggers a mutex lock.
if (_add_new_pipelines_to_map()) {
MutexLock lock(compiled_queue_mutex);
e = hash_map.find(p_key_hash);
}
}
Expand All @@ -170,13 +175,16 @@ class PipelineHashMapRD {

_add_new_pipelines_to_map();

e = hash_map.find(p_key_hash);
if (e != nullptr) {
return e->value();
} else {
// Pipeline could not be compiled due to an internal error. Store an empty RID so compilation is not attempted again.
hash_map[p_key_hash] = RID();
return RID();
{
MutexLock lock(compiled_queue_mutex);
e = hash_map.find(p_key_hash);
if (e != nullptr) {
return e->value();
} else {
// Pipeline could not be compiled due to an internal error. Store an empty RID so compilation is not attempted again.
hash_map[p_key_hash] = RID();
return RID();
}
}
} else {
return RID();
Expand Down

0 comments on commit e62b3cd

Please sign in to comment.