mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 18:14:18 +01:00
Permit dynamic indexing of arrays and matrices only behind a pointer. (#949)
This makes Naga IR validation impose the restrictions added to WGSL in gpuweb/gpuweb#1801. Remove code in the SPIR-V writer to spill arrays to temporary variables in order to index them dynamically. If such IR is encountered, treat it as a failure of validation.
This commit is contained in:
1 parent
1c3baf4557
commit
a2a35f2eb3
10 files changed
+187
-124
No files matched your search
+13
-7
@@ -19,6 +19,8 @@ pub enum ExpressionError {
|
||||
InvalidIndexType(Handle<crate::Expression>),
|
||||
#[error("Accessing index {1} is out of {0:?} bounds")]
|
||||
IndexOutOfBounds(Handle<crate::Expression>, u32),
|
||||
#[error("The expression {0:?} may only be indexed by a constant")]
|
||||
IndexMustBeConstant(Handle<crate::Expression>),
|
||||
#[error("Function argument {0:?} doesn't exist")]
|
||||
FunctionArgumentDoesntExist(u32),
|
||||
#[error("Constant {0:?} doesn't exist")]
|
||||
@@ -142,17 +144,16 @@ impl super::Validator {
|
||||
|
||||
let stages = match *expression {
|
||||
E::Access { base, index } => {
|
||||
match *resolver.resolve(base)? {
|
||||
Ti::Vector { .. }
|
||||
| Ti::Matrix { .. }
|
||||
| Ti::Array { .. }
|
||||
| Ti::Pointer { .. }
|
||||
| Ti::ValuePointer { size: Some(_), .. } => {}
|
||||
// See the documentation for `Expression::Access`.
|
||||
let dynamic_indexing_restricted = match *resolver.resolve(base)? {
|
||||
Ti::Vector { .. } => false,
|
||||
Ti::Matrix { .. } | Ti::Array { .. } => true,
|
||||
Ti::Pointer { .. } | Ti::ValuePointer { size: Some(_), .. } => false,
|
||||
ref other => {
|
||||
log::error!("Indexing of {:?}", other);
|
||||
return Err(ExpressionError::InvalidBaseType(base));
|
||||
}
|
||||
}
|
||||
};
|
||||
match *resolver.resolve(index)? {
|
||||
//TODO: only allow one of these
|
||||
Ti::Scalar {
|
||||
@@ -168,6 +169,11 @@ impl super::Validator {
|
||||
return Err(ExpressionError::InvalidIndexType(index));
|
||||
}
|
||||
}
|
||||
if dynamic_indexing_restricted
|
||||
&& function.expressions[index].is_dynamic_index(module)
|
||||
{
|
||||
return Err(ExpressionError::IndexMustBeConstant(base));
|
||||
}
|
||||
ShaderStages::all()
|
||||
}
|
||||
E::AccessIndex { base, index } => {
|
||||
|
||||
Reference in new issue
Block a user