Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code for setup of global_func_set in ShaderLanguage #93866

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#define HAS_WARNING(flag) (warning_flags & flag)

int ShaderLanguage::instance_counter = 0;

String ShaderLanguage::get_operator_text(Operator p_op) {
static const char *op_names[OP_MAX] = { "==",
"!=",
Expand Down Expand Up @@ -10812,17 +10814,16 @@ 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);
if (instance_counter == 0) {
int idx = 0;
while (builtin_func_defs[idx].name) {
if (builtin_func_defs[idx].tag == SubClassTag::TAG_GLOBAL) {
global_func_set.insert(builtin_func_defs[idx].name);
}
idx++;
}
idx++;
}
instance_counter++;

#ifdef DEBUG_ENABLED
warnings_check_map.insert(ShaderWarning::UNUSED_CONSTANT, &used_constants);
Expand All @@ -10837,5 +10838,8 @@ ShaderLanguage::ShaderLanguage() {

ShaderLanguage::~ShaderLanguage() {
clear();
global_func_set.clear();
instance_counter--;
if (instance_counter == 0) {
global_func_set.clear();
}
}
2 changes: 2 additions & 0 deletions servers/rendering/shader_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ class ShaderLanguage {
static bool is_control_flow_keyword(String p_keyword);
static void get_builtin_funcs(List<String> *r_keywords);

static int instance_counter;

struct BuiltInInfo {
DataType type = TYPE_VOID;
bool constant = false;
Expand Down
Loading