[glsl-in] Allow constructors from non-scalar to scalar (#1520)

This commit is contained in:
João Capucho authored and GitHub committed 2021-11-10 12:15:43 -05:00
1 parent c3c4ab7548
commit d168f15d81
3 files changed
+45 -9

No files matched your search

+36 -9
View File
@@ -117,15 +117,42 @@ impl Parser {
ctx.add_expression(Expression::Splat { size, value }, meta, body)
}
TypeInner::Scalar { kind, width } => ctx.add_expression(
Expression::As {
kind,
expr: value,
convert: Some(width),
},
meta,
body,
),
TypeInner::Scalar { kind, width } => {
let mut expr = value;
if let TypeInner::Vector { .. } | TypeInner::Matrix { .. } =
*self.resolve_type(ctx, value, expr_meta)?
{
expr = ctx.add_expression(
Expression::AccessIndex {
base: expr,
index: 0,
},
meta,
body,
);
}
if let TypeInner::Matrix { .. } = *self.resolve_type(ctx, value, expr_meta)? {
expr = ctx.add_expression(
Expression::AccessIndex {
base: expr,
index: 0,
},
meta,
body,
);
}
ctx.add_expression(
Expression::As {
kind,
expr,
convert: Some(width),
},
meta,
body,
)
}
TypeInner::Vector { size, kind, width } => {
if vector_size.map_or(true, |s| s != size) {
value = ctx.vector_resize(size, value, expr_meta, body);
+4
View File
@@ -70,6 +70,10 @@ void testStructConstructor() {
BST tree = BST(1);
}
void testNonScalarToScalarConstructor() {
float f = float(mat2(1.0));
}
void testArrayConstructor() {
float tree[1] = float[1](0.0);
}
+5
View File
@@ -180,6 +180,11 @@ fn testStructConstructor() {
}
fn testNonScalarToScalarConstructor() {
var f: f32 = 1.0;
}
fn testArrayConstructor() {
var tree_1: array<f32,1u> = array<f32,1u>(0.0);