Skip to content

fix(gpu): guard unmapped root views, sanitize 64-lane indirect draws, and defer GPU retirement - #403

Open
gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:fix/macos-agx-root-indirect-retire
Open

gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:fix/macos-agx-root-indirect-retire

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

On macOS with D3DMetal on Apple Silicon (AGX), several invalid or transiently unmapped GPU addresses submitted by a title trigger hard GPU page faults or premature backing-memory reclamation instead of silent console-like reads and writes:

  1. Null or unmapped direct root CBV / SRV / UAV descriptors: When a direct root descriptor (SetGraphicsRoot*View / SetComputeRoot*View) names 0, an address outside the 47-bit user virtual space, or a title range with no backing host copy, leaving the previous draw's GPU virtual address bound or passing an unmapped address faults the GPU MMU.
  2. Unfilled indirect draw / mesh dispatch argument slots & 1-lane fallback clamp: Unfilled indirect argument records can hold 0xffffffff (DispatchMesh > 65,535 groups) or IEEE-754 float bit patterns above 2^23 interpreted as vertex/index counts with zero instance/start fields, stalling or resetting the host command queue. With macos: build the 64-thread argument clamp with the DXC that D3DMetal ships #301 building the 64-lane indirect-clamp.hlsl shader via D3DMetal's shipped DXC, sanitizing unfilled draw/mesh records in indirect-clamp.hlsl takes effect on default macOS builds right away, while upgrading the WORDS_SOURCE cs_5_1 fallback to [numthreads(64, 1, 1)] keeps builds without an external cs_6_0 DXC on the same 64-lane clamping and sanitization behavior.
  3. Immediate fence == completed GPU resource retirement: Releasing host D3D12 buffers, descriptor heaps, and scratch chunks on the exact fence value just completed can reclaim Metal allocations while late command-buffer completion or cross-queue work still references their GPU virtual addresses.

What changed

  • Zeroed root-read & sink root-UAV fallbacks (draw.rs, compute.rs, host.rs, shadow.rs):
    • Reject addresses below LOWEST_MAPPED (64 KiB) or past USER_SPACE_END (1 << 47) up front in shadow::find and shadow::loose before consulting thread-local lookup caches or VirtualQuery.
    • Bind persistent shared Host::zero_root_read() (64 KiB zeroed buffer) and Host::sink_root_uav() (64 KiB writable sink buffer) fallbacks whenever a direct root CBV, SRV, or UAV slot is null, unset, or outside committed title buffers, while preserving Refresh only the proven read span of raw root SRVs #270's proven read span on valid root SRVs.
  • 64-lane cs_5_1 indirect clamp & unfilled-record sanitization (indirect-clamp.hlsl, indirect.rs, host.rs):
  • Submission-lagged GPU retirement (host.rs, list.rs, placement.rs, resource.rs, switch.rs):
    • Add VICTORY_BURY_LAG (default 16 submissions, =0 immediate) so retired ID3D12Resource, descriptor-heap, and scratch-pool allocations stay alive across a short submission window before final release.

How it was tested

  • Apple M5 Max, CrossOver Preview with D3DMetal (wave32=true), isolated test bottle:
    • cargo test --workspace (native macOS): all passed (0 failed).
    • victory-gpu --lib under Wine + D3DMetal (--test-threads=1): all passed (covers null_and_unmapped_direct_root_views_bind_safe_fallbacks, null_and_out_of_range_addresses_never_create_loose_copies, 64-lane multi-draw indirect clamping, > 65,535 compute indirect dispatches, unfilled mesh/draw sentinel zeroing, and VICTORY_BURY_LAG retirement).
    • cargo xtask policy, git diff --check, and cargo clippy --target x86_64-pc-windows-gnullvm -p victory-gpu --all-targets -- -D warnings (with and without --features diagnostics): clean. All test inputs are synthetic.

Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)

  • In a combined warm-cache 720p opening-sequence run on Apple M5 Max (CrossOver Preview + D3DMetal, wave32=true), the runtime reached and sustained the 3D world through +8, +24, +48, +90 at 1.5–1.8 FPS (549.7–672.1 ms/frame on 1,021–1,258 draws/frame, 1.275 FPS overall across +8..+90) with 0 2.48 s allocation stalls, 7.2–9.0 ms/frame GUARDS lock hold time (down from 4,887 ms/frame before unlocking GUARDS), 149–154 MB/frame buffer copy volume, 0 DirectStorage decompression or access-violation failures, and 38/38 over-32 KiB aligned mesh/pixel pairs linked with 0 host mesh refusals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant