Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions d3d12/crates/leonida-gpu/src/pipeline/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,11 @@ impl HostPipeline {
&state,
);
let pso = match mesh_pipeline(
&host.device, &root, None, code(0), code(1), g, depth_bounds,
&host.device,
&root,
MeshStages { amplify: None, ms: code(0), ps: code(1) },
g,
depth_bounds,
library.name(&name).as_deref(),
) {
Ok(pso) => pso,
Expand All @@ -935,7 +939,14 @@ impl HostPipeline {
&[&code_bytes(&stage), &code_bytes(&code(0)), &code_bytes(&code(1))],
&state,
);
match mesh_pipeline(&host.device, &root, Some(stage), code(0), code(1), g, depth_bounds, library.name(&name).as_deref()) {
match mesh_pipeline(
&host.device,
&root,
MeshStages { amplify: Some(stage), ms: code(0), ps: code(1) },
g,
depth_bounds,
library.name(&name).as_deref(),
) {
Ok(amplified) => {
crate::host::name(&amplified, || format!("{shaders:?} amplified"));
Some((amplified, at))
Expand Down Expand Up @@ -1211,16 +1222,21 @@ fn graphics_depth_bounds_pipeline(
/// "already exists"). The translation makes triangle mesh shaders only
/// (`mesh_prologue` refuses others), and the debug layer wants the two to
/// agree (1323).
fn mesh_pipeline(
device: &ID3D12Device,
root: &ID3D12RootSignature,
struct MeshStages {
amplify: Option<D3D12_SHADER_BYTECODE>,
ms: D3D12_SHADER_BYTECODE,
ps: D3D12_SHADER_BYTECODE,
}

fn mesh_pipeline(
device: &ID3D12Device,
root: &ID3D12RootSignature,
stages: MeshStages,
g: &GraphicsState,
depth_bounds: bool,
name: Option<&str>,
) -> windows::core::Result<ID3D12PipelineState> {
let MeshStages { amplify, ms, ps } = stages;
use windows::core::Interface;
/// `A`: the amplification stage's subobject, or nothing (`()`, no bytes in the stream).
#[repr(C)]
Expand Down Expand Up @@ -1533,9 +1549,9 @@ mod tests {
g.targets.NumRenderTargets = 1;
g.targets.RTFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
let name = super::super::library::name("mesh test", &root_blob, &[&ms, &ps], &g.describe());
mesh_pipeline(&host.device, &root, None, code(&ms), code(&ps), &g, false, Some(&name)).expect("made");
mesh_pipeline(&host.device, &root, MeshStages { amplify: None, ms: code(&ms), ps: code(&ps) }, &g, false, Some(&name)).expect("made");
let loaded = super::super::library::LOADED.load(Ordering::Relaxed);
mesh_pipeline(&host.device, &root, None, code(&ms), code(&ps), &g, false, Some(&name)).expect("made again");
mesh_pipeline(&host.device, &root, MeshStages { amplify: None, ms: code(&ms), ps: code(&ps) }, &g, false, Some(&name)).expect("made again");
assert!(
super::super::library::LOADED.load(Ordering::Relaxed) > loaded,
"the mesh pipeline was compiled again instead of loaded from the library"
Expand Down
7 changes: 4 additions & 3 deletions d3d12/crates/leonida-gpu/src/pipeline/known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ pub fn save_library() {
/// right after a precompile (run d287, 2026-12-01). The library is ours: what is stored stays.
pub fn store(dir: &Path, which: &[usize], threads: usize, each: impl FnMut(usize, Option<(f64, bool)>) + Send) {
let mut places = HashMap::new();
walk_shaders(dir, |stage, hash, at, len| drop(places.insert(hash, (stage, at, len))));
walk_shaders(dir, |stage, hash, at, len| {
let _ = places.insert(hash, (stage, at, len));
});
let wanted: HashSet<usize> = which.iter().copied().collect();
let mut entries = HashMap::new();
walk_pipelines(dir, |n, bytes| {
Expand All @@ -265,8 +267,7 @@ pub fn store(dir: &Path, which: &[usize], threads: usize, each: impl FnMut(usize
file.read_exact(&mut bytes).ok()?;
Some(bytes)
};
loop {
let Some(&n) = which.get(next.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) else { break };
while let Some(&n) = which.get(next.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) {
let Some(entry) = entries.get(&n) else { continue };
tell(n, None);
let began = std::time::Instant::now();
Expand Down
27 changes: 26 additions & 1 deletion d3d12/crates/leonida-hle/src/modules/glyphs/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn counters(memory: &impl Memory, slot: Slot) -> Option<Counters> {

/// Whether a find's counters hold what the code puts there: whole numbers from 0, below a billion.
pub fn plausible(memory: &impl Memory, slot: Slot) -> bool {
let whole = |v: f64| v.is_finite() && v >= 0.0 && v < 1e9 && v.fract() == 0.0;
let whole = |v: f64| (0.0..1e9).contains(&v) && v.fract() == 0.0;
counters(memory, slot).is_some_and(|c| whole(c.made) && whole(c.shown))
}

Expand Down Expand Up @@ -727,6 +727,31 @@ mod tests {
assert_eq!(heap.writes.get(), 2, "one write a change");
}

#[test]
fn plausible_checks_nonnegative_whole_counters_below_one_billion() {
let heap = Fake::new(BASE, 1 << 14);
heap.slots(BASE + 0x200, 24, slot_bits(Family::Xbox));
let slot = scan(&heap, 4096).slots[0];
let set = |made: f64, shown: f64| {
heap.put(BASE + 0x200 + 72, made.to_bits());
heap.put(BASE + 0x200 + 96, shown.to_bits());
};

for &(made, shown, want) in &[
(0.0, 0.0, true),
(-0.0, 999_999_999.0, true),
(1e9, 0.0, false),
(-1.0, 0.0, false),
(0.5, 0.0, false),
(f64::NAN, 0.0, false),
(f64::INFINITY, 0.0, false),
(f64::NEG_INFINITY, 0.0, false),
] {
set(made, shown);
assert_eq!(plausible(&heap, slot), want, "made={made:?} shown={shown:?}");
}
}

/// `follow` with the first look due at once.
fn follow_from(
memory: &Fake,
Expand Down
Loading