Skip to content

Commit

Permalink
[naga] Delete Constant::override and Override.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy authored and teoxoy committed Jan 8, 2024
1 parent a0d9da5 commit 03153af
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 115 deletions.
2 changes: 0 additions & 2 deletions naga/src/front/glsl/parser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ fn constants() {
constants.next().unwrap().1,
&Constant {
name: Some("a".to_owned()),
r#override: crate::Override::None,
ty: ty_handle,
init: init_handle
}
Expand All @@ -557,7 +556,6 @@ fn constants() {
constants.next().unwrap().1,
&Constant {
name: Some("b".to_owned()),
r#override: crate::Override::None,
ty: ty_handle,
init: init_handle
}
Expand Down
1 change: 0 additions & 1 deletion naga/src/front/glsl/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ impl Frontend {

let constant = Constant {
name: name.clone(),
r#override: crate::Override::None,
ty,
init,
};
Expand Down
13 changes: 0 additions & 13 deletions naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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 {
Expand Down Expand Up @@ -752,9 +746,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 {
Expand Down Expand Up @@ -4918,7 +4909,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
Expand Down Expand Up @@ -4969,7 +4959,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
Expand Down Expand Up @@ -5004,7 +4993,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,
Expand Down Expand Up @@ -5043,7 +5031,6 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
LookupConstant {
handle: module.constants.append(
crate::Constant {
r#override: decor.specialization(),
name: decor.name,
ty,
init,
Expand Down
1 change: 0 additions & 1 deletion naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
22 changes: 3 additions & 19 deletions naga/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand All @@ -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.
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -888,17 +886,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))]
Expand All @@ -907,20 +894,17 @@ 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.
///
/// 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>,
Expand Down
9 changes: 0 additions & 9 deletions naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,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()),
Expand All @@ -1650,7 +1649,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()),
Expand All @@ -1661,7 +1659,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 {
Expand Down Expand Up @@ -1760,7 +1757,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()),
Expand Down Expand Up @@ -1847,7 +1843,6 @@ mod tests {
let vec1 = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: vec_ty,
init: const_expressions.append(
Expression::Compose {
Expand All @@ -1863,7 +1858,6 @@ mod tests {
let vec2 = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: vec_ty,
init: const_expressions.append(
Expression::Compose {
Expand All @@ -1879,7 +1873,6 @@ mod tests {
let h = constants.append(
Constant {
name: None,
r#override: crate::Override::None,
ty: matrix_ty,
init: const_expressions.append(
Expression::Compose {
Expand Down Expand Up @@ -1975,7 +1968,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()),
Expand Down Expand Up @@ -2055,7 +2047,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()),
Expand Down
8 changes: 2 additions & 6 deletions naga/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,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,
}
}
Expand Down
4 changes: 1 addition & 3 deletions naga/src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,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));
}

Expand Down
8 changes: 1 addition & 7 deletions naga/src/valid/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -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,
},
Expand Down
19 changes: 0 additions & 19 deletions naga/tests/out/ir/shadow.compact.ron
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
Loading

0 comments on commit 03153af

Please sign in to comment.