Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override-expressions for Fixed Size Arrays #6654

Merged
merged 21 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions naga/src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ impl super::Validator {
if access == crate::StorageAccess::STORE {
return Err(GlobalVariableError::StorageAddressSpaceWriteOnlyNotSupported);
}
(TypeFlags::DATA | TypeFlags::HOST_SHAREABLE, true)
(
TypeFlags::DATA | TypeFlags::HOST_SHAREABLE | TypeFlags::CREATION_RESOLVED,
true,
)
}
crate::AddressSpace::Uniform => {
if let Err((ty_handle, disalignment)) = type_info.uniform_layout {
Expand All @@ -513,7 +516,8 @@ impl super::Validator {
TypeFlags::DATA
| TypeFlags::COPY
| TypeFlags::SIZED
| TypeFlags::HOST_SHAREABLE,
| TypeFlags::HOST_SHAREABLE
| TypeFlags::CREATION_RESOLVED,
true,
)
}
Expand Down Expand Up @@ -551,7 +555,10 @@ impl super::Validator {

(TypeFlags::empty(), true)
}
crate::AddressSpace::Private => (TypeFlags::CONSTRUCTIBLE, false),
crate::AddressSpace::Private => (
TypeFlags::CONSTRUCTIBLE | TypeFlags::CREATION_RESOLVED,
false,
),
crate::AddressSpace::WorkGroup => (TypeFlags::DATA | TypeFlags::SIZED, false),
crate::AddressSpace::PushConstant => {
if !self.capabilities.contains(Capabilities::PUSH_CONSTANT) {
Expand Down
80 changes: 64 additions & 16 deletions naga/src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ bitflags::bitflags! {
/// Can be used for host-shareable structures.
const HOST_SHAREABLE = 0x10;

/// The set of types with a fixed size at shader-creation time or a not-fixed size at
/// pipeline creation time (ie. everything except arrays sized by an override-expression)
const CREATION_RESOLVED = 0x20;
kentslaney marked this conversation as resolved.
Show resolved Hide resolved

/// This type can be passed as a function argument.
const ARGUMENT = 0x40;

Expand Down Expand Up @@ -323,6 +327,7 @@ impl super::Validator {
| TypeFlags::COPY
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED
| shareable,
Alignment::from_width(scalar.width),
)
Expand All @@ -340,6 +345,7 @@ impl super::Validator {
| TypeFlags::COPY
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED
| shareable,
Alignment::from(size) * Alignment::from_width(scalar.width),
)
Expand All @@ -359,7 +365,8 @@ impl super::Validator {
| TypeFlags::COPY
| TypeFlags::HOST_SHAREABLE
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE,
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED,
Alignment::from(rows) * Alignment::from_width(scalar.width),
)
}
Expand Down Expand Up @@ -387,7 +394,10 @@ impl super::Validator {
}
};
TypeInfo::new(
TypeFlags::DATA | TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE,
TypeFlags::DATA
| TypeFlags::SIZED
| TypeFlags::HOST_SHAREABLE
| TypeFlags::CREATION_RESOLVED,
Alignment::from_width(width),
)
}
Expand Down Expand Up @@ -428,7 +438,10 @@ impl super::Validator {
// Pointers cannot be stored in variables, structure members, or
// array elements, so we do not mark them as `DATA`.
TypeInfo::new(
argument_flag | TypeFlags::SIZED | TypeFlags::COPY,
argument_flag
| TypeFlags::SIZED
| TypeFlags::COPY
| TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
)
}
Expand All @@ -455,13 +468,19 @@ impl super::Validator {
// Pointers cannot be stored in variables, structure members, or
// array elements, so we do not mark them as `DATA`.
TypeInfo::new(
argument_flag | TypeFlags::SIZED | TypeFlags::COPY,
argument_flag
| TypeFlags::SIZED
| TypeFlags::COPY
| TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
)
}
Ti::Array { base, size, stride } => {
let base_info = &self.types[base.index()];
if !base_info.flags.contains(TypeFlags::DATA | TypeFlags::SIZED) {
if !base_info
.flags
.contains(TypeFlags::DATA | TypeFlags::SIZED | TypeFlags::CREATION_RESOLVED)
{
return Err(TypeError::InvalidArrayBaseType(base));
}

Expand Down Expand Up @@ -493,7 +512,16 @@ impl super::Validator {
};

let type_info_mask = match size {
crate::ArraySize::Constant(_) | crate::ArraySize::Pending(_) => {
crate::ArraySize::Constant(_) => {
TypeFlags::DATA
| TypeFlags::SIZED
| TypeFlags::COPY
| TypeFlags::HOST_SHAREABLE
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED
}
crate::ArraySize::Pending(_) => {
kentslaney marked this conversation as resolved.
Show resolved Hide resolved
TypeFlags::DATA
| TypeFlags::SIZED
| TypeFlags::COPY
Expand All @@ -505,7 +533,10 @@ impl super::Validator {
// Non-SIZED types may only appear as the last element of a structure.
// This is enforced by checks for SIZED-ness for all compound types,
// and a special case for structs.
TypeFlags::DATA | TypeFlags::COPY | TypeFlags::HOST_SHAREABLE
TypeFlags::DATA
| TypeFlags::COPY
| TypeFlags::HOST_SHAREABLE
| TypeFlags::CREATION_RESOLVED
}
};

Expand All @@ -527,7 +558,8 @@ impl super::Validator {
| TypeFlags::HOST_SHAREABLE
| TypeFlags::IO_SHAREABLE
| TypeFlags::ARGUMENT
| TypeFlags::CONSTRUCTIBLE,
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
);
ti.uniform_layout = Ok(Alignment::MIN_UNIFORM);
Expand All @@ -537,7 +569,10 @@ impl super::Validator {

for (i, member) in members.iter().enumerate() {
let base_info = &self.types[member.ty.index()];
if !base_info.flags.contains(TypeFlags::DATA) {
if !base_info
.flags
.contains(TypeFlags::DATA | TypeFlags::CREATION_RESOLVED)
{
return Err(TypeError::InvalidData(member.ty));
}
if !base_info.flags.contains(TypeFlags::HOST_SHAREABLE) {
Expand Down Expand Up @@ -653,28 +688,41 @@ impl super::Validator {
if arrayed && matches!(dim, crate::ImageDimension::Cube) {
self.require_type_capability(Capabilities::CUBE_ARRAY_TEXTURES)?;
}
TypeInfo::new(TypeFlags::ARGUMENT, Alignment::ONE)
TypeInfo::new(
TypeFlags::ARGUMENT | TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
)
}
Ti::Sampler { .. } => TypeInfo::new(TypeFlags::ARGUMENT, Alignment::ONE),
Ti::Sampler { .. } => TypeInfo::new(
TypeFlags::ARGUMENT | TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
),
Ti::AccelerationStructure => {
self.require_type_capability(Capabilities::RAY_QUERY)?;
TypeInfo::new(TypeFlags::ARGUMENT, Alignment::ONE)
TypeInfo::new(
TypeFlags::ARGUMENT | TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
)
}
Ti::RayQuery => {
self.require_type_capability(Capabilities::RAY_QUERY)?;
TypeInfo::new(
TypeFlags::DATA | TypeFlags::CONSTRUCTIBLE | TypeFlags::SIZED,
TypeFlags::DATA
| TypeFlags::CONSTRUCTIBLE
| TypeFlags::SIZED
| TypeFlags::CREATION_RESOLVED,
Alignment::ONE,
)
}
Ti::BindingArray { base, size } => {
let type_info_mask = match size {
crate::ArraySize::Constant(_) | crate::ArraySize::Pending(_) => {
TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE
crate::ArraySize::Constant(_) => {
TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE | TypeFlags::CREATION_RESOLVED
}
crate::ArraySize::Pending(_) => TypeFlags::SIZED | TypeFlags::HOST_SHAREABLE,
crate::ArraySize::Dynamic => {
// Final type is non-sized
TypeFlags::HOST_SHAREABLE
TypeFlags::HOST_SHAREABLE | TypeFlags::CREATION_RESOLVED
}
};
let base_info = &self.types[base.index()];
Expand Down
66 changes: 33 additions & 33 deletions naga/tests/out/analysis/access.info.ron
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
(
type_flags: [
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | HOST_SHAREABLE"),
("DATA | SIZED | HOST_SHAREABLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE"),
("DATA | HOST_SHAREABLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | SIZED | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | CREATION_RESOLVED | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | CREATION_RESOLVED | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | CREATION_RESOLVED | ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | CREATION_RESOLVED | ARGUMENT"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("SIZED | COPY | CREATION_RESOLVED | ARGUMENT"),
],
functions: [
(
Expand Down
8 changes: 4 additions & 4 deletions naga/tests/out/analysis/collatz.info.ron
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(
type_flags: [
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE"),
("DATA | COPY | HOST_SHAREABLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
],
functions: [
(
Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/analysis/overrides.info.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(
type_flags: [
("DATA | SIZED | COPY | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
],
functions: [],
entry_points: [
Expand Down
28 changes: 14 additions & 14 deletions naga/tests/out/analysis/shadow.info.ron
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(
type_flags: [
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE"),
("DATA | COPY | HOST_SHAREABLE"),
("ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("CREATION_RESOLVED | ARGUMENT"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | IO_SHAREABLE | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED | ARGUMENT | CONSTRUCTIBLE"),
("DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED"),
("DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED"),
("CREATION_RESOLVED | ARGUMENT"),
],
functions: [
(
Expand Down