Settle source layout constraints before publishing complete frames
Verify Tessera GUI / verify (push) Failing after 7m49s
Verify Tessera GUI / verify (push) Failing after 7m49s
This commit is contained in:
+171
-5
@@ -74,6 +74,13 @@ struct Plan {
|
||||
cache: Cache,
|
||||
pending: Vec<Option<Pending>>,
|
||||
constraints: Vec<[f32; 4]>,
|
||||
// Source-arranged dimensions remain exact for this solve, not business state.
|
||||
allocations: Vec<[Option<f32>; 2]>,
|
||||
custom_arrange: Vec<bool>,
|
||||
custom_measure: Vec<bool>,
|
||||
measured_limits: Vec<[Option<f32>; 2]>,
|
||||
previous: Option<Vec<u32>>,
|
||||
seen: BTreeSet<Vec<u32>>,
|
||||
}
|
||||
type Shared = Arc<Mutex<Plan>>;
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -129,7 +136,14 @@ impl NativeCallable for Step {
|
||||
.iter()
|
||||
.map(|child| plan.sizes[*child])
|
||||
.collect::<Vec<_>>();
|
||||
let bounds = plan.bounds[self.index];
|
||||
let bounds = if matches!(self.phase, Phase::Arrange) {
|
||||
plan.bounds[self.index]
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if matches!(self.phase, Phase::Measure) {
|
||||
plan.custom_measure[self.index] = method != native;
|
||||
}
|
||||
let native_size = if matches!(self.phase, Phase::Measure) && method == native {
|
||||
let constraints = plan.constraints[self.index];
|
||||
Some(
|
||||
@@ -180,6 +194,7 @@ impl NativeCallable for Step {
|
||||
};
|
||||
if matches!(self.phase, Phase::Arrange) {
|
||||
plan.runtime.arranged += 1;
|
||||
plan.custom_arrange[self.index] = method != native;
|
||||
}
|
||||
(node, children, bounds, native_size)
|
||||
};
|
||||
@@ -303,12 +318,36 @@ impl NativeCallable for Collect {
|
||||
},
|
||||
plan.constraints[self.index],
|
||||
);
|
||||
// Native shrink-to-content containers keep their existing input
|
||||
// policy. Only a source measurement that differs from the native
|
||||
// result supplies an additional content constraint.
|
||||
if plan.custom_measure[self.index] && !plan.children[self.index].is_empty() {
|
||||
let children = plan.children[self.index]
|
||||
.iter()
|
||||
.map(|child| plan.sizes[*child])
|
||||
.collect();
|
||||
let native = layout::measure_native(
|
||||
&plan.nodes[self.index],
|
||||
children,
|
||||
plan.constraints[self.index],
|
||||
)
|
||||
.ok()
|
||||
.map(|native| layout::constrained(native, plan.constraints[self.index]));
|
||||
// Equality after remeasurement does not retract a source
|
||||
// limit selected earlier in this solve. New renders start fresh.
|
||||
if !native.is_some_and(|native| native.width == size.width) {
|
||||
plan.measured_limits[self.index][0] = Some(size.width);
|
||||
}
|
||||
if !native.is_some_and(|native| native.height == size.height) {
|
||||
plan.measured_limits[self.index][1] = Some(size.height);
|
||||
}
|
||||
}
|
||||
// Decoding is part of the subcall dependency region: a source
|
||||
// method may return an existing result whose fields can change.
|
||||
let tracked = pending
|
||||
.map(|pending| {
|
||||
cx.store()
|
||||
.end_read_tracking(pending.token)
|
||||
.end_read_tracking_details(pending.token)
|
||||
.map(|reads| (pending, reads))
|
||||
})
|
||||
.transpose()?;
|
||||
@@ -316,7 +355,8 @@ impl NativeCallable for Collect {
|
||||
let mut versions = BTreeMap::new();
|
||||
let mut volatile = false;
|
||||
let registry = desktop_type_registry(cx, self.desktop)?;
|
||||
for object in reads {
|
||||
for read in reads {
|
||||
let object = read.object;
|
||||
if object == self.desktop || object == registry {
|
||||
continue;
|
||||
}
|
||||
@@ -324,7 +364,8 @@ impl NativeCallable for Collect {
|
||||
// source. Object-granular tracking cannot prove those
|
||||
// accesses stable, so conservatively bypass its cache.
|
||||
if cx.store().object(object)?.payload().as_any().is::<Mount>() {
|
||||
volatile = true;
|
||||
volatile |= read.content_read;
|
||||
continue;
|
||||
}
|
||||
versions.insert(object, cx.store().change_version(object)?);
|
||||
}
|
||||
@@ -398,13 +439,116 @@ impl NativeCallable for Collect {
|
||||
{
|
||||
return Err(invalid("arrangement bounds exceed limits"));
|
||||
}
|
||||
plan.bounds[children[position]] = Some(bounds);
|
||||
let child = children[position];
|
||||
if plan.custom_arrange[self.index] {
|
||||
if bounds[2] != plan.sizes[child].width {
|
||||
plan.allocations[child][0] = Some(bounds[2]);
|
||||
}
|
||||
if bounds[3] != plan.sizes[child].height {
|
||||
plan.allocations[child][1] = Some(bounds[3]);
|
||||
}
|
||||
}
|
||||
plan.bounds[child] = Some(bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(NativeResult::Return(Value::Nil))
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
struct Settle {
|
||||
plan: Shared,
|
||||
mounts: Vec<WeakObjectRef>,
|
||||
}
|
||||
impl NativeCallable for Settle {
|
||||
fn arity(&self) -> Option<endor_core::CallArity> {
|
||||
Some(endor_core::CallArity::exact(0))
|
||||
}
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
let repeat = {
|
||||
let mut plan = self
|
||||
.plan
|
||||
.lock()
|
||||
.map_err(|_| invalid("layout plan poisoned"))?;
|
||||
plan.runtime.settle_passes += 1;
|
||||
let mut next = plan.constraints.clone();
|
||||
for (index, children) in plan.children.iter().enumerate() {
|
||||
let [_, _, width, height] =
|
||||
plan.bounds[index].ok_or(invalid("unarranged occurrence"))?;
|
||||
let mut available = next[index];
|
||||
if let Some(width) = plan.measured_limits[index][0] {
|
||||
available[2] = width;
|
||||
}
|
||||
if let Some(height) = plan.measured_limits[index][1] {
|
||||
available[3] = height;
|
||||
}
|
||||
if width != plan.sizes[index].width {
|
||||
available[2] = width;
|
||||
}
|
||||
if height != plan.sizes[index].height {
|
||||
available[3] = height;
|
||||
}
|
||||
let base = layout::child_constraints(&plan.nodes[index], available);
|
||||
for child in children {
|
||||
let mut constraints = base;
|
||||
if let Some(width) = plan.allocations[*child][0] {
|
||||
constraints[0] = width;
|
||||
constraints[2] = width;
|
||||
}
|
||||
if let Some(height) = plan.allocations[*child][1] {
|
||||
constraints[1] = height;
|
||||
constraints[3] = height;
|
||||
}
|
||||
next[*child] = constraints;
|
||||
}
|
||||
}
|
||||
let mut state = Vec::with_capacity(plan.nodes.len() * 14);
|
||||
let bits = |value: f32| if value == 0.0 { 0 } else { value.to_bits() };
|
||||
for (index, constraints) in next.iter().enumerate() {
|
||||
state.extend(constraints.iter().copied().map(bits));
|
||||
state.extend([
|
||||
bits(plan.sizes[index].width),
|
||||
bits(plan.sizes[index].height),
|
||||
]);
|
||||
state.extend(
|
||||
plan.bounds[index]
|
||||
.ok_or(invalid("unarranged occurrence"))?
|
||||
.into_iter()
|
||||
.map(bits),
|
||||
);
|
||||
for dimension in plan.allocations[index] {
|
||||
state.push(u32::from(dimension.is_some()));
|
||||
state.push(dimension.map_or(0, bits));
|
||||
}
|
||||
}
|
||||
if plan.previous.as_ref() == Some(&state) && plan.constraints == next {
|
||||
false
|
||||
} else {
|
||||
if !plan.seen.insert(state.clone()) {
|
||||
return Err(invalid("layout constraints did not converge (cycle)"));
|
||||
}
|
||||
plan.previous = Some(state);
|
||||
plan.constraints = next;
|
||||
plan.bounds.fill(None);
|
||||
true
|
||||
}
|
||||
};
|
||||
if repeat {
|
||||
// No stale geometry from a prior pass is observable during measurement.
|
||||
for weak in &self.mounts {
|
||||
let mount = cx.upgrade(*weak)?.ok_or(invalid("layout Mount expired"))?;
|
||||
if let Some(context) = &cx.store().payload::<Mount>(mount, "Mount")?.layout {
|
||||
context
|
||||
.lock()
|
||||
.map_err(|_| invalid("layout context poisoned"))?
|
||||
.bounds = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(NativeResult::Return(Value::Bool(repeat)))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Prepare {
|
||||
plan: Shared,
|
||||
@@ -462,6 +606,22 @@ impl NativeCallable for Prepare {
|
||||
]);
|
||||
}
|
||||
}
|
||||
let settle = cx.allocate(ContextNativeFunction::new(
|
||||
"settle source layout",
|
||||
Settle {
|
||||
plan: self.plan.clone(),
|
||||
mounts: self.mounts.clone(),
|
||||
},
|
||||
vec![],
|
||||
))?;
|
||||
let check = constants.len() as u32;
|
||||
constants.push(Value::Object(settle));
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, check),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
Instruction::new(Opcode::Call, 0),
|
||||
]);
|
||||
crate::vm_sequence::repeat_while(&mut instructions)?;
|
||||
let end = constants.len() as u32;
|
||||
constants.push(Value::Nil);
|
||||
instructions.extend([
|
||||
@@ -566,6 +726,12 @@ pub fn render(
|
||||
cache: cache.clone(),
|
||||
pending: (0..count).map(|_| None).collect(),
|
||||
constraints,
|
||||
allocations: vec![[None, None]; count],
|
||||
custom_arrange: vec![false; count],
|
||||
custom_measure: vec![false; count],
|
||||
measured_limits: vec![[None, None]; count],
|
||||
previous: None,
|
||||
seen: BTreeSet::new(),
|
||||
}));
|
||||
let prepare = vm.allocate(ContextNativeFunction::new(
|
||||
"prepare source layout",
|
||||
|
||||
Reference in New Issue
Block a user