Skip to content

Commit

Permalink
Handle empty variable names in namer (#1484)
Browse files Browse the repository at this point in the history
* Handle empty variable names in namer

* Add glsl-in test with empty global name
  • Loading branch information
Gordon-F authored and kvark committed Dec 2, 2021
1 parent 870521c commit 469ebc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/proc/namer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ impl Namer {

pub fn call_or(&mut self, label: &Option<String>, fallback: &str) -> String {
self.call(match *label {
Some(ref name) => name,
Some(ref name) => {
if name.trim().is_empty() {
fallback
} else {
name
}
}
None => fallback,
})
}
Expand Down
7 changes: 7 additions & 0 deletions tests/in/glsl/empty-global-name.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
layout(set = 1, binding = 1) uniform TextureData {
vec4 material;
};

void main() {
vec2 coords = vec2(material.xy);
}
21 changes: 21 additions & 0 deletions tests/out/wgsl/empty-global-name-frag.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[block]]
struct TextureData {
material: vec4<f32>;
};

[[group(1), binding(1)]]
var<uniform> global: TextureData;

fn main1() {
var coords: vec2<f32>;

let e2: vec4<f32> = global.material;
coords = vec2<f32>(e2.xy);
return;
}

[[stage(fragment)]]
fn main() {
main1();
return;
}

0 comments on commit 469ebc0

Please sign in to comment.