fix(vk): map the NVN 5-5-5 and BGRA8 formats by their bit layout #924
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!924
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:fix/vk-555-formats"
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?
Type: fix · Risk: low · Tested on: Windows, AMD Radeon RX 9070 XT · Needs: none
Why
Textures in the NVN formats BGR5, BGR5A1, A1BGR5, BGRA8 and BGRA8_SRGB had no Vulkan format, so
texture_get()left them out ("NVN format ... has no Vulkan format: its textures are left out") and the game drew without them. RGB5 was mapped to B5G5R5A1, whose bits run the other way, so its colors and alpha came out scrambled.How to reproduce
Seen on: not seen in the game: found by reading
vk_format()ingpu/vk/vk_formats.cpp; any texture in one of these formats is dropped (logged once per format) or shown with the wrong colorsSettings and switches: defaults
Steps: game-free:
python -I -B tests/test_555_formats.py --source <main checkout>(the test from this PR); it readsvk_format()and the sampled view's swizzle invk_texture.cppExpected: each of these formats maps to the Vulkan format with its bit layout, and the sampled view fixes R/B order and the missing alpha
Actual: on main five of them map to UNDEFINED and RGB5 to B5G5R5A1; the test fails with ten problems
What changed
vk_format()maps the 5-5-5 and BGRA8 formats by their bit layout, and the sampled view swaps R and B, or reads alpha as one, where the Vulkan format cannot express the NVN one directly.vk_format()ingpu/vk/vk_formats.cpp:A1R5G5B5_UNORM_PACK16; A1BGR5 ->R5G5B5A1_UNORM_PACK16(new; they were UNDEFINED).A1R5G5B5_UNORM_PACK16, with RGB5A1 (wasB5G5R5A1_UNORM_PACK16).B8G8R8A8_UNORM, BGRA8_SRGB ->B8G8R8A8_SRGB(new; they were UNDEFINED).texture_view()ingpu/vk/vk_texture.cpp: BGR5 and RGB5 join the formats whose sampled view reads alpha as one; RGB5A1 and RGB5 get R and B swapped in the view's swizzle.V1_NVNinnx2/pipeline_states.py(the VkFormat -> NVN table used to convert old pipeline state lists) follows the mapping: Vulkan format 6 (R5G5B5A1_UNORM_PACK16) now converts to A1BGR5 (0x98), and 7 (B5G5R5A1_UNORM_PACK16) no longer has an NVN twin.tests/test_555_formats.py(new).Second commit, "leave A1BGR5 textures out where the GPU does not sample R5G5B5A1":
vk_format()ingpu/vk/vk_formats.cpp: A1BGR5 maps toR5G5B5A1_UNORM_PACK16only wherer5g5b5a1_sampled()(new, asked once withvkGetPhysicalDeviceFormatProperties) findsVK_FORMAT_FEATURE_SAMPLED_IMAGE_BITinoptimalTilingFeatures; elsewhere it isVK_FORMAT_UNDEFINEDand the texture is left out, as on main.tests/test_555_formats.pychecks that gate;tests/test_pipeline_state_portable.pycutsr5g5b5a1_sampled()into its fixture withvk_format();tests/test_pipeline_states.pyreads avk_format()case whose return asks such a function.R5G5B5A1_UNORM_PACK16has no mandatory support (the mandatory format support tables listA1R5G5B5, notR5G5B5A1). An image made in a format the device does not support for its usage breaks VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts".The bug, step by step:
B5G6R5_UNORM_PACK16, whose name lists the high bits first.A1R5G5B5, and A1BGR5 (A low) isR5G5B5A1.vk_format()had no case for them, nor for BGR5, BGRA8 and BGRA8_SRGB: they fell todefault: return {VK_FORMAT_UNDEFINED, ...}.texture_get()returnsnullptrfor an UNDEFINED format, so those textures were never made or bound.B5G5R5A1, which has R in the high bits and alpha in bit 0: every channel read from the wrong bits.A1R5G5B5(B low) and the sampled view swaps R and B. RGB5 and BGR5 have no alpha bit in the guest data, so their view reads alpha as one.This breaks no Vulkan rule: the textures were left out or read with the wrong bit layout.
Before (
vk_formats.cpp):After:
texture_view(), after:Measurements
Verdict: it fixes the bug:
test_555_formatsfails on main and passes here;test_pipeline_state_portablefails on main (its fixture from this PR cutsr5g5b5a1_sampled(), which main lacks) and passes here;test_pipeline_statespasses on both (it guards the V1_NVN table). Both interleaved runs gave the same result. No speed change is expected.Hardware: AMD Radeon RX 9070 XT, Windows; the tests are game-free (they read source or build a cut-out fixture, they do not use the GPU); Python 3.12
Scene: none, game-free
Method: the tests from this PR run against each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave
How to reproduce:
python -I -B tests/<test>.pywith--source <checkout>(and--cxx/--headerswhere the test asks for them) on each sidec167ec679d050e5dtests/test_555_formats.py, run 1tests/test_pipeline_state_portable.py, run 1tests/test_pipeline_states.py, run 1tests/test_555_formats.py, run 2tests/test_pipeline_state_portable.py, run 2tests/test_pipeline_states.py, run 2tests/test_555_formats.py, mediantests/test_pipeline_state_portable.py, mediantests/test_pipeline_states.py, medianFlags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12:
test_555_formatspasses (fails on main), and the other checks that readvk_formats.cpporV1_NVNpass:test_pipeline_states,test_pipeline_state_portable,test_native_astc_texture_count. Of the checks that importnx2/pipeline_states.py, these pass:test_dev_packs,test_pipeline_notes_open,test_pipeline_share,test_pipeline_state_computes,test_pipeline_state_counts,test_pipeline_state_sources,test_ship_state_list,test_state_list_plain;test_game_layout,test_lift_cacheandtest_pipeline_tourfail the same way on main on this PC (a missing program, numpy not installed, a tour run without--vk-profile), unrelated to this change.Built and played: this commit builds on Windows (llvm-mingw back end) and on Linux (
longshot_vk.so, without and with AMD FSR 4). Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.Not tested: a texture in one of these formats looked at in the game: not checked in the game (which textures use them was not traced). Linux was built, not run.
Must be tested: None:
A1R5G5B5_UNORM_PACK16is a format every Vulkan device must sample;B8G8R8A8must be sampled by every device too;R5G5B5A1_UNORM_PACK16need not be, and A1BGR5 is left out wherevkGetPhysicalDeviceFormatPropertiesdoes not report it sampled.Risks
What could break: textures that were left out now appear; if one of them was wrong for another reason it now shows. RGB5 textures change colors (they were scrambled). Pipeline state lists recorded by older builds with a
R5G5B5A1attachment now convert it to A1BGR5 instead of RGB5A1;B5G5R5A1ones are no longer converted (no NVN format uses it now).Turning it off: revert the commit.
Compatibility: Pipeline state lists in version 1 with a 5-5-5 attachment convert as described above; nothing else changes.
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (the checks that read the changed code, on this PR, Windows: all pass excepttest_game_layout,test_lift_cache,test_pipeline_tour, which fail the same way onmainon this PC)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_555_formats.py)tests/that reads changed source updated in this PR, not weakened. (tests/test_555_formats.pyadded; no check removed)longshot_vk.sowithout and with AMD FSR 4)WIP: fix(vk): map the NVN 5-5-5 and BGRA8 formats by their bit layoutto fix(vk): map the NVN 5-5-5 and BGRA8 formats by their bit layoutCode-only review of
034b3aaf4a; informational findings, with final approval left to another reviewer.No new correctness defect found in the mapping and sampled-view changes. RGB5/RGB5A1 remap the swizzle sources after descriptor/view selection, and the alpha-one substitution composes with that remap. The version-1 pipeline conversion change removes the obsolete B5G5R5A1 mapping and adds the newly supported R5G5B5A1 mapping consistently with the format switch.
The reported Windows RX 9070 XT game run and Windows/Linux builds are useful smoke coverage. The description correctly notes that no texture using the affected formats was identified and visually checked; those results therefore do not establish the advertised color correction in-game. A targeted packed-color sample/readback or before/after scene using the affected formats would close that gap. The new
test_555_formats.pymostly matches source spelling: for example, removing the alpha assignment while leaving the case labels would still satisfy its alpha-one check. Prefer a behavioral packed-pixel/swizzle fixture, including view overrides and BGR5 alpha, alongside the mapping checks.Merge coordination: PR 452 implements the same RGB5/RGB5A1 production correction with an exhaustive CPU fixture; this PR additionally covers BGR5/BGR5A1/A1BGR5 and BGRA8. Consolidate the shared fix once and preserve the stronger coverage. If both tests remain, reconcile this test's exact
// (X formats read alpha as one)marker with 452's changed comment, or the combined test will fail before checking the mapping. The broader PR 451 also overlaps these format mappings.Read the complete diff, surrounding sampled-view/cache code, NVN enums, pipeline conversion and its existing checks, and the overlapping 452 production diff. No tests, builds, generators or game runs performed. No active-work claim was present in the checked PR thread/team snapshot; the current head has no previous formal reviews.
034b3aaf4a9d050e5ddfNew commit, "leave A1BGR5 textures out where the GPU does not sample R5G5B5A1" (
9d050e5d); the branch is rebased onto main @c167ec67.R5G5B5A1_UNORM_PACK16has no mandatory support (the mandatory format support tables listA1R5G5B5, notR5G5B5A1). An image made in a format the device does not support for its usage breaks VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts".vk_format()ingpu/vk/vk_formats.cpp: A1BGR5 maps toR5G5B5A1_UNORM_PACK16only wherer5g5b5a1_sampled()(new, asked once withvkGetPhysicalDeviceFormatProperties) findsVK_FORMAT_FEATURE_SAMPLED_IMAGE_BITinoptimalTilingFeatures; elsewhere it isVK_FORMAT_UNDEFINEDand the texture is left out, as on main.tests/test_555_formats.pychecks that gate;tests/test_pipeline_state_portable.pycutsr5g5b5a1_sampled()into its fixture withvk_format();tests/test_pipeline_states.pyreads avk_format()case whose return asks such a function.test_555_formatsfails on main and passes here;test_pipeline_state_portablefails on main (its fixture from this PR cutsr5g5b5a1_sampled(), which main lacks) and passes here;test_pipeline_statespasses on both (it guards the V1_NVN table). Run twice each side, interleaved; What changed and Measurements in the description are updated.This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (
longshot_vk.so, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.