diff --git a/src/front/wgsl/conv.rs b/src/front/wgsl/conv.rs index 6d4dd954a..c1bbb8971 100644 --- a/src/front/wgsl/conv.rs +++ b/src/front/wgsl/conv.rs @@ -38,15 +38,6 @@ pub fn map_built_in(word: &str, span: Span) -> Result> }) } -pub fn map_shader_stage(word: &str, span: Span) -> Result> { - 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> { match word { "linear" => Ok(crate::Interpolation::Linear), diff --git a/src/front/wgsl/mod.rs b/src/front/wgsl/mod.rs index 854c3f51c..b78f9bd60 100644 --- a/src/front/wgsl/mod.rs +++ b/src/front/wgsl/mod.rs @@ -4210,11 +4210,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('('))?; diff --git a/src/front/wgsl/tests.rs b/src/front/wgsl/tests.rs index ffbe89936..1f7e451f9 100644 --- a/src/front/wgsl/tests.rs +++ b/src/front/wgsl/tests.rs @@ -463,7 +463,7 @@ fn parse_struct_instantiation() { b: vec3, } - @stage(fragment) + @fragment fn fs_main() { var foo: Foo = Foo(0.0, vec3(0.0, 1.0, 42.0)); } diff --git a/tests/in/access.wgsl b/tests/in/access.wgsl index e64ef2152..64e91c944 100644 --- a/tests/in/access.wgsl +++ b/tests/in/access.wgsl @@ -58,7 +58,7 @@ fn test_arr_as_arg(a: array, 5>) -> f32 { return a[4][9]; } -@stage(vertex) +@vertex fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4 { var foo: f32 = 0.0; // We should check that backed doesn't skip this expression @@ -88,7 +88,7 @@ fn foo_vert(@builtin(vertex_index) vi: u32) -> @builtin(position) vec4 { return vec4(matrix * vec4(vec4(value)), 2.0); } -@stage(fragment) +@fragment fn foo_frag() -> @location(0) vec4 { // test storage stores bar.matrix[1].z = 1.0; @@ -99,7 +99,7 @@ fn foo_frag() -> @location(0) vec4 { return vec4(0.0); } -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn atomics() { var tmp: i32; let value = atomicLoad(&bar.atom); diff --git a/tests/in/bits.wgsl b/tests/in/bits.wgsl index 9de7de547..24101d993 100644 --- a/tests/in/bits.wgsl +++ b/tests/in/bits.wgsl @@ -1,4 +1,4 @@ -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn main() { var i = 0; var i2 = vec2(0); diff --git a/tests/in/boids.wgsl b/tests/in/boids.wgsl index 7194d4878..31bbc85bb 100644 --- a/tests/in/boids.wgsl +++ b/tests/in/boids.wgsl @@ -24,7 +24,7 @@ struct Particles { @group(0) @binding(2) var 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) { let index : u32 = global_invocation_id.x; if index >= NUM_PARTICLES { diff --git a/tests/in/collatz.wgsl b/tests/in/collatz.wgsl index b2d990732..ebfc41b6f 100644 --- a/tests/in/collatz.wgsl +++ b/tests/in/collatz.wgsl @@ -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) { v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]); } diff --git a/tests/in/control-flow.wgsl b/tests/in/control-flow.wgsl index db87b320f..f059eeeb8 100644 --- a/tests/in/control-flow.wgsl +++ b/tests/in/control-flow.wgsl @@ -1,4 +1,4 @@ -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn main(@builtin(global_invocation_id) global_id: vec3) { //TODO: execution-only barrier? storageBarrier(); diff --git a/tests/in/cubeArrayShadow.wgsl b/tests/in/cubeArrayShadow.wgsl index aad2d5ae8..78b884558 100644 --- a/tests/in/cubeArrayShadow.wgsl +++ b/tests/in/cubeArrayShadow.wgsl @@ -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 { let frag_ls = vec4(1., 1., 2., 1.).xyz; let a = textureSampleCompare(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(1), 1.); diff --git a/tests/in/empty.wgsl b/tests/in/empty.wgsl index 862844479..b4af5cb41 100644 --- a/tests/in/empty.wgsl +++ b/tests/in/empty.wgsl @@ -1,2 +1,2 @@ -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn main() {} diff --git a/tests/in/extra.wgsl b/tests/in/extra.wgsl index a0130da17..ef68f4aa8 100644 --- a/tests/in/extra.wgsl +++ b/tests/in/extra.wgsl @@ -9,7 +9,7 @@ struct FragmentIn { @builtin(primitive_index) primitive_index: u32, } -@stage(fragment) +@fragment fn main(in: FragmentIn) -> @location(0) vec4 { if in.primitive_index == pc.index { return in.color; diff --git a/tests/in/functions-webgl.wgsl b/tests/in/functions-webgl.wgsl index 2e058ec72..9192f6868 100644 --- a/tests/in/functions-webgl.wgsl +++ b/tests/in/functions-webgl.wgsl @@ -7,7 +7,7 @@ fn test_fma() -> vec2 { } -@stage(vertex) +@vertex fn main() { let a = test_fma(); } diff --git a/tests/in/functions.wgsl b/tests/in/functions.wgsl index 6a15da1e3..23e4b0400 100644 --- a/tests/in/functions.wgsl +++ b/tests/in/functions.wgsl @@ -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(); diff --git a/tests/in/globals.wgsl b/tests/in/globals.wgsl index a4467eae7..6e571e271 100644 --- a/tests/in/globals.wgsl +++ b/tests/in/globals.wgsl @@ -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(); diff --git a/tests/in/image.wgsl b/tests/in/image.wgsl index 5fd0eec13..cc7746ea4 100644 --- a/tests/in/image.wgsl +++ b/tests/in/image.wgsl @@ -15,7 +15,7 @@ var image_1d_src: texture_1d; @group(0) @binding(2) var image_dst: texture_storage_1d; -@stage(compute) @workgroup_size(16) +@compute @workgroup_size(16) fn main( @builtin(local_invocation_id) local_id: vec3, //TODO: https://github.com/gpuweb/gpuweb/issues/1590 @@ -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) { let dim: vec2 = textureDimensions(image_storage_src); let itc: vec2 = ((dim * vec2(local_id.xy)) % vec2(10, 20)); @@ -55,7 +55,7 @@ var image_3d: texture_3d; @group(0) @binding(6) var image_aa: texture_multisampled_2d; -@stage(vertex) +@vertex fn queries() -> @builtin(position) vec4 { let dim_1d = textureDimensions(image_1d); let dim_1d_lod = textureDimensions(image_1d, i32(dim_1d)); @@ -77,7 +77,7 @@ fn queries() -> @builtin(position) vec4 { return vec4(f32(sum)); } -@stage(vertex) +@vertex fn levels_queries() -> @builtin(position) vec4 { let num_levels_2d = textureNumLevels(image_2d); let num_levels_2d_array = textureNumLevels(image_2d_array); @@ -96,7 +96,7 @@ fn levels_queries() -> @builtin(position) vec4 { @group(1) @binding(0) var sampler_reg: sampler; -@stage(fragment) +@fragment fn sample() -> @location(0) vec4 { let tc = vec2(0.5); let level = 2.3; @@ -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(0.5); let dref = 0.5; @@ -126,7 +126,7 @@ fn sample_comparison() -> @location(0) f32 { return s2d_depth + s2d_depth_level; } -@stage(fragment) +@fragment fn gather() -> @location(0) vec4 { let tc = vec2(0.5); let dref = 0.5; @@ -137,7 +137,7 @@ fn gather() -> @location(0) vec4 { return s2d + s2d_offset + s2d_depth + s2d_depth_offset; } -@stage(fragment) +@fragment fn depth_no_comparison() -> @location(0) vec4 { let tc = vec2(0.5); let s2d = textureSample(image_2d_depth, sampler_reg, tc); diff --git a/tests/in/interface.wgsl b/tests/in/interface.wgsl index 812afc51a..9bf713199 100644 --- a/tests/in/interface.wgsl +++ b/tests/in/interface.wgsl @@ -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, @@ -21,7 +21,7 @@ struct FragmentOutput { @location(0) color: f32, } -@stage(fragment) +@fragment fn fragment( in: VertexOutput, @builtin(front_facing) front_facing: bool, @@ -35,7 +35,7 @@ fn fragment( var output: array; -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn compute( @builtin(global_invocation_id) global_id: vec3, @builtin(local_invocation_id) local_id: vec3, @@ -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 { var index = 2u; return vec4(f32(in1.index), f32(in2.index), f32(index), 0.0); diff --git a/tests/in/interpolate.wgsl b/tests/in/interpolate.wgsl index 86753a83e..071891ee7 100644 --- a/tests/in/interpolate.wgsl +++ b/tests/in/interpolate.wgsl @@ -11,7 +11,7 @@ struct FragmentInput { @location(6) @interpolate(perspective, sample) perspective_sample : f32, } -@stage(vertex) +@vertex fn vert_main() -> FragmentInput { var out: FragmentInput; @@ -27,5 +27,5 @@ fn vert_main() -> FragmentInput { return out; } -@stage(fragment) +@fragment fn frag_main(val : FragmentInput) { } diff --git a/tests/in/math-functions.wgsl b/tests/in/math-functions.wgsl index 5d3a1f592..a298a5e2b 100644 --- a/tests/in/math-functions.wgsl +++ b/tests/in/math-functions.wgsl @@ -1,4 +1,4 @@ -@stage(vertex) +@vertex fn main() { let f = 1.0; let v = vec4(0.0); diff --git a/tests/in/operators.wgsl b/tests/in/operators.wgsl index 54949f419..f62329499 100644 --- a/tests/in/operators.wgsl +++ b/tests/in/operators.wgsl @@ -279,7 +279,7 @@ fn assignment() { a--; } -@stage(compute) @workgroup_size(1) +@compute @workgroup_size(1) fn main() { let _ = builtins(); let _ = splat(); diff --git a/tests/in/padding.wgsl b/tests/in/padding.wgsl index 0ff60f393..13331edf8 100644 --- a/tests/in/padding.wgsl +++ b/tests/in/padding.wgsl @@ -27,7 +27,7 @@ var input2: Test2; var input3: Test3; -@stage(vertex) +@vertex fn vertex() -> @builtin(position) vec4 { return vec4(1.0) * input.b * input2.b * input3.b; -} \ No newline at end of file +} diff --git a/tests/in/push-constants.wgsl b/tests/in/push-constants.wgsl index e0bf46758..cc8c4ab02 100644 --- a/tests/in/push-constants.wgsl +++ b/tests/in/push-constants.wgsl @@ -7,7 +7,7 @@ struct FragmentIn { @location(0) color: vec4 } -@stage(fragment) +@fragment fn main(in: FragmentIn) -> @location(0) vec4 { return in.color * pc.multiplier; } diff --git a/tests/in/quad.wgsl b/tests/in/quad.wgsl index 590ba0e4c..f2c85f095 100644 --- a/tests/in/quad.wgsl +++ b/tests/in/quad.wgsl @@ -6,7 +6,7 @@ struct VertexOutput { @builtin(position) position : vec4, } -@stage(vertex) +@vertex fn vert_main( @location(0) pos : vec2, @location(1) uv : vec2, @@ -18,7 +18,7 @@ fn vert_main( @group(0) @binding(0) var u_texture : texture_2d; @group(0) @binding(1) var u_sampler : sampler; -@stage(fragment) +@fragment fn frag_main(@location(0) uv : vec2) -> @location(0) vec4 { let color = textureSample(u_texture, u_sampler, uv); if color.a == 0.0 { @@ -32,7 +32,7 @@ fn frag_main(@location(0) uv : vec2) -> @location(0) vec4 { // 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 { return vec4(0.0, 0.5, 0.0, 0.5); } diff --git a/tests/in/shadow.wgsl b/tests/in/shadow.wgsl index bce4720cf..575018863 100644 --- a/tests/in/shadow.wgsl +++ b/tests/in/shadow.wgsl @@ -17,7 +17,7 @@ struct Entity { var u_entity: Entity; /* Not useful for testing -@stage(vertex) +@vertex fn vs_bake(@location(0) position: vec4) -> @builtin(position) vec4 { return u_globals.view_proj * u_entity.world * vec4(position); } @@ -29,7 +29,7 @@ struct VertexOutput { @location(1) world_position: vec4, } -@stage(vertex) +@vertex fn vs_main( @location(0) position: vec4, @location(1) normal: vec4, @@ -80,7 +80,7 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { let c_ambient: vec3 = vec3(0.05, 0.05, 0.05); let c_max_lights: u32 = 10u; -@stage(fragment) +@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { let normal = normalize(in.world_normal); // accumulate color @@ -100,7 +100,7 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4 { } // 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 { let normal = normalize(in.world_normal); var color: vec3 = c_ambient; diff --git a/tests/in/skybox.wgsl b/tests/in/skybox.wgsl index 0b589c7f5..f4cc37a44 100644 --- a/tests/in/skybox.wgsl +++ b/tests/in/skybox.wgsl @@ -10,7 +10,7 @@ struct Data { @group(0) @binding(0) var 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; @@ -32,7 +32,7 @@ var r_texture: texture_cube; @group(0) @binding(2) var r_sampler: sampler; -@stage(fragment) +@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4 { return textureSample(r_texture, r_sampler, in.uv); } diff --git a/tests/in/standard.wgsl b/tests/in/standard.wgsl index 9171db190..5b40b683a 100644 --- a/tests/in/standard.wgsl +++ b/tests/in/standard.wgsl @@ -1,6 +1,6 @@ // Standard functions. -@stage(fragment) +@fragment fn derivatives(@builtin(position) foo: vec4) -> @location(0) vec4 { let x = dpdx(foo); let y = dpdy(foo); diff --git a/tests/in/texture-arg.wgsl b/tests/in/texture-arg.wgsl index 70fd586f0..3b1bbe680 100644 --- a/tests/in/texture-arg.wgsl +++ b/tests/in/texture-arg.wgsl @@ -7,7 +7,7 @@ fn test(Passed_Texture: texture_2d, Passed_Sampler: sampler) -> vec4 { return textureSample(Passed_Texture, Passed_Sampler, vec2(0.0, 0.0)); } -@stage(fragment) +@fragment fn main() -> @location(0) vec4 { return test(Texture, Sampler); } diff --git a/tests/spirv-capabilities.rs b/tests/spirv-capabilities.rs index 83df32628..409768910 100644 --- a/tests/spirv-capabilities.rs +++ b/tests/spirv-capabilities.rs @@ -136,7 +136,7 @@ fn sample_rate_shading() { require( &[Ca::SampleRateShading], r#" - @stage(fragment) + @fragment fn f(@location(0) @interpolate(perspective, sample) x: f32) { } "#, ); @@ -144,7 +144,7 @@ fn sample_rate_shading() { require( &[Ca::SampleRateShading], r#" - @stage(fragment) + @fragment fn f(@builtin(sample_index) x: u32) { } "#, ); @@ -155,7 +155,7 @@ fn geometry() { require( &[Ca::Geometry], r#" - @stage(fragment) + @fragment fn f(@builtin(primitive_index) x: u32) { } "#, ); diff --git a/tests/wgsl-errors.rs b/tests/wgsl-errors.rs index 9f341ff45..4ccfa29bf 100644 --- a/tests/wgsl-errors.rs +++ b/tests/wgsl-errors.rs @@ -132,7 +132,7 @@ fn bad_texture() { r#" @group(0) @binding(0) var sampler1 : sampler; - @stage(fragment) + @fragment fn main() -> @location(0) vec4 { let a = 3; return textureSample(a, sampler1, vec2(0.0)); @@ -245,7 +245,7 @@ fn bad_texture_sample_type() { @group(0) @binding(0) var sampler1 : sampler; @group(0) @binding(1) var texture : texture_2d; - @stage(fragment) + @fragment fn main() -> @location(0) vec4 { return textureSample(texture, sampler1, vec2(0.0)); } @@ -343,22 +343,6 @@ fn unknown_access() { ); } -#[test] -fn unknown_shader_stage() { - check( - r#" - @stage(geometry) fn main() {} - "#, - r#"error: unknown shader stage: 'geometry' - ┌─ wgsl:2:20 - │ -2 │ @stage(geometry) fn main() {} - │ ^^^^^^^^ unknown shader stage - -"#, - ); -} - #[test] fn unknown_ident() { check( @@ -1027,7 +1011,7 @@ fn pointer_type_equivalence() { fn missing_bindings() { check_validation_error! { " - @stage(vertex) + @vertex fn vertex(input: vec4) -> @location(0) vec4 { return input; } @@ -1044,7 +1028,7 @@ fn missing_bindings() { check_validation_error! { " - @stage(vertex) + @vertex fn vertex(@location(0) input: vec4, more_input: f32) -> @location(0) vec4 { return input + more_input; } @@ -1061,7 +1045,7 @@ fn missing_bindings() { check_validation_error! { " - @stage(vertex) + @vertex fn vertex(@location(0) input: vec4) -> vec4 { return input; } @@ -1082,7 +1066,7 @@ fn missing_bindings() { uv: vec2 } - @stage(vertex) + @vertex fn vertex(input: VertexIn) -> @location(0) vec4 { return input.pos; }