perf(vk): opaque ASTC textures kept as BC1, half the video memory of BC3 #2554
Open
NotRexed wants to merge 1 commit from
perf/astc-opaque-bc1 into main
pull from: perf/astc-opaque-bc1
merge into: MagicBeanDev:main
MagicBeanDev:main
MagicBeanDev:github/pr/2893
MagicBeanDev:github/pr/2890
MagicBeanDev:github/pr/2887
MagicBeanDev:github/pr/2878
MagicBeanDev:github/pr/2875
MagicBeanDev:github/pr/2874
MagicBeanDev:github/pr/2873
MagicBeanDev:github/pr/2871
MagicBeanDev:github/pr/2756
MagicBeanDev:github/pr/2897
MagicBeanDev:github/pr/2896
MagicBeanDev:github/pr/2718
MagicBeanDev:github/pr/2842
MagicBeanDev:github/pr/2691
MagicBeanDev:github/pr/2895
MagicBeanDev:github/pr/2743
MagicBeanDev:github/pr/2765
MagicBeanDev:github/pr/2708
MagicBeanDev:github/pr/2732
MagicBeanDev:github/pr/2755
MagicBeanDev:github/pr/2817
MagicBeanDev:github/pr/2876
MagicBeanDev:release-please--branches--main
MagicBeanDev:release-please--branches--main--release-notes
MagicBeanDev:github/pr/2778
MagicBeanDev:github/pr/2888
MagicBeanDev:github/pr/2866
MagicBeanDev:github/pr/2877
MagicBeanDev:github/pr/2800
MagicBeanDev:github/pr/2829
MagicBeanDev:github/pr/2850
MagicBeanDev:github/pr/2889
MagicBeanDev:github/pr/2882
MagicBeanDev:github/pr/2860
MagicBeanDev:github/pr/2849
MagicBeanDev:github/pr/2886
MagicBeanDev:github/pr/2794
MagicBeanDev:github/pr/2840
MagicBeanDev:github/pr/2830
MagicBeanDev:github/pr/2834
MagicBeanDev:github/pr/2719
MagicBeanDev:github/pr/2742
MagicBeanDev:github/pr/2741
MagicBeanDev:github/pr/2820
MagicBeanDev:github/pr/2771
MagicBeanDev:github/pr/2859
MagicBeanDev:github/pr/2858
MagicBeanDev:github/pr/2823
MagicBeanDev:github/pr/2757
MagicBeanDev:github/pr/2769
MagicBeanDev:github/pr/2844
MagicBeanDev:github/pr/2843
MagicBeanDev:github/pr/2673
MagicBeanDev:github/pr/2855
MagicBeanDev:github/pr/2739
MagicBeanDev:github/pr/2807
MagicBeanDev:github/pr/2851
MagicBeanDev:github/pr/2789
MagicBeanDev:github/pr/2814
MagicBeanDev:github/pr/2818
MagicBeanDev:github/pr/2774
MagicBeanDev:github/pr/2772
MagicBeanDev:github/pr/2750
MagicBeanDev:github/pr/2786
MagicBeanDev:github/pr/2785
MagicBeanDev:github/pr/2782
MagicBeanDev:github/pr/2779
MagicBeanDev:github/pr/2775
MagicBeanDev:github/pr/2706
MagicBeanDev:github/pr/2766
MagicBeanDev:github/pr/2747
MagicBeanDev:github/pr/2759
MagicBeanDev:github/pr/2745
MagicBeanDev:github/pr/2740
MagicBeanDev:github/pr/2733
MagicBeanDev:github/pr/2725
MagicBeanDev:github/pr/2727
MagicBeanDev:github/pr/2728
MagicBeanDev:github/pr/2729
MagicBeanDev:github/pr/2721
MagicBeanDev:github/pr/2722
MagicBeanDev:github/pr/2715
MagicBeanDev:github/pr/2714
MagicBeanDev:github/pr/2707
MagicBeanDev:github/pr/2703
MagicBeanDev:github/pr/2705
MagicBeanDev:github/pr/2697
MagicBeanDev:github/pr/2679
MagicBeanDev:github/pr/2676
MagicBeanDev:github/pr/2669
MagicBeanDev:docs/what-hookshot-connects-to
MagicBeanDev:fix/hdr-encode-test
MagicBeanDev:fix/main-tests
MagicBeanDev:fix/play-cache-files
MagicBeanDev:perf/game-barrier-order
MagicBeanDev:feat/heap-lazy
MagicBeanDev:feat/texture-detail
MagicBeanDev:fix/fs-dir-lock
MagicBeanDev:fix/framegen-native-kept
MagicBeanDev:fix/update-no-downgrade
MagicBeanDev:port/k10-gcn-f16-mirrors
MagicBeanDev:fix/framegen-mult-cap
MagicBeanDev:chore/release-as-2.1.1
MagicBeanDev:perf/pcache-load-switch
MagicBeanDev:fix/prepare-progress-log
MagicBeanDev:fix/update-closes-stale-game
MagicBeanDev:fix/hdr-scaled-sampled
MagicBeanDev:perf/first-start-preset
MagicBeanDev:perf/zero-upload
MagicBeanDev:fix/vcore-escape-2s
MagicBeanDev:test/fake-gh-atomic
MagicBeanDev:perf/batch-idle-flush
MagicBeanDev:test/finish-stub-a
MagicBeanDev:chore/record-2.1.0
MagicBeanDev:fix/main-red-tests
MagicBeanDev:fix/test-display-startup-driver-cache
MagicBeanDev:feat/mesh-shader-mode
MagicBeanDev:fix/menu-probes-at-startup
MagicBeanDev:fix/fps-counter-classic
MagicBeanDev:fix/test-log-batch-flake
MagicBeanDev:fix/narrow-screen-hud
MagicBeanDev:ci/prereleases
MagicBeanDev:release/v2.0.15
MagicBeanDev:hotfix/v2.0.15
MagicBeanDev:fix/present-ahead-replay
MagicBeanDev:release/v2.0.13
MagicBeanDev:fix/bracket-paths-2013
MagicBeanDev:fix/hdr-overlays-2013
MagicBeanDev:fix/fps-counter-scale-2013
MagicBeanDev:fix/stick-seen-at-rest
MagicBeanDev:hotfix/menu-fits-screen
MagicBeanDev:fix/f1-always-opens-menu
MagicBeanDev:fix/ini-keep-lines
MagicBeanDev:claude/cranky-pike-7cf247
MagicBeanDev:perf/texture-answer-flat
MagicBeanDev:fix/stamp-test-modules
MagicBeanDev:fix/appimage-fonts
MagicBeanDev:fix/display-awake
MagicBeanDev:release/v2.0.12
MagicBeanDev:fix/discord-windows
MagicBeanDev:rc/v2.0.12-tests
MagicBeanDev:fix/dlss-keep-feature
MagicBeanDev:rc/v2.0.12
MagicBeanDev:button-icons
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
autorelease: pending
autorelease: tagged
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
github_actions
Pull requests that update GitHub Actions code
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
question
Further information is requested
testing wanted
wontfix
This will not be worked on
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2554
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/astc-opaque-bc1"
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?
Why. On cards up to 8 GB, the big ASTC textures (terrain, buildings) are decoded on the GPU and re-encoded as BC3, a byte per texel. A large share of the game's textures have no transparency at all, and BC1 stores them in half the space with the same colours. This targets the 8 GB "fps fades over time" reports (#993): less VRAM for the same picture.
How
The choice (
gpu/vk/astc_opaque.h). A block counts as opaque only when its header says so:Everything uncertain counts as alpha and keeps BC3: alpha modes (4, 5, 10, 12, 13), partitions of different modes, and HDR void extents. Blocks of zeros (storage the game hasn't written yet) decide nothing.
When (
upload_astc_gpu). A texture's first whole upload decides, if every block with data in it is opaque and those blocks are most of the storage. Its BC3 image is then made again as BC1 (bc_reformat). The old image and views are released once the work that used them is done, the same way the compaction moves images. Views are made again on demand, anddestroy_genis bumped.Switching back. An upload into a BC1 image that has alpha in it turns the image back into BC3 and uploads it whole.
Encoding.
bc_encode_intoruns the existing encoder in its BC1 mode (bc3 = 0). Without texels under half alpha, it writes the same four-colour blocks as BC3's colour half. A BC1 image's views areBC1_RGBA(UNORM / SRGB).Off switch.
RX_VK_ASTC_BC1=0keeps everything BC3. The log says how many textures went BC1, how many went back, and the MB saved.Tests:
tests/test_astc_opaque.pybuilds blocks bit by bit (every endpoint mode, shared and mixed partitions, void extents, zeros) and checks the scan and the whole-upload rule. All tests that readvk_texture.cpppass, and the file compiles. The narrowing error at line 1485 with plain clang flags is already on main.Not yet verified in-game: VRAM in Hyrule Field with and without it, plus the flash check. The PC is in use for the owner's 2.2.0 test.
🤖 Generated with Claude Code
WIP: perf(vk): opaque ASTC textures kept as BC1, half the video memory of BC3to perf(vk): opaque ASTC textures kept as BC1, half the video memory of BC3Heads-up for the rebase on main: #2226 (
RX_VK_ASTC_BC7) landed in the same spots, and I hit the conflict while merging this locally to test it on an RX 5600 XT.view_format_of. The conflict is one hunk. I resolved it as BC7 when the image is BC7, BC1 when it is BC1, else BC3. That keeps theconst bool bc1 = image == VK_FORMAT_BC1_RGBA_UNORM_BLOCK;line thattests/test_astc_opaque.pylooks for:bc_encode_intowith both switches on. It bindsbc7_enabled() ? bc7_pipe : bc_pipe, and only the BC3/BC1 encoder reads the push constant'sbc3flag. WithRX_VK_ASTC_BC7=1, a texture thatupload_astc_gputurned into BC1 (!is_bc1 && !tex.bc1is true for a BC7 image too) would be encoded by the BC7 pipeline into a BC1 image. BC7 is off by default, so the default path is fine. Two possible fixes:bc1_on()returns false whenbc7_enabled(), or the reformat goes back to BC7 instead of BC3 and the BC1 encode always takesbc_pipe.tests/test_astc_opaque.pypasses.In the game.
Setup: RX 5600 XT 6 GB (RDNA1, no mesh shaders), Adrenalin 26.10.1, Windows 11, Ryzen 5 5600X, 24 GB, 1920x1080, frame generation off. Every run starts from the same copied save and follows a scripted route through the control bridge (Kokiri Forest and Hyrule Field: settle 15 s, then 60 s standing); fps are the medians of the log's
N presentslines. Run-to-run noise on mainde866017(4 runs): Kokiri 31.5-34.6 fps, Hyrule Field 32.1-34.8.Merged on main
de866017(the #2226 conflict resolved as above). At Kokiri Forest and Hyrule Field:16 opaque textures kept as BC1, 0 back to BC3; 7 MB less than BC3. The textures held ~1,100 MB.So at these spots few of the big ASTC textures pass the whole-upload rule. The saving may be bigger elsewhere (Castle Town, Death Mountain); I can run those if useful.