mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
glsl-in: fix composite constructors (#1631)
* glsl-in: Remove unneeded mutability from reference * glsl-in: Fix composite constructors In the recent rework of the constructors it seems that the logic for composite types (arrays and structs) was accidentally removed by me.
This commit is contained in:
@@ -881,7 +881,7 @@ impl Context {
|
||||
|
||||
pub fn expr_scalar_components(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
expr: Handle<Expression>,
|
||||
meta: Span,
|
||||
) -> Result<Option<(ScalarKind, crate::Bytes)>> {
|
||||
@@ -891,7 +891,7 @@ impl Context {
|
||||
|
||||
pub fn expr_power(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
expr: Handle<Expression>,
|
||||
meta: Span,
|
||||
) -> Result<Option<u32>> {
|
||||
@@ -921,7 +921,7 @@ impl Context {
|
||||
|
||||
pub fn implicit_conversion(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: Span,
|
||||
kind: ScalarKind,
|
||||
@@ -941,7 +941,7 @@ impl Context {
|
||||
|
||||
pub fn binary_implicit_conversion(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
left: &mut Handle<Expression>,
|
||||
left_meta: Span,
|
||||
right: &mut Handle<Expression>,
|
||||
@@ -974,7 +974,7 @@ impl Context {
|
||||
|
||||
pub fn implicit_splat(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
parser: &Parser,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: Span,
|
||||
vector_size: Option<VectorSize>,
|
||||
|
||||
@@ -195,14 +195,39 @@ impl Parser {
|
||||
(value, expr_meta),
|
||||
meta,
|
||||
)?,
|
||||
TypeInner::Struct { .. } | TypeInner::Array { .. } => ctx.add_expression(
|
||||
Expression::Compose {
|
||||
ty,
|
||||
components: vec![value],
|
||||
},
|
||||
meta,
|
||||
body,
|
||||
),
|
||||
TypeInner::Struct { ref members, .. } => {
|
||||
let scalar_components = members
|
||||
.get(0)
|
||||
.and_then(|member| scalar_components(&self.module.types[member.ty].inner));
|
||||
if let Some((kind, width)) = scalar_components {
|
||||
ctx.implicit_conversion(self, &mut value, expr_meta, kind, width)?;
|
||||
}
|
||||
|
||||
ctx.add_expression(
|
||||
Expression::Compose {
|
||||
ty,
|
||||
components: vec![value],
|
||||
},
|
||||
meta,
|
||||
body,
|
||||
)
|
||||
}
|
||||
|
||||
TypeInner::Array { base, .. } => {
|
||||
let scalar_components = scalar_components(&self.module.types[base].inner);
|
||||
if let Some((kind, width)) = scalar_components {
|
||||
ctx.implicit_conversion(self, &mut value, expr_meta, kind, width)?;
|
||||
}
|
||||
|
||||
ctx.add_expression(
|
||||
Expression::Compose {
|
||||
ty,
|
||||
components: vec![value],
|
||||
},
|
||||
meta,
|
||||
body,
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
self.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError("Bad type constructor".into()),
|
||||
@@ -535,6 +560,26 @@ impl Parser {
|
||||
TypeInner::Vector { size, kind, width } => {
|
||||
return self.vector_constructor(ctx, body, ty, size, kind, width, &args, meta)
|
||||
}
|
||||
TypeInner::Array { base, .. } => {
|
||||
for (mut arg, meta) in args.iter().copied() {
|
||||
let scalar_components = scalar_components(&self.module.types[base].inner);
|
||||
if let Some((kind, width)) = scalar_components {
|
||||
ctx.implicit_conversion(self, &mut arg, meta, kind, width)?;
|
||||
}
|
||||
|
||||
components.push(arg)
|
||||
}
|
||||
}
|
||||
TypeInner::Struct { ref members, .. } => {
|
||||
for ((mut arg, meta), member) in args.iter().copied().zip(members.iter()) {
|
||||
let scalar_components = scalar_components(&self.module.types[member.ty].inner);
|
||||
if let Some((kind, width)) = scalar_components {
|
||||
ctx.implicit_conversion(self, &mut arg, meta, kind, width)?;
|
||||
}
|
||||
|
||||
components.push(arg)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Error {
|
||||
kind: ErrorKind::SemanticError("Constructor: Too many arguments".into()),
|
||||
|
||||
@@ -10,5 +10,16 @@ layout(location = 0) out FragmentData {
|
||||
vec2 a;
|
||||
} frag;
|
||||
|
||||
struct TestStruct {
|
||||
float a;
|
||||
float b;
|
||||
};
|
||||
|
||||
|
||||
void main() {
|
||||
const vec3 positions[2] = vec3[2](
|
||||
vec3(-1.0, 1.0, 0.0),
|
||||
vec3(-1.0, -1.0, 0.0)
|
||||
);
|
||||
const TestStruct strct = TestStruct( 1, 2 );
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ struct FragmentData {
|
||||
a: vec2<f32>;
|
||||
};
|
||||
|
||||
struct TestStruct {
|
||||
a: f32;
|
||||
b: f32;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[location(0)]] position: vec2<f32>;
|
||||
[[location(1)]] a: vec2<f32>;
|
||||
@@ -17,6 +22,9 @@ var<private> vert: VertexData;
|
||||
var<private> frag: FragmentData;
|
||||
|
||||
fn main_1() {
|
||||
var positions: array<vec3<f32>,2u> = array<vec3<f32>,2u>(vec3<f32>(-1.0, 1.0, 0.0), vec3<f32>(-1.0, -1.0, 0.0));
|
||||
var strct: TestStruct = TestStruct(1.0, 2.0);
|
||||
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
|
||||
Reference in New Issue
Block a user