Repository navigation
borealis,agx: close G17P bounded-UBO and dynamically-indexed sampler codegen gaps - #1246
Conversation
…elision hk_nir_border_address() only matched static 64-bit descriptor offsets of the form base + imm64. Dynamically-indexed sampler arrays (such as DXVK's separate sampler descriptors) compute set_ptr + u2u64(dyn + imm32), so hk_is_border_emulation_if() failed to match clamp_0_sampler_index against unbiased_clamp_0_sampler_index and kept full custom-border emulation on every SampleLevel/txl instruction even when no custom-border sampler exists on the device. Extend hk_nir_border_address() to match base + u2u64(dyn + imm32) (as well as zero-offset u2u64(dyn) and power-of-two shift-disjoint ior folding) and require identical base and dynamic index with the exact field delta. Add positive and negative unit tests in test-border-index.cpp. Signed-off-by: DjDeveloperr <hey@djdev.me>
…oads On G17P (!soft_fault), robust buffer loads (used by every DXVK shader) are lowered by lower_load_global_bounded() and hk_lower_aligned_ubo() to a bounds check selecting AGX_ZERO_PAGE_ADDRESS when out of bounds. Three gaps prevented these guarded loads from reaching native codegen parity: 1. hk_nir_lower_descriptors.c did not mark statically indexed, non-partially-bound dynamic buffer descriptors with ACCESS_BUFFER_DESCRIPTOR_AGX (unlike static UBO/SSBO descriptors). 2. lower_load_global_bounded() and hk_lower_aligned_ubo() omitted ACCESS_CAN_SPECULATE even when the underlying descriptor is guaranteed valid (or null with size == 0) and out-of-bounds accesses are clamped to AGX_ZERO_PAGE_ADDRESS. Constant loads inside loops stayed trapped in the loop body, preventing preamble hoisting and bloating the loop body past the 4x runtime-unroll threshold. 3. agx3_uniform_dma_buffer() and agx3_vertex_preamble_only_forwards() only matched unguarded pack_64_2x32_split(desc.x, desc.y) pointers, missing G17P's bounded bcsel(..., AGX_ZERO_PAGE_ADDRESS) form even though AGX3_UNIFORM_DMA_BUFFER already zero-fills past buffer.size. Fix all three gaps, add pre-unroll direct-body LICM for speculatable constant-load chains (agx_nir_opt_licm_direct_const_loads) under the same 56-half register-pressure budget as agx_nir_opt_licm_direct_sfu, and add unit tests covering direct constant-load LICM and bounded uniform DMA. Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 984f7df4658b920af15ca6597c54950d745c3d1d (code is ready; a row from a second GPU generation at this head is still owed before it can land, see below)
Blockers: none
Checked:
- Read the whole diff of both commits and the body.
- Border elision (
hk_nir_border_index.h, callerhk_is_border_emulation_if). The dynamic match requires the same base scalar, the same dynamic scalar (has_dynmust agree on both sides) and the exact field delta. Theiorform is only accepted when the other operand isishl(x, s)with constants < 32andc < 2^s, so the bits really are disjoint andior == iaddfor everyx. A 32-bit wrap ofdyn + immcannot cause a wrong elision. The match only identifies which branch is the emulation branch. Dropping the branch is still gated device-wide onpdev->border_emulation(any custom-border sampler created flips it, and the serialized twin is kept), so no dynamic index can reach a custom-border sampler in an elided shader. The only CLAMP_TO_0 samples come fromagx_nir_lower_custom_border. - Bounded loads (
hk_shader.c). The bounds check itself is unchanged: OOB still selectsAGX_ZERO_PAGE_ADDRESS, and the offset is either clamped or a constant now checked asoffset + load_size <= AGX_ZERO_PAGE_SIZE. Before, it was a fixed+16, which was wrong for 32-byte loads, so the new check is tighter and more correct. Speculation is only added for NON_WRITEABLE|CAN_REORDER, non-coherent/volatile loads whose base and size come from the sameACCESS_BUFFER_DESCRIPTOR_AGXload. That flag means a statically indexed, non-partially-bound, non-variable-count descriptor, which is valid whenever it is statically used. Null descriptors give size 0 and so go to the zero page. Unbound sparse pages map to the zeroed page. The new dynamic-bufferalways_validmirrors the existing static UBO/SSBO rule exactly. Descriptor buffers cannot hold dynamic buffers. The gating isagx_has_soft_fault()(DRM_ASAHI_FEATURE_SOFT_FAULTS) and the chip-info descriptor generation, so there is no raw chip-id compare. - Constant clamp fold in
load_descriptor/load_image_handle:MIN2(const, array_size - 1)is the same valuenir_uminwould fold to. - LICM (
agx_licm_filter_const_load). Same shape as the existingagx_licm_filter_sfu: dominate-exit invariants as before, plus direct-body chains that end in a CAN_SPECULATEload_global_constant. It refuses loops with terminate. Descriptor-only loads do not start a chain. Only loads that cannot fault are hoisted, so a zero-trip loop is safe.load_global(writable SSBO) is never a candidate, so no load moves past a store or barrier. - Uniform DMA (
agx3_uniform_dma_is_bounded_check). All four accepted predicate forms are equivalent tooff + size <= desc.size, withusub_satcoveringsize < load_size - 1. Condition, size word and address words must all come from the same descriptor load, and loads are dword-aligned and at least 4 bytes. A partially OOB vector load is zeroed per dword by DMA but whole-vector by the software path, which is fine under the robustness 16-byte rule. - Local drm-shim gate, head merged into
aurora-wipef132f5 (clean merge, tree eb79f6e5): 337/338. The only failure ishk_sync_stamps, the known #1235/#1213 clash that also fails on the base, so there are no new failures. The newBorderIndex.*,LicmDirectConstLoads*andBoundedDynamicUboPromotesToUniformDmatests pass. - Tests without the fix: I put
agx_compile.candhk_nir_border_index.hback to the base versions and kept the new tests.BorderIndex.MatchesOnlyRelatedImmutableDescriptorFieldsthen fails 4 assertions (lines 60/63/66/77) andBoundedDynamicUboPromotesToUniformDmafails (lines 1158/1159). The LICM tests exercise the new pass itself.
Non-blocking:
- No unit test covers the speculation flags added in
lower_load_global_bounded/hk_lower_aligned_ubo, or the dynamic-descriptorACCESS_BUFFER_DESCRIPTOR_AGX. Only the CTS rows cover them. agx3_vertex_preamble_only_forwardscounts the bounds-check ALU as free even when the condition also feeds a load that is not DMA'd. This only affects the cost heuristic, not correctness.
Rows at this head: J700 (G17P) is in the body (robustness2 uniform/storage buffer, ubo.random, descriptor_indexing texel buffer, border_swizzle). Missing: a second generation. The constant clamp fold is in shared descriptor lowering for every generation, and the gen-9 dynamic-descriptor flag is not G17P-only. A J713 row (G16G, gen 9) covering robustness.robustness2.buffer, ubo., binding_model descriptor indexing and pipeline.samplerborder would cover both.
Evidence
- Merged gate:
meson test --suite asahi --suite polyonaurora-wipef132f5 + 984f7df -> Ok 337, Fail 1 (hk_sync_stamps, baseline). - Fix-reverted run (
agx_tests --gtest_filter='BorderIndex.*:FeatureMatchingOpts.LicmDirect*:FeatureMatchingOpts.BoundedDynamic*'): 6 passed, 2 failed (BorderIndex.MatchesOnlyRelatedImmutableDescriptorFields,FeatureMatchingOpts.BoundedDynamicUboPromotesToUniformDma).
|
|
Resolve against #1291 (212c440) and #1246 (984f7df) in hk_lower_aligned_ubo(): keep the dynamically indexed vec4 element-bounds fast path behind #1291's upfront constant-bound inline-block check, propagate ubo_root_always_valid() / ACCESS_CAN_SPECULATE on the fast-path global constant load, reuse hk_lower_aligned_ubo_nir(), and update test-brl-aligned-ubo.c to call hk_lower_aligned_ubo_nir() and expect explicit I/O for constant-bound inline uniform blocks. Signed-off-by: Erik Bourget <erik@ebourget.net>
What
Close two general Borealis / AGX3 shader codegen gaps on G17P (
!soft_fault) that caused large instruction bloat and loop-load penalties on robust Vulkan / DXVK shaders:Recognize dynamically-indexed samplers in custom-border emulation elision (
hk_nir_border_index.h):hk_nir_border_address()previously matched only staticbase64 + imm64descriptor offsets. Dynamically-indexed sampler descriptor arrays (used by DXVK's separate sampler heap) computeset_ptr + u2u64(dyn + imm32)(or zero-offsetu2u64(dyn)/ power-of-two shift-disjointior), causinghk_is_border_emulation_if()to reject everySampleLevel/txlsample and retain full custom-border emulation + border-swizzle preambles even when no custom-border sampler exists on the device.hk_nir_border_address()to match dynamically-indexed descriptor offsets with identical base, identical dynamic index, and exact field delta, with unit tests intest-border-index.cpp.Speculate, hoist before unrolling, and uniform-DMA bounded G17P buffer loads (
hk_nir_lower_descriptors.c,hk_shader.c,agx_nir_opt_licm.c,agx_compile.c):clamp_desc_array_bounds(MIN2(const_idx, array_size - 1)instead of an unfoldednir_uminthat forcednir_def_is_const(index)tofalseon every robust shader) and attachACCESS_BUFFER_DESCRIPTOR_AGXto statically-indexed, non-partially-bound dynamic buffer descriptors (UNIFORM_BUFFER_DYNAMIC/STORAGE_BUFFER_DYNAMIC), matching static UBO/SSBO descriptors.lower_load_global_bounded()andhk_lower_aligned_ubo()loads withACCESS_CAN_SPECULATEwhen they are read-only, reorderable, non-coherent/non-volatile, guarded ontoAGX_ZERO_PAGE_ADDRESS, and backed by anACCESS_BUFFER_DESCRIPTOR_AGXdescriptor. Also tightenbound_offset()'s zero-page constant check tooffset + load_size <= AGX_ZERO_PAGE_SIZE.agx_nir_opt_licm_direct_const_loads()(parallelingagx_nir_opt_licm_direct_sfu()under the same 56-half register-pressure cap) beforeagx_nir_unroll_runtime_loops()so loop-invariant speculatable constant loads and their bounds checks move out of loops before unroll-budget counting.agx3_uniform_dma_buffer()andagx3_vertex_preamble_only_forwards()to recognize G17P's boundedbcsel(valid, desc.xy, AGX_ZERO_PAGE_ADDRESS)form whenvalidis an exact bounds predicate againstdesc.z, promoting constant-offset robust UBO reads toAGX3_UNIFORM_DMA_BUFFER.test-agx3-feature-matching-opts.cpp.Tested
DEFAULT_BRANCH=aurora-wip ./.github/aurora/agent-policy.sh pr HEAD->PR is clean../rig/fedora-mesaci.sh 984f7df4658b920af15ca6597c54950d745c3d1d): 218/218 PASS (0failures,0timeouts,0new warnings).J700, Apple A18 ProG17P B1, kernel7.3.0-41) exact-commit same-bootABBA+BAAB(base=4a868406592vshead=984f7df4658,n=4per arm,MESA_SHADER_CACHE_DISABLE=true,dxvk.enableStateCache = False):gpubench-d3d11 compute.heavy kind=alu(d=4):1463.79 us->1168.22 us(-20.19%/1.253x, matching native Vulkanvk_alu1196.17 us). Shader unrolls 4x (i201:g21vsi142:g27), zero loop loads, all 3 UBO fields promoted toAGX3_UNIFORM_DMA_BUFFER.gpubench-d3d11 render.postfx msaa=1,1440p(d=2):1392.77 us->1351.39 us(-2.97%); all 3 fragment shaders matchHK_PERF=noborderhashes bit-for-bit (postfx_downi113:g47->i57:g31,postfx_upi86:g47->i40:g31,postfx_tonemapi83:g39->i61:g31,0remainingCLAMP_TO_0samples).gpubench-d3d11 render.deferredVS (vs-fb492fb3): vertex software preamble eliminated viaAGX3_UNIFORM_DMA_BUFFER.gpubench-d3d11 compile.pso kind=graphics(count=32, clean cache):2.67 ms->2.58 ms(-3.42%).gpubench-vkcontrols:vk_alu1193.32->1196.17 us(+0.24%),vk_postfx1996.02->992.06 us(-0.40%),vk_fill672.05->673.86 us(+0.27%).base == head) on all verified D3D11 and Vulkan cases.deqp-vk,head=984f7df4658):dEQP-VK.robustness.robustness2.bind.notemplate.*.uniform_buffer*: 3456/3456 PASS (0fail,768not supported).dEQP-VK.robustness.robustness2.bind.notemplate.*.storage_buffer*: 13824/16896 PASS (0fail,3072not supported).dEQP-VK.ubo.random.scalar_types.*: 25/25 PASS (0fail).dEQP-VK.descriptor_indexing.uniform_texel_buffer*: 10/10 PASS (0fail).dEQP-VK.pipeline.monolithic.sampler.border_swizzle.r8g8b8a8_unorm.*: 948/1280 PASS,112pre-existingopaque_white.gather.*computefailures matchingbase=4a868406592identically (948pass /112fail /220not supported),0failures on allcustomborder and allgraphicscases.stock.shPRE==POST (0diffs),kfaults_delta=0,avc_delta=0across all runs.Risk
ACCESS_CAN_SPECULATEis only attached to bounded loads guarded ontoAGX_ZERO_PAGE_ADDRESSthrough statically-indexed, non-partially-bound, non-variable-count descriptors (ACCESS_BUFFER_DESCRIPTOR_AGX), preserving fault safety for partially-bound and dynamically-indexed descriptors.agx3_uniform_dma_buffer()only accepts bounded loads whose predicate exactly matches[offset_B, offset_B + size_B)againstdesc.zfor dword-aligned 32-bit+ loads, matchingAGX3_UNIFORM_DMA_BUFFER's zero-fill contract.hk_nir_border_address()requires matching descriptor set base, matching dynamic index expression, and exact field offset delta (clamp_0_sampler_index - unbiased_clamp_0_sampler_index).Not yet
UPDATE_AFTER_BINDdescriptor sets remain ineligible forAGX3_UNIFORM_DMA_BUFFER(by design inhk_static_set_mask()).compute.conv2dremaining gap vs native Vulkan stems fromZeroInitializeWorkgroupMemoryadding a workgroup clear + barrier and DXVK's per-submit event-queryvk-meta-fill-bufferdispatch/flush; dead shared-memory zero-init elision is left for follow-up work.