shader,gpu: trim shader code tables and guard pixel HDR & compose NaNs #75

Manually merged
github merged 2 commits from gh-pr/75/head into gh-pr/75/base 2026-12-01 20:06:57 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 04:03 UTC · original
Androtim:feat/iter75-hdr-clamp-compose-nan-code-table → main · +200 −64 · 5 files · 2 commits · merged 2026-11-29 14:31 UTC

Summary

Focused extraction of three visual correctness and shader-emission hardening fixes (with mbient.rs omitted so there is zero conflict with PR #69):

  • Pixel HDR output clamp (crates/victory-shader/src/emit/hdr.rs, lower.rs, shader_cache.rs): Adds VICTORY_HDR_CLAMP (default on, =0 disables), clamping pixel float color exports (kind == 16, comp == 9) to [-65024, 65024] and replacing NaNs with 65024.0 via bit-level is_nan_f32 so 16-bit float targets do not turn overflowed highlights into +Inf black blobs or specular glitter. Includes VICTORY_HDR_CLAMP in shader_cache::build().
  • Compositor NaN/Inf saturate (crates/victory-gpu/src/compose.rs): Adds VICTORY_COMPOSE_NAN (default on, =0 disables) with bit-level NaN/Inf detection (clean1 / clean) so saturate(NaN) does not produce black specks during overlay composition.
  • Shader constant code-table trimming (crates/victory-shader/src/emit/hdr.rs, emit/mod.rs): Adds code_table_start and moves code_dword + HDR clamping into the hdr submodule under lower.rs (keeping lower.rs well under the 640 KiB xtask policy file-size cap). Trims leading instruction bytes from emitted DXIL constant tables whenever no fixed-offset load reads below code_end, plus unit test he_code_table_starts_after_the_instructions.

Rig Specs Tested On

  • CPU: Intel Core i7-13700F
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB
  • OS & GPU Driver: Windows 11 Build 26300, NVIDIA driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA: plain --release & --features diagnostics @ $sha
  • Console Profile & Internal Resolution / Scale: series-s — quality (
**@⁠Androtim** on GitHub · 2026-11-29 04:03 UTC · [original](https://github.com/Androtim/MiniVI/pull/75) `Androtim:feat/iter75-hdr-clamp-compose-nan-code-table` → `main` · +200 −64 · 5 files · 2 commits · merged 2026-11-29 14:31 UTC ## Summary Focused extraction of three visual correctness and shader-emission hardening fixes (with mbient.rs omitted so there is zero conflict with PR #69): - **Pixel HDR output clamp (crates/victory-shader/src/emit/hdr.rs, lower.rs, shader_cache.rs):** Adds VICTORY_HDR_CLAMP (default on, =0 disables), clamping pixel float color exports (kind == 16, comp == 9) to [-65024, 65024] and replacing NaNs with 65024.0 via bit-level is_nan_f32 so 16-bit float targets do not turn overflowed highlights into +Inf black blobs or specular glitter. Includes VICTORY_HDR_CLAMP in shader_cache::build(). - **Compositor NaN/Inf saturate (crates/victory-gpu/src/compose.rs):** Adds VICTORY_COMPOSE_NAN (default on, =0 disables) with bit-level NaN/Inf detection (clean1 / clean) so saturate(NaN) does not produce black specks during overlay composition. - **Shader constant code-table trimming (crates/victory-shader/src/emit/hdr.rs, emit/mod.rs):** Adds code_table_start and moves code_dword + HDR clamping into the hdr submodule under lower.rs (keeping lower.rs well under the 640 KiB xtask policy file-size cap). Trims leading instruction bytes from emitted DXIL constant tables whenever no fixed-offset load reads below code_end, plus unit test he_code_table_starts_after_the_instructions. ## Rig Specs Tested On - **CPU:** Intel Core i7-13700F - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB - **OS & GPU Driver:** Windows 11 Build 26300, NVIDIA driver 32.0.16.2124 ## Run Settings & Profile - **Build & Commit SHA:** plain --release & --features diagnostics @ $sha - **Console Profile & Internal Resolution / Scale:** series-s — quality (
Fixes triage feedback on PR #75:
- Move [RootSignature(RS)] directly above float4 ps(V v) : SV_Target instead of clean1(float).
- Extract compile_with() and add root_signature_attaches_to_ps_and_compiles_for_both_clean_modes verifying both CLEAN=0 and CLEAN=1 compile through D3DCompile.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:06:55 +00:00
github manually merged commit 4461f6ed28 into gh-pr/75/base 2026-12-01 20:06:57 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 04:16 UTC · original · edited 2026-11-29 08:03 UTC

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

CI is passing and the logic across all three changes looks solid and well-scoped:

  1. Compositor NaN-safe saturate (crates/victory-gpu/src/compose.rs):

    • clean1 uses (asuint(x) & 0x7FFFFFFFu) > 0x7F800000u to detect NaN (mapping it to 1.0) while letting saturate(x) clamp finite values and ±Inf (+Inf -> 1.0, -Inf -> 0.0), gated by VICTORY_COMPOSE_NAN (default on, 0 disables).
    • root_signature_attaches_to_ps_and_compiles_for_both_clean_modes verifies D3DCompile succeeds for both vs_5_1 and ps_5_1 under CLEAN=0 and CLEAN=1.
  2. Pixel HDR output clamp (crates/victory-shader/src/emit/hdr.rs, lower.rs, shader_cache.rs):

    • Lower::clamp_hdr clamps pixel shader SV_Target float outputs (!mesh && HwStage::Ps && el.kind == 16 && el.comp == 9) to [-65024.0, 65024.0] via FMax/FMin and replaces NaN with 65024.0 via is_nan_f32, gated by VICTORY_HDR_CLAMP (default on, 0 disables).
    • VICTORY_HDR_CLAMP is added to shader_cache::build(), invalidating older unclamped cache entries and keeping toggle combinations distinct.
  3. Constant code-table trimming (crates/victory-shader/src/emit/hdr.rs, emit/mod.rs):

    • code_table_start trims leading instruction bytes from emitted DXIL code constant arrays when no fixed-offset CODE load reads below code_end, covered by the_code_table_starts_after_the_instructions.
    • Moving code_dword and clamp_hdr into emit/hdr.rs keeps lower.rs clean.

Notes for Local GPU Verification

  • Both VICTORY_HDR_CLAMP and VICTORY_COMPOSE_NAN are enabled by default and modify pixel shader DXIL / compositor HLSL output (including mapping NaN to 65024.0 on all float SV_Target outputs, not only 16-bit HDR targets). A real-GPU smoke test is warranted to confirm no visual regressions on G-buffer/UI targets and that shaders with dynamic CODE loads still render identically with trimmed constant tables.

Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 04:16 UTC · [original](https://github.com/Androtim/MiniVI/pull/75#issuecomment-7250558687) · edited 2026-11-29 08:03 UTC <!-- minivi-triage v1 head=4461f6ed286a7ff42e85e3eb75cf6d5d923e6a18 verdict=needs-gpu-test ci=passing at=2026-11-29T08:03:52Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary CI is passing and the logic across all three changes looks solid and well-scoped: 1. **Compositor NaN-safe saturate (`crates/victory-gpu/src/compose.rs`)**: - `clean1` uses `(asuint(x) & 0x7FFFFFFFu) > 0x7F800000u` to detect NaN (mapping it to `1.0`) while letting `saturate(x)` clamp finite values and `±Inf` (`+Inf -> 1.0`, `-Inf -> 0.0`), gated by `VICTORY_COMPOSE_NAN` (default on, `0` disables). - `root_signature_attaches_to_ps_and_compiles_for_both_clean_modes` verifies `D3DCompile` succeeds for both `vs_5_1` and `ps_5_1` under `CLEAN=0` and `CLEAN=1`. 2. **Pixel HDR output clamp (`crates/victory-shader/src/emit/hdr.rs`, `lower.rs`, `shader_cache.rs`)**: - `Lower::clamp_hdr` clamps pixel shader `SV_Target` float outputs (`!mesh && HwStage::Ps && el.kind == 16 && el.comp == 9`) to `[-65024.0, 65024.0]` via `FMax`/`FMin` and replaces NaN with `65024.0` via `is_nan_f32`, gated by `VICTORY_HDR_CLAMP` (default on, `0` disables). - `VICTORY_HDR_CLAMP` is added to `shader_cache::build()`, invalidating older unclamped cache entries and keeping toggle combinations distinct. 3. **Constant code-table trimming (`crates/victory-shader/src/emit/hdr.rs`, `emit/mod.rs`)**: - `code_table_start` trims leading instruction bytes from emitted DXIL `code` constant arrays when no fixed-offset `CODE` load reads below `code_end`, covered by `the_code_table_starts_after_the_instructions`. - Moving `code_dword` and `clamp_hdr` into `emit/hdr.rs` keeps `lower.rs` clean. ### Notes for Local GPU Verification - Both `VICTORY_HDR_CLAMP` and `VICTORY_COMPOSE_NAN` are enabled by default and modify pixel shader DXIL / compositor HLSL output (including mapping NaN to `65024.0` on all float `SV_Target` outputs, not only 16-bit HDR targets). A real-GPU smoke test is warranted to confirm no visual regressions on G-buffer/UI targets and that shaders with dynamic `CODE` loads still render identically with trimmed constant tables. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 06:08 UTC · original

Fixed the HLSL [RootSignature(RS)] placement in crates/victory-gpu/src/compose.rs so the attribute attaches directly to float4 ps(V v) : SV_Target instead of helper clean1(float), extracted compile_with, and added compose::tests::root_signature_attaches_to_ps_and_compiles_for_both_clean_modes covering both CLEAN=0 and CLEAN=1.

Verification Summary

  • cargo xtask policy: asset policy: 302 files ok
  • cargo test -p victory-gpu --lib --features diagnostics --locked -- compose:: --nocapture: 2 passed; 0 failed (root_signature_attaches_to_ps_and_compiles_for_both_clean_modes + live D3D12 composes_scaled_premultiplied_plane_on_gpu readback)
  • cargo test -p victory-shader --lib --locked -- the_code_table_starts_after_the_instructions: 1 passed; 0 failed
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
  • cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings: 0 warnings
  • Plain --release + objdump -p: only Windows system DLLs (zero MinGW runtime DLLs)
  • 75s Series S RTX 4060 Ti 8 GiB in-world verification (pr75-compose-rs-fix): 11/11 gates PASS
    • Median FPS: 12.1 fps (82.5 ms) vs 8.9 fps baseline (+3.20 fps)
    • Crashes / DRED / panics: 0
    • Peak VRAM: 5871 MB / 6947 MB min budget (over=0 MB, room_false=7.7%)
    • Waiting textures: 1954 vs 7121 baseline (-5167, 41947 uploaded)
    • Residency mapped() stalls: 7.18 ms/world_sec
    • Visual PNGs (24): lit=18/24, luma=105.68, near_black=0.0%, edge_energy=7.05, magenta=0.0% (inspected frame-8791.png, frame-8831.png, frame-8863.png: clean UI compose overlay, natural lighting, zero black specks or bloom flares)
**@⁠Androtim** on GitHub · 2026-11-29 06:08 UTC · [original](https://github.com/Androtim/MiniVI/pull/75#issuecomment-7251669176) Fixed the HLSL `[RootSignature(RS)]` placement in `crates/victory-gpu/src/compose.rs` so the attribute attaches directly to `float4 ps(V v) : SV_Target` instead of helper `clean1(float)`, extracted `compile_with`, and added `compose::tests::root_signature_attaches_to_ps_and_compiles_for_both_clean_modes` covering both `CLEAN=0` and `CLEAN=1`. ### Verification Summary - `cargo xtask policy`: `asset policy: 302 files ok` - `cargo test -p victory-gpu --lib --features diagnostics --locked -- compose:: --nocapture`: **2 passed; 0 failed** (`root_signature_attaches_to_ps_and_compiles_for_both_clean_modes` + live D3D12 `composes_scaled_premultiplied_plane_on_gpu` readback) - `cargo test -p victory-shader --lib --locked -- the_code_table_starts_after_the_instructions`: **1 passed; 0 failed** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **0 warnings** - `cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings`: **0 warnings** - Plain `--release` + `objdump -p`: only Windows system DLLs (zero MinGW runtime DLLs) - **75s Series S RTX 4060 Ti 8 GiB in-world verification (`pr75-compose-rs-fix`):** **11/11 gates PASS** - Median FPS: `12.1 fps` (`82.5 ms`) vs `8.9 fps` baseline (**+3.20 fps**) - Crashes / DRED / panics: `0` - Peak VRAM: `5871 MB` / `6947 MB` min budget (`over=0 MB`, `room_false=7.7%`) - Waiting textures: `1954` vs `7121` baseline (`-5167`, `41947` uploaded) - Residency `mapped()` stalls: `7.18 ms/world_sec` - Visual PNGs (`24`): `lit=18/24`, `luma=105.68`, `near_black=0.0%`, `edge_energy=7.05`, `magenta=0.0%` (inspected `frame-8791.png`, `frame-8831.png`, `frame-8863.png`: clean UI compose overlay, natural lighting, zero black specks or bloom flares)
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 07:26 UTC · original

Rebased cleanly onto origin/main (c20129f, new head 4461f6e), keeping both array_calculate_lod_passes_undef_for_slice_coord and the_code_table_starts_after_the_instructions in crates/victory-shader/src/emit/mod.rs, and re-verified everything:

  • cargo xtask policy: 304 files ok
  • cargo test -p victory-shader --lib --locked -- the_code_table_starts_after_the_instructions array_calculate_lod_passes_undef_for_slice_coord: 2 passed; 0 failed
  • cargo test -p victory-gpu --lib --features diagnostics --locked -- compose::: 2 passed; 0 failed
  • cargo clippy --workspace --all-targets -- -D warnings & --features diagnostics: 0 warnings
  • Plain --release + objdump -p: standard Windows system DLLs only
  • Live 75s Series S GPU verification (pr75-rebased-c20129f): 11/11 gates PASS
    • Median FPS: 12.5 fps (79.9 ms, vs 8.9 fps baseline, +3.60 fps)
    • Max VRAM: 5881 MB / 6956 MB budget (over=0 MB)
    • Waiting textures: 2002 (vs 7121 baseline) | mapped() stall rate: 5.94 ms/s
    • Shader translation: untranslated=1 | Crashes / host texture errors: 0 / 0
    • Visually inspected 24 captured frames (frame-8275.png, frame-8315.png, median luma 103.51, edge energy 7.23, 0.0% near-black/magenta): clean daylight rendering with no NaN artifacts.
**@⁠Androtim** on GitHub · 2026-11-29 07:26 UTC · [original](https://github.com/Androtim/MiniVI/pull/75#issuecomment-7252477264) Rebased cleanly onto `origin/main` (`c20129f`, new head `4461f6e`), keeping both `array_calculate_lod_passes_undef_for_slice_coord` and `the_code_table_starts_after_the_instructions` in `crates/victory-shader/src/emit/mod.rs`, and re-verified everything: - `cargo xtask policy`: `304 files ok` - `cargo test -p victory-shader --lib --locked -- the_code_table_starts_after_the_instructions array_calculate_lod_passes_undef_for_slice_coord`: **2 passed; 0 failed** - `cargo test -p victory-gpu --lib --features diagnostics --locked -- compose::`: **2 passed; 0 failed** - `cargo clippy --workspace --all-targets -- -D warnings` & `--features diagnostics`: **0 warnings** - Plain `--release` + `objdump -p`: standard Windows system DLLs only - Live 75s Series S GPU verification (`pr75-rebased-c20129f`): **11/11 gates PASS** - Median FPS: `12.5 fps` (`79.9 ms`, vs `8.9 fps` baseline, `+3.60 fps`) - Max VRAM: `5881 MB` / `6956 MB` budget (`over=0 MB`) - Waiting textures: `2002` (vs `7121` baseline) | `mapped()` stall rate: `5.94 ms/s` - Shader translation: `untranslated=1` | Crashes / host texture errors: `0` / `0` - Visually inspected 24 captured frames (`frame-8275.png`, `frame-8315.png`, median luma `103.51`, edge energy `7.23`, `0.0%` near-black/magenta): clean daylight rendering with no NaN artifacts.
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 14:31 UTC · original

Automated RTX 4060 Ti 8 GB Wave 3 A/B hardware verification passed (playtest/wave3 vs origin/main c7ed150 — 5/5 A/B gates PASS):

  • Hardware cargo test (RTX 4060 Ti): victory-gpu 542 passed, 0 failed (36 ignored); victory-shader 323 passed, 0 Wave 3 regressions (the 3 PSV0 validation failures in emit::rect::tests and emit::barycentric_tests also fail identically on origin/main c7ed150).
  • Automated 45s in-world A/B (scripts/verify-world.ps1, DLSS Quality + golden autosave):
    • FPS: median 10.25 fps vs 10.7 fps baseline (min FPS improved 6.9 vs 4.2, preparing 45.35 ms vs 50.3 ms)
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM: max 5948 MB vs 6073 MB (-125 MB, 0 MB over budget)
    • Texture backlog: final_waiting=5487 vs 7350 (-1863); no room for new ones 38 vs 43
    • Residency stalls: mapped_rate=20.95 ms/s vs 37.22 ms/s (-44%)
    • Visual check: Clean rendered frames (frame-10645.png, frame-10669.png), luma 82.77 vs 23.2, edge energy 2.27 vs 1.81, magenta 0.0%.
**@⁠Androtim** on GitHub · 2026-11-29 14:31 UTC · [original](https://github.com/Androtim/MiniVI/pull/75#issuecomment-7257373280) Automated RTX 4060 Ti 8 GB Wave 3 A/B hardware verification passed (`playtest/wave3` vs `origin/main` `c7ed150` — **5/5 A/B gates PASS**): - **Hardware `cargo test` (RTX 4060 Ti):** `victory-gpu` **542 passed, 0 failed** (36 ignored); `victory-shader` **323 passed, 0 Wave 3 regressions** (the 3 PSV0 validation failures in `emit::rect::tests` and `emit::barycentric_tests` also fail identically on `origin/main` `c7ed150`). - **Automated 45s in-world A/B (`scripts/verify-world.ps1`, DLSS Quality + golden autosave):** - **FPS:** median `10.25 fps` vs `10.7 fps` baseline (min FPS improved **`6.9`** vs `4.2`, preparing **`45.35 ms`** vs `50.3 ms`) - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM:** max **`5948 MB`** vs `6073 MB` (**-125 MB**, `0 MB` over budget) - **Texture backlog:** `final_waiting=5487` vs `7350` (**-1863**); `no room for new ones` `38` vs `43` - **Residency stalls:** `mapped_rate=20.95 ms/s` vs `37.22 ms/s` (**-44%**) - **Visual check:** Clean rendered frames (`frame-10645.png`, `frame-10669.png`), luma `82.77` vs `23.2`, edge energy `2.27` vs `1.81`, magenta `0.0%`.
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/Androtim--MiniVI!75
No description provided.