Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/gpu-patch-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Do the Adreno-generic metal2vulkan patches of userland/metal/patches/metal2vulkan apply to the pin of
# scripts/setup/get-references.sh, and does the crate still type-check with them? Public sources only, no Apple files.
# Manual run; on a failure the log is the artifact (send it back).
name: gpu-patch-check
on:
workflow_dispatch:
pull_request:
paths: ["userland/metal/patches/**"]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Pin
id: pin
run: |
set -euo pipefail
pin=$(awk '$1=="metal2vulkan" {print $3}' scripts/setup/get-references.sh)
echo "pin=$pin" >> "$GITHUB_OUTPUT"
- name: Restore executable bits (an upload drops them)
run: git ls-files -z | xargs -0 grep -lZI '^#!' 2>/dev/null | xargs -0 -r chmod +x
- name: metal2vulkan at the pin
run: |
set -euo pipefail
git clone --filter=blob:none --no-checkout https://github.com/steelbrain/metal2vulkan.git m2v
git -C m2v checkout -q ${{ steps.pin.outputs.pin }}
- name: Apply
run: |
set -euo pipefail
cd m2v
git config user.email ci@example.invalid; git config user.name ci
for p in ../userland/metal/patches/metal2vulkan/*.patch; do echo "== $p"; git apply --check "$p"; git apply "$p"; done 2>&1 | tee ../apply.log
- name: cargo check (host)
run: |
set -euo pipefail
cd m2v
cargo check -p metal2vulkan -p metal2vulkan-runtime 2>&1 | tee ../cargo.log
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: gpu-patch-check-logs
path: |
apply.log
cargo.log
8 changes: 7 additions & 1 deletion docs/gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ scripts/bg.sh metal userland/metal/build.sh # stage, turnip, plugin, finish
| Piece | Source | Notes |
|---|---|---|
| `libvulkan_freedreno.dylib` | `external/mesa-droidvm` cecc0e9 (Droid-VM/mesa, `droidvm`) + the 30 patches listed in Droid-VM-UniXNU `scripts/data/adreno-compiler-inputs.json` (`patches/mesa/`: `turnip-darwin-kmd`, `turnip-darwin-virtgpu`, ...) | meson cross build, `-Dvulkan-drivers=freedreno -Dfreedreno-kmds=darwin`, release. Its 5633 weak flat-namespace imports are bound to the image itself (`macho-weak-self-binds.py`) |
| `libadreno_metal_bridge.a` | `external/metal2vulkan` 624bab3 + NativeMetal `bridge/patches` 0001-0024 (without 0020) + Droid-VM-UniXNU `patches/metal2vulkan` 0011-0038, behind `bridge/NativeMetalBridge.rs` | Rust 1.98.0, target `arm64e-apple-ios`, std built from `rust-src`, fat LTO. No `Cargo.lock` is pinned upstream: the crates are the newest that fit at build time |
| `libadreno_metal_bridge.a` | `external/metal2vulkan` 624bab3 + NativeMetal `bridge/patches` 0001-0024 (without 0020) + Droid-VM-UniXNU `patches/metal2vulkan` 0011-0038 + this project's `userland/metal/patches/metal2vulkan/` 0101-0103 (staged as 9xxx so they sort last: the Adreno-generic shader-translation fixes of hakios-arm64e-dada; `0104…NEEDS-REBASE` stays out, and the Mesa/nativemetal sets stay out as the wrong tree), behind `bridge/NativeMetalBridge.rs` | Rust 1.98.0, target `arm64e-apple-ios`, std built from `rust-src`, fat LTO. No `Cargo.lock` is pinned upstream: the crates are the newest that fit at build time |
| `NativeAdrenoMetal` | `external/NativeMetal` b0d6a07 (`NativeAdrenoMetalPlugin.mm`, `NativeBridgeMetalFrontend.mm`), `external/AdrenoPM4`, the bridge | The Rust objects' callback imports go through `RustPacBoundary.c`; their indirect branches through its trampolines (`rust-pac-rewrite.py`) |

The steps are the kernel base's own scripts (`build-turnip-darwin.py`, `build-adreno-metal-bridge.py`,
Expand Down Expand Up @@ -1048,6 +1048,12 @@ framebuffer is `RGhA` half floats and the display path keeps them whole
half-float framebuffer asked (...)`. The headroom, threshold and virtualized overrides below stay as they are. Not
built or compiled yet (the plug-in builds on the Mac).

**Lasting debug tooling, off by default** (`stage`): `userland/metal/trace-turnip-init.patch` (into
`patches/mesa/` and the staged mesa-work tree, and appended to `adreno-compiler-inputs.json`),
`trace-metal-vulkan-init.patch` (into `patches/metal2vulkan/`), and `trace-metal-surfaces.patch` (into `patches/`,
applied to the staged frontend after the upstream replacements). Each only logs when its environment variable is
set (`ONEIOS_VK_INIT`, `ONEIOS_SURFACE_TRACE`), so a normal build is unchanged.

**The shared cache addresses.** Upstream's plug-in writes QuartzCore's options at fixed addresses of the iPad17,3
24A446 cache, relative to `CARenderServerStart`. They were re-found in this guest's cache
(`out/image/24A446/systemos.img`, cache UUID `77BC8C63-93DA-3E9B-BB9C-0BE2AF0C0E17`) and are recorded in
Expand Down
15 changes: 13 additions & 2 deletions docs/hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,10 @@ addresses are the binary's, unslid):
thread (overdrive, minimum on-time, duty limit, watchdog). Those protected an ERM on a bare LDO; here the chip's
DSP brakes and protects the LRA. New: each write's loud span is sent with its peak as the intensity and its
zero-crossing rate as the frequency.
- Messages: `OB_HAPTIC_VIB {on_ms, intensity 0..1000, frequency_hz}`, `OB_HAPTIC_STOP`.
- Messages: `OB_HAPTIC_VIB {on_ms, intensity 0..1000, frequency_hz}`, `OB_HAPTIC_STOP`,
`OB_HAPTIC_IMPACT {kind 1..3}` (an explicit one-shot, never a short VIB segment; only when the host
advertised `OB_FEAT_HAPTIC_IMPACT` in a length-extended v1 `OB_CTL_HELLO`, else the guest sends none and an
old host's 8-byte hello reads as features=0).

### UI haptics: the Actuator audio device (media, 2026-11-12; built, not run on the phone)

Expand All @@ -1314,12 +1317,20 @@ What is built:
latency one period (not the speaker's 6480 frames: the haptic synth keeps haptics in step with a device's
latency). Each period goes to `oneios_haptic_actuator_play()`, not to virtio-snd. Published only when
`drivers/haptics` has the host's actuator and UI haptics are on; `oneios-actuator=0` leaves it out.
- **The requests** (`drivers/haptics/oneios_actuator.h`, host-tested by `drivers/haptics/test_actuator.c`, 16 checks):
- **The requests** (`drivers/haptics/oneios_actuator.h`, host-tested by `drivers/haptics/test_actuator.c`, 19 checks):
a period is loud above 256 of 32768; the first loud period asks 20 ms (a tap), the run renews when less than 12 ms
is left (50 ms segments after 20 ms) or the level moves by more than 100 of 1000; a run of 30 ms or more is stopped
after 10 ms of silence, a tap runs out. Intensity = the period's peak; frequency = the run's zero crossings with
hysteresis, after 10 ms. A tap is one request; a long vibration about 20 a second (each is an effect upload on
the CS40L26's I2C).
- **Native impacts** (off by default, both sides opt in): with the guest boot argument `oneios_native_impacts=1`
and the host started with `ONEIOS_HAPTIC_NATIVE_IMPACTS=1` on a HAL whose `getSupportedEffects` advertises
TICK, CLICK and HEAVY_CLICK, a short isolated run (under 30 ms, confirmed by 10 ms of silence) becomes one
`OB_HAPTIC_IMPACT` instead of 20 ms motor starts; the intensity maps to LIGHT (<=250), MEDIUM (<=800), HEAVY.
The host plays the matching `IVibrator.perform()` preset through the same serialized worker; a later STOP never
cancels an already-finished preset (its HAL-reported duration bounds `off()`), so One UI's own vibration is not
interrupted. Longer runs keep VIB/STOP semantics, malformed or unsupported impacts are dropped, never mapped to
VIB. Host-tested (`test_bridges` native-impacts case, `test_hal_binder` preset case); not run on the phone.
- **The closed-loop node**: `oneios_haptic.c` waits (5 s at most) for the audio archive's decision
(`oneios_haptic_actuator_published`), then publishes `/product/haptics {closed-loop 1, supports-3rd-party-haptics 1}`
when the device exists (the old rule, an Actuator HAL plug-in in the root, stays as the second way in). Not copied
Expand Down
8 changes: 8 additions & 0 deletions drivers/bridge/OneiOSBridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static struct {
uint16_t tx_head, rx_used;
bool up, interrupt;
volatile uint32_t channels; // from the host's hello
volatile uint32_t features; // optional extended HELLO; zero on old hosts
struct { oneios_bridge_handler fn; void *context; } listener[OB_CH_COUNT];
} ob;

Expand Down Expand Up @@ -185,6 +186,7 @@ void oneios_bridge_listen(uint16_t channel, oneios_bridge_handler fn, void *cont

bool oneios_bridge_ready(void) { return ob.up && ob.channels != 0; }
uint32_t oneios_bridge_channels(void) { return ob.channels; }
uint32_t oneios_bridge_features(void) { return ob.features; }

static void ob_dispatch(const uint8_t *message, uint32_t written) {
struct ob_header header;
Expand All @@ -197,6 +199,12 @@ static void ob_dispatch(const uint8_t *message, uint32_t written) {
struct ob_ctl_hello hello;
memcpy(&hello, payload, sizeof(hello));
ob.channels = hello.channels;
ob.features = 0;
if (header.length >= sizeof(struct ob_ctl_hello_ext)) {
struct ob_ctl_hello_ext ext;
memcpy(&ext, payload, sizeof(ext));
if (ext.version == OB_PROTO_VERSION) ob.features = ext.features;
}
oneios_bridge_stage = 5;
snprintf(oneios_bridge_status, sizeof(oneios_bridge_status), "up, host channels %#x", hello.channels);
printf("ONEIOS BRIDGE: on: host protocol %u, channels %#x (1 control, 2 haptics, 4 Bluetooth)\n", hello.version, hello.channels);
Expand Down
5 changes: 5 additions & 0 deletions drivers/bridge/oneios_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void oneios_bridge_start(void);
bool oneios_bridge_ready(void);
// Bit n: the host serves channel n. 0 until ready.
uint32_t oneios_bridge_channels(void);
// Optional host features announced in a length-extended v1 HELLO. Older hosts: 0.
uint32_t oneios_bridge_features(void);
// Sends one message. Any thread context that may take a mutex. 0, or -1 (not up, too long, queue full).
int oneios_bridge_send(uint16_t channel, uint16_t type, const void *payload, uint32_t length);
// Messages from the host for `channel` are handed to fn on the bridge's worker thread.
Expand All @@ -32,6 +34,9 @@ void oneios_bridge_listen(uint16_t channel, oneios_bridge_handler fn, void *cont
int oneios_haptic_start(void);
// Vibrate from now for ms (0 = stop) at intensity 0..1000 and frequency_hz (0 = resonance).
int oneios_haptic_vib(uint32_t ms, uint32_t intensity, uint32_t frequency_hz);
// A semantically discrete impact. Only when the host advertised OB_FEAT_HAPTIC_IMPACT;
// not interchangeable with on_ms and never auto-falls back to a continuous buzz.
int oneios_haptic_impact(uint32_t kind);
void oneios_haptic_make_node(void);
int oneios_haptic_publish_closed_loop(void);
// The Actuator IOAudio2Device of the audio archive (DroidVMAudio.cpp as staged): ready = may publish it;
Expand Down
7 changes: 7 additions & 0 deletions drivers/bridge/oneios_bridge_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ enum { OB_CH_CONTROL = 0, OB_CH_HAPTIC = 1, OB_CH_HCI = 2, OB_CH_CAMERA = 3, OB_
// before, so the way back is never at risk.
enum { OB_CTL_HELLO = 1, OB_CTL_SHUTDOWN = 2 };
struct ob_ctl_hello { uint32_t version, channels; };
/* Optional v1 hello extension (12 bytes). An older guest ignores the extra
* word; a newer guest treats an 8-byte reply as features=0. */
#define OB_FEAT_HAPTIC_IMPACT (1u << 0)
struct ob_ctl_hello_ext { uint32_t version, channels, features; };

// ---- haptics (guest -> host only) -------------------------------------------------------------
enum {
OB_HAPTIC_VIB = 1, // struct ob_haptic_vib: vibrate from now; on_ms 0 stops
OB_HAPTIC_STOP = 2, // no payload
OB_HAPTIC_IMPACT = 3, // explicit one-shot impact; not a short VIB segment
};
enum { OB_IMPACT_LIGHT = 1, OB_IMPACT_MEDIUM = 2, OB_IMPACT_HEAVY = 3 };
struct ob_haptic_impact { uint32_t kind; };
struct ob_haptic_vib {
uint32_t on_ms; // 0 = stop
uint16_t intensity; // 0..1000 (iOS's 0.0..1.0)
Expand Down
22 changes: 21 additions & 1 deletion drivers/haptics/oneios_actuator.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
#define OA_QUIET_MS 10u
#define OA_LEVEL_STEP 100u

enum { OA_NONE = 0, OA_VIB = 1, OA_STOP = 2 };
enum { OA_NONE = 0, OA_VIB = 1, OA_STOP = 2, OA_IMPACT = 3 };

struct oa_state {
bool on; /* a request is in flight */
bool native_taps; /* opt-in; only if the host advertised native impacts */
uint32_t short_peak; /* strongest PCM sample in a not-yet-classified tap */
uint32_t now_us; /* the periods given so far, in microseconds */
uint32_t until_us; /* when the request in flight ends */
uint32_t level, hz; /* what it asked */
Expand Down Expand Up @@ -82,6 +84,7 @@ oa_period(struct oa_state *s, const int16_t *frames, uint32_t count, uint32_t ch
s->on = false; /* the request ran out by itself */
}
if (peak > OA_SILENT) {
if (peak > s->short_peak) s->short_peak = peak;
s->run_us += period_us;
s->run_crossings += crossings;
s->quiet_us = 0;
Expand All @@ -90,6 +93,12 @@ oa_period(struct oa_state *s, const int16_t *frames, uint32_t count, uint32_t ch
uint32_t hz = s->run_us >= 10000u ? (uint32_t)((uint64_t)s->run_crossings * 1000000u / (2u * s->run_us)) : 0u;
uint32_t moved = intensity > s->level ? intensity - s->level : s->level - intensity;
bool renew = s->on && s->until_us - s->now_us < OA_RENEW_MS * 1000u;
/* When opted in, hold a newly started run for at most 30 ms. A
* short run confirmed by silence becomes ONE impact rather than
* several 20 ms motor starts; longer runs keep VIB/STOP semantics. */
if (s->native_taps && !s->on && s->run_us < OA_LONG_MS * 1000u) {
return r;
}
if (!s->on || renew || moved > OA_LEVEL_STEP) {
r.action = OA_VIB;
r.ms = s->run_us > OA_TAP_MS * 1000u ? OA_SEGMENT_MS : OA_TAP_MS;
Expand All @@ -102,13 +111,24 @@ oa_period(struct oa_state *s, const int16_t *frames, uint32_t count, uint32_t ch
}
} else {
s->quiet_us += period_us;
if (s->native_taps && !s->on && s->run_us > 0 &&
s->run_us < OA_LONG_MS * 1000u &&
s->quiet_us >= OA_QUIET_MS * 1000u) {
r.action = OA_IMPACT;
r.intensity = s->short_peak * 1000u / 32768u;
if (r.intensity == 0) r.intensity = 1;
if (r.intensity > 1000) r.intensity = 1000;
s->short_peak = 0;
s->sign = 0;
}
if (s->quiet_us >= OA_QUIET_MS * 1000u) {
if (s->on && s->run_us >= OA_LONG_MS * 1000u) {
r.action = OA_STOP;
s->on = false;
}
s->run_us = 0;
s->run_crossings = 0;
if (s->native_taps) { s->short_peak = 0; s->sign = 0; }
}
}
/* a session of hours: keep the clock away from the 32-bit wrap */
Expand Down
Loading
Loading