Recompiler: sign-extend 16-bit SINT lanes in D16 image_store #3279

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3279 into main
Kalmarv commented 2026-11-29 03:27:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T03:27:00Z.


What is in it

IMAGE_STORE with D16 = 1 unpacks two 16-bit lanes per VGPR, but both Direct DXIL (crates/xcl/src/gpu/dxil/lower_image.rs) and HLSL (crates/xcl/src/gpu/recomp/emit.rs) only distinguished float (cls == 0, f16_to_f32) from non-float (zero-extended 16-bit lane). For signed integer formats (SINT, cls == 2, such as R16G16B16A16_SINT or R8G8B8A8_SINT), negative 16-bit signed values were zero-extended to positive 32-bit integers (e.g., -1 as 0x0000FFFF = +65535) and clamped to +32767 / +127 by textureStore.

  • Direct DXIL (crates/xcl/src/gpu/dxil/lower_image.rs): Sign-extend the 16-bit lane with sx16(hp) when cls == 2, matching buffer_store_format_d16 in lower_mem.rs.
  • HLSL (crates/xcl/src/gpu/recomp/emit.rs): Sign-extend the 16-bit lane with (uint)(((int)(hpart << 16)) >> 16) when cls == 2.
  • Tests (crates/xcl/src/gpu/recomp/tests.rs): Added gpu_image_store_d16_sign_extends_sint verifying both Direct DXIL and HLSL on R16G16B16A16_SINT, R8G8B8A8_SINT, R16G16B16A16_UINT, and R16G16B16A16_FLOAT.

Tested

Hardware and 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), DXC 1.9 (dxcompiler 1.9.2609.5, dxil 1.9.2609.5), debug + release builds.

  • cargo test -p xcl --lib -- gpu_image_store_d16_sign_extends_sint gpu_image_load_reads_a_store_of_the_same_dispatch mimg_view_and_sampler_heap_indices_are_guarded --test-threads=1 --nocapture: 3 passed, 0 failed (verified all 64 texels across all 4 formats on RTX 5070 Ti for both Direct DXIL and HLSL).
  • cargo test --workspace -- --test-threads=4: 2609 passed, 0 failed, 49 ignored (26 GPU tests reported SKIPPED: 21 no wave64, 3 #1426 f16 compiler refusals, 2 no heap windows).

Regression run

Baseline (origin/main ancestor f0e8fdd5, 150 s on RTX 5070 Ti):

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

This PR (1ff6d7c2, 150 s on RTX 5070 Ti):

xcl-smoke v1
commit: 1ff6d7c2a85f4170fff92483bc5f79cd4579cdca
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1825 (PresentX 1825)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33332 MB

Not tested

  • image_store_mip (currently unsupported in both translators).
  • Multi-adapter or non-NVIDIA GPUs (AMD/Intel).

AI use

Antigravity (Gemini) assisted with auditing the D16 image-store lowering, implementing the sign-extension fix and GPU test, and formatting this PR description. All code was reviewed, built, and verified locally on RTX 5070 Ti with DXC 1.9, the full workspace test suite, and a 150 s smoke run.

<!-- greyfinch-sync:ivall/xcl:issue:5547176502 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3279). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T03:27:00Z. --- **What is in it** `IMAGE_STORE` with `D16 = 1` unpacks two 16-bit lanes per VGPR, but both Direct DXIL (`crates/xcl/src/gpu/dxil/lower_image.rs`) and HLSL (`crates/xcl/src/gpu/recomp/emit.rs`) only distinguished float (`cls == 0`, `f16_to_f32`) from non-float (zero-extended 16-bit lane). For signed integer formats (`SINT`, `cls == 2`, such as `R16G16B16A16_SINT` or `R8G8B8A8_SINT`), negative 16-bit signed values were zero-extended to positive 32-bit integers (e.g., `-1` as `0x0000FFFF` = `+65535`) and clamped to `+32767` / `+127` by `textureStore`. - **Direct DXIL (`crates/xcl/src/gpu/dxil/lower_image.rs`)**: Sign-extend the 16-bit lane with `sx16(hp)` when `cls == 2`, matching `buffer_store_format_d16` in `lower_mem.rs`. - **HLSL (`crates/xcl/src/gpu/recomp/emit.rs`)**: Sign-extend the 16-bit lane with `(uint)(((int)(hpart << 16)) >> 16)` when `cls == 2`. - **Tests (`crates/xcl/src/gpu/recomp/tests.rs`)**: Added `gpu_image_store_d16_sign_extends_sint` verifying both Direct DXIL and HLSL on `R16G16B16A16_SINT`, `R8G8B8A8_SINT`, `R16G16B16A16_UINT`, and `R16G16B16A16_FLOAT`. **Tested** Hardware and 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)`, DXC 1.9 (`dxcompiler 1.9.2609.5`, `dxil 1.9.2609.5`), debug + release builds. - `cargo test -p xcl --lib -- gpu_image_store_d16_sign_extends_sint gpu_image_load_reads_a_store_of_the_same_dispatch mimg_view_and_sampler_heap_indices_are_guarded --test-threads=1 --nocapture`: 3 passed, 0 failed (verified all 64 texels across all 4 formats on RTX 5070 Ti for both Direct DXIL and HLSL). - `cargo test --workspace -- --test-threads=4`: 2609 passed, 0 failed, 49 ignored (26 GPU tests reported `SKIPPED`: 21 `no wave64`, 3 `#1426` f16 compiler refusals, 2 `no heap windows`). **Regression run** Baseline (`origin/main` ancestor `f0e8fdd5`, 150 s on RTX 5070 Ti): ``` 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 ``` This PR (`1ff6d7c2`, 150 s on RTX 5070 Ti): ``` xcl-smoke v1 commit: 1ff6d7c2a85f4170fff92483bc5f79cd4579cdca gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1825 (PresentX 1825) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 33332 MB ``` **Not tested** - `image_store_mip` (currently unsupported in both translators). - Multi-adapter or non-NVIDIA GPUs (AMD/Intel). **AI use** Antigravity (Gemini) assisted with auditing the D16 image-store lowering, implementing the sign-extension fix and GPU test, and formatting this PR description. All code was reviewed, built, and verified locally on RTX 5070 Ti with DXC 1.9, the full workspace test suite, and a 150 s smoke run.
Kalmarv commented 2026-11-29 03:55:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T03:55:35Z.


Closing in favor of existing open PRs #1194 (HLSL) and #1920 (Direct DXIL), which already cover D16 SINT sign-extension for image_store.

<!-- greyfinch-sync:ivall/xcl:comment:7250343023 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3279#issuecomment-7250343023). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T03:55:35Z. --- Closing in favor of existing open PRs #1194 (HLSL) and #1920 (Direct DXIL), which already cover D16 SINT sign-extension for `image_store`.

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!3279
No description provided.