Skip to content

Commit

Permalink
Use "literal" term where appropriate in shader language.
Browse files Browse the repository at this point in the history
Previously we were using "constant" to describe all
instances of immutable declarations, whether that was
an inline literal or an actual declared constant variable.

This lack of disambiguation also resulted in some misleading
error messages, ie: "expected integer constant" where only
a literal is actually valid (and passing an actual constant
like PI would fail with that exact error message).

This also improves a few error messages that only stated
the expectation of an integer literal when it was more appropriate
to say an integer OR float literal.
  • Loading branch information
maxpiepenbrink committed Jan 24, 2025
1 parent b0655dc commit 3f10cc8
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 187 deletions.
4 changes: 2 additions & 2 deletions drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ Variant ShaderData::get_default_parameter(const StringName &p_parameter) const {
if (uniforms.has(p_parameter)) {
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
Vector<ShaderLanguage::Scalar> default_value = uniform.default_value;
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
return ShaderLanguage::literal_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
}
return Variant();
}
Expand Down Expand Up @@ -626,7 +626,7 @@ void ShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceS
p.info = ShaderLanguage::uniform_to_property_info(E.value);
p.info.name = E.key; //supply name
p.index = E.value.instance_index;
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
p.default_value = ShaderLanguage::literal_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
p_param_list->push_back(p);
}
}
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/dummy/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void MaterialStorage::material_get_instance_shader_parameters(RID p_material, Li
p.info = ShaderLanguage::uniform_to_property_info(E.value);
p.info.name = E.key; //supply name
p.index = E.value.instance_index;
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
p.default_value = ShaderLanguage::literal_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
r_parameters->push_back(p);
}
}
Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/storage_rd/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ Variant MaterialStorage::ShaderData::get_default_parameter(const StringName &p_p
if (uniforms.has(p_parameter)) {
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
Vector<ShaderLanguage::Scalar> default_value = uniform.default_value;
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
return ShaderLanguage::literal_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
}
return Variant();
}
Expand Down Expand Up @@ -622,7 +622,7 @@ void MaterialStorage::ShaderData::get_instance_param_list(List<RendererMaterialS
p.info = ShaderLanguage::uniform_to_property_info(E.value);
p.info.name = E.key; //supply name
p.index = E.value.instance_index;
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
p.default_value = ShaderLanguage::literal_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
p_param_list->push_back(p);
}
}
Expand Down
20 changes: 10 additions & 10 deletions servers/rendering/shader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,28 +1086,28 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene
}

} break;
case SL::Node::NODE_TYPE_CONSTANT: {
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
case SL::Node::NODE_TYPE_LITERAL: {
SL::LiteralNode *lnode = (SL::LiteralNode *)p_node;

if (cnode->array_size == 0) {
return get_constant_text(cnode->datatype, cnode->values);
if (lnode->array_size == 0) {
return get_constant_text(lnode->datatype, lnode->values);
} else {
if (cnode->get_datatype() == SL::TYPE_STRUCT) {
code += _mkid(cnode->struct_name);
if (lnode->get_datatype() == SL::TYPE_STRUCT) {
code += _mkid(lnode->struct_name);
} else {
code += _typestr(cnode->datatype);
code += _typestr(lnode->datatype);
}
code += "[";
code += itos(cnode->array_size);
code += itos(lnode->array_size);
code += "]";
code += "(";
for (int i = 0; i < cnode->array_size; i++) {
for (int i = 0; i < lnode->array_size; i++) {
if (i > 0) {
code += ",";
} else {
code += "";
}
code += _dump_node_code(cnode->array_declarations[0].initializer[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
code += _dump_node_code(lnode->array_declarations[0].initializer[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
}
code += ")";
}
Expand Down
Loading

0 comments on commit 3f10cc8

Please sign in to comment.