fix(vk): emit strict f32 multiply in compute mesh fallback for AMD proprietary compiler #2086
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2086
Loading…
Reference in a new issue
No description provided.
Delete branch "DYNMK/Longshot:fix/amd-mesh-fallback-strict-fmul"
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?
Summary
Fixes #1710, Fixes #1799, Fixes #1934.
On Windows with AMD RDNA 1 and RDNA 2 GPUs (RX 5000 and RX 6000 series) running AMD's older Windows proprietary shader compiler, individual grass blade triangles randomly flash solid bright white for a single frame (most visibly in Death Mountain Trail, Kokiri Forest, and Lost Woods).
How to see the bug on
main:DeathMountainTrail_Child, walk slightly up the trail past the first grass clusters, and hold the camera looking at the grass.Root cause:
In the grass compute-fallback mesh shaders, the depth pre-pass (
6afe3fda) computesfma(t, v * rsq, add)wherev * rsqhas only a single use, while the colour pass (d905f52b) reusesv * rsqfor normals/lighting. Even though every floating-point op carriesOpDecorate NoContractionandVK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BITis set on the pipeline, AMD's older Windows proprietary shader compiler ignoresNoContractiononOpFMuland reassociatesfma(t, v * rsq, add)intov37 = v_mul_f32(rsq, t); fma(v37, v, add)in the depth pass while keepingfma(v * rsq, t, add)in the colour pass. Because compute-fallback mesh stages write positions to storage buffers,gl_Positioncannot be decoratedInvariant. The resulting ±1 ULP shift on blade-tip vertices causes a few grass triangles per frame to fail the colour pass'sVK_COMPARE_OP_EQUALdepth test and show the pre-drawn sky colour (white after tonemapping).What this changes:
DevicePolicy::mesh_fallback_strict_fmul(overrideable withRX_VK_MESH_STRICT_FMUL), defaulting on only for AMD's older Windows proprietary shader compiler (p.nan_bits, i.e.,VK_DRIVER_ID_AMD_PROPRIETARYwith"proprietary shader compiler"indriverInfo).EmitFPMul32, whenctx.mesh_fallback && mesh_fallback_strict_fmul && inst->Flags<IR::FpControl>().no_contraction, emitsGLSL.std.450 Fma(a, b, -0.0f)withNoContractioninstead of plainOpFMul.fma(a, b, -0.0f)is IEEE-754 bit-exact witha * b(including signed zero, subnormals, Inf, and NaN) and compiles to a single full-ratev_fmaak_f32 ..., 0x80000000on RDNA 1/2, preventing the compiler from reassociating across the multiply.Shader::Backend::SPIRV::mesh_fallback_strict_fmulincoopmat_init()and folds it intotranslator_stamp()so cached programs rebuild cleanly when the flag changes.tests/test_mesh_fallback_strict_fmul.py) and updatestests/test_device_policy.py.Result:
Depth-pass and colour-pass grass vertices match bit-for-bit (
24,264/24,264infbrecs), and white grass triangle flashes drop to0/100frames with no measurable frame-time or register-pressure cost.Files to read first:
gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp(EmitFPMul32)gpu/vk/device_policy.h(DevicePolicy::mesh_fallback_strict_fmul,device_policy_env)gpu/vk/vk_coopmat.cpp(coopmat_init) andgpu/vk/vk_shader.cpp(translator_stamp)tests/test_mesh_fallback_strict_fmul.pyTesting
Tested:
26.11.2, version0x800161):longshot_vk.dllwithpython -I scripts/dev.py vk(llvm-mingw).DeathMountainTrail_Child(main @ 1dbf9150vsthis PR @ 0b86df87, 2 runs of 100 frames each, plusRX_VK_MESH_STRICT_FMUL=0control):mainreproduced 5/100 flash frames in both runs; this PR produced 0/100 in both runs;RX_VK_MESH_STRICT_FMUL=0reproduced 10/100 flash frames.fbrecsvertex output between depth pass (6afe3fda) and colour pass (d905f52b):24,264/24,264identical vertices with unoptimized pipelines and24,164/24,164identical vertices with optimized pipelines (matching RDNA 1 wheremesh_no_optimizeris off).VK_KHR_pipeline_executable_propertieson6afe3fda:v_fmaak_f32 ..., 0x80000000eliminates the illegal reassociation with identical VGPR/SGPR/LDS/scratch usage (45/16unoptimized,46/38optimized,0scratch).tests/test_mesh_fallback_strict_fmul.py: failed onmain @ 1dbf9150(FAIL: coopmat_init does not set Shader::Backend::SPIRV::mesh_fallback_strict_fmul), passes on0b86df87.tests/test_device_policy.py,tests/test_vendor_fixes.py,tests/test_switch_table.py,tests/test_program_stamp_knobs.py,tests/test_translator_stamp_text.py,tests/test_run_all_declarations.py,tests/test_utf8_paths.py,tests/test_log_levels.py,tests/test_thinlto_tls.py,tests/test_doc_anchors.py,scripts/check_third_party.py.python -I -B tests/run_all.py --changed origin/main: 86 passed, 10 skipped (Linux-onlyspirv-val/ optionalzstandard), 11 failed — all 11 are pre-existing onmainin untouched files (tests/test_recorder_sync.pyandtests/test_pass_barrier.pyonvk_colour_vision.cpp/vk_recorder.h;tests/test_dev_ab.pyandtests/test_present_queue_default.pyonvk_menu.cpp;tests/test_dev_packs.pyonlongshot_fsr4_pipelines.bin;tests/test_linux_pressure.pyonvk_texture.cpp;tests/test_frame_overlap.py;tests/test_target_reuse_memory.py;tests/test_vk_occlusion_queries.py;tests/test_build_long_paths.pymissing localcapstone;tests/test_crash_dialog.pycp1252 decode on Windows).Still to test:
DeathMountainTrail_ChildandKokiriForest_Child, expectingmesh_fallback_strict_fmul=1invk: policy: driver fixesand no flashing white grass triangles (by hand).mise run testincludingtest_vendor_translation.pyandtest_mesh_fallback_strict_fmul.py), expectingmesh_fallback_strict_fmul=0on non-affected drivers and zero regressions (@Beanstalk build and run game-free checks and Tier 1 smoke tests).Measurements
Verdict: Fixes the flashing white grass triangles completely (median
5/100->0/100flash frames,27.5->0flash pixels) with no measurable GPU frame-time regression (within run-to-run spread at11.35 msvs11.6 ms, 60.0 fps cap) and zero VGPR/SGPR/LDS/scratch increase.RX_VK_MESH_STRICT_FMULships enabled by default on AMD's older Windows proprietary shader compiler (p.nan_bits) and disabled everywhere else because the fix eliminates all flashes on affected drivers at no cost while leaving unaffected drivers untouched.Setup: Windows 11, AMD Radeon RX 6900 XT, AMD proprietary driver
26.11.2(0x800161);DeathMountainTrail_Child(profile="test", 1280x720 headless capture,RX_VK_PRECOMPILE=0,RX_VK_NO_PROGRAM_CACHE=1,RX_VK_PCACHE_LOAD=0); 2 interleaved runs of 100 consecutive frames each after scene warm-up (main_1,pr_1,main_2,pr_2), plus a control run withRX_VK_MESH_STRICT_FMUL=0; white-blade flash count and steady-statevk: GPU timefromlog.txt, median reported.1dbf91500b86df870b86df876afe3fdaRDNA2 ISA VGPRs / SGPRs / Scratch (unopt; opt)Screenshots of the same spot (
DeathMountainTrail_Child, frame 94) are attached in the comment below showing the bright white grass blade tip at bottom center onmain @ 1dbf9150and clean rendering onthis PR @ 0b86df87.Risks
NoContraction32-bit float multiplies inside compute-fallback mesh stages (ctx.mesh_fallback) whenmesh_fallback_strict_fmulis enabled (by default, only AMD's older Windows proprietary shader compiler on RDNA 1/2). All other GPUs, Linux/RADV, AMD RDNA 3/4 LLPC, and native mesh shader stages emit identical SPIR-V tomain.RX_VK_MESH_STRICT_FMUL=0, or revert this commit.translator_stamp()changes whenmesh_fallback_strict_fmulis active, Windows AMD RDNA 1/2 players will see a normal one-time program/pipeline cache rebuild on first launch after updating. Saves,longshot_options.ini, and caches on unaffected GPUs are unchanged.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.mainand here, for a change that shows on screen.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Assisted-by: Antigravity
Before / After Screenshots (
DeathMountainTrail_Child, frame 94)Same PC, save, camera, and settings (Windows 11, AMD Radeon RX 6900 XT, AMD proprietary driver
26.11.2/0x800161, 1280x720).main @ 1dbf9150(white grass triangle at bottom centre)this PR @ 0b86df87(clean)@Beanstalk Please build and test this PR against
mainonwindows+amd,linux+amd,steamdeck, andwindows+nvidia:mise run test, includingtests/test_mesh_fallback_strict_fmul.py,tests/test_device_policy.py, andtests/test_vendor_translation.py).windows+amdwith AMD's older proprietary shader compiler (RDNA 1 / RDNA 2, RX 5000 / RX 6000): confirmmesh_fallback_strict_fmul=1invk: policy: driver fixesand no flashing white grass triangles inDeathMountainTrail_Child/KokiriForest_Child.windows+amd(RDNA 3 / 4 LLPC),linux+amd(Mesa RADV),steamdeck, andwindows+nvidia: confirmmesh_fallback_strict_fmul=0invk: policy: driver fixesand no regressions.@DYNMK only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.