graphics: resolve table border colors from the guest border color table #431

Closed
github-bot wants to merge 1 commit from gh-pr/431/head into gh-pr/431/base
Owner

@⁠brandostrong on GitHub · 2026-08-31 21:54 UTC · original
brandostrong:fix/border-color-table-v2 → main · +114 −34 · 7 files · 1 commits · closed without merging

Summary

  • Record the border color table base from TA_BC_BASE_ADDR / TA_CS_BC_BASE_ADDR instead of discarding it.
  • Resolve border_color_type == 3 by reading that table and creating the sampler through VK_EXT_custom_border_color.
  • Use the float border color constants instead of the integer ones.

Problem

The sampler descriptor's border color type selects opaque black, transparent black, opaque white, or a color at an index into a guest-resident table. Kyty handled the first three and substituted transparent black for the fourth:

temporary: approximating table border color as transparent black, index = %u

The registers holding the table base were already being parsed and then thrown away by HwCtxIgnoreBorderColorTableAddr / HwUcIgnoreBorderColorTableAddr, so everything needed to do this properly was already reaching the command processor.

Separately, every sampler was created with VK_BORDER_COLOR_INT_*. Those are only valid for a sampler used with an integer-format image, and the surfaces sampled through this path are float or normalized. On the driver I tested it happens not to matter, since the int and float constants carry the same values, but the combination is unspecified.

Implementation

  • TA_BC_BASE_ADDR / _HI (graphics) and TA_CS_BC_BASE_ADDR / _HI (compute) now store the table base, on both the direct and indirect paths. The two are kept as separate state and selected by shader stage, matching the register split.
  • The register pair holds the base shifted right by 8, so the address is reassembled as (lo << 8) | ((hi & 0xff) << 40). The remaining bits of the high register are reserved and masked off.
  • kFromTable reads four floats at base + border_color_ptr * 16 and sets VK_BORDER_COLOR_FLOAT_CUSTOM_EXT. VK_EXT_custom_border_color is enabled when the device exposes it with both customBorderColors and customBorderColorWithoutFormat; without it the transparent-black approximation stays, now rate-limited to four lines instead of one per sampler.
  • The sampler cache key grows from the four descriptor words to those plus the resolved color, so two identical descriptors resolved against different table contents no longer collide.
  • The three fixed types move to the FLOAT constants. Happy to split that into its own PR if you would rather keep the two apart.

Sources

  • AMD RDNA2 Instruction Set Architecture Reference Guide, image sampler resource (S#): 107:96 border color ptr, 127:126 border color type — "Opaque-black, transparent-black, white, use border color ptr".
  • The numeric ordering for those four kinds is the one already in gpu_defs.h (kTransBlack = 0 through kFromTable = 3); the guide lists the kinds without assigning values.
  • The register offsets, the shift, and the reserved bits in the high register were checked against the platform's own graphics register definitions.

Testing

  • Builds clean on Windows (clang-cl) off 6453baf.
  • All suites pass except RenderExecutorStencilBindingDiscovery, which fails identically on clean origin/main, so this adds no new failure.
  • The table path is unverified in a real title. In GTA V (PPSA04264), which is what is tested against, border_color_type == 3 never occurs — a run with warnings unsuppressed logged zero "approximating table border color" lines. So the read is correct against the descriptor layout and by construction, not by observation. Titles that do not use the table are unaffected apart from the int-to-float constant change.
  • No automated regression is included. Exercising this needs a guest-resident table at a live GPU address, which the existing host/GPU fixtures do not construct.

Not covered

bc_swizzle (T# 123:121), which reorders border color channels independently of the dst_sel_* fields, is not applied — identity ordering is assumed. Worth adding if a title turns up that both uses the table and sets it.

AI assistance

Entirely

**@⁠brandostrong** on GitHub · 2026-08-31 21:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/431) `brandostrong:fix/border-color-table-v2` → `main` · +114 −34 · 7 files · 1 commits · closed without merging ## Summary - Record the border color table base from `TA_BC_BASE_ADDR` / `TA_CS_BC_BASE_ADDR` instead of discarding it. - Resolve `border_color_type == 3` by reading that table and creating the sampler through `VK_EXT_custom_border_color`. - Use the float border color constants instead of the integer ones. ## Problem The sampler descriptor's border color type selects opaque black, transparent black, opaque white, or a color at an index into a guest-resident table. Kyty handled the first three and substituted transparent black for the fourth: ``` temporary: approximating table border color as transparent black, index = %u ``` The registers holding the table base were already being parsed and then thrown away by `HwCtxIgnoreBorderColorTableAddr` / `HwUcIgnoreBorderColorTableAddr`, so everything needed to do this properly was already reaching the command processor. Separately, every sampler was created with `VK_BORDER_COLOR_INT_*`. Those are only valid for a sampler used with an integer-format image, and the surfaces sampled through this path are float or normalized. On the driver I tested it happens not to matter, since the int and float constants carry the same values, but the combination is unspecified. ## Implementation - `TA_BC_BASE_ADDR` / `_HI` (graphics) and `TA_CS_BC_BASE_ADDR` / `_HI` (compute) now store the table base, on both the direct and indirect paths. The two are kept as separate state and selected by shader stage, matching the register split. - The register pair holds the base shifted right by 8, so the address is reassembled as `(lo << 8) | ((hi & 0xff) << 40)`. The remaining bits of the high register are reserved and masked off. - `kFromTable` reads four floats at `base + border_color_ptr * 16` and sets `VK_BORDER_COLOR_FLOAT_CUSTOM_EXT`. `VK_EXT_custom_border_color` is enabled when the device exposes it with both `customBorderColors` and `customBorderColorWithoutFormat`; without it the transparent-black approximation stays, now rate-limited to four lines instead of one per sampler. - The sampler cache key grows from the four descriptor words to those plus the resolved color, so two identical descriptors resolved against different table contents no longer collide. - The three fixed types move to the `FLOAT` constants. Happy to split that into its own PR if you would rather keep the two apart. ## Sources - AMD RDNA2 Instruction Set Architecture Reference Guide, image sampler resource (S#): `107:96 border color ptr`, `127:126 border color type` — "Opaque-black, transparent-black, white, use border color ptr". - The numeric ordering for those four kinds is the one already in `gpu_defs.h` (`kTransBlack` = 0 through `kFromTable` = 3); the guide lists the kinds without assigning values. - The register offsets, the shift, and the reserved bits in the high register were checked against the platform's own graphics register definitions. ## Testing - Builds clean on Windows (clang-cl) off `6453baf`. - All suites pass except `RenderExecutorStencilBindingDiscovery`, which fails identically on clean `origin/main`, so this adds no new failure. - **The table path is unverified in a real title.** In GTA V (PPSA04264), which is what is tested against, `border_color_type == 3` never occurs — a run with warnings unsuppressed logged zero "approximating table border color" lines. So the read is correct against the descriptor layout and by construction, not by observation. Titles that do not use the table are unaffected apart from the int-to-float constant change. - No automated regression is included. Exercising this needs a guest-resident table at a live GPU address, which the existing host/GPU fixtures do not construct. ## Not covered `bc_swizzle` (T# `123:121`), which reorders border color channels independently of the `dst_sel_*` fields, is not applied — identity ordering is assumed. Worth adding if a title turns up that both uses the table and sets it. ## AI assistance Entirely
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:34 +00:00
github-bot closed this pull request 2026-11-26 09:20:34 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.