fix(agc): sample 5_6_5, 1_5_5_5 and 4_4_4_4 textures in AMD's channel order #2386
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2386"
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?
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-09T17:09:02Z.
What
Textures in
5_6_5_UNORM(133),1_5_5_5_UNORM(134) and4_4_4_4_UNORM(136) are sampled with their channels in the wrong order.On AMD hardware the first component of a packed format sits in the least significant bits. Mesa's
gfx10_format_table.pyreverses the size list of each name ("Keep the bit sizes in little-endian order"). So:TextureFormat.cppmaps them toVK_FORMAT_R5G6B5_UNORM_PACK16,VK_FORMAT_A1R5G5B5_UNORM_PACK16andVK_FORMAT_R4G4B4A4_UNORM_PACK16. Those Vulkan formats name the most significant field first: R5G6B5 has R in bits 11..15, A1R5G5B5 has R in bits 10..14, and R4G4B4A4 has R in bits 12..15 and A in bits 0..3 (Formats).ViewComponentssends DST_SEL X straight toVK_COMPONENT_SWIZZLE_R. So a 5_6_5 texel0x001f(X = 1) samples as (0, 0, 1, 1), and 1_5_5_5 swaps red and blue the same way. In 4_4_4_4 the order is fully reversed, so X comes back from the alpha nibble.radv uses the same three Vulkan formats and compensates in the view swizzle:
vk_format.cmaps them toPIPE_FORMAT_B5G6R5_UNORM,B5G5R5A1_UNORMandA4B4G4R4_UNORM.This adds
TextureComponentChannel, which gives the Vulkan channel that holds a guest component: X, Y, Z, W read B, G, R, B for 133 (a DST_SEL W of 5_6_5 returns X, measured on gfx1035 in review), B, G, R, A for 134, and A, B, G, R for 136.ViewComponentscomposes it after DST_SEL, so every sampled view of these formats reads the bits the guest meant, with any swizzle. The VkFormats are unchanged, and no other format is affected.Tests:
RunTextureFormatTestschecks, for each component of the three formats, that the chosen Vulkan channel starts at the guest bit (low-bit table taken from the Vulkan format definitions).agc_driver_image_packed16_load(new) fills a 256×1 texture of each format, with every component either all zeros or all ones. It then checksimage_loadof every texel andimage_sample_lzof texel 0 on the GPU, with DST_SEL X Y Z W and Z Y X W.Found by comparing AnyPS5's GFX10 format tables with Mesa's and the Vulkan format definitions. Two independent passes flagged the same three entries.
Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at
d70b8998:agc_driver_graphicsandagc_driver_image_packed16_loadpass with--repeat until-fail:3on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU.TextureComponentChannelreturning the component unchanged, as on main, both fail:format 133 component 0 is not read from bit 05_6_5_UNORM image_load X Y Z W: texel 0 component 0 is 0x00000000, expected 0x3f800000on the RTX 4070.Checklist
main; no other open PR implements the same thing🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T17:44:06Z.
Linux run: Linux 7.2 (x86_64), Intel(R) Graphics (RPL-S) (Mesa 26.3.0-devel, Vulkan 1.4.363), GCC 16.2.1, Release,
-DBUILD_TESTING=ON, #2386 (6fa4b70a) tested on currentmain(0fdda7be).tests/agc_driver_graphics_tests: passes cleanly on Vulkan (Graphics validation tests passed), verifying the channel order updates for 5_6_5, 1_5_5_5 and 4_4_4_4 textures.tools/check_conventions.py: passes cleanly.TextureFormat.cpp.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:02:53Z.
Review: CHANGES_REQUESTED
Checked on RDNA2 (gfx1035) with the hardware oracle:
image_loadandimage_sample_lzof 133/134/136, one bit set per row, DST_SEL X Y Z W and Z Y X W. X/Y/Z of all three formats and W of 1_5_5_5 and 4_4_4_4 come from the bits the PR says. Build,texture_format_lookup,agc_driver_graphicsandagc_driver_image_packed16_loadpass here, and the new execution test fails without the change.One thing to fix before merging:
0x001freads W = 1.0,0x07e0and0xf800read W = 0, and0x1234reads W = 0.645 = X, through bothimage_loadandimage_sample_lz. Another 3-channel format (30) does the same. The PR maps W to Vulkan's A, which is 1, andImagePacked16Load.cpp:116pins that (masks[component] == 0u ? One). So the test fixes a value the hardware doesn't produce. Either map W to the X channel for 133 (Bin R5G6B5) and expect X in the test, or throw for DST_SEL W on 133, as converted 10_11_11 already does (TechnicalDebt, "Converted unorm images"). In both cases, add a TechnicalDebt line saying it was measured on gfx1035.Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-10T10:43:58Z.
Validated this on Windows — adds NVIDIA dGPU + an AMD iGPU to the RTX 4070 / Intel iGPU coverage in the PR description.
Setup: Windows 11 (10.0.26200), WinLibs GCC
15.2.0posix-14.0.0-ucrt-r7(the CI Windows toolchain), Ninja, Release,BUILD_TESTING=ON, PR head6fa4b70a.Ran
agc_driver_image_packed16_loadandagc_driver_graphicson each device:agc_driver_image_packed16_loadagc_driver_graphicsI also confirmed the new test actually exercises the bug (not a pass-through): with
TextureComponentChannelreturning the component unchanged — i.e. themainbehavior —agc_driver_image_packed16_loadfails on the 5090:…and passes again with the fix applied. So this is a positive confirmation on my hardware, not just "ran the PR's test and it passed".
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-10T15:22:08Z.
Thanks for measuring it. I went with the first option: for 5_6_5, W now selects X (
Bof R5G6B5), so DST_SEL W reads the low 5 bits as you measured.TextureComponentChannel(133, A)returnsVK_COMPONENT_SWIZZLE_B. 1_5_5_5 and 4_4_4_4 are unchanged.RunTextureFormatTestsexpects bit 0 for W of 133.ImagePacked16Loadnow expects W = X for 5_6_5; that's the line you pointed at, so the test no longer pins 1.Rebased on main
de5e541d.agc_driver_graphics,agc_driver_image_packed16_loadandtexture_format_lookuppass with--repeat until-fail:3on the RTX 4070 and the Intel iGPU. With W mapped back to A, both checks fail (format 133 component 3 is not read from bit 0, and5_6_5_UNORM image_load X Y Z W: texel 1 component 3 is 0x3f800000, expected 0x00000000).check_conventions.pypasses.Not changed here: format 36 (B10G11R11_UFLOAT) is another 3-channel format with no remap, so its DST_SEL W still reads Vulkan's 1. I haven't measured it.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:34:06Z.
Review: APPROVED
Checked on current main:
agc_driver_graphics,agc_driver_image_packed16_loadandtexture_format_lookuppass;agc_driver_image_packed16_loadfails without the change. The 5_6_5 DST_SEL W = X now matches what we measured on gfx1035, and the TechnicalDebt entry says so. Windows/NVIDIA/Intel runs by @klosixgaming-arch and @Kikoarl cover what we can't run here. Merging.Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T23:30:31Z.
agc_driver_image_packed16_loadfails onmainin CI'slinuxjob (lavapipe, llvmpipe LLVM 20.1.2) since this merged: runs 38092384980 at06b489d9and 38092669169 ata28a79c7both end with4_4_4_4_UNORM image_load X Y Z W: texel 0 component 0 is 0x00000000, expected 0x3f800000.Cause, measured in a container with CI's packages (ubuntu 24.04,
mesa-vulkan-drivers25.2.8-0ubuntu0.24.04.4): that lavapipe reports no format features forVK_FORMAT_R4G4B4A4_UNORM_PACK16(vulkaninfo omits it, whileB4G4R4A4,A4R4G4B4andA4B4G4R4_UNORM_PACK16are listed withSAMPLED_IMAGE_BIT).ResolveTextureFormatmaps 4_4_4_4 (136) toR4G4B4A4regardless, the texture is created, and a copy of this test that prints instead of throwing shows every channel reading 0 for all 240 non-zero texels and all 32 sampled threads, for both swizzles, while 5_6_5 and 1_5_5_5 are exact in the same run. Deterministic: 10 of 10 runs fail. The same binary passes on Mesa 26.0.8 (llvmpipe LLVM 21.1.8), which listsR4G4B4A4with full features, so it is a gap in the lavapipe CI gets, not in the channel order this PR fixed.CI stays red on that runner until 4_4_4_4 is either skipped when the format reports no features or mapped to a format that driver supports;
B4G4R4A4_UNORM_PACK16(also a mandatory Vulkan 1.0 sampled format) is reported by both Mesa versions.Thanks @krishnaraya4, the new test is what caught this.
AI-assisted: yes (Claude Code Fable 5.1 xhigh)