summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2019-02-26 23:20:39 -0300
committerJuan Linietsky <juan@godotengine.org>2019-02-26 23:21:37 -0300
commitffb9f342a52186b7fb7da4607af524786fea829e (patch)
treec379d36c6b1f57e55a000bf62057d01ceb5cd1d4 /servers
parentdf7541d2f95a81412e5c682ae9af1b42cac5f76b (diff)
Ensure implicit conversions for scalar constants work in shaders, closes #26239
Diffstat (limited to 'servers')
-rw-r--r--servers/visual/shader_language.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 9a0218d5d0..1f9d263354 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -2074,7 +2074,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
bool fail = false;
for (int i = 0; i < argcount; i++) {
- if (args[i] != builtin_func_defs[idx].args[i]) {
+ if (get_scalar_type(args[i]) == args[i] && p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[i + 1]), builtin_func_defs[idx].args[i])) {
+ //all good, but needs implicit conversion later
+ } else if (args[i] != builtin_func_defs[idx].args[i]) {
fail = true;
break;
}
@@ -2119,6 +2121,24 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
outarg_idx++;
}
+ //implicitly convert values if possible
+ for (int i = 0; i < argcount; i++) {
+
+ if (get_scalar_type(args[i]) != args[i] || args[i] == builtin_func_defs[idx].args[i] || p_func->arguments[i + 1]->type != Node::TYPE_CONSTANT) {
+ //can't do implicit conversion here
+ continue;
+ }
+
+ //this is an implicit conversion
+ ConstantNode *constant = static_cast<ConstantNode *>(p_func->arguments[i + 1]);
+ ConstantNode *conversion = alloc_node<ConstantNode>();
+
+ conversion->datatype = builtin_func_defs[idx].args[i];
+ conversion->values.resize(1);
+
+ convert_constant(constant, builtin_func_defs[idx].args[i], conversion->values.ptrw());
+ p_func->arguments.write[i + 1] = conversion;
+ }
if (r_ret_type)
*r_ret_type = builtin_func_defs[idx].rettype;
@@ -2184,13 +2204,35 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p
for (int j = 0; j < args.size(); j++) {
- if (args[j] != pfunc->arguments[j].type) {
+ if (get_scalar_type(args[j]) == args[j] && p_func->arguments[j + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[j + 1]), pfunc->arguments[j].type)) {
+ //all good, but it needs implicit conversion later
+ } else if (args[j] != pfunc->arguments[j].type) {
fail = true;
break;
}
}
if (!fail) {
+
+ //implicitly convert values if possible
+ for (int k = 0; k < args.size(); k++) {
+
+ if (get_scalar_type(args[k]) != args[k] || args[k] == pfunc->arguments[k].type || p_func->arguments[k + 1]->type != Node::TYPE_CONSTANT) {
+ //can't do implicit conversion here
+ continue;
+ }
+
+ //this is an implicit conversion
+ ConstantNode *constant = static_cast<ConstantNode *>(p_func->arguments[k + 1]);
+ ConstantNode *conversion = alloc_node<ConstantNode>();
+
+ conversion->datatype = pfunc->arguments[k].type;
+ conversion->values.resize(1);
+
+ convert_constant(constant, pfunc->arguments[k].type, conversion->values.ptrw());
+ p_func->arguments.write[k + 1] = conversion;
+ }
+
if (r_ret_type)
*r_ret_type = pfunc->return_type;
return true;