diff --git a/shader/coarse.wgsl b/shader/coarse.wgsl index 59b89427d..6caa35a13 100644 --- a/shader/coarse.wgsl +++ b/shader/coarse.wgsl @@ -357,40 +357,34 @@ fn main( let tile_ix = sh_tile_base[el_ix] + sh_tile_stride[el_ix] * tile_y + tile_x; let tile = tiles[tile_ix]; switch drawtag { - // DRAWTAG_FILL_COLOR - case 0x44u: { + case DRAWTAG_FILL_COLOR: { write_path(tile, tile_ix, draw_flags); let rgba_color = scene[dd]; write_color(CmdColor(rgba_color)); } - // DRAWTAG_FILL_LIN_GRADIENT - case 0x114u: { + case DRAWTAG_FILL_LIN_GRADIENT: { write_path(tile, tile_ix, draw_flags); let index = scene[dd]; let info_offset = di + 1u; write_grad(CMD_LIN_GRAD, index, info_offset); } - // DRAWTAG_FILL_RAD_GRADIENT - case 0x29cu: { + case DRAWTAG_FILL_RAD_GRADIENT: { write_path(tile, tile_ix, draw_flags); let index = scene[dd]; let info_offset = di + 1u; write_grad(CMD_RAD_GRAD, index, info_offset); } - // DRAWTAG_FILL_SWEEP_GRADIENT - case 0x254u: { + case DRAWTAG_FILL_SWEEP_GRADIENT: { write_path(tile, tile_ix, draw_flags); let index = scene[dd]; let info_offset = di + 1u; write_grad(CMD_SWEEP_GRAD, index, info_offset); } - // DRAWTAG_FILL_IMAGE - case 0x248u: { + case DRAWTAG_FILL_IMAGE: { write_path(tile, tile_ix, draw_flags); write_image(di + 1u); } - // DRAWTAG_BEGIN_CLIP - case 0x9u: { + case DRAWTAG_BEGIN_CLIP: { if tile.segment_count_or_ix == 0u && tile.backdrop == 0 { clip_zero_depth = clip_depth + 1u; } else { @@ -400,8 +394,7 @@ fn main( } clip_depth += 1u; } - // DRAWTAG_END_CLIP - case 0x21u: { + case DRAWTAG_END_CLIP: { clip_depth -= 1u; // A clip shape is always a non-zero fill (draw_flags=0). write_path(tile, tile_ix, /*draw_flags=*/0u); @@ -415,12 +408,10 @@ fn main( } else { // In "clip zero" state, suppress all drawing switch drawtag { - // DRAWTAG_BEGIN_CLIP - case 0x9u: { + case DRAWTAG_BEGIN_CLIP: { clip_depth += 1u; } - // DRAWTAG_END_CLIP - case 0x21u: { + case DRAWTAG_END_CLIP: { if clip_depth == clip_zero_depth { clip_zero_depth = 0u; } diff --git a/shader/draw_leaf.wgsl b/shader/draw_leaf.wgsl index fd04e2e2f..6f1a2e6c2 100644 --- a/shader/draw_leaf.wgsl +++ b/shader/draw_leaf.wgsl @@ -117,12 +117,10 @@ fn main( transform = read_transform(config.transform_base, bbox.trans_ix); } switch tag_word { - // DRAWTAG_FILL_COLOR - case 0x44u: { + case DRAWTAG_FILL_COLOR: { info[di] = draw_flags; } - // DRAWTAG_FILL_LIN_GRADIENT - case 0x114u: { + case DRAWTAG_FILL_LIN_GRADIENT: { info[di] = draw_flags; var p0 = bitcast>(vec2(scene[dd + 1u], scene[dd + 2u])); var p1 = bitcast>(vec2(scene[dd + 3u], scene[dd + 4u])); @@ -136,8 +134,7 @@ fn main( info[di + 2u] = bitcast(line_xy.y); info[di + 3u] = bitcast(line_c); } - // DRAWTAG_FILL_RAD_GRADIENT - case 0x29cu: { + case DRAWTAG_FILL_RAD_GRADIENT: { // Two-point conical gradient implementation based // on the algorithm at // This epsilon matches what Skia uses @@ -220,8 +217,7 @@ fn main( info[di + 8u] = bitcast(radius); info[di + 9u] = bitcast((flags << 3u) | kind); } - // DRAWTAG_FILL_SWEEP_GRADIENT - case 0x254u: { + case DRAWTAG_FILL_SWEEP_GRADIENT: { info[di] = draw_flags; let p0 = bitcast>(vec2(scene[dd + 1u], scene[dd + 2u])); let xform = transform_mul(transform, Transform(vec4(1.0, 0.0, 0.0, 1.0), p0)); @@ -235,8 +231,7 @@ fn main( info[di + 7u] = scene[dd + 3u]; info[di + 8u] = scene[dd + 4u]; } - // DRAWTAG_FILL_IMAGE - case 0x248u: { + case DRAWTAG_FILL_IMAGE: { info[di] = draw_flags; let inv = transform_inverse(transform); info[di + 1u] = bitcast(inv.matrx.x); diff --git a/shader/fine.wgsl b/shader/fine.wgsl index 1ec2482d8..539ccbe75 100644 --- a/shader/fine.wgsl +++ b/shader/fine.wgsl @@ -779,21 +779,18 @@ fn read_end_clip(cmd_ix: u32) -> CmdEndClip { return CmdEndClip(blend, alpha); } +const EXTEND_PAD: u32 = 0u; +const EXTEND_REPEAT: u32 = 1u; +const EXTEND_REFLECT: u32 = 2u; fn extend_mode(t: f32, mode: u32) -> f32 { - let EXTEND_PAD = 0u; - let EXTEND_REPEAT = 1u; - let EXTEND_REFLECT = 2u; switch mode { - // EXTEND_PAD - case 0u: { + case EXTEND_PAD: { return clamp(t, 0.0, 1.0); } - // EXTEND_REPEAT - case 1u: { + case EXTEND_REPEAT: { return fract(t); } - // EXTEND_REFLECT - default: { + case EXTEND_REFLECT, default: { return abs(t - 2.0 * round(0.5 * t)); } } @@ -891,8 +888,7 @@ fn main( break; } switch tag { - // CMD_FILL - case 1u: { + case CMD_FILL: { let fill = read_fill(cmd_ix); #ifdef msaa fill_path_ms(fill, local_id.xy, &area); @@ -901,25 +897,23 @@ fn main( #endif cmd_ix += 4u; } - // CMD_STROKE - case 2u: { + case CMD_STROKE: { // Stroking in fine rasterization is disabled, as strokes will be expanded // to fills earlier in the pipeline. This implementation is a stub, just to // keep the shader from crashing. + // TODO: Remove this case for (var i = 0u; i < PIXELS_PER_THREAD; i++) { area[i] = 0.0; } cmd_ix += 3u; } - // CMD_SOLID - case 3u: { + case CMD_SOLID: { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { area[i] = 1.0; } cmd_ix += 1u; } - // CMD_COLOR - case 5u: { + case CMD_COLOR: { let color = read_color(cmd_ix); let fg = unpack4x8unorm(color.rgba_color).wzyx; for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { @@ -928,8 +922,7 @@ fn main( } cmd_ix += 2u; } - // CMD_LIN_GRAD - case 6u: { + case CMD_LIN_GRAD: { let lin = read_lin_grad(cmd_ix); let d = lin.line_x * xy.x + lin.line_y * xy.y + lin.line_c; for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { @@ -941,8 +934,7 @@ fn main( } cmd_ix += 3u; } - // CMD_RAD_GRAD - case 7u: { + case CMD_RAD_GRAD: { let rad = read_rad_grad(cmd_ix); let focal_x = rad.focal_x; let radius = rad.radius; @@ -987,8 +979,7 @@ fn main( } cmd_ix += 3u; } - // CMD_SWEEP_GRAD - case 8u: { + case CMD_SWEEP_GRAD: { let sweep = read_sweep_grad(cmd_ix); let scale = 1.0 / (sweep.t1 - sweep.t0); for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { @@ -1021,8 +1012,7 @@ fn main( } cmd_ix += 3u; } - // CMD_IMAGE - case 9u: { + case CMD_IMAGE: { let image = read_image(cmd_ix); let atlas_extents = image.atlas_offset + image.extents; for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { @@ -1043,8 +1033,7 @@ fn main( } cmd_ix += 2u; } - // CMD_BEGIN_CLIP - case 10u: { + case CMD_BEGIN_CLIP: { if clip_depth < BLEND_STACK_SPLIT { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { blend_stack[clip_depth][i] = pack4x8unorm(rgba[i]); @@ -1056,8 +1045,7 @@ fn main( clip_depth += 1u; cmd_ix += 1u; } - // CMD_END_CLIP - case 11u: { + case CMD_END_CLIP: { let end_clip = read_end_clip(cmd_ix); clip_depth -= 1u; for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { @@ -1073,8 +1061,7 @@ fn main( } cmd_ix += 3u; } - // CMD_JUMP - case 12u: { + case CMD_JUMP: { cmd_ix = ptcl[cmd_ix + 1u]; } default: {} diff --git a/shader/shared/blend.wgsl b/shader/shared/blend.wgsl index 7a36f706c..f8090430a 100644 --- a/shader/shared/blend.wgsl +++ b/shader/shared/blend.wgsl @@ -142,64 +142,49 @@ fn set_sat(c: vec3, s: f32) -> vec3 { fn blend_mix(cb: vec3, cs: vec3, mode: u32) -> vec3 { var b = vec3(0.0); switch mode { - // MIX_MULTIPLY - case 1u: { + case MIX_MULTIPLY: { b = cb * cs; } - // MIX_SCREEN - case 2u: { + case MIX_SCREEN: { b = screen(cb, cs); } - // MIX_OVERLAY - case 3u: { + case MIX_OVERLAY: { b = hard_light(cs, cb); } - // MIX_DARKEN - case 4u: { + case MIX_DARKEN: { b = min(cb, cs); } - // MIX_LIGHTEN - case 5u: { + case MIX_LIGHTEN: { b = max(cb, cs); } - // MIX_COLOR_DODGE - case 6u: { + case MIX_COLOR_DODGE: { 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: { + case MIX_COLOR_BURN: { 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: { + case MIX_HARD_LIGHT: { b = hard_light(cb, cs); } - // MIX_SOFT_LIGHT - case 9u: { + case MIX_SOFT_LIGHT: { b = soft_light(cb, cs); } - // MIX_DIFFERENCE - case 10u: { + case MIX_DIFFERENCE: { b = abs(cb - cs); } - // MIX_EXCLUSION - case 11u: { + case MIX_EXCLUSION: { b = cb + cs - 2.0 * cb * cs; } - // MIX_HUE - case 12u: { + case MIX_HUE: { b = set_lum(set_sat(cs, sat(cb)), lum(cb)); } - // MIX_SATURATION - case 13u: { + case MIX_SATURATION: { b = set_lum(set_sat(cb, sat(cs)), lum(cb)); } - // MIX_COLOR - case 14u: { + case MIX_COLOR: { b = set_lum(cs, lum(cb)); } - // MIX_LUMINOSITY - case 15u: { + case MIX_LUMINOSITY: { b = set_lum(cb, lum(cs)); } default: { @@ -238,68 +223,55 @@ fn blend_compose( var fa = 0.0; var fb = 0.0; switch mode { - // COMPOSE_COPY - case 1u: { + case COMPOSE_COPY: { fa = 1.0; fb = 0.0; } - // COMPOSE_DEST - case 2u: { + case COMPOSE_DEST: { fa = 0.0; fb = 1.0; } - // COMPOSE_SRC_OVER - case 3u: { + case COMPOSE_SRC_OVER: { fa = 1.0; fb = 1.0 - as_; } - // COMPOSE_DEST_OVER - case 4u: { + case COMPOSE_DEST_OVER: { fa = 1.0 - ab; fb = 1.0; } - // COMPOSE_SRC_IN - case 5u: { + case COMPOSE_SRC_IN: { fa = ab; fb = 0.0; } - // COMPOSE_DEST_IN - case 6u: { + case COMPOSE_DEST_IN: { fa = 0.0; fb = as_; } - // COMPOSE_SRC_OUT - case 7u: { + case COMPOSE_SRC_OUT: { fa = 1.0 - ab; fb = 0.0; } - // COMPOSE_DEST_OUT - case 8u: { + case COMPOSE_DEST_OUT: { fa = 0.0; fb = 1.0 - as_; } - // COMPOSE_SRC_ATOP - case 9u: { + case COMPOSE_SRC_ATOP: { fa = ab; fb = 1.0 - as_; } - // COMPOSE_DEST_ATOP - case 10u: { + case COMPOSE_DEST_ATOP: { fa = 1.0 - ab; fb = as_; } - // COMPOSE_XOR - case 11u: { + case COMPOSE_XOR: { fa = 1.0 - ab; fb = 1.0 - as_; } - // COMPOSE_PLUS - case 12u: { + case COMPOSE_PLUS: { fa = 1.0; fb = 1.0; } - // COMPOSE_PLUS_LIGHTER - case 13u: { + case COMPOSE_PLUS_LIGHTER: { return min(vec4(1.0), vec4(as_ * cs + ab * cb, as_ + ab)); } default: {}