Repository navigation
borealis,agx: fix AGX2 texel buffer tail height and 4-byte RGB32 offsets - #1136
Conversation
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>
There was a problem hiding this comment.
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 belowceil((elements + tail) / 16384).CreateBufferView, the descriptor-buffer path and the PBE all use the same height.elements + tail ≤ 2^28keeps the height within the 14-bit field, in 64-bit arithmetic. - Robustness: the bound is
buffer_size_swwithout 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_agx2andagx_chip_agx3_path.
Not blocking
- The
MAX2(…, 1)height inhk_buffer_view.capplies 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:174returnsVK_ERROR_FORMAT_NOT_SUPPORTED, whichvkCreateBufferViewmay not return. Valid usage can't reach it now thatmaxTexelBufferElementsis 15 lower, so this is cosmetic.
|
b086cbd J316s (M1 Pro, G13S C0, stock 7.3.0-aurora-fleet89, assert-enabled Borealis overlay ICD) PASS: native aarch64 |
|
|
RyanTheTide
left a comment
There was a problem hiding this comment.
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):
- base
aurora-wip90211df6816: 335/335 OK. - batch build:
90211df6816with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into currentaurora-wipd2e883ab2e3): 335/336 OK. The one failure,agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails.
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:
+ tail_offset_elin AGX2texture.heightandpbe.heightin bothhk_CreateBufferView()andhk_texel_buffer_descriptor()(matching the AGX3 paths), reject views whoseelements + tail_offset_elexceedsAGX_TEXTURE_BUFFER_MAX_SIZEin 64-bit arithmetic before packing, and reserve the worst-case 15 R8 tail texels inmaxTexelBufferElementswhenever single-texel alignment is advertised.VK_FORMAT_R32G32B32_{SFLOAT,UINT,SINT}uniform texel buffers (offset & 0xfin{0, 4, 8, 12}) on AGX2 while keepingAGX_TEXTURE.address16-byte aligned: encode the sub-16-byte tail in 4-byte components (0..3) inbuffer_offset_sw, null the PBE descriptor for uniform-only RGB32 views, pass rawview_coordtolibagx_texture_load_rgb32(), and addd.buffer_offset_swinside the 32-bit component index with explicit 4-byte load alignment (uint3_align4). Gallium setsbuffer_offset_sw = 0for 64-byte-aligned GL buffer textures so its RGB32 path is unchanged, and AGX3/M5 keeps its metadata address path.Closes: #943
Tested:
-Db_ndebug=false -Dbuild-tests=true -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dtools=asahi -Dplatforms= -Dglx=disabled) andmeson test --suite asahi: 213/213 passed (0 failed, 0 skipped, 0 warnings in touched files), including new unit testshk_buffer_view(AGX2 G13G/G14G and AGX3 G17Phk_CreateBufferView+hk_texel_buffer_descriptor) andAgx2TexelBuffer.*inagx_tests(evaluating lowered AGX2 NIR with compiledlibagxagainst packedAGX_TEXTUREdescriptors for RGB32 4-byte tails, OOB/negative/zero-element bounds, non-RGB32 row wrap, and null descriptors).Not yet:
Risk: two-way · AGX2 Macs (M1, M2 family) on Borealis