Skip to content

[GPU/macOS] Defer texture descriptor materialization to reduce startup memory pressure - #151

Draft
pedrofort wants to merge 1 commit into
pragyaangaur:mainfrom
pedrofort:experimental/deferred-texture-descriptors
Draft

pedrofort wants to merge 1 commit into
pragyaangaur:mainfrom
pedrofort:experimental/deferred-texture-descriptors

Conversation

@pedrofort

Copy link
Copy Markdown

Summary

Experimental, opt-in macOS adaptation of deferred texture
descriptor materialization, based on merged main at
485b230ef596898cdd390cd5d9205b76e4289b82.

This draft is intended to gather feedback on startup
memory pressure on Apple Silicon with 16 GB unified memory.

Inspired by DexNom/VIctory at
2e01ab4760db91820ef5f9a9f85761f83cd6b5d0.

Related: #50.

Changes

  • Defer host materialization of resource-object SRV/UAV
    texture descriptors.
  • Track pending descriptor slots.
  • Conservatively restore pending object views in active
    direct-indexed heaps before submission.
  • Add counters for deferred, resolved and failed
    descriptor materializations.
  • Keep existing host texture ownership and eviction
    mechanisms.
  • Do not deliberately discard GPU-written contents.

The experiment is disabled by default.

Enable it with:

VICTORY_DEXMETAL_DEFER=1

Validation

Environment:

  • Apple M5, 16 GB unified memory
  • Wine / Rosetta / D3DMetal
  • x86_64-pc-windows-gnullvm
  • Release build with diagnostics

Two targeted tests passed under real D3DMetal:

Test Result
bindless::tests::dexmetal_waits_for_table_and_heap PASS
bindless::tests::dexmetal_direct_heap_numeric PASS

Each test ran separately with one test thread,
with zero failures and zero ignored tests.

The full regression suite has not yet been validated
for this experimental patch.

Local observations

Clean merged main:

  • 1504 host textures / 4630 MB at the last sample.
  • 145 MB used by lists.
  • Texture census: GPU-written 145 / 4088 / 0 MB;
    from title memory 0 / 58 / 0 MB.
  • Video memory: 7224 MB of a 12713 MB budget.

The GPU-written category describes resource creation
capabilities, not proof of an actual GPU write.

Experimental Series X run:

  • Early sample: 29 textures, 201 MB, 13 resolved
    descriptors.
  • Later sample: 1542 textures, 4659 MB, 5580
    resolved descriptors.
  • Runtime duration: 141.33 seconds.
  • Stopped by a local swap guard.

Experimental Series S run using the same runtime:

  • Duration: 318.85 seconds.
  • Peak swap: 2995.5 MiB from zero initial swap.
  • Peak sampled texture accounting: 3922 MB.
  • Introduction and configuration UI rendered.
  • Heavy graphics workload reached, but the world
    remained black.
  • Manually closed the window.
  • Process exit 0; not a spontaneous crash.

These observations are not a controlled benchmark.
Console profiles, initial memory, workload and stopping
policies differed between runs.

Known limitations / review requested

  • The conservative active-heap restore can materialize
    many textures at once, recreating the memory spike.
  • Descriptor overwrite, lifetime, concurrent mutation,
    heap destruction and materialization failure paths
    require additional review and regression coverage.
  • Direct heap indexing must not observe an incorrectly
    null or stale descriptor.
  • The two targeted tests do not establish correctness
    for all descriptor usage patterns.
  • General Wave64 fixes, shader permutation changes,
    partial image stores and mesh-output fixes are
    intentionally outside this PR.
  • No claim of playable gameplay or a complete memory fix.

Attribution

Deferred descriptor materialization principle:

https://github.com/DexNom/VIctory/tree/2e01ab4760db91820ef5f9a9f85761f83cd6b5d0

This is a local adaptation to the macOS fork, not a
wholesale merge of the Windows implementation.

AI-assisted engineering and analysis.
Tests executed locally.

Only source code and synthetic regression tests are
included. No game files, game-derived binaries,
Apple binaries, screenshots or personal paths.

Draft for design feedback; not ready for merge.

Experimental opt-in adaptation of deferred descriptor materialization from DexNom/VIctory 2e01ab4760db91820ef5f9a9f85761f83cd6b5d0.

Preserve host resource ownership and restore pending active-heap descriptors before submission. Add two targeted D3DMetal regression tests.
@pragyaangaur

Copy link
Copy Markdown
Owner

Thank you for the draft and the measurements. Before it is ready: the new tests need to skip by default (when the variable is off or no host exists, like the neighbouring tests) and not panic in a plain cargo test. The restore that materialises every pending view before each submission can bring the memory spike back, so a draw-driven restore or real read marks, or measurements showing a gain, are needed. The doc comment for is_placed_texture now sits above dex_enabled. Please also rebase after #152, which touches the same functions, and use plain names instead of DexMetal. The locking and failure paths still need a review.

@pragyaangaur pragyaangaur added area:gpu Host GPU runtime: resources, copies, presenting d3dmetal A difference in Apple's D3DMetal labels Nov 26, 2026
@pragyaangaur

Copy link
Copy Markdown
Owner

Update: main moved a lot (upstream merged in #202, plus #169, #174, #200). Upstream's own work on placed unordered views and view addresses for dynamic slots touches the same code in mirror, needs_remake and kept, so this branch will need a rebase and may partly overlap. #200 now also has opt-in switches for low-memory Macs. Please rebase, say what is still needed on top, and re-measure.

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

Labels

area:gpu Host GPU runtime: resources, copies, presenting d3dmetal A difference in Apple's D3DMetal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants