Skip to content

borealis: implement VK_EXT_depth_clamp_control - #1346

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
m0d16l14n1:j815/depth-clamp-control
Nov 29, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
m0d16l14n1:j815/depth-clamp-control

Conversation

@m0d16l14n1

Copy link
Copy Markdown

What: Implement VK_EXT_depth_clamp_control. With depth clamp on, the min/max Z of each scissor record (what the hardware clamps to) now comes from the user range when the mode is USER_DEFINED_RANGE, in the generic viewport path and in the HAL200 draw-state viewports of the native bind tail. The range is dynamic state: it re-emits the viewport records, and the bind-tail snapshot keeps the mode and range so a cached viewport payload is not reused across a range change.
Tested: J815 MacBook Air 15" M5 (T8142, G17G), Borealis, kernel 7.3.0-aurora-j815-dev, at 2fe6cb3 vs base 8bad0a5: depth clamp/fragdepth/depth range list (6,065): 273 -> 383 Pass, 110 fixes, 0 regressions; all 188 depth_clamp_control cases: 112 Pass, 76 NotSupported (D24 formats, depthRangeUnrestricted); earlier negative control (range ignored): 80 of the 112 fail; dEQP gate 0 diffs; meson test --suite asahi 223/223; Godot TPS demo 1080p FSR2 voxel GI (FAST=1): 49.4 / 49.7 static, 57.3 route vs 49.5 / 49.7, 57.5 base (neutral). 0 GPU faults. Regression line: 0 SELinux denials (N/A on this image), 0 failed units, 0 new kernel errors.
Risk: two-way door · all Borealis Macs; draws that do not set a user range take the same values as before.
Not yet: G13-G16 and M5 Pro/Max hardware; VK_KHR_depth_clamp_zero_one is not included (the CTS has no functional test for it).

Details
  • hk_depth_clamp_bounds(): clamp off -> [0, 1] as before; USER_DEFINED_RANGE -> the range; otherwise the viewport min/max. Used by hk_flush_vp_state() and hk_g17p_draw_state_viewports().
  • IS_DIRTY(VP_DEPTH_CLAMP_RANGE) joins IS_DIRTY(RS_DEPTH_CLAMP_ENABLE) at both viewport flush sites; hk_g17p_bind_tail_viewport_dyn_matches() compares the mode and range when clamp is on.
  • Without depthRangeUnrestricted the user range lies in [0, 1].
Evidence

Commands (gpu-perf):

CASE_S=60 python3 tools/deqp-ab.py r3-dcc deqp-lists/dcc-20261129.txt a=<base 8bad0a5741b ICD> b=<2fe6cb3338b ICD>
CASE_S=60 python3 tools/deqp-ab.py r3-dccgate deqp-lists/gate-20261128.txt a=<base> b=<2fe6cb3338b>
FAST=1 tools/mesa-ab.sh r3-tps a=<base> ... f=<2fe6cb3338b> (one arm per PR head)

dcc-20261129.txt: depth_clamp|clamp_zero_one|clamp_range|zero_one|fragdepth|depth_range minus depth_range_unrestricted and texture_gather

caselist deqp-lists/dcc-20261129.txt (6065 cases)
a (base) 2 s: {'Pass': 273, 'NotSupported': 5792} new GPU fault lines: 0
b (2fe6cb3) 2 s: {'Pass': 383, 'NotSupported': 5682} new GPU fault lines: 0
b vs a: 110 diffs, 0 regressions, 110 fixes
   dEQP-VK.draw.dynamic_rendering.complete_secondary_cmd_buff.depth_clamp.d16_unorm_clamp_control_half_viewport_range: NotSupported -> Pass
   dEQP-VK.draw.dynamic_rendering.complete_secondary_cmd_buff.depth_clamp.d16_unorm_clamp_control_half_viewport_range_dynamic: NotSupported -> Pass
   dEQP-VK.draw.dynamic_rendering.complete_secondary_cmd_buff.depth_clamp.d16_unorm_clamp_control_input_negative: NotSupported -> Pass
   dEQP-VK.draw.dynamic_rendering.complete_secondary_cmd_buff.depth_clamp.d16_unorm_clamp_control_input_negative_dynamic: NotSupported -> Pass
   ...

Gate (15,958, broad regression list):

caselist deqp-lists/gate-20261128.txt (15958 cases)
a (base) 128 s: {'Pass': 11230, 'NotSupported': 4728} new GPU fault lines: 0
b (2fe6cb3) 127 s: {'Pass': 11230, 'NotSupported': 4728} new GPU fault lines: 0
b vs a: 0 diffs, 0 regressions, 0 fixes

Godot TPS demo, 1080p FSR2 voxel GI, FAST=1 (BENCH lines, a = base, f = this PR):

a BENCH view=1 frames=742 fps=49.5 ms_p50=20.15 ms_p95=22.44 ms_p99=24.37 ms_max=58.0 gpu_p50=19.95 gpu_p95=20.66 cpu_p50=4.06
a BENCH view=1 frames=100 fps=49.7 ms_p50=20.01 ms_p95=22.12 ms_p99=24.18 ms_max=24.2 gpu_p50=20.04 gpu_p95=20.70 cpu_p50=4.53
a BENCH view=play frames=1383 fps=57.5 ms_p50=17.34 ms_p95=20.48 ms_p99=21.85 ms_max=24.3 gpu_p50=17.05 gpu_p95=19.89 cpu_p50=2.15
f BENCH view=1 frames=741 fps=49.4 ms_p50=20.22 ms_p95=22.05 ms_p99=24.79 ms_max=55.0 gpu_p50=19.95 gpu_p95=20.68 cpu_p50=4.04
f BENCH view=1 frames=100 fps=49.7 ms_p50=20.09 ms_p95=23.29 ms_p99=23.71 ms_max=24.0 gpu_p50=20.03 gpu_p95=20.53 cpu_p50=4.33
f BENCH view=play frames=1378 fps=57.3 ms_p50=17.38 ms_p95=20.73 ms_p99=22.16 ms_max=44.9 gpu_p50=17.08 gpu_p95=19.96 cpu_p50=2.11

With depth clamp enabled, the hardware clamps depth to the min/max Z of
each scissor record, which hk filled from the viewport depth range. Take
them from the user range instead when the clamp mode is
VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT, in both the generic and the
native bind-tail viewport paths (shared hk_depth_clamp_bounds()).

The range is dynamic state (VP_DEPTH_CLAMP_RANGE): it re-emits the
viewport records like the clamp enable does, and the bind-tail snapshot
keeps the mode and range so a cached viewport payload is not reused
across a range change.

Without depthRangeUnrestricted the user range lies within [0, 1], so
the clamp-disabled bounds are unchanged.

Signed-off-by: Nick <nekreshen@yandex.ru>
@m0d16l14n1
m0d16l14n1 requested review from a team and DjDeveloperr as code owners November 29, 2026 09:43

@aurora-silicon-review aurora-silicon-review Bot 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 2fe6cb33

Blockers: none.

Checked:

  • Audited all 3 changed files (src/asahi/vulkan/hk_cmd_buffer.h, src/asahi/vulkan/hk_cmd_draw.c, src/asahi/vulkan/hk_physical_device.c, +48/-11) and every depth_clamp / DEPTH_CLAMP reference across hk_cmd_draw.c.
  • Shared hk_depth_clamp_bounds() cleanly handles all three states (clamp disabled -> [0, 1], VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT -> user [minDepthClamp, maxDepthClamp], viewport range -> [MIN2, MAX2]) for both hk_flush_vp_state() and hk_g17p_draw_state_viewports().
  • Dynamic state tracking is complete: IS_DIRTY(VP_DEPTH_CLAMP_RANGE) triggers both viewport flush sites, hk_g17p_flush_dynamic_state_fast() falls back to slow whenever VP_DEPTH_CLAMP_RANGE is dirty, and hk_g17p_bind_tail_dyn_capture() / hk_g17p_bind_tail_viewport_dyn_matches() capture and compare depth_clamp_mode and depth_clamp_range (two floats, no padding) when depth_clamp_enable is active.
  • Exact-head J815 M5 (G17G) Borealis A/B verification: 6,065 depth-clamp/fragdepth/depth-range cases 273 -> 383 Pass (110 fixes / 0 regressions), all 188 depth_clamp_control cases 112 Pass / 76 NotSupported (negative control failed 80/112), 15,958-case dEQP gate 0 diffs, meson test --suite asahi 223/223, Godot TPS neutral, 0 GPU faults.
  • DCO Signed-off-by: present; no Apple material or policy issues.
Evidence
  • Diff: hk_cmd_buffer.h, hk_cmd_draw.c, hk_physical_device.c (+48/-11).
  • Audited hk_g17p_flush_dynamic_state_fast() L15738 and dirty.cull L13274 to confirm no fast-path or PPP-state bypass on VP_DEPTH_CLAMP_RANGE.
  • Note (non-blocking): G13–G16 and M5 Pro/Max hardware not yet run; viewport scissor Z clamp path is shared.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 2fe6cb3338be from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip 8bad0a57 + #1330 #1336 #1337 #1339 #1341 #1342 #1343 #1345 #1346 #1347 #1348) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@RyanTheTide

Copy link
Copy Markdown

Merge-train finding, holding this one out of batch 11. The rest of the batch lands without it.

The new VK_EXT_depth_clamp_control exposure turns dEQP-VK.draw.dynamic_rendering.primary_cmd_buff.depth_clamp.d32_sfloat_s8_uint_clamp_control_input_positive_dynamic from NotSupported to:

  • Pass on M1 Pro (J316s, G13S, 7.3.0-aurora-edge).
  • DeviceLost, 3/3 run alone on M4 Air (J713, G16G, 7.3.0-aurora-fleet85), with one kernel IOCTL: submit failed! ... err: EINVAL per run and 0 firmware crashes. The base arm reports NotSupported 3/3 on the same boot.

J713's fleet85 kernel already rejects a family of d32/s8 stencil and tess/geom submits with EINVAL on plain aurora-wip, so this may be that kernel bug and not this PR. I can't show that without a G16G on the Edge kernel. Could you post this case at this head from a G16G (or any AGX3 Mac) on the Edge kernel? If it passes there, this PR goes into the next batch as-is. If it EINVALs there too, the depth-clamp path builds a submission the kernel refuses on G16G. Evidence: traces/gpu/20261128-mergetrain-mesa/j713-comb11-depthclamp-rerun.txt.

@m0d16l14n1

Copy link
Copy Markdown
Author

Ran it on an AGX3 Mac at this head (2fe6cb3):

  • J815 MacBook Air 15" M5 (T8142, G17G), kernel built from aurora-silicon/linux main af1413ddc1c7 plus the J815 board patches (7.3.0-aurora-j815-dev).
  • dEQP-VK.draw.dynamic_rendering.primary_cmd_buff.depth_clamp.d32_sfloat_s8_uint_clamp_control_input_positive_dynamic, run alone 3/3: Pass, Pass, Pass. 0 kernel log lines during the runs (no EINVAL, no faults). The base arm (aurora-wip 724e94e) reports NotSupported on the same boot.
  • The renderpass variant (draw.renderpass.depth_clamp.d32_sfloat_s8_uint_clamp_control_input_positive_dynamic) also passes. The 128-case depth clamp list (draw.*.depth_clamp, clipping.clip_volume.depth_clamp) is 76 Pass, 0 Fail. The 15,958-case gate shows 0 diffs against its base (8bad0a5).

So on G17G the depth-clamp path builds a submission the kernel accepts. That points at the fleet85 d32/s8 EINVAL family rather than this PR. I don't have a G16G to check that kernel directly.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 2fe6cb3338be from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip 082b9e9c + #1344 #1346 #1350 #1354 #1357) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 2fe6cb3338be.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

@RyanTheTide
RyanTheTide merged commit a3866ea into aurora-silicon:aurora-wip Nov 29, 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.

2 participants