mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Clean up unneded type annotations in vec
Now that wgsl-analyzer 0.6 is released, most explicit type annotations on vec can be dropped (the exception being when it is a type conversion). Also changes mix to select when the selector is actually boolean.
This commit is contained in:
parent
7d5063b187
commit
94a310a245
|
@ -69,7 +69,7 @@ fn main(
|
|||
var y1 = 0;
|
||||
if element_ix < config.n_drawobj {
|
||||
let draw_monoid = draw_monoids[element_ix];
|
||||
var clip_bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9);
|
||||
var clip_bbox = vec4(-1e9, -1e9, 1e9, 1e9);
|
||||
if draw_monoid.clip_ix > 0u {
|
||||
clip_bbox = clip_bbox_buf[draw_monoid.clip_ix - 1u];
|
||||
}
|
||||
|
@ -79,10 +79,10 @@ fn main(
|
|||
// TODO check this is true
|
||||
|
||||
let path_bbox = path_bbox_buf[draw_monoid.path_ix];
|
||||
let pb = vec4<f32>(vec4<i32>(path_bbox.x0, path_bbox.y0, path_bbox.x1, path_bbox.y1));
|
||||
let pb = vec4<f32>(vec4(path_bbox.x0, path_bbox.y0, path_bbox.x1, path_bbox.y1));
|
||||
let bbox_raw = bbox_intersect(clip_bbox, pb);
|
||||
// TODO(naga): clunky expression a workaround for broken lhs swizzle
|
||||
let bbox = vec4<f32>(bbox_raw.xy, max(bbox_raw.xy, bbox_raw.zw));
|
||||
let bbox = vec4(bbox_raw.xy, max(bbox_raw.xy, bbox_raw.zw));
|
||||
|
||||
intersected_bbox[element_ix] = bbox;
|
||||
x0 = i32(floor(bbox.x * SX));
|
||||
|
|
|
@ -110,7 +110,7 @@ fn main(
|
|||
}
|
||||
}
|
||||
let b = sh_bic[ix].b;
|
||||
var bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9);
|
||||
var bbox = vec4(-1e9, -1e9, 1e9, 1e9);
|
||||
if sp < b {
|
||||
let el = clip_els[ix * WG_SIZE + b - sp - 1u];
|
||||
sh_stack[local_id.x] = el.parent_ix;
|
||||
|
@ -134,9 +134,9 @@ fn main(
|
|||
sh_bic[local_id.x] = bic;
|
||||
if is_push {
|
||||
let path_bbox = path_bboxes[inp];
|
||||
bbox = vec4<f32>(f32(path_bbox.x0), f32(path_bbox.y0), f32(path_bbox.x1), f32(path_bbox.y1));
|
||||
bbox = vec4(f32(path_bbox.x0), f32(path_bbox.y0), f32(path_bbox.x1), f32(path_bbox.y1));
|
||||
} else {
|
||||
bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9);
|
||||
bbox = vec4(-1e9, -1e9, 1e9, 1e9);
|
||||
}
|
||||
var inbase = 0u;
|
||||
for (var i = 0u; i < firstTrailingBit(WG_SIZE) - 1u; i += 1u) {
|
||||
|
@ -193,7 +193,7 @@ fn main(
|
|||
} else if grandparent + i32(stack_size) >= 0 {
|
||||
bbox = sh_stack_bbox[i32(WG_SIZE) + grandparent];
|
||||
} else {
|
||||
bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9);
|
||||
bbox = vec4(-1e9, -1e9, 1e9, 1e9);
|
||||
}
|
||||
}
|
||||
clip_bboxes[global_id.x] = bbox;
|
||||
|
|
|
@ -375,9 +375,9 @@ fn main(
|
|||
let m1 = bitcast<f32>(info[di + 2u]);
|
||||
let m2 = bitcast<f32>(info[di + 3u]);
|
||||
let m3 = bitcast<f32>(info[di + 4u]);
|
||||
rad.matrx = vec4<f32>(m0, m1, m2, m3);
|
||||
rad.xlat = vec2<f32>(bitcast<f32>(info[di + 5u]), bitcast<f32>(info[di + 6u]));
|
||||
rad.c1 = vec2<f32>(bitcast<f32>(info[di + 7u]), bitcast<f32>(info[di + 8u]));
|
||||
rad.matrx = vec4(m0, m1, m2, m3);
|
||||
rad.xlat = vec2(bitcast<f32>(info[di + 5u]), bitcast<f32>(info[di + 6u]));
|
||||
rad.c1 = vec2(bitcast<f32>(info[di + 7u]), bitcast<f32>(info[di + 8u]));
|
||||
rad.ra = bitcast<f32>(info[di + 9u]);
|
||||
rad.roff = bitcast<f32>(info[di + 10u]);
|
||||
write_rad_grad(rad);
|
||||
|
|
|
@ -44,8 +44,8 @@ fn read_transform(transform_base: u32, ix: u32) -> Transform {
|
|||
let c3 = bitcast<f32>(scene[base + 3u]);
|
||||
let c4 = bitcast<f32>(scene[base + 4u]);
|
||||
let c5 = bitcast<f32>(scene[base + 5u]);
|
||||
let matrx = vec4<f32>(c0, c1, c2, c3);
|
||||
let translate = vec2<f32>(c4, c5);
|
||||
let matrx = vec4(c0, c1, c2, c3);
|
||||
let translate = vec2(c4, c5);
|
||||
return Transform(matrx, translate);
|
||||
}
|
||||
|
||||
|
|
|
@ -70,9 +70,9 @@ fn read_rad_grad(cmd_ix: u32) -> CmdRadGrad {
|
|||
let m1 = bitcast<f32>(ptcl[cmd_ix + 3u]);
|
||||
let m2 = bitcast<f32>(ptcl[cmd_ix + 4u]);
|
||||
let m3 = bitcast<f32>(ptcl[cmd_ix + 5u]);
|
||||
let matrx = vec4<f32>(m0, m1, m2, m3);
|
||||
let xlat = vec2<f32>(bitcast<f32>(ptcl[cmd_ix + 6u]), bitcast<f32>(ptcl[cmd_ix + 7u]));
|
||||
let c1 = vec2<f32>(bitcast<f32>(ptcl[cmd_ix + 8u]), bitcast<f32>(ptcl[cmd_ix + 9u]));
|
||||
let matrx = vec4(m0, m1, m2, m3);
|
||||
let xlat = vec2(bitcast<f32>(ptcl[cmd_ix + 6u]), bitcast<f32>(ptcl[cmd_ix + 7u]));
|
||||
let c1 = vec2(bitcast<f32>(ptcl[cmd_ix + 8u]), bitcast<f32>(ptcl[cmd_ix + 9u]));
|
||||
let ra = bitcast<f32>(ptcl[cmd_ix + 10u]);
|
||||
let roff = bitcast<f32>(ptcl[cmd_ix + 11u]);
|
||||
return CmdRadGrad(index, matrx, xlat, c1, ra, roff);
|
||||
|
@ -137,10 +137,10 @@ fn stroke_path(seg: u32, half_width: f32, xy: vec2<f32>) -> array<f32, PIXELS_PE
|
|||
while segment_ix != 0u {
|
||||
let segment = segments[segment_ix];
|
||||
let delta = segment.delta;
|
||||
let dpos0 = xy + vec2<f32>(0.5, 0.5) - segment.origin;
|
||||
let dpos0 = xy + vec2(0.5, 0.5) - segment.origin;
|
||||
let scale = 1.0 / dot(delta, delta);
|
||||
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
|
||||
let dpos = vec2<f32>(dpos0.x + f32(i), dpos0.y);
|
||||
let dpos = vec2(dpos0.x + f32(i), dpos0.y);
|
||||
let t = clamp(dot(dpos, delta) * scale, 0.0, 1.0);
|
||||
// performance idea: hoist sqrt out of loop
|
||||
df[i] = min(df[i], length(delta * t - dpos));
|
||||
|
@ -161,7 +161,7 @@ fn main(
|
|||
@builtin(workgroup_id) wg_id: vec3<u32>,
|
||||
) {
|
||||
let tile_ix = wg_id.y * config.width_in_tiles + wg_id.x;
|
||||
let xy = vec2<f32>(f32(global_id.x * PIXELS_PER_THREAD), f32(global_id.y));
|
||||
let xy = vec2(f32(global_id.x * PIXELS_PER_THREAD), f32(global_id.y));
|
||||
#ifdef full
|
||||
var rgba: array<vec4<f32>, PIXELS_PER_THREAD>;
|
||||
var blend_stack: array<array<u32, BLEND_STACK_SPLIT>, PIXELS_PER_THREAD>;
|
||||
|
@ -213,7 +213,7 @@ fn main(
|
|||
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
|
||||
let my_d = d + lin.line_x * f32(i);
|
||||
let x = i32(round(clamp(my_d, 0.0, 1.0) * f32(GRADIENT_WIDTH - 1)));
|
||||
let fg_rgba = textureLoad(gradients, vec2<i32>(x, i32(lin.index)), 0);
|
||||
let fg_rgba = textureLoad(gradients, vec2(x, i32(lin.index)), 0);
|
||||
let fg_i = fg_rgba * area[i];
|
||||
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
|
||||
}
|
||||
|
@ -223,14 +223,14 @@ fn main(
|
|||
case 7u: {
|
||||
let rad = read_rad_grad(cmd_ix);
|
||||
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
|
||||
let my_xy = vec2<f32>(xy.x + f32(i), xy.y);
|
||||
let my_xy = vec2(xy.x + f32(i), xy.y);
|
||||
// TODO: can hoist y, but for now stick to piet-gpu
|
||||
let xy_xformed = rad.matrx.xz * my_xy.x + rad.matrx.yw * my_xy.y - rad.xlat;
|
||||
let ba = dot(xy_xformed, rad.c1);
|
||||
let ca = rad.ra * dot(xy_xformed, xy_xformed);
|
||||
let t = sqrt(ba * ba + ca) - ba - rad.roff;
|
||||
let x = i32(round(clamp(t, 0.0, 1.0) * f32(GRADIENT_WIDTH - 1)));
|
||||
let fg_rgba = textureLoad(gradients, vec2<i32>(x, i32(rad.index)), 0);
|
||||
let fg_rgba = textureLoad(gradients, vec2(x, i32(rad.index)), 0);
|
||||
let fg_i = fg_rgba * area[i];
|
||||
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ fn main(
|
|||
if clip_depth < BLEND_STACK_SPLIT {
|
||||
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
|
||||
blend_stack[clip_depth][i] = pack4x8unorm(rgba[i]);
|
||||
rgba[i] = vec4<f32>(0.0);
|
||||
rgba[i] = vec4(0.0);
|
||||
}
|
||||
} else {
|
||||
// TODO: spill to memory
|
||||
|
@ -277,7 +277,7 @@ fn main(
|
|||
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
|
||||
let fg = rgba[i];
|
||||
let a_inv = 1.0 / (fg.a + 1e-6);
|
||||
let rgba_sep = vec4<f32>(fg.r * a_inv, fg.g * a_inv, fg.b * a_inv, fg.a);
|
||||
let rgba_sep = vec4(fg.r * a_inv, fg.g * a_inv, fg.b * a_inv, fg.a);
|
||||
let bytes = pack4x8unorm(rgba_sep);
|
||||
output[out_ix + i] = bytes;
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ fn main(
|
|||
let tile = tiles[tile_ix];
|
||||
let area = fill_path(tile, xy);
|
||||
|
||||
let bytes = pack4x8unorm(vec4<f32>(area[0], area[1], area[2], area[3]));
|
||||
let bytes = pack4x8unorm(vec4(area[0], area[1], area[2], area[3]));
|
||||
let out_ix = global_id.y * (config.width_in_tiles * 4u) + global_id.x;
|
||||
output[out_ix] = bytes;
|
||||
#endif
|
||||
|
|
|
@ -36,14 +36,14 @@ var<private> pathdata_base: u32;
|
|||
fn read_f32_point(ix: u32) -> vec2<f32> {
|
||||
let x = bitcast<f32>(scene[pathdata_base + ix]);
|
||||
let y = bitcast<f32>(scene[pathdata_base + ix + 1u]);
|
||||
return vec2<f32>(x, y);
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
fn read_i16_point(ix: u32) -> vec2<f32> {
|
||||
let raw = scene[pathdata_base + ix];
|
||||
let x = f32(i32(raw << 16u) >> 16u);
|
||||
let y = f32(i32(raw) >> 16u);
|
||||
return vec2<f32>(x, y);
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
#ifndef cubics_out
|
||||
|
@ -276,7 +276,7 @@ fn main(
|
|||
tile_seg.delta = dp;
|
||||
var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx);
|
||||
if xymin.x < tile_x0 {
|
||||
let p = vec2<f32>(tile_x0, y_edge);
|
||||
let p = vec2(tile_x0, y_edge);
|
||||
if dp.x < 0.0 {
|
||||
tile_seg.delta = p - lp0;
|
||||
} else {
|
||||
|
|
|
@ -228,7 +228,7 @@ fn main(
|
|||
tile_seg.delta = dp;
|
||||
var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx);
|
||||
if xymin.x < tile_x0 {
|
||||
let p = vec2<f32>(tile_x0, y_edge);
|
||||
let p = vec2(tile_x0, y_edge);
|
||||
if dp.x < 0.0 {
|
||||
tile_seg.delta = p - lp0;
|
||||
} else {
|
||||
|
|
|
@ -75,14 +75,14 @@ var<private> pathdata_base: u32;
|
|||
fn read_f32_point(ix: u32) -> vec2<f32> {
|
||||
let x = bitcast<f32>(scene[pathdata_base + ix]);
|
||||
let y = bitcast<f32>(scene[pathdata_base + ix + 1u]);
|
||||
return vec2<f32>(x, y);
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
fn read_i16_point(ix: u32) -> vec2<f32> {
|
||||
let raw = scene[pathdata_base + ix];
|
||||
let x = f32(i32(raw << 16u) >> 16u);
|
||||
let y = f32(i32(raw) >> 16u);
|
||||
return vec2<f32>(x, y);
|
||||
return vec2(x, y);
|
||||
}
|
||||
|
||||
struct Transform {
|
||||
|
@ -98,8 +98,8 @@ fn read_transform(transform_base: u32, ix: u32) -> Transform {
|
|||
let c3 = bitcast<f32>(scene[base + 3u]);
|
||||
let c4 = bitcast<f32>(scene[base + 4u]);
|
||||
let c5 = bitcast<f32>(scene[base + 5u]);
|
||||
let matrx = vec4<f32>(c0, c1, c2, c3);
|
||||
let translate = vec2<f32>(c4, c5);
|
||||
let matrx = vec4(c0, c1, c2, c3);
|
||||
let translate = vec2(c4, c5);
|
||||
return Transform(matrx, translate);
|
||||
}
|
||||
|
||||
|
@ -162,10 +162,9 @@ fn main(
|
|||
}
|
||||
}
|
||||
let transform = read_transform(config.transform_base, tm.trans_ix);
|
||||
//let transform = Transform(vec4<f32>(1.0, 0.0, 0.0, 1.0), vec2<f32>());
|
||||
p0 = transform_apply(transform, p0);
|
||||
p1 = transform_apply(transform, p1);
|
||||
var bbox = vec4<f32>(min(p0, p1), max(p0, p1));
|
||||
var bbox = vec4(min(p0, p1), max(p0, p1));
|
||||
// Degree-raise
|
||||
if seg_type == PATH_TAG_LINETO {
|
||||
p3 = p1;
|
||||
|
@ -173,10 +172,10 @@ fn main(
|
|||
p1 = mix(p0, p3, 1.0 / 3.0);
|
||||
} else if seg_type >= PATH_TAG_QUADTO {
|
||||
p2 = transform_apply(transform, p2);
|
||||
bbox = vec4<f32>(min(bbox.xy, p2), max(bbox.zw, p2));
|
||||
bbox = vec4(min(bbox.xy, p2), max(bbox.zw, p2));
|
||||
if seg_type == PATH_TAG_CUBICTO {
|
||||
p3 = transform_apply(transform, p3);
|
||||
bbox = vec4<f32>(min(bbox.xy, p3), max(bbox.zw, p3));
|
||||
bbox = vec4(min(bbox.xy, p3), max(bbox.zw, p3));
|
||||
} else {
|
||||
p3 = p2;
|
||||
p2 = mix(p1, p2, 1.0 / 3.0);
|
||||
|
@ -187,8 +186,8 @@ fn main(
|
|||
// See https://www.iquilezles.org/www/articles/ellipses/ellipses.htm
|
||||
// This is the correct bounding box, but we're not handling rendering
|
||||
// in the isotropic case, so it may mismatch.
|
||||
let stroke = 0.5 * linewidth * vec2<f32>(length(transform.matrx.xz), length(transform.matrx.yw));
|
||||
bbox += vec4<f32>(-stroke, stroke);
|
||||
let stroke = 0.5 * linewidth * vec2(length(transform.matrx.xz), length(transform.matrx.yw));
|
||||
bbox += vec4(-stroke, stroke);
|
||||
}
|
||||
cubics[global_id.x] = Cubic(p0, p1, p2, p3, tm.path_ix, 0u);
|
||||
// Update bounding box using atomics only. Computing a monoid is a
|
||||
|
|
|
@ -45,23 +45,23 @@ fn color_burn(cb: f32, cs: f32) -> f32 {
|
|||
}
|
||||
|
||||
fn hard_light(cb: vec3<f32>, cs: vec3<f32>) -> vec3<f32> {
|
||||
return mix(
|
||||
return select(
|
||||
screen(cb, 2.0 * cs - 1.0),
|
||||
cb * 2.0 * cs,
|
||||
vec3<f32>(cs <= vec3<f32>(0.5))
|
||||
cs <= vec3(0.5)
|
||||
);
|
||||
}
|
||||
|
||||
fn soft_light(cb: vec3<f32>, cs: vec3<f32>) -> vec3<f32> {
|
||||
let d = mix(
|
||||
let d = select(
|
||||
sqrt(cb),
|
||||
((16.0 * cb - vec3(12.0)) * cb + vec3(4.0)) * cb,
|
||||
vec3<f32>(cb <= vec3<f32>(0.25))
|
||||
((16.0 * cb - 12.0) * cb + 4.0) * cb,
|
||||
cb <= vec3(0.25)
|
||||
);
|
||||
return mix(
|
||||
cb + (2.0 * cs - vec3(1.0)) * (d - cb),
|
||||
cb - (vec3(1.0) - 2.0 * cs) * cb * (vec3(1.0) - cb),
|
||||
vec3<f32>(cs <= vec3<f32>(0.5))
|
||||
return select(
|
||||
cb + (2.0 * cs - 1.0) * (d - cb),
|
||||
cb - (1.0 - 2.0 * cs) * cb * (1.0 - cb),
|
||||
(cs <= vec3(0.5))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ fn sat(c: vec3<f32>) -> f32 {
|
|||
}
|
||||
|
||||
fn lum(c: vec3<f32>) -> f32 {
|
||||
let f = vec3<f32>(0.3, 0.59, 0.11);
|
||||
let f = vec3(0.3, 0.59, 0.11);
|
||||
return dot(c, f);
|
||||
}
|
||||
|
||||
|
@ -133,13 +133,13 @@ fn set_sat(c: vec3<f32>, s: f32) -> vec3<f32> {
|
|||
}
|
||||
}
|
||||
}
|
||||
return vec3<f32>(r, g, b);
|
||||
return vec3(r, g, b);
|
||||
}
|
||||
|
||||
// Blends two RGB colors together. The colors are assumed to be in sRGB
|
||||
// color space, and this function does not take alpha into account.
|
||||
fn blend_mix(cb: vec3<f32>, cs: vec3<f32>, mode: u32) -> vec3<f32> {
|
||||
var b = vec3<f32>(0.0);
|
||||
var b = vec3(0.0);
|
||||
switch mode {
|
||||
// MIX_MULTIPLY
|
||||
case 1u: {
|
||||
|
@ -163,11 +163,11 @@ fn blend_mix(cb: vec3<f32>, cs: vec3<f32>, mode: u32) -> vec3<f32> {
|
|||
}
|
||||
// MIX_COLOR_DODGE
|
||||
case 6u: {
|
||||
b = vec3<f32>(color_dodge(cb.x, cs.x), color_dodge(cb.y, cs.y), color_dodge(cb.z, cs.z));
|
||||
b = vec3(color_dodge(cb.x, cs.x), color_dodge(cb.y, cs.y), color_dodge(cb.z, cs.z));
|
||||
}
|
||||
// MIX_COLOR_BURN
|
||||
case 7u: {
|
||||
b = vec3<f32>(color_burn(cb.x, cs.x), color_burn(cb.y, cs.y), color_burn(cb.z, cs.z));
|
||||
b = vec3(color_burn(cb.x, cs.x), color_burn(cb.y, cs.y), color_burn(cb.z, cs.z));
|
||||
}
|
||||
// MIX_HARD_LIGHT
|
||||
case 8u: {
|
||||
|
@ -299,14 +299,14 @@ fn blend_compose(
|
|||
}
|
||||
// COMPOSE_PLUS_LIGHTER
|
||||
case 13u: {
|
||||
return min(vec4<f32>(1.0), vec4<f32>(as_ * cs + ab * cb, as_ + ab));
|
||||
return min(vec4(1.0), vec4(as_ * cs + ab * cb, as_ + ab));
|
||||
}
|
||||
default: {}
|
||||
}
|
||||
let as_fa = as_ * fa;
|
||||
let ab_fb = ab * fb;
|
||||
let co = as_fa * cs + ab_fb * cb;
|
||||
return vec4<f32>(co, as_fa + ab_fb);
|
||||
return vec4(co, as_fa + ab_fb);
|
||||
}
|
||||
|
||||
// Apply color mixing and composition. Both input and output colors are
|
||||
|
@ -329,7 +329,7 @@ fn blend_mix_compose(backdrop: vec4<f32>, src: vec4<f32>, mode: u32) -> vec4<f32
|
|||
let compose_mode = mode & 0xffu;
|
||||
if compose_mode == COMPOSE_SRC_OVER {
|
||||
let co = mix(backdrop.rgb, cs, src.a);
|
||||
return vec4<f32>(co, src.a + backdrop.a * (1.0 - src.a));
|
||||
return vec4(co, src.a + backdrop.a * (1.0 - src.a));
|
||||
} else {
|
||||
return blend_compose(cb, cs, backdrop.a, src.a, compose_mode);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ fn main(
|
|||
storageBarrier();
|
||||
if drawobj_ix < config.n_drawobj {
|
||||
let tile_subix = select(0u, sh_tile_count[local_id.x - 1u], local_id.x > 0u);
|
||||
let bbox = vec4<u32>(ux0, uy0, ux1, uy1);
|
||||
let bbox = vec4(ux0, uy0, ux1, uy1);
|
||||
let path = Path(bbox, tile_offset + tile_subix);
|
||||
paths[drawobj_ix] = path;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue