fix(vk): the copy out of the BC encoder's buffer gives the layers' pitch, not the driver (Hyrule Field's grid lines on AMD Windows) #2015
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!2015
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/bc-copy-layer-pitch"
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 #2006. On AMD's Windows driver (RX 6700 XT, driver 26.10.1), Hyrule Field's ground has shown a grid of thin dark lines since #1843, worst on the far ground.
RX_VK_BC_SMALL_LAYERS=1removes them.Likely cause. The terrain's material arrays are 1365 x 1365 x 90 ASTC, kept as BC3. A run of layers is decoded, then encoded into a buffer, then copied into the image (
bc_encode_into). That copy leftbufferRowLengthandbufferImageHeightat 0, so the driver had to work out each layer's size in the buffer from the copy's extent. No level of a 1365 texture is a multiple of 4 (682, 341, 170, 85, ...), so that size depends on how the driver rounds a partial block. If it rounds differently from the encoder, every layer after a run's first is read from the wrong place, and its texture's edges come out wrong. Tiled across the field, those edges are the grid. This fits every report:ec89f92e, and this RX 6700 XT.That
ec89f92efix, one layer a run, avoided the bug without finding its cause, and #1843's eight-layer small scratch brought it back.The change. The copy now gives both values in whole blocks, as the encoder writes them (
blocks_x * 4,blocks_y * 4). The buffer's layout is now spelled out instead of left to the driver, and runs keep their eight layers. Readgpu/vk/vk_texture.cpp,bc_encode_into.Not confirmed yet: no one has run this on AMD's Windows driver, so whether it removes the lines there is still open (see Still to test).
Testing
Tested: not run in the game yet; this PR was opened before any game run, at the request of the person I work for. No checks were run on this PC. The new check and the full suite are left to CI.
Still to test:
RX_VK_BC_SMALL_LAYERS=1onmain(@Beanstalk, or the player from #2006, by hand).main(@Beanstalk).Measurements
Nothing to measure: only the copy's buffer layout is now given explicitly. The work done, the runs and the memory are the same as before.
Risks
Only the BC re-encode's copy into the image changes. For a level whose size is a multiple of 4, the values given are the ones a conforming driver already derived. A wrong value would garble BC-kept ASTC textures on every GPU, which the new check guards against. To roll back, revert this PR;
RX_VK_BC_SMALL_LAYERS=1still works around the lines as before. Players notice nothing after updating except, on AMD's Windows driver, the missing grid lines.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (not run on this PC; left to CI)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (tests/test_bc_copy_layer_pitch.py, the first commit, written to fail onmain; not yet run both ways)tests/that reads changed source is updated, not weakened. (test_bc_small_scratch.py's docstring)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Possibly related, for context:
@review
WIP: fix(vk): the copy out of the BC encoder's buffer gives the layers' pitch, not the driver (Hyrule Field's grid lines on AMD Windows)to fix(vk): the copy out of the BC encoder's buffer gives the layers' pitch, not the driver (Hyrule Field's grid lines on AMD Windows)Recommendation: Request changes. The explicit pitches match the encoder and preserve batching. The comments misstate Vulkan’s rounding rules, and the affected AMD Windows driver still needs to show that this change removes the grid lines.
Makes the buffer layout explicit for every ASTC-to-BC copy. It could clear Hyrule Field’s distant grid lines on AMD Windows while keeping eight-layer batches. The code change is small and keeps the same dispatches, barriers, copy regions and scratch allocations.
@fixwill do (5)gpu/vk/vk_texture.cpp:1089: Vulkan defines zero row length and image height as tightly packed and rounds compressed dimensions up to whole blocks in its address calculation. (more on the line)tests/test_bc_copy_layer_pitch.py:64: The expected pitch comes from the same production block counts that fill the copy fields. (more on the line)tests/test_bc_copy_layer_pitch.py:91: The documented standalone command defaults to g++ even with CXX set. (more on the line)For the author (1) (a run, a measurement or a decision)
gpu/vk/vk_texture.cpp:1093: Compare the base and head on the RX 6700 XT with driver 26.10.1, using the same save, settings, camera and build type. (more on the line)Checks: Still running:
CI / Conventional Commit title (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),PR description / Description follows the template (pull_request_target),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven. For the 682 × 682 mip, both the old Vulkan-defined layout and the explicit layout use 171 × 171 BC blocks, or 467,856 bytes per layer. The reported one-layer workaround is evidence from the old path. No matched run compares base
2b3de5b2with head006d3e4con the affected driver.Other systems: The shared helper also changes BC7, resized uploads, one-layer uploads and texture-to-texture copies into BC images. Both shaders pack 16-byte blocks in the same order, and the recorder copies the full region by value. The Vulkan-defined byte range is identical on a conforming driver. Windows NVIDIA, Linux NVIDIA, RADV and Steam Deck still need visual coverage. The change is confined to the renderer’s BC transfer parameters and adds no host I/O, save, audio, input or cache-format work.
Switches: No switches added, changed or removed. RX_VK_BC_SMALL_LAYERS remains 8 where the small scratch is available. The existing value 1 is the reported workaround on the base. Confirm the default on the affected driver with both runs.
Reviewed:
006d3e4cc5against2b3de5b27a: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, developer standards, the fix-with-test rules and both changed tests in full. No review checklist file was present. Read both changed vk_texture.cpp sections in full and traced the upload and texture-copy callers, scratch allocation and retirement, shader indexing, barriers, recorder and test discovery. Skimmed historical runs, existing test fixtures, CI wiring and the generated shader-header references. The rest of vk_texture.cpp and the generated shader byte arrays were outside the read scope. No comments or prior reviews were supplied.; nothing run (a code review).Checked and fine:
Testing: Read-only review. No build, test or game run was performed. CI reports no failures and lists pending checks. Still needed are the author’s in-game run, the fixture’s failure before the fix and pass on head, and the supported-platform checks.
Overlaps and merge order: No open overlap found in the checkout. #1843 is already in the base. The existing uneven-BC resize workaround is a separate path that shares the copy helper.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -1086,3 +1087,3 @@vkCmdDispatch(cmd, (pc.blocks_x + 7) / 8, (pc.blocks_y + 7) / 8, n);full_barrier(cmd);const VkBufferImageCopy c{0, 0, 0, {VK_IMAGE_ASPECT_COLOR_BIT, level, layer, n}, {dx, dy, 0}, {w, h, 1}};// (the buffer's rows and layers given in whole blocks, as the encoder wrote them: blocks_x * blocks_y blocks a layer.L1: Vulkan defines zero row length and image height as tightly packed and rounds compressed dimensions up to whole blocks in its address calculation. A 682 × 682 copy therefore has 171 blocks per axis even with both fields zero. Explain that explicit pitch works around a suspected driver defect. Keep that qualification in the small-scratch comment and both test docstrings until a driver comparison establishes the cause.
@ -1089,0 +1090,4 @@// Left at 0, the driver worked the layers' pitch out from the extent, and a level not a multiple of 4 leaves that to// its rounding: the terrain's material arrays are 1365 x 1365, and on AMD's Windows driver (an RX 6700 XT; an RX 6600// before, ec89f92e) every layer after a run's first came out wrong, Hyrule Field's ground in a grid of dark lines, #2006)const VkBufferImageCopy c{0, pc.blocks_x * 4, pc.blocks_y * 4, {VK_IMAGE_ASPECT_COLOR_BIT, level, layer, n}, {dx, dy, 0}, {w, h, 1}};L3 (minor): Compare the base and head on the RX 6700 XT with driver 26.10.1, using the same save, settings, camera and build type. Repeat at the western slopes with the default batch size and use one layer as a control. Include the Tier 1 regression checks, especially Linux NVIDIA and Steam Deck, which are missing from Still to test. Compare the field-entry ASTC upload spans during the same runs if the explicit copy changes driver timing.
@ -0,0 +61,4 @@Texture t;bc_encode_into((VkCommandBuffer)1, w, h, n, t, 1, 3, 0, 0);// (the encoder's layout: blocks_x * blocks_y blocks a layer, 16 bytes a block)const uint64_t enc_row = (uint64_t)pushed.blocks_x * 16, enc_layer = enc_row * pushed.blocks_y;L4 (minor): The expected pitch comes from the same production block counts that fill the copy fields. If the width rounds up by an extra block at 1024, the fixture still passes even though an eight-layer run would exceed its small scratch output buffer by 32 KiB. Derive expected block counts independently from the case dimensions and check the push constants and copy region against them.
@ -0,0 +88,4 @@def main():p = argparse.ArgumentParser(description=__doc__)p.add_argument("--headers", type=Path, required=True)p.add_argument("--cxx", default="g++")L5 (minor): The documented standalone command defaults to g++ even with CXX set. A Windows developer with only llvm-mingw clang++ gets a missing executable unless they pass --cxx explicitly. Keep the override and default to CXX or an available supported C++ compiler. The suite runner already passes its compiler explicitly.