D3D12.X: encode T# MIN_LOD, resolve wildcard SRV/3D-UAV counts, and validate CreateUnorderedAccessViewAt #3258

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3258 into main
Kalmarv commented 2026-11-29 01:37:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T01:37:46Z.


Fix three D3D12.X texture view descriptor bugs in real.rs: encode SRV ResourceMinLODClamp into RDNA2 T# MIN_LOD (t[1][19:8]), resolve wildcard ArraySize / NumCubes / 3D UAV WSize (u32::MAX) counts safely, and route CreateUnorderedAccessViewAt (#71) through dev_create_uav_checked_inner.

Previously:

  1. srv_tsharp_from_desc left T# MIN_LOD (t[1][19:8], u4.8 fixed-point) at 0 for all SRV dimensions, so direct-DXIL explicit-LOD image_gather4_l / image_gather4_c_l (which clamp against tw1[19:8]) ignored ResourceMinLODClamp.
  2. srv_tsharp_from_desc passed raw ArraySize == u32::MAX through into T# depth (0x1FFE) and evaluated NumCubes.max(1) * 6 without saturation/resolution (overflowing when NumCubes == u32::MAX), while dev_create_uav_x ignored Texture3D UAV WSize and shifted the full resource depth instead of resolving WSize / u32::MAX from FirstWSlice.
  3. dev_create_uav_at_x called dev_create_uav_x directly, bypassing dev_create_uav_checked_inner's sRGB-to-linear format mapping and TYPED_UNORDERED_ACCESS_VIEW capability fallback.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Add encode_tsharp_min_lod and populate t[1][19:8] from ResourceMinLODClamp across all 7 SRV view dimensions that carry it (1D, 1DArray, 2D, 2DArray, 3D, Cube, CubeArray).
    • Resolve ArraySize (0 / u32::MAX) on 1DArray / 2DArray / 2DMSArray SRVs and NumCubes (0 / u32::MAX) on CubeArray SRVs against remaining slices/cubes using resolve_uav_array_size.
    • Resolve Texture3D UAV WSize (0 / u32::MAX and explicit sub-ranges) against ((rd.DepthOrArraySize >> mip).max(1)) and FirstWSlice in dev_create_uav_x.
    • Route dev_create_uav_at_x texture views through dev_create_uav_checked_inner.
    • Add unit test srv_tsharp_encodes_min_lod_and_resolves_wildcard_array_and_cube_counts, WARP child-process test uav_3d_tsharp_wsize_and_uav_at_checked_format, and guarded RTX GPU test gpu_srv_tsharp_min_lod_clamp_controls_image_gather4_l_mip.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (build 26200), rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9 (XCL_DXC_DIR), debug for tests and release for xcl-smoke.
  • Targeted tests (cargo test -p xcl --lib -- srv_tsharp uav_3d_tsharp_wsize_and_uav_at_checked_format uav_companion_srv gpu_a_stencil_uav_by_address_is_a_view_of_the_placed_buffers_twin --nocapture): all 3 new tests failed before the fix; 8 passed, 0 failed after (0 skips on RTX 5070 Ti; verified IMAGE_GATHER4_L honors ResourceMinLODClamp=1.0 -> mip 1 0.75 vs 0.0 -> mip 0 0.25, 3D UAV WSize=3 and WSize=u32::MAX at mip 1, and dev_create_uav_at_x sRGB linearization on WARP).
  • Full workspace (cargo test --workspace -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::): 2602 passed, 0 failed, 49 ignored.
  • SKIPPED GPU tests on this wave32 adapter (26 total across --nocapture workspace baseline): 21 no wave64 (RTX 5070 Ti is wave32), 3 wave32 per-lane #1426 f16/cvt-f16 refusals, 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1).
  • Retail title (ea3b5e4d) 150 s regression run below (0 device removals, 0 crashes, 1918 frames vs 1695 on main, 31029 MB peak commit vs 31546 MB on main).

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 987c02536fb9e70d2229ede7d9f5eeb6244a73e7
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1918 (PresentX 1918)
presents per 2 s (last 3): 11 0 0
device removals: 0
crashes: 0
peak commit: 31029 MB

Not tested

  • AMD RDNA / wave64 GPUs and retail titles that use non-zero ResourceMinLODClamp or sub-range 3D UAV WSize (ea3b5e4d smoke is a regression check; behavior is verified by the unit, WARP, and RTX GPU tests).
  • uma_driver::tests:: (skipped locally due to pre-existing 0x7C10003 exit on NVIDIA) and test_title_runs_and_game_folder_is_untouched.

AI use

  • Antigravity (Gemini) used for root-cause verification, implementation, test authoring, and local verification; all diffs, tests, and smoke outputs reviewed and run locally.
<!-- greyfinch-sync:ivall/xcl:issue:5546491752 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3258). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T01:37:46Z. --- Fix three D3D12.X texture view descriptor bugs in `real.rs`: encode SRV `ResourceMinLODClamp` into RDNA2 `T#` `MIN_LOD` (`t[1][19:8]`), resolve wildcard `ArraySize` / `NumCubes` / 3D UAV `WSize` (`u32::MAX`) counts safely, and route `CreateUnorderedAccessViewAt` (`#71`) through `dev_create_uav_checked_inner`. Previously: 1. `srv_tsharp_from_desc` left `T#` `MIN_LOD` (`t[1][19:8]`, u4.8 fixed-point) at `0` for all SRV dimensions, so direct-DXIL explicit-LOD `image_gather4_l` / `image_gather4_c_l` (which clamp against `tw1[19:8]`) ignored `ResourceMinLODClamp`. 2. `srv_tsharp_from_desc` passed raw `ArraySize == u32::MAX` through into `T#` depth (`0x1FFE`) and evaluated `NumCubes.max(1) * 6` without saturation/resolution (overflowing when `NumCubes == u32::MAX`), while `dev_create_uav_x` ignored `Texture3D` UAV `WSize` and shifted the full resource depth instead of resolving `WSize` / `u32::MAX` from `FirstWSlice`. 3. `dev_create_uav_at_x` called `dev_create_uav_x` directly, bypassing `dev_create_uav_checked_inner`'s sRGB-to-linear format mapping and `TYPED_UNORDERED_ACCESS_VIEW` capability fallback. **What is in it** - `crates/xcl/src/hle/d3d12x/real.rs`: - Add `encode_tsharp_min_lod` and populate `t[1][19:8]` from `ResourceMinLODClamp` across all 7 SRV view dimensions that carry it (`1D`, `1DArray`, `2D`, `2DArray`, `3D`, `Cube`, `CubeArray`). - Resolve `ArraySize` (`0` / `u32::MAX`) on `1DArray` / `2DArray` / `2DMSArray` SRVs and `NumCubes` (`0` / `u32::MAX`) on `CubeArray` SRVs against remaining slices/cubes using `resolve_uav_array_size`. - Resolve `Texture3D` UAV `WSize` (`0` / `u32::MAX` and explicit sub-ranges) against `((rd.DepthOrArraySize >> mip).max(1))` and `FirstWSlice` in `dev_create_uav_x`. - Route `dev_create_uav_at_x` texture views through `dev_create_uav_checked_inner`. - Add unit test `srv_tsharp_encodes_min_lod_and_resolves_wildcard_array_and_cube_counts`, WARP child-process test `uav_3d_tsharp_wsize_and_uav_at_checked_format`, and guarded RTX GPU test `gpu_srv_tsharp_min_lod_clamp_controls_image_gather4_l_mip`. **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (build 26200), `rustc 1.99.0 (b940084d7 2026-09-28)`, DXC 1.9 (`XCL_DXC_DIR`), debug for tests and release for `xcl-smoke`. - Targeted tests (`cargo test -p xcl --lib -- srv_tsharp uav_3d_tsharp_wsize_and_uav_at_checked_format uav_companion_srv gpu_a_stencil_uav_by_address_is_a_view_of_the_placed_buffers_twin --nocapture`): all 3 new tests failed before the fix; 8 passed, 0 failed after (0 skips on RTX 5070 Ti; verified `IMAGE_GATHER4_L` honors `ResourceMinLODClamp=1.0` -> mip 1 `0.75` vs `0.0` -> mip 0 `0.25`, 3D UAV `WSize=3` and `WSize=u32::MAX` at mip 1, and `dev_create_uav_at_x` sRGB linearization on WARP). - Full workspace (`cargo test --workspace -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::`): 2602 passed, 0 failed, 49 ignored. - `SKIPPED` GPU tests on this wave32 adapter (26 total across `--nocapture` workspace baseline): 21 `no wave64` (RTX 5070 Ti is wave32), 3 wave32 per-lane `#1426` f16/cvt-f16 refusals, 2 `no heap windows` (opt-in `XCL_HEAP_WINDOWS=1`). - Retail title (`ea3b5e4d`) 150 s regression run below (`0` device removals, `0` crashes, `1918` frames vs `1695` on `main`, `31029 MB` peak commit vs `31546 MB` on `main`). **Regression run** ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` ``` xcl-smoke v1 commit: 987c02536fb9e70d2229ede7d9f5eeb6244a73e7 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1918 (PresentX 1918) presents per 2 s (last 3): 11 0 0 device removals: 0 crashes: 0 peak commit: 31029 MB ``` **Not tested** - AMD RDNA / wave64 GPUs and retail titles that use non-zero `ResourceMinLODClamp` or sub-range 3D UAV `WSize` (`ea3b5e4d` smoke is a regression check; behavior is verified by the unit, WARP, and RTX GPU tests). - `uma_driver::tests::` (skipped locally due to pre-existing `0x7C10003` exit on NVIDIA) and `test_title_runs_and_game_folder_is_untouched`. **AI use** - Antigravity (Gemini) used for root-cause verification, implementation, test authoring, and local verification; all diffs, tests, and smoke outputs reviewed and run locally.
Foniass commented 2026-12-01 06:35:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:35:17Z.


merge-check
base: d0832e614f
head: 987c02536f
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2893 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (real.rs, +477/-19, ~420 lines of tests). Three default-path changes: every SRV with ResourceMinLODClamp > 0 now carries T# MIN_LOD; 3D UAV T# depth is the resolved WSize and wildcard array / cube counts are resolved; and texture UAVs created by address now get sRGB -> linear and a null view for formats the PC can't use as typed UAVs. Findings: (1) three unrelated fixes in one PR, 477 lines; CONTRIBUTING asks for one per PR. (2) On main only the gather4_l lowering reads MIN_LOD (lower_image.rs ~546-555), comparing the raw clamp with a LOD counted from the view's first mip, while I believe D3D12's ResourceMinLODClamp counts from the resource's mip 0; every test uses MostDetailedMip = 0, so a case with MostDetailedMip > 0 would settle it. (3) No translated shader reads T# depth (get_resinfo uses GetDimensions on the PC view), so the array / cube / 3D-UAV depth changes only affect the T# words; the NumCubes * 6 overflow fix stands (a debug-build panic inside an extern "system" function on main). (4) AI use says "Antigravity (Gemini)", not an exact model; the PR's suite run skipped test_title_runs_and_game_folder_is_untouched and uma_driver::tests:: (stated). Fine: MIN_LOD sits in t[1][19:8] as u4.8, matching the desc::image decode, and NaN / negative / >= 16 clamps saturate correctly; the by-address UAV path now gets the same sRGB mapping and typed-UAV null fallback as CreateUnorderedAccessView, and the calls it changes were invalid PC calls on main; each new test fails without its fix.
performance: 60 s smoke of a retail title, main d0832e61 vs this merge (0ecc628e): 1516 -> 1677 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17167 MB, 0 device removals, 0 crashes.
verdict: not yet: three unrelated fixes in one 477-line PR should be split, and MIN_LOD with MostDetailedMip > 0 is untested against D3D12's clamp convention
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7303043894 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3258#issuecomment-7303043894). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:35:17Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: 987c02536fb9e70d2229ede7d9f5eeb6244a73e7 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2893 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (real.rs, +477/-19, ~420 lines of tests). Three default-path changes: every SRV with `ResourceMinLODClamp > 0` now carries T# MIN_LOD; 3D UAV T# depth is the resolved WSize and wildcard array / cube counts are resolved; and texture UAVs created by address now get sRGB -> linear and a null view for formats the PC can't use as typed UAVs. Findings: (1) three unrelated fixes in one PR, 477 lines; CONTRIBUTING asks for one per PR. (2) On main only the `gather4_l` lowering reads MIN_LOD (lower_image.rs ~546-555), comparing the raw clamp with a LOD counted from the view's first mip, while I believe D3D12's ResourceMinLODClamp counts from the resource's mip 0; every test uses MostDetailedMip = 0, so a case with MostDetailedMip > 0 would settle it. (3) No translated shader reads T# depth (`get_resinfo` uses GetDimensions on the PC view), so the array / cube / 3D-UAV depth changes only affect the T# words; the `NumCubes * 6` overflow fix stands (a debug-build panic inside an extern "system" function on main). (4) AI use says "Antigravity (Gemini)", not an exact model; the PR's suite run skipped `test_title_runs_and_game_folder_is_untouched` and `uma_driver::tests::` (stated). Fine: MIN_LOD sits in t[1][19:8] as u4.8, matching the `desc::image` decode, and NaN / negative / >= 16 clamps saturate correctly; the by-address UAV path now gets the same sRGB mapping and typed-UAV null fallback as CreateUnorderedAccessView, and the calls it changes were invalid PC calls on main; each new test fails without its fix. performance: 60 s smoke of a retail title, main d0832e61 vs this merge (0ecc628e): 1516 -> 1677 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17167 MB, 0 device removals, 0 crashes. verdict: not yet: three unrelated fixes in one 477-line PR should be split, and MIN_LOD with MostDetailedMip > 0 is untested against D3D12's clamp convention hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
Kalmarv commented 2026-12-02 20:50:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:50:06Z.


Closing: split per @Foniass's review. The T# MIN_LOD encoding part is consolidated into #3730 with unit and hardware D3D12 SampleLevel parity coverage for MostDetailedMip > 0 (max(0, clamp - MostDetailedMip)); the unrelated wildcard SRV/3D-UAV count and CreateUnorderedAccessViewAt changes were dropped.

<!-- greyfinch-sync:ivall/xcl:comment:7358391400 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3258#issuecomment-7358391400). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T20:50:06Z. --- Closing: split per @Foniass's review. The `T# MIN_LOD` encoding part is consolidated into #3730 with unit and hardware D3D12 `SampleLevel` parity coverage for `MostDetailedMip > 0` (`max(0, clamp - MostDetailedMip)`); the unrelated wildcard SRV/3D-UAV count and `CreateUnorderedAccessViewAt` changes were dropped.

Pull request closed

Sign in to join this conversation.
No reviewers
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!3258
No description provided.