Skip to content

Commit 105cb9d

Browse files
authored
[naga wgsl-in] Proper singular generic in vec and matrix (#6189)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent 8eb0e64 commit 105cb9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1812
-1744
lines changed

naga/src/front/wgsl/lower/construction.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,13 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
578578
Constructor::Type(ty)
579579
}
580580
ast::ConstructorType::PartialVector { size } => Constructor::PartialVector { size },
581-
ast::ConstructorType::Vector { size, scalar } => {
582-
let ty = ctx.ensure_type_exists(scalar.to_inner_vector(size));
581+
ast::ConstructorType::Vector { size, ty, ty_span } => {
582+
let ty = self.resolve_ast_type(ty, &mut ctx.as_global())?;
583+
let scalar = match ctx.module.types[ty].inner {
584+
crate::TypeInner::Scalar(sc) => sc,
585+
_ => return Err(Error::UnknownScalarType(ty_span)),
586+
};
587+
let ty = ctx.ensure_type_exists(crate::TypeInner::Vector { size, scalar });
583588
Constructor::Type(ty)
584589
}
585590
ast::ConstructorType::PartialMatrix { columns, rows } => {
@@ -588,13 +593,22 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
588593
ast::ConstructorType::Matrix {
589594
rows,
590595
columns,
591-
width,
596+
ty,
597+
ty_span,
592598
} => {
593-
let ty = ctx.ensure_type_exists(crate::TypeInner::Matrix {
594-
columns,
595-
rows,
596-
scalar: crate::Scalar::float(width),
597-
});
599+
let ty = self.resolve_ast_type(ty, &mut ctx.as_global())?;
600+
let scalar = match ctx.module.types[ty].inner {
601+
crate::TypeInner::Scalar(sc) => sc,
602+
_ => return Err(Error::UnknownScalarType(ty_span)),
603+
};
604+
let ty = match scalar.kind {
605+
crate::ScalarKind::Float => ctx.ensure_type_exists(crate::TypeInner::Matrix {
606+
columns,
607+
rows,
608+
scalar,
609+
}),
610+
_ => return Err(Error::BadMatrixScalarKind(ty_span, scalar)),
611+
};
598612
Constructor::Type(ty)
599613
}
600614
ast::ConstructorType::PartialArray => Constructor::PartialArray,

naga/src/front/wgsl/lower/mod.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,16 +2965,34 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
29652965
) -> Result<Handle<crate::Type>, Error<'source>> {
29662966
let inner = match ctx.types[handle] {
29672967
ast::Type::Scalar(scalar) => scalar.to_inner_scalar(),
2968-
ast::Type::Vector { size, scalar } => scalar.to_inner_vector(size),
2968+
ast::Type::Vector { size, ty, ty_span } => {
2969+
let ty = self.resolve_ast_type(ty, ctx)?;
2970+
let scalar = match ctx.module.types[ty].inner {
2971+
crate::TypeInner::Scalar(sc) => sc,
2972+
_ => return Err(Error::UnknownScalarType(ty_span)),
2973+
};
2974+
crate::TypeInner::Vector { size, scalar }
2975+
}
29692976
ast::Type::Matrix {
29702977
rows,
29712978
columns,
2972-
width,
2973-
} => crate::TypeInner::Matrix {
2974-
columns,
2975-
rows,
2976-
scalar: crate::Scalar::float(width),
2977-
},
2979+
ty,
2980+
ty_span,
2981+
} => {
2982+
let ty = self.resolve_ast_type(ty, ctx)?;
2983+
let scalar = match ctx.module.types[ty].inner {
2984+
crate::TypeInner::Scalar(sc) => sc,
2985+
_ => return Err(Error::UnknownScalarType(ty_span)),
2986+
};
2987+
match scalar.kind {
2988+
crate::ScalarKind::Float => crate::TypeInner::Matrix {
2989+
columns,
2990+
rows,
2991+
scalar,
2992+
},
2993+
_ => return Err(Error::BadMatrixScalarKind(ty_span, scalar)),
2994+
}
2995+
}
29782996
ast::Type::Atomic(scalar) => scalar.to_inner_atomic(),
29792997
ast::Type::Pointer { base, space } => {
29802998
let base = self.resolve_ast_type(base, ctx)?;

naga/src/front/wgsl/parse/ast.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ pub enum Type<'a> {
198198
Scalar(Scalar),
199199
Vector {
200200
size: crate::VectorSize,
201-
scalar: Scalar,
201+
ty: Handle<Type<'a>>,
202+
ty_span: Span,
202203
},
203204
Matrix {
204205
columns: crate::VectorSize,
205206
rows: crate::VectorSize,
206-
width: crate::Bytes,
207+
ty: Handle<Type<'a>>,
208+
ty_span: Span,
207209
},
208210
Atomic(Scalar),
209211
Pointer {
@@ -330,7 +332,8 @@ pub enum ConstructorType<'a> {
330332
/// `vec3<f32>(1.0)`.
331333
Vector {
332334
size: crate::VectorSize,
333-
scalar: Scalar,
335+
ty: Handle<Type<'a>>,
336+
ty_span: Span,
334337
},
335338

336339
/// A matrix construction whose component type is inferred from the
@@ -345,7 +348,8 @@ pub enum ConstructorType<'a> {
345348
Matrix {
346349
columns: crate::VectorSize,
347350
rows: crate::VectorSize,
348-
width: crate::Bytes,
351+
ty: Handle<Type<'a>>,
352+
ty_span: Span,
349353
},
350354

351355
/// An array whose component type and size are inferred from the arguments:

0 commit comments

Comments
 (0)