Pressure MemoryPo #3683

Open
opened 2026-12-02 09:09:22 +00:00 by willvixtor · 0 comments
willvixtor commented 2026-12-02 09:09:22 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by willvixtor on 2026-12-02T09:09:22Z.


Pressure MemoryPolicy::classify(
const SegmentTelemetry& s,
Pressure previous
) const
{
if (s.budgetBytes == 0)
return Pressure::Unknown;

const double ratio =
    static_cast<double>(s.usageBytes) /
    static_cast<double>(s.budgetBytes);

// Usage above the reported budget is always critical.
if (s.usageBytes > s.budgetBytes)
    return Pressure::Critical;

// CRITICAL: remain critical until usage reaches 93%.
if (previous == Pressure::Critical) {
    if (ratio > thresholds_.exitCritical)
        return Pressure::Critical;

    if (ratio > thresholds_.exitHigh)
        return Pressure::High;

    if (ratio > thresholds_.exitWatch)
        return Pressure::Watch;

    return Pressure::Normal;
}

// HIGH: escalate immediately, but use exit thresholds to recover.
if (previous == Pressure::High) {
    if (ratio >= thresholds_.enterCritical)
        return Pressure::Critical;

    if (ratio > thresholds_.exitHigh)
        return Pressure::High;

    if (ratio > thresholds_.exitWatch)
        return Pressure::Watch;

    return Pressure::Normal;
}

// WATCH: escalate immediately when a higher threshold is reached.
if (previous == Pressure::Watch) {
    if (ratio >= thresholds_.enterCritical)
        return Pressure::Critical;

    if (ratio >= thresholds_.enterHigh)
        return Pressure::High;

    if (ratio > thresholds_.exitWatch)
        return Pressure::Watch;

    return Pressure::Normal;
}

// Initial state: use entry thresholds.
if (ratio >= thresholds_.enterCritical)
    return Pressure::Critical;

if (ratio >= thresholds_.enterHigh)
    return Pressure::High;

if (ratio >= thresholds_.enterWatch)
    return Pressure::Watch;

return Pressure::Normal;

}

// Regression: Critical must not clear at 95% or 94%.
t.local.usageBytes = 990;
auto critical99 = p.evaluate(t);
CHECK(critical99.localPressure == Pressure::Critical);
CHECK(critical99.requestFenceSafeEviction);

t.local.usageBytes = 950;
auto critical95 = p.evaluate(t);
CHECK(critical95.localPressure == Pressure::Critical);
CHECK(critical95.requestFenceSafeEviction);

t.local.usageBytes = 940;
auto critical94 = p.evaluate(t);
CHECK(critical94.localPressure == Pressure::Critical);

// At 93%, leave Critical and enter High.
t.local.usageBytes = 930;
auto high93 = p.evaluate(t);
CHECK(high93.localPressure == Pressure::High);
CHECK(!high93.requestFenceSafeEviction);

// At 86%, leave High and enter Watch.
t.local.usageBytes = 860;
auto watch86 = p.evaluate(t);
CHECK(watch86.localPressure == Pressure::Watch);

// At 76%, leave Watch and return to Normal.
t.local.usageBytes = 760;
auto normal76 = p.evaluate(t);
CHECK(normal76.localPressure == Pressure::Normal);

auto decision = ChooseMip(assetDemand, memoryPressure);

// 1. Check whether the requested mip is already resident.
if (!texture.IsMipResident(decision.targetMip))
{
// 2. Do not exceed the upload budget for this frame.
if (uploadQueue.CanAccept(texture.GetMipUploadSize(
decision.targetMip)))
{
// 3. Queue upload without blocking the render thread.
uploadQueue.Enqueue(texture, decision.targetMip);
}
}

// 4. Keep the old resident mip until the GPU copy fence completes.
// 5. Publish the new mip only after successful completion.
// 6. Retire old resources only after their last-use fence.

Comprehensive Implementation Proposal — GTA VI PC Memory Management, GPU Optimization and World Streaming

Thank you for reviewing the memory-management proposal.

The source-level corrections and regression tests have already been provided. I would like to expand the scope of the proposal and outline the full range of improvements that could be implemented in XCL.

The objective is not simply to monitor GPU memory. It is to develop an adaptive memory-management and resource-streaming system capable of handling demanding world-loading scenarios, especially on GPUs with 8 GB, 12 GB and 16 GB of dedicated VRAM, as well as systems using shared memory.

  1. Intelligent GPU Memory Management

Implement a centralized memory-pressure controller that continuously evaluates:

  • DXGI LOCAL memory budget and current usage.
  • DXGI NON_LOCAL memory budget and current usage.
  • Available GPU memory budget.
  • Allocation failures and memory fragmentation.
  • Resource residency and eviction activity.
  • Pending GPU operations and fence synchronization.
  • Memory allocation peaks during world loading.

The controller should dynamically adjust memory-management behavior according to actual hardware conditions.

Memory pressure should trigger graduated responses instead of waiting for allocation failures.

  1. Adaptive Texture Streaming

Texture streaming should become fully integrated with the memory-pressure controller.

Possible improvements include:

  • Dynamically selecting texture mip levels based on screen-space importance.
  • Prioritizing visible objects and nearby geometry.
  • Reducing texture resolution for distant or temporarily irrelevant objects.
  • Increasing texture quality when memory becomes available.
  • Preventing unnecessary repeated texture uploads.
  • Maintaining minimum residency periods to prevent mipmap oscillation.
  • Prioritizing critical assets during camera movement.
  • Scheduling texture uploads asynchronously.
  • Limiting upload bandwidth per frame.
  • Releasing obsolete texture resources only after GPU synchronization.

The goal is to maintain visual quality while avoiding unnecessary VRAM consumption.

  1. Predictive World Streaming

Instead of reacting only after memory pressure occurs, XCL could implement predictive resource streaming.

Potential inputs:

  • Player position and movement direction.
  • Camera orientation and field of view.
  • Player velocity.
  • Nearby world geometry.
  • Expected world transitions.
  • Previously accessed streaming assets.
  • Current upload queue.
  • Available GPU memory budget.

This could allow the engine to prepare high-priority assets before they become visible while avoiding unnecessary preloading.

Predictive streaming should be conservative and automatically reduce its workload when memory pressure increases.

  1. Intelligent Memory Eviction

Implement a resource eviction manager that identifies resources according to:

  • Last access time.
  • Visibility.
  • Distance from the player.
  • Current GPU usage.
  • Reload cost.
  • Resource importance.
  • Whether the resource is currently referenced by GPU commands.

Prefer releasing obsolete, reloadable and low-priority resources.

Never release resources that are still being used by in-flight GPU operations.

All eviction operations must respect GPU fences and resource lifetime rules.

  1. Asynchronous Upload Scheduling

World loading can generate substantial upload activity.

Introduce a scheduler that:

  • Controls upload bandwidth.
  • Limits per-frame upload workloads.
  • Prioritizes visible and gameplay-critical assets.
  • Defers low-priority transfers.
  • Avoids unnecessary CPU/GPU synchronization.
  • Monitors upload queue saturation.
  • Coordinates copy queues and graphics queues where supported.

This could help prevent large asset transfers from creating noticeable frame-time spikes.

  1. CPU and GPU Workload Separation

Investigate whether world-loading stalls originate from:

  • CPU decompression.
  • Asset parsing.
  • Texture uploads.
  • GPU memory allocation.
  • Resource residency changes.
  • Shader compilation.
  • Pipeline-state creation.
  • Particle-system initialization.
  • Synchronization waits.

These systems should be measured independently.

Where supported by the engine architecture, consider parallel asset decompression, background resource preparation, asynchronous shader compilation and non-blocking upload scheduling.

Do not assume every loading stall is caused by VRAM pressure.

  1. Hardware-Adaptive Optimization

Create hardware profiles based on actual available memory budgets rather than fixed GPU model names.

For example:

8 GB VRAM

  • Aggressive speculative-prefetch restrictions.
  • Smaller texture residency targets.
  • Conservative upload budgets.
  • Earlier cache trimming.

12 GB VRAM

  • Balanced texture residency.
  • Moderate predictive streaming.
  • Adaptive cache management.

16 GB VRAM

  • Larger residency targets when justified by available budget.
  • More selective predictive prefetching.
  • Less aggressive cache eviction when memory pressure is low.

These should be dynamic policies, not hardcoded assumptions.

The system must also account for operating-system GPU reservations, other applications and changing DXGI budgets.

  1. Shared Memory and UMA Compatibility

Ensure correct behavior across:

  • Dedicated GPUs.
  • GPUs using shared system memory.
  • UMA architectures.
  • Different DXGI memory segments.
  • Multi-adapter configurations where supported.

Do not assume that shared memory provides the same performance as dedicated VRAM.

Memory budgets and usage must be evaluated independently, and the engine must avoid excessive transfers between CPU and GPU memory.

  1. World-Loading Stall Diagnostics

Develop a dedicated diagnostic mode that captures events around world-loading stalls.

Record:

  • Exact stall start and end timestamps.
  • GPU memory budget and usage.
  • Allocation requests and failures.
  • Upload queue depth.
  • Resource eviction events.
  • Fence wait durations.
  • CPU asset-processing times.
  • Shader compilation times.
  • Particle initialization times.
  • Frame-time spikes.
  • GPU utilization.
  • Storage read throughput.

This would make it possible to identify the actual bottleneck instead of guessing.

  1. Dynamic Quality Management

Consider integrating memory pressure with selected rendering-quality parameters.

Potential candidates include:

  • Texture mip residency.
  • Texture streaming distance.
  • Shadow-map residency.
  • Reflection and probe cache residency.
  • Geometry and asset cache sizes.
  • Non-essential streaming prefetch.

Quality reductions should be gradual, reversible and restricted to resources that can safely tolerate them.

Avoid changing unrelated rendering settings without evidence that they contribute to the problem.

  1. Benchmarking and Validation

Test at least three configurations:

  1. Original XCL implementation.
  2. Memory diagnostics enabled without adaptive optimization.
  3. Full memory-management and streaming optimization enabled.

Test multiple VRAM capacities and different hardware configurations.

Perform repeated cold-load and warm-load tests using identical routes, settings, drivers and game builds.

Measure:

  • Average FPS.
  • 1% low FPS.
  • P50, P95 and P99 frame times.
  • Number of stalls.
  • Total stall duration.
  • Local and non-local memory pressure.
  • Texture upload throughput.
  • Eviction activity.
  • Resource residency.
  • CPU loading time.
  • GPU synchronization time.

The implementation should only be considered successful when measurable improvements are reproducible without visual corruption, instability or increased loading times.

  1. Suggested Development Roadmap

Phase 1 — Correctness

  • Apply the memory-pressure hysteresis correction.
  • Expand regression tests.
  • Validate DXGI memory reporting.
  • Verify safe resource lifetime management.

Phase 2 — Diagnostics

  • Add detailed world-loading telemetry.
  • Capture upload and eviction events.
  • Identify reproducible loading stalls.

Phase 3 — Streaming

  • Integrate mip selection with actual texture residency.
  • Implement asynchronous upload scheduling.
  • Introduce adaptive cache management.

Phase 4 — Predictive Optimization

  • Introduce player and camera-aware asset prioritization.
  • Implement conservative predictive prefetch.
  • Dynamically adapt to available GPU memory.

Phase 5 — Hardware Scaling

  • Validate behavior across 8 GB, 12 GB and 16 GB GPUs.
  • Test dedicated and shared memory configurations.
  • Tune policies according to measured hardware capabilities.

Phase 6 — Performance Validation

  • Conduct controlled A/B benchmarks.
  • Compare frame-time distributions.
  • Verify visual quality and stability.
  • Publish reproducible results.

Final Objective

The broader objective is to investigate whether XCL can benefit from a unified, adaptive GPU memory and world-streaming architecture.

Rather than relying on static memory limits or waiting for allocation failures, the engine could continuously evaluate available resources, prioritize important assets, schedule transfers intelligently and respond to memory pressure before it becomes a critical problem.

This proposal is intended to give contributors several independently testable implementation paths.

Not every feature needs to be implemented simultaneously. The highest priority should be correctness, diagnostics and reproducible evidence, followed by streaming integration and predictive optimization.

I believe this approach deserves technical evaluation before the entire proposal is dismissed.

The ultimate goal is to make XCL more stable, scalable and efficient across a wider range of PC hardware, particularly GPUs with limited dedicated VRAM.

Originalmente postado por @willvixtor em https://github.com/xcl-dev/xcl/issues/3596#issuecomment-7335040605

<!-- greyfinch-sync:ivall/xcl:issue:6741103995 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3683). Originally posted by [willvixtor](https://github.com/willvixtor) on 2026-12-02T09:09:22Z. --- Pressure MemoryPolicy::classify( const SegmentTelemetry& s, Pressure previous ) const { if (s.budgetBytes == 0) return Pressure::Unknown; const double ratio = static_cast<double>(s.usageBytes) / static_cast<double>(s.budgetBytes); // Usage above the reported budget is always critical. if (s.usageBytes > s.budgetBytes) return Pressure::Critical; // CRITICAL: remain critical until usage reaches 93%. if (previous == Pressure::Critical) { if (ratio > thresholds_.exitCritical) return Pressure::Critical; if (ratio > thresholds_.exitHigh) return Pressure::High; if (ratio > thresholds_.exitWatch) return Pressure::Watch; return Pressure::Normal; } // HIGH: escalate immediately, but use exit thresholds to recover. if (previous == Pressure::High) { if (ratio >= thresholds_.enterCritical) return Pressure::Critical; if (ratio > thresholds_.exitHigh) return Pressure::High; if (ratio > thresholds_.exitWatch) return Pressure::Watch; return Pressure::Normal; } // WATCH: escalate immediately when a higher threshold is reached. if (previous == Pressure::Watch) { if (ratio >= thresholds_.enterCritical) return Pressure::Critical; if (ratio >= thresholds_.enterHigh) return Pressure::High; if (ratio > thresholds_.exitWatch) return Pressure::Watch; return Pressure::Normal; } // Initial state: use entry thresholds. if (ratio >= thresholds_.enterCritical) return Pressure::Critical; if (ratio >= thresholds_.enterHigh) return Pressure::High; if (ratio >= thresholds_.enterWatch) return Pressure::Watch; return Pressure::Normal; } // Regression: Critical must not clear at 95% or 94%. t.local.usageBytes = 990; auto critical99 = p.evaluate(t); CHECK(critical99.localPressure == Pressure::Critical); CHECK(critical99.requestFenceSafeEviction); t.local.usageBytes = 950; auto critical95 = p.evaluate(t); CHECK(critical95.localPressure == Pressure::Critical); CHECK(critical95.requestFenceSafeEviction); t.local.usageBytes = 940; auto critical94 = p.evaluate(t); CHECK(critical94.localPressure == Pressure::Critical); // At 93%, leave Critical and enter High. t.local.usageBytes = 930; auto high93 = p.evaluate(t); CHECK(high93.localPressure == Pressure::High); CHECK(!high93.requestFenceSafeEviction); // At 86%, leave High and enter Watch. t.local.usageBytes = 860; auto watch86 = p.evaluate(t); CHECK(watch86.localPressure == Pressure::Watch); // At 76%, leave Watch and return to Normal. t.local.usageBytes = 760; auto normal76 = p.evaluate(t); CHECK(normal76.localPressure == Pressure::Normal); auto decision = ChooseMip(assetDemand, memoryPressure); // 1. Check whether the requested mip is already resident. if (!texture.IsMipResident(decision.targetMip)) { // 2. Do not exceed the upload budget for this frame. if (uploadQueue.CanAccept(texture.GetMipUploadSize( decision.targetMip))) { // 3. Queue upload without blocking the render thread. uploadQueue.Enqueue(texture, decision.targetMip); } } // 4. Keep the old resident mip until the GPU copy fence completes. // 5. Publish the new mip only after successful completion. // 6. Retire old resources only after their last-use fence. Comprehensive Implementation Proposal — GTA VI PC Memory Management, GPU Optimization and World Streaming Thank you for reviewing the memory-management proposal. The source-level corrections and regression tests have already been provided. I would like to expand the scope of the proposal and outline the full range of improvements that could be implemented in XCL. The objective is not simply to monitor GPU memory. It is to develop an adaptive memory-management and resource-streaming system capable of handling demanding world-loading scenarios, especially on GPUs with 8 GB, 12 GB and 16 GB of dedicated VRAM, as well as systems using shared memory. 1. Intelligent GPU Memory Management Implement a centralized memory-pressure controller that continuously evaluates: - DXGI LOCAL memory budget and current usage. - DXGI NON_LOCAL memory budget and current usage. - Available GPU memory budget. - Allocation failures and memory fragmentation. - Resource residency and eviction activity. - Pending GPU operations and fence synchronization. - Memory allocation peaks during world loading. The controller should dynamically adjust memory-management behavior according to actual hardware conditions. Memory pressure should trigger graduated responses instead of waiting for allocation failures. 2. Adaptive Texture Streaming Texture streaming should become fully integrated with the memory-pressure controller. Possible improvements include: - Dynamically selecting texture mip levels based on screen-space importance. - Prioritizing visible objects and nearby geometry. - Reducing texture resolution for distant or temporarily irrelevant objects. - Increasing texture quality when memory becomes available. - Preventing unnecessary repeated texture uploads. - Maintaining minimum residency periods to prevent mipmap oscillation. - Prioritizing critical assets during camera movement. - Scheduling texture uploads asynchronously. - Limiting upload bandwidth per frame. - Releasing obsolete texture resources only after GPU synchronization. The goal is to maintain visual quality while avoiding unnecessary VRAM consumption. 3. Predictive World Streaming Instead of reacting only after memory pressure occurs, XCL could implement predictive resource streaming. Potential inputs: - Player position and movement direction. - Camera orientation and field of view. - Player velocity. - Nearby world geometry. - Expected world transitions. - Previously accessed streaming assets. - Current upload queue. - Available GPU memory budget. This could allow the engine to prepare high-priority assets before they become visible while avoiding unnecessary preloading. Predictive streaming should be conservative and automatically reduce its workload when memory pressure increases. 4. Intelligent Memory Eviction Implement a resource eviction manager that identifies resources according to: - Last access time. - Visibility. - Distance from the player. - Current GPU usage. - Reload cost. - Resource importance. - Whether the resource is currently referenced by GPU commands. Prefer releasing obsolete, reloadable and low-priority resources. Never release resources that are still being used by in-flight GPU operations. All eviction operations must respect GPU fences and resource lifetime rules. 5. Asynchronous Upload Scheduling World loading can generate substantial upload activity. Introduce a scheduler that: - Controls upload bandwidth. - Limits per-frame upload workloads. - Prioritizes visible and gameplay-critical assets. - Defers low-priority transfers. - Avoids unnecessary CPU/GPU synchronization. - Monitors upload queue saturation. - Coordinates copy queues and graphics queues where supported. This could help prevent large asset transfers from creating noticeable frame-time spikes. 6. CPU and GPU Workload Separation Investigate whether world-loading stalls originate from: - CPU decompression. - Asset parsing. - Texture uploads. - GPU memory allocation. - Resource residency changes. - Shader compilation. - Pipeline-state creation. - Particle-system initialization. - Synchronization waits. These systems should be measured independently. Where supported by the engine architecture, consider parallel asset decompression, background resource preparation, asynchronous shader compilation and non-blocking upload scheduling. Do not assume every loading stall is caused by VRAM pressure. 7. Hardware-Adaptive Optimization Create hardware profiles based on actual available memory budgets rather than fixed GPU model names. For example: 8 GB VRAM - Aggressive speculative-prefetch restrictions. - Smaller texture residency targets. - Conservative upload budgets. - Earlier cache trimming. 12 GB VRAM - Balanced texture residency. - Moderate predictive streaming. - Adaptive cache management. 16 GB VRAM - Larger residency targets when justified by available budget. - More selective predictive prefetching. - Less aggressive cache eviction when memory pressure is low. These should be dynamic policies, not hardcoded assumptions. The system must also account for operating-system GPU reservations, other applications and changing DXGI budgets. 8. Shared Memory and UMA Compatibility Ensure correct behavior across: - Dedicated GPUs. - GPUs using shared system memory. - UMA architectures. - Different DXGI memory segments. - Multi-adapter configurations where supported. Do not assume that shared memory provides the same performance as dedicated VRAM. Memory budgets and usage must be evaluated independently, and the engine must avoid excessive transfers between CPU and GPU memory. 9. World-Loading Stall Diagnostics Develop a dedicated diagnostic mode that captures events around world-loading stalls. Record: - Exact stall start and end timestamps. - GPU memory budget and usage. - Allocation requests and failures. - Upload queue depth. - Resource eviction events. - Fence wait durations. - CPU asset-processing times. - Shader compilation times. - Particle initialization times. - Frame-time spikes. - GPU utilization. - Storage read throughput. This would make it possible to identify the actual bottleneck instead of guessing. 10. Dynamic Quality Management Consider integrating memory pressure with selected rendering-quality parameters. Potential candidates include: - Texture mip residency. - Texture streaming distance. - Shadow-map residency. - Reflection and probe cache residency. - Geometry and asset cache sizes. - Non-essential streaming prefetch. Quality reductions should be gradual, reversible and restricted to resources that can safely tolerate them. Avoid changing unrelated rendering settings without evidence that they contribute to the problem. 11. Benchmarking and Validation Test at least three configurations: 1. Original XCL implementation. 2. Memory diagnostics enabled without adaptive optimization. 3. Full memory-management and streaming optimization enabled. Test multiple VRAM capacities and different hardware configurations. Perform repeated cold-load and warm-load tests using identical routes, settings, drivers and game builds. Measure: - Average FPS. - 1% low FPS. - P50, P95 and P99 frame times. - Number of stalls. - Total stall duration. - Local and non-local memory pressure. - Texture upload throughput. - Eviction activity. - Resource residency. - CPU loading time. - GPU synchronization time. The implementation should only be considered successful when measurable improvements are reproducible without visual corruption, instability or increased loading times. 12. Suggested Development Roadmap Phase 1 — Correctness - Apply the memory-pressure hysteresis correction. - Expand regression tests. - Validate DXGI memory reporting. - Verify safe resource lifetime management. Phase 2 — Diagnostics - Add detailed world-loading telemetry. - Capture upload and eviction events. - Identify reproducible loading stalls. Phase 3 — Streaming - Integrate mip selection with actual texture residency. - Implement asynchronous upload scheduling. - Introduce adaptive cache management. Phase 4 — Predictive Optimization - Introduce player and camera-aware asset prioritization. - Implement conservative predictive prefetch. - Dynamically adapt to available GPU memory. Phase 5 — Hardware Scaling - Validate behavior across 8 GB, 12 GB and 16 GB GPUs. - Test dedicated and shared memory configurations. - Tune policies according to measured hardware capabilities. Phase 6 — Performance Validation - Conduct controlled A/B benchmarks. - Compare frame-time distributions. - Verify visual quality and stability. - Publish reproducible results. Final Objective The broader objective is to investigate whether XCL can benefit from a unified, adaptive GPU memory and world-streaming architecture. Rather than relying on static memory limits or waiting for allocation failures, the engine could continuously evaluate available resources, prioritize important assets, schedule transfers intelligently and respond to memory pressure before it becomes a critical problem. This proposal is intended to give contributors several independently testable implementation paths. Not every feature needs to be implemented simultaneously. The highest priority should be correctness, diagnostics and reproducible evidence, followed by streaming integration and predictive optimization. I believe this approach deserves technical evaluation before the entire proposal is dismissed. The ultimate goal is to make XCL more stable, scalable and efficient across a wider range of PC hardware, particularly GPUs with limited dedicated VRAM. _Originalmente postado por @willvixtor em https://github.com/xcl-dev/xcl/issues/3596#issuecomment-7335040605_
Sign in to join this conversation.
No labels
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.

Reference
xcl-dev/xcl#3683
No description provided.