[pr-fix][shaders] The toward-zero half conversion survives a driver that folds the round trip #347
Loading…
Reference in a new issue
No description provided.
Delete branch "ntsthay/pkrtz-driver-fold"
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?
Not run in the game. A unit test shows the problem on the card.
Contributor role (optional)
What it changes
f16_toward_zeroconverts to a half, converts it back, and steps the half once toward zero when the value it came back as is larger than the input. Onf3840d7,whole_wave_sections_keep_rounding_mode_changesfails on an RTX 4080 under vkd3d-proton:left: 15360,right: 15359. The value 0x3F7FFFFF comes out as 0x3C00, rounded to nearest, when it should be 0x3BFF.I dumped the SPIR-V that vkd3d-proton makes from this shader (
VKD3D_SHADER_DUMP_PATH). It is a faithful translation:PackHalf2x16,UnpackHalf2x16,FAbs,FOrdGreaterThan,ISubandOpSelect. Then I replaced the shader throughVKD3D_SHADER_OVERRIDEwith versions that store the values in between. The packed half is 0x3C00, as it should be. The value that comes back has the bits of the input, 0x3F7FFFFF, which no half has. So the driver's compiler foldsUnpackHalf2x16(PackHalf2x16(x))intox, and the comparison is never true. With a mask of 0xFFFF on the half before it is unpacked, the same shader passes.The change does that in the DXIL:
legacyF16ToF32now readsh & 0xFFFF, which is the same value. It changes nothing on a driver that does not fold the round trip.This reaches
v_cvt_pkrtz_f16_f32and the round-toward-zero mode ofround_half. With the fold, a value above 65504 becomes infinity instead of stopping at 65504.The DXIL of every shader that goes through
f16_toward_zerochanges, so their pipelines are built again once.How it was tested
4e240f7, this branch onf3840d7.whole_wave_sections_keep_rounding_mode_changes: passes; fails onf3840d7with the message above.rtz|pkrtz|toward_zero|round_mode|f16and the 76emit::lower::andemit::bitcode::tests without the card pass.Checklist
main.docs/asset-policy.md.Checked for overlap
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.