Skip to content

agx, hk: address robust buffer accesses at the offset their bounds check tested - #559

Merged
RyanTheTide merged 2 commits into
aurora-silicon:aurora-wipfrom
funkzy:pr/agx-robust-offsets
Nov 20, 2026
Merged

RyanTheTide merged 2 commits into
aurora-silicon:aurora-wipfrom
funkzy:pr/agx-robust-offsets

Conversation

@funkzy

@funkzy funkzy commented Nov 20, 2026 •

Copy link
Copy Markdown

With robust buffer access, nir_lower_explicit_io checks each storage and uniform buffer access on its 32-bit byte offset, amul(index, stride) plus member offsets. The check therefore tests the offset modulo 2^32. AGX address lowering treats amul as a product that does not wrap, and rebuilds the address from the unwrapped index in four places:

  • the relaxed lea rules;
  • the zero-extended constant fold;
  • the index fold;
  • the stride rescale in fold_byte_offset.

When the product wraps, the address accessed then differs from the offset checked by a multiple of 4 GiB. This series makes robust accesses use exactly the checked offset, and fixes a related fold for byte accesses near 2 GiB.

Changes

  1. agx, hk: address robust buffer accesses at the offset their bounds check tested.
    • A new agx_shader_key::checked_offsets is set by Honeykrisp when storage or uniform buffers are robust.
    • Under it, agx_nir_lower_address turns every 32-bit amul into imul before fusing, so only the exact rules (agx: take a shifted index at its scale only where the shift cannot wrap #379) apply: an index is taken unwrapped only where range analysis proves the product cannot wrap.
    • scale_is_exact no longer treats the SPIR-V no-wrap decorations as that proof for these shaders.
    • SSBO descriptor array indices are covered the same way.
    • Shaders without robust buffers compile byte-identically.
  2. agx: fix byte accesses in the last 32 KiB of a 2 GiB buffer. fold_byte_offset excluded negative addends only for a byte stride, but the overflow depends on the access's scale. A byte access in the last 32 KiB of a 2 GiB buffer could be addressed 4 GiB too low. This applies with or without robustness.

Cost

Robust shaders lose some folded address modes. Instructions on the M5 profile, before → after:

Shape Before After
uint[] indexed by gl_GlobalInvocationID 14 15
Header + vec4[] loop 34 39
Stride-12 records 26 37
  • No cost: D3D-style raw buffers and gl_LocalInvocationIndex indices, whose range is proven.
  • Possible recovery: some of the cost might come back with a max_workgroup_count in agx_nir_options. Without it, range analysis cannot bound gl_GlobalInvocationID.

Testing

dEQP-VK on the Mac Studio

Run with and without the series, in the same boot. As with the test above, the series was applied on top of #362, which the M5 Ultra needs to run Vulkan. Each case gave the same result on both builds. There were no GPU faults.

Set Cases Pass NotSupported
robustness.buffer_access, robustness.pipeline_robustness 2879 1622 1257
robustness.robustness2, storage and uniform buffer cases 34020 18360 15660
ssbo.layout, ssbo.unsized_array_length 5287 5260 27
ubo 13240 13240 0
spirv_assembly.instruction.compute: 8-bit storage, 16-bit storage, variable pointers 883 693 190

…eck tested

With robustBufferAccess or robustBufferAccess2, nir_lower_explicit_io
checks each storage and uniform buffer access on its 32-bit byte
offset, amul(index, stride) plus member offsets, and accesses
base + u2u64(offset). The check tests that offset modulo 2^32. Address
lowering instead takes amul as a product that does not wrap: the
relaxed lea rules, the zero-extended constant fold, the index fold and
the stride rescale in fold_byte_offset all rebuild the address from the
unwrapped index. For an index whose product wraps, the address
accessed then differs from the offset checked by a multiple of 4 GiB.

amul's no-wrap promise holds only for a valid access, and an access
the check admits need not be valid. Add agx_shader_key::
checked_offsets, which Honeykrisp sets when storage or uniform buffers
are robust. agx_nir_lower_address then makes every 32-bit amul an imul
before it fuses anything, so only the exact rules apply: an index is
taken unwrapped at its scale only where range analysis proves the
product cannot wrap (scale_is_exact), and otherwise as the product
shifted back. The same holds for SSBO descriptor array indices, which
are checked against the binding's size the same way.

scale_is_exact no longer takes a no-wrap flag as that proof for checked
offsets: the flags come from the shader's SPIR-V decorations, and a
shader that breaks them still gets the checked offset.

Shaders without robust buffers are unchanged.

test-lower-address-checked-offsets.cpp lowers p + u2u64(offset) for
offsets amul(x, d), amul(x, d) + c, amul(x + k, d) and
amul(x + k, d) + c with strides 1-64, member offsets up to 0x7ff0 and
k = -1, 1, 3, for 8- to 32-bit loads and stores and 32-bit atomics
under every option set, and checks that each access names base plus
the 32-bit offset for indices across 2^28-2^32. It also checks the
forms above, that no-wrap flags do not move a checked access, and
that a range-bounded index is still taken unwrapped at the stride's
scale.

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
fold_byte_offset turns an index amul(i + c, stride) into i * stride
plus the byte offset c * stride, with i * stride a sign-extended 32-bit
product. For c < 0 that product exceeds the valid offset by up to the
byte offset's 32 KiB range, so in the last 32 KiB of a 2 GiB buffer it
can pass 2^31 and turn negative: a byte array of 3-byte records read at
a[i - 1] = offset 0x7ffffffe went to 2 GiB below the buffer instead.
The fold excluded c < 0 only for a byte stride, but the overflow
depends on the scale, not the stride: where the access scales the index
by 2 or more, the product stays below 2^30 + 2^14. Require c >= 0 at a
byte scale instead.

LowerAddressCheckedOffsets.ValidOffsetsKeepTheirAddressUnchecked lowers
the same offset forms without checked offsets and checks every valid
offset (below 2^31), including the last elements of a 2 GiB buffer.

Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
@funkzy
funkzy marked this pull request as ready for review November 20, 2026 02:22
@RyanTheTide

RyanTheTide commented Nov 20, 2026 •

Copy link
Copy Markdown

Lab row from the M4 Pro (J616s). A = aurora-wip e7e9ef3, B = A + this PR (d5ade7b) + #561. Native release builds, user-space overlay, same kernel:

  • dEQP-VK robustness.{robustness2,buffer_access,robustness1_vertex_access,pipeline_robustness}.* (85,483 cases) together with ssbo.*, binding_model.{descriptorset_random,descriptor_buffer}.*, descriptor_indexing.*, memory_model.message_passing.* and compute.pipeline.*: 169,809 cases, identical case by case (92,023 Pass / 77,786 NotSupported on both).
  • 0 GPU firmware crashes, no GPU errors in the kernel log.

An AGX2 row (M1 Pro or M2) is next. The x86 suite on the combined tree is running too.

@RyanTheTide

Copy link
Copy Markdown

M1 Pro (G13S) row. A = aurora-wip 173d51d, B = A + #561 + #559 + #562. Native release builds, user-space overlay, same kernel (7.3.0-aurora-fleet74):

  • dEQP-VK ssbo.*, robustness.{robustness2,buffer_access,robustness1_vertex_access,pipeline_robustness}.*, binding_model.{descriptorset_random,descriptor_buffer}.*, descriptor_indexing.*, memory_model.message_passing.*, compute.pipeline.*: 169,809 cases, identical case by case (44,342 Pass / 125,467 NotSupported on both).
  • dEQP-GLES3/31 fragment_ops, fbo, shaders.{operator,indexing}, draw, texture.format, blend (every second case): 7,082 cases, identical (7,053 Pass on both).
  • No GPU errors in the kernel log.

@RyanTheTide
RyanTheTide merged commit 852af85 into aurora-silicon:aurora-wip Nov 20, 2026
@funkzy

funkzy commented Nov 20, 2026

Copy link
Copy Markdown
Author

@erikwb, the two commits here came from your report and follow the fix you suggested in it, and they were merged without saying so. That was an omission on our side. For the record: Reported-by and Suggested-by Erik Bourget (erikwb). Our other open pull requests from your reports now carry both trailers.

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.

2 participants