Skip to content

Commit

Permalink
[wgsl-in] Update reserved keywords (#1847)
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Apr 17, 2022
1 parent 7ce98dc commit dc075e6
Show file tree
Hide file tree
Showing 58 changed files with 637 additions and 345 deletions.
402 changes: 347 additions & 55 deletions src/keywords/wgsl.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tests/in/access.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct AlignedWrapper {
}

struct Bar {
matrix: mat4x3<f32>,
_matrix: mat4x3<f32>,
matrix_array: array<mat2x2<f32>, 2>,
atom: atomic<i32>,
arr: array<vec2<u32>, 2>,
Expand Down Expand Up @@ -68,10 +68,10 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
test_matrix_within_struct_accesses();

// test storage loads
let matrix = bar.matrix;
let _matrix = bar._matrix;
let arr = bar.arr;
let index = 3u;
let b = bar.matrix[index].x;
let b = bar._matrix[index].x;
let a = bar.data[arrayLength(&bar.data) - 2u].value;

// test pointer types
Expand All @@ -85,14 +85,14 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {

var _ = test_arr_as_arg(array<array<f32, 10>, 5>());

return vec4<f32>(matrix * vec4<f32>(vec4<i32>(value)), 2.0);
return vec4<f32>(_matrix * vec4<f32>(vec4<i32>(value)), 2.0);
}

@fragment
fn foo_frag() -> @location(0) vec4<f32> {
// test storage stores
bar.matrix[1].z = 1.0;
bar.matrix = mat4x3<f32>(vec3<f32>(0.0), vec3<f32>(1.0), vec3<f32>(2.0), vec3<f32>(3.0));
bar._matrix[1].z = 1.0;
bar._matrix = mat4x3<f32>(vec3<f32>(0.0), vec3<f32>(1.0), vec3<f32>(2.0), vec3<f32>(3.0));
bar.arr = array<vec2<u32>, 2>(vec2<u32>(0u), vec2<u32>(1u));
bar.data[1].value = 1;

Expand Down
8 changes: 4 additions & 4 deletions tests/in/bounds-check-image-restrict.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn test_textureLoad_3d(coords: vec3<i32>, level: i32) -> vec4<f32> {
@group(0) @binding(0)
var image_multisampled_2d: texture_multisampled_2d<f32>;

fn test_textureLoad_multisampled_2d(coords: vec2<i32>, sample: i32) -> vec4<f32> {
return textureLoad(image_multisampled_2d, coords, sample);
fn test_textureLoad_multisampled_2d(coords: vec2<i32>, _sample: i32) -> vec4<f32> {
return textureLoad(image_multisampled_2d, coords, _sample);
}

@group(0) @binding(0)
Expand All @@ -50,8 +50,8 @@ fn test_textureLoad_depth_2d_array(coords: vec2<i32>, index: i32, level: i32) ->
@group(0) @binding(0)
var image_depth_multisampled_2d: texture_depth_multisampled_2d;

fn test_textureLoad_depth_multisampled_2d(coords: vec2<i32>, sample: i32) -> f32 {
return textureLoad(image_depth_multisampled_2d, coords, sample);
fn test_textureLoad_depth_multisampled_2d(coords: vec2<i32>, _sample: i32) -> f32 {
return textureLoad(image_depth_multisampled_2d, coords, _sample);
}

@group(0) @binding(0)
Expand Down
8 changes: 4 additions & 4 deletions tests/in/bounds-check-image-rzsw.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn test_textureLoad_3d(coords: vec3<i32>, level: i32) -> vec4<f32> {
@group(0) @binding(0)
var image_multisampled_2d: texture_multisampled_2d<f32>;

fn test_textureLoad_multisampled_2d(coords: vec2<i32>, sample: i32) -> vec4<f32> {
return textureLoad(image_multisampled_2d, coords, sample);
fn test_textureLoad_multisampled_2d(coords: vec2<i32>, _sample: i32) -> vec4<f32> {
return textureLoad(image_multisampled_2d, coords, _sample);
}

@group(0) @binding(0)
Expand All @@ -50,8 +50,8 @@ fn test_textureLoad_depth_2d_array(coords: vec2<i32>, index: i32, level: i32) ->
@group(0) @binding(0)
var image_depth_multisampled_2d: texture_depth_multisampled_2d;

fn test_textureLoad_depth_multisampled_2d(coords: vec2<i32>, sample: i32) -> f32 {
return textureLoad(image_depth_multisampled_2d, coords, sample);
fn test_textureLoad_depth_multisampled_2d(coords: vec2<i32>, _sample: i32) -> f32 {
return textureLoad(image_depth_multisampled_2d, coords, _sample);
}

@group(0) @binding(0)
Expand Down
8 changes: 4 additions & 4 deletions tests/in/extra.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ struct FragmentIn {
}

@fragment
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
if in.primitive_index == pc.index {
return in.color;
fn main(_in: FragmentIn) -> @location(0) vec4<f32> {
if _in.primitive_index == pc.index {
return _in.color;
} else {
return vec4<f32>(vec3<f32>(1.0) - in.color.rgb, in.color.a);
return vec4<f32>(vec3<f32>(1.0) - _in.color.rgb, _in.color.a);
}
}
4 changes: 2 additions & 2 deletions tests/in/image.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn levels_queries() -> @builtin(position) vec4<f32> {
var sampler_reg: sampler;

@fragment
fn sample() -> @location(0) vec4<f32> {
fn texture_sample() -> @location(0) vec4<f32> {
let tc = vec2<f32>(0.5);
let level = 2.3;
let s1d = textureSample(image_1d, sampler_reg, tc.x);
Expand All @@ -117,7 +117,7 @@ var image_2d_depth: texture_depth_2d;
var image_cube_depth: texture_depth_cube;

@fragment
fn sample_comparison() -> @location(0) f32 {
fn texture_sample_comparison() -> @location(0) f32 {
let tc = vec2<f32>(0.5);
let dref = 0.5;
let s2d_depth = textureSampleCompare(image_2d_depth, sampler_cmp, tc, dref);
Expand Down
10 changes: 5 additions & 5 deletions tests/in/interface.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

struct VertexOutput {
@builtin(position) @invariant position: vec4<f32>,
@location(1) varying: f32,
@location(1) _varying: f32,
}

@vertex
Expand All @@ -23,17 +23,17 @@ struct FragmentOutput {

@fragment
fn fragment(
in: VertexOutput,
_in: VertexOutput,
@builtin(front_facing) front_facing: bool,
@builtin(sample_index) sample_index: u32,
@builtin(sample_mask) sample_mask: u32,
) -> FragmentOutput {
let mask = sample_mask & (1u << sample_index);
let color = select(0.0, 1.0, front_facing);
return FragmentOutput(in.varying, mask, color);
return FragmentOutput(_in._varying, mask, color);
}

var<workgroup> output: array<u32, 1>;
var<workgroup> _output: array<u32, 1>;

@compute @workgroup_size(1)
fn compute(
Expand All @@ -43,7 +43,7 @@ fn compute(
@builtin(workgroup_id) wg_id: vec3<u32>,
@builtin(num_workgroups) num_wgs: vec3<u32>,
) {
output[0] = global_id.x + local_id.x + local_index + wg_id.x + num_wgs.x;
_output[0] = global_id.x + local_id.x + local_index + wg_id.x + num_wgs.x;
}

struct Input1 {
Expand Down
24 changes: 12 additions & 12 deletions tests/in/interpolate.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

struct FragmentInput {
@builtin(position) position: vec4<f32>,
@location(0) @interpolate(flat) flat : u32,
@location(1) @interpolate(linear) linear : f32,
@location(0) @interpolate(flat) _flat : u32,
@location(1) @interpolate(linear) _linear : f32,
@location(2) @interpolate(linear, centroid) linear_centroid : vec2<f32>,
@location(3) @interpolate(linear, sample) linear_sample : vec3<f32>,
@location(4) @interpolate(perspective) perspective : vec4<f32>,
Expand All @@ -13,18 +13,18 @@ struct FragmentInput {

@vertex
fn vert_main() -> FragmentInput {
var out: FragmentInput;
var _out: FragmentInput;

out.position = vec4<f32>(2.0, 4.0, 5.0, 6.0);
out.flat = 8u;
out.linear = 27.0;
out.linear_centroid = vec2<f32>(64.0, 125.0);
out.linear_sample = vec3<f32>(216.0, 343.0, 512.0);
out.perspective = vec4<f32>(729.0, 1000.0, 1331.0, 1728.0);
out.perspective_centroid = 2197.0;
out.perspective_sample = 2744.0;
_out.position = vec4<f32>(2.0, 4.0, 5.0, 6.0);
_out._flat = 8u;
_out._linear = 27.0;
_out.linear_centroid = vec2<f32>(64.0, 125.0);
_out.linear_sample = vec3<f32>(216.0, 343.0, 512.0);
_out.perspective = vec4<f32>(729.0, 1000.0, 1331.0, 1728.0);
_out.perspective_centroid = 2197.0;
_out.perspective_sample = 2744.0;

return out;
return _out;
}

@fragment
Expand Down
4 changes: 2 additions & 2 deletions tests/in/padding.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Test3 {
}

@group(0) @binding(0)
var<uniform> input: Test;
var<uniform> input1: Test;

@group(0) @binding(1)
var<uniform> input2: Test2;
Expand All @@ -29,5 +29,5 @@ var<uniform> input3: Test3;

@vertex
fn vertex() -> @builtin(position) vec4<f32> {
return vec4<f32>(1.0) * input.b * input2.b * input3.b;
return vec4<f32>(1.0) * input1.b * input2.b * input3.b;
}
4 changes: 2 additions & 2 deletions tests/in/push-constants.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ struct FragmentIn {
}

@fragment
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
return in.color * pc.multiplier;
fn main(_in: FragmentIn) -> @location(0) vec4<f32> {
return _in.color * pc.multiplier;
}
26 changes: 13 additions & 13 deletions tests/in/shadow.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ fn vs_main(
) -> VertexOutput {
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
var out: VertexOutput;
out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
out.world_position = world_pos;
out.proj_position = u_globals.view_proj * world_pos;
return out;
var _out: VertexOutput;
_out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
_out.world_position = world_pos;
_out.proj_position = u_globals.view_proj * world_pos;
return _out;
}

// fragment shader
Expand Down Expand Up @@ -81,16 +81,16 @@ let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
fn fs_main(_in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(_in.world_normal);
// accumulate color
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i++) {
let light = s_lights[i];
// project into the light space
let shadow = fetch_shadow(i, light.proj * in.world_position);
let shadow = fetch_shadow(i, light.proj * _in.world_position);
// compute Lambertian diffuse term
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let light_dir = normalize(light.pos.xyz - _in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
// add light contribution
color += shadow * diffuse * light.color.xyz;
Expand All @@ -101,15 +101,15 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {

// The fragment entrypoint used when storage buffers are not available for the lights
@fragment
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
fn fs_main_without_storage(_in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(_in.world_normal);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i++) {
// This line is the only difference from the entrypoint above. It uses the lights
// uniform instead of the lights storage buffer
let light = u_lights[i];
let shadow = fetch_shadow(i, light.proj * in.world_position);
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let shadow = fetch_shadow(i, light.proj * _in.world_position);
let light_dir = normalize(light.pos.xyz - _in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
color += shadow * diffuse * light.color.xyz;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/in/skybox.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ var r_texture: texture_cube<f32>;
var r_sampler: sampler;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
fn fs_main(_in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, _in.uv);
}
2 changes: 1 addition & 1 deletion tests/out/glsl/access.atomics.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Baz {
mat3x2 m;
};
layout(std430) buffer Bar_block_0Compute {
mat4x3 matrix;
mat4x3 _matrix;
mat2x2 matrix_array[2];
int atom;
uvec2 arr[2];
Expand Down
6 changes: 3 additions & 3 deletions tests/out/glsl/access.foo_frag.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Baz {
mat3x2 m;
};
layout(std430) buffer Bar_block_0Fragment {
mat4x3 matrix;
mat4x3 _matrix;
mat2x2 matrix_array[2];
int atom;
uvec2 arr[2];
Expand All @@ -29,8 +29,8 @@ float test_arr_as_arg(float a[5][10]) {
}

void main() {
_group_0_binding_0_fs.matrix[1][2] = 1.0;
_group_0_binding_0_fs.matrix = mat4x3(vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0));
_group_0_binding_0_fs._matrix[1][2] = 1.0;
_group_0_binding_0_fs._matrix = mat4x3(vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0));
_group_0_binding_0_fs.arr = uvec2[2](uvec2(0u), uvec2(1u));
_group_0_binding_0_fs.data[1].value = 1;
_fs2p_location0 = vec4(0.0);
Expand Down
8 changes: 4 additions & 4 deletions tests/out/glsl/access.foo_vert.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Baz {
mat3x2 m;
};
layout(std430) buffer Bar_block_0Vertex {
mat4x3 matrix;
mat4x3 _matrix;
mat2x2 matrix_array[2];
int atom;
uvec2 arr[2];
Expand Down Expand Up @@ -86,17 +86,17 @@ void main() {
float baz_1 = foo;
foo = 1.0;
test_matrix_within_struct_accesses();
mat4x3 matrix = _group_0_binding_0_vs.matrix;
mat4x3 _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];
float b = _group_0_binding_0_vs._matrix[3][0];
int a_1 = _group_0_binding_0_vs.data[(uint(_group_0_binding_0_vs.data.length()) - 2u)].value;
float _e28 = read_from_private(foo);
c = int[5](a_1, int(b), 3, 4, 5);
c[(vi + 1u)] = 42;
int value = c[vi];
float _e42 = test_arr_as_arg(float[5][10](float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), float[10](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
unnamed = _e42;
gl_Position = vec4((matrix * vec4(ivec4(value))), 2.0);
gl_Position = vec4((_matrix * vec4(ivec4(value))), 2.0);
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/out/glsl/interpolate.frag_main.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#version 400 core
struct FragmentInput {
vec4 position;
uint flat_;
float linear;
uint _flat;
float _linear;
vec2 linear_centroid;
vec3 linear_sample;
vec4 perspective;
Expand Down
Loading

0 comments on commit dc075e6

Please sign in to comment.