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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ removed no sooner than the next major (see `docs/API_STABILITY.md`).

## [Unreleased]

- Reuse exact horizontal confidence-mask indices across rows and skip identity
width transforms in the camera demo. Preserve complete confidence validation,
strict threshold and independent transferable output. Add exhaustive size,
byte and ownership comparisons plus interleaved timing evidence; retain adverse
initial observations. See [mask resize](docs/CAMERA_MASK_RESIZE.md).

- Summarize optional camera person-mask support once per frame, replacing repeated
inclusive 45x45 scans with exact bounded prefix queries and uniform-mask fast
paths. Preserve public reports and caller ownership; record frozen native and
Expand Down
15 changes: 15 additions & 0 deletions benchmarks/camera-mask-resize-pair-plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"schema": "spatialrust.camera-mask-resize-pair-plan.v1",
"slice": "146AT",
"candidate_source": "e26f360",
"reason": "The retained initial four-process surveys show order-dependent reversals. Add prospective in-process interleaving and longer checked warmup before drawing mask-only timing conclusions.",
"source_plan": "benchmarks/camera-mask-resize-plan.json",
"processes": 2,
"warmup_calls_per_function_per_shape": 1024,
"rounds_per_shape": 8,
"order_per_round": ["baseline", "candidate", "candidate", "baseline"],
"calls_per_sample": 16,
"samples_per_function_per_shape": 16,
"resource_limits": "Use the existing 128MiB owned root, zero shared-cache growth, one owned command, 900-second deadline and maximum 16 retained timed outputs. No new acquisition or compilation.",
"admission": "Preserve all initial measurements. Require exact masks and unchanged source data in both new processes. Publish every sample and shape, including adverse rows. Affinity, clock frequency, host load and GC remain uncontrolled; no confidence intervals, physical-phone, GPU, AI-inference or end-to-end speed claim."
}
40 changes: 40 additions & 0 deletions benchmarks/camera-mask-resize-plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"schema": "spatialrust.camera-mask-resize-plan.v1",
"slice": "146AT",
"parent_merge": "4ad75f001a501592afeeaeb52656c90e9c2f397c",
"purpose": "Hoist repeated nearest-neighbor horizontal confidence-mask indices out of the row loop, with an identity-width path and exact mask/admission parity.",
"contract": {
"math": "Preserve strict >0.5 threshold, floor(x*sourceWidth/width), floor(y*sourceHeight/height), binary bytes, all 1..320 dimensions, Float32Array checks and complete source finite/range validation before output allocation. Identity width uses the exact x index; other widths compute one Uint16 horizontal map per call. No retained map cache; at most 640 additional logical index bytes.",
"ownership": "Every result remains a fresh Uint8Array with caller-independent storage that can be transferred/detached. No signature, SDK/model/worker protocol, Rust tracker, gray conversion, explicit GPU/CPU readback or dependency change.",
"verification": "Run new independent frozen-parent mask controls on parent and candidate, exhaustive horizontal size pairs, small one-hot supports, strict float boundaries, unsampled invalid values and buffer transfer/ownership. Keep all existing browser/WASM/model controls and add actual-browser module parity controls. Compare all mask bytes and all timing rows in two balanced Node surveys, retaining adverse results and making no physical-phone, GPU or end-to-end speed claim.",
"preservation": "Preserve all previous camera/renderer files including the completed isolated Cargo target, 493 scientific JSON, 42 frozen native artifacts, room/reference outputs, shared raw WASM/cache, current tracker WASM and resolved lock. No Rust compilation, sensor reads/acquisition, vendor/model/browser/toolchain downloads or payload copies."
},
"resources": {
"build_root": "E:/SpatialRustBuild/camera-mask-resize-v1",
"cargo_cache": "E:/SpatialRustBuild/maturity-80-target",
"build_max_bytes": 134217728,
"positive_cache_growth_max_bytes": 0,
"combined_new_and_positive_cache_growth_max_bytes": 134217728,
"minimum_free_bytes": 21474836480,
"workers": 1,
"command_timeout_seconds": 900,
"sampling_seconds": 5,
"asset_download_max_bytes": 0,
"public_verification_stream_max_bytes": 41943040,
"sensor_downloads": 0,
"new_sensor_payload_copies": 0,
"strategy": "Reuse the exact tested current Rust WASM and nine hash-checked vendor hardlinks. Fresh owned E-drive site/logs only. Strict read-only inventory and hash-preserve all prior roots; fail closed on storage or source changes."
},
"benchmark": {
"shapes": [[256,256,192,144],[256,256,256,192],[256,256,144,192],[256,256,192,256],[320,320,320,320],[320,320,64,64],[64,64,320,320],[3,2,5,7],[320,1,192,1],[1,320,1,320]],
"samples": 7,
"calls_per_sample": 16,
"warmup_calls": 128,
"surveys": 2,
"order": ["baseline", "candidate", "candidate", "baseline"],
"host_workers": 1,
"retained_timed_output_bytes_max": 1638400,
"comparison": "Use one fixed confidence pattern including exact/adjacent Float32 threshold values. Check every timed output against the independent frozen parent outside the timer. Publish all raw samples, both survey ratios and adverse rows. No affinity, frequency, other-host-load or GC control and no confidence intervals."
},
"remaining_80_percent": "Measured calibration/timing and independent motion, full-room accuracy, qualifying physical Linux hardware and integrated operational acceptance remain open."
}
73 changes: 73 additions & 0 deletions crates/spatialrust-web/web/camera_controller.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,79 @@ import { FrameRate } from "../../../docs/site/camera/frame-rate.mjs";
import { CameraProgress } from "../../../docs/site/camera/camera-progress.mjs";
import { captureBitmap } from "../../../docs/site/camera/capture-bitmap.mjs";

// Frozen parent predicate: validate every source pixel before sampling.
function frozenPersonMask(source, sourceWidth, sourceHeight, width, height) {
if (!(source instanceof Float32Array) || ![sourceWidth, sourceHeight, width, height].every((n) => Number.isInteger(n) && n > 0 && n <= 320) || source.length !== sourceWidth * sourceHeight) throw new Error("人物マスクのサイズが想定と異なります。");
for (const value of source) if (!Number.isFinite(value) || value < 0 || value > 1) throw new Error("人物マスクの値が範囲外です。");
const mask = new Uint8Array(width * height);
for (let y = 0; y < height; y++) {
const row = Math.floor(y * sourceHeight / height) * sourceWidth;
for (let x = 0; x < width; x++) mask[y * width + x] = source[row + Math.floor(x * sourceWidth / width)] > 0.5 ? 1 : 0;
}
return mask;
}

test("mask resize preserves all bytes across production and irregular shapes", () => {
for (const [sw, sh, w, h] of [[1,1,1,1],[2,3,3,2],[3,2,2,3],[64,79,192,144],[256,256,192,144],[256,256,256,192],[320,320,320,320]]) {
for (let kind = 0; kind < 6; kind++) {
const source = Float32Array.from({ length: sw * sh }, (_, i) => [0, 1, .5, .5000000596046448, .4999999701976776, ((Math.imul(i, 73) ^ (i >>> 3)) >>> 0) % 101 / 100][kind]);
assert.deepEqual(personMask(source, sw, sh, w, h), frozenPersonMask(source, sw, sh, w, h));
}
}
});

test("mask resize covers every admitted horizontal source/destination size pair", () => {
let pairs = 0;
for (let sw = 1; sw <= 320; sw++) for (let w = 1; w <= 320; w++) {
const source = Float32Array.from({ length: sw }, (_, x) => ((Math.imul(x, 73) ^ (x >>> 2)) & 255) / 255);
assert.deepEqual(personMask(source, sw, 1, w, 2), frozenPersonMask(source, sw, 1, w, 2), `${sw}->${w}`);
pairs++;
}
assert.equal(pairs, 102400);
});

test("mask resize maps small single-pixel supports exactly in both axes", () => {
for (let sw = 1; sw <= 8; sw++) for (let sh = 1; sh <= 5; sh++) for (let w = 1; w <= 9; w++) for (let h = 1; h <= 7; h++) {
for (let pixel = 0; pixel < sw * sh; pixel++) {
const source = new Float32Array(sw * sh);source[pixel] = 1;
assert.deepEqual(personMask(source, sw, sh, w, h), frozenPersonMask(source, sw, sh, w, h));
}
}
});

test("mask resize retains the strict Float32 threshold including adjacent values", () => {
const source = new Float32Array([-0, 0, 1.401298464324817e-45, .4999999701976776, .5, .5000000596046448, 1]);
assert.deepEqual([...personMask(source, 7, 1, 7, 1)], [0,0,0,0,0,1,1]);
});

test("mask resize rejects invalid confidence even when its pixel is never sampled", () => {
for (const value of [NaN, Infinity, -Infinity, -.01, 1.01]) for (const pixel of [1, 11]) {
const source = new Float32Array(12);source[pixel] = value;
assert.throws(() => personMask(source, 4, 3, 1, 1), { message: "人物マスクの値が範囲外です。" });
}
});

test("mask resize output storage is fresh and independent across repeated geometry", () => {
const source = new Float32Array([1, 0, 0, 1]), frozen = source.slice();
const a = personMask(source, 2, 2, 5, 7), old = a.slice(), b = personMask(source, 2, 2, 5, 7);
assert.notEqual(a.buffer, b.buffer);a.fill(0);assert.deepEqual(source, frozen);assert.deepEqual(b, old);
source.fill(0);assert.deepEqual(personMask(source, 2, 2, 5, 7), new Uint8Array(35));assert.deepEqual(b, old);
});

test("transferring a mask does not detach or overwrite another result", () => {
const source = new Float32Array([1, 0, 0, 1]);
const a = personMask(source, 2, 2, 192, 144), expected = a.slice();
const moved = structuredClone(a.buffer, { transfer: [a.buffer] });assert.equal(a.byteLength, 0);
const b = personMask(source, 2, 2, 192, 144);assert.deepEqual(new Uint8Array(moved), expected);assert.deepEqual(b, expected);
});

test("mask resize preserves shape/type error priority without changing caller input", () => {
const source = new Float32Array([NaN, 1]);
for (const dimensions of [[0,1,1,1],[1.5,1,1,1],[1,1,321,1],[1,1,1,1]]) assert.throws(() => personMask(source, ...dimensions), { message: "人物マスクのサイズが想定と異なります。" });
for (const source of [new Float64Array([1]), new Uint8Array([1]), [1], null]) assert.throws(() => personMask(source, 1, 1, 1, 1), { message: "人物マスクのサイズが想定と異なります。" });
assert.ok(Number.isNaN(source[0]));assert.equal(source[1], 1);
});

test("a completed bitmap remains caller-owned after its deadline or signal abort", async (t) => {
t.mock.timers.enable({ apis: ["setTimeout"] });
const c = new AbortController();let closed = 0;const bitmap = { close() { closed++; } };
Expand Down
7 changes: 7 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ FAST/LK math and explicit CPU/GPU ownership remain. Frozen native and actual
WASM comparisons verify report parity; timing includes all adverse conditions.
Physical-phone and operational accuracy qualification remain separate.

[Confidence-mask resize](CAMERA_MASK_RESIZE.md) reuses exact horizontal sampling
indices across rows and skips identity-width coordinate math. Complete source
validation, strict threshold and fresh transferable results remain. Temporary
indices need at most 640 logical bytes with no retained cache; frozen byte,
ownership and actual-browser controls accompany both retained and interleaved
timing observations. Device readbacks, model and Rust tracking stay unchanged.

[Marching-tetrahedra topology](MESH_SURFACE_TOPOLOGY.md) orders quadrilateral
cut vertices around their boundary and orients all changed cases toward
increasing field values for the existing positive-oriented cube tetrahedra.
Expand Down
117 changes: 117 additions & 0 deletions docs/CAMERA_MASK_RESIZE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Confidence-mask resize (146AT)

The optional camera worker keeps the existing personMask signature and exact
binary output. For different source/output widths, a temporary Uint16 array
computes floor(x*sourceWidth/width) once per column, reusing it across rows.
For equal widths, the exact source column is x and no index array is needed.
Vertical sampling retains floor(y*sourceHeight/height); exclusion still uses
strict confidence >0.5.

Shape/type admission and validation of every source float retain their order,
bounds and error text, including invalid pixels that resizing never samples.
All axes remain in 1..320; every mapped column is 0..319 and fits Uint16.
The temporary horizontal indices need at most 640 logical bytes. No index
cache is retained, and each result remains a fresh independently transferable
Uint8Array. These logical sizes exclude output, input, runtime and allocator
memory and do not guarantee browser RSS.

The worker protocol, model/SDK, explicit confidence/image CPU readbacks, gray
conversion, Rust mask-support tracker, public reports and dependencies remain.
This is CPU indexing inside the existing optional demo, not a GPU kernel.

## Correctness and ownership

The [source-bound receipt](receipts/2026-10-22_camera_mask_resize.json) records
92 passing JS controls on both parent and candidate, including eight new tests:
42 shape/pattern cases, all 102,400 horizontal size pairs, small single-pixel
supports, exact/adjacent Float32 threshold values, unsampled invalid floats,
shape/type priority, caller independence and transfer/detachment ownership.
The independent frozen parent predicate remains unchanged between the tests.

All six asset checks and 86 actual WASM/model browser controls pass. Four new
browser checks load the real module, compare 42 complete masks, reject five
unsampled invalid confidences and transfer output buffers without aliasing or
detaching subsequent results. Existing lifecycle, rotation, deadlines, restart,
timing, model inference and CSP coverage remains. Captures are synthetic;
physical phone and iOS Safari behavior are unqualified.

No Rust compilation is needed. The site reuses the current tested tracker WASM,
preserving the previous shared original WASM as well. Exact-head CI, merge and
the matching public Pages/browser checks are verified after the local receipt.

## Interleaved mask-only timing

The original protocol is
C:/Users/rsasa/Workspace/SpatialRust/benchmarks/camera-mask-resize-plan.json.
Its four-process observations reversed with order in several conditions; all
are retained below. A prospective follow-up protocol is
C:/Users/rsasa/Workspace/SpatialRust/benchmarks/camera-mask-resize-pair-plan.json.
Two fresh Node processes each warm both functions with 1024 checked calls per
shape, then run eight baseline/candidate/candidate/baseline rounds. Every sample
contains 16 calls; the tables show per-call medians from 16 samples per function.
All timed and warmup output bytes match the frozen parent outside the timer,
and source confidence bytes remain unchanged.

These are local Windows Node observations. Affinity, CPU frequency, host load
and garbage collection are uncontrolled, with no confidence intervals. Ratios
below 1 favor the candidate. Neither survey proves physical-phone, GPU,
AI-inference or end-to-end camera speed. All conditions, including slower
single-row/downsample observations, remain in the tables and raw receipt.

| Source -> output | Parent 1 us/call | New 1 us/call | New/parent 1 | Parent 2 us/call | New 2 us/call | New/parent 2 |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| 256x256 -> 192x144 | 1063.378 | 924.891 | 0.870 | 1310.372 | 1067.575 | 0.815 |
| 256x256 -> 256x192 | 1730.441 | 1499.194 | 0.866 | 1640.900 | 1327.050 | 0.809 |
| 256x256 -> 144x192 | 1312.112 | 1183.625 | 0.902 | 1250.119 | 1083.906 | 0.867 |
| 256x256 -> 192x256 | 1607.606 | 1276.316 | 0.794 | 1740.150 | 1346.703 | 0.774 |
| 320x320 -> 320x320 | 3149.703 | 2472.656 | 0.785 | 2769.863 | 2069.425 | 0.747 |
| 320x320 -> 64x64 | 1440.091 | 1498.372 | 1.040 | 1411.537 | 1408.181 | 0.998 |
| 64x64 -> 320x320 | 880.716 | 455.163 | 0.517 | 954.619 | 491.800 | 0.515 |
| 3x2 -> 5x7 | 0.450 | 0.406 | 0.903 | 0.481 | 0.431 | 0.896 |
| 320x1 -> 192x1 | 6.909 | 7.312 | 1.058 | 3.744 | 4.787 | 1.279 |
| 1x320 -> 1x320 | 11.059 | 8.606 | 0.778 | 12.059 | 10.641 | 0.882 |

Node v24.19.0, V8 13.6.233.17-node.51. Of 20 paired medians, 17 are lower and 3 higher for the candidate.

## Retained initial four-process observations

The initial protocol uses 128 checked warmups per shape, then seven samples
of 16 calls, in separate parent/candidate/candidate/parent processes. The
per-call times and ratios are preserved without pooling with the follow-up.

| Source -> output | Parent 1 us/call | New 1 us/call | New/parent 1 | Parent 2 us/call | New 2 us/call | New/parent 2 |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| 256x256 -> 192x144 | 1469.775 | 1214.606 | 0.826 | 1875.438 | 2703.850 | 1.442 |
| 256x256 -> 256x192 | 1762.394 | 1669.144 | 0.947 | 2705.156 | 2214.975 | 0.819 |
| 256x256 -> 144x192 | 1492.806 | 1429.838 | 0.958 | 1776.244 | 2640.588 | 1.487 |
| 256x256 -> 192x256 | 1690.631 | 1655.125 | 0.979 | 2028.463 | 2658.369 | 1.311 |
| 320x320 -> 320x320 | 2985.669 | 2455.431 | 0.822 | 10847.000 | 3123.900 | 0.288 |
| 320x320 -> 64x64 | 1384.394 | 1631.781 | 1.179 | 2875.300 | 2455.619 | 0.854 |
| 64x64 -> 320x320 | 1455.081 | 520.337 | 0.358 | 1120.331 | 1094.475 | 0.977 |
| 3x2 -> 5x7 | 0.719 | 0.369 | 0.513 | 1.350 | 0.744 | 0.551 |
| 320x1 -> 192x1 | 8.925 | 4.944 | 0.554 | 5.231 | 5.844 | 1.117 |
| 1x320 -> 1x320 | 10.319 | 6.906 | 0.669 | 13.250 | 16.038 | 1.210 |

Both public benchmark drivers accept --module and --reference paths:
scripts/benchmark_camera_mask_resize.mjs and
scripts/benchmark_camera_mask_resize_pair.mjs. The reference is the frozen
parent person-mask.mjs. Their inputs, clocks, checks and raw samples are bound
to the receipt's command/source hashes.

The first follow-up launcher rejected an ambiguous source substitution before
Node started. Preserve its script and failure transcript; a fresh wrapper targets
the unique source-list location. Both subsequent owned measurements completed.
This was a diagnostic-launch failure, not an application regression.

## Storage and remaining qualification

The owned E-drive root has a prospective 128MiB limit, zero permitted shared
compiler-cache growth, one owned command at a time and a 900-second deadline.
Nine vendor hardlinks reuse 41,087,603 bytes. There is no sensor, model, SDK,
browser or toolchain acquisition. Preserve all 2,354 prior camera/renderer files,
including the completed isolated Cargo target, 493 scientific JSON, 42 frozen
native artifacts, room/reference outputs and resolved lockfile.

Public verification has a 40MiB streaming limit and retains no downloaded vendor
payload files. Physical phones/Safari, calibrated camera timing, independent
motion, metric/full-room accuracy and operational 80% qualification remain open.
16 changes: 16 additions & 0 deletions docs/MOBILE_CAMERA_DEMO.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,19 @@ native timing surveys retain all 18 conditions each, including slower rows.
Builds use a capped isolated E-drive target; the shared cache, raw baseline WASM,
786 earlier camera/renderer files and scientific/native evidence are preserved.
Physical phone/Safari and operational 80% qualification remain open.

## Confidence-mask resize evidence (146AT)

[Confidence-mask resize](CAMERA_MASK_RESIZE.md) replaces repeated horizontal
nearest-neighbor calculations with a bounded per-call lookup, using exact
column identity when widths agree. The strict threshold, validation of every
source confidence, fresh transferable mask storage, model and explicit readbacks
remain. Temporary indices need at most 640 logical bytes and are not retained.

The [receipt](receipts/2026-10-22_camera_mask_resize.json) binds 92 parent/candidate
JS controls, six asset checks and 86 real WASM/model browser controls, including
42 exact browser mask cases. Two interleaved native Node surveys supplement
the retained order-reversing four-process measurements; all slower rows remain.
Reuse the current tested Rust WASM and vendor hardlinks without compilation or
shared-cache growth. Preserve 2,354 earlier files and all scientific/native
evidence. Physical phone/Safari and operational 80% qualification remain open.
Loading
Loading