[wgsl-in] Update entry point stage attributes

This commit is contained in:
Igor Shaposhnik 2022-04-15 12:54:15 +03:00 committed by João Capucho
parent c93a5ede71
commit fbb77aa0dc
28 changed files with 61 additions and 83 deletions

View File

@ -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),

View File

@ -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('('))?;

View File

@ -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));
}

View File

@ -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
@ -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;
@ -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);

View File

@ -1,4 +1,4 @@
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
var i = 0;
var i2 = vec2<i32>(0);

View File

@ -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 {

View File

@ -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]);
}

View File

@ -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();

View File

@ -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.);

View File

@ -1,2 +1,2 @@
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {}

View File

@ -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;

View File

@ -7,7 +7,7 @@ fn test_fma() -> vec2<f32> {
}
@stage(vertex)
@vertex
fn main() {
let a = test_fma();
}

View File

@ -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();

View File

@ -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();

View File

@ -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
@ -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));
@ -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));
@ -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);
@ -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;
@ -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;
@ -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;
@ -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);

View File

@ -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<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>,
@ -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);

View File

@ -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) { }

View File

@ -1,4 +1,4 @@
@stage(vertex)
@vertex
fn main() {
let f = 1.0;
let v = vec4<f32>(0.0);

View File

@ -279,7 +279,7 @@ fn assignment() {
a--;
}
@stage(compute) @workgroup_size(1)
@compute @workgroup_size(1)
fn main() {
let _ = builtins();
let _ = splat();

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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>,
@ -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 {
@ -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);
}

View File

@ -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);
}
@ -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>,
@ -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
@ -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;

View File

@ -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;
@ -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);
}

View File

@ -1,6 +1,6 @@
// Standard functions.
@stage(fragment)
@fragment
fn derivatives(@builtin(position) foo: vec4<f32>) -> @location(0) vec4<f32> {
let x = dpdx(foo);
let y = dpdy(foo);

View File

@ -7,7 +7,7 @@ fn test(Passed_Texture: texture_2d<f32>, Passed_Sampler: sampler) -> vec4<f32> {
return textureSample(Passed_Texture, Passed_Sampler, vec2<f32>(0.0, 0.0));
}
@stage(fragment)
@fragment
fn main() -> @location(0) vec4<f32> {
return test(Texture, Sampler);
}

View File

@ -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) { }
"#,
);

View File

@ -132,7 +132,7 @@ fn bad_texture() {
r#"
@group(0) @binding(0) var sampler1 : sampler;
@stage(fragment)
@fragment
fn main() -> @location(0) vec4<f32> {
let a = 3;
return textureSample(a, sampler1, vec2<f32>(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<bool>;
@stage(fragment)
@fragment
fn main() -> @location(0) vec4<f32> {
return textureSample(texture, sampler1, vec2<f32>(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<f32>) -> @location(0) vec4<f32> {
return input;
}
@ -1044,7 +1028,7 @@ fn missing_bindings() {
check_validation_error! {
"
@stage(vertex)
@vertex
fn vertex(@location(0) input: vec4<f32>, more_input: f32) -> @location(0) vec4<f32> {
return input + more_input;
}
@ -1061,7 +1045,7 @@ fn missing_bindings() {
check_validation_error! {
"
@stage(vertex)
@vertex
fn vertex(@location(0) input: vec4<f32>) -> vec4<f32> {
return input;
}
@ -1082,7 +1066,7 @@ fn missing_bindings() {
uv: vec2<f32>
}
@stage(vertex)
@vertex
fn vertex(input: VertexIn) -> @location(0) vec4<f32> {
return input.pos;
}