fix(vk): split non-4-aligned multi-layer BC mip-tail copies on AMD Windows and restore 8-layer runs #2228
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2228
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:fix/bc-copy-per-layer"
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
Finds and fixes the root cause of Hyrule Field's dark terrain grid lines on AMD's Windows driver (#2006, #2107, #2110), and restores 8-layer ASTC-to-BC small-scratch batching (
bc_small_runs=1) andRX_VK_BC_LEVELSgrouped mip re-encoding (#1987) on AMD's Windows driver (which #2148 had to disable until the cause was found).Root cause (reproduced in standalone Vulkan probes on RX 6700 XT, AMD Windows driver
26.10.1/0x800161):On AMD's proprietary Windows driver (diagnosed on RDNA 2), a single
vkCmdCopyBufferToImageregion withlayerCount > 1into a block-compressed (BC3orBC7) mip-tail level whose extent is not a multiple of 4 ((w & 3) || (h & 3)) truncates the copied block extent tofloor(w/4) x floor(h/4)instead ofceil(w/4) x ceil(h/4), leaving the rightmost column and bottommost row of blocks all0x00(pure black) on every layer.1365 x 1365 x 90terrain material arrays, mip 8 is5 x 5(2 x 2blocks = 64 B/layer): only block(0,0)(16 B) is copied while blocks(1,0),(0,1),(1,1)(48 B — right/bottom border) stay zeroed on all 90 layers, creating the dark tile seams on distant hills while close-up mips0..7remain clean.layerCount = 2..8for bothBC3andBC7, both withbufferRowLength = 0and with #2015's explicitbufferRowLength = blocks_x * 4, bufferImageHeight = blocks_y * 4, and across other non-4-aligned mip tails (6x6,5x5,9x9).nsingle-layerVkBufferImageCopyregions (layerCount = 1, explicitbufferOffset = (i0 + j) * layer_bytes) inside the samevkCmdCopyBufferToImagecall produces a 100% bit-for-bit exact match againstn = 1across all 90 layers and all mips1..10, with zero measurable overhead (1731 msvs1746 ms).What this changes:
gpu/vk/device_policy.h&gpu/vk/switches.def:DevicePolicy::bc_copy_per_layer(RX_VK_BC_COPY_PER_LAYER), defaulted on across AMD's Windows driver (f.amd_win()) and off everywhere else, logged invk: policy: driver fixeswith(seen on 0x800161). Keepingbc_copy_per_layersymmetric withbc_small_runsavoids exposing untested AMD Windows generations (RDNA 1, RDNA 3, GCN) to #2006 at zero measurable cost.DevicePolicy::bc_small_runs = f.radv() || f.driver_id == VK_DRIVER_ID_NVIDIA_PROPRIETARY || f.amd_win();so AMD's Windows driver regains 8-layer small-scratch runs and #1987 mip-level grouping.gpu/vk/vk_texture.cpp(bc_encode_into): whendev.policy.bc_copy_per_layer && n > 1 && ((w & 3) || (h & 3)), emitsnsingle-layerVkBufferImageCopyregions (chunked by 8, so 1vkCmdCopyBufferToImagecall for normal runs up tokBcLayers = 8) with explicitbufferOffset. Every other driver and all 4-aligned or single-layer mips remain on the untouched single-region path.tests/test_bc_copy_layer_pitch.py(tests bothbc_copy_per_layer=0andbc_copy_per_layer=1, including non-zero(dx, dy)sub-region copies andn > 8chunking; fails onmain),tests/test_device_policy.py,tests/test_bc_small_scratch.py, andtests/test_astc_upload_chunking.py.To see the bug: Windows, AMD RDNA 2 (RX 6700 XT) with
RX_VK_BC_SMALL_LAYERS=8onmain(orRX_VK_BC_COPY_PER_LAYER=0here), loadcastle-gate(HyruleField_Child) and look across the distant sunlit hills left and right of the drawbridge: dark grid seams appear across the terrain. With this PR's defaults (bc_small_runs=1,bc_copy_per_layer=1), the terrain is clean and 8-layer batching stays active.Read first:
gpu/vk/device_policy.h(bc_copy_per_layer,bc_small_runs), thengpu/vk/vk_texture.cpp(bc_encode_into).See #2006, See #2015, See #2107, See #2110, See #2148
Testing
Tested: Windows 11, AMD Radeon RX 6700 XT (
1002:73df), AMD driver26.10.1(0x800161), headless in-game oncastle-gate(HyruleField_Child) andHyruleField_Adult(noon):bc_small_runs=1,bc_copy_per_layer=1,vk: the small BC3 scratch: 1024 x 1024, 8 layers): Hyrule Field distant terrain is completely clean (zero grid lines), matching 1-layer runs visually while restoring 8-layer batching.RX_VK_BC_COPY_PER_LAYER=0(bc_small_runs=1,bc_copy_per_layer=0*): dark square grid seams immediately reproduce across the distant hills on the exact samecastle-gateview (screenshots attached in comment).a724a83passed onwindows+amd-proprietary+gpu-rx-9xxx(RX 9060 XT, 2 reports),linux+radv(RX 9070 / XT, 2 reports), andwindows+nvidia-proprietary(RTX 4070 / 3080 Ti, 2 reports).3bab53e06:dev.py vkbuildslongshot_vk.dllcleanly on Windows (llvm-mingw), and game-free checks pass on bothclang++andg++:test_bc_copy_layer_pitch.py,test_bc_small_scratch.py,test_device_policy.py,test_gpu_arch.py,test_astc_upload_chunking.py, andtest_doc_anchors.py(test_switch_table.pyfails only on the pre-existingmainsort order ofRX_VK_GRASS_DISTANCE/RX_VK_SIM_TURF_ADAPTIVE, tracked in #2197).Still to test:
3bab53e06via Beanstalk on Windows AMD RDNA 3/4 (RX 7000 / RX 9000, now withbc_copy_per_layer=1alongsidebc_small_runs=1), plus Linux build/RADV and Windows NVIDIA (bc_copy_per_layer=0, unchanged).Measurements
Verdict: faster and clean: restores 8-layer ASTC-to-BC small-scratch batching on AMD Windows, cutting the two
1365 x 1365 x 90terrain array ASTC-on-GPU upload times at Hyrule Field entry by -375 ms (-17.8%) (2106 ms->1731 msmedian, non-overlapping runs) and the entry frame upload spike by -400 ms (2229 ms->1829 ms), with zero measurable overhead frombc_copy_per_layer=1(1731 msvs1746 mswithRX_VK_BC_COPY_PER_LAYER=0) and zero grid lines on Hyrule Field.RX_VK_BC_COPY_PER_LAYERships on by default onf.amd_win()(off elsewhere);RX_VK_BC_SMALL_LAYERSships at8onf.amd_win()alongside RADV and NVIDIA. (Wideningbc_copy_per_layerfromf.amd_win() && f.rdna2()tof.amd_win()in3bab53e06leaves RX 6700 XT behavior and code path bit-identical, so these numbers still hold.)Baseline:
a724a837withRX_VK_BC_SMALL_LAYERS=1(matchesmain @ a2dc5385, where #2148 setsbc_small_runs=0and skips creating the small BC3 scratch on AMD Windows).Setup: Windows 11, AMD Ryzen 5 5600X, AMD Radeon RX 6700 XT (
1002:73df), AMD Windows driver26.10.1(0x800161); headlesscastle-gate(HyruleField_Child),1920x1080, AF 4x, V-Sync off, FG off; two interleaved pairs (A1, B1, A2, B2) plus oneRX_VK_BC_COPY_PER_LAYER=0check, measured fromvk: a frame's uploads took ...on the1365x1365 x90terrain arrays.a724a837a724a837a724a8371365x1365 x90ASTC-on-GPU upload (run 1 / run 2)1024x1024 x8)8 layers)8 layers)Log lines:
Risks
low_vram_texture_mips()and in VRAM), the same as RADV and NVIDIA.bc_copy_per_layerto allf.amd_win()splits non-4-aligned multi-layer BC copies on RDNA 3/4 Windows too; single-layerVkBufferImageCopyregions are strictly simpler than multi-layer compressed copies and measured zero overhead on RX 6700 XT, and players can override either way viaRX_VK_BC_COPY_PER_LAYER=0/1orRX_VK_BC_SMALL_LAYERS=1.longshot_options.ini, or shader/pipeline caches; reverting restores #2148's 1-layer fallback.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.Tested in game: Windows 11, AMD Radeon RX 6700 XT (1002:73df), AMD driver 26.10.1 (0x800161), headless castle-gate (HyruleField_Child) and HyruleField_Adult (noon): default (bc_small_runs=1, bc_copy_per_layer=1, 1024x1024 x8 small BC3 scratch) renders distant Hyrule Field terrain cleanly with zero grid lines and cuts the 1365x1365 x90 terrain array ASTC-on-GPU upload median from 2106 ms (RX_VK_BC_SMALL_LAYERS=1) to 1731 ms (-375 ms / -17.8%); RX_VK_BC_COPY_PER_LAYER=0 reproduces the dark grid seams on the same view.
In-game A/B screenshots (
castle-gate,HyruleField_Child, RX 6700 XT, AMD Windows26.10.1/0x800161)Workaround off (

RX_VK_BC_COPY_PER_LAYER=0, 8-layer runs): dark grid seams across the distant hills left and right of the drawbridge:mainbehavior (RX_VK_BC_SMALL_LAYERS=1, 1-layer runs, no small BC3 scratch): clean terrain,2106 msmedian ASTC-on-GPU upload on the two1365x1365 x90terrain arrays:This PR default (

bc_small_runs=1,bc_copy_per_layer=1,1024x1024 x8small BC3 scratch): clean terrain (zero grid lines) at1731 msmedian (-375 ms/-17.8%faster):@Beanstalk please test on Windows AMD RDNA 3 / RDNA 4 (RX 7000 / RX 9000, AMD Windows driver) on
castle-gate(Hyrule Field) to confirmbc_small_runs=1,bc_copy_per_layer=0,the small BC3 scratch: 1024 x 1024, 8 layers, and clean distant terrain with no dark grid lines; and sanity-check Linux RADV and Windows NVIDIA oncastle-gate(bc_small_runs=1,bc_copy_per_layer=0, unchanged).Beanstalk test farm · an earlier run: commit
a724a83(the newer results are in a comment below)Commit
a724a83· approved by madebyjordan (reviewed) · dashboard⚠️ Note: The screenshot comparison detects changes against main, but cannot prove either image is free of dark grid lines if both contain them.
⚠️ Note: The scratch allocation check is unjudged if that allocation path is not reached; low-VRAM configurations can use a smaller scratch.
Started at 07:20 UTC.
windows+amd-proprietary+gpu-rx-7xxx(GPU "rx 7xxx")windows+amd-proprietary+gpu-rx-9xxx(GPU "rx 9xxx")linux+radvwindows+nvidia-proprietaryWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares the castle-gate view of Hyrule Field on Windows RX 7000 and RX 9000, Linux RADV, and Windows NVIDIA, taking about 20–25 minutes per tester. It checks the default BC policy and scratch allocation logs and compares distant terrain pictures against main; crashes, wrong policy logs, or significant picture differences fail. The RX 7000 target will wait for a matching tester; the online inventory does not list one. No tester online now matches windows+amd-proprietary+gpu-rx-7xxx: that target waits for one.
castle-gate, then take the picture distant-terrain to compare with main, measure field for 15 s (after 5 s warm-up); 2 runs on each side.Measurements on `windows+amd-proprietary+gpu-rx-9xxx`, for the PR description
Verdict: pass on windows+amd-proprietary+gpu-rx-9xxx (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+amd+amd-proprietary+dgpu
AMD Radeon RX 9060 XT, 2.0.416AMD Ryzen 5 5600 6-Core Processor, 32 GB RAM; 2: windows+amd+amd-proprietary+dgpuAMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMScene: castle-gate, from the repository's save castle-gate; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-gate: 2 game starts a side, field 15 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)a2dc538a724a83Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `linux+radv`, for the PR description
Verdict: pass on linux+radv (2 reports): no rule failed and no PR run crashed.
Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAM; 2: linux+amd+radv+dgpuAMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMScene: castle-gate, from the repository's save castle-gate; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-gate: 2 game starts a side, field 15 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)a2dc538a724a83Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `windows+nvidia-proprietary`, for the PR description
Verdict: pass on windows+nvidia-proprietary (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAMScene: castle-gate, from the repository's save castle-gate; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-gate: 2 game starts a side, field 15 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)a2dc538a724a83Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
The testers' hardware
windows+amd-proprietary+gpu-rx-9xxxAMD Radeon RX 9060 XT, 2.0.416AMD Ryzen 5 5600 6-Core Processor, 32 GB RAMwindows+amd-proprietary+gpu-rx-9xxxAMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMwindows+nvidia-proprietaryNVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAMwindows+nvidia-proprietaryNVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAMRead of
a724a837on #2227'se8915426(stacked on open #2227, so the diff includes itsgpu_arch.h). The block-truncation fix is right and the single-layer path is untouched. One default mismatch is what I would change before this ships: the workaround is as narrow as RDNA 2 while the 8-layer runs it protects are as wide as every AMD Windows GPU.1.
bc_small_runsis re-enabled forf.amd_win(), butbc_copy_per_layerisf.amd_win() && f.rdna2()(device_policy.h:629vs:563). So RDNA 1, GCN, RDNA 3 and RDNA 4 on AMD's Windows driver go back to 8-layer multi-layer copies into non-4-aligned mip tails — the exact copy the probe shows truncating — with no per-layer split. The policy test codifies it: the RX 5700 (RDNA 1) case expectsbc_small_runson and nobc_copy_per_layer(tests/test_device_policy.py:283-289), and the RDNA 3/4 and 860M cases likewise. Still to test covers RDNA 3/4 and Linux/NVIDIA only, so RDNA 1 and GCN are not scheduled at all. The split measured free (1731 vs 1746 ms — the PR's own "zero measurable overhead"), so unless the driver bug is known to be RDNA 2 hardware rather than this driver's copy path, either widenbc_copy_per_layertof.amd_win()or keep the 8-layer runs atf.radv() || NVIDIA || (f.amd_win() && f.rdna2())until the farm has looked; as written, the Risks' fallback ("widen if grid lines appear") means a player sees #2006 again before the widening. Good news on scope: the groupedRX_VK_BC_LEVELScopies are single-layer (layerCount = 1,vk_texture.cpp:1513) and the resident upload copies are too (:2442,layerCount = 1), sobc_encode_intois the only multi-layer compressed copy — the workaround is complete where it applies.2. The fix itself is correct. The condition
n > 1 && ((w & 3) || (h & 3))matches the probe's trigger; the per-layer regions usebufferOffset = i * layer_bytes(layer_bytes = blocks_x * blocks_y * 16, the encoder's layout),bufferRowLength = blocks_x * 4,bufferImageHeight = blocks_y * 4,baseArrayLayer = layer + i,layerCount = 1, the same{dx, dy}, and one call per 8 regions (vk_texture.cpp:1154-1168). The offsets are whole 16-byte blocks and the row pitch whole blocks, as Vulkan wants for BC; the 8-layer decode/encode run is kept (it is only the copy that is split), andn <= 8stays onevkCmdCopyBufferToImage. The 4-aligned case andn == 1take the old single region unchanged.3. The test fails on main for the bug's reason: with
per_layer=1it expectsnregions and main always emits one (tests/test_bc_copy_layer_pitch.py:78-101). It runs both switch states over 5x5, 6x6, 9x9, 683x170, 1024x1024 and a single-layer 1365, checking mip, base layer, layerCount, pitch, extent, offset, and thatn <= 8is one call. It cannot prove the driver's truncation (the standalone probe does); the 90-layer terrain array is modelled by the offset arithmetic, not by a 90-region call — which is fine whilen <= 8, but worth a line in the test or the body that the run size is the ceiling.4. The single-layer path is not regressed: the
n > 1guard keeps it on the old single region, and the(1365, 1365, 1)case is run with both switch values.5. The default row
RX_VK_BC_COPY_PER_LAYER(hw, on only for RDNA 2 Windows, logged with(seen on 0x800161)) matches the code and the measurement; the mismatch in 1 is inbc_small_runs, not in this row. The dependency on #2227 is real (this cannot merge first); the Raphael iGPU case in the policy test confirmsrdna2()includes RDNA 2 APUs.No approval, and no claim on it.
a724a837c73bab53e063Beanstalk test farm
Commit
3bab53e· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.fix(vk): fix RDNA 2 Windows multi-layer BC mip-tail copy and restore 8-layer runs on AMD Windowsto fix(vk): split non-4-aligned multi-layer BC mip-tail copies on AMD Windows and restore 8-layer runsUpdated in
3bab53e06(rebased onto updated #2227218a728d9) to address Review #2314:bc_copy_per_layertof.amd_win()(gpu/vk/device_policy.h,gpu/vk/switches.def,tests/test_device_policy.py), matchingbc_small_runssymmetrically so RDNA 1, RDNA 3, GCN, and RDNA 4 on AMD's Windows driver are all protected by the zero-overhead per-layer split instead of risking #2006 regressions on untested generations.tests/test_bc_copy_layer_pitch.pyto also check non-zero(dx, dy)sub-region offsets (astexture_copy_into_bc) andn = 10(>kBcLayers = 8) to verify the chunkedvkCmdCopyBufferToImageloop (ceil(n / 8)calls).dev.py vk(longshot_vk.dll) and game-free tests (test_bc_copy_layer_pitch.py,test_bc_small_scratch.py,test_device_policy.py,test_gpu_arch.py,test_astc_upload_chunking.py,test_doc_anchors.py) pass on bothclang++andg++.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.