Repository navigation
gfx10_descriptors: index the format table instead of scanning it (~20x faster SRV format lookups) - #8021
gfx10_descriptors: index the format table instead of scanning it (~20x faster SRV format lookups)#8021TG0000 wants to merge 1 commit into
Conversation
format_row, vulkan_format and vulkan_view_format walked the 94-row format_table on every call; an SRV makes five of these lookups (format_from_vulkan, vulkan_view_format, format_swizzle, vulkan_swizzle, vulkan_format), and the T# -> set 0 binding does two of them under the descriptor lock. The table is now indexed at compile time: by Vulkan format for the core range (< 256, the VK_EXT_4444_formats rows above it keep the scan) and by 9-bit GFX10 code (first row and row count). Each lookup returns the first row in table order, as the scan did; a static_assert keeps the rows of one code adjacent so the code's range is exactly the rows the scan visited. gfx10_format_bench times the lookups against the old scans (kept in the bench as the reference) and its --self-test, run by ctest, checks both agree on 502 formats x 1103 codes x cast/no cast. On a Ryzen host the SRV lookup sequence goes from ~111 ns to ~5 ns (about 20x). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Windows, synthetic inputs. Tested c77db34. I compiled gfx10_format_bench with MSVC x64 (/O2 /std:c++20) and ran the CPU self-test. The reference and indexed paths agreed across 502 formats, 1103 codes and 1,107,412 view-format queries. In the bundled per-SRV benchmark the median of seven runs of one million iterations was 73.33 ns for the scan and 3.42 ns for the index (21.5x). This measures just the lookup sequence. AI-assisted verification · GPT-6.2 Astra Medium |
|
Tested c77db34 on NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 build 26300, VS 2022 Build Tools (MSVC 19.44), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo: pass. Built Synthetic inputs only, no game files. AI-assisted (Claude Code). |
TEST validation — ApproveValidated on CPU (no GPU required for the test itself). Tests added: Verification:
Performance: SRV lookup sequence ~111 ns → ~5 ns (~20x speedup). Note: Author tested on AMD Radeon RX 6800 (gfx1030), but the change and tests are CPU-only — GPU was context only. Recommendation: Approve / merge. CPU-validatable, thoroughly tested (1.1M cross-check queries), performance confirmed by independent reviewers. |
|
Tested c77db34 on Windows 11 Pro 10.0.26300, MSVC 14.51 (VS Build Tools 2026), Windows SDK 10.0.26100, NVIDIA GeForce RTX 4060 / 621.24, Khronos Vulkan headers via Merged onto main dde82f2 (clean), full runtime build, AI-assisted (Claude Code). No game files. |
|
Tested
AI-assisted: yes (Claude ran the build and tests; results checked by me). |
Claim: self-proposed perf item, claimed in #7804 (#7804 (comment); no item ID in the tables). Depends on: none.
What
format_row,vulkan_formatandvulkan_view_formatinruntime/src/gfx10_descriptors.hwalked the 94-rowformat_tableon every call. One SRV/UAV view makes five of these lookups (format_from_vulkan,vulkan_view_format,format_swizzle,vulkan_swizzle,vulkan_format; seed3d12_vulkan_device.cpparound 4528–4579), and the T# → set 0 binding (bind_image, ~1136) does two of them while holdingdescriptor_mutex.The table is now indexed at compile time:
< 256). TheVK_EXT_4444_formatsrows above that range (A4R4G4B4/A4B4G4R4,1000340000+) and unknown values still use the scan.vulkan_view_formatnow visits only the rows of its code.Behaviour is unchanged. Each lookup still returns the first row in table order, as the scan did. A
static_assertkeeps all rows of one code next to each other, so[first, first + count)holds exactly the rows the scan would have matched. Out-of-range codes (>= 512) giveVK_FORMAT_UNDEFINED, as before. The table itself is not edited, and no open PR touches these lines (I checked #3128, #5170 and #5666, which edit other parts of the file).Numbers
runtime/test/gfx10_format_bench.cpp(new) times the call sequence of one SRV view over a mix of 18 common frame formats (BC1–7, RGBA8/sRGB, BGRA8, RGBA16F, R11G11B10, RGB10A2, R32F, D32→R32F, a cast). It runs the new lookups against the old linear scans, which the bench keeps as the reference. Release build, llvm-mingw clang 20261117, median of 15 runs × 2,000,000, three invocations:So each SRV view's format work drops by about 95%. This is CPU time on the descriptor-creation path, and part of the time
bind_imageholds the descriptor lock. It is not per-draw time. Creating the Vulkan image view, on abind_imagemiss, still dominates that path.Tests
gfx10_descriptors_testadds checks against a first-match scan for every table row, and checks that every unlisted code< 1024and unlisted format< 1024resolves to UNDEFINED/null. It also pins edge cases:vulkan_format(5) == R8_UINT(not S8), the 4444 extension formats,0x7FFFFFFF,0xFFFFFFFF, and second rows of a code (B8G8R8A8_UNORM→B8G8R8A8_SRGBunder 130). Passes.gfx10_format_bench --self-test(new ctestgfx10_format_bench_selftest) compares old and new on 502 formats × 1,103 codes × cast/no-cast, 1,107,412vulkan_view_formatqueries in total. Also compared:format_row,format_from_vulkan,format_swizzle,vulkan_format. All agree.-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF, llvm-mingw, Ninja, Release): 67 of 68 pass.vk_queue_query_syncfailed once underctest -j8and again in a--repeat until-fail:5run, but passed on its own. That test does not includegfx10_descriptors.h(checked withninja -t deps), so it is not affected by this change.scripts/run_gpu_tests.py(full run, ~95 s): 223 of 241 passed, 17 skipped, 1 failure (ms_wave_info_s3). The same failure shows on unmodifiedorigin/mainwith the same build (--filter ms_wave_info, run twice), so it was there before this change.Tested on AMD Radeon RX 6800 (gfx1030), AMD Software 26.11.2, Windows 11 Pro.
AI-assisted (Claude Code, Claude Opus 5.5).
🤖 Generated with Claude Code