Unify WGSL syntax to put stage decoration on same line

Bug: dawn:572
Change-Id: Ic7baba88bcff9cdb42e0507be58f84c824b62d25
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33980
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-11-25 17:31:15 +00:00 committed by Commit Bot service account
parent 6401506adf
commit 2b606e9297
9 changed files with 35 additions and 69 deletions

View File

@ -37,16 +37,14 @@ class ClipSpaceTest : public DawnTest {
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
Position = vec4<f32>(pos[VertexIndex], 1.0); Position = vec4<f32>(pos[VertexIndex], 1.0);
return; return;
})"); })");
pipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"( pipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> fragColor : vec4<f32>;; [[location(0)]] var<out> fragColor : vec4<f32>;;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0); fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
})"); })");

View File

@ -33,8 +33,7 @@ class ColorStateTest : public DawnTest {
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>( const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, -1.0),
vec2<f32>(3.0, -1.0), vec2<f32>(3.0, -1.0),
@ -64,8 +63,7 @@ class ColorStateTest : public DawnTest {
[[location(0)]] var<out> fragColor : vec4<f32>; [[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = myUbo.color; fragColor = myUbo.color;
return; return;
} }
@ -785,8 +783,7 @@ TEST_P(ColorStateTest, IndependentColorState) {
[[location(2)]] var<out> fragColor2 : vec4<f32>; [[location(2)]] var<out> fragColor2 : vec4<f32>;
[[location(3)]] var<out> fragColor3 : vec4<f32>; [[location(3)]] var<out> fragColor3 : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor0 = myUbo.color0; fragColor0 = myUbo.color0;
fragColor1 = myUbo.color1; fragColor1 = myUbo.color1;
fragColor2 = myUbo.color2; fragColor2 = myUbo.color2;
@ -890,8 +887,7 @@ TEST_P(ColorStateTest, DefaultBlendColor) {
[[location(0)]] var<out> fragColor : vec4<f32>; [[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = myUbo.color; fragColor = myUbo.color;
return; return;
} }
@ -1014,8 +1010,7 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) {
[[location(0)]] var<out> fragColor : vec4<f32>; [[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = myUbo.color; fragColor = myUbo.color;
return; return;
} }

View File

@ -145,8 +145,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>( const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-3.0, 1.0), vec2<f32>(-3.0, 1.0),
vec2<f32>( 3.0, 1.0), vec2<f32>( 3.0, 1.0),
@ -163,8 +162,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
[[location(0)]] var<in> texCoord : vec2<f32>; [[location(0)]] var<in> texCoord : vec2<f32>;
[[location(0)]] var<out> fragColor : vec4<f32>; [[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = textureSample(texture0, sampler0, texCoord); fragColor = textureSample(texture0, sampler0, texCoord);
return; return;
})"); })");

View File

@ -37,8 +37,7 @@ class CullingTest : public DawnTest {
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0); Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
return; return;
})"); })");
@ -50,8 +49,7 @@ class CullingTest : public DawnTest {
[[location(0)]] var<out> fragColor : vec4<f32>;; [[location(0)]] var<out> fragColor : vec4<f32>;;
[[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>; [[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = vec4<f32>( fragColor = vec4<f32>(
(FragCoord.xy - vec2<f32>(0.5, 0.5)) / vec2<f32>(255.0, 255.0), (FragCoord.xy - vec2<f32>(0.5, 0.5)) / vec2<f32>(255.0, 255.0),
0.0, 1.0); 0.0, 1.0);

View File

@ -103,16 +103,14 @@ TEST_P(D3D12CachingTests, SameShaderNoCache) {
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex_main() -> void {
fn vertex_main() -> void {
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return; return;
} }
[[location(0)]] var<out> outColor : vec4<f32>; [[location(0)]] var<out> outColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragment_main() -> void {
fn fragment_main() -> void {
outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0); outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
} }
@ -152,16 +150,14 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPointsPerStage) {
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex_main() -> void {
fn vertex_main() -> void {
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return; return;
} }
[[location(0)]] var<out> outColor : vec4<f32>; [[location(0)]] var<out> outColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragment_main() -> void {
fn fragment_main() -> void {
outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0); outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
} }
@ -199,16 +195,14 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPointsPerStage) {
wgpu::ShaderModule newModule = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule newModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex_main() -> void {
fn vertex_main() -> void {
Position = vec4<f32>(1.0, 1.0, 1.0, 1.0); Position = vec4<f32>(1.0, 1.0, 1.0, 1.0);
return; return;
} }
[[location(0)]] var<out> outColor : vec4<f32>; [[location(0)]] var<out> outColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragment_main() -> void {
fn fragment_main() -> void {
outColor = vec4<f32>(1.0, 1.0, 1.0, 1.0); outColor = vec4<f32>(1.0, 1.0, 1.0, 1.0);
return; return;
} }
@ -237,14 +231,12 @@ TEST_P(D3D12CachingTests, ReuseShaderWithMultipleEntryPoints) {
}; };
[[binding(0), set(0)]] var<storage_buffer> data : Data; [[binding(0), set(0)]] var<storage_buffer> data : Data;
[[stage(compute)]] [[stage(compute)]] fn write1() -> void {
fn write1() -> void {
data.data = 1u; data.data = 1u;
return; return;
} }
[[stage(compute)]] [[stage(compute)]] fn write42() -> void {
fn write42() -> void {
data.data = 42u; data.data = 42u;
return; return;
} }

View File

@ -38,8 +38,7 @@ class DepthBiasTests : public DawnTest {
vertexSource = R"( vertexSource = R"(
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
const pos : array<vec2<f32>, 6> = array<vec2<f32>, 6>( const pos : array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, -1.0), vec2<f32>( 1.0, -1.0),
@ -57,8 +56,7 @@ class DepthBiasTests : public DawnTest {
vertexSource = R"( vertexSource = R"(
[[builtin(vertex_idx)]] var<in> VertexIndex : i32; [[builtin(vertex_idx)]] var<in> VertexIndex : i32;
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
const pos : array<vec3<f32>, 6> = array<vec3<f32>, 6>( const pos : array<vec3<f32>, 6> = array<vec3<f32>, 6>(
vec3<f32>(-1.0, -1.0, 0.0), vec3<f32>(-1.0, -1.0, 0.0),
vec3<f32>( 1.0, -1.0, 0.0), vec3<f32>( 1.0, -1.0, 0.0),
@ -76,8 +74,7 @@ class DepthBiasTests : public DawnTest {
wgpu::ShaderModule fragmentModule = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule fragmentModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> fragColor : vec4<f32>;; [[location(0)]] var<out> fragColor : vec4<f32>;;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0); fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
})"); })");

View File

@ -27,16 +27,14 @@ TEST_P(EntryPointTests, FragAndVertexSameModule) {
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex_main() -> void {
fn vertex_main() -> void {
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return; return;
} }
[[location(0)]] var<out> outColor : vec4<f32>; [[location(0)]] var<out> outColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragment_main() -> void {
fn fragment_main() -> void {
outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0); outColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
} }
@ -82,14 +80,12 @@ TEST_P(EntryPointTests, TwoComputeInModule) {
}; };
[[binding(0), set(0)]] var<storage_buffer> data : Data; [[binding(0), set(0)]] var<storage_buffer> data : Data;
[[stage(compute)]] [[stage(compute)]] fn write1() -> void {
fn write1() -> void {
data.data = 1u; data.data = 1u;
return; return;
} }
[[stage(compute)]] [[stage(compute)]] fn write42() -> void {
fn write42() -> void {
data.data = 42u; data.data = 42u;
return; return;
} }

View File

@ -35,8 +35,7 @@ class VertexBufferRobustnessTest : public DawnTest {
return utils::CreateShaderModuleFromWGSL(device, (attributes + R"( return utils::CreateShaderModuleFromWGSL(device, (attributes + R"(
[[builtin(position)]] var<out> Position : vec4<f32>; [[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn main() -> void {
fn main() -> void {
if ()" + successExpression + R"() { if ()" + successExpression + R"() {
# Success case, move the vertex out of the viewport # Success case, move the vertex out of the viewport
Position = vec4<f32>(-10.0, 0.0, 0.0, 1.0); Position = vec4<f32>(-10.0, 0.0, 0.0, 1.0);
@ -61,8 +60,7 @@ class VertexBufferRobustnessTest : public DawnTest {
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> outColor : vec4<f32>; [[location(0)]] var<out> outColor : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn main() -> void {
fn main() -> void {
outColor = vec4<f32>(1.0, 1.0, 1.0, 1.0); outColor = vec4<f32>(1.0, 1.0, 1.0, 1.0);
return; return;
} }

View File

@ -594,15 +594,13 @@ TEST_F(RenderPipelineValidationTest, EntryPointNameValidation) {
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"( wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> position : vec4<f32>; [[builtin(position)]] var<out> position : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex_main() -> void {
fn vertex_main() -> void {
position = vec4<f32>(0.0, 0.0, 0.0, 1.0); position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return; return;
} }
[[location(0)]] var<out> color : vec4<f32>; [[location(0)]] var<out> color : vec4<f32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragment_main() -> void {
fn fragment_main() -> void {
color = vec4<f32>(1.0, 0.0, 0.0, 1.0); color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
return; return;
} }
@ -651,13 +649,11 @@ TEST_F(RenderPipelineValidationTest, VertexAttribCorrectEntryPoint) {
[[location(0)]] var<in> attrib0 : vec4<f32>; [[location(0)]] var<in> attrib0 : vec4<f32>;
[[location(1)]] var<in> attrib1 : vec4<f32>; [[location(1)]] var<in> attrib1 : vec4<f32>;
[[stage(vertex)]] [[stage(vertex)]] fn vertex0() -> void {
fn vertex0() -> void {
position = attrib0; position = attrib0;
return; return;
} }
[[stage(vertex)]] [[stage(vertex)]] fn vertex1() -> void {
fn vertex1() -> void {
position = attrib1; position = attrib1;
return; return;
} }
@ -700,13 +696,11 @@ TEST_F(RenderPipelineValidationTest, FragmentOutputCorrectEntryPoint) {
[[location(0)]] var<out> colorFloat : vec4<f32>; [[location(0)]] var<out> colorFloat : vec4<f32>;
[[location(0)]] var<out> colorUint : vec4<u32>; [[location(0)]] var<out> colorUint : vec4<u32>;
[[stage(fragment)]] [[stage(fragment)]] fn fragmentFloat() -> void {
fn fragmentFloat() -> void {
colorFloat = vec4<f32>(0.0, 0.0, 0.0, 0.0); colorFloat = vec4<f32>(0.0, 0.0, 0.0, 0.0);
return; return;
} }
[[stage(fragment)]] [[stage(fragment)]] fn fragmentUint() -> void {
fn fragmentUint() -> void {
colorUint = vec4<u32>(0, 0, 0, 0); colorUint = vec4<u32>(0, 0, 0, 0);
return; return;
} }