diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 1a4c8ea742a0..9aa54d0bb775 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -3067,6 +3067,8 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { { nullptr, TYPE_VOID, { TYPE_VOID }, { "" }, TAG_GLOBAL, false } }; +HashSet global_func_set; + const ShaderLanguage::BuiltinFuncOutArgs ShaderLanguage::builtin_func_out_args[] = { { "modf", { 1, -1 } }, { "umulExtended", { 2, 3 } }, @@ -9211,7 +9213,7 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f return ERR_PARSE_ERROR; } - if (shader->structs.has(name) || _find_identifier(nullptr, false, constants, name) || has_builtin(p_functions, name)) { + if (shader->structs.has(name) || _find_identifier(nullptr, false, constants, name) || has_builtin(p_functions, name, !is_constant)) { _set_redefinition_error(String(name)); return ERR_PARSE_ERROR; } @@ -9831,7 +9833,11 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f return OK; } -bool ShaderLanguage::has_builtin(const HashMap &p_functions, const StringName &p_name) { +bool ShaderLanguage::has_builtin(const HashMap &p_functions, const StringName &p_name, bool p_check_global_funcs) { + if (p_check_global_funcs && global_func_set.has(p_name)) { + return true; + } + for (const KeyValue &E : p_functions) { if (E.value.built_ins.has(p_name)) { return true; @@ -10701,6 +10707,18 @@ ShaderLanguage::ShaderLanguage() { nodes = nullptr; completion_class = TAG_GLOBAL; + int idx = 0; + while (builtin_func_defs[idx].name) { + if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) { + const StringName &name = StringName(builtin_func_defs[idx].name); + + if (!global_func_set.has(name)) { + global_func_set.insert(name); + } + } + idx++; + } + #ifdef DEBUG_ENABLED warnings_check_map.insert(ShaderWarning::UNUSED_CONSTANT, &used_constants); warnings_check_map.insert(ShaderWarning::UNUSED_FUNCTION, &used_functions); diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 38f304ff31a5..5615d7f457fd 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -884,7 +884,7 @@ public: bool can_discard = false; bool main_function = false; }; - static bool has_builtin(const HashMap &p_functions, const StringName &p_name); + static bool has_builtin(const HashMap &p_functions, const StringName &p_name, bool p_check_global_funcs = false); typedef DataType (*GlobalShaderUniformGetTypeFunc)(const StringName &p_name);