Skip to content

Commit

Permalink
[glsl-out] Add stage postfix to generated global name
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Shaposhnik committed Dec 23, 2021
1 parent 924ab17 commit 7397407
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Cargo.lock
/*.vert
/*.frag
/*.comp
/*.wgsl
25 changes: 23 additions & 2 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ impl fmt::Display for VaryingName<'_> {
}
}

impl ShaderStage {
fn to_str(self) -> &'static str {
match self {
ShaderStage::Compute => "cs",
ShaderStage::Fragment => "fs",
ShaderStage::Vertex => "vs",
}
}
}

/// Shorthand result used internally by the backend
type BackendResult<T = ()> = Result<T, Error>;

Expand Down Expand Up @@ -961,7 +971,12 @@ impl<'a, W: Write> Writer<'a, W> {
) -> String {
match global.binding {
Some(ref br) => {
format!("_group_{}_binding_{}", br.group, br.binding)
format!(
"_group_{}_binding_{}_{}",
br.group,
br.binding,
self.entry_point.stage.to_str()
)
}
None => self.names[&NameKey::GlobalVariable(handle)].clone(),
}
Expand All @@ -974,7 +989,13 @@ impl<'a, W: Write> Writer<'a, W> {
global: &crate::GlobalVariable,
) -> BackendResult {
match global.binding {
Some(ref br) => write!(self.out, "_group_{}_binding_{}", br.group, br.binding)?,
Some(ref br) => write!(
self.out,
"_group_{}_binding_{}_{}",
br.group,
br.binding,
self.entry_point.stage.to_str()
)?,
None => write!(
self.out,
"{}",
Expand Down
22 changes: 11 additions & 11 deletions tests/out/glsl/access.atomics.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ layout(std430) buffer Bar_block_0Compute {
int atom;
uvec2 arr[2];
int data[];
} _group_0_binding_0;
} _group_0_binding_0_cs;


float read_from_private(inout float foo_2) {
Expand All @@ -20,24 +20,24 @@ float read_from_private(inout float foo_2) {

void main() {
int tmp = 0;
int value = _group_0_binding_0.atom;
int _e6 = atomicAdd(_group_0_binding_0.atom, 5);
int value = _group_0_binding_0_cs.atom;
int _e6 = atomicAdd(_group_0_binding_0_cs.atom, 5);
tmp = _e6;
int _e9 = atomicAdd(_group_0_binding_0.atom, -5);
int _e9 = atomicAdd(_group_0_binding_0_cs.atom, -5);
tmp = _e9;
int _e12 = atomicAnd(_group_0_binding_0.atom, 5);
int _e12 = atomicAnd(_group_0_binding_0_cs.atom, 5);
tmp = _e12;
int _e15 = atomicOr(_group_0_binding_0.atom, 5);
int _e15 = atomicOr(_group_0_binding_0_cs.atom, 5);
tmp = _e15;
int _e18 = atomicXor(_group_0_binding_0.atom, 5);
int _e18 = atomicXor(_group_0_binding_0_cs.atom, 5);
tmp = _e18;
int _e21 = atomicMin(_group_0_binding_0.atom, 5);
int _e21 = atomicMin(_group_0_binding_0_cs.atom, 5);
tmp = _e21;
int _e24 = atomicMax(_group_0_binding_0.atom, 5);
int _e24 = atomicMax(_group_0_binding_0_cs.atom, 5);
tmp = _e24;
int _e27 = atomicExchange(_group_0_binding_0.atom, 5);
int _e27 = atomicExchange(_group_0_binding_0_cs.atom, 5);
tmp = _e27;
_group_0_binding_0.atom = value;
_group_0_binding_0_cs.atom = value;
return;
}

18 changes: 9 additions & 9 deletions tests/out/glsl/access.foo.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ layout(std430) buffer Bar_block_0Vertex {
int atom;
uvec2 arr[2];
int data[];
} _group_0_binding_0;
} _group_0_binding_0_vs;


float read_from_private(inout float foo_2) {
Expand All @@ -22,15 +22,15 @@ void main() {
int c[5];
float baz = foo_1;
foo_1 = 1.0;
mat4x4 matrix = _group_0_binding_0.matrix;
uvec2 arr[2] = _group_0_binding_0.arr;
float b = _group_0_binding_0.matrix[3][0];
int a = _group_0_binding_0.data[(uint(_group_0_binding_0.data.length()) - 2u)];
mat4x4 matrix = _group_0_binding_0_vs.matrix;
uvec2 arr[2] = _group_0_binding_0_vs.arr;
float b = _group_0_binding_0_vs.matrix[3][0];
int a = _group_0_binding_0_vs.data[(uint(_group_0_binding_0_vs.data.length()) - 2u)];
float _e25 = read_from_private(foo_1);
_group_0_binding_0.matrix[1][2] = 1.0;
_group_0_binding_0.matrix = mat4x4(vec4(0.0), vec4(1.0), vec4(2.0), vec4(3.0));
_group_0_binding_0.arr = uvec2[2](uvec2(0u), uvec2(1u));
_group_0_binding_0.data[1] = 1;
_group_0_binding_0_vs.matrix[1][2] = 1.0;
_group_0_binding_0_vs.matrix = mat4x4(vec4(0.0), vec4(1.0), vec4(2.0), vec4(3.0));
_group_0_binding_0_vs.arr = uvec2[2](uvec2(0u), uvec2(1u));
_group_0_binding_0_vs.data[1] = 1;
c = int[5](a, int(b), 3, 4, 5);
c[(vi + 1u)] = 42;
int value = c[vi];
Expand Down
32 changes: 16 additions & 16 deletions tests/out/glsl/boids.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ struct SimParams {
float rule2Scale;
float rule3Scale;
};
uniform SimParams_block_0Compute { SimParams _group_0_binding_0; };
uniform SimParams_block_0Compute { SimParams _group_0_binding_0_cs; };

layout(std430) readonly buffer Particles_block_1Compute {
Particle particles[];
} _group_0_binding_1;
} _group_0_binding_1_cs;

layout(std430) buffer Particles_block_2Compute {
Particle particles[];
} _group_0_binding_2;
} _group_0_binding_2_cs;


void main() {
Expand All @@ -45,9 +45,9 @@ void main() {
if ((index >= 1500u)) {
return;
}
vec2 _e10 = _group_0_binding_1.particles[index].pos;
vec2 _e10 = _group_0_binding_1_cs.particles[index].pos;
vPos = _e10;
vec2 _e15 = _group_0_binding_1.particles[index].vel;
vec2 _e15 = _group_0_binding_1_cs.particles[index].vel;
vVel = _e15;
cMass = vec2(0.0, 0.0);
cVel = vec2(0.0, 0.0);
Expand All @@ -68,14 +68,14 @@ void main() {
continue;
}
uint _e42 = i;
vec2 _e45 = _group_0_binding_1.particles[_e42].pos;
vec2 _e45 = _group_0_binding_1_cs.particles[_e42].pos;
pos = _e45;
uint _e47 = i;
vec2 _e50 = _group_0_binding_1.particles[_e47].vel;
vec2 _e50 = _group_0_binding_1_cs.particles[_e47].vel;
vel = _e50;
vec2 _e51 = pos;
vec2 _e52 = vPos;
float _e55 = _group_0_binding_0.rule1Distance;
float _e55 = _group_0_binding_0_cs.rule1Distance;
if ((distance(_e51, _e52) < _e55)) {
vec2 _e57 = cMass;
vec2 _e58 = pos;
Expand All @@ -85,7 +85,7 @@ void main() {
}
vec2 _e63 = pos;
vec2 _e64 = vPos;
float _e67 = _group_0_binding_0.rule2Distance;
float _e67 = _group_0_binding_0_cs.rule2Distance;
if ((distance(_e63, _e64) < _e67)) {
vec2 _e69 = colVel;
vec2 _e70 = pos;
Expand All @@ -94,7 +94,7 @@ void main() {
}
vec2 _e74 = pos;
vec2 _e75 = vPos;
float _e78 = _group_0_binding_0.rule3Distance;
float _e78 = _group_0_binding_0_cs.rule3Distance;
if ((distance(_e74, _e75) < _e78)) {
vec2 _e80 = cVel;
vec2 _e81 = vel;
Expand All @@ -118,18 +118,18 @@ void main() {
}
vec2 _e107 = vVel;
vec2 _e108 = cMass;
float _e110 = _group_0_binding_0.rule1Scale;
float _e110 = _group_0_binding_0_cs.rule1Scale;
vec2 _e113 = colVel;
float _e115 = _group_0_binding_0.rule2Scale;
float _e115 = _group_0_binding_0_cs.rule2Scale;
vec2 _e118 = cVel;
float _e120 = _group_0_binding_0.rule3Scale;
float _e120 = _group_0_binding_0_cs.rule3Scale;
vVel = (((_e107 + (_e108 * _e110)) + (_e113 * _e115)) + (_e118 * _e120));
vec2 _e123 = vVel;
vec2 _e125 = vVel;
vVel = (normalize(_e123) * clamp(length(_e125), 0.0, 0.10000000149011612));
vec2 _e131 = vPos;
vec2 _e132 = vVel;
float _e134 = _group_0_binding_0.deltaT;
float _e134 = _group_0_binding_0_cs.deltaT;
vPos = (_e131 + (_e132 * _e134));
float _e138 = vPos.x;
if ((_e138 < -1.0)) {
Expand All @@ -148,9 +148,9 @@ void main() {
vPos.y = -1.0;
}
vec2 _e164 = vPos;
_group_0_binding_2.particles[index].pos = _e164;
_group_0_binding_2_cs.particles[index].pos = _e164;
vec2 _e168 = vVel;
_group_0_binding_2.particles[index].vel = _e168;
_group_0_binding_2_cs.particles[index].vel = _e168;
return;
}

4 changes: 2 additions & 2 deletions tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
precision highp float;
precision highp int;

uniform highp samplerCubeArrayShadow _group_0_binding_4;
uniform highp samplerCubeArrayShadow _group_0_binding_4_fs;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
vec3 frag_ls = vec4(1.0, 1.0, 2.0, 1.0).xyz;
float a = texture(_group_0_binding_4, vec4(frag_ls, int(1)), 1.0);
float a = texture(_group_0_binding_4_fs, vec4(frag_ls, int(1)), 1.0);
_fs2p_location0 = vec4(a, 1.0, 1.0, 1.0);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/out/glsl/image.gather.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
precision highp float;
precision highp int;

uniform highp sampler2D _group_0_binding_1;
uniform highp sampler2D _group_0_binding_1_fs;

uniform highp sampler2DShadow _group_1_binding_2;
uniform highp sampler2DShadow _group_1_binding_2_fs;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
vec2 tc = vec2(0.5);
vec4 s2d = textureGather(_group_0_binding_1, vec2(tc), 1);
vec4 s2d_offset = textureGatherOffset(_group_0_binding_1, vec2(tc), ivec2(3, 1), 3);
vec4 s2d_depth = textureGather(_group_1_binding_2, vec2(tc), 0.5);
vec4 s2d_depth_offset = textureGatherOffset(_group_1_binding_2, vec2(tc), 0.5, ivec2(3, 1));
vec4 s2d = textureGather(_group_0_binding_1_fs, vec2(tc), 1);
vec4 s2d_offset = textureGatherOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1), 3);
vec4 s2d_depth = textureGather(_group_1_binding_2_fs, vec2(tc), 0.5);
vec4 s2d_depth_offset = textureGatherOffset(_group_1_binding_2_fs, vec2(tc), 0.5, ivec2(3, 1));
_fs2p_location0 = (((s2d + s2d_offset) + s2d_depth) + s2d_depth_offset);
return;
}
Expand Down
22 changes: 11 additions & 11 deletions tests/out/glsl/image.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ precision highp int;

layout(local_size_x = 16, local_size_y = 1, local_size_z = 1) in;

uniform highp usampler2D _group_0_binding_0;
uniform highp usampler2D _group_0_binding_0_cs;

uniform highp usampler2DMS _group_0_binding_3;
uniform highp usampler2DMS _group_0_binding_3_cs;

layout(rgba8ui) readonly uniform highp uimage2D _group_0_binding_1;
layout(rgba8ui) readonly uniform highp uimage2D _group_0_binding_1_cs;

uniform highp usampler2DArray _group_0_binding_5;
uniform highp usampler2DArray _group_0_binding_5_cs;

layout(r32ui) writeonly uniform highp uimage2D _group_0_binding_2;
layout(r32ui) writeonly uniform highp uimage2D _group_0_binding_2_cs;


void main() {
uvec3 local_id = gl_LocalInvocationID;
ivec2 dim = imageSize(_group_0_binding_1).xy;
ivec2 dim = imageSize(_group_0_binding_1_cs).xy;
ivec2 itc = ((dim * ivec2(local_id.xy)) % ivec2(10, 20));
uvec4 value1_ = texelFetch(_group_0_binding_0, itc, int(local_id.z));
uvec4 value2_ = texelFetch(_group_0_binding_3, itc, int(local_id.z));
uvec4 value4_ = imageLoad(_group_0_binding_1, itc);
uvec4 value5_ = texelFetch(_group_0_binding_5, ivec3(itc, int(local_id.z)), (int(local_id.z) + 1));
imageStore(_group_0_binding_2, ivec2(itc.x, 0.0), (((value1_ + value2_) + value4_) + value5_));
uvec4 value1_ = texelFetch(_group_0_binding_0_cs, itc, int(local_id.z));
uvec4 value2_ = texelFetch(_group_0_binding_3_cs, itc, int(local_id.z));
uvec4 value4_ = imageLoad(_group_0_binding_1_cs, itc);
uvec4 value5_ = texelFetch(_group_0_binding_5_cs, ivec3(itc, int(local_id.z)), (int(local_id.z) + 1));
imageStore(_group_0_binding_2_cs, ivec2(itc.x, 0.0), (((value1_ + value2_) + value4_) + value5_));
return;
}

34 changes: 17 additions & 17 deletions tests/out/glsl/image.queries.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
precision highp float;
precision highp int;

uniform highp sampler2D _group_0_binding_0;
uniform highp sampler2D _group_0_binding_0_vs;

uniform highp sampler2D _group_0_binding_1;
uniform highp sampler2D _group_0_binding_1_vs;

uniform highp sampler2DArray _group_0_binding_2;
uniform highp sampler2DArray _group_0_binding_2_vs;

uniform highp samplerCube _group_0_binding_3;
uniform highp samplerCube _group_0_binding_3_vs;

uniform highp samplerCubeArray _group_0_binding_4;
uniform highp samplerCubeArray _group_0_binding_4_vs;

uniform highp sampler3D _group_0_binding_5;
uniform highp sampler3D _group_0_binding_5_vs;


void main() {
int dim_1d = textureSize(_group_0_binding_0, 0).x;
ivec2 dim_2d = textureSize(_group_0_binding_1, 0).xy;
ivec2 dim_2d_lod = textureSize(_group_0_binding_1, 1).xy;
ivec2 dim_2d_array = textureSize(_group_0_binding_2, 0).xy;
ivec2 dim_2d_array_lod = textureSize(_group_0_binding_2, 1).xy;
ivec2 dim_cube = textureSize(_group_0_binding_3, 0).xy;
ivec2 dim_cube_lod = textureSize(_group_0_binding_3, 1).xy;
ivec2 dim_cube_array = textureSize(_group_0_binding_4, 0).xy;
ivec2 dim_cube_array_lod = textureSize(_group_0_binding_4, 1).xy;
ivec3 dim_3d = textureSize(_group_0_binding_5, 0).xyz;
ivec3 dim_3d_lod = textureSize(_group_0_binding_5, 1).xyz;
int dim_1d = textureSize(_group_0_binding_0_vs, 0).x;
ivec2 dim_2d = textureSize(_group_0_binding_1_vs, 0).xy;
ivec2 dim_2d_lod = textureSize(_group_0_binding_1_vs, 1).xy;
ivec2 dim_2d_array = textureSize(_group_0_binding_2_vs, 0).xy;
ivec2 dim_2d_array_lod = textureSize(_group_0_binding_2_vs, 1).xy;
ivec2 dim_cube = textureSize(_group_0_binding_3_vs, 0).xy;
ivec2 dim_cube_lod = textureSize(_group_0_binding_3_vs, 1).xy;
ivec2 dim_cube_array = textureSize(_group_0_binding_4_vs, 0).xy;
ivec2 dim_cube_array_lod = textureSize(_group_0_binding_4_vs, 1).xy;
ivec3 dim_3d = textureSize(_group_0_binding_5_vs, 0).xyz;
ivec3 dim_3d_lod = textureSize(_group_0_binding_5_vs, 1).xyz;
int sum = ((((((((((dim_1d + dim_2d.y) + dim_2d_lod.y) + dim_2d_array.y) + dim_2d_array_lod.y) + dim_cube.y) + dim_cube_lod.y) + dim_cube_array.y) + dim_cube_array_lod.y) + dim_3d.z) + dim_3d_lod.z);
gl_Position = vec4(float(sum));
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
Expand Down
14 changes: 7 additions & 7 deletions tests/out/glsl/image.sample.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
precision highp float;
precision highp int;

uniform highp sampler2D _group_0_binding_0;
uniform highp sampler2D _group_0_binding_0_fs;

uniform highp sampler2D _group_0_binding_1;
uniform highp sampler2D _group_0_binding_1_fs;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
vec2 tc = vec2(0.5);
vec4 s1d = texture(_group_0_binding_0, vec2(tc.x, 0.0));
vec4 s2d = texture(_group_0_binding_1, vec2(tc));
vec4 s2d_offset = textureOffset(_group_0_binding_1, vec2(tc), ivec2(3, 1));
vec4 s2d_level = textureLod(_group_0_binding_1, vec2(tc), 2.299999952316284);
vec4 s2d_level_offset = textureLodOffset(_group_0_binding_1, vec2(tc), 2.299999952316284, ivec2(3, 1));
vec4 s1d = texture(_group_0_binding_0_fs, vec2(tc.x, 0.0));
vec4 s2d = texture(_group_0_binding_1_fs, vec2(tc));
vec4 s2d_offset = textureOffset(_group_0_binding_1_fs, vec2(tc), ivec2(3, 1));
vec4 s2d_level = textureLod(_group_0_binding_1_fs, vec2(tc), 2.299999952316284);
vec4 s2d_level_offset = textureLodOffset(_group_0_binding_1_fs, vec2(tc), 2.299999952316284, ivec2(3, 1));
_fs2p_location0 = ((((s1d + s2d) + s2d_offset) + s2d_level) + s2d_level_offset);
return;
}
Expand Down
Loading

0 comments on commit 7397407

Please sign in to comment.