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
15 changes: 14 additions & 1 deletion docs/ios27/METAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ iOS 27 on the S9 renders with OpenGL ES through `sbca` ([GPU-PATH.md](GPU-PATH.m
framework on the Mali-G72, through a Metal plug-in that Starbite wrote for iOS 26 (a Metal 2 frontend, `HotMetal2.mm` and
`NativeBridgeMetalFrontend.mm`; metal2vulkan's bridge; Mesa's PanVK over the kernel's StarbiteMali). The scripts and tools in
`tools/ios27/metal/` rebuild that stack for iOS 27.0.1 and test it. Starbite's own part of it is in `tools/ios27/metal2/` (the two frontend files,
`HotMetal2.mm` and `NativeBridgeMetalFrontend.mm`, `build-m2v-bridge.sh`, the bridge's Rust sources and its patches 0001-0016 and 0100-0102,
`HotMetal2.mm` and `NativeBridgeMetalFrontend.mm`, `build-m2v-bridge.sh`, the bridge's Rust sources and its patches 0001-0016 and 0100-0103,
`Info.plist`, `m2vtest.c`; MIT, credited below), so the scripts and the three patches in `tools/ios27/metal/patches/` work from this repository
as it is. No binary of any kind is in the repository.

Expand Down Expand Up @@ -64,3 +64,16 @@ What came of the frame rate question is in [LIQUID-GLASS.md](LIQUID-GLASS.md): w
- The wallpaper (above), and the 12 `NotRepresentable` no-copy buffers.
- The decmpfs type 16 of nine SplashBoard `*.ktx` snapshots (the kernel registers type 1 only): unrelated to Metal.
- The scripts were run against Starbite's tree (`SB=`) before `tools/ios27/metal2/` was imported; the import changed their paths only (`tools/metal2` to `tools/ios27/metal2`, the repository as the tree). `bridge.sh` and `mk-bundle27.sh` were not re-run on a phone for it.

## The bridge library the bundles link (recorded 18 Nov 2026)

Every Metal bundle since 12 Nov links `libnative_metal_bridge.a` as built on the Mac mini on 12 Nov 17:45 (metal-perf). The tree
it was built from had changes that were not in this repository: the render-pass-instance split counters in metal2vulkan's
runtime (`INSTANCE_SPLITS` in `lib.rs`, counted in `render.rs` where a draw cannot record in the current instance) and, in the
bridge, the kept runtime messages and the work-counts text (`nmb_take_message`, `nmb_device_work_counts_text`) that the
plug-in's telemetry (`touch /var/local/mtl2-telemetry`) prints with `new_instance_<reason>=N`. They are now
`tools/ios27/metal2/bridge/patches/0103-sweet-instance-split-counters.patch` and
`tools/ios27/metal2/bridge/NativeMetalTelemetry.rs` (include!d by `NativeMetalObjects.rs`; the code is unchanged, only moved
to a file of its own for the size rule) with the two declarations in `NativeMetalObjects.h`. Checked: metal2vulkan 720ef1ce
plus patches 0001-0016 and 0100-0103 gives the 12 Nov tree's metal2vulkan sources file for file. The library was not rebuilt
from the repository for this (a 300 MB Rust build); the counters cost one relaxed atomic add per new instance.
2 changes: 1 addition & 1 deletion tools/arch-size.allow
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ 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 2764
tools/ios27/metal2/bridge/NativeMetalObjects.rs 2396
tools/ios27/metal2/bridge/NativeMetalObjects.rs 2399
tools/mesa/air/air_intrinsics.c 2716
tools/mesa/air/air_metal.c 7072
tools/mesa/air/air_metal.h 1313
Expand Down
3 changes: 3 additions & 0 deletions tools/ios27/metal2/bridge/NativeMetalObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct NmbShaderCacheStats {
};
bool nmb_device_shader_cache_stats(const NmbDevice *, struct NmbShaderCacheStats *);
size_t nmb_last_warning(char *out, size_t size);
// The oldest of the process's first 300 distinct runtime messages not yet taken (0: none); the device's work counts that are not zero.
size_t nmb_take_message(char *out, size_t size);
size_t nmb_device_work_counts_text(const NmbDevice *, char *out, size_t size);
bool nmb_device_max_threads_per_threadgroup(const NmbDevice *, uint64_t out[3]);
/* Device queries the runtime answers by Metal selector: Apple's private counts and flags where the device has an answer of its own,
* and the public queries. A selector's kind says its result and argument. */
Expand Down
3 changes: 3 additions & 0 deletions tools/ios27/metal2/bridge/NativeMetalObjects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ fn log_message(message: &DebugMessage) {
let _ = writeln!(file, "[{} {}] {:?} {}", std::process::id(), std::env::args().next().unwrap_or_default(), message.severity, key);
}

include!("NativeMetalTelemetry.rs");

fn observe_message(message: &DebugMessage) {
use std::sync::atomic::Ordering::Relaxed;
if message.id_name == "metal2vulkan-pipeline-creation" {
Expand All @@ -225,6 +227,7 @@ fn observe_message(message: &DebugMessage) {
return;
}
log_message(message);
keep_message(message);
if message.severity >= MessageSeverity::Warning {
OTHER_MESSAGES[1].fetch_add(1, Relaxed);
if let Ok(mut last) = LAST_WARNING.lock() {
Expand Down
64 changes: 64 additions & 0 deletions tools/ios27/metal2/bridge/NativeMetalTelemetry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
// Starbite telemetry of the native Metal bridge, part of NativeMetalObjects.rs (include!d there; a file of its own for the size
// rule): the runtime's first distinct messages and the device's work counts with the render-pass-instance split counters
// (patches/0103-sweet-instance-split-counters.patch), which the plug-in reports (HotMetal2.mm, /var/local/mtl2-telemetry).
// Recorded 18 Nov 2026, unchanged, from the tree the bundles' libnative_metal_bridge.a was built from on 12 Nov.

// The first 300 distinct messages of the process (but the pipeline log), kept until the plug-in takes them for its telemetry
// (`nmb_take_messages`): what the runtime announces once, a degradation among them, is otherwise seen by nobody on a phone.
static KEPT_MESSAGES: std::sync::Mutex<(Vec<String>, Option<std::collections::HashSet<String>>)> = std::sync::Mutex::new((Vec::new(), None));

fn keep_message(message: &DebugMessage) {
let Ok(mut kept) = KEPT_MESSAGES.lock() else { return };
let (pending, seen) = &mut *kept;
let seen = seen.get_or_insert_with(std::collections::HashSet::new);
let text: String = message.text.chars().take(400).collect();
let key = format!("{:?} {} {}", message.severity, message.id_name, text);
if seen.len() < 300 && seen.insert(key.clone()) {
pending.push(key);
}
}

/// The oldest kept message not yet taken, as a C string; returns its length, 0 when there is none.
#[unsafe(no_mangle)]
pub extern "C" fn nmb_take_message(out: *mut c_char, size: usize) -> usize {
guard(0, || {
let Ok(mut kept) = KEPT_MESSAGES.lock() else { return Ok(0) };
if kept.0.is_empty() {
return Ok(0);
}
let text = kept.0.remove(0);
Ok(copy_out(&text, out, size))
})
}

/// The device's work counts that are not zero (`Device::work_counts`), as "name=value name=value ..."; returns the length.
#[unsafe(no_mangle)]
pub extern "C" fn nmb_device_work_counts_text(device: *const NmbDevice, out: *mut c_char, size: usize) -> usize {
guard(0, || {
let counts = format!("{:?}", get(device)?.0.work_counts());
let inner = counts.trim_start_matches("WorkCounts {").trim_end_matches('}');
let mut text = String::new();
for field in inner.split(',') {
let Some((name, value)) = field.split_once(':') else { continue };
let value = value.trim();
if value != "0" && !value.is_empty() {
if !text.is_empty() {
text.push(' ');
}
text.push_str(name.trim());
text.push('=');
text.push_str(value);
}
}
use std::sync::atomic::Ordering::Relaxed;
let names = ["stand_in", "storage", "locations", "reformats", "shadow", "shader_tests", "views", "dispatched", "barrier", "ordered", "all", "with_draws"];
for (name, count) in names.iter().zip(metal2vulkan_runtime::INSTANCE_SPLITS.iter()) {
let count = count.load(Relaxed);
if count != 0 {
text.push_str(&format!(" new_instance_{name}={count}"));
}
}
Ok(copy_out(&text, out, size))
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs
index 4781491b..4f1ebd68 100644
--- a/crates/metal2vulkan-runtime/src/lib.rs
+++ b/crates/metal2vulkan-runtime/src/lib.rs
@@ -23,6 +23,13 @@
// warnings-denied gates.
#![warn(missing_docs)]

+/// Starbite diagnostics: how often a draw began a new render pass instance, by what differed from the current one
+/// (`render.rs`, `next_instance`): a stand-in arriving, the interlocked storage colors, the color locations, the views
+/// of another format, the stencil shadow, the shader-side tests, the views, a tile dispatch since, a barrier since, an
+/// ordered tile-memory reach; then all of them, and those whose current instance had draws recorded (a real split).
+#[doc(hidden)]
+pub static INSTANCE_SPLITS: [std::sync::atomic::AtomicU64; 12] = [const { std::sync::atomic::AtomicU64::new(0) }; 12];
+
mod address;
mod address_map;
mod address_pool;
diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs
index 5cd377c9..23bb5804 100644
--- a/crates/metal2vulkan-runtime/src/render.rs
+++ b/crates/metal2vulkan-runtime/src/render.rs
@@ -4598,20 +4598,35 @@ impl RenderCommandEncoder {
standing.push(Standing::Hidden(target));
}
let images = standing.iter().any(|s| !matches!(s, Standing::Planes(..)));
- if !images
- && self.current.shape.storage == storage
- && self.current.shape.locations == locations
- && Reformat::same(&self.current.reformats, reformats)
- && self.current.shadow == shadow
- && self.current.shader_tests == shader_tests
- && self.current.views == views
- && !self.dispatched
- && !self.barrier
- && !ordered
- {
+ // (Starbite diagnostics: why a draw could not record in the current instance, counted for the plug-in's telemetry.)
+ let same = [
+ !images,
+ self.current.shape.storage == storage,
+ self.current.shape.locations == locations,
+ Reformat::same(&self.current.reformats, reformats),
+ self.current.shadow == shadow,
+ self.current.shader_tests == shader_tests,
+ self.current.views == views,
+ !self.dispatched,
+ !self.barrier,
+ !ordered,
+ ];
+ if same.iter().all(|s| *s) {
let stood = (!standing.is_empty()).then(|| stood(&self.layout, standing));
return Ok((Next::Current, stood));
}
+ {
+ use std::sync::atomic::Ordering::Relaxed;
+ for (reason, same) in same.iter().enumerate() {
+ if !*same {
+ crate::INSTANCE_SPLITS[reason].fetch_add(1, Relaxed);
+ }
+ }
+ crate::INSTANCE_SPLITS[10].fetch_add(1, Relaxed);
+ if self.current.recorded {
+ crate::INSTANCE_SPLITS[11].fetch_add(1, Relaxed);
+ }
+ }
// The first instance runs the pass's load actions. An attachment it leaves out that
// clears is cleared before the pass where the clear covers its level and layer (the
// render area is the whole of it), or its sample planes are where they take transfer
Loading