GPU: pipelines off the render thread and cached; indirect execution on

With indirect execution the world's first frame asked for over 1,200
pipelines at once and took more than 30 s, so the title's own GPU
watchdog ended the run. Host pipelines are now made by worker threads: a
first use waits at most 0.5 s per title frame, and that pipeline's draws
are dropped until it is ready. The world presents frames again, and
indirect execution is the default (the switch is gone).

Pipelines are cached across runs:
- every host pipeline goes into a pipeline library saved under the cache
  folder (named by a hash of the translated code, our root signature and
  the state; a blob the device rejects starts an empty library);
- the pipelines drawn with are remembered and started during loading on
  the next run.
One cold and one warm run: the last pipeline was ready 38 s after the
world's first frame cold, 1.4 s warm; the first world frame took 3.2 s
cold, 0.37 s warm.

Also:
- Copy-backs of shader-written ranges return only the bytes the GPU
  changed; they used to overwrite what the title's CPU wrote meanwhile,
  which crashed the title.
- Indirect dispatch records are bounded (group counts were not), and the
  console's single-dispatch argument type runs as a dispatch.
- Per-shader counts of dropped draws in the diagnostics log; a switch
  that submits and times each list alone.

Not working yet: the world shows no geometry, and runs end on a GPU page
fault after at most about 55 s.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
MarvisandClaude Fable 5.2 committed 2026-11-24 01:02:11 +01:00
1 parent 97c78d1087
commit 35b054ec03
13 files changed
+1018 -101

No files matched your search

+72 -15
View File
@@ -159,11 +159,10 @@ struct Pipeline {
shaders: Vec<Arc<Shader>>,
/// Whether a list has bound it yet (its shaders are logged then).
bound: std::sync::atomic::AtomicBool,
/// The rest of a stream's graphics state, for the host pipeline.
/// What its host pipeline is made from, and the host pipeline once made
/// (by a worker: the title may release the pipeline meanwhile).
#[cfg(windows)]
graphics: Option<Box<host::GraphicsState>>,
#[cfg(windows)]
host: OnceLock<Option<host::HostPipeline>>,
host: Arc<make::Pending>,
}
const _: () = assert!(offset_of!(Pipeline, packet) == 0x10);
@@ -191,17 +190,56 @@ pub(crate) fn bound(this: This) {
}
}
/// The host pipeline of a title pipeline, made on first use; `None` if one
/// of its shaders does not translate or the host refuses it.
/// The host pipeline of a title pipeline; `None` if one of its shaders does
/// not translate, the host refuses it, or it is still being made (its first
/// use starts that, see [`make`]).
#[cfg(windows)]
pub(crate) fn host_pipeline<'a>(this: This) -> Option<&'a host::HostPipeline> {
if this.is_null() {
return None;
}
let p = pipeline(this);
p.host
.get_or_init(|| host::HostPipeline::new(&p.shaders, p.graphics.as_deref()))
.as_ref()
make::ready(&pipeline(this).host)
}
/// Host pipelines queued and not made yet.
#[cfg(windows)]
pub(crate) fn making() -> u64 {
make::waiting()
}
/// Draws and dispatches dropped since the last [`take_drops`], by why their
/// pipeline has no host pipeline (diagnostics).
#[cfg(all(windows, feature = "diagnostics"))]
static DROPS: Mutex<Option<HashMap<String, u64>>> = Mutex::new(None);
/// Counts a draw or dispatch of `this` dropped for want of a host pipeline
/// (diagnostics).
#[cfg(all(windows, feature = "diagnostics"))]
pub(crate) fn note_drop(this: This) {
let why = if this.is_null() {
Some("no pipeline set".to_owned())
} else {
make::missing(&pipeline(this).host)
};
if let Some(why) = why {
note_why(why);
}
}
/// Counts a draw or dispatch dropped for `why` (diagnostics).
#[cfg(all(windows, feature = "diagnostics"))]
pub(crate) fn note_why(why: String) {
let mut drops = DROPS.lock().unwrap_or_else(|e| e.into_inner());
*drops.get_or_insert_with(HashMap::new).entry(why).or_default() += 1;
}
/// The drops counted since the last call, most first (diagnostics).
#[cfg(all(windows, feature = "diagnostics"))]
pub(crate) fn take_drops() -> Vec<(String, u64)> {
let drops = DROPS.lock().unwrap_or_else(|e| e.into_inner()).take();
let mut drops: Vec<(String, u64)> = drops.into_iter().flatten().collect();
drops.sort_by_key(|d| std::cmp::Reverse(d.1));
drops
}
/// The stage's container, if it has one.
@@ -222,15 +260,17 @@ fn hand_out(
out: *mut This,
) -> HRESULT {
tracing::trace!(?shaders, "pipeline state");
#[cfg(windows)]
let host = Arc::new(make::Pending::new(shaders.clone(), graphics));
#[cfg(windows)]
make::early(&host);
let pipeline = Box::new(Pipeline {
object: Object::new(&FUNCTIONS),
packet: [0; 8],
#[cfg(windows)]
host,
shaders,
bound: std::sync::atomic::AtomicBool::new(false),
#[cfg(windows)]
graphics,
#[cfg(windows)]
host: OnceLock::new(),
});
object::hand_out(PIPELINE, pipeline, iid, &PIPELINE_IIDS, out)
}
@@ -398,6 +438,23 @@ static FUNCTIONS: Table<24> = {
#[cfg(windows)]
pub(crate) mod host;
#[cfg(windows)]
mod library;
#[cfg(windows)]
mod make;
/// Keeps compiled host pipelines, and the list of title pipelines to start
/// early, in `dir` (a folder of the cache) across runs.
#[cfg(windows)]
pub fn use_pipeline_cache(dir: std::path::PathBuf) {
library::use_pipeline_cache(dir);
}
/// Saves the pipeline cache now if anything was added (at the end of a run).
#[cfg(windows)]
pub fn save_pipeline_cache() {
library::save(true);
}
#[cfg(test)]
mod tests {
@@ -499,7 +556,7 @@ mod tests {
assert_eq!(shaders(p), [("mesh", ms.to_vec()), ("pixel", ps.to_vec())]);
#[cfg(windows)]
{
let g = pipeline(p).graphics.as_deref().unwrap();
let g = pipeline(p).host.graphics.as_deref().unwrap();
assert_eq!(g.topology.0, 3);
assert_eq!(
(g.targets.NumRenderTargets, g.targets.RTFormats[0].0),