Files
6gbvram---16gb-ram/crates/victory-gpu/src/lib.rs
T
readmet3xt-labandClaude Opus 5.5 fb838e8251 Title views kept in the books alone until the title's CPU touches them (VICTORY_SOFT_VIEWS, off by default)
VICTORY_SOFT_VIEWS=1 (pool: the title's XMemMapPhysicalPages views alone;
copies: those of CopyPageMappingsBatchX alone): a view is noted in the
runtime's books and told to the GPU side as mapped, its addresses are one
placeholder of their own, and the host maps nothing. Each view of the host's
was a MapViewOfFile3 (45 us) and later an UnmapViewOfFile2 (93 us), both
behind a lock of the kernel's that the guards' protection changes take too:
445,503 maps (20.1 s) and 349,175 unmaps (32.6 s) in 143 s of run stream2,
359,969 mapping calls 23.8 s, 3,294 page-mapping copies 33.7 s, one of them
467 ms of a 608 ms frame (timeline tl.120).

Who gets the bytes of such a view, and how:
- DirectStorage writes pages by number through the section's own view, and
  page-mapping copies read the pool from the books: as before.
- The GPU side's reads of title memory (host::read, read_sparse) take them
  from the pages through the section's view (xmem::soft_read); a texture
  with such views is read through a copy, not in place; texture::committed
  takes such views for committed.
- The guards keep such a view in their books (watch::protect_here,
  protect_alias): no VirtualProtect, no question to the host. A write the
  runtime tells of, or one through another view of the page, opens it as
  before.
- Any touch of the memory itself (the title's CPU, a direct read of ours)
  faults; the GPU side's handler has the runtime map the view and the access
  is made again; the guards then open it and every other view of its page
  (title_memory_made_real). Our writes through the kernel, announced kernel
  writes, and the title's XMemVirtualQuery, XMemVirtualAlloc, VirtualFree
  and (with the switch) VirtualQuery and VirtualProtect ask first.

Why VICTORY_LAZY_VIEWS=1 ran at 2 fps (run xw-lazy, 2.4 to 3.4 GB of copies
a frame): a view guarded together with a lazy view of the same page was
never clean, because the host refuses to protect a placeholder
(protect_alias), so it was copied again at every asking; and every guarded
range made its lazy views real. Both are what the books replace here. Also
for both switches: a view is known as lazy before the GPU side is told of
it (a refresh in between noted the block absent), and its pages are
committed when it is noted (the GPU side writes them through its own view
of the section).

Counted: the streaming log's M line gets twelve more fields with either
switch (noted, let go untouched, made real; noted by mapping calls, by
copies; made real by a fault of the title's code, of other code, asked for
by the GPU side, by a call of the title's; reads served from the pages,
their KiB; such views now), and with VICTORY_SOFT_VIEWS the log has a line
of the same every 10 s, with the last faulting address and code.

Tests: xmem and host views_in_the_books_alone_are_read_from_their_pages, watch
a_view_in_the_books_alone_is_guarded_there. Not run in the game yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 00:32:01 +05:30

126 lines
3.3 KiB
Rust

//! D3D12.X on host D3D12.
//!
//! D3D12.X records commands from code inlined into the title, which writes
//! packets into the command list while its put pointer is below a limit and
//! calls the list's method otherwise. Our lists keep the limits at zero, so
//! every command arrives here as a call, to be run on host D3D12. The
//! title's GPU addresses are CPU addresses (console memory is unified).
//!
//! [`device`] is the device object titles create, [`dxgi`] its adapter side,
//! [`resource`] heaps and resources, [`fence`] fences, [`queue`] command
//! queues, [`list`] command allocators and lists, [`descriptor`]
//! descriptor heaps, [`root`] root signatures, [`query`] query heaps,
//! [`signature`] command signatures, [`pipeline`] pipeline states,
//! [`frame`] frame pacing, [`object`] what all console graphics objects
//! share, [`console`] which console model the title sees. Planned:
//! `present` (swap chain).
#[cfg(windows)]
mod ambient;
#[cfg(all(windows, feature = "diagnostics"))]
mod capture;
#[cfg(windows)]
mod compose;
pub mod console;
#[cfg(all(windows, feature = "diagnostics"))]
mod copystat;
#[cfg(all(windows, feature = "diagnostics"))]
mod faultbook;
#[cfg(windows)]
mod cores;
pub mod descriptor;
pub mod device;
#[cfg(windows)]
mod draw;
pub mod dxgi;
#[cfg(windows)]
mod external;
pub mod fence;
pub mod frame;
#[cfg(all(windows, feature = "diagnostics"))]
mod book;
#[cfg(windows)]
mod host;
#[cfg(windows)]
mod indirect;
#[cfg(windows)]
mod inplace;
#[cfg(windows)]
mod land;
pub mod list;
pub mod object;
pub mod pipeline;
#[cfg(windows)]
mod picked;
#[cfg(windows)]
mod pool;
#[cfg(all(windows, feature = "diagnostics"))]
mod popwatch;
#[cfg(windows)]
mod primitive;
pub mod query;
pub mod queue;
#[cfg(all(windows, feature = "diagnostics"))]
pub mod replay;
#[cfg(windows)]
mod residency;
pub mod resource;
pub mod root;
#[cfg(windows)]
mod safecopy;
#[cfg(windows)]
mod sampler;
#[cfg(windows)]
pub mod shader_cache;
#[cfg(windows)]
mod memory;
#[cfg(windows)]
mod shadow;
#[cfg(windows)]
mod tiles;
pub mod signature;
#[cfg(windows)]
pub mod streamline;
mod switch;
#[cfg(all(windows, feature = "diagnostics"))]
mod ab;
#[cfg(windows)]
mod tdr;
#[cfg(windows)]
mod texture;
pub mod timeline;
#[cfg(windows)]
pub mod titlewrite;
#[cfg(windows)]
mod upload;
#[cfg(windows)]
mod watch;
#[cfg(windows)]
mod texback;
#[cfg(windows)]
pub use host::on_failure;
/// Whether `switch` is on now, if it is one of those `VICTORY_AB` turns on and
/// off while the title runs (`ab`).
#[cfg(all(windows, feature = "diagnostics"))]
pub fn switched(switch: &str) -> Option<bool> {
ab::pick(switch)
}
/// What the frame is at (`copystat::phase`), for the sampling profiler.
#[cfg(all(windows, feature = "diagnostics"))]
pub fn frame_phase() -> u32 {
copystat::phase()
}
#[cfg(windows)]
pub use inplace::{title_memory_freeing, title_memory_section, title_memory_section_gone, title_memory_view};
#[cfg(windows)]
pub use shadow::title_memory_write_combined;
#[cfg(windows)]
pub use watch::{
SoftViews, kernel_writing, soft_view_guards, title_memory_allocated, title_memory_freed, title_memory_made_real,
title_memory_reading, title_memory_remapped, title_memory_remapping, title_memory_splitting, title_memory_unmapping,
title_memory_written, use_lazy_views, use_soft_views, writing as kernel_will_write,
};