mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 17:44:09 +01:00
[glsl-in] Allow constructors from non-scalar to scalar (#1520)
This commit is contained in:
1 parent
c3c4ab7548
commit
d168f15d81
3 files changed
+45
-9
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user