Fix vector reduction in shader language

(cherry picked from commit 5b50685b38)
This commit is contained in:
JFonS 2018-04-29 20:58:42 +02:00 committed by Hein-Pieter van Braam
parent c461b15720
commit 4de1d0905a
2 changed files with 44 additions and 3 deletions

View File

@ -2212,6 +2212,37 @@ ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) {
return scalar_types[p_type]; return scalar_types[p_type];
} }
int ShaderLanguage::get_cardinality(DataType p_type) {
static const int cardinality_table[] = {
0,
1,
2,
3,
4,
1,
2,
3,
4,
1,
2,
3,
4,
1,
2,
3,
4,
2,
3,
4,
1,
1,
1,
1,
};
return cardinality_table[p_type];
}
bool ShaderLanguage::_get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier) { bool ShaderLanguage::_get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier) {
identifier = StringName(); identifier = StringName();
@ -3122,9 +3153,18 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha
if (get_scalar_type(cn->datatype) == base) { if (get_scalar_type(cn->datatype) == base) {
int cardinality = get_cardinality(op->arguments[i]->get_datatype());
if (cn->values.size() == cardinality) {
for (int j = 0; j < cn->values.size(); j++) { for (int j = 0; j < cn->values.size(); j++) {
values.push_back(cn->values[j]); values.push_back(cn->values[j]);
} }
} else if (cn->values.size() == 1) {
for (int j = 0; j < cardinality; j++) {
values.push_back(cn->values[0]);
}
} // else: should be filtered by the parser as it's an invalid constructor
} else if (get_scalar_type(cn->datatype) == cn->datatype) { } else if (get_scalar_type(cn->datatype) == cn->datatype) {
ConstantNode::Value v; ConstantNode::Value v;

View File

@ -532,6 +532,7 @@ public:
static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = NULL); static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = NULL);
static DataType get_scalar_type(DataType p_type); static DataType get_scalar_type(DataType p_type);
static int get_cardinality(DataType p_type);
static bool is_scalar_type(DataType p_type); static bool is_scalar_type(DataType p_type);
static bool is_sampler_type(DataType p_type); static bool is_sampler_type(DataType p_type);