shader: lower v_cvt_f64_f32, the widening half of the pair #140

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

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


What this adds

#138 lowers v_cvt_f32_f64 (a double narrowed to one dword). This is the other direction — an f32 widened to a double in two VGPRs — and it was refused for the same reason: before #138 nothing in emit had a double at all.

The lowering is the mirror: an i32 (every VALU source is one) bitcasts to f32, widens with fpext, and its bits become an i64 that split64 writes to the pair. That is the shape every 64-bit VALU result already takes (v_lshlrev_b64 and friends).

Three refusals, each masking the next

The validator caught three separate mistakes. Worth recording because a test that only proves "it translated" would have hidden all of them:

1. FPExt only operates on FP — %10 = fpext i32 %9 to double

The source register holds an i32, not an f32. Bitcast first. This is exactly why v_cvt_f32_f16 goes through legacyF16ToF32 (integer in, float out) instead of casting the raw register.

2. Flags must match usage. declared=…4, actual=…0 — the DOUBLES bit

I had removed it after an earlier experiment suggested widening did not need it. That experiment was invalid: it passed only because the fpext was still malformed, so the module never contained a real double. Once the bitcast was right, the bit was required. Both directions need D3D_SHADER_FEATURE_DOUBLES.

A false green that teaches the wrong lesson is worse than a red — this is the second time in this pair of PRs that an error message looked like progress.

3. Flags must match usage. declared=…40000004, actual=…40100004 — flags::INT64

Taking the widened value's bits as an i64 and splitting them is 64-bit integer work. v_lshlrev_b64 sets that flag before its split64 call for the same reason; I had not.

The test checks the value, not the lowering

v_cvt_f64_f32_widens_one_dword_into_two moves the pair's high dword into v0 (which build_cs stores) and compares it against f64::from(f).to_bits() >> 32 for 1.0, 2.0, −1.0 and 0.0, on both the hardware adapter and WARP.

My first version asserted only !shader.dxil.is_empty() — and it passed with a lowering that wrote only the low half. I found that by mutating the code, not by reading it. That is a test that measures nothing, so it is gone.

low half only  ->  FAILED

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. 215 passed; 0 failed; 2 ignored

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

$ cargo xtask policy
asset policy: 172 files ok

215 rather than #138's 214 because two weak tests were removed and one strong one replaced them.

What is not claimed

Neither instruction appears in #132's log. The two shaders that stop on v_cvt_f32_f64 (5dc3b25986622949, 6f225b641c5b0708) contain the narrowing one. Whether they also contain this one, or stop at something else next, I do not know. This completes a pair, it does not fix a reported failure.

Only the conversion pair exists. gfx10/fields.rs names v_add_f64, v_mul_f64, v_min_f64, v_max_f64, v_ldexp_f64 and the compare forms; none of them lower. Now that Types::f64, TypeDef::Double, Cast::FPTrunc and Cast::FPExt all exist, each is a small addition — but each is a claim I have not tested, so none are here.

Relation to #138

Independent branch, same files. #138 adds Double/f64/FPTrunc and the narrowing; this adds FPExt and the widening. This one does not apply to main without #138 (it uses Types::f64), so it should land after it — or I can squash both into one branch if you would rather review the pair together.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6606131683 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/140). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T13:56:39Z. --- ## What this adds #138 lowers `v_cvt_f32_f64` (a `double` narrowed to one dword). This is **the other direction** — an `f32` widened to a `double` in two VGPRs — and it was refused for the same reason: before #138 nothing in `emit` had a `double` at all. The lowering is the mirror: an `i32` (every VALU source is one) bitcasts to `f32`, widens with `fpext`, and its bits become an `i64` that `split64` writes to the pair. That is the shape every 64-bit VALU result already takes (`v_lshlrev_b64` and friends). ## Three refusals, each masking the next The validator caught three separate mistakes. Worth recording because a test that only proves "it translated" would have hidden all of them: **1. `FPExt only operates on FP` — `%10 = fpext i32 %9 to double`** The source register holds an `i32`, not an `f32`. Bitcast first. This is exactly why `v_cvt_f32_f16` goes through `legacyF16ToF32` (integer in, float out) instead of casting the raw register. **2. `Flags must match usage. declared=…4, actual=…0` — the `DOUBLES` bit** I had **removed** it after an earlier experiment suggested widening did not need it. **That experiment was invalid**: it passed only because the `fpext` was still malformed, so the module never contained a real `double`. Once the bitcast was right, the bit was required. **Both directions need `D3D_SHADER_FEATURE_DOUBLES`.** A false green that teaches the wrong lesson is worse than a red — this is the second time in this pair of PRs that an error message looked like progress. **3. `Flags must match usage. declared=…40000004, actual=…40100004` — `flags::INT64`** Taking the widened value's bits as an `i64` and splitting them is 64-bit integer work. `v_lshlrev_b64` sets that flag before its `split64` call for the same reason; I had not. ## The test checks the value, not the lowering `v_cvt_f64_f32_widens_one_dword_into_two` moves the pair's **high** dword into `v0` (which `build_cs` stores) and compares it against `f64::from(f).to_bits() >> 32` for 1.0, 2.0, −1.0 and 0.0, on **both the hardware adapter and WARP**. My first version asserted only `!shader.dxil.is_empty()` — and it **passed with a lowering that wrote only the low half**. I found that by mutating the code, not by reading it. That is a test that measures nothing, so it is gone. ``` low half only -> FAILED ``` ## 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. 215 passed; 0 failed; 2 ignored $ cargo clippy -p victory-shader --all-targets clean $ cargo xtask policy asset policy: 172 files ok ``` 215 rather than #138's 214 because two weak tests were removed and one strong one replaced them. ## What is not claimed **Neither instruction appears in #132's log.** The two shaders that stop on `v_cvt_f32_f64` (`5dc3b25986622949`, `6f225b641c5b0708`) contain the *narrowing* one. Whether they also contain this one, or stop at something else next, I do not know. **This completes a pair, it does not fix a reported failure.** **Only the conversion pair exists.** `gfx10/fields.rs` names `v_add_f64`, `v_mul_f64`, `v_min_f64`, `v_max_f64`, `v_ldexp_f64` and the compare forms; none of them lower. Now that `Types::f64`, `TypeDef::Double`, `Cast::FPTrunc` and `Cast::FPExt` all exist, each is a small addition — but each is a claim I have not tested, so none are here. ## Relation to #138 Independent branch, same files. #138 adds `Double`/`f64`/`FPTrunc` and the narrowing; this adds `FPExt` and the widening. **This one does not apply to `main` without #138** (it uses `Types::f64`), so it should land after it — or I can squash both into one branch if you would rather review the pair together.
upstream-sync closed this pull request 2026-11-25 14:11:03 +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:35Z.


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:7164873061 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/140#issuecomment-7164873061). Originally posted by [xiaotu030202](https://github.com/xiaotu030202) on 2026-11-25T14:10:35Z. --- 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!140
No description provided.