Skip to content

Commit

Permalink
Remove unnecessary "gl_PerVertex" name check so unused builtins will be
Browse files Browse the repository at this point in the history
handled even when this name is not in the input SPIRV.
  • Loading branch information
Imberflur committed Feb 9, 2024
1 parent 5ea1601 commit 9577d9b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
47 changes: 23 additions & 24 deletions naga/src/front/spv/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,34 +376,33 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {
// See the docs for `Frontend::gl_per_vertex_builtin_access`.
{
let ty = &module.types[result.ty];
match ty.inner {
crate::TypeInner::Struct {
members: ref original_members,
span,
} if ty.name.as_deref() == Some("gl_PerVertex") => {
let mut new_members = original_members.clone();
for member in &mut new_members {
if let Some(crate::Binding::BuiltIn(built_in)) = member.binding
{
if !self.gl_per_vertex_builtin_access.contains(&built_in) {
member.binding = None
}
if let crate::TypeInner::Struct {
members: ref original_members,
span,
} = ty.inner
{
let mut new_members = None;
for (idx, member) in original_members.iter().enumerate() {
if let Some(crate::Binding::BuiltIn(built_in)) = member.binding {
if !self.gl_per_vertex_builtin_access.contains(&built_in) {
new_members
.get_or_insert_with(|| original_members.clone())[idx]
.binding = None;
}
}
if &new_members != original_members {
module.types.replace(
result.ty,
crate::Type {
name: ty.name.clone(),
inner: crate::TypeInner::Struct {
members: new_members,
span,
},
}
if let Some(new_members) = new_members {
module.types.replace(
result.ty,
crate::Type {
name: ty.name.clone(),
inner: crate::TypeInner::Struct {
members: new_members,
span,
},
);
}
},
);
}
_ => {}
}
}

Expand Down
10 changes: 4 additions & 6 deletions naga/src/front/spv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,12 +1562,10 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
span,
);

if ty.name.as_deref() == Some("gl_PerVertex") {
if let Some(crate::Binding::BuiltIn(built_in)) =
members[index as usize].binding
{
self.gl_per_vertex_builtin_access.insert(built_in);
}
if let Some(crate::Binding::BuiltIn(built_in)) =
members[index as usize].binding
{
self.gl_per_vertex_builtin_access.insert(built_in);
}

AccessExpression {
Expand Down

0 comments on commit 9577d9b

Please sign in to comment.