add constant assertion that composite original mask bit is free
diff --git a/sparse_strips/vello_hybrid/src/filter.rs b/sparse_strips/vello_hybrid/src/filter.rs index 34cf99b..93b69e0 100644 --- a/sparse_strips/vello_hybrid/src/filter.rs +++ b/sparse_strips/vello_hybrid/src/filter.rs
@@ -34,6 +34,7 @@ const FILTER_SIZE_BYTES: usize = 48; const FILTER_SIZE_U32: usize = FILTER_SIZE_BYTES / 4; const COMPOSITE_ORIGINAL_SHIFT: u32 = 13; +const COMPOSITE_ORIGINAL_MASK: u32 = 1 << COMPOSITE_ORIGINAL_SHIFT; const _: () = assert!( size_of::<GpuFilterData>() == FILTER_SIZE_BYTES, @@ -97,7 +98,7 @@ filter_type } -fn pack_header_with_gaussian_params( +const fn pack_header_with_gaussian_params( filter_type: u32, edge_mode: u32, n_decimations: u32, @@ -111,6 +112,11 @@ filter_type | (edge_mode << 5) | (n_decimations << 7) | (n_linear_taps << 11) } +const _: () = assert!( + pack_header_with_gaussian_params(31, 3, 15, 3) & COMPOSITE_ORIGINAL_MASK == 0, + "Gaussian filter parameters overlap the composite_original bit" +); + // To a large degree, the vello_hybrid implementation of gaussian blur follows the one in vello_cpu. // However, we apply a specific optimization, where instead of averaging and weighting each sample // one after the other, we use linear sampling to sample two pixels at once, and adjust the @@ -280,13 +286,19 @@ )] fn from(shadow: &DropShadow) -> Self { let lk = LinearKernel::new(&shadow.kernel, shadow.kernel_size); + let composite_original = if shadow.composite_original { + COMPOSITE_ORIGINAL_MASK + } else { + 0 + }; + Self { header: pack_header_with_gaussian_params( filter_type::DROP_SHADOW, edge_mode_to_gpu(shadow.edge_mode), shadow.n_decimations as u32, lk.n_taps as u32, - ) | (u32::from(shadow.composite_original) << COMPOSITE_ORIGINAL_SHIFT), + ) | composite_original, center_weight: lk.center_weight, linear_weights: lk.weights, linear_offsets: lk.offsets, @@ -321,7 +333,7 @@ } pub(crate) fn composite_original(&self) -> bool { - (self.data[0] >> COMPOSITE_ORIGINAL_SHIFT) & 1 != 0 + self.data[0] & COMPOSITE_ORIGINAL_MASK != 0 } pub(crate) fn needs_copy_pass(&self) -> bool {