Skip to content

borealis,agx: fix AGX2 texel buffer tail height and 4-byte RGB32 offsets - #1136

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx2-texel-buffer-offset
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx2-texel-buffer-offset

Conversation

@AxxzyWasTaken

Copy link
Copy Markdown

What:
Fixes two AGX2 texel-buffer descriptor bugs when single-texel alignment produces a non-zero sub-16-byte tail offset, and adds host unit tests for both descriptor packing and NIR lowering:

  1. Include + tail_offset_el in AGX2 texture.height and pbe.height in both hk_CreateBufferView() and hk_texel_buffer_descriptor() (matching the AGX3 paths), reject views whose elements + tail_offset_el exceeds AGX_TEXTURE_BUFFER_MAX_SIZE in 64-bit arithmetic before packing, and reserve the worst-case 15 R8 tail texels in maxTexelBufferElements whenever single-texel alignment is advertised.
  2. Support 4-byte component-aligned VK_FORMAT_R32G32B32_{SFLOAT,UINT,SINT} uniform texel buffers (offset & 0xf in {0, 4, 8, 12}) on AGX2 while keeping AGX_TEXTURE.address 16-byte aligned: encode the sub-16-byte tail in 4-byte components (0..3) in buffer_offset_sw, null the PBE descriptor for uniform-only RGB32 views, pass raw view_coord to libagx_texture_load_rgb32(), and add d.buffer_offset_sw inside the 32-bit component index with explicit 4-byte load alignment (uint3_align4). Gallium sets buffer_offset_sw = 0 for 64-byte-aligned GL buffer textures so its RGB32 path is unchanged, and AGX3/M5 keeps its metadata address path.

Closes: #943

Tested:

  • Native assert-enabled host build (-Db_ndebug=false -Dbuild-tests=true -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dtools=asahi -Dplatforms= -Dglx=disabled) and meson test --suite asahi: 213/213 passed (0 failed, 0 skipped, 0 warnings in touched files), including new unit tests hk_buffer_view (AGX2 G13G/G14G and AGX3 G17P hk_CreateBufferView + hk_texel_buffer_descriptor) and Agx2TexelBuffer.* in agx_tests (evaluating lowered AGX2 NIR with compiled libagx against packed AGX_TEXTURE descriptors for RGB32 4-byte tails, OOB/negative/zero-element bounds, non-RGB32 row wrap, and null descriptors).

Not yet:

  • On-hardware AGX2 (M1/M2) Vulkan CTS run covering single-texel-aligned texel buffers and 4-byte-aligned RGB32 descriptor-buffer views.

Risk: two-way · AGX2 Macs (M1, M2 family) on Borealis

AGX2 advertises single-texel alignment for uniform and storage texel buffers, decomposing sub-16-byte offsets into a 16-byte-aligned base address and a software tail in buffer_offset_sw. Two bugs broke views with non-zero tail offsets:

1. Both hk_CreateBufferView() and hk_texel_buffer_descriptor() computed AGX2 texture.height and pbe.height from elements alone, omitting + tail_offset_el. Whenever elements + tail_offset_el crossed a multiple of AGX_TEXTURE_BUFFER_WIDTH (16384), the trailing tail_offset_el valid texels mapped past the 2D texture/PBE height and were clamped to zero on reads or dropped on writes. Include + tail_offset_el in the height calculation, reject views that exceed AGX_TEXTURE_BUFFER_MAX_HEIGHT cleanly before packing, and reserve the worst-case 15 R8 tail elements in maxTexelBufferElements whenever single-texel alignment is advertised.

2. Under uniformTexelBufferOffsetSingleTexelAlignment, 3-component RGB32 formats (blocksize 12) permit 4-byte component alignment, so (offset & 0xf) may be 4 or 8 in addition to 0 or 12. Previously hk_CreateBufferView() asserted on non-multiple-of-12 tails and hk_texel_buffer_descriptor() emitted a null descriptor. Because AGX_TEXTURE.address requires 16-byte alignment, store the sub-16-byte tail in 4-byte components (0..3) in buffer_offset_sw for AGX2 emulated RGB32 descriptors, pass the raw view coordinate to libagx_texture_load_rgb32(), and add d.buffer_offset_sw inside the 32-bit word index (with 4-byte load alignment). Gallium packs buffer_offset_sw = 0 for 64-byte-aligned GL buffer textures, so its RGB32 address math is unchanged, and AGX3/G17P continues to use its metadata address path.

Add host unit tests covering AGX2/AGX3 buffer view and descriptor-buffer packing plus AGX2 NIR texel-buffer lowering.

Closes: aurora-silicon#943
Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 26, 2026 11:10

@DjDeveloperr DjDeveloperr left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict merge at b086cbd83208 once a G14 (M2) row is in. The J316s (G13S) row at this head passes: 210/210 host tests and 902/0 CTS. The AGX2 descriptor path is shared by G13 and G14, so it needs one row on each generation. Thanks for this.
Blockers none.
Checked

  • Tail height: the last texel, elements - 1 + tail, always lands in a row below ceil((elements + tail) / 16384). CreateBufferView, the descriptor-buffer path and the PBE all use the same height. elements + tail ≤ 2^28 keeps the height within the 14-bit field, in 64-bit arithmetic.
  • Robustness: the bound is buffer_size_sw without the tail. An out-of-bounds coordinate takes the hardware path and reads 0, and RGB32 reads run only in bounds.
  • RGB32: the read is base16 + (coord * 3 + w) * 4, which is correct for tails of 0, 4, 8 and 12 and stays inside the view. Unaligned descriptor-buffer addresses get a null descriptor.
  • There are no chip gates or switches. Scope is through hk_texel_rgb32, hk_descriptor_generation_is_agx2 and agx_chip_agx3_path.

Not blocking

  • The MAX2(…, 1) height in hk_buffer_view.c applies on every chip. On G17P/M5, a view with zero elements used to fail and now succeeds; every fetch from it reads 0. That's an improvement, but the PR's "AGX2 only" isn't quite true.
  • hk_buffer_view.c:174 returns VK_ERROR_FORMAT_NOT_SUPPORTED, which vkCreateBufferView may not return. Valid usage can't reach it now that maxTexelBufferElements is 15 lower, so this is cosmetic.

@RyanTheTide

Copy link
Copy Markdown

b086cbd J316s (M1 Pro, G13S C0, stock 7.3.0-aurora-fleet89, assert-enabled Borealis overlay ICD) PASS: native aarch64 meson test --suite asahi 210/210 PASS; vulkaninfo reports maxTexelBufferElements=268435441 and uniform/storageTexelBufferOffsetSingleTexelAlignment=true; live Vulkan CTS 902 PASS / 0 FAIL / 0 warnings (dEQP-VK.api.buffer_view.* 656/1004 [348 NS], dEQP-VK.binding_model.descriptor_buffer.*texel* 210/390 [180 NS], dEQP-VK.*r32g32b32*texel* 36/108 [72 NS]); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 AVC, stock Mesa untouched.

@RyanTheTide

Copy link
Copy Markdown

b086cbd83208 J413 (M2 Air, Apple M2 (G14G B0), 7.3.0-aurora-fleet89, Borealis overlay ICD) PASS: maxTexelBufferElements=268435441, uniform/storageTexelBufferOffsetSingleTexelAlignment=true, live VK CTS 902 PASS / 0 FAIL (api.buffer_view.* 656/1004 [348 NS], binding_model.descriptor_buffer.*texel* 210/390 [180 NS], *r32g32b32*texel* 36/108 [72 NS]), 0 GPU faults, Enforcing, 0 failed, 0 AVC.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at b086cbd83208

Blockers: none

Checked: Read the whole diff. Tail height: DIV_ROUND_UP(elements + tail_offset_el, 16384) is used by the texture, the PBE and the descriptor-buffer path alike, and the elements > MAX - tail_offset_el check runs before packing, so the 14-bit height cannot overflow; maxTexelBufferElements now reserves the 15 R8 texels whenever single-texel alignment is advertised. RGB32: buffer_offset_sw holds the 4-byte word tail (0..3), coord * 3 + offset_sw stays in 32 bits for 2^28 elements, the load is aligned(4), and passing view_coord instead of coord is right because the tail is now added inside the libagx load (Gallium keeps offset_sw 0). Nulling the PBE for RGB32 is safe: hk_get_buffer_format_features() never exposes STORAGE_TEXEL_BUFFER for the non-power-of-two RGB32 formats. On G17P the RGB32 metadata path is unchanged. No chip gates added; the descriptor generation decides. Exact-head rows on both AGX2 generations are on the PR (J316s G13S 902/0 CTS, J413 G14G 902/0 CTS), and the gate is green.

Evidence

Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):

This was referenced Nov 27, 2026
@RyanTheTide
RyanTheTide merged commit b743ac3 into aurora-silicon:aurora-wip Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

borealis: AGX2 texel buffer height omits tail_offset_el and descriptor-buffer rejects 4-byte-aligned RGB32

3 participants