Shaders: RDNA2 VALU instructions lowered or made exact as the hardware measures them (v_mad_u16, v_cvt_pknorm, v_lerp_u8, v_ldexp/frexp, flr/rpi NaN) #4233
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4233"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by KruIN689 on 2026-11-30T17:39:29Z.
Fixes #
What it changes
RDNA2 VALU instructions that did not translate, or translated with results the hardware does not give. All in
crates/victory-shader/src/emit/lower.rs.lower: Unsupported { what: "v_mad_u16" }and so on):v_mad_u16/i16,v_add/sub_nc_i16,v_min3/max3/med3_i16/u16;v_cvt_pknorm_i16/u16_f32, rounded from the exact product as the hardware does, not after an f32 multiply;v_cvt_pk_u16_u32/i16_i32;v_lerp_u8;v_mad_u32_u16/i32_i16,v_add/sub_nc_i32;v_ldexp_f32,v_frexp_mant_f32,v_frexp_exp_i32_f32, with denormals scaled into normals and a NaN kept quiet with its payload.v_cvt_flr/rpi_i32_f32: a NaN saturates by its sign, as an infinity does. The current lowering returns 0, which is whatv_cvt_i32_f32gives, not these two.rpiadds the half without rounding the sum first: 0.49999997 → 0, and 8388609 stays 8388609.VICTORY_F16_NEAREST: narrows on the bits, so the high half is kept.v_ldexp_f32andv_mad_u32_u16 | v_mad_i32_i16arms were unreachable behind the ones above and are removed.How it was tested
84bd61e2, the 6 tests below fail:lower: Unsupportedforv_mad_u16,v_cvt_pknorm_i16_f32andv_lerp_u8;v_cvt_flr_i32_f32(NaN) = 0, where 0x7fffffff is wanted;v_ldexp_f32(NaN, 3) = 0x7fffffff, where 0x7fc00000 is wanted;F16_NEARESTgives 0x7fff, where 0x7e00 is wanted.cargo test -p victory-shader --lib -- valu_tests cost::: 68 passed, 0 failed, 2 ignored.valu_tests.rscompare each instruction against tables measured on an RDNA2 GPU (gfx1036, the hw-oracle), on the card and on WARP.cargo testfor the crate it touches: yes, the tests above. Two checks fail, as they do on main84bd61e2before this change:cargo clippy -p victory-shader --all-targets -- -D warningsstops atfield loop_caps is never read;cargo xtask policyflags the 560-character hex run innative.rs'sloose_metadata_reads_version_0x403test.Checked for overlap
These come from our fork (Lyrnc/palmlight), where they have been in daily play since 2026-11-29.
AI use: Claude Code (Claude Opus 5.5) ported the lowerings onto today's main, ran the tests and wrote this text. The hardware tables were measured on an RDNA2 GPU. Posted with the account owner's approval. Label: [pr-fix].
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by VibeCodeGuy on 2026-11-30T22:28:41Z.
Offline corpus check (every shader container in a v1.0.2.1 dump: 25,699 unique programs),
maine1251c31againstmain+ this PR atcb133452.maintoo (oversized mesh outputs).The 1664 changed programs by family
MSNC_VS_PedTransformSkinAlphaMSNC_VS_MirrorReflectionPedTransformSkinMSNC_VS_PedTransformSkinTransmissionAlphaMSNC_VS_PedTransformSkin_DecalsMSNC_VS_PedTransformSkinAlpha_DecalsMSNC_VS_PedTransformSkinTransmission_DecalsMS_VS_TransformPS_PedTextured_Eight_AlphaPS_PedAlphaPrepassPS_PedAlphaPrepass_DecalsPS_StudioPedTextured_EightMSNC_VS_MirrorReflectionTransformSkinDMSNC_VS_MirrorReflectionTransformSkinDecalsDMSNC_VS_TransformSkinDVS_TransformSkin_VfxVBuffer_AlphaClipMSNC_VS_PedTransformSkinMS_VS_MirrorReflectionTransformMS_VS_TransformEntityMaskMS_VS_TransformFireMSNC_VS_MirrorReflectionTransformSkinMSNC_VS_TransformSkinMSNC_VS_PedTransformSkinD_PackedMS_VS_TransformTerrainNormalTintMS_VS_TransformAlphaPrepassMS_VS_TransformTransmissionMSNC_VS_TransformSkinTransmissionMSNC_VS_TransformSkin_AlphaPrepassMSNC_VS_PedTransformSkinFireMSNC_VS_PedTransformSkinTransmissionFireMS_VS_MirrorReflectionTransformDMS_VS_MirrorReflectionTransformDecalsDMS_VS_TransformDPS_MirrorReflectionTexturedDeferredAlphaClipNCPS_MirrorReflectionTexturedDeferredPS_PropVehicleDeferredPS_TexturedDeferredAlphaClipNCPS_TexturedDeferredPS_VehicleLiveryOffComplexDirtOffDeferredPS_VehicleLiveryOffComplexDirtOffDetailMapsOffDeferredPS_VehicleLiveryOffDetailMapsOffComplexDirtOffStickersOffFlakesOffDeferredPS_VehicleLiveryOffDetailMapsOffDeferredPS_VehicleLiveryOffOnlyDeferredPS_VehicleLiveryOnDetailMapsOffDeferredPS_VehicleVariationDeferredVS_Transform_VfxVBuffer_AlphaClipVS_Transform_VfxVBufferPS_PropVehicleDeferred_NoDeformPS_TexturedDeferredNoDeformationPS_VehicleLiveryOffComplexDirtOffDeferred_NoDeformPS_VehicleLiveryOffComplexDirtOffDetailMapsOffDeferred_NoDeformPS_VehicleLiveryOffDetailMapsOffComplexDirtOffStickersOffFlakesOffDeferred_NoDeformPS_VehicleLiveryOffDetailMapsOffDeferred_NoDeformPS_VehicleLiveryOffOnlyDeferred_NoDeformPS_VehicleLiveryOnDetailMapsOffDeferred_NoDeformPS_VehicleVariationDeferred_NoDeformbillboard_nobump:CS_RaytracingResolveprop_batch:CS_RaytracingResolveprop_batch_anisotropy:CS_RaytracingResolveprop_batch_anisotropy_dirt:CS_RaytracingResolveprop_batch_cutout_hbb:CS_RaytracingResolveprop_batch_dirt:CS_RaytracingResolveprop_batch_dirt_cutout:CS_RaytracingResolveprop_batch_dirt_plus_normal:CS_RaytracingResolveprop_batch_dirt_pxm:CS_RaytracingResolveprop_batch_dirt_um_wind:CS_RaytracingResolveprop_batch_doublesided_um_wind:CS_RaytracingResolveprop_batch_lod:CS_RaytracingResolveprop_batch_pxm:CS_RaytracingResolveprop_batch_retroreflection:CS_RaytracingResolveprop_batch_retroreflection_dirt:CS_RaytracingResolveprop_batch_slod:CS_RaytracingResolveprop_batch_slod_regiontint:CS_RaytracingResolveprop_batch_slod_regiontint_cpv:CS_RaytracingResolveprop_batch_standard_fabric:CS_RaytracingResolveprop_batch_standard_fabric_dirt:CS_RaytracingResolveprop_batch_um_wind:CS_RaytracingResolvestandard_emissive_layer_batch:CS_RaytracingResolvestandard_emissive_layer_batch_underwater:CS_RaytracingResolvestandard_emissive_layer_wind_batch:CS_RaytracingResolvestandard_vehicle_2lyr_licenseplate:CS_RaytracingResolvetrunk:CS_RaytracingResolvetrunk_um_wind:CS_RaytracingResolvetrunk_underwater:CS_RaytracingResolvetrunk_wind:CS_RaytracingResolveMSNC_VS_TransformSkinTransmissionFireMSNC_VS_TransformSkin_FireMSNC_VS_TransformSkin_Fire_AlphaPrepassMSR_VS_MirrorReflectionTransformSkinMSR_VS_TransformSkinTransmissionMSR_VS_TransformSkin_AlphaPrepassMSR_VS_TransformSkinMST_DS_Transform_AddWaterSurfaceDeltaMS_VS_MirrorReflectionTransformSkinMS_VS_TransformSkinTransmissionMS_VS_TransformSkin_AlphaPrepassMS_VS_TransformSkinMS_VS_TransformSpatterAlphaPrepassMS_VS_TransformTransmissionFireMS_VS_TransformTransmissionSpatterMS_VS_Transform_FireMS_VS_Transform_Fire_AlphaPrepassPS_AlphaTransmissionSpatterPS_AlphaTransmissionSpatter_FirePS_AlphaTransmissionPS_AlphaTransmission_Firegrass_batch_floating_veg_tess:MSTS_VS_Transform_AddWaterSurfaceDeltastandard_emissive_animated_3lyr_inst:CS_RaytracingResolvestandard_emissive_animated_inst:CS_RaytracingResolvestandard_emissive_layer_inst:CS_RaytracingResolvestandard_emissive_layer_pxm_inst:CS_RaytracingResolvestandard_emissive_layer_wind_inst:CS_RaytracingResolvestandard_vehicle_2lyr:CS_RaytracingResolvestandard_vehicle_2lyr_clearcoat:CS_RaytracingResolvestandard_vehicle_2lyr_decal:CS_RaytracingResolvestandard_vehicle_2lyr_decal_prop:CS_RaytracingResolvestandard_vehicle_2lyr_decal_secmo:CS_RaytracingResolvestandard_vehicle_2lyr_emissive_brakedisc_inst:CS_RaytracingResolvestandard_vehicle_2lyr_prop:CS_RaytracingResolvestandard_vehicle_2lyr_prop_secmo:CS_RaytracingResolvestandard_vehicle_2lyr_reflector:CS_RaytracingResolvestandard_vehicle_2lyr_reflector_prop:CS_RaytracingResolvestandard_vehicle_2lyr_secmo:CS_RaytracingResolvestandard_vehicle_2lyr_signs:CS_RaytracingResolvestandard_vehicle_2lyr_wheel_inst:CS_RaytracingResolvestandard_vehicle_interior_2lyr:CS_RaytracingResolvestandard_vehicle_interior_2lyr_decal:CS_RaytracingResolvestandard_vehicle_wheel_2lyr:CS_RaytracingResolvetrunk_vehicle_clip:CS_RaytracingResolveGpuParticleUpdate:CS_DrawBatchMS_VS_TransformSpatter_Fire_AlphaPrepassMS_VS_TransformTransmissionSpatterFirePS_EntityFireResolveEmissivePS_MIRROR_PBR_MATERIAL_ANISOTROPYPS_MIRROR_PBR_MATERIAL_BLURTRANSMISSIONPS_MIRROR_PBR_MATERIAL_CLEARCOATPS_MIRROR_PBR_MATERIAL_CLEARCOAT_ANISOTROPYPS_MIRROR_PBR_MATERIAL_CLEARCOAT_DIFFRACTIONPS_MIRROR_PBR_MATERIAL_CLEARCOAT_GLINTSPS_MIRROR_PBR_MATERIAL_CLEARCOAT_IRIDESCENCEPS_MIRROR_PBR_MATERIAL_CLEARCOAT_RADIAL_DIFFRACTIONPS_MIRROR_PBR_MATERIAL_DIFFRACTIONPS_MIRROR_PBR_MATERIAL_EMISSIVEPS_MIRROR_PBR_MATERIAL_EMISSIVE_DIFFRACTIONPS_MIRROR_PBR_MATERIAL_EMISSIVE_RETROREFLECTIONPS_MIRROR_PBR_MATERIAL_EYEPS_MIRROR_PBR_MATERIAL_EYE_RETROREFLECTIONPS_MIRROR_PBR_MATERIAL_GLINTSPS_MIRROR_PBR_MATERIAL_HAIRPS_MIRROR_PBR_MATERIAL_HAZEPS_MIRROR_PBR_MATERIAL_IRIDESCENCEHow:
victory translate <dump> --validate --listbuilt for each side (release, cross-built with cargo-xwin, run under Wine),VICTORY_HOST_WAVE=32, plus the four shader-cache-key settingsplaystarts with (VICTORY_EARLY_DEPTH=1,VICTORY_NAN_SCRUB=1,VICTORY_BVH_MISS=1,VICTORY_SAMPLED_MARKS=1). Validator:dxil.dllfrom DXC v1.9.2609. "Changed" compares translate'semittedhash of each module and its bindings. There was no GPU on this side, so no host pipelines were made and nothing was run on a card. Onmainthe same run has 72 failures: 71 mesh programs over the 32 KiB output limit (the known shortcut inmesh_prologue) andCS_TraceShadowRays_FullAdaptive(#2993).On
mainevery program in this dump already translates (26,180 of 26,180), so none of the newly lowered instructions was holding a program of this title back. For this title the change is the programs above that come out different ("made exact"), among them many ped skin mesh and pixel programs.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KruIN689 on 2026-11-30T23:35:51Z.
@VibeCodeGuy thank you, that corpus run is exactly what this needed. 0 newly failing, and the 12 validator failures already on main, are reassuring.
You're right about the gains: for this title main already translates every program, so the lowered instructions add nothing here. They matter for other titles, or for programs this dump doesn't have. For this title, what the PR changes is the "made exact" part (NaN and rounding behaviour as the RDNA2 tables show). It reaches the 1,664 programs you list, ped skin, vehicles and CS_RaytracingResolve among them.
That is a picture change, so I'll check it in game rather than claim it: captured frames of peds close up, vehicles and RT reflections on main vs main + this PR (RTX 5080, same save). I'll post what I find here, including if anything looks worse. If you have a quick way to see which instructions those 1,664 programs share, that would narrow it down.
(Claude Code, for KruIN689.)
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KruIN689 on 2026-12-01T00:46:18Z.
In-game picture check, as promised. RTX 5080, Series X native 1440p,
VICTORY_HW_RT=1, diagnostics builds. Frames captured at the same save, standing still. Main7d93ee07against this PR's headcb133452, which sits on84bd61e2, so the two sides also differ by main's newer commits.Result: no visible difference. The scene has the player in a dark, glossy car beside foliage and water, in sunlight. I compared the full frames and 2× crops of the car's body and door. The paint and its RT reflections, the chrome, the badges, the wheels, the sleeve and shirt pattern, the trees, the water and the shadows match. The only difference is the character's animation frame.
Limits:
Together with your corpus run (0 newly failing, all 1,664 changed programs pass the validator), I see nothing against it. A face close-up and a night street would be the next places to look, if someone has a save there.
(Claude Code, for KruIN689.)
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:45:08Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed