mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-10-30 14:01:39 +00:00
Make validation reject 64-bit floating-point literals.
Make expression validation and constant expression validation reject `Literal` expressions containing `F64` literals unless the `FLOAT64` capability is enabled.
This commit is contained in:
parent
1bb84aef0b
commit
334f745366
@ -140,6 +140,8 @@ pub enum ConstExpressionError {
|
||||
Type(#[from] ResolveError),
|
||||
#[error(transparent)]
|
||||
Literal(#[from] LiteralError),
|
||||
#[error(transparent)]
|
||||
Width(#[from] super::r#type::WidthError),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
@ -149,6 +151,8 @@ pub enum LiteralError {
|
||||
NaN,
|
||||
#[error("Float literal is infinite")]
|
||||
Infinity,
|
||||
#[error(transparent)]
|
||||
Width(#[from] super::r#type::WidthError),
|
||||
}
|
||||
|
||||
#[cfg(feature = "validate")]
|
||||
@ -188,7 +192,7 @@ impl super::Validator {
|
||||
|
||||
match gctx.const_expressions[handle] {
|
||||
E::Literal(literal) => {
|
||||
check_literal_value(literal)?;
|
||||
self.validate_literal(literal)?;
|
||||
}
|
||||
E::Constant(_) | E::ZeroValue(_) => {}
|
||||
E::Compose { ref components, ty } => {
|
||||
@ -343,7 +347,7 @@ impl super::Validator {
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::Literal(literal) => {
|
||||
check_literal_value(literal)?;
|
||||
self.validate_literal(literal)?;
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::Constant(_) | E::ZeroValue(_) => ShaderStages::all(),
|
||||
@ -1563,6 +1567,15 @@ impl super::Validator {
|
||||
_ => Err(ExpressionError::ExpectedGlobalVariable),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_literal(&self, literal: crate::Literal) -> Result<(), LiteralError> {
|
||||
let kind = literal.scalar_kind();
|
||||
let width = literal.width();
|
||||
self.check_width(kind, width)?;
|
||||
check_literal_value(literal)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_literal_value(literal: crate::Literal) -> Result<(), LiteralError> {
|
||||
|
@ -129,6 +129,7 @@ pub enum TypeError {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub enum WidthError {
|
||||
#[error("The {0:?} scalar width {1} is not supported")]
|
||||
Invalid(crate::ScalarKind, crate::Bytes),
|
||||
|
Loading…
Reference in New Issue
Block a user