Repository navigation
fix(formats,shader,gpu): guard BC7 rotation, SDWA sext and RDNA 2 legacy FMA, and skip read-only table UAV writeback - #406
Open
gdemontalivet wants to merge 2 commits into
Conversation
… legacy FMA - Restrict BC7 channel rotation bits to modes 4 and 5 in bcpack (modes 0/1/2/3/6/7 have no rotation field), preventing channel corruption and shift-overflow panics (upstream #3111 / victory-gta6 06702fe). - Lower v_mac_legacy_f32 and v_mad_legacy_f32 as RDNA 2 fused multiply-add with FTZ inputs and the legacy zero-factor rule (victory-gta6 f6a09d3 / PR #1026). - Sign-extend SDWA 16-bit WORD_0 destinations with dst_unused=1 (UNUSED_SEXT) and refuse reserved dst_unused=3 (upstream #3124 / victory-gta6 58de9bf). Add unit tests covering BC7 rotation, legacy FMA fusing/FTZ/zero-factor semantics, and SDWA sign extension.
Trace buffer/SMEM stores and atomics in each translated shader through victory_shader::resource::track back to their root-table (user_data, table_offset_dwords) descriptors, recording per-UsedResource write flags and a conservative write_unknown fallback in Translated. In draw::State::tables and readable_entry, skip shadow.gpu_writes and full-page refresh widening for table buffer UAVs that the shader never writes (with VICTORY_TABLE_UAV_WRITE_SKIP=0 to disable). Texture UAV state transitions remain unchanged. Adapted from VItoriaBr 6d97bea using sound resource::track resolution instead of comparing SGPR indices against HLSL register lower_bound.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three decoding/lowering accuracy bugs and one unnecessary GPU buffer copy-back cost show up across texture unpacking, shader lowering, and root-table UAV bindings:
victory-formats/src/bcpack.rs): In the BC7 specification, only modes 4 and 5 carry a 2-bit channel rotation field; modes 0–3, 6, and 7 have none. Reading rotation bits unconditionally on non-4/5 blocks swaps colour and alpha channels or triggers shift overflows on malformed bit patterns.v_mac_legacy_f32/v_mad_legacy_f32and SDWA 16-bitUNUSED_SEXT(victory-shader/src/emit/lower.rs):v_mac_legacy_f32andv_mad_legacy_f32compute a fused multiply-add with FTZ inputs where either factor being±0.0(after FTZ) forces the product term to+0.0even if the other factor isNaNor±Inf. Lowering them as unfusedfmul+faddloses precision and diverges on edge inputs.WORD_0destination withdst_unused = 1(UNUSED_SEXT) must sign-extend bit 15 into bits16..31(and refuse reserveddst_unused = 3) instead of zero-extending or leaving high bits unchanged.victory-gpu/src/pipeline.rs,draw.rs): Shaders frequently bind descriptor tables containingRWBuffer/RWStructuredBuffer/RWByteAddressBufferslots that a given dispatch only reads (or never touches), while writing to a different UAV slot. Marking every buffer UAV in every bound table range forShadow::gpu_writesforces full-page forward refresh widening, pre-write snapshot arming, and post-submission reverse copy-back on read-only buffers.What changed
UNUSED_SEXT(732ff99e):bcpack.rsto modes4and5.v_mac_legacy_f32andv_mad_legacy_f32via DXILFmawith FTZ-flushed inputs and the RDNA 2 zero-factor select rule.WORD_0destinations whendst_unused == 1(UNUSED_SEXT) and refuse reserveddst_unused == 3.resource::track-verified table buffer UAV writeback skip (792f2c2d):victory_shader::resource::trackback to their(user_data, table_offset_dwords)root-table descriptors, recording per-UsedResourcewrite flags alongside a conservativewrite_unknownfallback onTranslatedwhenever any store/atomic target cannot be statically proven.draw::State::tablesandreadable_entry, skipshadow.gpu_writesand full-page writeback widening for table buffer UAVs proven read-only by that shader (VICTORY_TABLE_UAV_WRITE_SKIP=0restores unconditional writeback). Texture UAV resource-state transitions remain unchanged.How it was tested
wave32=true), isolated test bottle:cargo test --workspace(native macOS): all passed (0failed).--test-threads=1):victory-formats(bcpack::tests):11passed, verifying BC7 modes 0–7 rotation handling and round-trip unpacking.victory-shader(valu_tests):7targeted hardware/WARP execution tests passed, covering RDNA 2 legacy FMA fusing/FTZ/zero-factor semantics and SDWA 16-bitUNUSED_SEXT.victory-gpu:38D3DMetal pipeline/draw UAV tests passed, verifying read-only table buffer UAVs skipgpu_writeswhile written or dynamically indexed UAVs preserve full writeback.cargo xtask policy,git diff --check, andcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings(with and without--features diagnostics): clean. All test inputs are synthetic.Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)
CrossOver Preview+ D3DMetal,wave32=true), the runtime reached and sustained the 3D world through+8, +24, +48, +90at1.5–1.8 FPS(549.7–672.1 ms/frameon1,021–1,258 draws/frame,1.275 FPSoverall across+8..+90) with02.48 sallocation stalls,7.2–9.0 ms/frameGUARDSlock hold time (down from4,887 ms/framebefore unlockingGUARDS),149–154 MB/framebuffer copy volume,0DirectStorage decompression or access-violation failures, and38/38over-32 KiB aligned mesh/pixel pairs linked with0host mesh refusals.