WIP: Reduce texture queue work for held slots #539

Draft
holoslicer wants to merge 3 commits from holoslicer/Darner:perf/skip-inactive-texture-wakes into Main
Contributor

All 36 CPU queue snapshot comparisons agree. This remains a draft. The full workspace hit a worker-pool assertion, and a separate package-level run produced one wrong texture selection in the GPU readback test. Tested on Windows 11 x64 with an Intel Core i7-12700K. Gameplay, texture appearance, and frame rates were outside this comparison.

Contributor role (optional)

Fluxer ID 1577921940104949761.

What it changes

The texture queue gathers eligible slots while holding a lock shared with descriptor writers. On main, the flat queue checks a hash map for future writes and the indexed queue visits held entries even when no shader feedback is available and the held census is off.

Choose the wake path once per snapshot. The index can skip its held map when neither feedback nor telemetry needs it. The flat queue records whether the current write is held in the entry flags, so it can check eligibility and count current holds in the same scan. Replacing a write or releasing a hold clears that bit. When feedback history exists, each wake still checks the latest completed sample. No configuration default changes.

How it was tested

Compared main c8258f9 with c7f3bb1. Synthetic writes filled a 32,768-slot queue. I measured the production snapshot function with reusable output vectors, using the same allowed logical processor. Four launches per revision in A/B/B/A/B/A/A/B order, seven timed batches of 64 snapshots per launch. Values are median microseconds per snapshot. The benchmark excludes GPU upload, descriptor allocation, lock contention and game frame time.

Feedback and queue layout Main (µs) This PR (µs)
Off, 7,179 due / 4,096 held, flat 84.53 36.96
Off, 7,179 due / 4,096 held, indexed 67.76 14.75
Off, 16 due / 24,576 held, flat 104.87 21.68
Off, 16 due / 24,576 held, indexed 209.65 0.05
Every eighth slot marked, 16 due / 24,576 held, flat 124.88 46.14
Every eighth slot marked, 16 due / 24,576 held, indexed 246.10 237.76
Every eighth slot marked, same load, indexed with census 258.06 236.57

All 36 before/after pairs produced the same census, ordered fresh/recheck slot versions, and checked metadata within each storage layout. The three feedback cases were marks off, marks on before buffer initialization, and a completed synthetic readback marking every eighth slot. Each was tested with the census both on and off and with zero, 4,096, or 24,576 held slots.

To reproduce the off case, append the module below to crates/darner-gpu/src/descriptor/host.rs on each revision, set DARNER_SAMPLED_MARKS=0, then run cargo test --locked -p darner-gpu --lib --config 'profile.test.package.darner-gpu.opt-level=2' offline_queue_snapshot_measurement -- --ignored --nocapture --test-threads=1. For the active feedback comparison I fed synthetic words to the ordinary readback history at frame 40 and checked the additional eligible slots and adjusted held census.

Reproduction fixture using synthetic texture slots
#[cfg(all(test, windows))]
mod offline_queue_probe {
use super::*;
use std::{hash::{Hash, Hasher}, hint::black_box, time::Instant};

#[test]
#[ignore = "offline measurement with synthetic textures"]
fn offline_queue_snapshot_measurement() {
    const TOTAL: u32 = 32768;
    let samples = std::env::var("DARNER_PROBE_SAMPLES").ok().and_then(|v| v.parse().ok()).unwrap_or(7usize);
    for (case, due_count, held) in [("empty-held", 7179, 0), ("mixed", 7179, 4096), ("held-heavy", 16, 24576)] {
        for indexed in [false, true] {
            let mut q = TextureQueue::with_marks_and_index(std::sync::Arc::new(QueueMarks::new(TOTAL as usize)), indexed);
            for i in 0..TOTAL {
                q.written(i, 1, if i < due_count { 1 } else { 150 }, false);
                let w = q.entry(i).unwrap().write;
                if i >= TOTAL - held { q.hold(i, w, 200); }
                if i < due_count && i % 3 == 0 { q.recheck(i, w, 1, (1000 + u64::from(i), 4096), 37, 1, 1); }
            }
            for telemetry in [false, true] {
                let mut due = Due::with_capacity(TOTAL as usize, TOTAL as usize, TOTAL as usize);
                let census = q.collect_due_and_census(40, &mut due, telemetry);
                assert_eq!(census[0], u64::from(TOTAL));
                assert_eq!(census[1], u64::from(due_count));
                assert_eq!(census[8], if telemetry { u64::from(held) } else { 0 });
                assert_eq!(due.fresh.len()+due.again.len(), due_count as usize);
                let mut h = std::collections::hash_map::DefaultHasher::new();
                census.hash(&mut h); due.again.hash(&mut h); due.checked.hash(&mut h); due.fresh.hash(&mut h);
                let signature = h.finish();
                let mut times = Vec::new();
                for _ in 0..=samples {
                    let start = Instant::now();
                    for _ in 0..64 {
                        due.again.clear(); due.fresh.clear(); due.checked.clear();
                        black_box(black_box(&q).collect_due_and_census(black_box(40), &mut due, black_box(telemetry)));
                        black_box(&due);
                    }
                    times.push(start.elapsed().as_secs_f64() * 1e6 / 64.);
                }
                println!("queue case={case} indexed={indexed} census={telemetry} signature={signature:016x} us={:?}", &times[1..]);
            }
        }
    }
}
}

On c7f3bb1, both workspace Clippy configurations (all targets, default and all features, warnings denied) and cargo xtask policy passed. The first workspace run stopped at the worker-pool test nested_wide_each_scoped_handles_overflow_concurrency_and_panics with owner panic did not unwind. I also found that assertion in a pre-existing workspace log from a different PR. This patch leaves shadow.rs byte-identical to main. A complete retry in a fresh test directory using cargo test --workspace --offline --locked --no-fail-fast --config 'profile.test.package.darner-shader.opt-level=3' -- --test-threads=1 reported 3,520 passed, 1 failed and 121 ignored. The same worker test failed on the retry. The texture tests and exhaustive shader arithmetic oracle passed. In separate serial GPU-library runs using package-default features, official main had 1,805 passed and 0 failed, and this revision had 1,803 passed and 3 failed. With the workspace’s record feature on official main, 1,823 passed and 0 failed.

The three failures in the first candidate package-default GPU run were the worker-pool assertion, a_capped_draw_waits_once_then_drops, and streamed_texture_written_through_an_alias_reaches_a_full_queue. In the last test, page 0 selected slot 2, showing 0/1,024 expected pixels, and the queue had 8,194 entries instead of 8,193. Both workspace runs passed that texture test. Repeating the entire package binary in a new process passed 1,805 tests, including the texture and pipeline cases, and failed only the worker assertion. Six fresh-process readbacks across main and the candidate had the expected 1,024/1,024 pixels on both pages. Five runs with the 55 neighboring texture-watch tests also passed. The cause of the larger suite’s mis-selection is unresolved.

A private test-only trace recorded which remap range requeued slots 0–2. The individual test and two complete package runs returned the expected pixels on both pages. The trace showed exactly one target requeued on each remap, slots 0 then 1, and slot 2 kept its original generation. One instrumented suite passed all 1,806 tests, and the other passed 1,805 with one failure in ask_once_delta_reask_direct_carves_refreshes_and_updates_page_epochs. There is still no trace of the failing selection. The instrumentation is outside this PR.

Checklist

  • In-game A/B. The snapshot timing above is offline.
  • One change based on main.
  • The diff follows the asset policy and contains no game data.
  • Depends on no other PR.

Checked for overlap

  • Searched open and closed issues and PRs for the queue paths and checked open PRs touching these files.
  • #528 changes upload ordering after the snapshot. #345 changes feedback cadence. Other PRs touching the descriptor module include #508, #380, #335 and #292. This change is independent of those PRs.
All 36 CPU queue snapshot comparisons agree. This remains a draft. The full workspace hit a worker-pool assertion, and a separate package-level run produced one wrong texture selection in the GPU readback test. Tested on Windows 11 x64 with an Intel Core i7-12700K. Gameplay, texture appearance, and frame rates were outside this comparison. ## Contributor role (optional) Fluxer ID `1577921940104949761`. ## What it changes The texture queue gathers eligible slots while holding a lock shared with descriptor writers. On main, the flat queue checks a hash map for future writes and the indexed queue visits held entries even when no shader feedback is available and the held census is off. Choose the wake path once per snapshot. The index can skip its held map when neither feedback nor telemetry needs it. The flat queue records whether the current write is held in the entry flags, so it can check eligibility and count current holds in the same scan. Replacing a write or releasing a hold clears that bit. When feedback history exists, each wake still checks the latest completed sample. No configuration default changes. ## How it was tested Compared main `c8258f9` with `c7f3bb1`. Synthetic writes filled a 32,768-slot queue. I measured the production snapshot function with reusable output vectors, using the same allowed logical processor. Four launches per revision in A/B/B/A/B/A/A/B order, seven timed batches of 64 snapshots per launch. Values are median microseconds per snapshot. The benchmark excludes GPU upload, descriptor allocation, lock contention and game frame time. | Feedback and queue layout | Main (µs) | This PR (µs) | |---|---:|---:| | Off, 7,179 due / 4,096 held, flat | 84.53 | 36.96 | | Off, 7,179 due / 4,096 held, indexed | 67.76 | 14.75 | | Off, 16 due / 24,576 held, flat | 104.87 | 21.68 | | Off, 16 due / 24,576 held, indexed | 209.65 | 0.05 | | Every eighth slot marked, 16 due / 24,576 held, flat | 124.88 | 46.14 | | Every eighth slot marked, 16 due / 24,576 held, indexed | 246.10 | 237.76 | | Every eighth slot marked, same load, indexed with census | 258.06 | 236.57 | All 36 before/after pairs produced the same census, ordered fresh/recheck slot versions, and checked metadata within each storage layout. The three feedback cases were marks off, marks on before buffer initialization, and a completed synthetic readback marking every eighth slot. Each was tested with the census both on and off and with zero, 4,096, or 24,576 held slots. To reproduce the off case, append the module below to `crates/darner-gpu/src/descriptor/host.rs` on each revision, set `DARNER_SAMPLED_MARKS=0`, then run `cargo test --locked -p darner-gpu --lib --config 'profile.test.package.darner-gpu.opt-level=2' offline_queue_snapshot_measurement -- --ignored --nocapture --test-threads=1`. For the active feedback comparison I fed synthetic words to the ordinary readback history at frame 40 and checked the additional eligible slots and adjusted held census. <details><summary>Reproduction fixture using synthetic texture slots</summary> ```rust #[cfg(all(test, windows))] mod offline_queue_probe { use super::*; use std::{hash::{Hash, Hasher}, hint::black_box, time::Instant}; #[test] #[ignore = "offline measurement with synthetic textures"] fn offline_queue_snapshot_measurement() { const TOTAL: u32 = 32768; let samples = std::env::var("DARNER_PROBE_SAMPLES").ok().and_then(|v| v.parse().ok()).unwrap_or(7usize); for (case, due_count, held) in [("empty-held", 7179, 0), ("mixed", 7179, 4096), ("held-heavy", 16, 24576)] { for indexed in [false, true] { let mut q = TextureQueue::with_marks_and_index(std::sync::Arc::new(QueueMarks::new(TOTAL as usize)), indexed); for i in 0..TOTAL { q.written(i, 1, if i < due_count { 1 } else { 150 }, false); let w = q.entry(i).unwrap().write; if i >= TOTAL - held { q.hold(i, w, 200); } if i < due_count && i % 3 == 0 { q.recheck(i, w, 1, (1000 + u64::from(i), 4096), 37, 1, 1); } } for telemetry in [false, true] { let mut due = Due::with_capacity(TOTAL as usize, TOTAL as usize, TOTAL as usize); let census = q.collect_due_and_census(40, &mut due, telemetry); assert_eq!(census[0], u64::from(TOTAL)); assert_eq!(census[1], u64::from(due_count)); assert_eq!(census[8], if telemetry { u64::from(held) } else { 0 }); assert_eq!(due.fresh.len()+due.again.len(), due_count as usize); let mut h = std::collections::hash_map::DefaultHasher::new(); census.hash(&mut h); due.again.hash(&mut h); due.checked.hash(&mut h); due.fresh.hash(&mut h); let signature = h.finish(); let mut times = Vec::new(); for _ in 0..=samples { let start = Instant::now(); for _ in 0..64 { due.again.clear(); due.fresh.clear(); due.checked.clear(); black_box(black_box(&q).collect_due_and_census(black_box(40), &mut due, black_box(telemetry))); black_box(&due); } times.push(start.elapsed().as_secs_f64() * 1e6 / 64.); } println!("queue case={case} indexed={indexed} census={telemetry} signature={signature:016x} us={:?}", &times[1..]); } } } } } ``` </details> On `c7f3bb1`, both workspace Clippy configurations (all targets, default and all features, warnings denied) and `cargo xtask policy` passed. The first workspace run stopped at the worker-pool test `nested_wide_each_scoped_handles_overflow_concurrency_and_panics` with `owner panic did not unwind`. I also found that assertion in a pre-existing workspace log from a different PR. This patch leaves `shadow.rs` byte-identical to main. A complete retry in a fresh test directory using `cargo test --workspace --offline --locked --no-fail-fast --config 'profile.test.package.darner-shader.opt-level=3' -- --test-threads=1` reported 3,520 passed, 1 failed and 121 ignored. The same worker test failed on the retry. The texture tests and exhaustive shader arithmetic oracle passed. In separate serial GPU-library runs using package-default features, official main had 1,805 passed and 0 failed, and this revision had 1,803 passed and 3 failed. With the workspace’s `record` feature on official main, 1,823 passed and 0 failed. The three failures in the first candidate package-default GPU run were the worker-pool assertion, `a_capped_draw_waits_once_then_drops`, and `streamed_texture_written_through_an_alias_reaches_a_full_queue`. In the last test, page 0 selected slot 2, showing 0/1,024 expected pixels, and the queue had 8,194 entries instead of 8,193. Both workspace runs passed that texture test. Repeating the entire package binary in a new process passed 1,805 tests, including the texture and pipeline cases, and failed only the worker assertion. Six fresh-process readbacks across main and the candidate had the expected 1,024/1,024 pixels on both pages. Five runs with the 55 neighboring texture-watch tests also passed. The cause of the larger suite’s mis-selection is unresolved. A private test-only trace recorded which remap range requeued slots 0–2. The individual test and two complete package runs returned the expected pixels on both pages. The trace showed exactly one target requeued on each remap, slots 0 then 1, and slot 2 kept its original generation. One instrumented suite passed all 1,806 tests, and the other passed 1,805 with one failure in `ask_once_delta_reask_direct_carves_refreshes_and_updates_page_epochs`. There is still no trace of the failing selection. The instrumentation is outside this PR. ## Checklist - [ ] In-game A/B. The snapshot timing above is offline. - [x] One change based on main. - [x] The diff follows the asset policy and contains no game data. - [x] Depends on no other PR. ## Checked for overlap - [x] Searched open and closed issues and PRs for the queue paths and checked open PRs touching these files. - #528 changes upload ordering after the snapshot. #345 changes feedback cadence. Other PRs touching the descriptor module include #508, #380, #335 and #292. This change is independent of those PRs.
holoslicer changed title from WIP: [pr-performance][rendering][memory] Skip held texture lookups when shader marks are off to WIP: [pr-performance][rendering][memory] Reduce texture queue work for held slots 2026-12-05 10:05:52 +00:00
Author
Contributor

I’m investigating the worker-pool assertion and the extra texture slot using deterministic schedules and synthetic journal writes. I’ll keep this PR in draft while testing and post the controls and observed outcomes here. #542 also reports a full-suite failure of the alias test on an app-only change, but its report does not identify which slot was selected.

I’m investigating the worker-pool assertion and the extra texture slot using deterministic schedules and synthetic journal writes. I’ll keep this PR in draft while testing and post the controls and observed outcomes here. #542 also reports a full-suite failure of the alias test on an app-only change, but its report does not identify which slot was selected.
Author
Contributor

Both previously intermittent failures now have deterministic reproductions on upstream main c8258f9. I am keeping this PR in draft.

  • Worker pool, #549. The owner-panic test assumes the caller receives one of two chunks. In the native test binary, stock passed 24/24 caller-first schedules and failed all 26 when helpers claimed both chunks before the caller. The tests-only change passed all 50 controlled schedules. Stock and candidate each passed 29/29 ordinary launches across 1–32 helpers.
  • Texture queue, #547. A predecessor heap and writes through the normal remap entry point reproduced the earlier two-page failure on both upstream main and this PR, three fresh processes per revision. With 8,192 uploads already pending, the first write produced 8,194 entries, selected slot 2, and returned 0/1,024 matching pixels. Publishing the new heap's initial cursor fixed that sequence on both branches, three runs each. Both writes produced 8,193 entries, selected slots 0 then 1, returned 1,024/1,024 matching pixels and left 8,192 queued. Reverting only the constructor's publication restored the failure. This is a sufficient cause for the earlier signature. The original run did not capture its pre-heap history.
  • Integration. A private build of this PR with both fixes (c7f3bb1 + 0ea931e + aaf411c) passed the complete serial darner-gpu library suite with the record feature, 1,826 passed and 81 ignored. A separate run with just the cursor fix passed both regressions and the ordinary GPU readback but failed a_capped_draw_waits_once_then_drops, which passed in a fresh process. The capped-draw timing test is separate from these two regressions.

These results concern queue correctness and test scheduling. Gameplay frame times and FPS were outside this pass.

Both previously intermittent failures now have deterministic reproductions on upstream main `c8258f9`. I am keeping this PR in draft. - **Worker pool, #549.** The owner-panic test assumes the caller receives one of two chunks. In the native test binary, stock passed 24/24 caller-first schedules and failed all 26 when helpers claimed both chunks before the caller. The tests-only change passed all 50 controlled schedules. Stock and candidate each passed 29/29 ordinary launches across 1–32 helpers. - **Texture queue, #547.** A predecessor heap and writes through the normal remap entry point reproduced the earlier two-page failure on both upstream main and this PR, three fresh processes per revision. With 8,192 uploads already pending, the first write produced 8,194 entries, selected slot 2, and returned 0/1,024 matching pixels. Publishing the new heap's initial cursor fixed that sequence on both branches, three runs each. Both writes produced 8,193 entries, selected slots 0 then 1, returned 1,024/1,024 matching pixels and left 8,192 queued. Reverting only the constructor's publication restored the failure. This is a sufficient cause for the earlier signature. The original run did not capture its pre-heap history. - **Integration.** A private build of this PR with both fixes (`c7f3bb1` + `0ea931e` + `aaf411c`) passed the complete serial `darner-gpu` library suite with the `record` feature, 1,826 passed and 81 ignored. A separate run with just the cursor fix passed both regressions and the ordinary GPU readback but failed `a_capped_draw_waits_once_then_drops`, which passed in a fresh process. The capped-draw timing test is separate from these two regressions. These results concern queue correctness and test scheduling. Gameplay frame times and FPS were outside this pass.
TrustNo1 changed title from WIP: [pr-performance][rendering][memory] Reduce texture queue work for held slots to WIP: Reduce texture queue work for held slots 2026-12-06 03:27:32 +00:00
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/skip-inactive-texture-wakes:holoslicer-perf/skip-inactive-texture-wakes'
git switch 'holoslicer-perf/skip-inactive-texture-wakes'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'holoslicer-perf/skip-inactive-texture-wakes'
git switch 'holoslicer-perf/skip-inactive-texture-wakes'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'holoslicer-perf/skip-inactive-texture-wakes'
git switch 'holoslicer-perf/skip-inactive-texture-wakes'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'holoslicer-perf/skip-inactive-texture-wakes'
git switch 'Main'
git merge --squash 'holoslicer-perf/skip-inactive-texture-wakes'
git switch 'Main'
git merge --ff-only 'holoslicer-perf/skip-inactive-texture-wakes'
git switch 'Main'
git merge 'holoslicer-perf/skip-inactive-texture-wakes'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!539
No description provided.