GPU/VRAM: texture pool admission counts resting and fragmented memory as reusable capacity #262

Open
opened 2026-11-26 13:38:13 +00:00 by github-bot · 0 comments
Owner

@⁠FunWithFlagsDev on GitHub · 2026-11-26 13:34 UTC · original

<html>

Summary

While investigating memory management on NVIDIA GPUs with limited VRAM, I identified a mismatch between the texture pool's reported reusable capacity and the capacity that its allocator can actually reuse for a particular request.

The current accounting may include:

  • Released pieces that are still subject to the mandatory 2,500 ms resting period.

  • Fragmented free ranges that cannot accommodate the requested allocation.

  • Pieces reserved for an allocation whose resource creation has not yet completed.

  • Pool capacity credited toward requests that cannot use pooled allocation.

This capacity is subtracted from reported local video memory usage when evaluating texture admission.

Consequently, the automatic admission policy may allow additional texture preparation even when the allocator cannot reuse existing memory and must attempt another allocation.

This is particularly relevant to 8–12 GiB GPUs, where the available local memory budget can be substantially smaller than physical VRAM capacity.

The attached archive contains source references, an executable synthetic model, 11 regression tests and a matrix of 360 deterministic evaluations.

1. Affected revision

Repository: avatarmanz/VIctory-7900XTX

Commit:

c9c932cbcc38defd8f1683d62dd298187f565031

Primary files:

  • crates/victory-gpu/src/pool.rs

  • crates/victory-gpu/src/resource.rs

2. Current pool accounting

pool.rs:365–374

pub(crate) fn texture_room() -> u64 {
    (lock(&TEXTURES).blocks() as u64 * BLOCK)
        .saturating_sub(HELD.load(Ordering::Relaxed))
}

This calculates the difference between total allocated block capacity and the bytes counted as held by textures.

However, this difference is not necessarily equivalent to immediately allocatable capacity.

The allocator itself operates on contiguous, aligned free ranges within individual blocks.

3. Resting pieces are counted before they become reusable

When the final reference to a pooled texture is released, its piece is returned through the following sequence:

pool.rs:450–465

HELD.fetch_sub(gone.piece.len, Ordering::Relaxed);
lock(&TEXTURES).give(gone.piece, now());

However, Pool::give() does not immediately restore that piece to the allocator's free ranges.

fn give(&mut self, piece: Piece, now: u64) {
    self.resting.push_back((now + REST, piece));
}

The mandatory resting period is:

const REST: u64 = 2500;

Only after the deadline is reached can Pool::reclaim() restore the piece to the block's free ranges.

See pool.rs:315–340.

Therefore:

State of a released 64 MiB block | Current accounting credit | Reusable capacity -- | -- | -- Before release | 0 MiB | 0 MiB Immediately after release | 64 MiB | 0 MiB After 2,499 ms | 64 MiB | 0 MiB After the deadline and reclamation | 64 MiB | 64 MiB

The test should exercise the actual allocator and accounting implementation rather than only reproducing their formulas.

No title files, proprietary shaders or physical GPU memory exhaustion are necessary for the initial regression.

11. Relationship to existing VRAM work

I inspected the following related PR revisions.

#119 — Adaptive spare-block retention

Revision:

d39a0b5185cc73bf85ee8ac2d6ca884c9290ae90

This proposal reduces empty block retention according to remaining DXGI headroom.

It retains the existing texture_room() calculation.

#205 — Host RAM reduction

Revision:

5a26c94b59cb4d6539a8b2d989177a5d6d2b71ab

This proposal introduces idle memory trimming and additional reclamation policies.

It also retains the existing texture_room() calculation.

#212 — Fence-safe LRU eviction and adaptive mip clamping

Revision:

1e710c4bbeb03ce24bd3f2398621c0cb1c572702

This proposal introduces texture eviction and budget-aware mip clamping.

It continues using the pool credit when evaluating automatic texture admission, idle texture retention and adaptive mip policy.

The accounting issue may therefore also affect those decisions.

I suggest coordinating any production correction with these contributors rather than creating another independent eviction architecture.

The duplicate search was limited to selected issues, PRs and source paths.

12. Relevance to NVIDIA GPUs with 8 GiB of VRAM

On memory-constrained GPUs, even a small number of temporarily unavailable 64 MiB blocks can materially affect the difference between reported usage and the adjusted admission calculation.

The proposed direction complements:

  • Adaptive spare-block retention.

  • Fence-safe texture eviction.

  • Mip-tail clamping.

  • Descriptor recycling.

  • Recovery after transient allocation failure.

The objective is not to reduce texture quality unnecessarily or to reclaim memory that may still be in use.

The objective is to make admission decisions more accurately reflect existing allocation opportunities and the incremental cost of new allocations.

Attachment

avatar_pool_room_audit.zip

Contents:

  • README.md

  • model.py

  • test_model.py

  • matrix.csv

  • results.txt

Reproduction:

python model.py
python -m unittest -v test_model

No external Python dependencies are required.

Requested verification

Could an independent contributor validate the resting-capacity counterexample using the existing generic Pool<B> test infrastructure?

If reproduced, I suggest first establishing a regression for allocator availability and then evaluating request-aware admission in coordination with the existing VRAM management PRs.

Credits and limitations

AI-assisted source investigation and synthetic modeling using ChatGPT.

Only public repository source and invented test data were used.

No proprietary game files, executable files, shader dumps, console SDK material or gameplay captures are included.

The Python model and its 11 tests were executed successfully.

The investigation does not include a compiled Rust patch, native D3D12 validation, physical VRAM measurements or gameplay benchmarks.

The model does not simulate physical residency, concurrent allocation execution, proactive block growth, or every mandatory allocation and budget override path.

No FPS improvement, VRAM reduction or visual correction is claimed.

</html>## Summary

While investigating memory management on NVIDIA GPUs with limited VRAM, I identified a mismatch between the texture pool's reported reusable capacity and the capacity that its allocator can actually reuse for a particular request.

The current accounting may include:

  • Released pieces that are still subject to the mandatory 2,500 ms resting period.
  • Fragmented free ranges that cannot accommodate the requested allocation.
  • Pieces reserved for an allocation whose resource creation has not yet completed.
  • Pool capacity credited toward requests that cannot use pooled allocation.

This capacity is subtracted from reported local video memory usage when evaluating texture admission.

Consequently, the automatic admission policy may allow additional texture preparation even when the allocator cannot reuse existing memory and must attempt another allocation.

This is particularly relevant to 8–12 GiB GPUs, where the available local memory budget can be substantially smaller than physical VRAM capacity.

The attached archive contains source references, an executable synthetic model, 11 regression tests and a matrix of 360 deterministic evaluations.

1. Affected revision

Repository: avatarmanz/VIctory-7900XTX

Commit:

c9c932cbcc38defd8f1683d62dd298187f565031

Primary files:

  • crates/victory-gpu/src/pool.rs
  • crates/victory-gpu/src/resource.rs

2. Current pool accounting

[pool.rs:365–374](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L365-L374)

pub(crate) fn texture_room() -> u64 {
    (lock(&TEXTURES).blocks() as u64 * BLOCK)
        .saturating_sub(HELD.load(Ordering::Relaxed))
}

This calculates the difference between total allocated block capacity and the bytes counted as held by textures.

However, this difference is not necessarily equivalent to immediately allocatable capacity.

The allocator itself operates on contiguous, aligned free ranges within individual blocks.

3. Resting pieces are counted before they become reusable

When the final reference to a pooled texture is released, its piece is returned through the following sequence:

[pool.rs:450–465](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L450-L465)

HELD.fetch_sub(gone.piece.len, Ordering::Relaxed);
lock(&TEXTURES).give(gone.piece, now());

However, Pool::give() does not immediately restore that piece to the allocator's free ranges.

fn give(&mut self, piece: Piece, now: u64) {
    self.resting.push_back((now + REST, piece));
}

The mandatory resting period is:

const REST: u64 = 2500;

Only after the deadline is reached can Pool::reclaim() restore the piece to the block's free ranges.

See [pool.rs:315–340](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L315-L340).

Therefore:

State of a released 64 MiB block Current accounting credit Reusable capacity
Before release 0 MiB 0 MiB
Immediately after release 64 MiB 0 MiB
After 2,499 ms 64 MiB 0 MiB
After the deadline and reclamation 64 MiB 64 MiB

The resting period should remain intact. The issue is the accounting credit applied before the capacity becomes reusable.

4. Synthetic 8 GiB GPU counterexample

Consider the following invented memory state:

Parameter Value
Physical GPU memory class 8 GiB
DXGI local budget 7,424 MiB
Reported local usage 7,168 MiB
Existing pool blocks 16
Block size 64 MiB
Entirely resting pool capacity 1,024 MiB
Immediately reusable capacity 0 MiB

Assume:

  • No explicit texture-budget override.
  • The unconditional initial texture floor has already been satisfied.
  • No additional remaining card-buffer or render-target reservation.
  • The resting deadlines have not expired.

The existing automatic admission policy subtracts texture_room() from reported usage.

See [resource.rs:1725–1754](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/resource.rs#L1725-L1754).

With the default 90% threshold:

Reported local usage:       7168 MiB
Current pool credit:        1024 MiB
Adjusted usage:             6144 MiB
90% admission threshold:   ~6682 MiB

The current policy admits the request because adjusted usage is below the threshold.

However:

Immediately reusable pool capacity: 0 MiB
Actual reported local usage:     7168 MiB

Reported usage already exceeds the automatic admission threshold.

If a new eligible 32 MiB texture request reaches the allocator before the resting pieces are reclaimed, it cannot reuse those pieces.

It must either obtain another block, fail allocation, or proceed through an applicable allocation fallback.

This demonstrates a mismatch between the accounting credit and allocator eligibility.

It does not establish that the driver will necessarily refuse the allocation or that a device failure will occur.

5. Fragmentation is a separate problem

Even counting only genuinely free ranges is insufficient to determine whether a particular texture fits.

Consider one 64 MiB block:

[16 MiB free][16 MiB held][16 MiB free][16 MiB held]

Total free capacity is 32 MiB.

The largest contiguous free range is only 16 MiB.

A texture requiring a contiguous 32 MiB placement cannot use this block despite its reported free capacity.

Repeating this arrangement across 32 blocks produces 1 GiB of aggregate free capacity without any existing range that can accommodate a 32 MiB allocation.

Alignment constraints can also prevent an allocation from fitting into a range whose byte count would otherwise be sufficient.

The allocator correctly checks individual aligned ranges in Ranges::take().

The admission policy does not receive equivalent request-specific information.

6. Allocation reservations in progress

There is another accounting interval during pooled texture creation.

See [pool.rs:668–725](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L668-L725).

The sequence is approximately:

  1. Reserve a piece through take_ripe().
  2. Release the pool lock.
  3. Attempt CreatePlacedResource().
  4. Increment HELD after successful creation.
  5. Associate the piece's lifetime with the resulting texture.

Between steps 1 and 4, the reserved range is no longer available to another allocation but is not yet represented in HELD.

A concurrent accounting query may therefore credit capacity that has already been reserved.

On placement failure, the piece is returned through the resting mechanism rather than immediately becoming free.

This is a source-level accounting observation. The attached model does not reproduce a native multithreaded D3D12 execution.

7. Requests that cannot reuse pooled capacity

Some resource descriptions cannot use the texture pool.

The existing allocator also imposes limits on individual pooled allocation sizes.

See [pool.rs:224–275](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L224-L275).

A committed texture cannot consume an existing free piece from this pool.

Consequently, subtracting the entire pool credit when deciding whether such a request should proceed may not represent its incremental memory requirement.

The same consideration applies when a pooled placement fails and the creation path falls back to a committed allocation.

An existing compatible pooled range also does not necessarily imply zero additional physical residency cost.

8. Asset-free differential validation

The attached Python model compares the current accounting formula with reusable free ranges and an illustrative request-aware allocation growth gate.

The matrix contains:

  • Six synthetic pool states.
  • Four timestamps around the resting deadline.
  • Five allocation request types and sizes.
  • Three reported memory usage levels.

Total: 360 deterministic evaluations.

Result Evaluations
Current credit exceeds immediately reusable byte count 120
Current policy admits, no existing fit, illustrative growth gate refuses 128

These are separate, potentially overlapping categories.

All 11 Python tests passed.

The tests cover:

  • Resting deadlines.
  • Fragmentation.
  • Alignment.
  • Pending allocation reservations.
  • Fully occupied blocks.
  • Nonpooled allocations.
  • Range coalescing.
  • Admission thresholds.
  • Reserved memory.
  • Incremental growth size.
  • Matrix consistency.

The inputs are deliberately constructed counterexamples, not samples from gameplay or estimates of real-world failure frequency.

9. Suggested correction

I suggest separating diagnostic capacity accounting from actual allocation admission.

A. Distinguish the pool's memory states

Maintain or derive separate values for:

Allocated block capacity
Live texture pieces
Resting pieces
Reserved pieces awaiting creation
Free ranges
Largest compatible free range

This would make it possible to identify how much pool memory is genuinely reusable and how much is temporarily unavailable.

B. Consider the requested allocation

Where practical, determine whether an existing block can accommodate the requested size and alignment before relying on pool capacity as an admission credit.

A total free-byte count alone cannot establish this.

C. Gate incremental allocations separately

If no compatible range exists, consider evaluating the incremental memory cost of:

  • Allocating another 64 MiB pool block.
  • Creating a committed texture.
  • Creating additional proactive ripe blocks.

take_ripe() may allocate a spare block even after finding a compatible existing range. Therefore, successful reuse and proactive growth should be considered separately.

D. Preserve safety and existing policy semantics

Any production correction should preserve:

  • The mandatory resting period.
  • Existing resource lifetime guarantees.
  • Descriptor publication and submission ordering.
  • The initial texture floor and explicit budget override semantics.
  • Mandatory resource allocation behavior.
  • Existing allocation fallbacks.
  • Safe lock ordering.

In particular, avoid calling a memory-budget helper that recursively acquires the texture pool mutex while that mutex is already held.

A production solution should also account for concurrent reservations and stale DXGI budget samples.

The attached growth gate is an illustrative model, not a proposed drop-in production implementation.

10. Proposed native CPU-only regression

A useful first step would be to add tests directly to the existing pool.rs test module using the generic Pool<B> implementation.

The existing tests already use synthetic pool blocks and controlled timestamps without requiring GPU allocations.

Suggested regression sequence:

  1. Construct a synthetic Pool<u32>.
  2. Allocate one or more pieces.
  3. Return those pieces through the production Pool::give() path.
  4. Inspect the accounting before their resting deadline.
  5. Attempt a compatible allocation with an instrumented growth closure.
  6. Confirm that unavailable resting capacity cannot satisfy the request.
  7. Advance the timestamp beyond the deadline and reclaim.
  8. Confirm that the existing range becomes reusable.
  9. Repeat with fragmented ranges and alignment constraints.
  10. Verify that a denied growth operation does not modify existing live pieces.

Additional controls should cover:

Case Expected property
Fully occupied block No reusable capacity
Resting piece Not reusable before deadline
Reclaimed piece Reusable after deadline
Fragmented free ranges Admission depends on a compatible fit
Pending allocation Reserved capacity is not reusable
Committed fallback Does not consume pooled free ranges
Proactive block creation Growth evaluated independently

The test should exercise the actual allocator and accounting implementation rather than only reproducing their formulas.

No title files, proprietary shaders or physical GPU memory exhaustion are necessary for the initial regression.

11. Relationship to existing VRAM work

I inspected the following related PR revisions.

#119 — Adaptive spare-block retention

Revision:

d39a0b5185cc73bf85ee8ac2d6ca884c9290ae90

This proposal reduces empty block retention according to remaining DXGI headroom.

It retains the existing texture_room() calculation.

#205 — Host RAM reduction

Revision:

5a26c94b59cb4d6539a8b2d989177a5d6d2b71ab

This proposal introduces idle memory trimming and additional reclamation policies.

It also retains the existing texture_room() calculation.

#212 — Fence-safe LRU eviction and adaptive mip clamping

Revision:

1e710c4bbeb03ce24bd3f2398621c0cb1c572702

This proposal introduces texture eviction and budget-aware mip clamping.

It continues using the pool credit when evaluating automatic texture admission, idle texture retention and adaptive mip policy.

The accounting issue may therefore also affect those decisions.

I suggest coordinating any production correction with these contributors rather than creating another independent eviction architecture.

The duplicate search was limited to selected issues, PRs and source paths.

12. Relevance to NVIDIA GPUs with 8 GiB of VRAM

On memory-constrained GPUs, even a small number of temporarily unavailable 64 MiB blocks can materially affect the difference between reported usage and the adjusted admission calculation.

The proposed direction complements:

  • Adaptive spare-block retention.
  • Fence-safe texture eviction.
  • Mip-tail clamping.
  • Descriptor recycling.
  • Recovery after transient allocation failure.

The objective is not to reduce texture quality unnecessarily or to reclaim memory that may still be in use.

The objective is to make admission decisions more accurately reflect existing allocation opportunities and the incremental cost of new allocations.

Attachment

avatar_pool_room_audit.zip

Contents:

  • README.md
  • model.py
  • test_model.py
  • matrix.csv
  • results.txt

Reproduction:

python model.py
python -m unittest -v test_model

No external Python dependencies are required.

Requested verification

Could an independent contributor validate the resting-capacity counterexample using the existing generic Pool<B> test infrastructure?

If reproduced, I suggest first establishing a regression for allocator availability and then evaluating request-aware admission in coordination with the existing VRAM management PRs.

Credits and limitations

avatar_pool_room_audit.zip

Only public repository source and invented test data were used.

No proprietary game files, executable files, shader dumps, console SDK material or gameplay captures are included.

The Python model and its 11 tests were executed successfully.

The investigation does not include a compiled Rust patch, native D3D12 validation, physical VRAM measurements or gameplay benchmarks.

The model does not simulate physical residency, concurrent allocation execution, proactive block growth, or every mandatory allocation and budget override path.

No FPS improvement, VRAM reduction or visual correction is claimed.

**@⁠FunWithFlagsDev** on GitHub · 2026-11-26 13:34 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/262) <html> <body> <!--StartFragment--><h2><span>Summary</span></h2><p><span>While investigating memory management on NVIDIA GPUs with limited VRAM, I identified a mismatch between the texture pool's reported reusable capacity and the capacity that its allocator can actually reuse for a particular request.</span></p><p><span>The current accounting may include:</span></p><ul><li><p><span>Released pieces that are still subject to the mandatory 2,500 ms resting period.</span></p></li><li><p><span>Fragmented free ranges that cannot accommodate the requested allocation.</span></p></li><li><p><span>Pieces reserved for an allocation whose resource creation has not yet completed.</span></p></li><li><p><span>Pool capacity credited toward requests that cannot use pooled allocation.</span></p></li></ul><p><span>This capacity is subtracted from reported local video memory usage when evaluating texture admission.</span></p><p><span>Consequently, the automatic admission policy may allow additional texture preparation even when the allocator cannot reuse existing memory and must attempt another allocation.</span></p><p><span>This is particularly relevant to 8–12 GiB GPUs, where the available local memory budget can be substantially smaller than physical VRAM capacity.</span></p><p><span>The attached archive contains source references, an executable synthetic model, 11 regression tests and a matrix of 360 deterministic evaluations.</span></p><h2><span>1. Affected revision</span></h2><p><span>Repository: </span><code><span>avatarmanz/VIctory-7900XTX</span></code></p><p><span>Commit:</span></p><p><code><span>c9c932cbcc38defd8f1683d62dd298187f565031</span></code></p><p><span>Primary files:</span></p><ul><li><p><code><span>crates/victory-gpu/src/pool.rs</span></code></p></li><li><p><code><span>crates/victory-gpu/src/resource.rs</span></code></p></li></ul><h2><span>2. Current pool accounting</span></h2><p><a href="https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L365-L374"><code><span>pool.rs:365–374</span></code></a></p><pre><code><span>pub(crate) fn texture_room() -&gt; u64 { (lock(&amp;TEXTURES).blocks() as u64 * BLOCK) .saturating_sub(HELD.load(Ordering::Relaxed)) }</span></code></pre><p><span>This calculates the difference between total allocated block capacity and the bytes counted as held by textures.</span></p><p><span>However, this difference is not necessarily equivalent to immediately allocatable capacity.</span></p><p><span>The allocator itself operates on contiguous, aligned free ranges within individual blocks.</span></p><h2><span>3. Resting pieces are counted before they become reusable</span></h2><p><span>When the final reference to a pooled texture is released, its piece is returned through the following sequence:</span></p><p><a href="https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L450-L465"><code><span>pool.rs:450–465</span></code></a></p><pre><code><span>HELD.fetch_sub(gone.piece.len, Ordering::Relaxed); lock(&amp;TEXTURES).give(gone.piece, now());</span></code></pre><p><span>However, </span><code><span>Pool::give()</span></code><span> does not immediately restore that piece to the allocator's free ranges.</span></p><pre><code><span>fn give(&amp;mut self, piece: Piece, now: u64) { self.resting.push_back((now + REST, piece)); }</span></code></pre><p><span>The mandatory resting period is:</span></p><pre><code><span>const REST: u64 = 2500;</span></code></pre><p><span>Only after the deadline is reached can </span><code><span>Pool::reclaim()</span></code><span> restore the piece to the block's free ranges.</span></p><p><span>See </span><a href="https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L315-L340"><code><span>pool.rs:315–340</span></code></a><span>.</span></p><p><span>Therefore:</span></p> State of a released 64 MiB block | Current accounting credit | Reusable capacity -- | -- | -- Before release | 0 MiB | 0 MiB Immediately after release | 64 MiB | 0 MiB After 2,499 ms | 64 MiB | 0 MiB After the deadline and reclamation | 64 MiB | 64 MiB <p><span>The test should exercise the actual allocator and accounting implementation rather than only reproducing their formulas.</span></p><p><span>No title files, proprietary shaders or physical GPU memory exhaustion are necessary for the initial regression.</span></p><h2><span>11. Relationship to existing VRAM work</span></h2><p><span>I inspected the following related PR revisions.</span></p><h3><span>#119 — Adaptive spare-block retention</span></h3><p><span>Revision:</span></p><p><code><span>d39a0b5185cc73bf85ee8ac2d6ca884c9290ae90</span></code></p><p><span>This proposal reduces empty block retention according to remaining DXGI headroom.</span></p><p><span>It retains the existing </span><code><span>texture_room()</span></code><span> calculation.</span></p><h3><span>#205 — Host RAM reduction</span></h3><p><span>Revision:</span></p><p><code><span>5a26c94b59cb4d6539a8b2d989177a5d6d2b71ab</span></code></p><p><span>This proposal introduces idle memory trimming and additional reclamation policies.</span></p><p><span>It also retains the existing </span><code><span>texture_room()</span></code><span> calculation.</span></p><h3><span>#212 — Fence-safe LRU eviction and adaptive mip clamping</span></h3><p><span>Revision:</span></p><p><code><span>1e710c4bbeb03ce24bd3f2398621c0cb1c572702</span></code></p><p><span>This proposal introduces texture eviction and budget-aware mip clamping.</span></p><p><span>It continues using the pool credit when evaluating automatic texture admission, idle texture retention and adaptive mip policy.</span></p><p><span>The accounting issue may therefore also affect those decisions.</span></p><p><span>I suggest coordinating any production correction with these contributors rather than creating another independent eviction architecture.</span></p><p><span>The duplicate search was limited to selected issues, PRs and source paths.</span></p><h2><span>12. Relevance to NVIDIA GPUs with 8 GiB of VRAM</span></h2><p><span>On memory-constrained GPUs, even a small number of temporarily unavailable 64 MiB blocks can materially affect the difference between reported usage and the adjusted admission calculation.</span></p><p><span>The proposed direction complements:</span></p><ul><li><p><span>Adaptive spare-block retention.</span></p></li><li><p><span>Fence-safe texture eviction.</span></p></li><li><p><span>Mip-tail clamping.</span></p></li><li><p><span>Descriptor recycling.</span></p></li><li><p><span>Recovery after transient allocation failure.</span></p></li></ul><p><span>The objective is not to reduce texture quality unnecessarily or to reclaim memory that may still be in use.</span></p><p><span>The objective is to make admission decisions more accurately reflect existing allocation opportunities and the incremental cost of new allocations.</span></p><h2><span>Attachment</span></h2><p><code><span>avatar_pool_room_audit.zip</span></code></p><p><span>Contents:</span></p><ul><li><p><code><span>README.md</span></code></p></li><li><p><code><span>model.py</span></code></p></li><li><p><code><span>test_model.py</span></code></p></li><li><p><code><span>matrix.csv</span></code></p></li><li><p><code><span>results.txt</span></code></p></li></ul><p><span>Reproduction:</span></p><pre><code><span>python model.py python -m unittest -v test_model</span></code></pre><p><span>No external Python dependencies are required.</span></p><h2><span>Requested verification</span></h2><p><span>Could an independent contributor validate the resting-capacity counterexample using the existing generic </span><code><span>Pool&lt;B&gt;</span></code><span> test infrastructure?</span></p><p><span>If reproduced, I suggest first establishing a regression for allocator availability and then evaluating request-aware admission in coordination with the existing VRAM management PRs.</span></p><h2><span>Credits and limitations</span></h2><p><span>AI-assisted source investigation and synthetic modeling using ChatGPT.</span></p><p><span>Only public repository source and invented test data were used.</span></p><p><span>No proprietary game files, executable files, shader dumps, console SDK material or gameplay captures are included.</span></p><p><span>The Python model and its 11 tests were executed successfully.</span></p><p><span>The investigation does not include a compiled Rust patch, native D3D12 validation, physical VRAM measurements or gameplay benchmarks.</span></p><p><span>The model does not simulate physical residency, concurrent allocation execution, proactive block growth, or every mandatory allocation and budget override path.</span></p><p><span>No FPS improvement, VRAM reduction or visual correction is claimed.</span></p><!--EndFragment--> </body> </html>## Summary While investigating memory management on NVIDIA GPUs with limited VRAM, I identified a mismatch between the texture pool's reported reusable capacity and the capacity that its allocator can actually reuse for a particular request. The current accounting may include: - Released pieces that are still subject to the mandatory 2,500 ms resting period. - Fragmented free ranges that cannot accommodate the requested allocation. - Pieces reserved for an allocation whose resource creation has not yet completed. - Pool capacity credited toward requests that cannot use pooled allocation. This capacity is subtracted from reported local video memory usage when evaluating texture admission. Consequently, the automatic admission policy may allow additional texture preparation even when the allocator cannot reuse existing memory and must attempt another allocation. This is particularly relevant to 8–12 GiB GPUs, where the available local memory budget can be substantially smaller than physical VRAM capacity. The attached archive contains source references, an executable synthetic model, 11 regression tests and a matrix of 360 deterministic evaluations. ## 1. Affected revision Repository: `avatarmanz/VIctory-7900XTX` Commit: `c9c932cbcc38defd8f1683d62dd298187f565031` Primary files: - `crates/victory-gpu/src/pool.rs` - `crates/victory-gpu/src/resource.rs` ## 2. Current pool accounting [`[pool.rs:365–374](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L365-L374)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L365-L374) ```rust pub(crate) fn texture_room() -> u64 { (lock(&TEXTURES).blocks() as u64 * BLOCK) .saturating_sub(HELD.load(Ordering::Relaxed)) } ``` This calculates the difference between total allocated block capacity and the bytes counted as held by textures. However, this difference is not necessarily equivalent to immediately allocatable capacity. The allocator itself operates on contiguous, aligned free ranges within individual blocks. ## 3. Resting pieces are counted before they become reusable When the final reference to a pooled texture is released, its piece is returned through the following sequence: [`[pool.rs:450–465](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L450-L465)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L450-L465) ```rust HELD.fetch_sub(gone.piece.len, Ordering::Relaxed); lock(&TEXTURES).give(gone.piece, now()); ``` However, `Pool::give()` does not immediately restore that piece to the allocator's free ranges. ```rust fn give(&mut self, piece: Piece, now: u64) { self.resting.push_back((now + REST, piece)); } ``` The mandatory resting period is: ```rust const REST: u64 = 2500; ``` Only after the deadline is reached can `Pool::reclaim()` restore the piece to the block's free ranges. See [`[pool.rs:315–340](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L315-L340)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L315-L340). Therefore: | State of a released 64 MiB block | Current accounting credit | Reusable capacity | |---|---:|---:| | Before release | 0 MiB | 0 MiB | | Immediately after release | 64 MiB | 0 MiB | | After 2,499 ms | 64 MiB | 0 MiB | | After the deadline and reclamation | 64 MiB | 64 MiB | The resting period should remain intact. The issue is the accounting credit applied before the capacity becomes reusable. ## 4. Synthetic 8 GiB GPU counterexample Consider the following invented memory state: | Parameter | Value | |---|---:| | Physical GPU memory class | 8 GiB | | DXGI local budget | 7,424 MiB | | Reported local usage | 7,168 MiB | | Existing pool blocks | 16 | | Block size | 64 MiB | | Entirely resting pool capacity | 1,024 MiB | | Immediately reusable capacity | 0 MiB | Assume: - No explicit texture-budget override. - The unconditional initial texture floor has already been satisfied. - No additional remaining card-buffer or render-target reservation. - The resting deadlines have not expired. The existing automatic admission policy subtracts `texture_room()` from reported usage. See [`[resource.rs:1725–1754](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/resource.rs#L1725-L1754)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/resource.rs#L1725-L1754). With the default 90% threshold: ```text Reported local usage: 7168 MiB Current pool credit: 1024 MiB Adjusted usage: 6144 MiB 90% admission threshold: ~6682 MiB ``` The current policy admits the request because adjusted usage is below the threshold. However: ```text Immediately reusable pool capacity: 0 MiB Actual reported local usage: 7168 MiB ``` Reported usage already exceeds the automatic admission threshold. If a new eligible 32 MiB texture request reaches the allocator before the resting pieces are reclaimed, it cannot reuse those pieces. It must either obtain another block, fail allocation, or proceed through an applicable allocation fallback. This demonstrates a mismatch between the accounting credit and allocator eligibility. It does not establish that the driver will necessarily refuse the allocation or that a device failure will occur. ## 5. Fragmentation is a separate problem Even counting only genuinely free ranges is insufficient to determine whether a particular texture fits. Consider one 64 MiB block: ```text [16 MiB free][16 MiB held][16 MiB free][16 MiB held] ``` Total free capacity is 32 MiB. The largest contiguous free range is only 16 MiB. A texture requiring a contiguous 32 MiB placement cannot use this block despite its reported free capacity. Repeating this arrangement across 32 blocks produces 1 GiB of aggregate free capacity without any existing range that can accommodate a 32 MiB allocation. Alignment constraints can also prevent an allocation from fitting into a range whose byte count would otherwise be sufficient. The allocator correctly checks individual aligned ranges in `Ranges::take()`. The admission policy does not receive equivalent request-specific information. ## 6. Allocation reservations in progress There is another accounting interval during pooled texture creation. See [`[pool.rs:668–725](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L668-L725)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L668-L725). The sequence is approximately: 1. Reserve a piece through `take_ripe()`. 2. Release the pool lock. 3. Attempt `CreatePlacedResource()`. 4. Increment `HELD` after successful creation. 5. Associate the piece's lifetime with the resulting texture. Between steps 1 and 4, the reserved range is no longer available to another allocation but is not yet represented in `HELD`. A concurrent accounting query may therefore credit capacity that has already been reserved. On placement failure, the piece is returned through the resting mechanism rather than immediately becoming free. This is a source-level accounting observation. The attached model does not reproduce a native multithreaded D3D12 execution. ## 7. Requests that cannot reuse pooled capacity Some resource descriptions cannot use the texture pool. The existing allocator also imposes limits on individual pooled allocation sizes. See [`[pool.rs:224–275](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L224-L275)`](https://github.com/avatarmanz/VIctory-7900XTX/blob/c9c932cb/crates/victory-gpu/src/pool.rs#L224-L275). A committed texture cannot consume an existing free piece from this pool. Consequently, subtracting the entire pool credit when deciding whether such a request should proceed may not represent its incremental memory requirement. The same consideration applies when a pooled placement fails and the creation path falls back to a committed allocation. An existing compatible pooled range also does not necessarily imply zero additional physical residency cost. ## 8. Asset-free differential validation The attached Python model compares the current accounting formula with reusable free ranges and an illustrative request-aware allocation growth gate. The matrix contains: - Six synthetic pool states. - Four timestamps around the resting deadline. - Five allocation request types and sizes. - Three reported memory usage levels. Total: 360 deterministic evaluations. | Result | Evaluations | |---|---:| | Current credit exceeds immediately reusable byte count | 120 | | Current policy admits, no existing fit, illustrative growth gate refuses | 128 | These are separate, potentially overlapping categories. All 11 Python tests passed. The tests cover: - Resting deadlines. - Fragmentation. - Alignment. - Pending allocation reservations. - Fully occupied blocks. - Nonpooled allocations. - Range coalescing. - Admission thresholds. - Reserved memory. - Incremental growth size. - Matrix consistency. The inputs are deliberately constructed counterexamples, not samples from gameplay or estimates of real-world failure frequency. ## 9. Suggested correction I suggest separating diagnostic capacity accounting from actual allocation admission. ### A. Distinguish the pool's memory states Maintain or derive separate values for: ```text Allocated block capacity Live texture pieces Resting pieces Reserved pieces awaiting creation Free ranges Largest compatible free range ``` This would make it possible to identify how much pool memory is genuinely reusable and how much is temporarily unavailable. ### B. Consider the requested allocation Where practical, determine whether an existing block can accommodate the requested size and alignment before relying on pool capacity as an admission credit. A total free-byte count alone cannot establish this. ### C. Gate incremental allocations separately If no compatible range exists, consider evaluating the incremental memory cost of: - Allocating another 64 MiB pool block. - Creating a committed texture. - Creating additional proactive ripe blocks. `take_ripe()` may allocate a spare block even after finding a compatible existing range. Therefore, successful reuse and proactive growth should be considered separately. ### D. Preserve safety and existing policy semantics Any production correction should preserve: - The mandatory resting period. - Existing resource lifetime guarantees. - Descriptor publication and submission ordering. - The initial texture floor and explicit budget override semantics. - Mandatory resource allocation behavior. - Existing allocation fallbacks. - Safe lock ordering. In particular, avoid calling a memory-budget helper that recursively acquires the texture pool mutex while that mutex is already held. A production solution should also account for concurrent reservations and stale DXGI budget samples. The attached growth gate is an illustrative model, not a proposed drop-in production implementation. ## 10. Proposed native CPU-only regression A useful first step would be to add tests directly to the existing `pool.rs` test module using the generic `Pool<B>` implementation. The existing tests already use synthetic pool blocks and controlled timestamps without requiring GPU allocations. Suggested regression sequence: 1. Construct a synthetic `Pool<u32>`. 2. Allocate one or more pieces. 3. Return those pieces through the production `Pool::give()` path. 4. Inspect the accounting before their resting deadline. 5. Attempt a compatible allocation with an instrumented growth closure. 6. Confirm that unavailable resting capacity cannot satisfy the request. 7. Advance the timestamp beyond the deadline and reclaim. 8. Confirm that the existing range becomes reusable. 9. Repeat with fragmented ranges and alignment constraints. 10. Verify that a denied growth operation does not modify existing live pieces. Additional controls should cover: | Case | Expected property | |---|---| | Fully occupied block | No reusable capacity | | Resting piece | Not reusable before deadline | | Reclaimed piece | Reusable after deadline | | Fragmented free ranges | Admission depends on a compatible fit | | Pending allocation | Reserved capacity is not reusable | | Committed fallback | Does not consume pooled free ranges | | Proactive block creation | Growth evaluated independently | The test should exercise the actual allocator and accounting implementation rather than only reproducing their formulas. No title files, proprietary shaders or physical GPU memory exhaustion are necessary for the initial regression. ## 11. Relationship to existing VRAM work I inspected the following related PR revisions. ### #119 — Adaptive spare-block retention Revision: `d39a0b5185cc73bf85ee8ac2d6ca884c9290ae90` This proposal reduces empty block retention according to remaining DXGI headroom. It retains the existing `texture_room()` calculation. ### #205 — Host RAM reduction Revision: `5a26c94b59cb4d6539a8b2d989177a5d6d2b71ab` This proposal introduces idle memory trimming and additional reclamation policies. It also retains the existing `texture_room()` calculation. ### #212 — Fence-safe LRU eviction and adaptive mip clamping Revision: `1e710c4bbeb03ce24bd3f2398621c0cb1c572702` This proposal introduces texture eviction and budget-aware mip clamping. It continues using the pool credit when evaluating automatic texture admission, idle texture retention and adaptive mip policy. The accounting issue may therefore also affect those decisions. I suggest coordinating any production correction with these contributors rather than creating another independent eviction architecture. The duplicate search was limited to selected issues, PRs and source paths. ## 12. Relevance to NVIDIA GPUs with 8 GiB of VRAM On memory-constrained GPUs, even a small number of temporarily unavailable 64 MiB blocks can materially affect the difference between reported usage and the adjusted admission calculation. The proposed direction complements: - Adaptive spare-block retention. - Fence-safe texture eviction. - Mip-tail clamping. - Descriptor recycling. - Recovery after transient allocation failure. The objective is not to reduce texture quality unnecessarily or to reclaim memory that may still be in use. The objective is to make admission decisions more accurately reflect existing allocation opportunities and the incremental cost of new allocations. ## Attachment `avatar_pool_room_audit.zip` Contents: - `README.md` - `model.py` - `test_model.py` - `matrix.csv` - `results.txt` Reproduction: ```bash python model.py python -m unittest -v test_model ``` No external Python dependencies are required. ## Requested verification Could an independent contributor validate the resting-capacity counterexample using the existing generic `Pool<B>` test infrastructure? If reproduced, I suggest first establishing a regression for allocator availability and then evaluating request-aware admission in coordination with the existing VRAM management PRs. ## Credits and limitations [avatar_pool_room_audit.zip](https://github.com/user-attachments/files/35466340/avatar_pool_room_audit.zip) Only public repository source and invented test data were used. No proprietary game files, executable files, shader dumps, console SDK material or gameplay captures are included. The Python model and its 11 tests were executed successfully. The investigation does not include a compiled Rust patch, native D3D12 validation, physical VRAM measurements or gameplay benchmarks. The model does not simulate physical residency, concurrent allocation execution, proactive block growth, or every mandatory allocation and budget override path. No FPS improvement, VRAM reduction or visual correction is claimed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:38:13 +00:00
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#262
No description provided.