From 0b7e2dfdfc57fac776d4da1c579aa3f1c325c1f0 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 13 Jun 2023 13:20:11 -0700 Subject: [PATCH] Ensure that "detect 3D" is only called when using 3D shaders --- drivers/gles3/storage/material_storage.cpp | 20 +++++++++---------- drivers/gles3/storage/material_storage.h | 6 ++---- .../storage_rd/material_storage.cpp | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index d246c47b6a7..473974fc7c1 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -714,7 +714,7 @@ static const RS::CanvasItemTextureFilter filter_from_uniform_canvas[ShaderLangua RS::CanvasItemTextureFilter::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, // ShaderLanguage::TextureFilter::FILTER_DEFAULT, }; -void MaterialData::update_uniform_buffer(const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const HashMap &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color) { +void MaterialData::update_uniform_buffer(const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const HashMap &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size) { MaterialStorage *material_storage = MaterialStorage::get_singleton(); bool uses_global_buffer = false; @@ -820,7 +820,7 @@ MaterialData::~MaterialData() { } } -void MaterialData::update_textures(const HashMap &p_parameters, const HashMap> &p_default_textures, const Vector &p_texture_uniforms, RID *p_textures, bool p_use_linear_color) { +void MaterialData::update_textures(const HashMap &p_parameters, const HashMap> &p_default_textures, const Vector &p_texture_uniforms, RID *p_textures, bool p_is_3d_shader_type) { TextureStorage *texture_storage = TextureStorage::get_singleton(); MaterialStorage *material_storage = MaterialStorage::get_singleton(); @@ -991,7 +991,7 @@ void MaterialData::update_textures(const HashMap &p_paramet if (tex) { gl_texture = textures[j]; #ifdef TOOLS_ENABLED - if (tex->detect_3d_callback && p_use_linear_color) { + if (tex->detect_3d_callback && p_is_3d_shader_type) { tex->detect_3d_callback(tex->detect_3d_callback_ud); } if (tex->detect_normal_callback && (p_texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL || p_texture_uniforms[i].hint == ShaderLanguage::ShaderNode::Uniform::HINT_ROUGHNESS_NORMAL)) { @@ -1046,7 +1046,7 @@ void MaterialData::update_textures(const HashMap &p_paramet } } -void MaterialData::update_parameters_internal(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const Vector &p_texture_uniforms, const HashMap> &p_default_texture_params, uint32_t p_ubo_size) { +void MaterialData::update_parameters_internal(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const Vector &p_texture_uniforms, const HashMap> &p_default_texture_params, uint32_t p_ubo_size, bool p_is_3d_shader_type) { if ((uint32_t)ubo_data.size() != p_ubo_size) { p_uniform_dirty = true; if (!uniform_buffer) { @@ -1061,7 +1061,7 @@ void MaterialData::update_parameters_internal(const HashMap //check whether buffer changed if (p_uniform_dirty && ubo_data.size()) { - update_uniform_buffer(p_uniforms, p_uniform_offsets, p_parameters, ubo_data.ptrw(), ubo_data.size(), true); + update_uniform_buffer(p_uniforms, p_uniform_offsets, p_parameters, ubo_data.ptrw(), ubo_data.size()); glBindBuffer(GL_UNIFORM_BUFFER, uniform_buffer); glBufferData(GL_UNIFORM_BUFFER, ubo_data.size(), ubo_data.ptrw(), GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); @@ -1078,7 +1078,7 @@ void MaterialData::update_parameters_internal(const HashMap } if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), true); + update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), p_is_3d_shader_type); } } @@ -2626,7 +2626,7 @@ GLES3::ShaderData *GLES3::_create_canvas_shader_func() { } void CanvasMaterialData::update_parameters(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { - update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size); + update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, false); } static void bind_uniforms_generic(const Vector &p_textures, const Vector &p_texture_uniforms, int texture_offset = 0, const RS::CanvasItemTextureFilter *filter_mapping = filter_from_uniform, const RS::CanvasItemTextureRepeat *repeat_mapping = repeat_from_uniform) { @@ -2795,7 +2795,7 @@ GLES3::ShaderData *GLES3::_create_sky_shader_func() { void SkyMaterialData::update_parameters(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { uniform_set_updated = true; - update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size); + update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, true); } SkyMaterialData::~SkyMaterialData() { @@ -3061,7 +3061,7 @@ void SceneMaterialData::set_next_pass(RID p_pass) { } void SceneMaterialData::update_parameters(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { - update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size); + update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, true); } SceneMaterialData::~SceneMaterialData() { @@ -3160,7 +3160,7 @@ GLES3::ShaderData *GLES3::_create_particles_shader_func() { } void ParticleProcessMaterialData::update_parameters(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty) { - update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size); + update_parameters_internal(p_parameters, p_uniform_dirty, p_textures_dirty, shader_data->uniforms, shader_data->ubo_offsets.ptr(), shader_data->texture_uniforms, shader_data->default_texture_params, shader_data->ubo_size, true); } ParticleProcessMaterialData::~ParticleProcessMaterialData() { diff --git a/drivers/gles3/storage/material_storage.h b/drivers/gles3/storage/material_storage.h index 92399127bba..9c63c8847de 100644 --- a/drivers/gles3/storage/material_storage.h +++ b/drivers/gles3/storage/material_storage.h @@ -88,7 +88,7 @@ struct Shader { /* Material structs */ struct MaterialData { - void update_uniform_buffer(const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const HashMap &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size, bool p_use_linear_color); + void update_uniform_buffer(const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const HashMap &p_parameters, uint8_t *p_buffer, uint32_t p_buffer_size); void update_textures(const HashMap &p_parameters, const HashMap> &p_default_textures, const Vector &p_texture_uniforms, RID *p_textures, bool p_use_linear_color); virtual void set_render_priority(int p_priority) = 0; @@ -98,7 +98,7 @@ struct MaterialData { virtual ~MaterialData(); // Used internally by all Materials - void update_parameters_internal(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const Vector &p_texture_uniforms, const HashMap> &p_default_texture_params, uint32_t p_ubo_size); + void update_parameters_internal(const HashMap &p_parameters, bool p_uniform_dirty, bool p_textures_dirty, const HashMap &p_uniforms, const uint32_t *p_uniform_offsets, const Vector &p_texture_uniforms, const HashMap> &p_default_texture_params, uint32_t p_ubo_size, bool p_is_3d_shader_type); protected: Vector ubo_data; @@ -112,8 +112,6 @@ private: List::Element *global_texture_E = nullptr; uint64_t global_textures_pass = 0; HashMap used_global_textures; - - //internally by update_parameters_internal }; typedef MaterialData *(*MaterialDataRequestFunction)(ShaderData *); diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 42db459133e..8d1eb87e3cf 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -1033,7 +1033,7 @@ bool MaterialStorage::MaterialData::update_parameters_uniform_set(const HashMap< } if (p_textures_dirty && tex_uniform_count) { - update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), true); + update_textures(p_parameters, p_default_texture_params, p_texture_uniforms, texture_cache.ptrw(), p_use_linear_color); } if (p_ubo_size == 0 && (p_texture_uniforms.size() == 0)) {