mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 16:01:04 +01:00
Add insert/extractBits and pack/unpack functions (#1449)
This commit is contained in:
1 parent
3e1244c5cb
commit
2f5a41cce9
25 files changed
+1225
-40
No files matched your search
+136
-22
@@ -870,15 +870,17 @@ impl super::Validator {
|
||||
arg,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3,
|
||||
} => {
|
||||
use crate::MathFunction as Mf;
|
||||
|
||||
let arg_ty = resolver.resolve(arg)?;
|
||||
let arg1_ty = arg1.map(|expr| resolver.resolve(expr)).transpose()?;
|
||||
let arg2_ty = arg2.map(|expr| resolver.resolve(expr)).transpose()?;
|
||||
let arg3_ty = arg3.map(|expr| resolver.resolve(expr)).transpose()?;
|
||||
match fun {
|
||||
Mf::Abs => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
let good = match *arg_ty {
|
||||
@@ -890,8 +892,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Min | Mf::Max => {
|
||||
let arg1_ty = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), None) => ty1,
|
||||
let arg1_ty = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), None, None) => ty1,
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
let good = match *arg_ty {
|
||||
@@ -910,8 +912,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Clamp => {
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), Some(ty2)) => (ty1, ty2),
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), None) => (ty1, ty2),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
let good = match *arg_ty {
|
||||
@@ -961,7 +963,7 @@ impl super::Validator {
|
||||
| Mf::Sign
|
||||
| Mf::Sqrt
|
||||
| Mf::InverseSqrt => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
@@ -975,8 +977,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Atan2 | Mf::Pow | Mf::Distance | Mf::Step => {
|
||||
let arg1_ty = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), None) => ty1,
|
||||
let arg1_ty = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), None, None) => ty1,
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
match *arg_ty {
|
||||
@@ -997,8 +999,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Modf | Mf::Frexp | Mf::Ldexp => {
|
||||
let arg1_ty = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), None) => ty1,
|
||||
let arg1_ty = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), None, None) => ty1,
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
let (size0, width0) = match *arg_ty {
|
||||
@@ -1032,8 +1034,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Dot | Mf::Outer | Mf::Cross | Mf::Reflect => {
|
||||
let arg1_ty = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), None) => ty1,
|
||||
let arg1_ty = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), None, None) => ty1,
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
match *arg_ty {
|
||||
@@ -1051,8 +1053,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Refract => {
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), Some(ty2)) => (ty1, ty2),
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), None) => (ty1, ty2),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
|
||||
@@ -1092,7 +1094,7 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Normalize => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
@@ -1103,8 +1105,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::FaceForward | Mf::Fma | Mf::SmoothStep => {
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), Some(ty2)) => (ty1, ty2),
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), None) => (ty1, ty2),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
match *arg_ty {
|
||||
@@ -1132,8 +1134,8 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Mix => {
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty) {
|
||||
(Some(ty1), Some(ty2)) => (ty1, ty2),
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), None) => (ty1, ty2),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
let arg_width = match *arg_ty {
|
||||
@@ -1172,7 +1174,7 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Inverse | Mf::Determinant => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
let good = match *arg_ty {
|
||||
@@ -1184,7 +1186,7 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::Transpose => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
@@ -1193,7 +1195,7 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
Mf::CountOneBits | Mf::ReverseBits => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
@@ -1204,6 +1206,118 @@ impl super::Validator {
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
}
|
||||
Mf::InsertBits => {
|
||||
let (arg1_ty, arg2_ty, arg3_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), Some(ty3)) => (ty1, ty2, ty3),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
match *arg_ty {
|
||||
Ti::Scalar { kind: Sk::Sint, .. }
|
||||
| Ti::Scalar { kind: Sk::Uint, .. }
|
||||
| Ti::Vector { kind: Sk::Sint, .. }
|
||||
| Ti::Vector { kind: Sk::Uint, .. } => {}
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
if arg1_ty != arg_ty {
|
||||
return Err(ExpressionError::InvalidArgumentType(
|
||||
fun,
|
||||
1,
|
||||
arg1.unwrap(),
|
||||
));
|
||||
}
|
||||
match *arg2_ty {
|
||||
Ti::Scalar { kind: Sk::Uint, .. } => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidArgumentType(
|
||||
fun,
|
||||
2,
|
||||
arg2.unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
match *arg3_ty {
|
||||
Ti::Scalar { kind: Sk::Uint, .. } => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidArgumentType(
|
||||
fun,
|
||||
2,
|
||||
arg3.unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
Mf::ExtractBits => {
|
||||
let (arg1_ty, arg2_ty) = match (arg1_ty, arg2_ty, arg3_ty) {
|
||||
(Some(ty1), Some(ty2), None) => (ty1, ty2),
|
||||
_ => return Err(ExpressionError::WrongArgumentCount(fun)),
|
||||
};
|
||||
match *arg_ty {
|
||||
Ti::Scalar { kind: Sk::Sint, .. }
|
||||
| Ti::Scalar { kind: Sk::Uint, .. }
|
||||
| Ti::Vector { kind: Sk::Sint, .. }
|
||||
| Ti::Vector { kind: Sk::Uint, .. } => {}
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
match *arg1_ty {
|
||||
Ti::Scalar { kind: Sk::Uint, .. } => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidArgumentType(
|
||||
fun,
|
||||
2,
|
||||
arg1.unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
match *arg2_ty {
|
||||
Ti::Scalar { kind: Sk::Uint, .. } => {}
|
||||
_ => {
|
||||
return Err(ExpressionError::InvalidArgumentType(
|
||||
fun,
|
||||
2,
|
||||
arg2.unwrap(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
Mf::Pack2x16unorm | Mf::Pack2x16snorm | Mf::Pack2x16float => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
Ti::Vector {
|
||||
size: crate::VectorSize::Bi,
|
||||
kind: Sk::Float,
|
||||
..
|
||||
} => {}
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
}
|
||||
Mf::Pack4x8snorm | Mf::Pack4x8unorm => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
Ti::Vector {
|
||||
size: crate::VectorSize::Quad,
|
||||
kind: Sk::Float,
|
||||
..
|
||||
} => {}
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
}
|
||||
Mf::Unpack2x16float
|
||||
| Mf::Unpack2x16snorm
|
||||
| Mf::Unpack2x16unorm
|
||||
| Mf::Unpack4x8snorm
|
||||
| Mf::Unpack4x8unorm => {
|
||||
if arg1_ty.is_some() | arg2_ty.is_some() | arg3_ty.is_some() {
|
||||
return Err(ExpressionError::WrongArgumentCount(fun));
|
||||
}
|
||||
match *arg_ty {
|
||||
Ti::Scalar { kind: Sk::Uint, .. } => {}
|
||||
_ => return Err(ExpressionError::InvalidArgumentType(fun, 0, arg)),
|
||||
}
|
||||
}
|
||||
}
|
||||
ShaderStages::all()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user