Modernize some internal WGSL syntax

Change-Id: I4706e517608d436fa646537fec9e930ae47d1c40
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118029
Commit-Queue: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
This commit is contained in:
Austin Eng
2023-02-02 20:17:46 +00:00
committed by Dawn LUCI CQ
parent 78b14285bc
commit 08027c662e
103 changed files with 1545 additions and 1550 deletions

View File

@@ -35,15 +35,15 @@ namespace {
// General helper functions and data structures for applying clear values with draw
static const char kVSSource[] = R"(
@vertex
fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4<f32> {
var pos = array<vec2<f32>, 6>(
vec2<f32>( 0.0, -1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 0.0, 1.0),
vec2<f32>( 0.0, 1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 1.0, 1.0));
return vec4<f32>(pos[VertexIndex], 0.0, 1.0);
fn main(@builtin(vertex_index) VertexIndex : u32) -> @builtin(position) vec4f {
var pos = array(
vec2f( 0.0, -1.0),
vec2f( 1.0, -1.0),
vec2f( 0.0, 1.0),
vec2f( 0.0, 1.0),
vec2f( 1.0, -1.0),
vec2f( 1.0, 1.0));
return vec4f(pos[VertexIndex], 0.0, 1.0);
})";
const char* GetTextureComponentTypeString(DeviceBase* device, wgpu::TextureFormat format) {

View File

@@ -34,27 +34,27 @@ constexpr char kBlitRG8ToDepthShaders[] = R"(
@vertex fn vert_fullscreen_quad(
@builtin(vertex_index) vertex_index : u32
) -> @builtin(position) vec4<f32> {
const pos = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 3.0, -1.0),
vec2<f32>(-1.0, 3.0));
return vec4<f32>(pos[vertex_index], 0.0, 1.0);
) -> @builtin(position) vec4f {
const pos = array(
vec2f(-1.0, -1.0),
vec2f( 3.0, -1.0),
vec2f(-1.0, 3.0));
return vec4f(pos[vertex_index], 0.0, 1.0);
}
struct Params {
origin : vec2<u32>
origin : vec2u
};
@group(0) @binding(0) var src_tex : texture_2d<u32>;
@group(0) @binding(1) var<uniform> params : Params;
@fragment fn blit_to_depth(
@builtin(position) position : vec4<f32>
@builtin(position) position : vec4f
) -> @builtin(frag_depth) f32 {
// Load the source texel.
let src_texel = textureLoad(
src_tex, vec2<u32>(position.xy) - params.origin, 0u);
src_tex, vec2u(position.xy) - params.origin, 0u);
let depth_u16_val = (src_texel.y << 8u) + src_texel.x;
@@ -68,7 +68,7 @@ constexpr char kBlitStencilShaders[] = R"(
struct VertexOutputs {
@location(0) @interpolate(flat) stencil_val : u32,
@builtin(position) position : vec4<f32>,
@builtin(position) position : vec4f,
};
// The instance_index here is not used for instancing.
@@ -80,18 +80,18 @@ struct VertexOutputs {
@builtin(vertex_index) vertex_index : u32,
@builtin(instance_index) instance_index: u32,
) -> VertexOutputs {
const pos = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 3.0, -1.0),
vec2<f32>(-1.0, 3.0));
const pos = array(
vec2f(-1.0, -1.0),
vec2f( 3.0, -1.0),
vec2f(-1.0, 3.0));
return VertexOutputs(
instance_index,
vec4<f32>(pos[vertex_index], 0.0, 1.0),
vec4f(pos[vertex_index], 0.0, 1.0),
);
}
struct Params {
origin : vec2<u32>
origin : vec2u
};
@group(0) @binding(0) var src_tex : texture_2d<u32>;
@@ -106,7 +106,7 @@ struct Params {
@fragment fn frag_check_src_stencil(input : VertexOutputs) {
// Load the source stencil value.
let src_val : u32 = textureLoad(
src_tex, vec2<u32>(input.position.xy) - params.origin, 0u)[0];
src_tex, vec2u(input.position.xy) - params.origin, 0u)[0];
// Discard it if it doesn't contain the stencil reference.
if ((src_val & input.stencil_val) == 0u) {

View File

@@ -33,19 +33,19 @@ constexpr char kBlitToDepthShaders[] = R"(
@vertex fn vert_fullscreen_quad(
@builtin(vertex_index) vertex_index : u32,
) -> @builtin(position) vec4<f32> {
const pos = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 3.0, -1.0),
vec2<f32>(-1.0, 3.0));
return vec4<f32>(pos[vertex_index], 0.0, 1.0);
) -> @builtin(position) vec4f {
const pos = array(
vec2f(-1.0, -1.0),
vec2f( 3.0, -1.0),
vec2f(-1.0, 3.0));
return vec4f(pos[vertex_index], 0.0, 1.0);
}
@group(0) @binding(0) var src_tex : texture_depth_2d;
// Load the depth value and return it as the frag_depth.
@fragment fn blit_to_depth(@builtin(position) position : vec4<f32>) -> @builtin(frag_depth) f32 {
return textureLoad(src_tex, vec2<u32>(position.xy), 0);
@fragment fn blit_to_depth(@builtin(position) position : vec4f) -> @builtin(frag_depth) f32 {
return textureLoad(src_tex, vec2u(position.xy), 0);
}
)";

View File

@@ -50,8 +50,8 @@ static const char sCopyForBrowserShader[] = R"(
};
struct Uniforms { // offset align size
scale: vec2<f32>, // 0 8 8
offset: vec2<f32>, // 8 8 8
scale: vec2f, // 0 8 8
offset: vec2f, // 8 8 8
steps_mask: u32, // 16 4 4
// implicit padding; // 20 12
conversion_matrix: mat3x3<f32>, // 32 16 48
@@ -63,8 +63,8 @@ static const char sCopyForBrowserShader[] = R"(
@binding(0) @group(0) var<uniform> uniforms : Uniforms;
struct VertexOutputs {
@location(0) texcoords : vec2<f32>,
@builtin(position) position : vec4<f32>,
@location(0) texcoords : vec2f,
@builtin(position) position : vec4f,
};
// Chromium uses unified equation to construct gamma decoding function
@@ -89,13 +89,13 @@ static const char sCopyForBrowserShader[] = R"(
fn vs_main(
@builtin(vertex_index) VertexIndex : u32
) -> VertexOutputs {
var texcoord = array<vec2<f32>, 3>(
vec2<f32>(-0.5, 0.0),
vec2<f32>( 1.5, 0.0),
vec2<f32>( 0.5, 2.0));
var texcoord = array(
vec2f(-0.5, 0.0),
vec2f( 1.5, 0.0),
vec2f( 0.5, 2.0));
var output : VertexOutputs;
output.position = vec4<f32>((texcoord[VertexIndex] * 2.0 - vec2<f32>(1.0, 1.0)), 0.0, 1.0);
output.position = vec4f((texcoord[VertexIndex] * 2.0 - vec2f(1.0, 1.0)), 0.0, 1.0);
output.texcoords = texcoord[VertexIndex] * uniforms.scale + uniforms.offset;
return output;
@@ -109,15 +109,15 @@ static const char sCopyForBrowserShader[] = R"(
// Resource used in copyExternalTexture entry point only.
@binding(2) @group(0) var mySourceExternalTexture: texture_external;
fn discardIfOutsideOfCopy(texcoord : vec2<f32>) {
fn discardIfOutsideOfCopy(texcoord : vec2f) {
var clampedTexcoord =
clamp(texcoord, vec2<f32>(0.0, 0.0), vec2<f32>(1.0, 1.0));
clamp(texcoord, vec2f(0.0, 0.0), vec2f(1.0, 1.0));
if (!all(clampedTexcoord == texcoord)) {
discard;
}
}
fn transform(srcColor : vec4<f32>) -> vec4<f32> {
fn transform(srcColor : vec4f) -> vec4f {
var color = srcColor;
let kUnpremultiplyStep = 0x01u;
let kDecodeToLinearStep = 0x02u;
@@ -132,14 +132,14 @@ static const char sCopyForBrowserShader[] = R"(
// This step is exclusive with clear src alpha to one step.
if (bool(uniforms.steps_mask & kUnpremultiplyStep)) {
if (color.a != 0.0) {
color = vec4<f32>(color.rgb / color.a, color.a);
color = vec4f(color.rgb / color.a, color.a);
}
}
// Linearize the source color using the source color spaces
// transfer function if it is non-linear.
if (bool(uniforms.steps_mask & kDecodeToLinearStep)) {
color = vec4<f32>(gamma_conversion(color.r, uniforms.gamma_decoding_params),
color = vec4f(gamma_conversion(color.r, uniforms.gamma_decoding_params),
gamma_conversion(color.g, uniforms.gamma_decoding_params),
gamma_conversion(color.b, uniforms.gamma_decoding_params),
color.a);
@@ -149,13 +149,13 @@ static const char sCopyForBrowserShader[] = R"(
// multiplying by a 3x3 matrix. Calculate transformFromXYZD50 * transformToXYZD50
// in CPU side and upload the final result in uniforms.
if (bool(uniforms.steps_mask & kConvertToDstGamutStep)) {
color = vec4<f32>(uniforms.conversion_matrix * color.rgb, color.a);
color = vec4f(uniforms.conversion_matrix * color.rgb, color.a);
}
// Encode that color using the inverse of the destination color
// spaces transfer function if it is non-linear.
if (bool(uniforms.steps_mask & kEncodeToGammaStep)) {
color = vec4<f32>(gamma_conversion(color.r, uniforms.gamma_encoding_params),
color = vec4f(gamma_conversion(color.r, uniforms.gamma_encoding_params),
gamma_conversion(color.g, uniforms.gamma_encoding_params),
gamma_conversion(color.b, uniforms.gamma_encoding_params),
color.a);
@@ -164,12 +164,12 @@ static const char sCopyForBrowserShader[] = R"(
// Premultiply step.
// This step is exclusive with clear src alpha to one step.
if (bool(uniforms.steps_mask & kPremultiplyStep)) {
color = vec4<f32>(color.rgb * color.a, color.a);
color = vec4f(color.rgb * color.a, color.a);
}
// Decode for copying from non-srgb formats to srgb formats
if (bool(uniforms.steps_mask & kDecodeForSrgbDstFormat)) {
color = vec4<f32>(gamma_conversion(color.r, uniforms.gamma_decoding_for_dst_srgb_params),
color = vec4f(gamma_conversion(color.r, uniforms.gamma_decoding_for_dst_srgb_params),
gamma_conversion(color.g, uniforms.gamma_decoding_for_dst_srgb_params),
gamma_conversion(color.b, uniforms.gamma_decoding_for_dst_srgb_params),
color.a);
@@ -185,8 +185,8 @@ static const char sCopyForBrowserShader[] = R"(
}
@fragment
fn copyTexture(@location(0) texcoord : vec2<f32>
) -> @location(0) vec4<f32> {
fn copyTexture(@location(0) texcoord : vec2f
) -> @location(0) vec4f {
var color = textureSample(mySourceTexture, mySampler, texcoord);
// TODO(crbug.com/tint/1723): Discard before sampling should be valid.
@@ -196,8 +196,8 @@ static const char sCopyForBrowserShader[] = R"(
}
@fragment
fn copyExternalTexture(@location(0) texcoord : vec2<f32>
) -> @location(0) vec4<f32> {
fn copyExternalTexture(@location(0) texcoord : vec2f
) -> @location(0) vec4f {
var color = textureSampleBaseClampToEdge(mySourceExternalTexture, mySampler, texcoord);
// TODO(crbug.com/tint/1723): Discard before sampling should be valid.

View File

@@ -131,7 +131,7 @@ static const char sRenderValidationShaderSource[] = R"(
}
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) id : vec3<u32>) {
fn main(@builtin(global_invocation_id) id : vec3u) {
if (id.x >= batch.numDraws) {
return;
}

View File

@@ -67,7 +67,7 @@ static const char sConvertTimestampsToNanoseconds[] = R"(
const sizeofTimestamp : u32 = 8u;
@compute @workgroup_size(8, 1, 1)
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3<u32>) {
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3u) {
if (GlobalInvocationID.x >= params.count) { return; }
var index = GlobalInvocationID.x + params.offset / sizeofTimestamp;