Skip to content

Commit

Permalink
Update color byte packing
Browse files Browse the repository at this point in the history
Colors are now packed in little-endian u32s rather than big-endian
which lets us get rid of some swizzling within the shaders.

We also get to take advantage of the new `to_u8_array` functions
to simplify the image creation for some tests.
  • Loading branch information
waywardmonkeys committed Dec 1, 2024
1 parent 1e48628 commit 9b59cc0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ skrifa = "0.26.0"
# The version of kurbo used below should be kept in sync
# with the version of kurbo used by peniko.
# peniko = "0.2.0"
peniko = { version = "0.2.0", git = "https://github.com/linebender/peniko.git", rev = "cb75a00" }
peniko = { version = "0.2.0", git = "https://github.com/linebender/peniko.git", rev = "d114c62" }
# FIXME: This can be removed once peniko supports the schemars feature.
kurbo = "0.11.1"
futures-intrusive = "0.5.0"
Expand Down
14 changes: 2 additions & 12 deletions examples/scenes/src/test_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,12 +1796,7 @@ mod impls {
]
.iter()
.for_each(|c| {
// FIXME(color): Get rid of the to_u32 and just use the PremulRgba8
let b = c.premultiply().to_rgba8().to_u32().to_ne_bytes();
blob.push(b[3]);
blob.push(b[2]);
blob.push(b[1]);
blob.push(b[0]);
blob.extend(c.premultiply().to_rgba8().to_u8_array());
});
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);
Expand Down Expand Up @@ -1844,12 +1839,7 @@ mod impls {
]
.iter()
.for_each(|c| {
// FIXME(color): Get rid of the to_u32 and just use the PremulRgba8
let b = c.premultiply().to_rgba8().to_u32().to_ne_bytes();
blob.push(b[3]);
blob.push(b[2]);
blob.push(b[1]);
blob.push(b[0]);
blob.extend(c.premultiply().to_rgba8().to_u8_array());
});
let data = Blob::new(Arc::new(blob));
let image = Image::new(data, Format::Rgba8, 2, 2);
Expand Down
6 changes: 3 additions & 3 deletions vello_shaders/shader/fine.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ fn main(
let local_xy = vec2(f32(local_id.x * PIXELS_PER_THREAD), f32(local_id.y));
var rgba: array<vec4<f32>, PIXELS_PER_THREAD>;
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
rgba[i] = unpack4x8unorm(config.base_color).wzyx;
rgba[i] = unpack4x8unorm(config.base_color);
}
var blend_stack: array<array<u32, PIXELS_PER_THREAD>, BLEND_STACK_SPLIT>;
var clip_depth = 0u;
Expand Down Expand Up @@ -953,7 +953,7 @@ fn main(
}
case CMD_COLOR: {
let color = read_color(cmd_ix);
let fg = unpack4x8unorm(color.rgba_color).wzyx;
let fg = unpack4x8unorm(color.rgba_color);
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
let fg_i = fg * area[i];
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
Expand Down Expand Up @@ -1044,7 +1044,7 @@ fn main(
let d = d_pos + d_neg - r1;
let alpha = scale * (erf7(inv_std_dev * (min_edge + d)) - erf7(inv_std_dev * d));

let fg_rgba = unpack4x8unorm(blur.rgba_color).wzyx * alpha;
let fg_rgba = unpack4x8unorm(blur.rgba_color) * alpha;
let fg_i = fg_rgba * area[i];
rgba[i] = rgba[i] * (1.0 - fg_i.a) + fg_i;
}
Expand Down

0 comments on commit 9b59cc0

Please sign in to comment.