Prebuilding Architecture V2 - Phase 1 and Phase 2 #20
No reviewers
Labels
No labels
accessibility
area: compatibility
area: docs
area: hygiene
area: infra
area: memory
area: ray-tracing
area: rendering
area: shaders
area: submission
area: textures
bug
ci
dependencies
difficulty: advanced systems
difficulty: intermediate
documentation
duplicate
enhancement
experimental
good first issue
help wanted
invalid
known issue
performance
priority: P0
priority: P1
priority: P2
proposal
question
rendering
research
testing
triage
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/VictoryX-dev--VictoryX!20
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-20"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@VictoryX-dev on GitHub · 2026-12-03 09:43 UTC · original
VictoryX-dev:arch/prebuilding-overhaul→main· +9846 −291 · 38 files · 20 commits · draftPull Request: Prebuilding Architecture Overhaul (
VICTORY_PREBUILD_V2)Branch:
arch/prebuilding-overhaul(isolated frommain; preserves existing public implementation as rollback baseline viaVICTORY_PREBUILD_V2=0default)License: GPL-3.0-or-later (upstream attribution preserved)
Summary
This PR investigates VictoryX's existing command-list prebuilding and resource preparation subsystem (
victory-gpu) and introduces Prebuilding Architecture v2 (victory-prebuild+ reversiblevictory-gpu/src/prebuild_v2.rsintegration behindVICTORY_PREBUILD_V2=1).Root Causes Confirmed in Existing
mainImplementationlist.rs,host.rs,draw.rs):list::submitted_recordingretainsHostListandRecordingMemory(RootSlots,_uploads) until explicitReset()/Release()because concrete host GPU VAs are eagerly baked at recording time.HostListbundles immutable translated commands with mutable per-submission state (prelude,scratch,budget,backs,last_late), forcingreplay::execute_repeatedto split batches andreplay::prepareto stall the submission lane waiting forlanded_through().shadow.rs,host.rs):shadow::loosekeys loose windows by(start, len). Overlapping sized windows and staggered root-view tails (TAIL_STEP = 256 KiB) create multiple independent committed buffers andCopied::pagestables over the same 4 MiB guest cells.Host::submitkeys refresh spans byArc::as_ptr(shadow), copying the same dirty 64 KiB pages once per overlapping window and walking ~28,000 rawSteps/frame across 4–5 passes.host/draw_inputs.rs,shadow.rs,host.rs):host/draw_inputs.rsstores only a singlelatest: Option<ExactWrite>per list (same-listplace_copyonly), missing multiple disjoint copies and all cross-list / cross-submission GPU producers.shadow::copy_stalestampscopied.pages[i] = nowbeforetake_all, permanently caching zeros whenevercopy_mappedfalls back toread_unreadduring a concurrent remap or unmapped hole (VICTORY_SOURCE_RETRYdefaults off).Architectural Changes
1. New Internal Crate:
runtime/crates/victory-prebuildpage_store.rs(PageStore/CanonicalSegment/ExecutionLease):SegmentKey,canonical_loose_span) with per-64 KiBCanonicalPageStateand 16-bit 4 KiB subpage bitmasks.BackingId+backing_gen+mapping_gen.PageValidity::TransientZero: failed/unmapped reads substitute zeros for the current draw only and are never stamped fresh.ExecutionLeasehandles: idle closed templates hold zero strong leases, allowing full reclamation of unleased segments viareclaim_idle().coherence.rs(CoherenceTracker):BTreeMap<u64, AuthoritativeWrite>tracking multiple simultaneousExactGpuCopyandGpuShaderUavproducers across within-list, cross-list, and cross-submission boundaries.record_cpu_overwrite), immediate invalidation on guest remaps (invalidate_remap), and fence-based retirement (retire_through).InputResolution::RequiresSyncwhen partial GPU overwrites prevent safe whole-range aliasing.template.rs(CompiledCommandTemplate/TemplateBuilder):Close()off the submitting thread into hazard-orderedPrepPhases and pre-sorted, coalescedall_read_pages: Box<[CanonicalPageRange]>.BackingHints (zero idle backing retention) and classifiesReplayCapability::ConcurrentSafevsSerializedSharedTarget.planner.rs(SubmissionPlanner/EphemeralSlotPool/SubmitSnapshot/LeaseManager):PlannerScratchbuffers to produce minimal coalesced write-watch queries and strictly deduplicated canonical page refresh jobs.EphemeralSlotPooleliminates stalls on repeated concurrent-safe template executions.SubmitSnapshotisolates dynamic CPU ring overwrites without poisoningPageStore.LeaseManagerdrops all strong leases and returns ephemeral slots immediately on GPU fence retirement.2. Reversible Windows D3D12 Integration in
victory-gpu(VICTORY_PREBUILD_V2)Gated behind
VICTORY_PREBUILD_V2=1(off by default, A/B-capable in diagnostics builds, documented indocs/RUNTIME_SWITCHES.md):prebuild_v2.rs: bridgesPrebuildRuntimeintovictory-gpuusingWeak<Shadow>(no extra retention).shadow.rs: routesloose()onto canonical 4 MiB keys (canonical_loose_key), propagates guest remaps (in_place_let_go→on_guest_remap), and guardscopy_staleagainst permanently caching transient zero reads.host.rs: compilesCompiledCommandTemplateatHostList::close(), uses single-passmerge_watch_rangesinHost::submit(), enablessource_retryand tracksSOURCE_ZEROS, notifiesCoherenceTrackeronStep::CopyandStep::GpuWrite, and retires fences inbury().host/place.rs&host/draw_inputs.rs: publishes exact GPU copies intoCoherenceTrackerand resolves multi-write and cross-list draw-input aliases.host/replay.rs: skips thereplay::preparelane stall for immutableConcurrentSafelists with no mutable prelude/readback/budget state.Verification & Measured Results
Executed Tests & Checks (Linux host + Windows cross-check)
cargo test -p victory-prebuild: 8 / 8 passed (memory ownership & zero idle retention + post-eviction rebind, repeated concurrent & serialized execution, overlapping views & 4 KiB subpage tracking, multi-copy & cross-list aliasing + partial sync + CPU split + remap, 8-thread concurrent stress test, isolated submit snapshots &TransientZerorecovery, 2,000-round randomizedcoalesce_page_rangesoracle test, overflow bounds & cross-submission coherence).cargo clippy -p victory-prebuild --all-targets -- -D warnings: 0 warnings.cargo check -p victory-gpu --target x86_64-pc-windows-gnu --tests(default &--features diagnostics): passed with 0 errors and 0 new warnings.cargo test -p xtask: 0 violations on any new/modified switch or file (VICTORY_PREBUILD_V2passes switch-doc check; all newvictory-prebuildand doc files pass asset policy; 2 pre-existing upstreammainfailures remain untouched:host.rspre-existing size > 640 KiB and 6 pre-existing undocumented switches in unrelated docs).Reproducible Synthetic Benchmarks (
cargo run --release -p victory-prebuild --example prebuild_bench)10.134 ms4.160 ms2.44×faster (0.705 ms/worker close-time across 8 workers)2,5681,10557.0%duplicate copies eliminated5126487.5%fewer query spans5,390 MiB(53.9%overlap)2,632 MiB(0.0%overlap)51.2%less allocated memory1,644 MiBpinned0 MiBsegments (106.5 KiBmetadata)100%idle backing reclaimable4splits +4stalls0splits,80concurrent replays (45.4 µs)128 / 128missed128 / 128resolved (0.562 ms)Remaining Windows & GPU Hardware Validation Requirements
No Windows or GPU hardware tests were executed in this Linux environment. Before flipping
VICTORY_PREBUILD_V2on by default:cargo test --workspaceon Windows (x86_64-pc-windows-msvc).draw::geometry_alias_tests,host::prep_pipeline::tests::hardware_refresh_wave_*,shadow_tail_tests,host::refresh_tests) withVICTORY_PREBUILD_V2=0and=1.VICTORY_D3D12_DEBUG=1andVICTORY_PREBUILD_V2=1(zero D3D12 debug-layer lifetime/state errors).VICTORY_AB,VICTORY_XFER=2,VICTORY_FRAME_METRICS=1,VICTORY_STALE_DRAWS=1,VICTORY_MEM_LINE_S=10) across AMD RDNA, NVIDIA, and Intel GPUs.thin::Recordingword streams onSubmittedRecordingso evicted idle Windows D3D12 command lists can re-materialize afterRootSlotsrelease (unlocking the full idle D3D12 window eviction already verified invictory-prebuild).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.