[spv-in] Permit pointers to runtime arrays only in StorageBuffer. (#1522)

* [spv-in] Change shadow.spv test input to use StorageBuffer.

The ecosystem around Naga will generally not be able to use Vulkan adapters that
don't support the SPV_KHR_storage_buffer_storage_class (which was incorporated
into SPIR-V 1.3), so we can assume it is present.

Changing the test not to use runtime-sized arrays in the Uniform storage class
will allow Naga to tighten up some validation checks.

* [spv-in] Permit pointers to runtime arrays only in StorageBuffer.

Fixes #1519.
This commit is contained in:
Jim Blandy 2021-11-10 13:58:57 -08:00 committed by GitHub
parent eda078d736
commit e69a70bfb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 6 deletions

View File

@ -41,6 +41,8 @@ pub enum Error {
UnsupportedControlFlow(spirv::Word),
#[error("unsupported binary operator %{0}")]
UnsupportedBinaryOperator(spirv::Word),
#[error("Naga supports OpTypeRuntimeArray in the StorageBuffer storage class only")]
UnsupportedRuntimeArrayStorageClass,
#[error("unknown binary operator {0:?}")]
UnknownBinaryOperator(spirv::Op),
#[error("unknown relational function {0:?}")]

View File

@ -3881,7 +3881,8 @@ impl<I: Iterator<Item = u32>> Parser<I> {
let decor = self.future_decor.remove(&id);
let base_lookup_ty = self.lookup_type.lookup(type_id)?;
let class = if let Some(class) = module.types[base_lookup_ty.handle].inner.pointer_class() {
let base_inner = &module.types[base_lookup_ty.handle].inner;
let class = if let Some(class) = base_inner.pointer_class() {
class
} else if self
.lookup_storage_buffer_types
@ -3897,6 +3898,22 @@ impl<I: Iterator<Item = u32>> Parser<I> {
}
};
// We don't support pointers to runtime-sized arrays in the `Uniform`
// storage class with the `BufferBlock` decoration. Runtime-sized arrays
// should be in the StorageBuffer class.
if let crate::TypeInner::Array {
size: crate::ArraySize::Dynamic,
..
} = *base_inner
{
match class {
crate::StorageClass::Storage { .. } => {}
_ => {
return Err(Error::UnsupportedRuntimeArrayStorageClass);
}
}
}
// Don't bother with pointer stuff for `Handle` types.
let lookup_ty = if class == crate::StorageClass::Handle {
base_lookup_ty.clone()

Binary file not shown.

View File

@ -200,21 +200,33 @@
name: None,
inner: Pointer(
base: 19,
class: Uniform,
class: Storage(
access: (
bits: 3,
),
),
),
),
(
name: None,
inner: Pointer(
base: 18,
class: Uniform,
class: Storage(
access: (
bits: 3,
),
),
),
),
(
name: None,
inner: Pointer(
base: 17,
class: Uniform,
class: Storage(
access: (
bits: 3,
),
),
),
),
(
@ -235,14 +247,22 @@
name: None,
inner: Pointer(
base: 4,
class: Uniform,
class: Storage(
access: (
bits: 3,
),
),
),
),
(
name: None,
inner: Pointer(
base: 1,
class: Uniform,
class: Storage(
access: (
bits: 3,
),
),
),
),
(