Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

[glsl-out] ImageMultipleSamplers error for multiple samplers due to name collision #1137

Closed
jakobhellermann opened this issue Jul 25, 2021 · 2 comments · Fixed by #1144
Closed
Labels
area: back-end Outputs of shader conversion help wanted Extra attention is needed kind: bug Something isn't working

Comments

@jakobhellermann
Copy link
Contributor

jakobhellermann commented Jul 25, 2021

Given the WGSL code

[[group(0), binding(1)]]
var texture_a: texture_2d<f32>;
[[group(0), binding(2)]]
var sampler_a: sampler;
[[group(0), binding(3)]]
var texture_b: texture_2d<f32>;
[[group(0), binding(4)]]
var sampler_b: sampler;

[[stage(fragment)]]
fn main() -> [[location(0)]] vec4<f32> {
    let a = textureSample(texture_a, sampler_a, vec2<f32>(0.0));
    let b = textureSample(texture_b, sampler_b, vec2<f32>(0.0));
    return vec4<f32>(1.0);
}

naga fails to convert it to GLSL due to Conflicting samplers for _group_0_binding_3.

The relevant code is here

naga/src/back/glsl/mod.rs

Lines 2441 to 2457 in 526a29e

let global = self.module.global_variables[sampling.image].clone();
let tex_name = self.reflection_names[&global.ty].clone();
match mappings.entry(tex_name) {
Entry::Vacant(v) => {
v.insert(TextureMapping {
texture: sampling.image,
sampler: Some(sampling.sampler),
});
}
Entry::Occupied(e) => {
if e.get().sampler != Some(sampling.sampler) {
log::error!("Conflicting samplers for {}", e.key());
return Err(Error::ImageMultipleSamplers);
}
}
}

Logging the global and tex_name values gives to

GlobalVariable { name: Some("texture_a"), class: Handle, binding: Some(ResourceBinding { group: 0, binding: 1 }), ty: [1], init: None, storage_access: (empty) }
_group_0_binding_3
GlobalVariable { name: Some("texture_b"), class: Handle, binding: Some(ResourceBinding { group: 0, binding: 3 }), ty: [1], init: None, storage_access: (empty) }
_group_0_binding_3

The tex_name is looked up using only the global's ty which is the same for both both textures.

@kvark kvark added area: back-end Outputs of shader conversion help wanted Extra attention is needed kind: bug Something isn't working labels Jul 26, 2021
@Gordon-F
Copy link
Collaborator

Hello @jakobhellermann! Thank you for reporting this. Would you like to send a PR with a fix?

@jakobhellermann
Copy link
Contributor Author

I opened a PR: #1144

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: back-end Outputs of shader conversion help wanted Extra attention is needed kind: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants