Merge pull request #211 from linebender/cleanup_vec

Clean up unneeded type annotations in vec
This commit is contained in:
Raph Levien 2022-11-25 13:05:17 -05:00 committed by GitHub
commit fddd019567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 57 additions and 58 deletions

View file

@ -69,7 +69,7 @@ fn main(
var y1 = 0; var y1 = 0;
if element_ix < config.n_drawobj { if element_ix < config.n_drawobj {
let draw_monoid = draw_monoids[element_ix]; 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 { if draw_monoid.clip_ix > 0u {
clip_bbox = clip_bbox_buf[draw_monoid.clip_ix - 1u]; clip_bbox = clip_bbox_buf[draw_monoid.clip_ix - 1u];
} }
@ -79,10 +79,10 @@ fn main(
// TODO check this is true // TODO check this is true
let path_bbox = path_bbox_buf[draw_monoid.path_ix]; 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); let bbox_raw = bbox_intersect(clip_bbox, pb);
// TODO(naga): clunky expression a workaround for broken lhs swizzle // 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; intersected_bbox[element_ix] = bbox;
x0 = i32(floor(bbox.x * SX)); x0 = i32(floor(bbox.x * SX));

View file

@ -110,7 +110,7 @@ fn main(
} }
} }
let b = sh_bic[ix].b; let b = sh_bic[ix].b;
var bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9); var bbox = vec4(-1e9, -1e9, 1e9, 1e9);
if sp < b { if sp < b {
let el = clip_els[ix * WG_SIZE + b - sp - 1u]; let el = clip_els[ix * WG_SIZE + b - sp - 1u];
sh_stack[local_id.x] = el.parent_ix; sh_stack[local_id.x] = el.parent_ix;
@ -134,9 +134,9 @@ fn main(
sh_bic[local_id.x] = bic; sh_bic[local_id.x] = bic;
if is_push { if is_push {
let path_bbox = path_bboxes[inp]; 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 { } else {
bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9); bbox = vec4(-1e9, -1e9, 1e9, 1e9);
} }
var inbase = 0u; var inbase = 0u;
for (var i = 0u; i < firstTrailingBit(WG_SIZE) - 1u; i += 1u) { for (var i = 0u; i < firstTrailingBit(WG_SIZE) - 1u; i += 1u) {
@ -193,7 +193,7 @@ fn main(
} else if grandparent + i32(stack_size) >= 0 { } else if grandparent + i32(stack_size) >= 0 {
bbox = sh_stack_bbox[i32(WG_SIZE) + grandparent]; bbox = sh_stack_bbox[i32(WG_SIZE) + grandparent];
} else { } else {
bbox = vec4<f32>(-1e9, -1e9, 1e9, 1e9); bbox = vec4(-1e9, -1e9, 1e9, 1e9);
} }
} }
clip_bboxes[global_id.x] = bbox; clip_bboxes[global_id.x] = bbox;

View file

@ -61,7 +61,7 @@ fn main(
let path_ix = sh_path_ix[local_id.x]; let path_ix = sh_path_ix[local_id.x];
let path_bbox = path_bboxes[path_ix]; let path_bbox = path_bboxes[path_ix];
let parent_ix = sh_parent[local_id.x] + wg_id.x * WG_SIZE; let parent_ix = sh_parent[local_id.x] + wg_id.x * WG_SIZE;
let bbox = vec4<f32>(f32(path_bbox.x0), f32(path_bbox.y0), f32(path_bbox.x1), f32(path_bbox.y1)); let bbox = vec4(f32(path_bbox.x0), f32(path_bbox.y0), f32(path_bbox.x1), f32(path_bbox.y1));
clip_out[global_id.x] = ClipEl(parent_ix, bbox); clip_out[global_id.x] = ClipEl(parent_ix, bbox);
} }
} }

View file

@ -375,9 +375,9 @@ fn main(
let m1 = bitcast<f32>(info[di + 2u]); let m1 = bitcast<f32>(info[di + 2u]);
let m2 = bitcast<f32>(info[di + 3u]); let m2 = bitcast<f32>(info[di + 3u]);
let m3 = bitcast<f32>(info[di + 4u]); let m3 = bitcast<f32>(info[di + 4u]);
rad.matrx = vec4<f32>(m0, m1, m2, m3); rad.matrx = vec4(m0, m1, m2, m3);
rad.xlat = vec2<f32>(bitcast<f32>(info[di + 5u]), bitcast<f32>(info[di + 6u])); rad.xlat = vec2(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.c1 = vec2(bitcast<f32>(info[di + 7u]), bitcast<f32>(info[di + 8u]));
rad.ra = bitcast<f32>(info[di + 9u]); rad.ra = bitcast<f32>(info[di + 9u]);
rad.roff = bitcast<f32>(info[di + 10u]); rad.roff = bitcast<f32>(info[di + 10u]);
write_rad_grad(rad); write_rad_grad(rad);

View file

@ -44,8 +44,8 @@ fn read_transform(transform_base: u32, ix: u32) -> Transform {
let c3 = bitcast<f32>(scene[base + 3u]); let c3 = bitcast<f32>(scene[base + 3u]);
let c4 = bitcast<f32>(scene[base + 4u]); let c4 = bitcast<f32>(scene[base + 4u]);
let c5 = bitcast<f32>(scene[base + 5u]); let c5 = bitcast<f32>(scene[base + 5u]);
let matrx = vec4<f32>(c0, c1, c2, c3); let matrx = vec4(c0, c1, c2, c3);
let translate = vec2<f32>(c4, c5); let translate = vec2(c4, c5);
return Transform(matrx, translate); return Transform(matrx, translate);
} }
@ -150,7 +150,7 @@ fn main(
let r0 = bitcast<f32>(scene[dd + 5u]); let r0 = bitcast<f32>(scene[dd + 5u]);
let r1 = bitcast<f32>(scene[dd + 6u]); let r1 = bitcast<f32>(scene[dd + 6u]);
let inv_det = 1.0 / (matrx.x * matrx.w - matrx.y * matrx.z); let inv_det = 1.0 / (matrx.x * matrx.w - matrx.y * matrx.z);
let inv_mat = inv_det * vec4<f32>(matrx.w, -matrx.y, -matrx.z, matrx.x); let inv_mat = inv_det * vec4(matrx.w, -matrx.y, -matrx.z, matrx.x);
var inv_tr = inv_mat.xz * translate.x + inv_mat.yw * translate.y; var inv_tr = inv_mat.xz * translate.x + inv_mat.yw * translate.y;
inv_tr += p0; inv_tr += p0;
let center1 = p1 - p0; let center1 = p1 - p0;

View file

@ -70,9 +70,9 @@ fn read_rad_grad(cmd_ix: u32) -> CmdRadGrad {
let m1 = bitcast<f32>(ptcl[cmd_ix + 3u]); let m1 = bitcast<f32>(ptcl[cmd_ix + 3u]);
let m2 = bitcast<f32>(ptcl[cmd_ix + 4u]); let m2 = bitcast<f32>(ptcl[cmd_ix + 4u]);
let m3 = bitcast<f32>(ptcl[cmd_ix + 5u]); let m3 = bitcast<f32>(ptcl[cmd_ix + 5u]);
let matrx = vec4<f32>(m0, m1, m2, m3); let matrx = vec4(m0, m1, m2, m3);
let xlat = vec2<f32>(bitcast<f32>(ptcl[cmd_ix + 6u]), bitcast<f32>(ptcl[cmd_ix + 7u])); let xlat = vec2(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 c1 = vec2(bitcast<f32>(ptcl[cmd_ix + 8u]), bitcast<f32>(ptcl[cmd_ix + 9u]));
let ra = bitcast<f32>(ptcl[cmd_ix + 10u]); let ra = bitcast<f32>(ptcl[cmd_ix + 10u]);
let roff = bitcast<f32>(ptcl[cmd_ix + 11u]); let roff = bitcast<f32>(ptcl[cmd_ix + 11u]);
return CmdRadGrad(index, matrx, xlat, c1, ra, roff); 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 { while segment_ix != 0u {
let segment = segments[segment_ix]; let segment = segments[segment_ix];
let delta = segment.delta; 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); let scale = 1.0 / dot(delta, delta);
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { 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); let t = clamp(dot(dpos, delta) * scale, 0.0, 1.0);
// performance idea: hoist sqrt out of loop // performance idea: hoist sqrt out of loop
df[i] = min(df[i], length(delta * t - dpos)); df[i] = min(df[i], length(delta * t - dpos));
@ -161,7 +161,7 @@ fn main(
@builtin(workgroup_id) wg_id: vec3<u32>, @builtin(workgroup_id) wg_id: vec3<u32>,
) { ) {
let tile_ix = wg_id.y * config.width_in_tiles + wg_id.x; 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 #ifdef full
var rgba: array<vec4<f32>, PIXELS_PER_THREAD>; var rgba: array<vec4<f32>, PIXELS_PER_THREAD>;
var blend_stack: array<array<u32, BLEND_STACK_SPLIT>, 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) { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
let my_d = d + lin.line_x * f32(i); 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 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]; let fg_i = fg_rgba * area[i];
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i; rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
} }
@ -223,14 +223,14 @@ fn main(
case 7u: { case 7u: {
let rad = read_rad_grad(cmd_ix); let rad = read_rad_grad(cmd_ix);
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { 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 // 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 xy_xformed = rad.matrx.xz * my_xy.x + rad.matrx.yw * my_xy.y - rad.xlat;
let ba = dot(xy_xformed, rad.c1); let ba = dot(xy_xformed, rad.c1);
let ca = rad.ra * dot(xy_xformed, xy_xformed); let ca = rad.ra * dot(xy_xformed, xy_xformed);
let t = sqrt(ba * ba + ca) - ba - rad.roff; let t = sqrt(ba * ba + ca) - ba - rad.roff;
let x = i32(round(clamp(t, 0.0, 1.0) * f32(GRADIENT_WIDTH - 1))); 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]; let fg_i = fg_rgba * area[i];
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i; rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
} }
@ -241,7 +241,7 @@ fn main(
if clip_depth < BLEND_STACK_SPLIT { if clip_depth < BLEND_STACK_SPLIT {
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
blend_stack[clip_depth][i] = pack4x8unorm(rgba[i]); blend_stack[clip_depth][i] = pack4x8unorm(rgba[i]);
rgba[i] = vec4<f32>(0.0); rgba[i] = vec4(0.0);
} }
} else { } else {
// TODO: spill to memory // TODO: spill to memory
@ -277,7 +277,7 @@ fn main(
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
let fg = rgba[i]; let fg = rgba[i];
let a_inv = 1.0 / (fg.a + 1e-6); 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); let bytes = pack4x8unorm(rgba_sep);
output[out_ix + i] = bytes; output[out_ix + i] = bytes;
} }
@ -285,7 +285,7 @@ fn main(
let tile = tiles[tile_ix]; let tile = tiles[tile_ix];
let area = fill_path(tile, xy); 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; let out_ix = global_id.y * (config.width_in_tiles * 4u) + global_id.x;
output[out_ix] = bytes; output[out_ix] = bytes;
#endif #endif

View file

@ -36,14 +36,14 @@ var<private> pathdata_base: u32;
fn read_f32_point(ix: u32) -> vec2<f32> { fn read_f32_point(ix: u32) -> vec2<f32> {
let x = bitcast<f32>(scene[pathdata_base + ix]); let x = bitcast<f32>(scene[pathdata_base + ix]);
let y = bitcast<f32>(scene[pathdata_base + ix + 1u]); 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> { fn read_i16_point(ix: u32) -> vec2<f32> {
let raw = scene[pathdata_base + ix]; let raw = scene[pathdata_base + ix];
let x = f32(i32(raw << 16u) >> 16u); let x = f32(i32(raw << 16u) >> 16u);
let y = f32(i32(raw) >> 16u); let y = f32(i32(raw) >> 16u);
return vec2<f32>(x, y); return vec2(x, y);
} }
#ifndef cubics_out #ifndef cubics_out
@ -276,7 +276,7 @@ fn main(
tile_seg.delta = dp; tile_seg.delta = dp;
var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx); var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx);
if xymin.x < tile_x0 { 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 { if dp.x < 0.0 {
tile_seg.delta = p - lp0; tile_seg.delta = p - lp0;
} else { } else {

View file

@ -228,7 +228,7 @@ fn main(
tile_seg.delta = dp; tile_seg.delta = dp;
var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx); var y_edge = mix(lp0.y, lp1.y, (tile_x0 - lp0.x) * recip_dx);
if xymin.x < tile_x0 { 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 { if dp.x < 0.0 {
tile_seg.delta = p - lp0; tile_seg.delta = p - lp0;
} else { } else {

View file

@ -75,14 +75,14 @@ var<private> pathdata_base: u32;
fn read_f32_point(ix: u32) -> vec2<f32> { fn read_f32_point(ix: u32) -> vec2<f32> {
let x = bitcast<f32>(scene[pathdata_base + ix]); let x = bitcast<f32>(scene[pathdata_base + ix]);
let y = bitcast<f32>(scene[pathdata_base + ix + 1u]); 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> { fn read_i16_point(ix: u32) -> vec2<f32> {
let raw = scene[pathdata_base + ix]; let raw = scene[pathdata_base + ix];
let x = f32(i32(raw << 16u) >> 16u); let x = f32(i32(raw << 16u) >> 16u);
let y = f32(i32(raw) >> 16u); let y = f32(i32(raw) >> 16u);
return vec2<f32>(x, y); return vec2(x, y);
} }
struct Transform { struct Transform {
@ -98,8 +98,8 @@ fn read_transform(transform_base: u32, ix: u32) -> Transform {
let c3 = bitcast<f32>(scene[base + 3u]); let c3 = bitcast<f32>(scene[base + 3u]);
let c4 = bitcast<f32>(scene[base + 4u]); let c4 = bitcast<f32>(scene[base + 4u]);
let c5 = bitcast<f32>(scene[base + 5u]); let c5 = bitcast<f32>(scene[base + 5u]);
let matrx = vec4<f32>(c0, c1, c2, c3); let matrx = vec4(c0, c1, c2, c3);
let translate = vec2<f32>(c4, c5); let translate = vec2(c4, c5);
return Transform(matrx, translate); return Transform(matrx, translate);
} }
@ -162,10 +162,9 @@ fn main(
} }
} }
let transform = read_transform(config.transform_base, tm.trans_ix); 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); p0 = transform_apply(transform, p0);
p1 = transform_apply(transform, p1); 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 // Degree-raise
if seg_type == PATH_TAG_LINETO { if seg_type == PATH_TAG_LINETO {
p3 = p1; p3 = p1;
@ -173,10 +172,10 @@ fn main(
p1 = mix(p0, p3, 1.0 / 3.0); p1 = mix(p0, p3, 1.0 / 3.0);
} else if seg_type >= PATH_TAG_QUADTO { } else if seg_type >= PATH_TAG_QUADTO {
p2 = transform_apply(transform, p2); 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 { if seg_type == PATH_TAG_CUBICTO {
p3 = transform_apply(transform, p3); 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 { } else {
p3 = p2; p3 = p2;
p2 = mix(p1, p2, 1.0 / 3.0); p2 = mix(p1, p2, 1.0 / 3.0);
@ -187,8 +186,8 @@ fn main(
// See https://www.iquilezles.org/www/articles/ellipses/ellipses.htm // See https://www.iquilezles.org/www/articles/ellipses/ellipses.htm
// This is the correct bounding box, but we're not handling rendering // This is the correct bounding box, but we're not handling rendering
// in the isotropic case, so it may mismatch. // in the isotropic case, so it may mismatch.
let stroke = 0.5 * linewidth * vec2<f32>(length(transform.matrx.xz), length(transform.matrx.yw)); let stroke = 0.5 * linewidth * vec2(length(transform.matrx.xz), length(transform.matrx.yw));
bbox += vec4<f32>(-stroke, stroke); bbox += vec4(-stroke, stroke);
} }
cubics[global_id.x] = Cubic(p0, p1, p2, p3, tm.path_ix, 0u); cubics[global_id.x] = Cubic(p0, p1, p2, p3, tm.path_ix, 0u);
// Update bounding box using atomics only. Computing a monoid is a // Update bounding box using atomics only. Computing a monoid is a

View file

@ -45,23 +45,23 @@ fn color_burn(cb: f32, cs: f32) -> f32 {
} }
fn hard_light(cb: vec3<f32>, cs: vec3<f32>) -> vec3<f32> { fn hard_light(cb: vec3<f32>, cs: vec3<f32>) -> vec3<f32> {
return mix( return select(
screen(cb, 2.0 * cs - 1.0), screen(cb, 2.0 * cs - 1.0),
cb * 2.0 * cs, 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> { fn soft_light(cb: vec3<f32>, cs: vec3<f32>) -> vec3<f32> {
let d = mix( let d = select(
sqrt(cb), sqrt(cb),
((16.0 * cb - vec3(12.0)) * cb + vec3(4.0)) * cb, ((16.0 * cb - 12.0) * cb + 4.0) * cb,
vec3<f32>(cb <= vec3<f32>(0.25)) cb <= vec3(0.25)
); );
return mix( return select(
cb + (2.0 * cs - vec3(1.0)) * (d - cb), cb + (2.0 * cs - 1.0) * (d - cb),
cb - (vec3(1.0) - 2.0 * cs) * cb * (vec3(1.0) - cb), cb - (1.0 - 2.0 * cs) * cb * (1.0 - cb),
vec3<f32>(cs <= vec3<f32>(0.5)) cs <= vec3(0.5)
); );
} }
@ -70,7 +70,7 @@ fn sat(c: vec3<f32>) -> f32 {
} }
fn lum(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); 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 // Blends two RGB colors together. The colors are assumed to be in sRGB
// color space, and this function does not take alpha into account. // color space, and this function does not take alpha into account.
fn blend_mix(cb: vec3<f32>, cs: vec3<f32>, mode: u32) -> vec3<f32> { 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 { switch mode {
// MIX_MULTIPLY // MIX_MULTIPLY
case 1u: { case 1u: {
@ -163,11 +163,11 @@ fn blend_mix(cb: vec3<f32>, cs: vec3<f32>, mode: u32) -> vec3<f32> {
} }
// MIX_COLOR_DODGE // MIX_COLOR_DODGE
case 6u: { 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 // MIX_COLOR_BURN
case 7u: { 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 // MIX_HARD_LIGHT
case 8u: { case 8u: {
@ -299,14 +299,14 @@ fn blend_compose(
} }
// COMPOSE_PLUS_LIGHTER // COMPOSE_PLUS_LIGHTER
case 13u: { 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: {} default: {}
} }
let as_fa = as_ * fa; let as_fa = as_ * fa;
let ab_fb = ab * fb; let ab_fb = ab * fb;
let co = as_fa * cs + ab_fb * cb; 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 // 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; let compose_mode = mode & 0xffu;
if compose_mode == COMPOSE_SRC_OVER { if compose_mode == COMPOSE_SRC_OVER {
let co = mix(backdrop.rgb, cs, src.a); 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 { } else {
return blend_compose(cb, cs, backdrop.a, src.a, compose_mode); return blend_compose(cb, cs, backdrop.a, src.a, compose_mode);
} }

View file

@ -81,7 +81,7 @@ fn main(
storageBarrier(); storageBarrier();
if drawobj_ix < config.n_drawobj { if drawobj_ix < config.n_drawobj {
let tile_subix = select(0u, sh_tile_count[local_id.x - 1u], local_id.x > 0u); 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); let path = Path(bbox, tile_offset + tile_subix);
paths[drawobj_ix] = path; paths[drawobj_ix] = path;
} }