[naga] Delete Constant::override and Override.

This commit is contained in:
Jim Blandy 2023-12-06 16:07:15 -08:00 committed by Teodor Tanasoaia
parent 3bda381812
commit b3dfc40c9d
11 changed files with 7 additions and 115 deletions

View File

@ -557,7 +557,6 @@ fn constants() {
constants.next().unwrap().1,
&Constant {
name: Some("a".to_owned()),
r#override: crate::Override::None,
ty: ty_handle,
init: init_handle
}
@ -567,7 +566,6 @@ fn constants() {
constants.next().unwrap().1,
&Constant {
name: Some("b".to_owned()),
r#override: crate::Override::None,
ty: ty_handle,
init: init_handle
}

View File

@ -472,7 +472,6 @@ impl Frontend {
let constant = Constant {
name: name.clone(),
r#override: crate::Override::None,
ty,
init,
};

View File

@ -196,7 +196,6 @@ struct Decoration {
location: Option<spirv::Word>,
desc_set: Option<spirv::Word>,
desc_index: Option<spirv::Word>,
specialization: Option<spirv::Word>,
storage_buffer: bool,
offset: Option<spirv::Word>,
array_stride: Option<NonZeroU32>,
@ -216,11 +215,6 @@ impl Decoration {
}
}
fn specialization(&self) -> crate::Override {
self.specialization
.map_or(crate::Override::None, crate::Override::ByNameOrId)
}
const fn resource_binding(&self) -> Option<crate::ResourceBinding> {
match *self {
Decoration {
@ -756,9 +750,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
spirv::Decoration::RowMajor => {
dec.matrix_major = Some(Majority::Row);
}
spirv::Decoration::SpecId => {
dec.specialization = Some(self.next()?);
}
other => {
log::warn!("Unknown decoration {:?}", other);
for _ in base_words + 1..inst.wc {
@ -4931,7 +4922,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
@ -4982,7 +4972,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
@ -5017,7 +5006,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
.append(crate::Expression::ZeroValue(ty), span);
let handle = module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
@ -5056,7 +5044,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,

View File

@ -956,7 +956,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let handle = ctx.module.constants.append(
crate::Constant {
name: Some(c.name.name.to_string()),
r#override: crate::Override::None,
ty,
init,
},

View File

@ -175,7 +175,7 @@ tree.
A Naga *constant expression* is one of the following [`Expression`]
variants, whose operands (if any) are also constant expressions:
- [`Literal`]
- [`Constant`], for [`Constant`s][const_type] whose [`override`] is [`None`]
- [`Constant`], for [`Constant`s][const_type] whose `override` is `None`
- [`ZeroValue`], for fixed-size types
- [`Compose`]
- [`Access`]
@ -195,7 +195,7 @@ A constant expression can be evaluated at module translation time.
A Naga *override expression* is the same as a [constant expression],
except that it is also allowed to refer to [`Constant`s][const_type]
whose [`override`] is something other than [`None`].
whose `override` is something other than `None`.
An override expression can be evaluated at pipeline creation time.
@ -239,8 +239,6 @@ An override expression can be evaluated at pipeline creation time.
[`As`]: Expression::As
[const_type]: Constant
[`override`]: Constant::override
[`None`]: Override::None
[constant expression]: index.html#constant-expressions
*/
@ -892,17 +890,6 @@ pub enum Literal {
AbstractFloat(f64),
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "clone", derive(Clone))]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub enum Override {
None,
ByName,
ByNameOrId(u32),
}
/// Constant value.
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "clone", derive(Clone))]
@ -911,7 +898,6 @@ pub enum Override {
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct Constant {
pub name: Option<String>,
pub r#override: Override,
pub ty: Handle<Type>,
/// The value of the constant.
@ -919,12 +905,10 @@ pub struct Constant {
/// This [`Handle`] refers to [`Module::const_expressions`], not
/// any [`Function::expressions`] arena.
///
/// If [`override`] is [`None`], then this must be a Naga
/// If `override` is `None`, then this must be a Naga
/// [constant expression]. Otherwise, this may be a Naga
/// [override expression] or [constant expression].
///
/// [`override`]: Constant::override
/// [`None`]: Override::None
/// [constant expression]: index.html#constant-expressions
/// [override expression]: index.html#override-expressions
pub init: Handle<Expression>,

View File

@ -2059,7 +2059,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: scalar_ty,
init: const_expressions
.append(Expression::Literal(Literal::I32(4)), Default::default()),
@ -2070,7 +2069,6 @@ mod tests {
let h1 = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: scalar_ty,
init: const_expressions
.append(Expression::Literal(Literal::I32(8)), Default::default()),
@ -2081,7 +2079,6 @@ mod tests {
let vec_h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: vec_ty,
init: const_expressions.append(
Expression::Compose {
@ -2180,7 +2177,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: scalar_ty,
init: const_expressions
.append(Expression::Literal(Literal::I32(4)), Default::default()),
@ -2267,7 +2263,6 @@ mod tests {
let vec1 = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: vec_ty,
init: const_expressions.append(
Expression::Compose {
@ -2283,7 +2278,6 @@ mod tests {
let vec2 = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: vec_ty,
init: const_expressions.append(
Expression::Compose {
@ -2299,7 +2293,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: matrix_ty,
init: const_expressions.append(
Expression::Compose {
@ -2395,7 +2388,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: i32_ty,
init: const_expressions
.append(Expression::Literal(Literal::I32(4)), Default::default()),
@ -2475,7 +2467,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: i32_ty,
init: const_expressions
.append(Expression::Literal(Literal::I32(4)), Default::default()),

View File

@ -553,13 +553,9 @@ impl crate::Expression {
///
/// [`Access`]: crate::Expression::Access
/// [`ResolveContext`]: crate::proc::ResolveContext
pub fn is_dynamic_index(&self, module: &crate::Module) -> bool {
pub const fn is_dynamic_index(&self) -> bool {
match *self {
Self::Literal(_) | Self::ZeroValue(_) => false,
Self::Constant(handle) => {
let constant = &module.constants[handle];
!matches!(constant.r#override, crate::Override::None)
}
Self::Literal(_) | Self::ZeroValue(_) | Self::Constant(_) => false,
_ => true,
}
}

View File

@ -252,9 +252,7 @@ impl super::Validator {
return Err(ExpressionError::InvalidIndexType(index));
}
}
if dynamic_indexing_restricted
&& function.expressions[index].is_dynamic_index(module)
{
if dynamic_indexing_restricted && function.expressions[index].is_dynamic_index() {
return Err(ExpressionError::IndexMustBeConstant(base));
}

View File

@ -76,12 +76,7 @@ impl super::Validator {
|handle| Self::validate_expression_handle(handle, const_expressions);
for (_handle, constant) in constants.iter() {
let &crate::Constant {
name: _,
r#override: _,
ty,
init,
} = constant;
let &crate::Constant { name: _, ty, init } = constant;
validate_type(ty)?;
validate_const_expr(init)?;
}
@ -679,7 +674,6 @@ fn constant_deps() {
let self_referential_const = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: i32_handle,
init: fun_expr,
},

View File

@ -159,115 +159,96 @@
constants: [
(
name: None,
override: None,
ty: 1,
init: 1,
),
(
name: None,
override: None,
ty: 1,
init: 2,
),
(
name: None,
override: None,
ty: 1,
init: 3,
),
(
name: None,
override: None,
ty: 1,
init: 4,
),
(
name: None,
override: None,
ty: 1,
init: 5,
),
(
name: None,
override: None,
ty: 2,
init: 9,
),
(
name: None,
override: None,
ty: 3,
init: 10,
),
(
name: None,
override: None,
ty: 3,
init: 11,
),
(
name: None,
override: None,
ty: 3,
init: 12,
),
(
name: None,
override: None,
ty: 7,
init: 13,
),
(
name: None,
override: None,
ty: 7,
init: 14,
),
(
name: None,
override: None,
ty: 7,
init: 15,
),
(
name: None,
override: None,
ty: 7,
init: 16,
),
(
name: None,
override: None,
ty: 7,
init: 17,
),
(
name: None,
override: None,
ty: 7,
init: 18,
),
(
name: None,
override: None,
ty: 7,
init: 19,
),
(
name: None,
override: None,
ty: 7,
init: 20,
),
(
name: None,
override: None,
ty: 7,
init: 21,
),
(
name: None,
override: None,
ty: 7,
init: 22,
),

View File

@ -282,211 +282,176 @@
constants: [
(
name: None,
override: None,
ty: 1,
init: 1,
),
(
name: None,
override: None,
ty: 1,
init: 2,
),
(
name: None,
override: None,
ty: 1,
init: 3,
),
(
name: None,
override: None,
ty: 1,
init: 4,
),
(
name: None,
override: None,
ty: 1,
init: 5,
),
(
name: None,
override: None,
ty: 2,
init: 9,
),
(
name: None,
override: None,
ty: 3,
init: 10,
),
(
name: None,
override: None,
ty: 3,
init: 11,
),
(
name: None,
override: None,
ty: 3,
init: 12,
),
(
name: None,
override: None,
ty: 1,
init: 13,
),
(
name: None,
override: None,
ty: 9,
init: 14,
),
(
name: None,
override: None,
ty: 9,
init: 15,
),
(
name: None,
override: None,
ty: 9,
init: 16,
),
(
name: None,
override: None,
ty: 9,
init: 17,
),
(
name: None,
override: None,
ty: 9,
init: 18,
),
(
name: None,
override: None,
ty: 9,
init: 19,
),
(
name: None,
override: None,
ty: 9,
init: 20,
),
(
name: None,
override: None,
ty: 9,
init: 21,
),
(
name: None,
override: None,
ty: 9,
init: 22,
),
(
name: None,
override: None,
ty: 9,
init: 23,
),
(
name: None,
override: None,
ty: 9,
init: 24,
),
(
name: None,
override: None,
ty: 9,
init: 25,
),
(
name: None,
override: None,
ty: 9,
init: 26,
),
(
name: None,
override: None,
ty: 9,
init: 27,
),
(
name: None,
override: None,
ty: 9,
init: 28,
),
(
name: None,
override: None,
ty: 9,
init: 29,
),
(
name: None,
override: None,
ty: 9,
init: 30,
),
(
name: None,
override: None,
ty: 9,
init: 31,
),
(
name: None,
override: None,
ty: 9,
init: 32,
),
(
name: None,
override: None,
ty: 9,
init: 33,
),
(
name: None,
override: None,
ty: 9,
init: 34,
),
(
name: None,
override: None,
ty: 9,
init: 35,
),
(
name: None,
override: None,
ty: 9,
init: 36,
),
(
name: None,
override: None,
ty: 9,
init: 37,
),
(
name: None,
override: None,
ty: 9,
init: 38,
),