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

[naga] Delete Constant::override and Override. #4845

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -197,7 +197,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 @@ -217,11 +216,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 @@ -753,9 +747,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 @@ -4919,7 +4910,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 @@ -4970,7 +4960,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 @@ -5005,7 +4994,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 @@ -5044,7 +5032,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 @@ -924,7 +924,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: inferred_type,
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 @@ -873,17 +871,6 @@ pub enum Literal {
Bool(bool),
}

#[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 @@ -892,20 +879,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 @@ -1360,7 +1360,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 @@ -1371,7 +1370,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 @@ -1382,7 +1380,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 @@ -1481,7 +1478,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 @@ -1568,7 +1564,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 @@ -1584,7 +1579,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 @@ -1600,7 +1594,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 @@ -1696,7 +1689,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 @@ -1776,7 +1768,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 @@ -509,13 +509,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
Loading