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

Conversation

jakobhellermann
Copy link
Contributor

fixes #1137, not sure whether this is the right approach

The issue in #1137 was that the reflection_names map was per type but different globals shared the same type, so the first one got overwritten.
This PR splits the reflection_names into a map of Handle<GlobalVariable> => String and the old Handle<Type> => String.

I'm not sure if the globals map is even needed though, because the usage here could just be let tex_name = self.get_global_name(handle, global) and the global map could be removed.

The last change to this code was in #606, @Gordon-F can you take a look and comment on which approach you think is best?

@zicklag
Copy link
Contributor

zicklag commented Jul 27, 2021

This fixes the WGPU Bevy problem I ran into! ❤️ Thanks!

Copy link
Collaborator

@Gordon-F Gordon-F left a comment

Choose a reason for hiding this comment

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

@jakobhellermann Thank you! LGTM.

@@ -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_structs: crate::FastHashMap<Handle<crate::Type>, String>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe reflection_names_buffers or reflection_names_uniforms?

Copy link
Member

Choose a reason for hiding this comment

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

why do we ever need to reflect the type names? they shouldn't be exposed anywhere in the GL API

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need names only for uniforms here - https://github.com/gfx-rs/wgpu/blob/master/wgpu-hal/src/gles/device.rs#L38.

they shouldn't be exposed anywhere in the GL API

Performance? We already got this info.

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 renamed it to reflection_names_uniforms.

Copy link
Member

Choose a reason for hiding this comment

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

@Gordon-F that lookup goes with a variable handle, not a type handle. I'm asking why we need to look up any reflection based on the type.

@@ -2455,7 +2457,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

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

let's rebase and land this

@jakobhellermann
Copy link
Contributor Author

jakobhellermann commented Jul 28, 2021

let's rebase and land this

I rebased the PR.

@kvark kvark merged commit fa05f0d into gfx-rs:master Jul 29, 2021
@jakobhellermann jakobhellermann deleted the fix-duplicate-sampler branch July 29, 2021 06:43
JCapucho pushed a commit to JCapucho/naga that referenced this pull request Aug 1, 2021
…r globals (gfx-rs#1144)

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

* reflection_names_structs -> reflection_names_uniforms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[glsl-out] ImageMultipleSamplers error for multiple samplers due to name collision
4 participants