shader: load program constant tables from root SRV and fix raw buffer size CFG #173

Manually merged
github merged 1 commit from gh-pr/173/head into gh-pr/173/base 2026-12-01 20:15:12 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-30 00:01 UTC · original
Androtim:feat/iter170-shader-root-srv-const-table-and-amd-fix → main · +177 −8 · 17 files · 1 commits · merged 2026-11-30 09:15 UTC

Summary

Moves shader program constant tables out of per-shader internal DXIL constant arrays into a deduplicated root SRV (SLOT_CODE_TABLE, t250) and fixes an AMD DXIL raw buffer size query CFG lowering crash:

  1. Root SRV constant table (SLOT_CODE_TABLE, crates/victory-shader + crates/victory-gpu):

    • Adds SLOT_CODE_TABLE = 250 (crates/victory-shader/src/emit/shader.rs) and exposes HostShader::code_table (Vec<u32>).
    • code_dword in crates/victory-shader/src/emit/hdr.rs now loads from root SRV t250 via rawBufferLoad.f32 at the clamped dword * 4 byte offset instead of indexing an internal constant array (avoiding large per-thread Private scratch allocations under dxil-spirv on Vulkan/Proton drivers; opt-out via VICTORY_CODE_TABLE_PRIVATE=1 for debugging).
    • crates/victory-gpu/src/shader_cache.rs appends non-empty code_table words cleanly at the tail of cache records so older cached entries still decode, with unit test coverage for both legacy and extended records.
    • crates/victory-gpu/src/pipeline/host.rs and crates/victory-gpu/src/draw.rs deduplicate each table by content inside pooled 4 MiB upload buffers and bind SLOT_CODE_TABLE across compute and graphics command lists.
  2. AMD DXIL raw buffer size query block split (crates/victory-shader/src/emit/lower.rs):

    • Terminates the active basic block cleanly after branching/handling descriptor_data around raw buffer size queries so the emitted DXIL satisfies strict block-terminator validation.

Verification

  • Policy & Static Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy: asset policy: 311 files ok
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings: pass
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings: pass
  • Targeted Unit Tests (victory-shader + victory-gpu):
    • victory-shader (resource::tests::, emit::lower::tests::, emit::valu_tests::, emit::wave64_tests::, emit::size_tests::, emit::waterfall_tests::): pass
    • victory-gpu (shader_cache::, pipeline::, draw::, including legacy/extended cache round-trip): pass
  • Live GPU Verification (RTX 4060 Ti 8 GB, --release --features diagnostics, DLSS quality, 75s in-world off origin/main 64 MiB texture blocks, dedicated shader cache):
    • Series S (LowVram): 0 crashes, 0 untranslated shaders, 9.0 fps median (max_draws=11700), used_max=6607 MB / budget_min=6836 MB (over=0 MB, room_false=81.2% vs 92.9% on pr170, 55 x 64 MiB blocks = 3520 MB, no_room_reuploads=52000), 16/24 lit frames (luma=107.62, near_black=0.0%, edge_energy=7.99, magenta=0.0%).
    • Series X (1440p, PlayParity, LowVram): 0 crashes, 0 untranslated shaders, 10.8 fps median (max_draws=14300), used_max=6911 MB / budget_min=6868 MB (over=29 MB on unmerged 64 MiB blocks), 18/24 lit frames (luma=97.71, edge_energy=6.72, magenta=0.0%).
    • (Note: on native Windows NVIDIA D3D12, per-thread scratch bloat is minimal so non-pool DXGI usage stays flat, while Linux/Proton dxil-spirv + Vulkan avoids multi-GB SPIR-V Private scratch allocations and AMD avoids the raw buffer size DXIL validation failure; combining with PR #171's 16 MiB pool blocks keeps Series X 1440p within 8 GB budget.)
**@⁠Androtim** on GitHub · 2026-11-30 00:01 UTC · [original](https://github.com/Androtim/MiniVI/pull/173) `Androtim:feat/iter170-shader-root-srv-const-table-and-amd-fix` → `main` · +177 −8 · 17 files · 1 commits · merged 2026-11-30 09:15 UTC ### Summary Moves shader program constant tables out of per-shader internal DXIL constant arrays into a deduplicated root SRV (`SLOT_CODE_TABLE`, `t250`) and fixes an AMD DXIL raw buffer size query CFG lowering crash: 1. **Root SRV constant table (`SLOT_CODE_TABLE`, `crates/victory-shader` + `crates/victory-gpu`):** - Adds `SLOT_CODE_TABLE = 250` (`crates/victory-shader/src/emit/shader.rs`) and exposes `HostShader::code_table` (`Vec<u32>`). - `code_dword` in `crates/victory-shader/src/emit/hdr.rs` now loads from root SRV `t250` via `rawBufferLoad.f32` at the clamped `dword * 4` byte offset instead of indexing an internal constant array (avoiding large per-thread `Private` scratch allocations under `dxil-spirv` on Vulkan/Proton drivers; opt-out via `VICTORY_CODE_TABLE_PRIVATE=1` for debugging). - `crates/victory-gpu/src/shader_cache.rs` appends non-empty `code_table` words cleanly at the tail of cache records so older cached entries still decode, with unit test coverage for both legacy and extended records. - `crates/victory-gpu/src/pipeline/host.rs` and `crates/victory-gpu/src/draw.rs` deduplicate each table by content inside pooled 4 MiB upload buffers and bind `SLOT_CODE_TABLE` across compute and graphics command lists. 2. **AMD DXIL raw buffer size query block split (`crates/victory-shader/src/emit/lower.rs`):** - Terminates the active basic block cleanly after branching/handling `descriptor_data` around raw buffer size queries so the emitted DXIL satisfies strict block-terminator validation. ### Verification - **Policy & Static Checks:** - `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy`: `asset policy: 311 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings`: pass - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings`: pass - **Targeted Unit Tests (`victory-shader` + `victory-gpu`):** - `victory-shader` (`resource::tests::`, `emit::lower::tests::`, `emit::valu_tests::`, `emit::wave64_tests::`, `emit::size_tests::`, `emit::waterfall_tests::`): pass - `victory-gpu` (`shader_cache::`, `pipeline::`, `draw::`, including legacy/extended cache round-trip): pass - **Live GPU Verification (`RTX 4060 Ti 8 GB`, `--release --features diagnostics`, `DLSS quality`, `75s` in-world off `origin/main` `64 MiB` texture blocks, dedicated shader cache):** - **Series S (`LowVram`):** `0` crashes, `0` untranslated shaders, `9.0 fps` median (`max_draws=11700`), `used_max=6607 MB / budget_min=6836 MB` (`over=0 MB`, `room_false=81.2%` vs `92.9%` on `pr170`, `55` x 64 MiB blocks = `3520 MB`, `no_room_reuploads=52000`), `16/24` lit frames (`luma=107.62`, `near_black=0.0%`, `edge_energy=7.99`, `magenta=0.0%`). - **Series X (`1440p`, `PlayParity`, `LowVram`):** `0` crashes, `0` untranslated shaders, `10.8 fps` median (`max_draws=14300`), `used_max=6911 MB / budget_min=6868 MB` (`over=29 MB` on unmerged `64 MiB` blocks), `18/24` lit frames (`luma=97.71`, `edge_energy=6.72`, `magenta=0.0%`). - *(Note: on native Windows NVIDIA D3D12, per-thread scratch bloat is minimal so non-pool DXGI usage stays flat, while Linux/Proton `dxil-spirv` + Vulkan avoids multi-GB `SPIR-V Private` scratch allocations and AMD avoids the raw buffer size DXIL validation failure; combining with PR #171's 16 MiB pool blocks keeps Series X `1440p` within 8 GB budget.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:15:10 +00:00
github manually merged commit fbbb8fb702 into gh-pr/173/base 2026-12-01 20:15:12 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-30 00:03 UTC · original · edited 2026-11-30 01:05 UTC

Automated triage for the maintainers (not an approval).

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

Review Summary

Logic and safety look solid, and CI is passing. This PR touches shader emission, D3D12 root signatures, upload-buffer pooling, and command-list binding, so it warrants a local real-GPU smoke test before merging.

What Was Checked

  • Constant table root SRV (crates/victory-shader/src/emit/shader.rs, hdr.rs, lower.rs, mod.rs):
    • Adds SLOT_CODE_TABLE = 250 and HostShader::code_table: Vec<u32>, with VICTORY_CODE_TABLE_PRIVATE=1 preserving the previous in-shader constant array path.
    • In Lower::code_dword, index is unsigned-clamped (IUGT) to 0..=len - 1 before computing the byte offset (index << 2) for rawBufferLoad.f32, preventing out-of-bounds reads through the root SRV descriptor.
    • SLOT_CODE_TABLE is only registered when words is non-empty, matching the !t.code_table.is_empty() guard in HostPipeline.
  • Host pooling & binding (crates/victory-gpu/src/pipeline/host.rs, draw.rs):
    • code_table_address deduplicates constant tables by content into 256-byte-aligned slices of process-lifetime 4 MiB upload buffers (CHUNK = 4 << 20), keeping ID3D12Resource allocations alive in a static Mutex<Option<Pool>>.
    • SLOT_CODE_TABLE is added to the ours set so it remains a root SRV descriptor (not wrapped in a one-view table under bounded_root_srvs()), matching SetComputeRootShaderResourceView / SetGraphicsRootShaderResourceView in draw.rs.
    • (Minor defensive note) code_table_address assumes words is non-empty (currently guaranteed by its sole caller); an early if words.is_empty() { return Some(0); } or debug assert would prevent a null copy_nonoverlapping if another caller is added later.
  • Shader cache compatibility (crates/victory-gpu/src/shader_cache.rs):
    • Adds "VICTORY_CODE_TABLE_PRIVATE" to build() so toggling the env var does not collide with cached translations.
    • Appends code_table only when non-empty and decodes trailing bytes when present, preserving backwards compatibility with legacy entries (covered by unit tests).
  • AMD DXIL raw buffer size query block split (crates/victory-shader/src/emit/lower.rs):
    • Splits self.cur with an unconditional Term::Br(next) after a raw buffer (props.0 & 0xff == 11) descriptor size query when the size dword is read as a number, keeping the emitted DXIL CFG well-formed.

Verdict

needs-gpu-test — Code and CI look good; run a local real-GPU smoke test (ideally covering both default root-SRV mode and VICTORY_CODE_TABLE_PRIVATE=1, plus AMD/Vulkan-Proton if available) to confirm constant-table rendering and shader compilation stability.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-30 00:03 UTC · [original](https://github.com/Androtim/MiniVI/pull/173#issuecomment-7264931105) · edited 2026-11-30 01:05 UTC <!-- minivi-triage v1 head=fbbb8fb7021ae02988ecb2602d5bcd24a066ca9b verdict=needs-gpu-test ci=passing at=2026-11-30T01:05:45Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic and safety look solid, and CI is passing. This PR touches shader emission, D3D12 root signatures, upload-buffer pooling, and command-list binding, so it warrants a local real-GPU smoke test before merging. ### What Was Checked - **Constant table root SRV (`crates/victory-shader/src/emit/shader.rs`, `hdr.rs`, `lower.rs`, `mod.rs`):** - Adds `SLOT_CODE_TABLE = 250` and `HostShader::code_table: Vec<u32>`, with `VICTORY_CODE_TABLE_PRIVATE=1` preserving the previous in-shader constant array path. - In `Lower::code_dword`, `index` is unsigned-clamped (`IUGT`) to `0..=len - 1` before computing the byte offset (`index << 2`) for `rawBufferLoad.f32`, preventing out-of-bounds reads through the root SRV descriptor. - `SLOT_CODE_TABLE` is only registered when `words` is non-empty, matching the `!t.code_table.is_empty()` guard in `HostPipeline`. - **Host pooling & binding (`crates/victory-gpu/src/pipeline/host.rs`, `draw.rs`):** - `code_table_address` deduplicates constant tables by content into 256-byte-aligned slices of process-lifetime 4 MiB upload buffers (`CHUNK = 4 << 20`), keeping `ID3D12Resource` allocations alive in a `static Mutex<Option<Pool>>`. - `SLOT_CODE_TABLE` is added to the `ours` set so it remains a root SRV descriptor (not wrapped in a one-view table under `bounded_root_srvs()`), matching `SetComputeRootShaderResourceView` / `SetGraphicsRootShaderResourceView` in `draw.rs`. - *(Minor defensive note)* `code_table_address` assumes `words` is non-empty (currently guaranteed by its sole caller); an early `if words.is_empty() { return Some(0); }` or debug assert would prevent a null `copy_nonoverlapping` if another caller is added later. - **Shader cache compatibility (`crates/victory-gpu/src/shader_cache.rs`):** - Adds `"VICTORY_CODE_TABLE_PRIVATE"` to `build()` so toggling the env var does not collide with cached translations. - Appends `code_table` only when non-empty and decodes trailing bytes when present, preserving backwards compatibility with legacy entries (covered by unit tests). - **AMD DXIL raw buffer size query block split (`crates/victory-shader/src/emit/lower.rs`):** - Splits `self.cur` with an unconditional `Term::Br(next)` after a raw buffer (`props.0 & 0xff == 11`) descriptor size query when the size dword is read as a number, keeping the emitted DXIL CFG well-formed. ### Verdict **`needs-gpu-test`** — Code and CI look good; run a local real-GPU smoke test (ideally covering both default root-SRV mode and `VICTORY_CODE_TABLE_PRIVATE=1`, plus AMD/Vulkan-Proton if available) to confirm constant-table rendering and shader compilation stability. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-30 09:15 UTC · original

Hardware-verified on RTX 4060 Ti 8 GB (Series X 1440p -PlayParity, warm shader cache, stacked Wave 7A: #173, #199, #203, #204, #205, #206, #207, #208, #211, #213, #221):

  • FPS: 5.55 fps (vs 5.25 fps Wave 6) | Draws: 11475 | Crashes/DRED: 0
  • Texture Queue: final_waiting=14855 (-11729 vs Wave 6 26584), uploaded=44921
  • VRAM: 7397 / 6862 MB (warm 60 blocks / 6988 MB on first pass), 0 failed bakes
  • Visuals: spotless Jason & lit house (luma=98.64, near_black=0.08%, edge_energy=17.55, magenta=0.0%)

Merging onto main.

**@⁠Androtim** on GitHub · 2026-11-30 09:15 UTC · [original](https://github.com/Androtim/MiniVI/pull/173#issuecomment-7273961060) Hardware-verified on RTX 4060 Ti 8 GB (Series X 1440p `-PlayParity`, warm shader cache, stacked Wave 7A: `#173, #199, #203, #204, #205, #206, #207, #208, #211, #213, #221`): - **FPS:** `5.55 fps` (vs `5.25 fps` Wave 6) | **Draws:** `11475` | **Crashes/DRED:** `0` - **Texture Queue:** `final_waiting=14855` (`-11729` vs Wave 6 `26584`), `uploaded=44921` - **VRAM:** `7397 / 6862 MB` (warm `60` blocks / `6988 MB` on first pass), `0` failed bakes - **Visuals:** spotless Jason & lit house (`luma=98.64`, `near_black=0.08%`, `edge_energy=17.55`, `magenta=0.0%`) Merging onto `main`.
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!173
No description provided.