Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/ios27/CAMERA.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,73 @@ the tests). On phone 1 (all **measured**, M2M-SCALER.md "The phone test"):
Without it the source node's preview output leads nowhere, scaler or not (the boot with `m2m=0` showed the same).
- The shutter still fails at once with -16808 (BWUBNode); the scaler changes nothing there.

### The display side: the picture reaches backboardd's GPU, CoreAnimation's draw of it is lost (24 November)

Phone 1, kernel built from main 72c0b593 and the fork 4285c9c8 (`cam_trace=1 cam_metal=1`), root as found plus a StarbiteMetal
with the diagnostics below (`YCbCrProbe.h`, `DrawNote.h`, all off unless set in `/var/local/mtl2-env`). Seven boots, D1 to D7.

- **Measured: the texture is right.** backboardd makes a `YCBCR8_420_2P` (500) texture over each of the image queue sink's
surfaces and binds it in its main pass (render encoder, fragment slot 3). The probe (`SWEET_MTL2_YCCPROBE=1`) reads it on
backboardd's own GPU: with the front camera, `read()`, a linear and a nearest sample in a compute function, and linear and
nearest half-precision samples from fragment slot 3, all give RGB about 59 60 59 with 40 of 64 points lit, where the
processor reads luma 59 with 40 of 64 lit. The 4:2:0 conversion, the surface's bytes as backboardd's GPU sees them, and
sampling in either stage are right.
- **Measured: replacing the texture changes nothing.** With `SWEET_MTL2_YCCFLAT=1` every fragment binding of such a texture
gets a BGRA8 copy of it instead (made by a compute pass on the caller's queue, committed just before the caller's command
buffer). The viewfinder is still black. So the black does not come from the two-plane texture.
- **Measured: which draws show the camera** (pass log `SWEET_MTL2_PASSLOG`, draw notes `SWEET_MTL2_DRAWNOTE=1`). The first frame
draws it with `TimgA3Xhf_Ixrg` straight into the framebuffer. Every later frame draws it with `TimgA3S1Xhfu_Ixrg` (four draws)
into color 1, the pass's memoryless `RGBA16Float` attachment (load and store don't care), with the framebuffer's color 0
masked off. `TimgBbcmA3Xhf_Isup` (twice) and `TbdsA3Xhf_Isup_Isrc` then write color 0. Samplers are clamped and normalized
(nearest for the first draw, linear for the rest); texture coordinates are normalized (v from 178/1702). The camera's control
blur also samples it (`TimgA2Xhfu_Ixrg` into 22 x 22 and 208 x 144, `downsample_4_frag_lph`). No refusal from backboardd while
the viewfinder was up.
- **Inferred, not verified: where it is lost.** In the `S1` path the picture only reaches the screen through color 1, a
memoryless attachment read back by a later draw of the same pass (framebuffer fetch). That is the next place to measure:
what metal2vulkan does with that attachment and that fetch on PanVK (its rasterization-order and interlock features), and
whether the pass is split into instances there. With the bridge's telemetry on (`touch /var/local/mtl2-telemetry`) through a
camera session: no `new_instance_<reason>` count (the pass is not split), no degradation notice and no refusal from backboardd.
So the next measurement is inside PanVK: how it keeps the memoryless color and serves its fetch.
- **Also measured:** with the camera open, backboardd runs at 495 to 498 of its 514 MiB GPU cap. The kernel refused it a
24 MiB buffer after the photo (D5), and 13 times with the BGRA8 copies on (D7), where `mtl2.log` also has `OutOfMemory(Device)`
refusals of textures and of two command buffers. Each converted 828 x 1702 texture keeps an `RGBA16Float` image of about
11 MiB. Such refusals reach the console only while the process's console line budget lasts.
- **Also seen once, not explained:** both boots of D6, where the BGRA8 copy waited on the caller's thread for its own command
buffer, stopped backboardd after its first textures (SpringBoard never drawn); D7, without the wait, booted normally.

### The display side, part two: not the memoryless attachment; the picture reaches backboardd's framebuffer (24 November, evening)

Phone 1, the same kernel and line as above (`cam_trace=1 cam_metal=1`), root as handed back plus a StarbiteMetal with
`FetchProbe.h` / `FetchProbe.metal` and more draw-note modes (all off unless set in `/var/local/mtl2-env`). Boots F1 to F5.

- **Measured: framebuffer fetch through a memoryless color attachment works on PanVK** (`SWEET_MTL2_FBPROBE=1`, F1). In
backboardd, on its own queue, 64 x 64 passes of the camera layer's shape: color 0 BGRA8 stored, color 1 a memoryless
`RGBA16Float` (load and store don't care), color 2 a memoryless `R32Float`. A draw that writes only color 1 (color 0 masked off)
and then a draw that reads color 1 by `[[color(1)]]` and writes color 0 leave exactly the value written (B G R 191 128 64). The
same with color 1 private and stored, with only colors 0 and 1, with color 1 cleared by the load action, and a read of color 0
itself, all right; a pixel no draw wrote reads 0. metal2vulkan reads such attachments as input attachments with
`VK_EXT_rasterization_order_attachment_access` (on this PanVK for v6 through `mesa26-panvk-ios.patch`), and PanVK lowers the
read to `LD_TILE` from the tile buffer; the Bifrost scheduler orders it after earlier fragments (the clause waits on the
eldest-colour slot). No render-pass split, input-attachment copy or barrier is involved.
- **Measured: on steady frames the main pass's color 1 holds nothing** (`SWEET_MTL2_FBPROBE=2`, F3): with color 1 of the 828 x 1702
main pass made a stored private texture for the camera session, 20 reads of it over 60 s gave 0 0 0 0 everywhere. The draws that
write color 1 (`TimgA3S1Xhfu_Ixrg` and the other `S1` functions) belong to the flip animation's blur, not to steady frames.
QuartzCore's functions are specialized with `fc_framebuffer_fetch=1`; their `_Isup` input is a sampled backdrop texture
(`RGBA16Float` 192 x 192 at slots 3 and 4), not color 1 (`SWEET_MTL2_DRAWNOTE=2`).
- **Measured: the steady preview draw is direct, and it puts the picture into the framebuffer** (`SWEET_MTL2_FBPROBE=3`, F5).
`TimgA3Xhf_Ixrg` samples the format 500 texture over the sink's surfaces into color 0 (x 0 to 828, y from 178, v from 0.1046),
at least once a second. The processor's read of that pass's color 0 surface when its command buffer completed gave, over the
viewfinder, RGB means 16 to 21 with 10 to 17 of 64 points lit, where the image queue sink's sample 300 had luma mean 21 with 109
of 256 above black (front camera, a dim room). At the same moment the screen (the kernel's `shot`) is exactly 0 over the
viewfinder. Skipping CoreAnimation's `luma_boost_lph` (a diagnostic, `SWEET_MTL2_SKIPLUMA=1`) did not change the black.
- **Measured: backboardd hands the preview to the display as a layer of its own.** The kernel's framebuffer said
`SWEET FB: layer 2 surface 284 at 0,0 828x1702 (swap 512)`: surface 284 is one of the sink's `420f` surfaces. SwapEnd in the
fork's `iokit/Kernel/arm/SweetFramebuffer.cpp` copies layer 0 and blends upper layers as premultiplied BGRA (made for the
pointer); a two-plane `420f` layer is not converted there (read in the code, not measured).
- **So the black viewfinder is not in the Metal layer.** The next piece is the display path: what SwapEnd gets for the preview's
layer (its rectangles, and which surface layer 0 is then) and a YCbCr layer in SwapEnd (colour conversion into the panel), or a
display that tells QuartzCore truthfully which layer formats it scans out. The black app-switcher cards were not looked at.

### SpringBoard's main-display layout (18 November)

`camera_sbtrace.c` on phone 1 (dylib `-16`, `-17`) shows that SpringBoard does publish its layout: the home screen, the lock
Expand Down
2 changes: 1 addition & 1 deletion tools/arch-size.allow
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tools/ios27/fullroot/pipeline/cache/aot/fp16_stub.py 1424
tools/ios27/fullroot/pipeline/cache/aot/rewrite-grow.py 1047
tools/ios27/lse/lse-rewrite.py 826
tools/ios27/mesa-ios/starbite-drm/starbite_drm.c 985
tools/ios27/metal2/NativeBridgeMetalFrontend.mm 2767
tools/ios27/metal2/NativeBridgeMetalFrontend.mm 2777
tools/ios27/metal2/bridge/NativeMetalObjects.rs 2440
tools/mesa/air/air_intrinsics.c 2716
tools/mesa/air/air_metal.c 7072
Expand Down
10 changes: 10 additions & 0 deletions tools/ios27/metal/mk-bundle27.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ if [ -z "${NOPATCH:-}" ]; then
xcrun -sdk iphoneos metallib $W/src27/turn.air -o $W/src27/turn.metallib || exit 1
{ echo "static const unsigned char sweet_turn_metallib[] = {"; xxd -i < $W/src27/turn.metallib; echo "};"; } > $M2/TurnShaders.inc
fi
# YCbCrProbe.h includes YCbCrProbe.inc: tools/ios27/metal2/YCbCrProbe.metal (the GPU's read of a two-plane YCbCr texture, the camera
# preview's display side; used only with SWEET_MTL2_YCCPROBE=1) compiled the same way
xcrun -sdk iphoneos metal -mios-version-min=16.0 -c $M2/YCbCrProbe.metal -o $W/src27/ycc-probe.air || exit 1
xcrun -sdk iphoneos metallib $W/src27/ycc-probe.air -o $W/src27/ycc-probe.metallib || exit 1
{ echo "static const unsigned char sweet_ycc_probe_metallib[] = {"; xxd -i < $W/src27/ycc-probe.metallib; echo "};"; } > $M2/YCbCrProbe.inc
# FetchProbe.h includes FetchProbe.inc: tools/ios27/metal2/FetchProbe.metal (framebuffer fetch through a memoryless color attachment,
# the shape of the camera layer's draw; used only with SWEET_MTL2_FBPROBE=1) compiled the same way
xcrun -sdk iphoneos metal -mios-version-min=16.0 -c $M2/FetchProbe.metal -o $W/src27/fetch-probe.air || exit 1
xcrun -sdk iphoneos metallib $W/src27/fetch-probe.air -o $W/src27/fetch-probe.metallib || exit 1
{ echo "static const unsigned char sweet_fetch_probe_metallib[] = {"; xxd -i < $W/src27/fetch-probe.metallib; echo "};"; } > $M2/FetchProbe.inc
$CC -x objective-c++ -std=c++17 -fobjc-arc -O2 -g -Wall -Wno-deprecated-declarations -Wno-unused-function -bundle \
-o "$B/StarbiteMetal" $M2/HotMetal2.mm $M2/NativeBridgeMetalFrontend.mm -x none "$BRIDGE" \
-Wl,-dead_strip -lc++ -framework Foundation -framework Metal -framework IOSurface -framework IOKit \
Expand Down
Loading
Loading