vgpu: the type-11 class has a size and a reach, and only the size was counted

Component: crates/reims-vgpu, runtime compute rail, x86 macOS / Linux Vulkan
pathway, macos-13 rail, PCI attach, page shift 12.

`direct_destination` answers `Host` for a type-11 destination before it has
looked at anything, and `compute_dst_host_not_linear` counts those. On this
rail that counter is the largest class the direct-to-guest-pages arm does not
reach, by a wide margin over every other decline, which is what puts a type-11
licence at the top of the queue.

The counter cannot decide that, because it says how many there are and not how
many are reachable, and those are different numbers. A copy converts nothing, so
a type-11 window can only be served raw when the format the guest will read the
bytes back as is exactly the one the dispatch's storage image holds. A compute
storage image takes its format from the specialized SPIR-V texel format, which
has no reason to match a surface mapping's declared one, so the reachable share
could be anything from all of it to none of it and nothing measured which.

`note_type11_shape` bands it. Three counters that partition the class --
`agrees`, `differs`, `unresolved` -- plus one `OFF` line per distinct declared/
held format pair, deduped by `first_sight` because a driven boot repeats a
handful of pairs thousands of times. `compute_dst_no_writeback` splits off the
storage images the guest gave nowhere to land, which are not part of the
population at all.

Behaviour is unchanged: nothing here reaches a decision, every window still
takes the route it took before, and the emitters are on the `OFF` channel
because a readback loses no guest work.

Tests. `only_a_licensed_transient_linear_window_can_take_the_direct_arm` gained
three type-11 cases -- a mapping declaring the held texel, one declaring
another, and one never registered -- and asserts the three verdicts partition
the class, so a fourth outcome or one counted twice cannot make the band
overstate reach. 2354 lib tests pass serially with backend-vulkan,host-window,
0 failed. Clippy `-D warnings --all-targets` clean on all three arms. cargo fmt
--all applied and --check clean.

Live, macos-13. A driven Maps interaction on a fresh boot with the fail log
cleared (`grep -c vk_caps` = 1), 86 phases over 45 s of sustained pan and zoom.
The band closes on its own class:

  compute_dst_host_not_linear            35
    type11_agrees                        32
    type11_differs                        3
    type11_unresolved                     0   (route absent)
  compute_dst_no_writeback                0   (route absent)
  compute_dst_guest_pages                15   (2 resident + 13 transient)
  readback_compute_image                 39

So 32 of the 35 windows this arm declines are reachable by a raw copy and 3 are
not, against 15 destinations that take the direct arm today. The five distinct
format pairs the boot produced are on the OFF channel; three name the same texel
on both sides, and the two that differ are a B8G8R8A8_UNORM surface under a
R32G32B32A32_UINT and an R8G8B8A8_UNORM storage image.

Visual. Maps windowed before the drive and full-screen after it both render
correctly with the type layer intact at two very different zoom levels --
Tallinn/Tartu/Parnu/ESTONIA, then the whole Baltic and western Russia with every
label and the scale bar present. Wallpaper gradients, menu bar and Dock all
correct. All eight silent-loss classes read zero, `device_lost=0` across 148
census samples, and no fence wedge or guest panic.

Not verified. Observation only: no guest-visible branch changed, so no
conformance battery was run against a control. One boot, one workload, one rail,
one pathway; the reachable share is a property of this drive's traffic and
another workload may split differently. Metal and arm64 compile but were not
booted.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Anees IqbalandClaude Opus 5 committed 2026-08-30 02:12:15 +03:00
1 parent 753cbc7880
commit bc76f9c46c
2 files changed
+137 -23

No files matched your search

@@ -1381,7 +1381,10 @@ fn staged_window_pages<M: HostMemory>(
///
/// - the writeback must be a **guest-linear plane**. A type-11 destination is a
/// tiled surface mapping, which [`crate::runtime::render_writeback::GvaPlaneDestination`]
/// cannot describe and the licence therefore cannot walk.
/// cannot describe and the licence therefore cannot walk. It is the largest
/// class this arm does not reach, so [`note_type11_shape`] bands how much of
/// it a raw copy could ever serve — see that function for why the route
/// counter alone does not say.
/// - the licence must be granted. That is where the format, the complete page
/// walk, the texel alignment and the guest-RAM references are all checked, in
/// the one place both GPU-side writers of a guest plane meet them.
@@ -1419,6 +1422,7 @@ fn direct_destination<M: HostMemory + HostOps>(
} = &tex.writeback
else {
crate::runtime::drain::note_store_route("compute_dst_host_not_linear");
note_type11_shape(state, tex, held);
return ComputeImageDestination::Host;
};
let Ok(row_stride) = u32::try_from(*row_stride) else {
@@ -1471,6 +1475,67 @@ fn direct_destination<M: HostMemory + HostOps>(
}
}
/// Record whether a type-11 destination could ever be served by a raw copy.
///
/// The type-11 windows are the largest class this arm does not reach, and
/// [`direct_destination`]'s type-11 answer is `Host` before it has looked at
/// anything — so the route counter says how many there are and nothing says how
/// many are *reachable*. That is the number that decides whether a type-11
/// licence is worth building, and it is not the same number: a copy converts
/// nothing, so a window is only reachable when the format the guest will read
/// these bytes back as is exactly the format the dispatch's storage image holds.
///
/// A compute storage image takes its format from the specialized SPIR-V texel
/// format, which has no reason to match a surface mapping's declared one, so
/// `differs` is an expected outcome rather than a defect. The counters split
/// three ways and add up to `compute_dst_host_not_linear`:
///
/// - `agrees` — a raw copy would land these bytes. The reachable population.
/// - `differs` — the mapping and the resident name different texels. Readback
/// and its row converter are the only rail that can land these.
/// - `unresolved` — no mapping, or a declared format with no linear texel
/// order to name. Not reachable by any copy either.
#[cfg(feature = "backend-vulkan")]
fn note_type11_shape(state: &DeviceState, tex: &StagedTexture, held: ash::vk::Format) {
let TextureWriteback::Type11 {
mapping_id,
width,
height,
..
} = &tex.writeback
else {
// A storage image the guest gave nowhere to land. There is no
// destination to reach, so it is not part of the population above.
crate::runtime::drain::note_store_route("compute_dst_no_writeback");
return;
};
let declared = state
.mappings
.get(mapping_id)
.map(crate::runtime::mapping_write::mapping_store_format);
let want = declared
.and_then(crate::contract::pixel_format::store_texel_order)
.map(crate::backend::vulkan::translate::pixel::vk_texel_layout);
match want {
Some(want) if want == held => {
crate::runtime::drain::note_store_route("compute_dst_type11_agrees")
}
Some(_) => crate::runtime::drain::note_store_route("compute_dst_type11_differs"),
None => crate::runtime::drain::note_store_route("compute_dst_type11_unresolved"),
}
// One line per distinct format pair rather than per window: the pairs are
// what a licence would have to serve, and a driven boot repeats a handful of
// them thousands of times.
let key = (u64::from(declared.unwrap_or(0)) << 32) | u64::from(held.as_raw() as u32);
if crate::observe::first_sight("compute_dst_type11_shape", key) {
crate::observe::off(format!(
"compute_dst_type11 bind={} mid={mapping_id} dims={width}x{height} declared={:#x} want={want:?} held={held:?}",
tex.binding,
declared.unwrap_or(0),
));
}
}
/// [`staged_window_pages`] for a flat span — the buffer rail's shape.
fn staged_span_pages<M: HostMemory>(
state: &DeviceState,
@@ -2296,6 +2296,13 @@ fn a_staged_buffer_carries_the_pages_its_writeback_is_bounded_to() {
/// identically to one an earlier gate caught. The census route is what
/// distinguishes them, so each case is asserted on its own counter.
///
/// The type-11 case asserts one thing more. That class is the largest this arm
/// does not reach, and its route counter says only how big it is; the decision
/// about whether to build a type-11 licence turns on how much of it a raw copy
/// could ever serve, which is a different number. So the three verdicts are
/// asserted to *partition* the class — a fourth outcome, or an outcome counted
/// twice, would make the band say more or less reach than there is.
///
/// Vulkan-only: the direct arm is a `VK_EXT_external_memory_host` import, and
/// `StagedTexture` does not carry a residency candidate on the Metal arm at all.
#[cfg(feature = "backend-vulkan")]
@@ -2360,33 +2367,75 @@ fn only_a_licensed_transient_linear_window_can_take_the_direct_arm() {
"the licence refusal is the gate that caught it"
);
// A type-11 destination is not a guest-linear plane at all.
let before = store_route_count("compute_dst_host_not_linear");
assert!(
is_host(&direct_destination(
&mut state,
&mut host,
&staged(
TextureWriteback::Type11 {
mapping_id: 1,
surface_offset: 0,
surface_bpr: 8,
span_end: 16,
width: 2,
height: 2,
bpp: 4,
},
None,
),
held,
)),
"a tiled surface mapping reads back"
// A type-11 destination is not a guest-linear plane at all. It is also the
// largest class this arm does not reach, so the same call must band whether
// a raw copy could ever have served it — the route counter says how many
// there are and the split says how many are reachable.
let type11 = |mapping_id| TextureWriteback::Type11 {
mapping_id,
surface_offset: 0,
surface_bpr: 8,
span_end: 16,
width: 2,
height: 2,
bpp: 4,
};
let split = || {
(
store_route_count("compute_dst_type11_agrees"),
store_route_count("compute_dst_type11_differs"),
store_route_count("compute_dst_type11_unresolved"),
)
};
// A mapping declaring the same texel the dispatch holds: reachable.
state.mappings.insert(
1,
crate::model::MappingEntry {
mapped: true,
has_geom: true,
width: 2,
height: 2,
format: MTL_FORMAT_RGBA8_UNORM,
..Default::default()
},
);
// One declaring a different texel: a copy converts nothing, so no licence
// could land it however the pages resolve.
state.mappings.insert(
2,
crate::model::MappingEntry {
mapped: true,
has_geom: true,
width: 2,
height: 2,
format: crate::contract::pixel_format::MTL_FORMAT_RGBA16_FLOAT,
..Default::default()
},
);
// Mapping 3 is never registered, so its declared format is unresolvable.
let before = store_route_count("compute_dst_host_not_linear");
let (agrees, differs, unresolved) = split();
for mapping_id in [1, 2, 3] {
assert!(
is_host(&direct_destination(
&mut state,
&mut host,
&staged(type11(mapping_id), None),
held,
)),
"a tiled surface mapping reads back"
);
}
assert_eq!(
store_route_count("compute_dst_host_not_linear"),
before + 1,
before + 3,
"a type-11 window never reaches the guest-linear licence"
);
assert_eq!(
split(),
(agrees + 1, differs + 1, unresolved + 1),
"the three verdicts partition the class they band"
);
// And the case this test exists for: a resident window is routed on its
// destination like any other, so it reaches the licence. Asserted against