Skip to content

Commit 02be18c

Browse files
authored
Use short vec and mat types (#381)
I'm guessing these are more popular and at glance give a most positive first impressions of WGSL
1 parent 92bb1a3 commit 02be18c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+265
-265
lines changed

sample/a-buffer/composite.wgsl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Uniforms {
2-
modelViewProjectionMatrix: mat4x4<f32>,
2+
modelViewProjectionMatrix: mat4x4f,
33
maxStorableFragments: u32,
44
targetWidth: u32,
55
};
@@ -14,7 +14,7 @@ struct Heads {
1414
};
1515

1616
struct LinkedListElement {
17-
color: vec4<f32>,
17+
color: vec4f,
1818
depth: f32,
1919
next: u32
2020
};
@@ -30,8 +30,8 @@ struct LinkedList {
3030

3131
// Output a full screen quad
3232
@vertex
33-
fn main_vs(@builtin(vertex_index) vertIndex: u32) -> @builtin(position) vec4<f32> {
34-
const position = array<vec2<f32>, 6>(
33+
fn main_vs(@builtin(vertex_index) vertIndex: u32) -> @builtin(position) vec4f {
34+
const position = array<vec2f, 6>(
3535
vec2(-1.0, -1.0),
3636
vec2(1.0, -1.0),
3737
vec2(1.0, 1.0),
@@ -44,8 +44,8 @@ fn main_vs(@builtin(vertex_index) vertIndex: u32) -> @builtin(position) vec4<f32
4444
}
4545

4646
@fragment
47-
fn main_fs(@builtin(position) position: vec4<f32>) -> @location(0) vec4<f32> {
48-
let fragCoords = vec2<i32>(position.xy);
47+
fn main_fs(@builtin(position) position: vec4f) -> @location(0) vec4f {
48+
let fragCoords = vec2i(position.xy);
4949
let headsIndex = u32(fragCoords.y - sliceInfo.sliceStartY) * uniforms.targetWidth + u32(fragCoords.x);
5050

5151
// The maximum layers we can process for any pixel

sample/a-buffer/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const indexBuffer = device.createBuffer({
6262
}
6363

6464
// Uniforms contains:
65-
// * modelViewProjectionMatrix: mat4x4<f32>
65+
// * modelViewProjectionMatrix: mat4x4f
6666
// * maxStorableFragments: u32
6767
// * targetWidth: u32
6868
const uniformsSize = roundUp(
@@ -365,7 +365,7 @@ const configure = () => {
365365
const averageLayersPerFragment = 4;
366366

367367
// Each element stores
368-
// * color : vec4<f32>
368+
// * color : vec4f
369369
// * depth : f32
370370
// * index of next element in the list : u32
371371
const linkedListElementSize =

sample/a-buffer/opaque.wgsl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
struct Uniforms {
2-
modelViewProjectionMatrix: mat4x4<f32>,
2+
modelViewProjectionMatrix: mat4x4f,
33
};
44

55
@binding(0) @group(0) var<uniform> uniforms: Uniforms;
66

77
struct VertexOutput {
8-
@builtin(position) position: vec4<f32>,
8+
@builtin(position) position: vec4f,
99
@location(0) @interpolate(flat) instance: u32
1010
};
1111

1212
@vertex
13-
fn main_vs(@location(0) position: vec4<f32>, @builtin(instance_index) instance: u32) -> VertexOutput {
13+
fn main_vs(@location(0) position: vec4f, @builtin(instance_index) instance: u32) -> VertexOutput {
1414
var output: VertexOutput;
1515

1616
// distribute instances into a staggered 4x4 grid
@@ -30,8 +30,8 @@ fn main_vs(@location(0) position: vec4<f32>, @builtin(instance_index) instance:
3030
}
3131

3232
@fragment
33-
fn main_fs(@location(0) @interpolate(flat) instance: u32) -> @location(0) vec4<f32> {
34-
const colors = array<vec3<f32>,6>(
33+
fn main_fs(@location(0) @interpolate(flat) instance: u32) -> @location(0) vec4f {
34+
const colors = array<vec3f,6>(
3535
vec3(1.0, 0.0, 0.0),
3636
vec3(0.0, 1.0, 0.0),
3737
vec3(0.0, 0.0, 1.0),

sample/a-buffer/translucent.wgsl

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Uniforms {
2-
modelViewProjectionMatrix: mat4x4<f32>,
2+
modelViewProjectionMatrix: mat4x4f,
33
maxStorableFragments: u32,
44
targetWidth: u32,
55
};
@@ -14,7 +14,7 @@ struct Heads {
1414
};
1515

1616
struct LinkedListElement {
17-
color: vec4<f32>,
17+
color: vec4f,
1818
depth: f32,
1919
next: u32
2020
};
@@ -30,12 +30,12 @@ struct LinkedList {
3030
@binding(4) @group(0) var<uniform> sliceInfo: SliceInfo;
3131

3232
struct VertexOutput {
33-
@builtin(position) position: vec4<f32>,
33+
@builtin(position) position: vec4f,
3434
@location(0) @interpolate(flat) instance: u32
3535
};
3636

3737
@vertex
38-
fn main_vs(@location(0) position: vec4<f32>, @builtin(instance_index) instance: u32) -> VertexOutput {
38+
fn main_vs(@location(0) position: vec4f, @builtin(instance_index) instance: u32) -> VertexOutput {
3939
var output: VertexOutput;
4040

4141
// distribute instances into a staggered 4x4 grid
@@ -56,8 +56,8 @@ fn main_vs(@location(0) position: vec4<f32>, @builtin(instance_index) instance:
5656
}
5757

5858
@fragment
59-
fn main_fs(@builtin(position) position: vec4<f32>, @location(0) @interpolate(flat) instance: u32) {
60-
const colors = array<vec3<f32>,6>(
59+
fn main_fs(@builtin(position) position: vec4f, @location(0) @interpolate(flat) instance: u32) {
60+
const colors = array<vec3f,6>(
6161
vec3(1.0, 0.0, 0.0),
6262
vec3(0.0, 1.0, 0.0),
6363
vec3(0.0, 0.0, 1.0),
@@ -66,7 +66,7 @@ fn main_fs(@builtin(position) position: vec4<f32>, @location(0) @interpolate(fla
6666
vec3(0.0, 1.0, 1.0),
6767
);
6868

69-
let fragCoords = vec2<i32>(position.xy);
69+
let fragCoords = vec2i(position.xy);
7070
let opaqueDepth = textureLoad(opaqueDepthTexture, fragCoords, 0);
7171

7272
// reject fragments behind opaque objects

sample/animometer/animometer.wgsl

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ struct Uniforms {
1414
@binding(0) @group(1) var<uniform> uniforms : Uniforms;
1515

1616
struct VertexOutput {
17-
@builtin(position) Position : vec4<f32>,
18-
@location(0) v_color : vec4<f32>,
17+
@builtin(position) Position : vec4f,
18+
@location(0) v_color : vec4f,
1919
}
2020

2121
@vertex
2222
fn vert_main(
23-
@location(0) position : vec4<f32>,
24-
@location(1) color : vec4<f32>
23+
@location(0) position : vec4f,
24+
@location(1) color : vec4f
2525
) -> VertexOutput {
2626
var fade = (uniforms.scalarOffset + time.value * uniforms.scalar / 10.0) % 1.0;
2727
if (fade < 0.5) {
@@ -44,6 +44,6 @@ fn vert_main(
4444
}
4545

4646
@fragment
47-
fn frag_main(@location(0) v_color : vec4<f32>) -> @location(0) vec4<f32> {
47+
fn frag_main(@location(0) v_color : vec4f) -> @location(0) vec4f {
4848
return v_color;
4949
}

sample/bitonicSort/bitonicCompute.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ fn local_compare_and_swap(idx_before: u32, idx_after: u32) {
3636
}
3737
3838
// invoke_id goes from 0 to workgroupSize
39-
fn get_flip_indices(invoke_id: u32, block_height: u32) -> vec2<u32> {
39+
fn get_flip_indices(invoke_id: u32, block_height: u32) -> vec2u {
4040
// Caculate index offset (i.e move indices into correct block)
4141
let block_offset: u32 = ((2 * invoke_id) / block_height) * block_height;
4242
let half_height = block_height / 2;
4343
// Calculate index spacing
44-
var idx: vec2<u32> = vec2<u32>(
44+
var idx: vec2u = vec2u(
4545
invoke_id % half_height, block_height - (invoke_id % half_height) - 1,
4646
);
4747
idx.x += block_offset;
4848
idx.y += block_offset;
4949
return idx;
5050
}
5151
52-
fn get_disperse_indices(invoke_id: u32, block_height: u32) -> vec2<u32> {
52+
fn get_disperse_indices(invoke_id: u32, block_height: u32) -> vec2u {
5353
var block_offset: u32 = ((2 * invoke_id) / block_height) * block_height;
5454
let half_height = block_height / 2;
55-
var idx: vec2<u32> = vec2<u32>(
55+
var idx: vec2u = vec2u(
5656
invoke_id % half_height, (invoke_id % half_height) + half_height
5757
);
5858
idx.x += block_offset;
@@ -76,9 +76,9 @@ const ALGO_GLOBAL_FLIP = 3;
7676
// Our compute shader will execute specified # of invocations or elements / 2 invocations
7777
@compute @workgroup_size(${workgroupSize}, 1, 1)
7878
fn computeMain(
79-
@builtin(global_invocation_id) global_id: vec3<u32>,
80-
@builtin(local_invocation_id) local_id: vec3<u32>,
81-
@builtin(workgroup_id) workgroup_id: vec3<u32>,
79+
@builtin(global_invocation_id) global_id: vec3u,
80+
@builtin(local_invocation_id) local_id: vec3u,
81+
@builtin(workgroup_id) workgroup_id: vec3u,
8282
) {
8383
8484
let offset = ${workgroupSize} * 2 * workgroup_id.x;

sample/bitonicSort/bitonicDisplay.frag.wgsl

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ struct FragmentUniforms {
1111
}
1212

1313
struct VertexOutput {
14-
@builtin(position) Position: vec4<f32>,
15-
@location(0) fragUV: vec2<f32>
14+
@builtin(position) Position: vec4f,
15+
@location(0) fragUV: vec2f
1616
}
1717

1818
// Uniforms from compute shader
@@ -22,13 +22,13 @@ struct VertexOutput {
2222
@group(1) @binding(0) var<uniform> fragment_uniforms: FragmentUniforms;
2323

2424
@fragment
25-
fn frag_main(input: VertexOutput) -> @location(0) vec4<f32> {
26-
var uv: vec2<f32> = vec2<f32>(
25+
fn frag_main(input: VertexOutput) -> @location(0) vec4f {
26+
var uv: vec2f = vec2f(
2727
input.fragUV.x * uniforms.width,
2828
input.fragUV.y * uniforms.height
2929
);
3030

31-
var pixel: vec2<u32> = vec2<u32>(
31+
var pixel: vec2u = vec2u(
3232
u32(floor(uv.x)),
3333
u32(floor(uv.y)),
3434
);
@@ -41,16 +41,16 @@ fn frag_main(input: VertexOutput) -> @location(0) vec4<f32> {
4141
if (fragment_uniforms.highlight == 1) {
4242
return select(
4343
//If element is above halfHeight, highlight green
44-
vec4<f32>(vec3<f32>(0.0, 1.0 - subtracter, 0.0).rgb, 1.0),
44+
vec4f(vec3f(0.0, 1.0 - subtracter, 0.0).rgb, 1.0),
4545
//If element is below halfheight, highlight red
46-
vec4<f32>(vec3<f32>(1.0 - subtracter, 0.0, 0.0).rgb, 1.0),
46+
vec4f(vec3f(1.0 - subtracter, 0.0, 0.0).rgb, 1.0),
4747
elementIndex % uniforms.blockHeight < uniforms.blockHeight / 2
4848
);
4949
}
5050

51-
var color: vec3<f32> = vec3f(
51+
var color: vec3f = vec3f(
5252
1.0 - subtracter
5353
);
5454

55-
return vec4<f32>(color.rgb, 1.0);
55+
return vec4f(color.rgb, 1.0);
5656
}

sample/cameras/cube.wgsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Uniforms {
2-
modelViewProjectionMatrix : mat4x4<f32>,
2+
modelViewProjectionMatrix : mat4x4f,
33
}
44

55
@group(0) @binding(0) var<uniform> uniforms : Uniforms;

sample/computeBoids/sprite.wgsl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
struct VertexOutput {
2-
@builtin(position) position : vec4<f32>,
3-
@location(4) color : vec4<f32>,
2+
@builtin(position) position : vec4f,
3+
@location(4) color : vec4f,
44
}
55

66
@vertex
77
fn vert_main(
8-
@location(0) a_particlePos : vec2<f32>,
9-
@location(1) a_particleVel : vec2<f32>,
10-
@location(2) a_pos : vec2<f32>
8+
@location(0) a_particlePos : vec2f,
9+
@location(1) a_particleVel : vec2f,
10+
@location(2) a_pos : vec2f
1111
) -> VertexOutput {
1212
let angle = -atan2(a_particleVel.x, a_particleVel.y);
1313
let pos = vec2(
@@ -26,6 +26,6 @@ fn vert_main(
2626
}
2727

2828
@fragment
29-
fn frag_main(@location(4) color : vec4<f32>) -> @location(0) vec4<f32> {
29+
fn frag_main(@location(4) color : vec4f) -> @location(0) vec4f {
3030
return color;
3131
}

sample/computeBoids/updateSprites.wgsl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Particle {
2-
pos : vec2<f32>,
3-
vel : vec2<f32>,
2+
pos : vec2f,
3+
vel : vec2f,
44
}
55
struct SimParams {
66
deltaT : f32,
@@ -20,7 +20,7 @@ struct Particles {
2020

2121
// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
2222
@compute @workgroup_size(64)
23-
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3<u32>) {
23+
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3u) {
2424
var index = GlobalInvocationID.x;
2525

2626
var vPos = particlesA.particles[index].pos;
@@ -30,8 +30,8 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3<u32>) {
3030
var colVel = vec2(0.0);
3131
var cMassCount = 0u;
3232
var cVelCount = 0u;
33-
var pos : vec2<f32>;
34-
var vel : vec2<f32>;
33+
var pos : vec2f;
34+
var vel : vec2f;
3535

3636
for (var i = 0u; i < arrayLength(&particlesA.particles); i++) {
3737
if (i == index) {

sample/cubemap/sampleCubemap.frag.wgsl

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
@fragment
55
fn main(
6-
@location(0) fragUV: vec2<f32>,
7-
@location(1) fragPosition: vec4<f32>
8-
) -> @location(0) vec4<f32> {
6+
@location(0) fragUV: vec2f,
7+
@location(1) fragPosition: vec4f
8+
) -> @location(0) vec4f {
99
// Our camera and the skybox cube are both centered at (0, 0, 0)
1010
// so we can use the cube geomtry position to get viewing vector to sample the cube texture.
1111
// The magnitude of the vector doesn't matter.

0 commit comments

Comments
 (0)