Skip to content

Fix iOS AR passthrough: pixel format crash, tile thread-budget overruns, missing render prep, and reverse-Z mismatch - #1427

Merged
untoldengine merged 1 commit into
developfrom
issue/1425
Dec 1, 2026
Merged

untoldengine merged 1 commit into
developfrom
issue/1425

Conversation

@untoldengine

Copy link
Copy Markdown
Owner

Summary

Fixes #1425 and several follow-on bugs found while chasing it down on an iPhone 11 running UntoldGaussian iOS AR.

  • Pixel format crash (UntoldEngineAR crashes on every frame: captured-image pipeline pixel format mismatch #1425): UntoldEngineAR's captured-image pipeline hardcoded .bgra8Unorm_srgb, but it's bound against environmentColorMap (.rgba16Float) — a guaranteed Metal validation crash on every frame that draws the passthrough background. Now reads the format off environmentColorMap directly.
  • Light-tile thread-budget crash: tileLightStage(for:) left tileWidth/tileHeight at 0 (Metal auto-picks), but Metal could pick a tile whose thread count exceeds the pipeline's own maxTotalThreadsPerThreadgroup — seen under ARKit camera capture, where the GPU's tile budget is squeezed. Now requests an explicit square tile sized to fit both the memory and thread budgets. Applied the same fix to the Gaussian pass's tile dispatch, which had the identical hardcoded-32×32 problem.
  • AR passthrough color overexposed: fixing the pixel format above exposed that capturedImageFragmentShader never linearized the camera's gamma-encoded YCbCr→RGB output. The target holds linear HDR scene radiance (same contract as fragmentEnvironmentShader), so the un-decoded gamma values were read downstream as far brighter than they are. Added the sRGB-to-linear decode.
  • iOS AR rendered nothing at all (meshes or Gaussian splats): UpdateXRRenderingSystem — the function UntoldEngineAR drives every frame — never ran frustum culling, never snapshotted visibleEntityIds (which every mesh-drawing pass filters by), never advanced renderInfo.currentInFlightFrameSlot, and never ran the Gaussian cull/preprocess/radix-sort pipeline that populates GaussianSharedWorkingSet. visionOS's executeXRSystemPass already does all of this once per frame before its stereo eye loop; the AR path (which renders a single eye through this same function) had none of it.
  • Geometry looked stretched and swam as the device moved: ARKit's camera.projectionMatrix(...) is a standard forward-Z matrix (near→0, far→1), but renderInfo.reverseZEnabled is always true for this path, and every depth compare, HZB occlusion test, and shadow depth in the renderer assumes the reverse-Z convention (near→1, far→0). Added matrixPerspectiveReverseZ(fromForwardZ:nearZ:farZ:), which remaps only the Z terms of ARKit's matrix, leaving the X/Y terms — including any real camera principal-point offset — untouched.
  • Minor: matched the AR renderer's initial viewport units (pixels via drawableSize, not points via bounds.size) to the already-working non-AR init path.

Also updated TileLightStageTests.testTileStageFollowsTheSetting, which asserted the old "tile size left to Metal" behavior (tileWidth == 0); it now asserts the new explicit-square-tile behavior.

Test plan

  • swift build passes
  • swift test --filter UntoldEngineRenderTests.TileLightStageTests passes (4/4)
  • Shader kernels rebuilt via buildkernels.sh
  • Verified on a physical iPhone 11 running UntoldGaussian iOS AR: AR session no longer crashes, passthrough color looks correct, meshes and Gaussian splats both render, geometry no longer distorts as the device moves
  • Full make testrenderer/make testcore suite — pre-commit hook run was interrupted for time; recommend CI run before merge

…ns, missing render prep, and reverse-Z mismatch

UntoldEngineAR's camera-passthrough pipeline crashed on every frame on device
(captured-image pipeline pixel format didn't match the framebuffer it drew
into) and, once that was fixed, hit a second Metal validation crash from the
light-tile stage dispatching more threads per tile than the pipeline's
budget allows. Fixing the pixel format also exposed a latent bug in the AR
shader: it never linearized the camera's gamma-encoded YCbCr->RGB output,
so the HDR post-process pipeline read it as far brighter than it is.

Separately, iOS AR rendered nothing at all - meshes or Gaussian splats -
because UpdateXRRenderingSystem (the function UntoldEngineAR drives every
frame) never ran frustum culling, never snapshotted visibleEntityIds (which
every mesh-drawing pass filters by), and never ran the Gaussian cull/
preprocess/radix-sort pipeline that populates GaussianSharedWorkingSet.
visionOS's executeXRSystemPass already does all of this once per frame
before its stereo eye loop; the AR path, which renders a single eye through
this same function, had none of it.

Once meshes were visible, their geometry looked stretched and swam as the
device moved: ARKit's projection matrix is a standard forward-Z matrix
(near->0, far->1), but renderInfo.reverseZEnabled is always true for this
path, and every depth compare, HZB occlusion test, and shadow depth in the
renderer assumes the reverse-Z convention (near->1, far->0). Added a
conversion that remaps only the Z terms of ARKit's matrix, leaving the X/Y
terms - including any real camera principal-point offset - untouched.

Also applied the same tile thread-budget guard to the Gaussian pass that
the light-tile stage needed, and matched the AR renderer's initial viewport
units (pixels, not points) to the already-working non-AR init path.
@untoldengine
untoldengine merged commit 101b99b into develop Dec 1, 2026
2 of 7 checks passed
@untoldengine
untoldengine deleted the issue/1425 branch December 1, 2026 16:28
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.

UntoldEngineAR crashes on every frame: captured-image pipeline pixel format mismatch

1 participant