mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 17:44:09 +01:00
[ir] Remove Matrix Kind from the IR (#230)
This commit is contained in:
1 parent
f67dfd251a
commit
4420258001
10 files changed
+49
-64
No files matched your search
+3
-9
@@ -940,11 +940,10 @@ fn write_expression<'a, 'b>(
|
||||
TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
} => format!(
|
||||
"{}mat{}x{}",
|
||||
map_scalar(kind, width, builder.manager)?.prefix,
|
||||
map_scalar(crate::ScalarKind::Float, width, builder.manager)?.prefix,
|
||||
columns as u8,
|
||||
rows as u8,
|
||||
),
|
||||
@@ -1405,20 +1404,15 @@ fn write_type<'a>(
|
||||
TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
} => {
|
||||
if kind != ScalarKind::Float {
|
||||
return Err(Error::Custom(String::from(
|
||||
"Non float matrices aren't allowed",
|
||||
)));
|
||||
} else if width == 8 {
|
||||
if width == 8 {
|
||||
manager.request(Features::DOUBLE_TYPE);
|
||||
}
|
||||
|
||||
Cow::Owned(format!(
|
||||
"{}mat{}x{}",
|
||||
map_scalar(kind, width, manager)?.prefix,
|
||||
map_scalar(crate::ScalarKind::Float, width, manager)?.prefix,
|
||||
columns as u8,
|
||||
rows as u8
|
||||
))
|
||||
|
||||
+2
-7
@@ -814,16 +814,11 @@ impl<W: Write> Writer<W> {
|
||||
name
|
||||
)?;
|
||||
}
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
..
|
||||
} => {
|
||||
crate::TypeInner::Matrix { columns, rows, .. } => {
|
||||
write!(
|
||||
self.out,
|
||||
"typedef {}{}x{} {}",
|
||||
scalar_kind_string(kind),
|
||||
scalar_kind_string(crate::ScalarKind::Float),
|
||||
vector_size_string(columns),
|
||||
vector_size_string(rows),
|
||||
name
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
pub(super) fn validate_instruction(words: &[spirv::Word], instruction: &crate::back::spv::Instruction) {
|
||||
pub(super) fn validate_instruction(
|
||||
words: &[spirv::Word],
|
||||
instruction: &crate::back::spv::Instruction,
|
||||
) {
|
||||
let mut inst_index = 0;
|
||||
let (wc, op) = ((words[inst_index] >> 16) as u16, words[inst_index] as u16);
|
||||
inst_index += 1;
|
||||
|
||||
@@ -465,14 +465,13 @@ impl Writer {
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows: _,
|
||||
kind,
|
||||
width,
|
||||
} => {
|
||||
let vector_id = self.get_type_id(
|
||||
arena,
|
||||
LookupType::Local(LocalType::Vector {
|
||||
size: columns,
|
||||
kind,
|
||||
kind: crate::ScalarKind::Float,
|
||||
width,
|
||||
}),
|
||||
);
|
||||
@@ -836,14 +835,13 @@ impl Writer {
|
||||
crate::TypeInner::Matrix {
|
||||
rows,
|
||||
columns,
|
||||
kind,
|
||||
width,
|
||||
} => {
|
||||
let vector_type_id = self.get_type_id(
|
||||
&ir_module.types,
|
||||
LookupType::Local(LocalType::Vector {
|
||||
width,
|
||||
kind,
|
||||
kind: crate::ScalarKind::Float,
|
||||
size: columns,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
|
||||
let kind = iter.next()?;
|
||||
let size = iter.next()?;
|
||||
let (kind, width) = kind_width_parse(kind)?;
|
||||
let (_, width) = kind_width_parse(kind)?;
|
||||
|
||||
let (columns, rows) = if let Some(size) = size_parse(size) {
|
||||
(size, size)
|
||||
@@ -94,7 +94,6 @@ pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
inner: TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1846,10 +1846,9 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
let num_columns = self.next()?;
|
||||
let vector_type_lookup = self.lookup_type.lookup(vector_type_id)?;
|
||||
let inner = match module.types[vector_type_lookup.handle].inner {
|
||||
crate::TypeInner::Vector { size, kind, width } => crate::TypeInner::Matrix {
|
||||
crate::TypeInner::Vector { size, width, .. } => crate::TypeInner::Matrix {
|
||||
columns: map_vector_size(num_columns)?,
|
||||
rows: size,
|
||||
kind,
|
||||
width,
|
||||
},
|
||||
_ => return Err(Error::InvalidInnerType(vector_type_id)),
|
||||
|
||||
+17
-22
@@ -298,11 +298,17 @@ impl Parser {
|
||||
index: usize,
|
||||
) -> Result<Handle<crate::Type>, Error<'static>> {
|
||||
match type_arena[ty].inner {
|
||||
crate::TypeInner::Vector { kind, width, .. }
|
||||
| crate::TypeInner::Matrix { kind, width, .. } => {
|
||||
crate::TypeInner::Vector { kind, width, .. } => {
|
||||
let inner = crate::TypeInner::Scalar { kind, width };
|
||||
Ok(type_arena.fetch_or_append(crate::Type { name: None, inner }))
|
||||
}
|
||||
crate::TypeInner::Matrix { width, .. } => {
|
||||
let inner = crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Float,
|
||||
width,
|
||||
};
|
||||
Ok(type_arena.fetch_or_append(crate::Type { name: None, inner }))
|
||||
}
|
||||
crate::TypeInner::Array { base, .. } => Ok(base),
|
||||
crate::TypeInner::Struct { ref members } => Ok(members[index].ty),
|
||||
_ => Err(Error::NotCompositeType(ty)),
|
||||
@@ -543,14 +549,12 @@ impl Parser {
|
||||
crate::TypeInner::Matrix {
|
||||
rows,
|
||||
columns,
|
||||
kind,
|
||||
width,
|
||||
} => match Composition::make(handle, columns, name, ctx.expressions)? {
|
||||
Composition::Multi(columns, components) => {
|
||||
let inner = crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
};
|
||||
crate::Expression::Compose {
|
||||
@@ -1049,83 +1053,74 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
Token::Word("mat2x2") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Bi,
|
||||
rows: crate::VectorSize::Bi,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat2x3") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Bi,
|
||||
rows: crate::VectorSize::Tri,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat2x4") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Bi,
|
||||
rows: crate::VectorSize::Quad,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat3x2") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Tri,
|
||||
rows: crate::VectorSize::Bi,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat3x3") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Tri,
|
||||
rows: crate::VectorSize::Tri,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat3x4") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Tri,
|
||||
rows: crate::VectorSize::Quad,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat4x2") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Quad,
|
||||
rows: crate::VectorSize::Bi,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat4x3") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Quad,
|
||||
rows: crate::VectorSize::Tri,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
Token::Word("mat4x4") => {
|
||||
let (kind, width) = lexer.next_scalar_generic()?;
|
||||
let (_, width) = lexer.next_scalar_generic()?;
|
||||
crate::TypeInner::Matrix {
|
||||
columns: crate::VectorSize::Quad,
|
||||
rows: crate::VectorSize::Quad,
|
||||
kind,
|
||||
width,
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -351,11 +351,10 @@ pub enum TypeInner {
|
||||
kind: ScalarKind,
|
||||
width: Bytes,
|
||||
},
|
||||
/// Matrix of numbers.
|
||||
/// Matrix of floats.
|
||||
Matrix {
|
||||
columns: VectorSize,
|
||||
rows: VectorSize,
|
||||
kind: ScalarKind,
|
||||
width: Bytes,
|
||||
},
|
||||
/// Pointer to a value.
|
||||
|
||||
+7
-10
@@ -23,12 +23,10 @@ impl Clone for Resolution {
|
||||
crate::TypeInner::Matrix {
|
||||
rows,
|
||||
columns,
|
||||
kind,
|
||||
width,
|
||||
} => crate::TypeInner::Matrix {
|
||||
rows,
|
||||
columns,
|
||||
kind,
|
||||
width,
|
||||
},
|
||||
_ => panic!("Unepxected clone type: {:?}", v),
|
||||
@@ -101,9 +99,12 @@ impl Typifier {
|
||||
crate::TypeInner::Matrix {
|
||||
rows: size,
|
||||
columns: _,
|
||||
kind,
|
||||
width,
|
||||
} => Resolution::Value(crate::TypeInner::Vector { size, kind, width }),
|
||||
} => Resolution::Value(crate::TypeInner::Vector {
|
||||
size,
|
||||
kind: crate::ScalarKind::Float,
|
||||
width,
|
||||
}),
|
||||
ref other => panic!("Can't access into {:?}", other),
|
||||
},
|
||||
crate::Expression::AccessIndex { base, index } => match *self.get(base, types) {
|
||||
@@ -116,7 +117,6 @@ impl Typifier {
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
} => {
|
||||
if index >= columns as u32 {
|
||||
@@ -124,7 +124,7 @@ impl Typifier {
|
||||
}
|
||||
Resolution::Value(crate::TypeInner::Vector {
|
||||
size: rows,
|
||||
kind,
|
||||
kind: crate::ScalarKind::Float,
|
||||
width,
|
||||
})
|
||||
}
|
||||
@@ -186,11 +186,10 @@ impl Typifier {
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows: _,
|
||||
kind,
|
||||
width,
|
||||
} => Resolution::Value(crate::TypeInner::Vector {
|
||||
size: columns,
|
||||
kind,
|
||||
kind: crate::ScalarKind::Float,
|
||||
width,
|
||||
}),
|
||||
_ => panic!("Incompatible arguments {:?} x {:?}", ty_left, ty_right),
|
||||
@@ -219,12 +218,10 @@ impl Typifier {
|
||||
crate::TypeInner::Matrix {
|
||||
columns,
|
||||
rows,
|
||||
kind,
|
||||
width,
|
||||
} => Resolution::Value(crate::TypeInner::Matrix {
|
||||
columns: rows,
|
||||
rows: columns,
|
||||
kind,
|
||||
width,
|
||||
}),
|
||||
ref other => panic!("incompatible transpose of {:?}", other),
|
||||
|
||||
+11
-5
@@ -228,14 +228,14 @@ impl Validator {
|
||||
| (crate::ShaderStage::Fragment, crate::StorageClass::Input) => {
|
||||
match module.types[var.ty].inner {
|
||||
crate::TypeInner::Scalar { kind, .. }
|
||||
| crate::TypeInner::Vector { kind, .. }
|
||||
| crate::TypeInner::Matrix { kind, .. } => {
|
||||
| crate::TypeInner::Vector { kind, .. } => {
|
||||
if kind != crate::ScalarKind::Float
|
||||
&& var.interpolation != Some(crate::Interpolation::Flat)
|
||||
{
|
||||
return Err(EntryPointError::InvalidIntegerInterpolation);
|
||||
}
|
||||
}
|
||||
crate::TypeInner::Matrix { .. } => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -342,9 +342,7 @@ impl Validator {
|
||||
for (handle, ty) in module.types.iter() {
|
||||
use crate::TypeInner as Ti;
|
||||
match ty.inner {
|
||||
Ti::Scalar { kind, width }
|
||||
| Ti::Vector { kind, width, .. }
|
||||
| Ti::Matrix { kind, width, .. } => {
|
||||
Ti::Scalar { kind, width } | Ti::Vector { kind, width, .. } => {
|
||||
let expected = match kind {
|
||||
crate::ScalarKind::Bool => 1,
|
||||
_ => 4,
|
||||
@@ -353,6 +351,14 @@ impl Validator {
|
||||
return Err(ValidationError::InvalidTypeWidth(kind, width));
|
||||
}
|
||||
}
|
||||
Ti::Matrix { width, .. } => {
|
||||
if width != 4 {
|
||||
return Err(ValidationError::InvalidTypeWidth(
|
||||
crate::ScalarKind::Float,
|
||||
width,
|
||||
));
|
||||
}
|
||||
}
|
||||
Ti::Pointer { base, class: _ } => {
|
||||
if base >= handle {
|
||||
return Err(ValidationError::UnresolvedType(base));
|
||||
|
||||
Reference in new issue
Block a user