Rename GlobalUse variants

This commit is contained in:
Dzmitry Malyshau
2021-01-21 20:00:36 -05:00
committed by Dzmitry Malyshau
parent bc66f784c1
commit b441a25956
4 changed files with 38 additions and 38 deletions

View File

@@ -40,7 +40,7 @@ impl<'a> TypedGlobalVariable<'a> {
let (space_qualifier, reference) = match ty.inner {
crate::TypeInner::Struct { .. } => match var.class {
crate::StorageClass::Uniform | crate::StorageClass::Storage => {
let space = if self.usage.contains(crate::GlobalUse::STORE) {
let space = if self.usage.contains(crate::GlobalUse::WRITE) {
"device "
} else {
"constant "
@@ -930,7 +930,7 @@ impl<W: Write> Writer<W> {
module.global_variables.iter().zip(&fun.global_usage)
{
if var.class != crate::StorageClass::Input
|| !usage.contains(crate::GlobalUse::LOAD)
|| !usage.contains(crate::GlobalUse::READ)
{
continue;
}
@@ -956,7 +956,7 @@ impl<W: Write> Writer<W> {
module.global_variables.iter().zip(&fun.global_usage)
{
if var.class != crate::StorageClass::Output
|| !usage.contains(crate::GlobalUse::STORE)
|| !usage.contains(crate::GlobalUse::WRITE)
{
continue;
}

View File

@@ -445,9 +445,9 @@ bitflags::bitflags! {
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
pub struct GlobalUse: u8 {
/// Data will be read from the variable.
const LOAD = 0x1;
const READ = 0x1;
/// Data will be written to the variable.
const STORE = 0x2;
const WRITE = 0x2;
}
}

View File

@@ -203,13 +203,13 @@ struct GlobalUseVisitor<'a>(&'a mut [crate::GlobalUse]);
impl Visitor for GlobalUseVisitor<'_> {
fn visit_expr(&mut self, expr: &crate::Expression) {
if let crate::Expression::GlobalVariable(handle) = expr {
self.0[handle.index()] |= crate::GlobalUse::LOAD;
self.0[handle.index()] |= crate::GlobalUse::READ;
}
}
fn visit_lhs_expr(&mut self, expr: &crate::Expression) {
if let crate::Expression::GlobalVariable(handle) = expr {
self.0[handle.index()] |= crate::GlobalUse::STORE;
self.0[handle.index()] |= crate::GlobalUse::WRITE;
}
}
}
@@ -291,10 +291,10 @@ mod tests {
assert_eq!(
&function.global_usage,
&[
GlobalUse::LOAD,
GlobalUse::STORE,
GlobalUse::STORE,
GlobalUse::LOAD,
GlobalUse::READ,
GlobalUse::WRITE,
GlobalUse::WRITE,
GlobalUse::READ,
],
)
}

View File

@@ -219,10 +219,10 @@ impl crate::GlobalVariable {
fn storage_usage(access: crate::StorageAccess) -> crate::GlobalUse {
let mut storage_usage = crate::GlobalUse::empty();
if access.contains(crate::StorageAccess::LOAD) {
storage_usage |= crate::GlobalUse::LOAD;
storage_usage |= crate::GlobalUse::READ;
}
if access.contains(crate::StorageAccess::STORE) {
storage_usage |= crate::GlobalUse::STORE;
storage_usage |= crate::GlobalUse::WRITE;
}
storage_usage
}
@@ -230,24 +230,24 @@ fn storage_usage(access: crate::StorageAccess) -> crate::GlobalUse {
fn built_in_usage(built_in: crate::BuiltIn) -> (crate::ShaderStage, crate::GlobalUse) {
use crate::{BuiltIn as Bi, GlobalUse as Gu, ShaderStage as Ss};
match built_in {
Bi::BaseInstance => (Ss::Vertex, Gu::LOAD),
Bi::BaseVertex => (Ss::Vertex, Gu::LOAD),
Bi::ClipDistance => (Ss::Vertex, Gu::STORE),
Bi::InstanceIndex => (Ss::Vertex, Gu::LOAD),
Bi::PointSize => (Ss::Vertex, Gu::STORE),
Bi::Position => (Ss::Vertex, Gu::STORE),
Bi::VertexIndex => (Ss::Vertex, Gu::LOAD),
Bi::FragCoord => (Ss::Fragment, Gu::LOAD),
Bi::FragDepth => (Ss::Fragment, Gu::LOAD),
Bi::FrontFacing => (Ss::Fragment, Gu::LOAD),
Bi::SampleIndex => (Ss::Fragment, Gu::LOAD),
Bi::SampleMaskIn => (Ss::Fragment, Gu::LOAD),
Bi::SampleMaskOut => (Ss::Fragment, Gu::STORE),
Bi::GlobalInvocationId => (Ss::Compute, Gu::LOAD),
Bi::LocalInvocationId => (Ss::Compute, Gu::LOAD),
Bi::LocalInvocationIndex => (Ss::Compute, Gu::LOAD),
Bi::WorkGroupId => (Ss::Compute, Gu::LOAD),
Bi::WorkGroupSize => (Ss::Compute, Gu::LOAD),
Bi::BaseInstance => (Ss::Vertex, Gu::READ),
Bi::BaseVertex => (Ss::Vertex, Gu::READ),
Bi::ClipDistance => (Ss::Vertex, Gu::WRITE),
Bi::InstanceIndex => (Ss::Vertex, Gu::READ),
Bi::PointSize => (Ss::Vertex, Gu::WRITE),
Bi::Position => (Ss::Vertex, Gu::WRITE),
Bi::VertexIndex => (Ss::Vertex, Gu::READ),
Bi::FragCoord => (Ss::Fragment, Gu::READ),
Bi::FragDepth => (Ss::Fragment, Gu::READ),
Bi::FrontFacing => (Ss::Fragment, Gu::READ),
Bi::SampleIndex => (Ss::Fragment, Gu::READ),
Bi::SampleMaskIn => (Ss::Fragment, Gu::READ),
Bi::SampleMaskOut => (Ss::Fragment, Gu::WRITE),
Bi::GlobalInvocationId => (Ss::Compute, Gu::READ),
Bi::LocalInvocationId => (Ss::Compute, Gu::READ),
Bi::LocalInvocationIndex => (Ss::Compute, Gu::READ),
Bi::WorkGroupId => (Ss::Compute, Gu::READ),
Bi::WorkGroupSize => (Ss::Compute, Gu::READ),
}
}
@@ -524,7 +524,7 @@ impl Validator {
Some(crate::Binding::BuiltIn(built_in)) => {
let (allowed_stage, allowed_usage) = built_in_usage(built_in);
if allowed_stage != stage
|| !allowed_usage.contains(crate::GlobalUse::LOAD)
|| !allowed_usage.contains(crate::GlobalUse::READ)
{
return Err(EntryPointError::InvalidBuiltIn(built_in));
}
@@ -537,14 +537,14 @@ impl Validator {
Some(crate::Binding::Resource { .. }) => unreachable!(),
None => (),
}
crate::GlobalUse::LOAD
crate::GlobalUse::READ
}
crate::StorageClass::Output => {
match var.binding {
Some(crate::Binding::BuiltIn(built_in)) => {
let (allowed_stage, allowed_usage) = built_in_usage(built_in);
if allowed_stage != stage
|| !allowed_usage.contains(crate::GlobalUse::STORE)
|| !allowed_usage.contains(crate::GlobalUse::WRITE)
{
return Err(EntryPointError::InvalidBuiltIn(built_in));
}
@@ -557,21 +557,21 @@ impl Validator {
Some(crate::Binding::Resource { .. }) => unreachable!(),
None => (),
}
crate::GlobalUse::LOAD | crate::GlobalUse::STORE
crate::GlobalUse::READ | crate::GlobalUse::WRITE
}
crate::StorageClass::Uniform => crate::GlobalUse::LOAD,
crate::StorageClass::Uniform => crate::GlobalUse::READ,
crate::StorageClass::Storage => storage_usage(var.storage_access),
crate::StorageClass::Handle => match module.types[var.ty].inner {
crate::TypeInner::Image {
class: crate::ImageClass::Storage(_),
..
} => storage_usage(var.storage_access),
_ => crate::GlobalUse::LOAD,
_ => crate::GlobalUse::READ,
},
crate::StorageClass::Private | crate::StorageClass::WorkGroup => {
crate::GlobalUse::all()
}
crate::StorageClass::PushConstant => crate::GlobalUse::LOAD,
crate::StorageClass::PushConstant => crate::GlobalUse::READ,
};
if !allowed_usage.contains(usage) {
log::warn!("\tUsage error for: {:?}", var);