Skip to content

fix: renderer device leak, target rebuilds from window size, planar probe culls, golden tests on Windows - #242

Open
proggeramlug wants to merge 5 commits into
mainfrom
fix/windows-output-scale-renderer-leak
Open

proggeramlug wants to merge 5 commits into
mainfrom
fix/windows-output-scale-renderer-leak

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Found while bringing the shooter up on Windows (Radeon 760M iGPU, 4K panel).

Renderer memory leak (all platforms). MaterialSystem::new mem::forget-ed a stub depth texture, two views and the comparison sampler. Each wgpu handle holds the device, so no renderer's device (or its memory heaps) was ever freed: about 580 MB per renderer on DX12 and on Vulkan. A game builds one renderer and doesn't notice; the golden suite builds one per test and ran out of GPU memory after about 30 (41 failures in a serial Windows run, now 2, see below). New test dropping_a_renderer_releases_its_textures fails without the fix (82 KB and 3 views left alive) and passes with it.

Render-target rebuilds from the window size. main already fixed set_render_scale compounding the output scale (I had found the same bug; the new test output_scale_does_not_compound_through_render_scale_changes covers it and fails on the old code). set_temporal_upscale and rebuild_render_targets read native_width/height directly, which is 0 before the first resize; they now use native_size().

Planar probes. In the shooter the water probe costs 5 ms of a 27 ms fight frame on the 760M, nearly all of it vertex work: a 256-pixel probe saves only 0.5 ms. Two culls that leave the picture unchanged:

  • A probe renders only on frames where a draw whose material samples it is inside the main frustum.
  • A model whose bounding sphere covers under 3 probe pixels is not drawn into the probe.

Measured honestly: in the shooter's fight harness the river is almost always in view, so the first cull gains nothing there; the second gains about 0.4 ms. They pay off when the water is off-screen. The real fix for that scene is LODs for the trees.

Golden tests on Windows. wgpu-hal 29's Vulkan backend never counts a created texture but subtracts on every destroy, so hal.textures reads negative (-76). Vulkan is the default pick on Windows, so the static-ultra memory test failed its precondition; it now accepts live texture memory, which is counted on every backend and still catches a leaked texture. WGPU_BACKEND=vulkan|dx12 now narrows try_engine's adapter pick.

Results (Windows, Radeon 760M):

  • render_targets: 6 of 6.
  • golden_render --test-threads=1: 87 passed, 2 failed. The two failures, camera_motion_sequence_bounds_ghosting_flicker_and_cut_residue and ssgi_hiz_immediate_scene_produces_finite_indirect_radiance, also fail on main without this change, on DX12 and Vulkan, each run on its own.
  • tools/check-file-lines.js: 0 failures.

Ralph Kuepper added 4 commits November 16, 2026 12:52
MaterialSystem::new mem::forget-ed a stub depth texture, two of its views and
the comparison sampler, on the theory that the bind group keeps them alive.
It does - without the forget. A forgotten wgpu handle never releases its
reference, and every handle holds the device, so no renderer's device (or any
memory heap it had allocated) was ever freed: ~580 MB per renderer on a Radeon
760M, on DX12 and Vulkan alike. The golden suite, which builds a renderer per
test, ran out of GPU memory after ~30 (41 failures in a serial run on
Windows). Measured with a create/drop loop: private bytes now stay flat.
…e and renderer teardown

set_temporal_upscale and rebuild_render_targets read native_width/height
directly, which is 0 before the platform's first resize, and resize(0, 0)
configures a 1x1 surface; they use native_size() now, like set_render_scale.

Tests: the output scale stays applied once through render-scale and
temporal-upscale changes (it compounded before set_render_scale's fix: a 4K
window at 0.75 ended at 1215x683 after four dynamic-resolution steps), and
dropping a renderer leaves no texture memory or views alive (82 KB and 3 views
before the previous commit).
… show

A planar probe redraws the scene mirrored, almost all of it vertex work: in
the shooter on a Radeon 760M the water probe cost 5 ms of a 27 ms fight frame
(40.6 fps without it, 31.7 with). Two culls that cannot change the picture:
- a probe renders only on frames where a draw whose material samples it is
  inside the main frustum (instanced or unbounded draws count as visible);
- a cached model or scene node whose bounding sphere covers under 3 probe
  pixels, seen from the mirrored eye, is not drawn into the probe.
…kan's texture count

wgpu-hal 29's Vulkan backend never counts a created texture (only
add_raw_texture does) but subtracts on every destroy, so hal.textures reads
negative there (-76), and Vulkan is the default pick on Windows: the
static-ultra memory test failed its 'counters enabled' precondition. It now
accepts live texture memory instead; texture memory and views are counted
both ways on every backend and still catch a leaked texture in the growth
check. WGPU_BACKEND=vulkan|dx12 narrows try_engine's adapter pick.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0adec86f-fde1-42d0-b200-6f0f551b4ff4
Commits

Reviewing files that changed from the base of the PR and between 9c23420 and 3134412.

Files selected for processing: 7

  • native/shared/src/renderer/material_system.rs
  • native/shared/src/renderer/planar_pass.rs
  • native/shared/src/renderer/quality_preset.rs
  • native/shared/src/renderer/shaders/post.rs
  • native/shared/tests/golden_render.rs
  • native/shared/tests/golden_render/lighting_upload.rs
  • native/shared/tests/render_targets.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

With a current weight of 1 (a reset, a camera cut, the first frames) the
resolve still loaded the history texture's provenance, and its stale
confidence fed the reconstruction-detail term added to the output: the frame
after reset_temporal_history() differed from a fresh render of the same pose
by one 8-bit level. History is now read only when it can be used (the
history_usable condition the blend already applies). Found by
temporal_history::camera_motion_sequence_bounds_ghosting_flicker_and_cut_residue,
which failed on DX12 and Vulkan on a Radeon 760M and now passes on both;
golden_render 88/89 on both backends (the remaining failure,
ssgi_hiz_immediate_scene_produces_finite_indirect_radiance, is SSIM 0.99844
against 0.9985 and fails on main too).
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Added a TAA fix (fix(taa): do not read history the frame has no use for): after a camera cut, history confidence that was no longer valid still fed the reconstruction-detail term, which left a one-level residue of the old image. The camera-cut golden test now passes on DX12 and Vulkan; golden_render 88/89 on both. The remaining failure is SSGI stability at SSIM 0.99844 against 0.9985 on this AMD iGPU, and it fails on main too.

proggeramlug pushed a commit to Bloom-Engine/shooter that referenced this pull request Nov 16, 2026
… profile

- New video row WATER REFLECTIONS (settings key waterReflections, default on,
  off in the LOW preset). It links or unlinks the river's planar probe from the
  water material; the engine (Bloom-Engine/engine#242) renders a probe only
  when something on screen samples it, so off costs nothing and the water
  reflects the sky.
- First-run calibration: under 30 fps on the title screen it also applies the
  LOW preset with the sun's shadows off (applySlowGpuProfile).

Radeon 760M, 4K panel, fresh install: the title measured 27.6 fps at 0.75 and
chose output 0.5, LOW, shadows off, water reflections off; a fight then runs
57.9 fps mean (worst window 46.2), against 29 on HIGH. tools/check.sh --bot:
static, boot, AI, menus 22/22, whole run won.
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.

1 participant