shader: lower v_cvt_f32_f64, the first double in the emitter #138

Closed
xiaotu030202 wants to merge 1 commit from upstream-pr/138 into main
xiaotu030202 commented 2026-11-25 14:11:02 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by xiaotu030202 on 2026-11-25T13:47:11Z.


What this fixes

v_cvt_f32_f64 was refused outright — not because the instruction is hard, but because nothing in emit touched a double at all. #132's log has two shaders that stop there:

compute 5dc3b25986622949: v_cvt_f32_f64 is not supported
compute 6f225b641c5b0708: v_cvt_f32_f64 is not supported

Three things were missing, and all three had to exist before the instruction could:

missing now
TypeDef::Double — LLVM type 4 could not be written added, record(4)
Types.f64 added, plus Module::double()
Cast::FPTrunc — the enum jumped SiToFp = 6 → Bitcast = 11 added as 7

The lowering is three steps: the console's double arrives as an i64 (two VGPRs, through the existing src64), bitcasts to f64, narrows with fptrunc. That is what DXC emits for (float)d.

The feature flag, and why the error message was the wrong thing to read

My first attempt used a double without declaring it. The validator was precise:

error: Flags must match usage.
note: Flags declared=1074790400, actual=1074790404

The delta is 0x4 — and 0x4 is not the answer. It is the difference the validator computed between two values, not the bit to set. d3dcommon.h has the real one:

#define D3D_SHADER_FEATURE_DOUBLES   0x00001

0x1, the first entry of the enum. Every other flag already in this file matches that enum exactly — STENCIL_REF 0x200, TYPED_UAV_LOADS 0x800, WAVE_OPS 0x4000, INT64_OPS 0x8000, BARYCENTRICS 0x20000 — which is what made the header the right authority rather than the diff.

Setting 0x4 passed the usage check and failed the next one:

error: Container part 'Feature Info' does not match expected for module.

Two wrong answers that each look like progress is exactly why I went to the header instead of bisecting.

Tests, checked in both directions

  • v_cvt_f32_f64_narrows_a_double_to_one_dword — a compute shader holding the instruction, lowered; build_cs runs dxil.dll over the container, so a wrong one is a failure, not a skip.
  • v_cvt_f32_f64_takes_a_scalar_pair_too — the same with an SGPR pair rather than a VGPR pair, which is the other way a title reaches it.
features |= 0x1  ->  features |= 0x0
  FAILED  "Container part 'Feature Info' does not match expected for module"

Verification

Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK 10.0.26100.0, VICTORY_DXIL set. No game files.

$ cargo test -p victory-shader --lib -- --test-threads=1
test result: ok. 214 passed; 0 failed; 2 ignored      (212 before)

$ cargo clippy -p victory-shader --all-targets
clean

$ cargo xtask policy
asset policy: 172 files ok

What is not claimed

v_cvt_f64_f32 is still refused — the same gap in the other direction. It needs fpext (which I added to Cast and then removed, since nothing constructed it) and a 64-bit destination register pair, which is a different code path from the one this PR touches. Doing one and leaving its mirror refused is deliberate: half a feature that says so beats half a feature that does not.

I have not seen those two shaders translate. What is established: the instruction lowers, the DXIL validates, 214 tests pass. Whether the two now go through, or stop at the next thing they contain, is what victory translate --list over shaders.rpf would say — and that needs game files.

If someone can run the census on this branch, the two hashes either disappear from the refusal list or name the next reason, and either answer is worth having.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6605943218 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/138). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T13:47:11Z. --- ## What this fixes `v_cvt_f32_f64` was refused outright — **not** because the instruction is hard, but because nothing in `emit` touched a `double` at all. #132's log has two shaders that stop there: ``` compute 5dc3b25986622949: v_cvt_f32_f64 is not supported compute 6f225b641c5b0708: v_cvt_f32_f64 is not supported ``` Three things were missing, and all three had to exist before the instruction could: | missing | now | |---|---| | `TypeDef::Double` — LLVM type `4` could not be written | added, `record(4)` | | `Types.f64` | added, plus `Module::double()` | | `Cast::FPTrunc` — the enum jumped `SiToFp = 6` → `Bitcast = 11` | added as `7` | The lowering is three steps: the console's double arrives as an `i64` (two VGPRs, through the existing `src64`), bitcasts to `f64`, narrows with `fptrunc`. That is what DXC emits for `(float)d`. ## The feature flag, and why the error message was the wrong thing to read My first attempt used a `double` without declaring it. The validator was precise: ``` error: Flags must match usage. note: Flags declared=1074790400, actual=1074790404 ``` The delta is `0x4` — **and `0x4` is not the answer.** It is the difference the validator computed between two values, not the bit to set. `d3dcommon.h` has the real one: ```c #define D3D_SHADER_FEATURE_DOUBLES 0x00001 ``` `0x1`, the *first* entry of the enum. Every other flag already in this file matches that enum exactly — `STENCIL_REF 0x200`, `TYPED_UAV_LOADS 0x800`, `WAVE_OPS 0x4000`, `INT64_OPS 0x8000`, `BARYCENTRICS 0x20000` — which is what made the header the right authority rather than the diff. Setting `0x4` passed the usage check and failed the next one: ``` error: Container part 'Feature Info' does not match expected for module. ``` Two wrong answers that each look like progress is exactly why I went to the header instead of bisecting. ## Tests, checked in both directions - **`v_cvt_f32_f64_narrows_a_double_to_one_dword`** — a compute shader holding the instruction, lowered; `build_cs` runs `dxil.dll` over the container, so a wrong one is a failure, not a skip. - **`v_cvt_f32_f64_takes_a_scalar_pair_too`** — the same with an SGPR pair rather than a VGPR pair, which is the other way a title reaches it. ``` features |= 0x1 -> features |= 0x0 FAILED "Container part 'Feature Info' does not match expected for module" ``` ## Verification Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK 10.0.26100.0, `VICTORY_DXIL` set. **No game files.** ``` $ cargo test -p victory-shader --lib -- --test-threads=1 test result: ok. 214 passed; 0 failed; 2 ignored (212 before) $ cargo clippy -p victory-shader --all-targets clean $ cargo xtask policy asset policy: 172 files ok ``` ## What is not claimed **`v_cvt_f64_f32` is still refused** — the same gap in the other direction. It needs `fpext` (which I added to `Cast` and then removed, since nothing constructed it) *and* a 64-bit destination register pair, which is a different code path from the one this PR touches. Doing one and leaving its mirror refused is deliberate: half a feature that says so beats half a feature that does not. **I have not seen those two shaders translate.** What is established: the instruction lowers, the DXIL validates, 214 tests pass. Whether the two now go through, or stop at the next thing they contain, is what `victory translate --list` over `shaders.rpf` would say — and that needs game files. If someone can run the census on this branch, the two hashes either disappear from the refusal list or name the next reason, and either answer is worth having.
upstream-sync closed this pull request 2026-11-25 14:11:02 +00:00
xiaotu030202 commented 2026-11-25 14:11:06 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by xiaotu030202 on 2026-11-25T14:10:31Z.


Superseded by #142, which is all three of these in one branch.

They were split because each was verifiable on its own, but two of them cannot apply to main without the first — so reviewing them apart means reviewing a branch that does not build. #142 has the same content with one description and one diff.

Closing rather than leaving three open PRs for one feature.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7164871405 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/138#issuecomment-7164871405). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T14:10:31Z. --- Superseded by #142, which is all three of these in one branch. They were split because each was verifiable on its own, but two of them cannot apply to `main` without the first — so reviewing them apart means reviewing a branch that does not build. #142 has the same content with one description and one diff. Closing rather than leaving three open PRs for one feature.

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
Zettrox/ztrx!138
No description provided.