Resolve a primitive's position through a chain of move slots
The plumbing for O(1) subtree movement (LAYOUT.md §2), with every slot still at zero, so this changes no pixels and the next commit can change behaviour against a known-good picture. Every active widget owns a slot in `UiData::moves`: a translation in physical pixels and the slot it is relative to. A primitive instance and a mask each name one, and `prelude.wgsl` walks the chain and adds the accumulated delta. A mask resolves its own chain rather than the drawn primitive's, so a stationary viewport can clip content that moves inside it. `CHAIN_LIMIT` is stated on both sides; it bounds a malformed cycle rather than any real tree. A slot outlives any one `ActiveData`, because a redraw replaces that while the widget's children go on pointing at the slot, so it lives in `UiRenderState::moves` keyed by widget and is retired when the widget stops being drawn. `MoveIdx` is its own type rather than another `Id<u32>`: it sits beside `MaskIdx` in an instance and the two must not be swappable. `Vec2` is now `repr(align(8))`, which is WGSL's alignment for a `vec2<f32>`, so a GPU struct holding one is laid out the way its shader reads it without saying so itself -- `GlyphPrimitive` no longer states its own alignment, and `MoveOffset` never has to. Both keep a manual `unsafe impl Pod`, since the trailing padding that alignment introduces is what `derive(Pod)` refuses. `WindowUniform` holds the `Vec2` its shader has always called `dim` rather than two loose floats, which was the last place the two sides described the same bytes differently. Checked: fmt, clippy and 40 tests. `tabs` (with the image replay), `view` and `minimal` render byte-identical to `upstream/main`, and `text` is unchanged.
This commit is contained in:
1 parent
ca2b4b2173
commit
f9ef7514e7
11 files changed
+262
-40
No files matched your search
@@ -3,7 +3,7 @@ use std::{any::TypeId, marker::PhantomData};
|
||||
use crate::{
|
||||
Color, TextureHandle, UiData, UiRegion, WidgetId,
|
||||
render::{
|
||||
data::{MaskIdx, PrimitiveInstance},
|
||||
data::{MaskIdx, MoveIdx, PrimitiveInstance},
|
||||
page::GlyphRender,
|
||||
texture::ImageRender,
|
||||
},
|
||||
@@ -246,6 +246,7 @@ impl LayerDraws {
|
||||
primitive,
|
||||
region,
|
||||
mask_idx,
|
||||
move_idx,
|
||||
}: PrimitiveInst<P>,
|
||||
) -> PrimitiveHandle {
|
||||
self.updated = true;
|
||||
@@ -258,7 +259,11 @@ impl LayerDraws {
|
||||
.get_or_insert_with(InstanceList::new::<P>)
|
||||
.push(
|
||||
id,
|
||||
PrimitiveInstance { region, mask_idx },
|
||||
PrimitiveInstance {
|
||||
region,
|
||||
mask_idx,
|
||||
move_idx,
|
||||
},
|
||||
bytemuck::bytes_of(&primitive),
|
||||
);
|
||||
PrimitiveHandle {
|
||||
@@ -304,6 +309,7 @@ pub struct PrimitiveInst<P> {
|
||||
pub primitive: P,
|
||||
pub region: UiRegion,
|
||||
pub mask_idx: MaskIdx,
|
||||
pub move_idx: MoveIdx,
|
||||
}
|
||||
|
||||
pub struct PrimitiveChange {
|
||||
@@ -347,7 +353,7 @@ impl RectPrimitive {
|
||||
|
||||
/// `color` is multiplied by the atlas alpha for a mask glyph; a colour glyph
|
||||
/// takes the texel unchanged, which `GlyphEntry::IS_COLORED` selects.
|
||||
#[repr(C, align(8))]
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct GlyphPrimitive {
|
||||
pub uv_min: Vec2,
|
||||
@@ -358,8 +364,8 @@ pub struct GlyphPrimitive {
|
||||
pub flags: u32,
|
||||
}
|
||||
|
||||
// Manual rather than derived: the align(8) leaves four bytes of padding, which
|
||||
// is how WGSL lays the struct out.
|
||||
// Manual rather than derived: `Vec2`'s alignment leaves four bytes of padding
|
||||
// here, which is how WGSL lays the struct out.
|
||||
unsafe impl bytemuck::Pod for GlyphPrimitive {}
|
||||
unsafe impl bytemuck::Zeroable for GlyphPrimitive {}
|
||||
impl Primitive for GlyphPrimitive {
|
||||
|
||||
Reference in new issue
Block a user