vgpu: a tiled surface mapping is not a linear plane, which never made it unreachable
Component: crates/reims-vgpu, runtime compute rail and mapping_write, x86 macOS / Linux Vulkan pathway, macos-13 rail, PCI attach, page shift 12. `direct_destination` answered `Host` for a type-11 destination on the shape of the writeback alone, with a `return` before it had looked at the surface. The sentence justifying it was true -- a tiled surface mapping is not a guest-linear plane, and `GvaPlaneDestination` cannot describe one -- and it was an argument about the wrong thing: that the *GVA* licence could not serve these, not that nothing could. The census landed in the parent priced the difference on this rail at 32 of 35 windows, so most of the largest remaining readback class was being read device->host because the code asked which licence it had rather than which one it needed. The destination that describes a type-11 surface already existed, inline in the render rail's `write_bgra8_from_resident_gpu`: resolve the sample window, walk the mapping's page entries, take the guest-write witnesses, build a `GuestPageTarget`. That is split out as `licence_type11_surface`, the type-11 counterpart of `render_writeback::licence_gva_plane`, and the render caller is now three lines over it. Both rails that write a guest surface from the GPU meet the geometry rule, the format rule, the page walk and the guest-RAM references in one place, and a third could not spell any of them differently. Two things the split had to decide rather than move: - The format check moves into the licence. The render caller left it to `copy_target_to_guest_pages`, which compares against the resident image's own format -- a real check, still there, and one the compute rail has no equivalent of, because its dispatch writes the guest's pages itself and there is no second pair downstream. The licence now takes `held` and refuses `ResidentFormatMismatch` by name. Whole formats, not channel orders: RGBA16_FLOAT and RGBA8_UNORM are both RGBA-ordered and four bytes per texel apart, so an order comparison would land a frame of the wrong size. - The post-copy bookkeeping becomes `note_type11_landed` -- the residency window, the mapping's written mark, the surface cache forget. Called by the render Store after its copy and by the compute `Landed` arm. Both err early rather than late: a cache forgotten early costs a re-read, one forgotten late hands out a stale frame. The engine pin needs no change. `record_guest_write_debt` keys off the resource's residency and its destination being `GuestPages`, neither of which is about the writeback's shape, so a type-11 resident takes the same `ResidentStorage` pin against the same re-key window. Tests. `a_licence_and_not_the_destinations_shape_decides_the_direct_arm` (renamed from `only_a_licensed_transient_linear_window_can_take_the_direct_arm`, which no longer described it) asserts `compute_dst_host_not_linear` does not move for three type-11 mappings and that all three land on `compute_dst_host_type11_unlicensed` instead. Confirmed red without the change by stubbing the arm back to its early return: it fails 3 against an expected 0 on `compute_dst_host_not_linear`; restored by copying the file back, never via git. 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. Conformance, macos-13. Three controls atbc76f9c4and two candidates, complete battery each: 184 PASS / 77 FAIL / 29 SKIP in all five, and the per-case result files are byte-identical across all five runs over 290 cases. Zero transitions, no missing or duplicate case, no catastrophic run. The routing moved as the census predicted. Against the control envelope (`compute_dst_guest_pages` 7, `compute_dst_host_not_linear` 15-17 splitting into 14 agrees and 1-3 differs), the candidate reads `compute_dst_guest_pages` 21 -- the same 7 plus 14 type-11 residents, exactly the agreeing population -- with `compute_dst_host_type11_unlicensed` 3 and `readback_compute_image` down from 17-19 to 5-7. `compute_wb_landed` 21 matches. Visual, 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. Maps windowed before the drive and full-screen after it both render correctly with the type layer intact -- Tallinn/Tartu/Parnu/ESTONIA at one zoom, the Indian Ocean rim with every city label at the other. Wallpaper, menu bar and Dock correct. All eight silent-loss classes zero, no device loss, no fence wedge, no panic. Under that workload the arm took 35 landings, 20 of them type-11 residents, with `readback_compute_image` at 21 against the parent boot's 39. All 15 remaining type-11 declines are `GeometryMoved`. Import-off. Two `REIMS_VGPU_GUEST_IMPORT=off` controls atbc76f9c4and two candidates. Both controls read 182 PASS / 79 FAIL / 29 SKIP and are identical per case. One candidate is identical to them; the other reads 183 PASS, passing `srt_blit_after_render_1024x768`, which both controls fail. Zero regressions in that cell, and the `srt_blit_after_render_*` family remains the control-unstable one already on record for it. Not verified. `GeometryMoved` refusing 15 of the 19 remaining compute readbacks is measured and not repaired here; it is a scanout Store's rule applied to a destination that is not one, and it wants its own change. Bytes saved are counted, not measured against a byte total. One visual interaction; two candidate batteries per cell. Only the macos-13 rail and the x86 macOS / Linux Vulkan pathway were booted -- the Metal arm compiles and its tests do not run on this host, and no arm64 or MoltenVK pathway was exercised. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bc76f9c46c
commit
4eb3fcb906
3 files changed
+254
-96
No files matched your search
@@ -1421,9 +1421,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;
|
||||
return type11_destination(state, host, tex, held);
|
||||
};
|
||||
let Ok(row_stride) = u32::try_from(*row_stride) else {
|
||||
crate::runtime::drain::note_store_route("compute_dst_host_stride_width");
|
||||
@@ -1475,28 +1473,32 @@ fn direct_destination<M: HostMemory + HostOps>(
|
||||
}
|
||||
}
|
||||
|
||||
/// Record whether a type-11 destination could ever be served by a raw copy.
|
||||
/// [`direct_destination`] for a type-11 surface mapping.
|
||||
///
|
||||
/// 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 tiled surface mapping is not a guest-linear plane and the GVA licence
|
||||
/// cannot describe one — but it is not therefore unreachable, and treating it as
|
||||
/// such is what this arm used to do. It answered `Host` before looking at
|
||||
/// anything, and on a driven macos-13 boot that was 35 of the 51 storage
|
||||
/// destinations, every one of them a device→host crossing.
|
||||
///
|
||||
/// 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`:
|
||||
/// The destination that *can* describe it already existed on the render rail,
|
||||
/// resolving the sample window, walking the mapping's page entries and building
|
||||
/// the same [`crate::backend::vulkan::engine::GuestPageTarget`] this rail wants.
|
||||
/// It is now [`crate::runtime::mapping_write::licence_type11_surface`] and both
|
||||
/// rails ask it, so the surface geometry, the format rule, the page walk and the
|
||||
/// guest-RAM references have one spelling rather than two.
|
||||
///
|
||||
/// - `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.
|
||||
/// Every decline is a routing answer on the `OFF` channel, not a loss: readback
|
||||
/// lands identical bytes, and on a host without the guest-RAM import it is the
|
||||
/// only rail there is.
|
||||
#[cfg(feature = "backend-vulkan")]
|
||||
fn note_type11_shape(state: &DeviceState, tex: &StagedTexture, held: ash::vk::Format) {
|
||||
fn type11_destination<M: HostMemory + HostOps>(
|
||||
state: &mut DeviceState,
|
||||
host: &mut M,
|
||||
tex: &StagedTexture,
|
||||
held: ash::vk::Format,
|
||||
) -> crate::backend::vulkan::engine::ComputeImageDestination {
|
||||
use crate::backend::vulkan::engine::ComputeImageDestination;
|
||||
let TextureWriteback::Type11 {
|
||||
mapping_id,
|
||||
width,
|
||||
@@ -1504,35 +1506,45 @@ fn note_type11_shape(state: &DeviceState, tex: &StagedTexture, held: ash::vk::Fo
|
||||
..
|
||||
} = &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.
|
||||
// A storage image the guest gave nowhere to land. Not a destination this
|
||||
// arm declined — there is no destination.
|
||||
crate::runtime::drain::note_store_route("compute_dst_no_writeback");
|
||||
return;
|
||||
return ComputeImageDestination::Host;
|
||||
};
|
||||
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")
|
||||
match crate::runtime::mapping_write::licence_type11_surface(
|
||||
state,
|
||||
host,
|
||||
*mapping_id,
|
||||
held,
|
||||
*width,
|
||||
*height,
|
||||
) {
|
||||
Ok(licence) => {
|
||||
crate::runtime::drain::note_store_route("compute_dst_guest_pages");
|
||||
crate::runtime::drain::note_store_route(if tex.residency.is_some() {
|
||||
"compute_dst_guest_pages_type11_resident"
|
||||
} else {
|
||||
"compute_dst_guest_pages_type11_transient"
|
||||
});
|
||||
ComputeImageDestination::GuestPages {
|
||||
target: Box::new(licence.target),
|
||||
pages: licence.gpas,
|
||||
}
|
||||
}
|
||||
Err(decline) => {
|
||||
// Named, because the reasons are not interchangeable and the route
|
||||
// counter cannot tell them apart. The one that dominates is
|
||||
// `ResidentFormatMismatch` — a storage image's format comes from the
|
||||
// specialized SPIR-V texel format and owes the mapping's declaration
|
||||
// nothing — and no copy can serve those, so a boot where it is most
|
||||
// of this counter is this arm working rather than failing.
|
||||
crate::observe::off(format!(
|
||||
"compute_dst_type11 bind={} mid={mapping_id} dims={width}x{height} held={held:?} reason={decline:?}",
|
||||
tex.binding
|
||||
));
|
||||
crate::runtime::drain::note_store_route("compute_dst_host_type11_unlicensed");
|
||||
ComputeImageDestination::Host
|
||||
}
|
||||
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),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4490,16 +4502,36 @@ fn execute_dispatch_linux<M: HostMemory + HostOps>(
|
||||
// previous dispatch's readback may have left an entry, and it
|
||||
// is stale by exactly one frame. Same call, same reason, as
|
||||
// both arms of the render rail's GVA Store.
|
||||
if let TextureWriteback::Linear {
|
||||
gva, texture_ref, ..
|
||||
} = &t.writeback
|
||||
{
|
||||
crate::runtime::surface_cache::forget_gva_copies(
|
||||
match &t.writeback {
|
||||
TextureWriteback::Linear {
|
||||
gva, texture_ref, ..
|
||||
} => crate::runtime::surface_cache::forget_gva_copies(
|
||||
state,
|
||||
task_id,
|
||||
*gva,
|
||||
*texture_ref,
|
||||
);
|
||||
),
|
||||
// The surface-keyed rail owes more than a cache forget — a
|
||||
// resident storage window over these bytes and the mapping's
|
||||
// own written mark — and the render Store that shares this
|
||||
// destination owes exactly the same set. Both call it.
|
||||
//
|
||||
// The offsets are the staged ones rather than the licence's,
|
||||
// and they are the same offsets: `licence_type11_surface`
|
||||
// resolves the window through `type11_sample_window`, which
|
||||
// is where these came from when the texture was staged.
|
||||
TextureWriteback::Type11 {
|
||||
mapping_id,
|
||||
surface_offset,
|
||||
span_end,
|
||||
..
|
||||
} => crate::runtime::mapping_write::note_type11_landed(
|
||||
state,
|
||||
*mapping_id,
|
||||
*surface_offset,
|
||||
*span_end,
|
||||
),
|
||||
TextureWriteback::None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2276,12 +2276,12 @@ fn a_staged_buffer_carries_the_pages_its_writeback_is_bounded_to() {
|
||||
assert!(staged_span_pages(&state, &host, 1, page, 0).is_empty());
|
||||
}
|
||||
|
||||
/// The direct arm refuses on the shape of the destination, and on nothing else.
|
||||
/// Every destination reaches a licence; nothing is turned away for its shape.
|
||||
///
|
||||
/// Two refusals, and the third case is the one that must *not* refuse. A type-11
|
||||
/// destination is a tiled surface mapping the guest-linear licence cannot
|
||||
/// describe. A window whose pages did not resolve cannot be licensed. Residency
|
||||
/// is neither: a registered resident is a perfectly good source for a copy, and
|
||||
/// Both destination shapes have one, and the shapes differ only in which licence
|
||||
/// answers — a guest-linear plane goes to `licence_gva_plane` and a tiled surface
|
||||
/// mapping to `licence_type11_surface`. Residency is not a shape at all: a
|
||||
/// registered resident is a perfectly good source for a copy, and
|
||||
/// what holds it across a submitted-not-waited copy is the engine's pin, taken
|
||||
/// where the write debt is armed and released from the ring slot's cleanup.
|
||||
///
|
||||
@@ -2296,18 +2296,20 @@ 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.
|
||||
/// The type-11 cases assert the thing that is easiest to regress back to. That
|
||||
/// class was the largest this arm did not reach — 35 of the 51 storage
|
||||
/// destinations of a driven macos-13 boot — and the reason was a `return` on the
|
||||
/// destination's *shape*, before anything about the surface had been asked. A
|
||||
/// tiled surface mapping is not a guest-linear plane, which is true, and does
|
||||
/// not make it unreachable. So `compute_dst_host_not_linear` is asserted at
|
||||
/// zero: reintroducing that early answer would read as a correct statement about
|
||||
/// the GVA licence and put 91 % of the class back on the readback rail.
|
||||
///
|
||||
/// 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")]
|
||||
#[test]
|
||||
fn only_a_licensed_transient_linear_window_can_take_the_direct_arm() {
|
||||
fn a_licence_and_not_the_destinations_shape_decides_the_direct_arm() {
|
||||
use crate::backend::vulkan::engine::ComputeImageDestination;
|
||||
use crate::contract::pixel_format::MTL_FORMAT_RGBA8_UNORM;
|
||||
use crate::runtime::drain::census::store_route_count;
|
||||
@@ -2380,13 +2382,7 @@ fn only_a_licensed_transient_linear_window_can_take_the_direct_arm() {
|
||||
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"),
|
||||
)
|
||||
};
|
||||
let unlicensed = || store_route_count("compute_dst_host_type11_unlicensed");
|
||||
// A mapping declaring the same texel the dispatch holds: reachable.
|
||||
state.mappings.insert(
|
||||
1,
|
||||
@@ -2412,9 +2408,16 @@ fn only_a_licensed_transient_linear_window_can_take_the_direct_arm() {
|
||||
..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();
|
||||
// Mapping 3 is never registered, so there is nothing to write into.
|
||||
//
|
||||
// All three answer `Host` here, and for three different reasons, only one of
|
||||
// which is about the format: `FakeHost` publishes no guest-RAM import, so
|
||||
// even the agreeing mapping's licence is refused at the reference walk. What
|
||||
// this asserts is that all three *reached* the licence — the arm no longer
|
||||
// answers `Host` on the shape of the destination alone, which is what it did
|
||||
// for 35 of the 51 storage destinations of a driven macos-13 boot.
|
||||
let before = unlicensed();
|
||||
let not_linear = store_route_count("compute_dst_host_not_linear");
|
||||
for mapping_id in [1, 2, 3] {
|
||||
assert!(
|
||||
is_host(&direct_destination(
|
||||
@@ -2423,18 +2426,21 @@ fn only_a_licensed_transient_linear_window_can_take_the_direct_arm() {
|
||||
&staged(type11(mapping_id), None),
|
||||
held,
|
||||
)),
|
||||
"a tiled surface mapping reads back"
|
||||
"no guest-RAM import, so every type-11 licence is refused here"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
store_route_count("compute_dst_host_not_linear"),
|
||||
unlicensed(),
|
||||
before + 3,
|
||||
"a type-11 window never reaches the guest-linear licence"
|
||||
"the type-11 licence is what refused, not the destination's shape"
|
||||
);
|
||||
// A delta and not an absolute: these counters are process-global and this
|
||||
// suite runs serially in one binary, so a zero read absolutely would be
|
||||
// asserting about every other test too.
|
||||
assert_eq!(
|
||||
split(),
|
||||
(agrees + 1, differs + 1, unresolved + 1),
|
||||
"the three verdicts partition the class they band"
|
||||
store_route_count("compute_dst_host_not_linear"),
|
||||
not_linear,
|
||||
"a type-11 destination is no longer turned away for not being linear"
|
||||
);
|
||||
|
||||
// And the case this test exists for: a resident window is routed on its
|
||||
|
||||
@@ -666,6 +666,21 @@ pub enum GpuWritebackDecline {
|
||||
/// it needs a per-row conversion. A buffer→image copy performs none, which
|
||||
/// is why this is a routing answer rather than something to work around.
|
||||
FormatNeedsConversion { format: u16 },
|
||||
/// The mapping's declared format has a linear texel to name, and the source
|
||||
/// image does not hold it. Same consequence as the variant above and a
|
||||
/// different cause: there the guest declared something no copy can express,
|
||||
/// here the two sides simply disagree.
|
||||
///
|
||||
/// Expected on the compute rail, where a storage image's format comes from
|
||||
/// the specialized SPIR-V texel format and owes a surface mapping's
|
||||
/// declaration nothing. Whole formats, not channel orders: `RGBA16_FLOAT`
|
||||
/// and `RGBA8_UNORM` are both RGBA-ordered and four bytes per texel apart,
|
||||
/// so an order comparison would admit a half-float source over an eight-bit
|
||||
/// destination and land a frame of the wrong size.
|
||||
ResidentFormatMismatch {
|
||||
held: ash::vk::Format,
|
||||
want: ash::vk::Format,
|
||||
},
|
||||
/// The guest's row pitch is not a whole number of texels, so it cannot be
|
||||
/// expressed as `bufferRowLength`.
|
||||
PitchNotTexels { bpr: u32 },
|
||||
@@ -715,6 +730,7 @@ impl crate::observe::Decline for GpuWritebackDecline {
|
||||
Self::GeometryMoved { .. } => "gpuwb_geometry_moved",
|
||||
Self::WindowUnresolved { .. } => "gpuwb_window_unresolved",
|
||||
Self::FormatNeedsConversion { .. } => "gpuwb_format_needs_conversion",
|
||||
Self::ResidentFormatMismatch { .. } => "gpuwb_resident_format_mismatch",
|
||||
Self::PitchNotTexels { .. } => "gpuwb_pitch_not_texels",
|
||||
Self::OffsetNotTexelAligned { .. } => "gpuwb_offset_not_texel_aligned",
|
||||
Self::PageListShort { .. } => "gpuwb_page_list_short",
|
||||
@@ -757,6 +773,9 @@ impl crate::observe::Decline for GpuWritebackDecline {
|
||||
("fmt", format!("{format:#x}")),
|
||||
],
|
||||
Self::FormatNeedsConversion { format } => vec![("fmt", format!("{format:#x}"))],
|
||||
Self::ResidentFormatMismatch { held, want } => {
|
||||
vec![("held", format!("{held:?}")), ("want", format!("{want:?}"))]
|
||||
}
|
||||
Self::PitchNotTexels { bpr } => vec![("bpr", bpr.to_string())],
|
||||
Self::OffsetNotTexelAligned { in_page } => vec![("in_page", in_page.to_string())],
|
||||
Self::PageListShort { need, have } => {
|
||||
@@ -925,6 +944,83 @@ pub fn write_bgra8_from_resident_gpu<M: HostMemory + HostOps>(
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<u64, GpuWritebackDecline> {
|
||||
let licence = licence_type11_surface(
|
||||
state,
|
||||
host,
|
||||
mapping_id,
|
||||
identity.resident_format(),
|
||||
width,
|
||||
height,
|
||||
)?;
|
||||
crate::backend::vulkan::engine::copy_target_to_guest_pages(
|
||||
identity,
|
||||
&licence.target,
|
||||
&licence.gpas,
|
||||
)
|
||||
.map_err(|inner| GpuWritebackDecline::Engine { inner })?;
|
||||
note_type11_landed(state, mapping_id, licence.base_off, licence.span_end);
|
||||
Ok(licence.span_end - licence.base_off)
|
||||
}
|
||||
|
||||
/// A licensed direct-to-guest-pages destination over a type-11 surface mapping.
|
||||
///
|
||||
/// The type-11 counterpart of
|
||||
/// [`crate::runtime::render_writeback::GvaPlaneLicence`], and it exists for the
|
||||
/// same reason: the two rails that write a guest surface from the GPU — a render
|
||||
/// Store and a compute storage-image output — differ only in the image they copy
|
||||
/// *from* and in which command buffer records the copy. Everything about the
|
||||
/// destination is this, so it is derived once and the second rail cannot spell
|
||||
/// any of it differently.
|
||||
///
|
||||
/// `base_off` and `span_end` are carried because the landing note needs them and
|
||||
/// deriving them a second time would be a second answer to a question the
|
||||
/// licence already asked. See [`note_type11_landed`].
|
||||
#[cfg(feature = "backend-vulkan")]
|
||||
pub(crate) struct Type11SurfaceLicence {
|
||||
pub target: crate::backend::vulkan::engine::GuestPageTarget,
|
||||
/// The pages walked, in the surface's own order — what the copy is licensed
|
||||
/// over and what every witness on this path is armed against.
|
||||
pub gpas: Vec<u64>,
|
||||
/// The window within the mapping the copy names, and nothing past it.
|
||||
pub base_off: u64,
|
||||
pub span_end: u64,
|
||||
}
|
||||
|
||||
/// Resolve a type-11 surface mapping into a destination the GPU may copy into,
|
||||
/// or the typed reason it may not.
|
||||
///
|
||||
/// `held` is the format the source image actually holds. **A copy converts
|
||||
/// nothing**, so a source whose format is not the one the guest will read these
|
||||
/// bytes back as must be refused here rather than landed.
|
||||
///
|
||||
/// # Why this asks about the format and the render caller used not to
|
||||
///
|
||||
/// On the render rail the question is very nearly a tautology — a target's
|
||||
/// identity takes its format from [`mapping_store_format`], the same function
|
||||
/// [`mapping_write_geometry`] reads below — and the comparison that can actually
|
||||
/// fail is made downstream by `copy_target_to_guest_pages`, against the resident
|
||||
/// *image's* own format, which a mapping may have redeclared underneath. Both of
|
||||
/// those are still true and that check is still there.
|
||||
///
|
||||
/// The compute rail has no such downstream. Its dispatch writes the guest's
|
||||
/// pages itself, so there is no second pair to compare and this is the only
|
||||
/// place the question can be asked. A storage image takes its format from the
|
||||
/// specialized SPIR-V texel format, which has no reason to match a surface
|
||||
/// mapping's declaration — measured at 3 of 35 type-11 windows on a driven
|
||||
/// macos-13 boot — so on that rail it is not a healthy zero either.
|
||||
///
|
||||
/// Asking it for both callers rather than for the one that needs it keeps the
|
||||
/// rule in the licence, where a third writer of a guest surface would meet it
|
||||
/// without knowing to look.
|
||||
#[cfg(feature = "backend-vulkan")]
|
||||
pub(crate) fn licence_type11_surface<M: HostMemory + HostOps>(
|
||||
state: &mut DeviceState,
|
||||
host: &mut M,
|
||||
mapping_id: u32,
|
||||
held: ash::vk::Format,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<Type11SurfaceLicence, GpuWritebackDecline> {
|
||||
if !scanout_extent_ok(width, height) {
|
||||
return Err(GpuWritebackDecline::NotWritable);
|
||||
}
|
||||
@@ -948,19 +1044,19 @@ pub fn write_bgra8_from_resident_gpu<M: HostMemory + HostOps>(
|
||||
// name. A compressed or planar declaration has none, and the copying rail's
|
||||
// row converter is the only thing that can land it.
|
||||
//
|
||||
// Not a check that the resident *holds* that format. The identity carries
|
||||
// the format its image was created with and takes it from
|
||||
// `mapping_store_format`, the same function `mapping_write_geometry` above
|
||||
// reads — so asking here whether the two agree would be asking one input
|
||||
// whether it equals itself. The question is asked once, on the authoritative
|
||||
// pair, by `copy_target_to_guest_pages`: it compares the destination's
|
||||
// format against the resident image's own and refuses by name. That is the
|
||||
// comparison that can actually fail, because a mapping can redeclare its
|
||||
// format under a resident minted before it did.
|
||||
let Some(layout) = pixel_format::store_texel_order(format) else {
|
||||
return Err(GpuWritebackDecline::FormatNeedsConversion { format });
|
||||
};
|
||||
let dst_format = crate::backend::vulkan::translate::pixel::vk_texel_layout(layout);
|
||||
// And that the source holds exactly it. See this function's doc for why the
|
||||
// render caller's own downstream check stays where it is: the two compare
|
||||
// different pairs, and this is the only one the compute rail has.
|
||||
if held != dst_format {
|
||||
return Err(GpuWritebackDecline::ResidentFormatMismatch {
|
||||
held,
|
||||
want: dst_format,
|
||||
});
|
||||
}
|
||||
let texel = layout.bytes_per_texel();
|
||||
let Some((base_off, bpr, span_end)) = type11_sample_window(m, mw, mh, format) else {
|
||||
return Err(GpuWritebackDecline::WindowUnresolved {
|
||||
@@ -1127,16 +1223,40 @@ pub fn write_bgra8_from_resident_gpu<M: HostMemory + HostOps>(
|
||||
ReadbackPhase::Resolve,
|
||||
resolve_started.elapsed().as_micros() as u64,
|
||||
);
|
||||
crate::backend::vulkan::engine::copy_target_to_guest_pages(identity, &target, &gpas)
|
||||
.map_err(|inner| GpuWritebackDecline::Engine { inner })?;
|
||||
Ok(Type11SurfaceLicence {
|
||||
target,
|
||||
gpas,
|
||||
base_off,
|
||||
span_end,
|
||||
})
|
||||
}
|
||||
|
||||
/// What a landed type-11 GPU write owes the rest of the device.
|
||||
///
|
||||
/// Called once the copy is *issued*, not once it has completed, and by both
|
||||
/// rails that issue one — the render Store, which submits and waits, and the
|
||||
/// compute storage-image output, whose copy rides its dispatch's own command
|
||||
/// buffer and lands at the fence. Neither leaves a host copy of the frame, so
|
||||
/// nothing on the host may go on naming one, and that is true from the moment
|
||||
/// the copy is queued rather than from the moment it retires.
|
||||
///
|
||||
/// Every one of these errs in the same direction on purpose: a cache forgotten
|
||||
/// early costs a re-read of bytes that are about to change anyway, while one
|
||||
/// forgotten late hands out a stale frame as fresh. The same argument the
|
||||
/// witnesses in [`licence_type11_surface`] are armed on.
|
||||
#[cfg(feature = "backend-vulkan")]
|
||||
pub(crate) fn note_type11_landed(
|
||||
state: &mut DeviceState,
|
||||
mapping_id: u32,
|
||||
base_off: u64,
|
||||
span_end: u64,
|
||||
) {
|
||||
state.invalidate_storage_residency_window(mapping_id, base_off, span_end);
|
||||
let _ = state.mark_mapping_written(mapping_id);
|
||||
// Nothing here leaves a host copy of the frame, so the surface cache must
|
||||
// not go on naming one: its entry, if any, is a previous flush's bytes and
|
||||
// the guest's pages are now the only place this frame exists. Same reason
|
||||
// The guest's pages are now the only place this frame exists, and the
|
||||
// surface cache's entry, if any, is a previous flush's bytes. Same reason
|
||||
// `write_bgra8_uncached` invalidates rather than publishes.
|
||||
crate::runtime::surface_cache::forget(state, mapping_id);
|
||||
Ok(span_end - base_off)
|
||||
}
|
||||
|
||||
/// Publish a Store from an attachment already backed by this mapping.
|
||||
|
||||
Reference in new issue
Block a user