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

Closed
github-bot wants to merge 1 commit from github-bot/gh-543 into main AGit
Owner

@⁠fladit123 on GitHub · 2026-11-28 00:36 UTC · original
fladit123:perf/texture-pool-best-fit → main · +168 −30 · 1 files · 1 commits · closed without merging

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.

**@⁠fladit123** on GitHub · 2026-11-28 00:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/543) `fladit123:perf/texture-pool-best-fit` → `main` · +168 −30 · 1 files · 1 commits · closed without merging ## 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: ```powershell $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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:41:05 +00:00
github-bot closed this pull request 2026-11-28 19:25:18 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 19:23 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-11-28 19:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/543#issuecomment-7244509578) 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.
Author
Owner

@⁠fladit123 on GitHub · 2026-11-30 04:30 UTC · original

Thanks for the guidance!

I've updated the implementation for the current main and opened a replacement PR: #3711.

The updated patch preserves the fullest-block-first default, the new pool accounting, and unlocked heap creation. I've also repeated the comparative benchmarks and D3D12 validation on my RTX 4060 and WARP, documenting both the benefits and the trade-offs.

The feature remains experimental and opt-in.

Thanks again for your time!

**@⁠fladit123** on GitHub · 2026-11-30 04:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/543#issuecomment-7268839197) Thanks for the guidance! I've updated the implementation for the current main and opened a replacement PR: #3711. The updated patch preserves the fullest-block-first default, the new pool accounting, and unlocked heap creation. I've also repeated the comparative benchmarks and D3D12 validation on my RTX 4060 and WARP, documenting both the benefits and the trade-offs. The feature remains experimental and opt-in. Thanks again for your time!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/trustno1-coder--VIctory-NVIDIA!543
No description provided.