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

[glsl-out] split reflection_names into a map for types and another for globals #1144

Merged
merged 2 commits into from
Jul 29, 2021
Merged
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
16 changes: 9 additions & 7 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ pub struct Writer<'a, W> {
/// (generated by a [`Namer`](crate::proc::Namer))
names: crate::FastHashMap<NameKey, String>,
/// A map with all the names needed for reflections
reflection_names: crate::FastHashMap<Handle<crate::Type>, String>,
reflection_names_uniforms: crate::FastHashMap<Handle<crate::Type>, String>,
/// A map with the names of global variables needed for reflections
reflection_names_globals: crate::FastHashMap<Handle<crate::GlobalVariable>, String>,
/// The selected entry point
entry_point: &'a crate::EntryPoint,
/// The index of the selected entry point
Expand Down Expand Up @@ -366,7 +368,8 @@ impl<'a, W: Write> Writer<'a, W> {
namer,
features: FeaturesManager::new(),
names,
reflection_names: crate::FastHashMap::default(),
reflection_names_uniforms: crate::FastHashMap::default(),
reflection_names_globals: crate::FastHashMap::default(),
entry_point: &module.entry_points[ep_idx],
entry_point_idx: ep_idx as u16,

Expand Down Expand Up @@ -549,7 +552,7 @@ impl<'a, W: Write> Writer<'a, W> {
writeln!(self.out, " {};", global_name)?;
writeln!(self.out)?;

self.reflection_names.insert(global.ty, global_name);
self.reflection_names_globals.insert(handle, global_name);
}
// glsl has no concept of samplers so we just ignore it
TypeInner::Sampler { .. } => continue,
Expand Down Expand Up @@ -1236,7 +1239,7 @@ impl<'a, W: Write> Writer<'a, W> {
);
writeln!(self.out, "{} {{", block_name)?;

self.reflection_names.insert(handle, block_name);
self.reflection_names_uniforms.insert(handle, block_name);
} else {
writeln!(self.out, "struct {} {{", name)?;
}
Expand Down Expand Up @@ -2445,8 +2448,7 @@ impl<'a, W: Write> Writer<'a, W> {
let mut uniforms = crate::FastHashMap::default();

for sampling in info.sampling_set.iter() {
let global = self.module.global_variables[sampling.image].clone();
let tex_name = self.reflection_names[&global.ty].clone();
let tex_name = self.reflection_names_globals[&sampling.image].clone();

match mappings.entry(tex_name) {
Entry::Vacant(v) => {
Expand All @@ -2471,7 +2473,7 @@ impl<'a, W: Write> Writer<'a, W> {
match self.module.types[var.ty].inner {
crate::TypeInner::Struct { .. } => match var.class {
crate::StorageClass::Uniform | crate::StorageClass::Storage { .. } => {
let name = self.reflection_names[&var.ty].clone();
let name = self.reflection_names_uniforms[&var.ty].clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we looking up var.ty instead of looking up handle directly in that other map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is because the write_struct function, where reflection_names_uniforms.insert is called, has no access to the global variable handle, only the type handle.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we need a block struct name, that will be generated as uniform buffer.

naga/src/back/glsl/mod.rs

Lines 1233 to 1239 in ab2fa43

let block_name = format!(
"{}_block_{}{}",
name,
self.block_id.generate(),
stage_postfix
);
writeln!(self.out, "{} {{", block_name)?;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we will use the global variable handle here, we still need to check the variable type and ensure that the variable is a struct with a uniform storage class.

If we want to change this, we need to change block struct writing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I see. So the block name shows up in the API, not the variable name, and the block name comes from the type. Ok

uniforms.insert(handle, name);
}
_ => (),
Expand Down