Fix shader crash when using local var with the same name as varying
This commit is contained in:
parent
1a9c8aaba9
commit
fa96c98bdf
3 changed files with 9 additions and 2 deletions
|
@ -887,7 +887,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
|
||||||
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
|
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
|
||||||
bool use_fragment_varying = false;
|
bool use_fragment_varying = false;
|
||||||
|
|
||||||
if (!(p_actions.entry_point_stages.has(current_func_name) && p_actions.entry_point_stages[current_func_name] == STAGE_VERTEX)) {
|
if (!vnode->is_local && !(p_actions.entry_point_stages.has(current_func_name) && p_actions.entry_point_stages[current_func_name] == STAGE_VERTEX)) {
|
||||||
if (p_assigning) {
|
if (p_assigning) {
|
||||||
if (shader->varyings.has(vnode->name)) {
|
if (shader->varyings.has(vnode->name)) {
|
||||||
use_fragment_varying = true;
|
use_fragment_varying = true;
|
||||||
|
@ -1037,7 +1037,7 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
|
||||||
SL::ArrayNode *anode = (SL::ArrayNode *)p_node;
|
SL::ArrayNode *anode = (SL::ArrayNode *)p_node;
|
||||||
bool use_fragment_varying = false;
|
bool use_fragment_varying = false;
|
||||||
|
|
||||||
if (!(p_actions.entry_point_stages.has(current_func_name) && p_actions.entry_point_stages[current_func_name] == STAGE_VERTEX)) {
|
if (!anode->is_local && !(p_actions.entry_point_stages.has(current_func_name) && p_actions.entry_point_stages[current_func_name] == STAGE_VERTEX)) {
|
||||||
if (anode->assign_expression != nullptr && shader->varyings.has(anode->name)) {
|
if (anode->assign_expression != nullptr && shader->varyings.has(anode->name)) {
|
||||||
use_fragment_varying = true;
|
use_fragment_varying = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4228,6 +4228,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||||
IdentifierType ident_type;
|
IdentifierType ident_type;
|
||||||
int array_size = 0;
|
int array_size = 0;
|
||||||
StringName struct_name;
|
StringName struct_name;
|
||||||
|
bool is_local = false;
|
||||||
|
|
||||||
if (p_block && p_block->block_tag != SubClassTag::TAG_GLOBAL) {
|
if (p_block && p_block->block_tag != SubClassTag::TAG_GLOBAL) {
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
@ -4284,6 +4285,8 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||||
} else {
|
} else {
|
||||||
last_type = ident_type;
|
last_type = ident_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_local = ident_type == IDENTIFIER_LOCAL_VAR || ident_type == IDENTIFIER_FUNCTION_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *index_expression = nullptr;
|
Node *index_expression = nullptr;
|
||||||
|
@ -4358,6 +4361,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||||
arrname->assign_expression = assign_expression;
|
arrname->assign_expression = assign_expression;
|
||||||
arrname->is_const = is_const;
|
arrname->is_const = is_const;
|
||||||
arrname->array_size = array_size;
|
arrname->array_size = array_size;
|
||||||
|
arrname->is_local = is_local;
|
||||||
expr = arrname;
|
expr = arrname;
|
||||||
} else {
|
} else {
|
||||||
VariableNode *varname = alloc_node<VariableNode>();
|
VariableNode *varname = alloc_node<VariableNode>();
|
||||||
|
@ -4365,6 +4369,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
|
||||||
varname->datatype_cache = data_type;
|
varname->datatype_cache = data_type;
|
||||||
varname->is_const = is_const;
|
varname->is_const = is_const;
|
||||||
varname->struct_name = struct_name;
|
varname->struct_name = struct_name;
|
||||||
|
varname->is_local = is_local;
|
||||||
expr = varname;
|
expr = varname;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
|
|
|
@ -409,6 +409,7 @@ public:
|
||||||
StringName name;
|
StringName name;
|
||||||
StringName struct_name;
|
StringName struct_name;
|
||||||
bool is_const = false;
|
bool is_const = false;
|
||||||
|
bool is_local = false;
|
||||||
|
|
||||||
virtual DataType get_datatype() const override { return datatype_cache; }
|
virtual DataType get_datatype() const override { return datatype_cache; }
|
||||||
virtual String get_datatype_name() const override { return String(struct_name); }
|
virtual String get_datatype_name() const override { return String(struct_name); }
|
||||||
|
@ -444,6 +445,7 @@ public:
|
||||||
Node *assign_expression = nullptr;
|
Node *assign_expression = nullptr;
|
||||||
bool is_const = false;
|
bool is_const = false;
|
||||||
int array_size = 0;
|
int array_size = 0;
|
||||||
|
bool is_local = false;
|
||||||
|
|
||||||
virtual DataType get_datatype() const override { return datatype_cache; }
|
virtual DataType get_datatype() const override { return datatype_cache; }
|
||||||
virtual String get_datatype_name() const override { return String(struct_name); }
|
virtual String get_datatype_name() const override { return String(struct_name); }
|
||||||
|
|
Loading…
Reference in a new issue