Intel iGPU: OpSMulExtended by the constants -1, -2 and -32768 returns a wrong high word (agc_driver_vop3_mad_i64) #1246

Closed
opened 2026-10-07 19:25:47 +00:00 by kr4y4 · 1 comment
kr4y4 commented 2026-10-07 19:25:47 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-07T19:25:47Z.


agc_driver_vop3_mad_i64 fails on an Intel iGPU because the driver returns a wrong high word for OpSMulExtended when one operand is the constant -1, -2 or -32768. Integer multiplies are exact in Vulkan, so this is a driver bug. Recording it here because every signed EmitMulHigh with such a constant gives wrong results on this hardware.

Intel Raptor Lake-S Mobile Graphics, Windows driver 32.0.101.6790, current main:

AGC graphics: vop3 mad i64: lane 6 i64 neg1 hi is 0x00008000, expected 0x00000000

The "neg1" case is v_mad_i64_i32 with an inline -1. EmitMulHigh (SpirvAlu/SpirvAluEmitterMath.cpp) emits it as OpSMulExtended %x %c, where %c is OpBitcast of OpConstant 4294967295. The same test passes on an RTX 4070 in the same machine.

Standalone repro with no AnyPS5 code: a GLSL compute shader that takes the high word of imulExtended(x, k) for 32 inputs:

k Intel mismatches RTX 4070
-1 (constant) 21/32 0
-1 (from a buffer) 0/32 0
-2 (constant) 22/32 0
-32768 (constant) 22/32 0
3, 65535, -65536, 0x7fffffff, INT_MIN (constants) 0/32 0
umulExtended(x, 0xffffffffu) (constant) 0/32 0

Example: x = 0x2f45e678, imulExtended(x, -1) gives a high word of 0xffffd0b9 instead of 0xffffffff.

A signed high word built from the unsigned product has no mismatches on either device:

hi = umulhi(a, b) - (a < 0 ? b : 0) - (b < 0 ? a : 0)

That is Hacker's Delight 8-3, and it's exact for all inputs. It costs two compares, two selects and two subtractions per signed mul-high, on every device. If working around the driver here is wanted, I can send it as a PR to EmitMulHigh's signed path, the only emitter of OpSMulExtended. Otherwise this is only a record for anyone testing on Intel.

Found with AI assistance (Claude Code); the results above were measured on the hardware listed.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5750615530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1246). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-07T19:25:47Z. --- `agc_driver_vop3_mad_i64` fails on an Intel iGPU because the driver returns a wrong high word for `OpSMulExtended` when one operand is the constant -1, -2 or -32768. Integer multiplies are exact in Vulkan, so this is a driver bug. Recording it here because every signed `EmitMulHigh` with such a constant gives wrong results on this hardware. Intel Raptor Lake-S Mobile Graphics, Windows driver 32.0.101.6790, current main: ``` AGC graphics: vop3 mad i64: lane 6 i64 neg1 hi is 0x00008000, expected 0x00000000 ``` The "neg1" case is `v_mad_i64_i32` with an inline -1. `EmitMulHigh` (`SpirvAlu/SpirvAluEmitterMath.cpp`) emits it as `OpSMulExtended %x %c`, where `%c` is `OpBitcast` of `OpConstant 4294967295`. The same test passes on an RTX 4070 in the same machine. Standalone repro with no AnyPS5 code: a GLSL compute shader that takes the high word of `imulExtended(x, k)` for 32 inputs: | `k` | Intel mismatches | RTX 4070 | |---|---|---| | `-1` (constant) | 21/32 | 0 | | `-1` (from a buffer) | 0/32 | 0 | | `-2` (constant) | 22/32 | 0 | | `-32768` (constant) | 22/32 | 0 | | `3`, `65535`, `-65536`, `0x7fffffff`, `INT_MIN` (constants) | 0/32 | 0 | | `umulExtended(x, 0xffffffffu)` (constant) | 0/32 | 0 | Example: `x = 0x2f45e678`, `imulExtended(x, -1)` gives a high word of `0xffffd0b9` instead of `0xffffffff`. A signed high word built from the unsigned product has no mismatches on either device: ``` hi = umulhi(a, b) - (a < 0 ? b : 0) - (b < 0 ? a : 0) ``` That is Hacker's Delight 8-3, and it's exact for all inputs. It costs two compares, two selects and two subtractions per signed mul-high, on every device. If working around the driver here is wanted, I can send it as a PR to `EmitMulHigh`'s signed path, the only emitter of `OpSMulExtended`. Otherwise this is only a record for anyone testing on Intel. Found with AI assistance (Claude Code); the results above were measured on the hardware listed.
klosixgaming-arch commented 2026-10-08 11:52:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:52:38Z.


This is a valuable finding about Intel iGPU driver behavior with OpSMulExtended. Based on my review of recent PRs related to the shader recompiler, I can provide some context:

The comprehensive testing showing that only specific constants (-1, -2, -32768) trigger the issue while others work correctly is very useful for understanding the driver bug. The fact that using a buffer instead of a constant avoids the issue suggests this is an optimization in the Intel driver that's producing incorrect results.

The proposed workaround using Hacker's Delight 8-3 (building signed high word from unsigned product) seems reasonable and would be exact for all inputs. This approach has been used successfully in other shader compilers to work around similar hardware/driver issues.

I'd suggest implementing this workaround in EmitMulHigh's signed path, as it would fix the issue on Intel iGPUs without affecting correctness on other devices. The additional ALU operations (two compares, two selects, two subtractions) are likely negligible compared to the overall shader execution time.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059258566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1246#issuecomment-6059258566). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:52:38Z. --- This is a valuable finding about Intel iGPU driver behavior with `OpSMulExtended`. Based on my review of recent PRs related to the shader recompiler, I can provide some context: The comprehensive testing showing that only specific constants (-1, -2, -32768) trigger the issue while others work correctly is very useful for understanding the driver bug. The fact that using a buffer instead of a constant avoids the issue suggests this is an optimization in the Intel driver that's producing incorrect results. The proposed workaround using Hacker's Delight 8-3 (building signed high word from unsigned product) seems reasonable and would be exact for all inputs. This approach has been used successfully in other shader compilers to work around similar hardware/driver issues. I'd suggest implementing this workaround in `EmitMulHigh`'s signed path, as it would fix the issue on Intel iGPUs without affecting correctness on other devices. The additional ALU operations (two compares, two selects, two subtractions) are likely negligible compared to the overall shader execution time.
Sign in to join this conversation.
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
boykopovar/AnyPS5#1246
No description provided.