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

[wgsl-in] Update entry point stage attributes #1833

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<W: Write> Writer<W> {
ShaderStage::Fragment => "fragment",
ShaderStage::Compute => "compute",
};
write!(self.out, "@stage({}) ", stage_str)?;
write!(self.out, "@{} ", stage_str)?;
}
Attribute::WorkGroupSize(size) => {
write!(
Expand Down
9 changes: 0 additions & 9 deletions src/front/wgsl/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ pub fn map_built_in(word: &str, span: Span) -> Result<crate::BuiltIn, Error<'_>>
})
}

pub fn map_shader_stage(word: &str, span: Span) -> Result<crate::ShaderStage, Error<'_>> {
match word {
"vertex" => Ok(crate::ShaderStage::Vertex),
"fragment" => Ok(crate::ShaderStage::Fragment),
"compute" => Ok(crate::ShaderStage::Compute),
_ => Err(Error::UnknownShaderStage(span)),
}
}

pub fn map_interpolation(word: &str, span: Span) -> Result<crate::Interpolation, Error<'_>> {
match word {
"linear" => Ok(crate::Interpolation::Linear),
Expand Down
13 changes: 8 additions & 5 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4200,11 +4200,14 @@ impl Parser {
bind_group = Some(parse_non_negative_sint_literal(lexer, 4)?);
lexer.expect(Token::Paren(')'))?;
}
("stage", _) => {
lexer.expect(Token::Paren('('))?;
let (ident, ident_span) = lexer.next_ident_with_span()?;
stage = Some(conv::map_shader_stage(ident, ident_span)?);
lexer.expect(Token::Paren(')'))?;
("vertex", _) => {
stage = Some(crate::ShaderStage::Vertex);
}
("fragment", _) => {
stage = Some(crate::ShaderStage::Fragment);
}
("compute", _) => {
stage = Some(crate::ShaderStage::Compute);
}
("workgroup_size", _) => {
lexer.expect(Token::Paren('('))?;
Expand Down
2 changes: 1 addition & 1 deletion src/front/wgsl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn parse_struct_instantiation() {
b: vec3<f32>,
}

@stage(fragment)
@fragment
fn fs_main() {
var foo: Foo = Foo(0.0, vec3<f32>(0.0, 1.0, 42.0));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/in/access.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_arr_as_arg(a: array<array<f32, 10>, 5>) -> f32 {
return a[4][9];
}

@stage(vertex)
@vertex
fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
var foo: f32 = 0.0;
// We should check that backed doesn't skip this expression
Expand Down Expand Up @@ -88,7 +88,7 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4<f32> {
return vec4<f32>(matrix * vec4<f32>(vec4<i32>(value)), 2.0);
}

@stage(fragment)
@fragment
fn foo_frag() -> @location(0) vec4<f32> {
// test storage stores
bar.matrix[1].z = 1.0;
Expand All @@ -99,7 +99,7 @@ fn foo_frag() -> @location(0) vec4<f32> {
return vec4<f32>(0.0);
}

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn atomics() {
var tmp: i32;
let value = atomicLoad(&bar.atom);
Expand Down
2 changes: 1 addition & 1 deletion tests/in/bits.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
var i = 0;
var i2 = vec2<i32>(0);
Expand Down
2 changes: 1 addition & 1 deletion tests/in/boids.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Particles {
@group(0) @binding(2) var<storage,read_write> particlesDst : Particles;

// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
@stage(compute) @workgroup_size(64)
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) global_invocation_id : vec3<u32>) {
let index : u32 = global_invocation_id.x;
if index >= NUM_PARTICLES {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/collatz.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn collatz_iterations(n_base: u32) -> u32 {
return i;
}

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]);
}
2 changes: 1 addition & 1 deletion tests/in/control-flow.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
//TODO: execution-only barrier?
storageBarrier();
Expand Down
2 changes: 1 addition & 1 deletion tests/in/cubeArrayShadow.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var point_shadow_textures: texture_depth_cube_array;
@group(0) @binding(5)
var point_shadow_textures_sampler: sampler_comparison;

@stage(fragment)
@fragment
fn fragment() -> @location(0) vec4<f32> {
let frag_ls = vec4<f32>(1., 1., 2., 1.).xyz;
let a = textureSampleCompare(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(1), 1.);
Expand Down
2 changes: 1 addition & 1 deletion tests/in/empty.wgsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {}
2 changes: 1 addition & 1 deletion tests/in/extra.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct FragmentIn {
@builtin(primitive_index) primitive_index: u32,
}

@stage(fragment)
@fragment
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
if in.primitive_index == pc.index {
return in.color;
Expand Down
2 changes: 1 addition & 1 deletion tests/in/functions-webgl.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn test_fma() -> vec2<f32> {
}


@stage(vertex)
@vertex
fn main() {
let a = test_fma();
}
2 changes: 1 addition & 1 deletion tests/in/functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_integer_dot_product() -> i32 {
return c_4;
}

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
let a = test_fma();
let b = test_integer_dot_product();
Expand Down
2 changes: 1 addition & 1 deletion tests/in/globals.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_msl_packed_vec3() {
let _ = 2.0 * data.v3;
}

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
test_msl_packed_vec3();

Expand Down
16 changes: 8 additions & 8 deletions tests/in/image.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var image_1d_src: texture_1d<u32>;
@group(0) @binding(2)
var image_dst: texture_storage_1d<r32uint,write>;

@stage(compute) @workgroup_size(16)
@compute @workgroup_size(16)
fn main(
@builtin(local_invocation_id) local_id: vec3<u32>,
//TODO: https://github.com/gpuweb/gpuweb/issues/1590
Expand All @@ -31,7 +31,7 @@ fn main(
textureStore(image_dst, itc.x, value1 + value2 + value4 + value5 + value6);
}

@stage(compute) @workgroup_size(16, 1, 1)
@compute @workgroup_size(16, 1, 1)
fn depth_load(@builtin(local_invocation_id) local_id: vec3<u32>) {
let dim: vec2<i32> = textureDimensions(image_storage_src);
let itc: vec2<i32> = ((dim * vec2<i32>(local_id.xy)) % vec2<i32>(10, 20));
Expand All @@ -55,7 +55,7 @@ var image_3d: texture_3d<f32>;
@group(0) @binding(6)
var image_aa: texture_multisampled_2d<f32>;

@stage(vertex)
@vertex
fn queries() -> @builtin(position) vec4<f32> {
let dim_1d = textureDimensions(image_1d);
let dim_1d_lod = textureDimensions(image_1d, i32(dim_1d));
Expand All @@ -77,7 +77,7 @@ fn queries() -> @builtin(position) vec4<f32> {
return vec4<f32>(f32(sum));
}

@stage(vertex)
@vertex
fn levels_queries() -> @builtin(position) vec4<f32> {
let num_levels_2d = textureNumLevels(image_2d);
let num_levels_2d_array = textureNumLevels(image_2d_array);
Expand All @@ -96,7 +96,7 @@ fn levels_queries() -> @builtin(position) vec4<f32> {
@group(1) @binding(0)
var sampler_reg: sampler;

@stage(fragment)
@fragment
fn sample() -> @location(0) vec4<f32> {
let tc = vec2<f32>(0.5);
let level = 2.3;
Expand All @@ -116,7 +116,7 @@ var image_2d_depth: texture_depth_2d;
@group(1) @binding(3)
var image_cube_depth: texture_depth_cube;

@stage(fragment)
@fragment
fn sample_comparison() -> @location(0) f32 {
let tc = vec2<f32>(0.5);
let dref = 0.5;
Expand All @@ -126,7 +126,7 @@ fn sample_comparison() -> @location(0) f32 {
return s2d_depth + s2d_depth_level;
}

@stage(fragment)
@fragment
fn gather() -> @location(0) vec4<f32> {
let tc = vec2<f32>(0.5);
let dref = 0.5;
Expand All @@ -137,7 +137,7 @@ fn gather() -> @location(0) vec4<f32> {
return s2d + s2d_offset + s2d_depth + s2d_depth_offset;
}

@stage(fragment)
@fragment
fn depth_no_comparison() -> @location(0) vec4<f32> {
let tc = vec2<f32>(0.5);
let s2d = textureSample(image_2d_depth, sampler_reg, tc);
Expand Down
8 changes: 4 additions & 4 deletions tests/in/interface.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct VertexOutput {
@location(1) varying: f32,
}

@stage(vertex)
@vertex
fn vertex(
@builtin(vertex_index) vertex_index: u32,
@builtin(instance_index) instance_index: u32,
Expand All @@ -21,7 +21,7 @@ struct FragmentOutput {
@location(0) color: f32,
}

@stage(fragment)
@fragment
fn fragment(
in: VertexOutput,
@builtin(front_facing) front_facing: bool,
Expand All @@ -35,7 +35,7 @@ fn fragment(

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

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn compute(
@builtin(global_invocation_id) global_id: vec3<u32>,
@builtin(local_invocation_id) local_id: vec3<u32>,
Expand All @@ -54,7 +54,7 @@ struct Input2 {
@builtin(instance_index) index: u32,
}

@stage(vertex)
@vertex
fn vertex_two_structs(in1: Input1, in2: Input2) -> @builtin(position) @invariant vec4<f32> {
var index = 2u;
return vec4<f32>(f32(in1.index), f32(in2.index), f32(index), 0.0);
Expand Down
4 changes: 2 additions & 2 deletions tests/in/interpolate.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct FragmentInput {
@location(6) @interpolate(perspective, sample) perspective_sample : f32,
}

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

Expand All @@ -27,5 +27,5 @@ fn vert_main() -> FragmentInput {
return out;
}

@stage(fragment)
@fragment
fn frag_main(val : FragmentInput) { }
2 changes: 1 addition & 1 deletion tests/in/math-functions.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@stage(vertex)
@vertex
fn main() {
let f = 1.0;
let v = vec4<f32>(0.0);
Expand Down
2 changes: 1 addition & 1 deletion tests/in/operators.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn binary_assignment() {
a--;
}

@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
let a = builtins();
let b = splat();
Expand Down
4 changes: 2 additions & 2 deletions tests/in/padding.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var<uniform> input2: Test2;
var<uniform> input3: Test3;


@stage(vertex)
@vertex
fn vertex() -> @builtin(position) vec4<f32> {
return vec4<f32>(1.0) * input.b * input2.b * input3.b;
}
}
2 changes: 1 addition & 1 deletion tests/in/push-constants.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct FragmentIn {
@location(0) color: vec4<f32>
}

@stage(fragment)
@fragment
fn main(in: FragmentIn) -> @location(0) vec4<f32> {
return in.color * pc.multiplier;
}
6 changes: 3 additions & 3 deletions tests/in/quad.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct VertexOutput {
@builtin(position) position : vec4<f32>,
}

@stage(vertex)
@vertex
fn vert_main(
@location(0) pos : vec2<f32>,
@location(1) uv : vec2<f32>,
Expand All @@ -18,7 +18,7 @@ fn vert_main(
@group(0) @binding(0) var u_texture : texture_2d<f32>;
@group(0) @binding(1) var u_sampler : sampler;

@stage(fragment)
@fragment
fn frag_main(@location(0) uv : vec2<f32>) -> @location(0) vec4<f32> {
let color = textureSample(u_texture, u_sampler, uv);
if color.a == 0.0 {
Expand All @@ -32,7 +32,7 @@ fn frag_main(@location(0) uv : vec2<f32>) -> @location(0) vec4<f32> {


// We need to make sure that backends are successfully handling multiple entry points for the same shader stage.
@stage(fragment)
@fragment
fn fs_extra() -> @location(0) vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}
8 changes: 4 additions & 4 deletions tests/in/shadow.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Entity {
var<uniform> u_entity: Entity;

/* Not useful for testing
@stage(vertex)
@vertex
fn vs_bake(@location(0) position: vec4<i32>) -> @builtin(position) vec4<f32> {
return u_globals.view_proj * u_entity.world * vec4<f32>(position);
}
Expand All @@ -29,7 +29,7 @@ struct VertexOutput {
@location(1) world_position: vec4<f32>,
}

@stage(vertex)
@vertex
fn vs_main(
@location(0) position: vec4<i32>,
@location(1) normal: vec4<i32>,
Expand Down Expand Up @@ -80,7 +80,7 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;

@stage(fragment)
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
// accumulate color
Expand All @@ -100,7 +100,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
}

// The fragment entrypoint used when storage buffers are not available for the lights
@stage(fragment)
@fragment
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
var color: vec3<f32> = c_ambient;
Expand Down
4 changes: 2 additions & 2 deletions tests/in/skybox.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Data {
@group(0) @binding(0)
var<uniform> r_data: Data;

@stage(vertex)
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
// hacky way to draw a large triangle
var tmp1 = i32(vertex_index) / 2;
Expand All @@ -32,7 +32,7 @@ var r_texture: texture_cube<f32>;
@group(0) @binding(2)
var r_sampler: sampler;

@stage(fragment)
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(r_texture, r_sampler, in.uv);
}
Loading