Skip to content

perf(gpu): opt-in best-fit texture pool placement to reduce fragmentation - #543

Closed
fladit123 wants to merge 1 commit into
trustno1-coder:mainfrom
fladit123:perf/texture-pool-best-fit
Closed

fladit123 wants to merge 1 commit into
trustno1-coder:mainfrom
fladit123:perf/texture-pool-best-fit

Conversation

@fladit123

Copy link
Copy Markdown

Summary

Adds an experimental, opt-in best-fit placement policy for the texture pool, intended to preserve larger contiguous free ranges and reduce heap growth under fragmentation.

First-fit remains the default.

Enable the experimental policy with:

$env:VICTORY_POOL_BEST_FIT = "1"

Implementation

  • Selects the smallest suitable free range across eligible ripe texture blocks.
  • Stops searching when an exact fit is found.
  • Skips ranges that cannot improve the current best candidate before calculating alignment.
  • Preserves deterministic tie-breaking, alignment padding, quarantine, ripe-block priority and the existing unripe fallback.
  • Leaves staging allocation and the existing heap reclamation policy unchanged.
  • Adds four focused unit tests.

Experimental results

The comparative campaign covered 70 deterministic CPU workload scenarios and physical D3D12 validation on NVIDIA RTX 4060 (8 GiB) and Microsoft WARP.

Compared with the same candidate with best-fit disabled:

Metric Result
Median peak heap capacity −64 MiB
Median active-window mean heap capacity −78.22 MiB
Scenarios with lower peak capacity 64/70
Scenarios with lower active-window mean capacity 70/70
Allocation p99 −26.6%
Median full-trace mean heap capacity +48.76 MiB

Best-fit increased full-trace heap capacity in 44 of 70 scenarios. This is an important trade-off: preserving contiguous ranges does not necessarily make entire heaps easier to reclaim.

Synthetic mutex contention benchmarks also showed higher allocation costs than first-fit. The pruning optimization reduced execution time by approximately 10–14% relative to the earlier unpruned best-fit implementation, without changing placement decisions in 10,000 deterministic equivalence cases.

The comparative campaign also measured a median paired throughput reduction of approximately 5% with eight threads when the feature was disabled, relative to clean upstream. This result warrants further investigation.

Relationship to #399

This proposal is distinct from the fullest-block-first policy and VRAM growth gate introduced in #399.

Two controlled physical scenarios demonstrated complementary strengths on both RTX 4060 and WARP:

Scenario Best-fit Fullest-block-first
Fragmentation-driven heap growth 128 MiB 192 MiB
Heap reclamation 128 MiB 64 MiB

Best-fit can preserve larger contiguous ranges, while fullest-block-first can concentrate allocations and facilitate whole-heap reclamation.

The policies should not be considered universally superior to one another. Coordination with #399's VRAM gate may be useful.

Validation

  • 10,000 deterministic exact-versus-pruned equivalence cases.
  • 11,932 byte-exact readbacks across 161 successful D3D12 processes in the final comparative campaign.
  • Zero D3D12 debug-layer errors or device removals in those successful runs.
  • Physical validation with small placement enabled and disabled.
  • Effective ahead counts of 2 and 12.
  • Single-threaded and concurrent texture creation.
  • Final focused pool tests on 64d4931: 11 passed with best-fit disabled and 11 passed with best-fit enabled.

The comparative full-library suites reproduced the same three failures on clean upstream and both candidate settings. No additional test failures were observed in the candidate.

The comparative performance measurements remain tied to their pinned test base. Initial fixture failures and corrected reruns were retained in the experimental evidence.

Limitations

  • No in-game FPS or frametime improvements have been demonstrated.
  • Reduced heap capacity in a controlled workload does not imply equivalent savings in total process VRAM.
  • The policy can increase allocation cost and delay whole-heap reclamation in some workloads.
  • AMD hardware has not been tested.
  • The feature remains disabled by default.

Disclosure

AI-assisted implementation, benchmarking and analysis. Tests were executed on local hardware. No proprietary game data or assets were used in this investigation.

@trustno1-coder

Copy link
Copy Markdown
Owner

Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

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.

2 participants