Skip to content

Commit

Permalink
Add cpu support for blurred rounded rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
msiglreith committed Aug 16, 2024
1 parent cf50b87 commit 62c1003
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions vello_shaders/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const CMD_IMAGE: u32 = 9;
const CMD_BEGIN_CLIP: u32 = 10;
const CMD_END_CLIP: u32 = 11;
const CMD_JUMP: u32 = 12;
const CMD_BLUR_RECT: u32 = 13;

// The following are computed in draw_leaf from the generic gradient parameters
// encoded in the scene, and stored in the gradient's info struct, for
Expand Down
24 changes: 22 additions & 2 deletions vello_shaders/src/cpu/coarse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use vello_encoding::{
};

use super::{
CpuBinding, CMD_BEGIN_CLIP, CMD_COLOR, CMD_END, CMD_END_CLIP, CMD_FILL, CMD_IMAGE, CMD_JUMP,
CMD_LIN_GRAD, CMD_RAD_GRAD, CMD_SOLID, CMD_SWEEP_GRAD, PTCL_INITIAL_ALLOC,
CpuBinding, CMD_BEGIN_CLIP, CMD_BLUR_RECT, CMD_COLOR, CMD_END, CMD_END_CLIP, CMD_FILL,
CMD_IMAGE, CMD_JUMP, CMD_LIN_GRAD, CMD_RAD_GRAD, CMD_SOLID, CMD_SWEEP_GRAD, PTCL_INITIAL_ALLOC,
};

// Tiles per bin
Expand Down Expand Up @@ -138,6 +138,21 @@ impl TileState {
self.cmd_offset += 3;
}

fn write_blur_rect(
&mut self,
config: &ConfigUniform,
bump: &mut BumpAllocators,
ptcl: &mut [u32],
rgba_color: u32,
info_offset: u32,
) {
self.alloc_cmd(3, config, bump, ptcl);
self.write(ptcl, 0, CMD_BLUR_RECT);
self.write(ptcl, 1, info_offset);
self.write(ptcl, 2, rgba_color);
self.cmd_offset += 3;
}

fn write_begin_clip(
&mut self,
config: &ConfigUniform,
Expand Down Expand Up @@ -313,6 +328,11 @@ fn coarse_main(
di + 1,
);
}
DrawTag::BLUR_RECT => {
tile_state.write_path(config, bump, ptcl, tile, draw_flags);
let rgba_color = scene[dd as usize];
tile_state.write_blur_rect(config, bump, ptcl, rgba_color, di + 1);
}
DrawTag::BEGIN_CLIP => {
if tile.segment_count_or_ix == 0 && tile.backdrop == 0 {
clip_zero_depth = clip_depth + 1;
Expand Down
15 changes: 15 additions & 0 deletions vello_shaders/src/cpu/draw_leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn draw_leaf_main(
|| tag_word == DrawTag::SWEEP_GRADIENT
|| tag_word == DrawTag::IMAGE
|| tag_word == DrawTag::BEGIN_CLIP
|| tag_word == DrawTag::BLUR_RECT
{
let bbox = path_bbox[m.path_ix as usize];
let transform = Transform::read(config.layout.transform_base, bbox.trans_ix, scene);
Expand Down Expand Up @@ -175,6 +176,20 @@ fn draw_leaf_main(
info[di + 7] = scene[dd as usize];
info[di + 8] = scene[dd as usize + 1];
}
DrawTag::BLUR_RECT => {
info[di] = draw_flags;
let xform = transform.inverse();
info[di + 1] = f32::to_bits(xform.0[0]);
info[di + 2] = f32::to_bits(xform.0[1]);
info[di + 3] = f32::to_bits(xform.0[2]);
info[di + 4] = f32::to_bits(xform.0[3]);
info[di + 5] = f32::to_bits(xform.0[4]);
info[di + 6] = f32::to_bits(xform.0[5]);
info[di + 7] = scene[dd as usize + 1];
info[di + 8] = scene[dd as usize + 2];
info[di + 9] = scene[dd as usize + 3];
info[di + 10] = scene[dd as usize + 4];
}
DrawTag::BEGIN_CLIP => (),
_ => todo!("unhandled draw tag {:x}", tag_word.0),
}
Expand Down

0 comments on commit 62c1003

Please sign in to comment.