Repository navigation
Fix iOS AR passthrough: pixel format crash, tile thread-budget overruns, missing render prep, and reverse-Z mismatch - #1427
Merged
Merged
Conversation
3 tasks done
…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
force-pushed
the
issue/1425
branch
from
December 1, 2026 16:00
6beb34e to
628e33c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1425 and several follow-on bugs found while chasing it down on an iPhone 11 running
UntoldGaussian iOS AR.UntoldEngineAR's captured-image pipeline hardcoded.bgra8Unorm_srgb, but it's bound againstenvironmentColorMap(.rgba16Float) — a guaranteed Metal validation crash on every frame that draws the passthrough background. Now reads the format offenvironmentColorMapdirectly.tileLightStage(for:)lefttileWidth/tileHeightat0(Metal auto-picks), but Metal could pick a tile whose thread count exceeds the pipeline's ownmaxTotalThreadsPerThreadgroup— 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.capturedImageFragmentShadernever linearized the camera's gamma-encoded YCbCr→RGB output. The target holds linear HDR scene radiance (same contract asfragmentEnvironmentShader), so the un-decoded gamma values were read downstream as far brighter than they are. Added the sRGB-to-linear decode.UpdateXRRenderingSystem— the functionUntoldEngineARdrives every frame — never ran frustum culling, never snapshottedvisibleEntityIds(which every mesh-drawing pass filters by), never advancedrenderInfo.currentInFlightFrameSlot, and never ran the Gaussian cull/preprocess/radix-sort pipeline that populatesGaussianSharedWorkingSet. visionOS'sexecuteXRSystemPassalready 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.camera.projectionMatrix(...)is a standard forward-Z matrix (near→0, far→1), butrenderInfo.reverseZEnabledis alwaystruefor this path, and every depth compare, HZB occlusion test, and shadow depth in the renderer assumes the reverse-Z convention (near→1, far→0). AddedmatrixPerspectiveReverseZ(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.drawableSize, not points viabounds.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 buildpassesswift test --filter UntoldEngineRenderTests.TileLightStageTestspasses (4/4)buildkernels.shUntoldGaussian iOS AR: AR session no longer crashes, passthrough color looks correct, meshes and Gaussian splats both render, geometry no longer distorts as the device movesmake testrenderer/make testcoresuite — pre-commit hook run was interrupted for time; recommend CI run before merge