Skip to content

Commit

Permalink
[glsl-out] split reflection_names into a map for types and another fo…
Browse files Browse the repository at this point in the history
…r globals (gfx-rs#1144)

* split reflection_names into a map for types and another for globals

* reflection_names_structs -> reflection_names_uniforms
  • Loading branch information
jakobhellermann authored and JCapucho committed Jul 30, 2021
1 parent de0647a commit 42c2e99
Showing 1 changed file with 9 additions and 7 deletions.
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();
uniforms.insert(handle, name);
}
_ => (),
Expand Down

0 comments on commit 42c2e99

Please sign in to comment.