Skip to content

Latest commit

 

History

History
62 lines (32 loc) · 13.4 KB

BUILD_VALIDATION.md

File metadata and controls

62 lines (32 loc) · 13.4 KB

Android validation and frame ownership

The Android example in ../example/android pins React Native 0.88.1, Skia 3.12.0, WebGPU 0.24.0 and their shared binaries-158.1.0 release (Dawn chrome-m158, Skia m158a); Gradle downloads the Dawn and Graphite archives from the packages' GitHub releases on the first build, and needs node to resolve the packages. Since WebGPU 0.19.0, export renders straight into the codec's input Surface through a WebGPU canvas context on it (MakeWebGPUCanvasContextFromNativeWindow, Vulkan swapchain), with no EGL; CPU readback, drawn into the Surface by EGL, stays the fallback. On API 29+, 8-bit SDR H.264/HEVC clips go through an ImageReader, whose YUV buffers WebGPU converts, crops, rotates and scales to the frame's size (capped or explicit sizes included since the 3.7.4 migration); since 3.6.1 each buffer is imported once, and exports sample the converted frame in place. The 3.7.0 build was assembled and run on a Pixel 8a on 2026-10-19 (verification), after the 3.6.1 build of 2026-10-16 (verification) and the 3.4.4 build of 2026-10-14/15 (verification); the evidence below is from Skia 3.0.6 / WebGPU 0.12.1 / Graphite 154.1.0. It uses Java 17, Gradle 9.4.1, Android SDK 37 (target 36) and NDK 27.1.12297006. The library requires API 28; a consuming application with a lower minimum receives an explicit Gradle configuration error. The default example ABI is arm64-v8a; RNSKV_ANDROID_ABI selects another ABI for the validation script.

Run android/scripts/validate.sh build from the repository. It assembles the example Debug and unsigned Release APKs, library AAR, standalone instrumentation APK and JVM tests. Release uses the installed hermes-compiler package, and both native and Metro build concurrency are bounded to two workers. The Release APK is unsigned: device installation requires signing a separate local qualification artifact. The project supplies no publishing or release signing configuration.

Run android/scripts/validate.sh instrument DEVICE_SERIAL to execute the native cases on an explicitly selected connected device. instrumentation-inventory.json records the 40 original named cases / 86 parameterized executions and sixteen additional ownership executions, for 52 named cases / 102 planned executions. Unsupported hardware codecs produce JUnit assumption skips, never passes. The library's AndroidTest variant packages its own React JNI dependencies; its AAR keeps the original dependency exclusions.

Verified build evidence

build-validation.json records hashes of produced artifacts, source fingerprints and the actual JVM results. The initial checkpoint is dated 08:59 UTC and contains compilation and host-test results with no connected device. Later physical-device follow-up is recorded separately in the device report and machine-readable evidence; it does not retroactively change the initial artifact hashes.

The initial successful full Debug build, before the direct-buffer optimization, was preserved at /private/tmp/rnskwgpu-android-baseline-20261007 with the APK, AAR, test APK, source archive, fingerprints and build logs. This is a candidate implementation checkpoint, not the original Skia 2 reference. The original repository remains the separate benchmark reference.

Historical direct-buffer checkpoint

A decoder owns an isolated EGL context and SurfaceTexture. It normalizes its external codec texture into a packed RGBA framebuffer at the requested output dimensions, then reads pixels once into a distinct owned direct buffer. It does not expose an OpenGL texture from another graphics context, share Skia EGL state, or recycle a frame by its age.

The preceding staging path retained a reusable readback buffer, copied into a Java byte array and copied again into a C++ vector. The historical direct-buffer checkpoint removed the reusable CPU scratch and both full-frame memcpy operations. Java and JSI viewed the same owned storage. This was a structural reduction in copies, not a measured millisecond or process-memory improvement. GPU-to-CPU readback and GPU upload still occurred; that checkpoint reported cpu-rgba-readback, cpu-rgba-upload and zeroCopyDecode: false. Normal rendering later switched to the scoped-copy fallback and the AHardwareBuffer transport described below.

The RGBA backing is allocated through Android's ByteBuffer.allocateDirect, so ART sees real allocation pressure. A native memory-budget token is reserved before allocating pixels, including the seven bytes used by Android's alignment. An allocation owner and its phantom cleanup are registered before allocating the backing. A JNI-created buffer points to those pixels; its tracked root holds the owner. Android's JNI buffer implementation preserves that root through slices, duplicates and read-only views. A JSI MutableBuffer holds a global reference to a view, and attaches its finalizer thread before deleting that reference. No second reservation is made for additional Java/JS aliases.

When all exposed Java/JS buffers die, the first phantom reference drops the allocation owner. Only after the owner and its backing are collected does its pre-registered phantom return the budget token. The reaper allocates no cleanup trackers. Allocation/alias-registration failures after the backing exists remain conservatively accounted; the token is released immediately only if registration failed before any pixel backing was allocated. frame.dispose() drops that frame's JSI ArrayBuffer reference. Existing ArrayBuffer aliases and retained Java frames remain valid and retain the reservation. Cleanup therefore need not immediately return to zero after disposing a reader; a tight budget may reject another frame while GC cleanup remains pending.

Each producer writes a buffer once and never mutates it for a later frame. Java consumers receive read-only views. Consumers of the raw JSI ArrayBuffer should treat it as source pixels; ordinary rendering copies them through the public frame helper before releasing its reference.

Device tests additionally retain a read-only slice after dropping its VideoFrame, verify unchanged bytes and a retained reservation, and require bounded GC cleanup before accepting return to the baseline. JVM tests cover pre-allocation rejection, failure after backing allocation, idempotent cleanup and both lifetime stages independently of GC timing. They do not replace the device tests.

The Surface decoder output callback queues its output index and presentation time directly. Android documents that MediaCodec.getOutputBuffer() returns null for an output Surface; querying it had prevented valid frames from being queued. Empty non-EOS Surface outputs are accepted, while empty EOS and codec-configuration buffers are not treated as frames.

Example measurements

The Android-only VideoBenchmarkHarness streams bundled verified fixtures into the application files directory before timed work, creates scoped export/result files, and supplies Android device metadata. It records actual /proc/self/status RSS, Debug.MemoryInfo total PSS and native-heap PSS. Complete process GPU allocation is unavailable and remains explicitly unavailable. It reports Android power/thermal state and React foreground lifecycle.

Export verification decodes the output with MediaCodec, counts decoded frames and checks presentation timestamps. It releases the codec and extractor on success or failure and bounds stalled verification. JSON results live in the app-scoped externalFilesDir/benchmark-results directory, with an internal-files fallback; this is not a public Downloads directory. The shared example screen selects the real platform and Android helper; it no longer assumes the iOS helper or an iPhone identifier.

Primary ownership/API evidence

Physical-device follow-up and scoped copy

A Pixel 8a was subsequently connected. The preserved 24-attempt candidate-only campaign completed six 1080p playback operations and six exports, but all attempts failed strict two-second cleanup and twelve uncapped 4K operations failed controlled ART allocation. A single bounded-allocation-retry follow-up also failed 4K; five JNI ownership/refusal tests and 37 JVM tests passed at that checkpoint. See the linked device report for exact binary identities and limits. No valid baseline A/B improvement is claimed. The current full inventory has 52 named cases / 102 planned executions and has not passed in full.

The next scoped-copy path exposes texture.copyPixelsTo(destination: ArrayBuffer) and retains the opaque texture.data compatibility getter lazily. Normal rendering copies into one budgeted, reusable JS scratch buffer, then performs the existing WebGPU upload/snapshot and checked fence. This deliberately adds one CPU memory copy to remove per-frame Java-backed ArrayBuffer ownership from normal rendering. The library reports the extra copy in backend metadata. Full-resolution decode and the quota remain unchanged.

frame.dispose() releases its native lease promptly and clears a JavaScript-owned raw-buffer cache. Bound JS getter/copy/dispose functions retain that cache through ordinary GC-traced edges; C++ holds no strong JSI object back to the container. Raw ArrayBuffer aliases obtained explicitly retain their own shared storage after disposal. The cache holder credits source memory to Hermes before materialization, transfers that credit to the raw ArrayBuffer if requested, and removes the holder credit at disposal. Copies validate readable lifetime and destination capacity before writing; memmove permits explicit overlapping aliases.

bash android/scripts/test-frame-lease.sh runs six focused C++ ownership/copy checks with AddressSanitizer and UndefinedBehaviorSanitizer. They cover incomplete destinations without partial writes, retained aliases, prompt owner release, disposed-source rejection and overlap; they do not replace the actual Hermes/ART/device path. The scoped-copy checkpoint completed all eight focused operations without OOM, but all eight failed strict two-second cleanup. It remains a one-attempt diagnostic reference rather than a qualified memory result.

AHardwareBuffer transport and device validation

When the shared Skia WebGPU device supports AHardwareBuffer textures and sync-fd fences, Android probes its independent EGL context before enabling the transport for a new decoder. Unsupported hardware is rejected with an explicit capability error before decode and selects the CPU fallback. Quota, allocation and import errors remain visible. Existing decoders capture their chosen transport.

The codec SurfaceTexture is drawn into a new immutable RGBA8 AHardwareBuffer through an EGLImage texture. The producer detaches its FBO attachment and waits for checked GL completion before publishing a native-buffer lease. Normal rendering performs no RGBA CPU readback or full-frame CPU copy. Skia imports the allocation, blits it and creates an owned GPU snapshot; its checked completion precedes source-lease disposal. Export still uses the CPU RGBA readback/upload path. This is not a claim of zero-copy rendering or complete GPU memory accounting.

Producer frames, returned Java snapshots and JSI frames have independent leases of one shared native allocation. Replacement closes only the producer lease; retained Java or JS frames remain valid. JNI closes every returned Java wrapper, including cache hits and conversion errors. Explicit disposal releases the normal path promptly; raw consumers may retain a lease until close or GC. Budget reservation precedes allocation and accounts the described AHB stride, with uncertain GPU cleanup retaining its reservation. AHB uses CPU_READ_RARELY for the Java pixel oracle; possible layout costs have not been isolated.

The frozen Release APK passed ten physical CPU/AHB sampled-pixel comparisons on a Pixel 8a, covering padded dimensions, portrait, rotation, H264/HEVC full 4K and both copy/direct modes. All compared channels were identical, including an old frame imported after producer teardown. Six targeted native AHB ownership, fence, abort, quota and read-validation tests passed with zero skips. The same source passed 43 JVM tests. These focused results do not establish full-suite, HDR, whole-image or audio correctness; 24 repeated focused playback/export attempts passed strict cleanup on the same frozen binary; exact physical memory and limits are recorded separately in the device report.

Four existing lifecycle cases also passed once on the same AHB Release artifact: pause/resume, frame-map pruning, paused seek/wait plus further seeks, and a lazy/direct eight-4K montage with 25 churn and 40 remount cycles. Five CPU ownership tests passed again on the current instrumentation artifact. The montage reached 800.250 MiB RSS / 1037.908 MiB PSS and retained 785.816 MiB settled RSS despite tracked owned reservations returning to zero; this is not an endurance or memory-plateau qualification. Full scope, raw hashes and unavailable pixel/native-PTS checks are preserved in the device report.