Intel iGPU: OpSMulExtended by the constants -1, -2 and -32768 returns a wrong high word (agc_driver_vop3_mad_i64) #1246
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-07T19:25:47Z.
agc_driver_vop3_mad_i64fails on an Intel iGPU because the driver returns a wrong high word forOpSMulExtendedwhen 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 signedEmitMulHighwith such a constant gives wrong results on this hardware.Intel Raptor Lake-S Mobile Graphics, Windows driver 32.0.101.6790, current main:
The "neg1" case is
v_mad_i64_i32with an inline -1.EmitMulHigh(SpirvAlu/SpirvAluEmitterMath.cpp) emits it asOpSMulExtended %x %c, where%cisOpBitcastofOpConstant 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-1(constant)-1(from a buffer)-2(constant)-32768(constant)3,65535,-65536,0x7fffffff,INT_MIN(constants)umulExtended(x, 0xffffffffu)(constant)Example:
x = 0x2f45e678,imulExtended(x, -1)gives a high word of0xffffd0b9instead of0xffffffff.A signed high word built from the unsigned product has no mismatches on either device:
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 ofOpSMulExtended. 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.
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.