<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Ovi Labs: log</title>
  <subtitle>What I shipped, verified and made faster, and the bugs I caught, week by week.</subtitle>
  <id>https://ovi.lt/</id>
  <link href="https://ovi.lt/log/"/>
  <link rel="self" href="https://ovi.lt/feed.xml"/>
  <updated>2026-11-23T12:00:00Z</updated>
  <author><name>Ovi</name></author>
  <entry>
    <title>Kelyje II: Merging triangle fans cut a quarter of the draws</title>
    <id>https://ovi.lt/log/kelyje2-fewer-draws/</id>
    <link href="https://ovi.lt/log/kelyje2-fewer-draws/"/>
    <updated>2026-11-23T12:00:00Z</updated>
    <summary>Stitching Direct3D 7 triangle fans into Kelyje II's strip batcher cut draws per frame by 25.1% and frame time by 12.8%, with zero differing pixels.</summary>
    <content type="html">&lt;p&gt;After &lt;a href=&quot;../kelyje2-faster-frames/&quot;&gt;moving the hottest scene functions to the C++ rewrite&lt;/a&gt;, the browser build still paid for hundreds of small Direct3D 7 draw calls on every frame. Counting what the batcher rejected showed most of the leftover calls were not hard cases at all.&lt;/p&gt;
&lt;h2 id=&quot;counting-what-fell-through&quot;&gt;Counting what fell through&lt;/h2&gt;
&lt;p&gt;The native batcher in the browser build merges consecutive triangle strips that share the same render state, joining them with zero-area (degenerate) triangles so the GPU draws them in one call. Anything the batcher does not recognise falls through to JavaScript as its own draw call.&lt;/p&gt;
&lt;p&gt;I added throwaway counters to the batcher over frames 100 to 1,000 of the &lt;a href=&quot;../kelyje2-frame-exact/&quot;&gt;1,000-frame scripted drive&lt;/a&gt;. Out of 560.3 draw submissions per frame, 170.1 fell through to JavaScript. Nearly all of those came from two places: triangle fans already in scope that were rejected solely for being fans, and draws from three functions (&lt;code&gt;0x005b4770&lt;/code&gt;, &lt;code&gt;0x005c89a0&lt;/code&gt; and &lt;code&gt;0x005cfd30&lt;/code&gt;) that sat outside the batcher's scope (plus one legacy fan format at &lt;code&gt;0x005b5773&lt;/code&gt;).&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;already batched:390.2|fans rejected by topology:87.9|three unscoped functions:70.3|legacy format (kept on JS):11.0|other (indexed):1.0&quot; data-unit=&quot;draw submissions per frame before the change&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;h2 id=&quot;turning-a-fan-into-a-strip&quot;&gt;Turning a fan into a strip&lt;/h2&gt;
&lt;p&gt;A triangle fan shares its first vertex across every triangle: &lt;code&gt;(v0, v1, v2)&lt;/code&gt;, then &lt;code&gt;(v0, v2, v3)&lt;/code&gt;, and so on. Expanding each triangle into an even-parity strip segment and joining it with the same degenerate stitch lets a fan ride inside a strip batch. That matches the expansion the renderer was already doing on its own.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;before (separate calls)
  strip A  -&amp;gt; draw 1
  fan   B  -&amp;gt; draw 2 (fell through to JS)
  strip C  -&amp;gt; draw 3

after (one stitched strip)
  [strip A | deg | fan B | deg | strip C]
           -&amp;gt; draw 1&lt;/pre&gt;
&lt;p&gt;Two guards keep the shortcut honest. Fan merging is only allowed under Gouraud shading (any other shade mode turns it off for the rest of the run), and a fan with a non-finite vertex position stays on the JavaScript path, matching the renderer's own finite check. A single legacy fan format (&lt;code&gt;0x1e2&lt;/code&gt;, 11.0 calls per frame) also stays on the JavaScript path.&lt;/p&gt;
&lt;h2 id=&quot;what-remained-and-what-it-saved&quot;&gt;What remained, and what it saved&lt;/h2&gt;
&lt;p&gt;With fans admitted and the three extra functions added to the submission scopes, every in-scope draw merges until the game actually changes render state: 118 texture switches (&lt;code&gt;SetTexture&lt;/code&gt;) and 21.7 transform changes (&lt;code&gt;SetTransform&lt;/code&gt;) per frame.&lt;/p&gt;
&lt;p&gt;On the 1,000-frame scripted drive, total draws fell from 258,215 to 193,366 (258.2 to 193.4 per frame, 25.1% fewer). Every one of the 1,000 frames kept the same state hash and the same pixel hash as the canonical run, with zero differing pixels, alongside 1,054 submission fixture checks and 415 regression tests.&lt;/p&gt;
&lt;p&gt;In a quiet alternating (old, new, new, old) run over frames 100 to 1,000, frame time dropped from 13.998 to 12.207 ms per frame, 1.79 ms (12.8%) faster. That is the scripted drive on one desktop browser; other scenes and browsers will vary with how often they switch textures.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>XP Max: Hardware WebGPU in Chromium 160 on Windows XP</title>
    <id>https://ovi.lt/log/xp-max-webgpu/</id>
    <link href="https://ovi.lt/log/xp-max-webgpu/"/>
    <updated>2026-11-23T12:00:00Z</updated>
    <summary>Hardware WebGPU in Chromium 160 on Windows XP Max: Direct3D 11.1, a non-zero adapter LUID and shared textures between ANGLE and Dawn, at 59.7 fps with exact compute readback.</summary>
    <content type="html">&lt;p&gt;Windows XP shipped in 2001 with DirectX 8.1. My virtual GPU for XP Max already gave Chromium 160 hardware WebGL 1 and WebGL 2 at 60 fps through Direct3D 11. The next question was whether WebGPU could run on it too.&lt;/p&gt;
&lt;p&gt;It now does. Chromium 160 on XP Max gets a real hardware WebGPU adapter (&lt;code&gt;vendor=nvidia&lt;/code&gt;, &lt;code&gt;architecture=lovelace&lt;/code&gt;, &lt;code&gt;isFallbackAdapter=false&lt;/code&gt;), renders a live canvas at 59.1–59.8 fps, and runs GPU compute shaders with exact readback.&lt;/p&gt;
&lt;figure class=&quot;shot&quot;&gt;&lt;a href=&quot;/media/xpmax-webgpu.png&quot;&gt;&lt;img src=&quot;/media/xpmax-webgpu.png&quot; alt=&quot;Chromium 160 running hardware WebGPU render and compute on Windows XP Max&quot; loading=&quot;lazy&quot;&gt;&lt;/a&gt;&lt;figcaption&gt;Chromium 160 on Windows XP Max: a live rotating RGB triangle rendered with WebGPU (59.7 fps) alongside a 4,096-element compute shader verified with &lt;code&gt;mapAsync&lt;/code&gt;, backed by the host RTX 4070 Ti Super through GigaMax D3D11.&lt;/figcaption&gt;&lt;/figure&gt;
&lt;h2 id=&quot;what-webgpu-is-and-how-it-compares-to-webgl&quot;&gt;What WebGPU is, and how it compares to WebGL&lt;/h2&gt;
&lt;p&gt;WebGL was built on OpenGL ES — a design from the early 1990s shaped around one global state machine. Every draw call mutates hidden context state, validation happens at draw time, and the browser has to work hard on the CPU to translate that model onto modern GPUs. Worse, WebGL has no real compute shaders: if you want general-purpose GPU math in WebGL, you have to pack numbers into textures and pretend you are drawing pixels.&lt;/p&gt;
&lt;p&gt;WebGPU is the replacement designed around how modern GPUs actually work (Direct3D 12, Metal and Vulkan). Pipelines, shader layouts and resource bindings are compiled and validated up front into immutable objects, commands are recorded into command buffers and submitted in batches, and shaders are written in WGSL. Most importantly, WebGPU gives the browser first-class compute shaders (&lt;code&gt;@compute&lt;/code&gt;) with read/write storage buffers and workgroup shared memory.&lt;/p&gt;
&lt;div class=&quot;table&quot;&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;WebGL 1 / 2&lt;/th&gt;&lt;th&gt;WebGPU&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;th scope=&quot;row&quot;&gt;Underlying model&lt;/th&gt;&lt;td&gt;OpenGL ES global state machine&lt;/td&gt;&lt;td&gt;Modern explicit GPU APIs (D3D12 / Metal / Vulkan)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th scope=&quot;row&quot;&gt;Compute shaders&lt;/th&gt;&lt;td&gt;None (fragment-shader texture hacks)&lt;/td&gt;&lt;td&gt;Native &lt;code&gt;@compute&lt;/code&gt; + read/write storage buffers&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th scope=&quot;row&quot;&gt;Shader language&lt;/th&gt;&lt;td&gt;GLSL&lt;/td&gt;&lt;td&gt;WGSL&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th scope=&quot;row&quot;&gt;Validation &amp;amp; CPU cost&lt;/th&gt;&lt;td&gt;Per-draw state checks on the main path&lt;/td&gt;&lt;td&gt;Up-front immutable pipelines and bind groups&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;th scope=&quot;row&quot;&gt;Typical native backend on Windows&lt;/th&gt;&lt;td&gt;ANGLE over Direct3D 11&lt;/td&gt;&lt;td&gt;Dawn over Direct3D 12 (or D3D11)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;h2 id=&quot;why-it-matters&quot;&gt;Why it matters&lt;/h2&gt;
&lt;p&gt;WebGPU is where GPU work on the web is moving. Browser-side machine learning (WebLLM, ONNX Runtime Web, Transformers.js) relies on compute shaders to run neural networks locally on the GPU instead of crawling on the CPU. Physics, particle simulations, video and audio filters, CAD tools and modern 3D engines are moving off WebGL for the same reason, and Chromium's own next-generation 2D renderer (Skia Graphite) is built on Dawn. Getting WebGPU working on XP Max means a 25-year-old operating system can run the modern GPU web natively on the host card rather than falling back to a CPU software rasterizer.&lt;/p&gt;
&lt;h2 id=&quot;why-it-did-not-work-out-of-the-box&quot;&gt;Why it did not work out of the box&lt;/h2&gt;
&lt;p&gt;On Windows, Chromium's WebGPU implementation (Dawn) defaults to Direct3D 12, and XP has no &lt;code&gt;d3d12.dll&lt;/code&gt; and no Vulkan ICD. Firefox 160 was a dead end for a different reason: the 32-bit Windows build rejects WebGPU before choosing a backend at all (&lt;code&gt;WebGPU is only available on 64-bit architectures&lt;/code&gt;), and its &lt;code&gt;wgpu&lt;/code&gt; engine has no Direct3D 11 backend anyway.&lt;/p&gt;
&lt;p&gt;Chromium's Dawn, however, does have a Direct3D 11 backend. Passing &lt;code&gt;--use-webgpu-adapter=d3d11&lt;/code&gt; switches Dawn onto D3D11 — and immediately exposed three gaps between our existing D3D11.0 stack (enough for ANGLE and WebGL 2) and what Dawn expects.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;Chromium 160 GPU process (Windows XP Max)
+--------------------------------------------------+
| WebGL / Compositor (ANGLE)    WebGPU (Dawn)      |
|  D3D11.0 device                D3D11.1 device    |
|  creates shared BGRA tex -----&amp;gt; OpenSharedRes1   |
|  (NT handle + keyed mutex)     renders + compute |
+------------------+--------------------+----------+
                   |  guest dxgi.dll + d3d11.dll   |
                   +---------------+---------------+
                                   | shared memory ring (\\.\XpGpu)
Host presenter (Windows 11)        v
+--------------------------------------------------+
| d3d11host.inc -&amp;gt; real host D3D11.1 on RTX 4070Ti |
|  MISC_SHARED cross-device texture + KM_SYNC wait |
+--------------------------------------------------+&lt;/pre&gt;
&lt;h2 id=&quot;what-had-to-be-implemented&quot;&gt;What had to be implemented&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A real adapter LUID and DXGI 1.2–1.4 (&lt;code&gt;dxgi.dll&lt;/code&gt;).&lt;/strong&gt; Our virtual DXGI adapter previously reported an &lt;code&gt;AdapterLuid&lt;/code&gt; of zero. Chromium reads ANGLE's active adapter LUID and treats zero as &amp;quot;no GPU&amp;quot;, aborting WebGPU before Dawn even starts (&lt;code&gt;Failed to query ID3D11Device from ANGLE&lt;/code&gt;). Giving the adapter a fixed non-zero LUID and implementing &lt;code&gt;IDXGIAdapter2&lt;/code&gt;/&lt;code&gt;3&lt;/code&gt; (&lt;code&gt;GetDesc2&lt;/code&gt;, &lt;code&gt;QueryVideoMemoryInfo&lt;/code&gt;) and &lt;code&gt;IDXGIFactory3&lt;/code&gt;/&lt;code&gt;4&lt;/code&gt; (&lt;code&gt;EnumAdapterByLuid&lt;/code&gt;) let Dawn find the card. Two interfaces were deliberately left unclaimed: omitting &lt;code&gt;IDXGIAdapter4&lt;/code&gt; tells Dawn to run fence-less (avoiding &lt;code&gt;ID3D11Device5&lt;/code&gt; and &lt;code&gt;ID3D11Fence&lt;/code&gt;), and omitting &lt;code&gt;IDXGIFactory2&lt;/code&gt; keeps ANGLE on its existing swap-chain path.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Direct3D 11.1–11.3 (&lt;code&gt;d3d11.dll&lt;/code&gt;).&lt;/strong&gt; Dawn asks &lt;code&gt;D3D11CreateDevice&lt;/code&gt; specifically for &lt;code&gt;{11_1, 11_0}&lt;/code&gt; — Feature Level &lt;code&gt;11_1&lt;/code&gt; is required for WebGPU core, with &lt;code&gt;ConstantBufferOffsetting&lt;/code&gt; reported TRUE from &lt;code&gt;CheckFeatureSupport&lt;/code&gt;. We added FL &lt;code&gt;11_1&lt;/code&gt; selection for Dawn's probe (leaving ANGLE untouched at &lt;code&gt;11_0&lt;/code&gt;), plus &lt;code&gt;ID3D11Device1..3&lt;/code&gt;, &lt;code&gt;ID3D11DeviceContext1..3&lt;/code&gt;, &lt;code&gt;ID3D11Multithread&lt;/code&gt;, &lt;code&gt;ID3DUserDefinedAnnotation&lt;/code&gt;, constant-buffer binding with offsets (&lt;code&gt;*SetConstantBuffers1&lt;/code&gt;), &lt;code&gt;UpdateSubresource1&lt;/code&gt; and &lt;code&gt;CopySubresourceRegion1&lt;/code&gt;, &lt;code&gt;Create*View1&lt;/code&gt;, &lt;code&gt;CreateDeviceContextState&lt;/code&gt; / &lt;code&gt;SwapDeviceContextState&lt;/code&gt;, &lt;code&gt;Flush1(event)&lt;/code&gt;, and raised UAV slot counts from 8 to 64.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shared textures between ANGLE and Dawn (&lt;code&gt;d3d11.dll&lt;/code&gt; + host presenter).&lt;/strong&gt; Once compute shaders passed, presenting a WebGPU &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; crashed the GPU process: Chromium creates the canvas backing texture on ANGLE's D3D11 device with &lt;code&gt;SHARED_NTHANDLE | SHARED_KEYEDMUTEX&lt;/code&gt;, asks it for &lt;code&gt;IDXGIResource1::CreateSharedHandle&lt;/code&gt;, and hands that handle to Dawn's separate D3D11 device via &lt;code&gt;OpenSharedResource1&lt;/code&gt;. We implemented &lt;code&gt;IDXGIResource1&lt;/code&gt; and &lt;code&gt;IDXGIKeyedMutex&lt;/code&gt; on shared guest textures: &lt;code&gt;CreateSharedHandle&lt;/code&gt; returns a real named kernel event encoding the texture id so Chromium can duplicate and close it normally, and &lt;code&gt;OpenSharedResource1&lt;/code&gt; recovers the id via &lt;code&gt;NtQueryObject&lt;/code&gt;. Two new wire ops (&lt;code&gt;OPEN_SHARED&lt;/code&gt; and &lt;code&gt;KM_SYNC&lt;/code&gt;) let the host presenter map guest NT-handle textures to host &lt;code&gt;MISC_SHARED&lt;/code&gt; textures, open them on the target host device, and synchronize on keyed-mutex release.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-was-verified-and-what-is-still-rough&quot;&gt;What was verified, and what is still rough&lt;/h2&gt;
&lt;p&gt;In a Chromium 160 VM launched with &lt;code&gt;--enable-unsafe-webgpu --use-webgpu-adapter=d3d11&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Adapter:&lt;/strong&gt; &lt;code&gt;vendor=nvidia&lt;/code&gt;, &lt;code&gt;architecture=lovelace&lt;/code&gt;, &lt;code&gt;isFallbackAdapter=false&lt;/code&gt;, &lt;code&gt;maxTextureDimension2D=16384&lt;/code&gt;, &lt;code&gt;maxComputeInvocationsPerWorkgroup=1024&lt;/code&gt;, with &lt;code&gt;float32-blendable&lt;/code&gt;, &lt;code&gt;depth32float-stencil8&lt;/code&gt;, &lt;code&gt;rg11b10ufloat-renderable&lt;/code&gt;, &lt;code&gt;bgra8unorm-storage&lt;/code&gt;, &lt;code&gt;texture-formats-tier1&lt;/code&gt; and &lt;code&gt;depth-clip-control&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Render:&lt;/strong&gt; rotating RGB triangle on a &lt;code&gt;bgra8unorm&lt;/code&gt; canvas at &lt;strong&gt;59.1–59.8 fps&lt;/strong&gt;, zero uncaptured errors, no device loss; two screenshots 2 seconds apart differ in 50.9k pixels.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compute:&lt;/strong&gt; a &lt;code&gt;@workgroup_size(64)&lt;/code&gt; WGSL shader computing &lt;code&gt;v * 2 + id&lt;/code&gt; across 4,096 &lt;code&gt;u32&lt;/code&gt; values, copied to a &lt;code&gt;MAP_READ&lt;/code&gt; buffer and read back with &lt;code&gt;mapAsync&lt;/code&gt;, returned &lt;strong&gt;4,096 of 4,096&lt;/strong&gt; exact values (&lt;code&gt;14, 21, 28, 35 ... 28679&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Regressions:&lt;/strong&gt; &lt;code&gt;d11test native&lt;/code&gt; passed 9/9 with 0 differing pixels, &lt;code&gt;d11test presenter&lt;/code&gt; passed with 0 differing pixels, and WebGL 2 stayed at 60.0 fps with zero errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The rough edges are clear: Chromium still needs &lt;code&gt;--enable-unsafe-webgpu --use-webgpu-adapter=d3d11&lt;/code&gt; because D3D11 is not selected by default on Windows and the adapter sits behind Chromium's WebGPU blocklist; &lt;code&gt;IDXGIKeyedMutex::ReleaseSync&lt;/code&gt; currently costs one host GPU wait per canvas frame; shared textures are same-process only for now; and &lt;code&gt;SwapDeviceContextState&lt;/code&gt; swaps only the state object (fine for Dawn's dedicated device, not yet general). Even with those limits, real hardware WebGPU rendering and compute shaders now run on Windows XP.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Kelyje II: The C++ rewrite now matches the original, frame for frame</title>
    <id>https://ovi.lt/log/kelyje2-frame-exact/</id>
    <link href="https://ovi.lt/log/kelyje2-frame-exact/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>Kelyje II's C++ rewrite now runs inside the original game: on a scripted drive the truck, money and clocks match bit for bit on 1,000 of 1,000 frames.</summary>
    <content type="html">&lt;p&gt;Code recovered from a 2000 binary still runs, but nobody can maintain it. Rewriting it as C++ with clear names is only worth doing if the result still behaves exactly like the original.&lt;/p&gt;
&lt;h2 id=&quot;swap-some-functions-keep-the-rest&quot;&gt;Swap some functions, keep the rest&lt;/h2&gt;
&lt;p&gt;The rewrite is built as a DLL and loaded next to the original game. Each replaced function is patched to jump to its C++ version. Everything else stays original, so the game still runs with only part of it rewritten.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;original game          C++ rewrite (DLL)
+------------+         +------------+
| function A-+--jump--&amp;gt;| function A |
| function B |         |            |
| function C-+--jump--&amp;gt;| function C |
+------------+         +------------+
B still runs as the original&lt;/pre&gt;
&lt;h2 id=&quot;what-matches-means-here&quot;&gt;What &amp;quot;matches&amp;quot; means here&lt;/h2&gt;
&lt;p&gt;The reference is the original game on a scripted drive: a fixed 20 ms step, a fixed random seed, and the same key presses every time. On each of 1,000 frames the test writes down the player's truck (velocity, spin, position, gear), the money and the game clocks, as raw float bits. The rewrite has to produce the same 1,000 lines, bit for bit.&lt;/p&gt;
&lt;p&gt;That is a sample of the game's state. It proves the truck, the money and the clocks on that one drive, and says nothing about paths the drive never takes.&lt;/p&gt;
&lt;h2 id=&quot;growing-it-in-steps&quot;&gt;Growing it in steps&lt;/h2&gt;
&lt;p&gt;I grew it in four steps: 19 functions on the first run, then 23 source files (484 functions), 79 files (2,696) and all 108 (5,227). Small steps keep failures findable: when one breaks, the cause is among the functions added since the last good run.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;first run:19|23 source files:484|79 source files:2696|all 108 source files:5227&quot; data-unit=&quot;functions replaced&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;With all 5,227 swapped in, 1,000 of 1,000 frames equalled the original. The first thing that broke on the way was &lt;a href=&quot;../kelyje2-wrong-slots/&quot;&gt;104 classes with misplaced methods&lt;/a&gt;; that is the next entry.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Kelyje II: It compiled, and 104 of 211 classes were wrong</title>
    <id>https://ovi.lt/log/kelyje2-wrong-slots/</id>
    <link href="https://ovi.lt/log/kelyje2-wrong-slots/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>Kelyje II's C++ rewrite compiled cleanly and crashed: 104 of 211 classes had virtual methods in the wrong vtable slots.</summary>
    <content type="html">&lt;p&gt;I test the C++ rewrite by building it as a DLL and loading it into the original game, where each rewritten function takes over from the original's. The first build compiled cleanly. Loaded, it crashed within seconds. This was before it &lt;a href=&quot;../kelyje2-frame-exact/&quot;&gt;matched the original&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-a-wrong-slot-is&quot;&gt;What a wrong slot is&lt;/h2&gt;
&lt;p&gt;A C++ class with virtual methods keeps a table of them, the vtable, and calls go by position: call whatever is in slot 2. The original binary fixed those positions in 2000 and still calls by them. If the rewrite declares the same methods in a different order, the original asks for slot 2 and gets a different method.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;slot  original calls  rewrite has
0     destructor      destructor
1     update          draw      wrong
2     draw            update    wrong&lt;/pre&gt;
&lt;p&gt;That class is made up. In the real one that gave it away, a method sat at offset &lt;code&gt;0xb0&lt;/code&gt; (slot 44) in the game and &lt;code&gt;0x64&lt;/code&gt; (slot 25) in my header.&lt;/p&gt;
&lt;h2 id=&quot;reading-the-answer-out-of-the-binary&quot;&gt;Reading the answer out of the binary&lt;/h2&gt;
&lt;p&gt;I had no source code showing the original method order, so I wrote a checker. Every constructor writes the address of its class's vtable into the new object. The checker reads that address from each constructor, finds the table in the game's executable, and compares it slot by slot with the table the compiler produces from my headers.&lt;/p&gt;
&lt;p&gt;It checked 211 classes and 1,242 slots: 104 classes and 621 slots were wrong. The fix was bookkeeping: give each class its base classes in the right order, make each override really override its base method, and add the missing placeholder slots. Now all 1,242 match.&lt;/p&gt;
&lt;h2 id=&quot;what-else-the-same-runs-turned-up&quot;&gt;What else the same runs turned up&lt;/h2&gt;
&lt;p&gt;None of these stops the compiler. Each showed itself within seconds of running:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a menu that stopped taking input because its vtable lacked one override&lt;/li&gt;
&lt;li&gt;a function with the wrong calling convention, so both caller and callee popped the stack&lt;/li&gt;
&lt;li&gt;18 destructors that called themselves&lt;/li&gt;
&lt;li&gt;a function that assigned a truck's body height to itself&lt;/li&gt;
&lt;li&gt;a lookup that compared the wrong column, so the game insisted there was no such vehicle as a Fiat&lt;/li&gt;
&lt;li&gt;an allocator that deadlocked by taking its own lock twice&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And the DLL itself first loaded at &lt;code&gt;0x10000000&lt;/code&gt;, on top of memory the game had already mapped.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Kelyje II: The street lamp that stopped the game</title>
    <id>https://ovi.lt/log/kelyje2-street-lamp/</id>
    <link href="https://ovi.lt/log/kelyje2-street-lamp/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>One street lamp stopped Kelyje II in the browser: its light range was one float away from a value I had measured at the wrong precision.</summary>
    <content type="html">&lt;h2 id=&quot;a-strict-check-on-five-kinds-of-light&quot;&gt;A strict check on five kinds of light&lt;/h2&gt;
&lt;p&gt;The browser build of Kelyje II draws through my own renderer, and the renderer is strict: a spot light is accepted only if its values match, bit for bit, one of five kinds I measured from the original game (beam, police, helicopter, lamp and warm lamp). Anything else stops the game with an error. I switched the browser build to the float precision the original uses, and from then on it halted whenever one particular street lamp came into view.&lt;/p&gt;
&lt;h2 id=&quot;floats-come-in-steps&quot;&gt;Floats come in steps&lt;/h2&gt;
&lt;p&gt;A 32-bit float cannot hold every number, only a fixed set of them. Near 126, neighbouring floats are about 0.0000076 apart, and that gap is called one unit in the last place. Two calculations that differ only in how they round can land on neighbouring floats.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;0x42fcfb70  .
0x42fcfb71  #  on my list (measured at 24-bit)
0x42fcfb72  o  what the game computes at 53-bit
0x42fcfb73  .&lt;/pre&gt;
&lt;h2 id=&quot;measured-at-24-bit-computed-at-53&quot;&gt;Measured at 24-bit, computed at 53&lt;/h2&gt;
&lt;p&gt;The x87 floating-point unit does its working at a set precision (24 significant bits like a float, 53 like a double, or 64) and only rounds to a 32-bit float when the result is stored. The original game works at 53. When I measured those lights, my test harness had dropped a flag the game passes to Direct3D, so Direct3D quietly switched the maths to 24-bit. I recorded the game's numbers at the wrong precision and copied them into the browser build.&lt;/p&gt;
&lt;p&gt;At the right precision the lamp's range, 4 divided by a square root, rounds one float higher: &lt;code&gt;0x42fcfb72&lt;/code&gt; where my list said &lt;code&gt;0x42fcfb71&lt;/code&gt;. Both are about 126.49. Nobody could see the difference on screen, yet the check stopped the game over it.&lt;/p&gt;
&lt;p&gt;The fix admits both values for the two lamp kinds, and a new test replays 22 recorded lights through 431 checks.&lt;/p&gt;
&lt;h2 id=&quot;a-second-gap-nan&quot;&gt;A second gap: NaN&lt;/h2&gt;
&lt;p&gt;The same week my native Apple Silicon build, which runs outside the browser, stopped on a point whose coordinates were all NaN, &amp;quot;not a number&amp;quot;. That is a different check in the same renderer, just as strict: it accepted only one bit pattern for NaN, and NaN has many. The original's x87 maths produces one with the sign bit set, &lt;code&gt;0xffc00000&lt;/code&gt;. Apple Silicon's default NaN has it clear, &lt;code&gt;0x7fc00000&lt;/code&gt;, and the check knew only the first. It now ignores the sign bit.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Kelyje II: The browser build now takes 18.56% less time per frame</title>
    <id>https://ovi.lt/log/kelyje2-faster-frames/</id>
    <link href="https://ovi.lt/log/kelyje2-faster-frames/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>Kelyje II's C++ rewrite, compiled to WebAssembly and swapped into the browser build: 18.56% less time per frame on the game's thread.</summary>
    <content type="html">&lt;p&gt;The &lt;a href=&quot;../kelyje2-frame-exact/&quot;&gt;C++ rewrite, now verified against the original&lt;/a&gt;, can replace the translated code where the game spends its time. I wanted the rewrite for reading first; speed was the plan once I knew it matched.&lt;/p&gt;
&lt;h2 id=&quot;one-slice-at-a-time&quot;&gt;One slice at a time&lt;/h2&gt;
&lt;p&gt;I compile the rewrite to WebAssembly in slices (groups of related functions) and swap each into the busiest parts of the browser build. Each slice keeps the old code behind it: if a call arrives in a case the new code has not been proved to handle, the old code handles it instead, and I count each such fallback. The first slice was a trial, rotation maths: 1,046,942 calls went through it and none fell back. Next came a bridge so old and new code could call each other, then three slices for the scene: query, walk and render.&lt;/p&gt;
&lt;h2 id=&quot;virtual-calls-made-direct&quot;&gt;Virtual calls made direct&lt;/h2&gt;
&lt;p&gt;A virtual call looks up its target in a table while the game runs. A direct call already knows its target, which costs less and lets the compiler inline it. A devirtualising pass in my build makes that change wherever the target is known.&lt;/p&gt;
&lt;p&gt;With query and walk in, 94.8% of the 26.9 million calls that used to be virtual in the 1,000-frame test drive were direct. Render took that to 96.2%.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;made direct, after query and walk:94.8|made direct, after render:96.2&quot; data-max=&quot;100&quot; data-unit=&quot;% of virtual calls&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;h2 id=&quot;how-i-measured-it&quot;&gt;How I measured it&lt;/h2&gt;
&lt;p&gt;Each measurement runs old, new, new, old, so anything that drifts during the run affects both equally. It runs on a machine with nothing else busy, over frames 100 to 1,000 of the scripted drive &lt;a href=&quot;../kelyje2-frame-exact/&quot;&gt;used to verify the rewrite&lt;/a&gt;. A sample only counts if the build still reproduces all 1,000 reference frames bit for bit, so a faster build that is subtly wrong cannot win.&lt;/p&gt;
&lt;p&gt;With query and walk only, the game's thread went from 20.876 to 17.088 ms per frame, 18.1% less. With render added and all three on by default, it is 18.56% less. That is the game's own thread; putting the picture on screen is separate and takes about 0.03 ms.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Browsteer: Browsteer 2: locked until you open it</title>
    <id>https://ovi.lt/log/browsteer-2/</id>
    <link href="https://ovi.lt/log/browsteer-2/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>Browsteer 2 locks agent access to a signed-in browser by default: same machine only, a pairing key, one site at a time, and it locks itself again after an hour.</summary>
    <content type="html">&lt;h2 id=&quot;locked-by-default&quot;&gt;Locked by default&lt;/h2&gt;
&lt;p&gt;Browsteer now accepts connections only from the same machine, needs a pairing key, works on one site at a time and locks itself again after an hour. The extension's popup shows the state by colour: grey when locked, blue when open, amber when about to lock, with a bar that drains over the hour. The popup turns red when one of two settings is on, &amp;quot;Until I press Stop&amp;quot; or &amp;quot;Every site except blocked&amp;quot;. Both are off by default and ask for confirmation.&lt;/p&gt;
&lt;h2 id=&quot;the-hole-a-review-found&quot;&gt;The hole a review found&lt;/h2&gt;
&lt;p&gt;An independent review found a way around the one-site rule. When the agent fetched a page, Browsteer checked the first URL against the allowed site, then followed redirects with your cookies.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;1  agent fetches a page on the allowed site
     checked, allowed
2  that page redirects to another site
3  the fetch follows, cookies attached
     never checked&lt;/pre&gt;
&lt;p&gt;The first fix refused every redirect. The second allows them safely: a request now stops at each redirect, and the URL it points to goes through the same three checks as the initial URL (on your allowed list, not on your blocked list, and the one site this session is open for) before anything is sent, for at most five hops.&lt;/p&gt;
&lt;h2 id=&quot;signed-and-updating-itself&quot;&gt;Signed, and updating itself&lt;/h2&gt;
&lt;p&gt;Tagging a release now gets the Firefox build signed by Mozilla's add-on service and publishes a small file that lists the new version and its checksum, so version 2 is the first I do not have to hand out myself. Firefox checks that file about once a day.&lt;/p&gt;
&lt;h2 id=&quot;also-in-version-2&quot;&gt;Also in version 2&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Password fields no longer appear in the page snapshots an agent reads.&lt;/li&gt;
&lt;li&gt;A refused session fails at once and says why; it used to wait out a 130-second timeout.&lt;/li&gt;
&lt;li&gt;Browsteer can now hold sessions across several browsers at once, and compare the same page between them.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
  <entry>
    <title>devserver: One command for the dev server</title>
    <id>https://ovi.lt/log/devserver/</id>
    <link href="https://ovi.lt/log/devserver/"/>
    <updated>2026-11-22T12:00:00Z</updated>
    <summary>I read 246 coding-agent sessions and saw commands wasted on netstat, sleeps and port picking. devserver is one command that reuses a dev server or starts it.</summary>
    <content type="html">&lt;h2 id=&quot;how-dev-project-works&quot;&gt;How &lt;code&gt;dev &amp;lt;project&amp;gt;&lt;/code&gt; works&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;dev &amp;lt;project&amp;gt;&lt;/code&gt; reuses the project's dev server if it is already running and starts it in the background if not. A second checkout of the same project gets its own free port. The command returns only when the server answers its health URL, or fails at once and shows the end of the server's log.&lt;/p&gt;
&lt;h2 id=&quot;alive-or-not-without-tracking-process-ids&quot;&gt;Alive or not, without tracking process IDs&lt;/h2&gt;
&lt;p&gt;The first version tracked servers by process ID and lock folders. Now each server is started by a small launcher process, and the launcher listens on a named pipe on Windows, or a Unix socket elsewhere. Only a live launcher can answer, so a crashed one cannot look alive the way a stale process ID or lock folder can. To stop the server, the command sends a message to the same pipe.&lt;/p&gt;
&lt;h2 id=&quot;is-this-server-mine&quot;&gt;Is this server mine?&lt;/h2&gt;
&lt;p&gt;A review found a hole: the command assumed whatever process held the port was its own server. Now it walks up from the process listening on the port, parent by parent, and accepts the server only if that chain reaches its own launcher.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;launcher (mine)
  -&amp;gt; shell
       -&amp;gt; dev server, on the port

walk up from the listener:
reach the launcher, or refuse&lt;/pre&gt;
&lt;p&gt;The check also compares start times: a parent that started later than its child is a reused process ID, not a parent. It took six rounds of review to get there.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Local models: Qwen3.6-35B on a 16 GB RTX 4070 Ti Super: 40 to 102 tokens a second</title>
    <id>https://ovi.lt/log/qwen-35b-rtx-4070-ti-super-16gb/</id>
    <link href="https://ovi.lt/log/qwen-35b-rtx-4070-ti-super-16gb/"/>
    <updated>2026-11-15T12:00:00Z</updated>
    <summary>Qwen3.6-35B-A3B on a 16 GB RTX 4070 Ti Super with llama.cpp: from 40 to 102 tokens/s, the exact flags, tool-call results and what broke.</summary>
    <content type="html">&lt;p&gt;I wanted open-weight coding models running on my own desktop, fast enough for an agent that calls tools in a loop. The card is an RTX 4070 Ti Super with 16 GB, next to a Ryzen 7 5700X3D and 32 GB of DDR4. The model, Qwen3.6-35B-A3B, is about 22 GB at 4-bit, so it does not fit.&lt;/p&gt;
&lt;h2 id=&quot;what-is-fast-enough-for-a-coding-agent&quot;&gt;What is fast enough for a coding agent?&lt;/h2&gt;
&lt;p&gt;I set the targets before measuring, all at 32,000 tokens of context:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;at least 50 tokens a second of generation, because agents write a lot of thinking and tool-call JSON&lt;/li&gt;
&lt;li&gt;at least 1,000 tokens a second reading the prompt; an agent's system prompt runs to 10 or 30 thousand tokens, and at 300 a second a cold 20,000-token prompt takes over a minute&lt;/li&gt;
&lt;li&gt;at least 64,000 tokens of usable context&lt;/li&gt;
&lt;li&gt;at least 98% of tool calls that parse, since one broken call derails a run&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;does-a-35b-model-fit-in-16-gb-of-video-memory&quot;&gt;Does a 35B model fit in 16 GB of video memory?&lt;/h2&gt;
&lt;p&gt;This model is a mixture of experts: 35 billion parameters, of which about 3 billion are used for any one token. So most of it can sit in ordinary RAM, as long as the parts every token needs, and the experts used most often, are on the card.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;video card, 16 GB        RAM, 32 GB
+------------------+     +----------------+
| attention        |     | all the        |
| context cache    |&amp;lt;----| experts        |
| hot experts      |     |                |
+------------------+     +----------------+
keep about 1.5 GB free for the desktop&lt;/pre&gt;
&lt;h2 id=&quot;llama-cpp-settings-one-change-at-a-time&quot;&gt;llama.cpp settings, one change at a time&lt;/h2&gt;
&lt;p&gt;Each run changed one setting, with the desktop in normal use, and every number went into a results file.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;1 default settings:40|2 no memory mapping:54|3 draft tokens:59|4 larger batches:67|5 expert cache:83|6 all of it, 64K:113|7 the same at 128K:98&quot; data-unit=&quot;tokens per second, short generation&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;Two changes did most of the work. With default settings the machine ran out of RAM and kept re-reading 8.7 GB of the model from disk; turning memory mapping off ended that and doubled prompt reading, from about 500 tokens a second to 1,320. Then a cache of the most-used experts in spare video memory added 55% to generation for the same memory.&lt;/p&gt;
&lt;p&gt;Three things did not help: computing half the cache misses on the CPU (83 down to 70; the RAM is too slow), a longer draft, and a 128K context without shrinking the cache, which spilled video memory and halved prompt reading.&lt;/p&gt;
&lt;h2 id=&quot;tool-calls-and-claude-code-on-a-local-model&quot;&gt;Tool calls and Claude Code on a local model&lt;/h2&gt;
&lt;p&gt;Speed is no use if the tool calls come out broken. I ran nine agent-style cases five times each: 45 of 45 well-formed calls, one or two seconds per call. Then I pointed Claude Code at the local server. The first turn reads an 11,200-token system prompt in 7 seconds, later turns start in under a second, and a bug-fix task took 17 turns and 48 seconds and was correct.&lt;/p&gt;
&lt;p&gt;A second model of the same design, Ornith 1.5, was faster and a little less careful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ornith: 99 tokens a second short, 85 at 32K, 42 of 45 tool calls&lt;/li&gt;
&lt;li&gt;Qwen: 90 short, 72 at 32K, 45 of 45&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;two-things-that-broke&quot;&gt;Two things that broke&lt;/h2&gt;
&lt;p&gt;Threads got stuck. Two kinds of message made the server answer with an error: a block Claude Code sends after it looks up a tool, and images. Claude Code retries, and because the bad message stays in the history, every later turn fails too. A corrected chat template fixed the first. Loading the model's vision part on the CPU fixed the second, at about 1.5 seconds per image and no video memory.&lt;/p&gt;
&lt;p&gt;Then Windows' own compositor crashed. At a 128K context the model held 15.8 of the card's 16 GB, and the desktop ran out. Storing the context cache at 8 bits bought back about 1.2 GB for 8% slower prompt reading and no loss in generation. The rule since: leave about 1.5 GB of video memory for the desktop.&lt;/p&gt;
&lt;h2 id=&quot;the-settings-i-use&quot;&gt;The settings I use&lt;/h2&gt;
&lt;p&gt;These are the llama-server flags behind the final numbers, for llama.cpp build b12406 and the UD-Q4_K_XL file:&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;-c 131072 -ctk q8_0 -ctv q8_0 -np 1
-ngl 99 -lm none -fit off -fa on
-ncmoe 30 --moe-cache-mib 3000
-b 2048 -ub 2048
--spec-type draft-mtp --spec-draft-n-max 2
--mmproj mmproj-F16.gguf --no-mmproj-offload
--jinja --chat-template-file &amp;lt;fixed template&amp;gt;&lt;/pre&gt;
&lt;p&gt;After both fixes the daily setting gives 102 tokens a second on short answers, 92 at 16K and 85 at 32K, and reads prompts at about 1,900.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>keypi: A Raspberry Pi as an AI agent's hands: USB keyboard, mouse and HDMI capture in one evening</title>
    <id>https://ovi.lt/log/keypi-raspberry-pi-usb-keyboard-ai-agent/</id>
    <link href="https://ovi.lt/log/keypi-raspberry-pi-usb-keyboard-ai-agent/"/>
    <updated>2026-11-08T12:00:00Z</updated>
    <summary>A Pi Zero W in USB gadget mode as keyboard and mouse, plus an HDMI capture stick, so an AI agent can use a machine it has no software access to.</summary>
    <content type="html">&lt;p&gt;Some computers cannot be reached by software: a BIOS screen, an installer, a recovery mode, a machine kept off the network on purpose. A person works on those with a screen, a keyboard and a mouse. I wanted an AI agent to have the same three things.&lt;/p&gt;
&lt;h2 id=&quot;three-parts&quot;&gt;Three parts&lt;/h2&gt;
&lt;p&gt;A Raspberry Pi Zero W plugs into the target's USB port and says it is a keyboard and a mouse. An HDMI capture stick takes the target's picture to the computer the agent runs on. The agent looks at a frame, decides, and sends keys and clicks to the Pi over Wi-Fi.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;agent's computer            target
+--------------+           +----------+
| screenshot &amp;lt;-+-- HDMI ---+ screen   |
| decide       |           |          |
| keys, clicks +-- Wi-Fi   |          |
+--------------+     |     |          |
                  Pi Zero -+ USB port |
                           +----------+&lt;/pre&gt;
&lt;p&gt;The capture stick goes into the agent's computer and not the Pi, because the Zero has one USB data port and that one is busy being a keyboard.&lt;/p&gt;
&lt;h2 id=&quot;a-keyboard-made-of-files&quot;&gt;A keyboard made of files&lt;/h2&gt;
&lt;p&gt;Linux can present a small computer as a USB device. Set up that way, the Pi gets three files, and writing a few bytes to one of them is a key press or a mouse move on the target.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;keyboard report, 8 bytes
[modifiers][0][key][key][key][key][key][key]

absolute mouse: x and y from 0 to 32767
relative mouse: kept for BIOS screens&lt;/pre&gt;
&lt;p&gt;Keys are sent as positions on a US keyboard, so the target's layout has to be US. At first each command was an SSH login to the Pi, one or two seconds every time. A small web service on the Pi, behind a random token, brought that to well under a second.&lt;/p&gt;
&lt;h2 id=&quot;no-ocr&quot;&gt;No OCR&lt;/h2&gt;
&lt;p&gt;I had planned a step that turns the picture into text. It was never needed: the model reads the screenshot itself. The tool scales each frame to 1,280 pixels wide, can draw a coordinate grid over it, and can cut a zoomed crop when the text is small.&lt;/p&gt;
&lt;p&gt;Grabbing one frame takes about 3.2 seconds, most of it spent opening the capture device. At 1920 by 1080 the stick's uncompressed mode manages 5 frames a second and keeps text sharp; its compressed mode is faster and blurrier.&lt;/p&gt;
&lt;h2 id=&quot;teaching-the-mouse-where-the-screen-is&quot;&gt;Teaching the mouse where the screen is&lt;/h2&gt;
&lt;p&gt;The mouse works in its own numbers, 0 to 32767, and the agent thinks in pixels of a screenshot. How one maps to the other changes with the resolution, the monitors and the capture source, so the tool measures it. It moves the pointer over a 5 by 5 grid, finds the pointer in each frame, and fits a line.&lt;/p&gt;
&lt;p&gt;The first run found the pointer at 4 of the 25 points. It was comparing each frame with two fixed frames taken earlier, and anything else moving on a busy screen ruined that. Comparing each frame with the ones just before and after found all 25.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;pointer found, first attempt:4|comparing neighbouring frames:25&quot; data-max=&quot;25&quot; data-unit=&quot;of 25 grid points&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;The fit was then off by a median of 0.64 pixels, and against the true pointer position by at most 2.&lt;/p&gt;
&lt;h2 id=&quot;what-went-wrong-on-the-way&quot;&gt;What went wrong on the way&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The first &amp;quot;hello world&amp;quot; went into the wrong window. Notepad had reopened one of my own files, and the agent typed &amp;quot;hello wor&amp;quot; into it before noticing. The rule since: look at what has focus before typing.&lt;/li&gt;
&lt;li&gt;The Pi's first boot took ten minutes. Normal boots take 30 to 40 seconds, which is too slow to catch a BIOS key if the Pi is powered by the machine it controls. It needs its own power for that, and I have not built that yet.&lt;/li&gt;
&lt;li&gt;The picture looked purple. I checked with colour bars, which came through exactly. The purple was the wallpaper.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-first-real-job-and-the-way-round&quot;&gt;The first real job, and the way round&lt;/h2&gt;
&lt;p&gt;The reason for building it that evening was a Mac that needed about 9 GB freed from Recovery mode. The capture stick showed the Mac's Recovery terminal clearly. The keyboard half never arrived: the Mac asked the Pi to identify itself eight times, about three seconds apart, and gave up. Windows had accepted the same Pi an hour earlier.&lt;/p&gt;
&lt;p&gt;So the hands went over the network. I typed two commands on the Mac, and they opened a connection out to my desktop and started a temporary login server inside Recovery, open only to that connection and only to one key. Recovery is a thin system: it had no way to make the server's key, and no &lt;code&gt;du&lt;/code&gt; or &lt;code&gt;python3&lt;/code&gt; either, so the key was made on the desktop, and file sizes were added up with &lt;code&gt;find&lt;/code&gt; and &lt;code&gt;stat&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first agent would not take this route; its replies were stopped by its own safety checks three times. A second agent did the work. It confirmed the exact folder and version first, deleted one old phone-simulator image of 8,994,719,232 bytes, and left the rest. Free space reached about 37 GB, without turning off any of the Mac's protections.&lt;/p&gt;
&lt;p&gt;The steps are in the repository, with my addresses taken out.&lt;/p&gt;
&lt;h2 id=&quot;one-evening-and-what-it-has-not-done&quot;&gt;One evening, and what it has not done&lt;/h2&gt;
&lt;p&gt;From the first message to a typed &amp;quot;hello world&amp;quot; took 75 minutes, and to a calibrated mouse and a finished tool under two hours. The whole evening was 2 hours 46 minutes.&lt;/p&gt;
&lt;p&gt;As a keyboard and mouse it has typed and clicked its way around a Windows desktop. It has not yet changed a BIOS setting, run an installer, or worked on a machine that is truly offline; those are what it is for, and the next thing to try.&lt;/p&gt;
&lt;p&gt;The code is public: &lt;a href=&quot;https://github.com/ovidijusr/keypi&quot;&gt;keypi on GitHub&lt;/a&gt;.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>iDrive 8 on a desk: BMW iDrive 8 running on a PC: from firmware image to home screen in three days</title>
    <id>https://ovi.lt/log/idrive-8-emulator-reverse-engineering/</id>
    <link href="https://ovi.lt/log/idrive-8-emulator-reverse-engineering/"/>
    <updated>2026-10-27T12:00:00Z</updated>
    <summary>Running BMW's iDrive 8 interface on a desktop: the real head-unit software under QEMU, the other car computers faked over SOME/IP, GPU calls forwarded.</summary>
    <content type="html">&lt;p&gt;The screen in a current BMW is drawn by a computer of its own, the head unit: a Linux machine with a Qualcomm ARM chip. Its software update is not encrypted. It unpacks, in three ordinary steps, to a normal disk image. The whole interface is one program, 277 MB, that loads 276 libraries and exports 211,460 named functions.&lt;/p&gt;
&lt;p&gt;I wanted that program running on my desktop, with nothing from the car around it.&lt;/p&gt;
&lt;h2 id=&quot;three-days-of-stops&quot;&gt;Three days of stops&lt;/h2&gt;
&lt;p&gt;I ran the program under an emulator that translates ARM code, and treated each crash as a question: what did it expect to find? The first tools are dated 21 October. The home screen came up on the 24th.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It asked for the chip's graphics driver and died. I swapped in a software renderer; the program never talks to the driver directly, only through its rendering library.&lt;/li&gt;
&lt;li&gt;It died at once with &amp;quot;illegal instruction&amp;quot;. The program is built with a branch-protection feature that the real chip, a Cortex-A76, does not enforce and the emulator's default processor does. Telling the emulator to be a Cortex-A76 fixed it.&lt;/li&gt;
&lt;li&gt;It followed a null pointer. A car's options are written into the unit when the car is configured, and in the update that storage is empty. The firmware ships its maker's own test shim that loads default options, so I used that.&lt;/li&gt;
&lt;li&gt;It waited forever for data packs that install separately. I installed them.&lt;/li&gt;
&lt;li&gt;It needed a display server that speaks a car-specific protocol, and the real one wants display hardware. I wrote a small one, with the protocol rebuilt from the unit's own libraries.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;fake-the-rest-of-the-car-not-the-unit&quot;&gt;Fake the rest of the car, not the unit&lt;/h2&gt;
&lt;p&gt;Touch was next. The emulator does not pass through the calls a touchscreen driver answers, so a small shim answers them from a socket. The touches arrived, and the interface threw them away: it believed its display was off, because no other computer in the car had told it the car was on.&lt;/p&gt;
&lt;p&gt;That set the rule for everything after. The unit's own services run for real. Only the other computers are faked, as peers on the car's internal network protocol.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;the head unit, real        faked peers
+----------------+       +--------------+
| interface      |       | power state  |
| its services   |&amp;lt;-----&amp;gt;| display      |
| its renderer   |       | climate      |
+----------------+       | drive modes  |
                         +--------------+&lt;/pre&gt;
&lt;p&gt;Finding what a fake has to say needs no documentation. Offer the service with nothing in it and watch what the interface asks for: which events it subscribes to, which calls it makes, with what bytes. Its own log then says whether an answer parsed. The firmware names 1,242 such interfaces. Five fakes were enough for a working screen: power (state 11 means fully on), display, vehicle condition, climate and drive modes. The climate bar shows temperatures, and its plus and minus buttons work.&lt;/p&gt;
&lt;h2 id=&quot;why-it-was-slow-and-the-fix&quot;&gt;Why it was slow, and the fix&lt;/h2&gt;
&lt;p&gt;Every tap took seconds. I measured where the time went: 89% of it was the software renderer running inside the emulator, about 33 processor-seconds for one frame.&lt;/p&gt;
&lt;p&gt;The renderer uses 99 graphics calls and 16 set-up calls. I replaced the graphics library inside the emulator with a thin one that forwards those calls to a small native program, which draws on the desktop's real graphics card.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;tap to first frame, before:2.0|after:0.2|screen settled, before:6.2|after:1.3&quot; data-unit=&quot;seconds&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;Processor time per tap fell from 111 seconds to 2.2. What is left is the interface's own logic under emulation, and a start-up of about 80 seconds.&lt;/p&gt;
&lt;h2 id=&quot;everything-was-pink&quot;&gt;Everything was pink&lt;/h2&gt;
&lt;p&gt;Until 26 October every highlight on the screen was magenta. Magenta is the fallback when a colour is missing. The service that sets the colour theme asked for it about one second before the colour tables had loaded, got nothing, and only asks again when the drive mode changes. So the fake drive-mode computer now reports &amp;quot;none&amp;quot; at first and the normal mode 15 seconds later. The theme applied, 645 colours at once, and as a side effect the 3D model of the car appeared on the home screen.&lt;/p&gt;
&lt;h2 id=&quot;where-it-stands&quot;&gt;Where it stands&lt;/h2&gt;
&lt;p&gt;The home screen, the app menu, the live 3D vehicle view and the climate bar work, in a window I can click. I added a tile of my own to the app menu. The buttons inside the climate screen do nothing yet, the navigation map is not running, and there is no video.&lt;/p&gt;
&lt;p&gt;My own car has the older unit, with an Intel chip. I checked its updates too: they are encrypted, and hold only the previous generation of the interface. So this runs on a desk and not in a car.&lt;/p&gt;</content>
  </entry>
  <entry>
    <title>Nightcore remake: Remaking a low-quality nightcore track in lossless: measure the speed and the pitch</title>
    <id>https://ovi.lt/log/nightcore-hd-remake-speed-pitch/</id>
    <link href="https://ovi.lt/log/nightcore-hd-remake-speed-pitch/"/>
    <updated>2026-07-19T12:00:00Z</updated>
    <summary>How to rebuild a low-quality nightcore MP3 from the lossless original: measure the exact tempo by drift and the pitch in cents, then render with ffmpeg.</summary>
    <content type="html">&lt;p&gt;I had an old nightcore edit as a low-quality MP3, and the original song as a lossless file. A nightcore edit is the song played faster, which also raises its pitch. So a clean copy needs only two numbers: how much faster, and how much higher. I wanted to measure them, not guess.&lt;/p&gt;
&lt;h2 id=&quot;why-not-divide-the-two-lengths&quot;&gt;Why not divide the two lengths?&lt;/h2&gt;
&lt;p&gt;It is the obvious way to get the speed, and it was wrong. The old MP3 had 4.3 seconds of silence added at the end and its outro trimmed, two errors stacked. The lengths gave a speed of 1.104. The true one was 1.1113.&lt;/p&gt;
&lt;p&gt;That gap is 0.66%. It sounds small, and it puts the beats 0.4 seconds apart after one minute.&lt;/p&gt;
&lt;h2 id=&quot;a-first-speed-from-the-beat&quot;&gt;A first speed, from the beat&lt;/h2&gt;
&lt;p&gt;Both files have a steady beat, so I measured the tempo of each and divided. The script follows how loud the track is over time, finds the spacing at which that pattern best repeats, and reads the beats per minute from it. That is good to about 0.3%, enough for a first copy.&lt;/p&gt;
&lt;h2 id=&quot;the-exact-speed-from-drift&quot;&gt;The exact speed, from drift&lt;/h2&gt;
&lt;p&gt;Render the copy at that speed, then lay it next to the old file. If the speed is slightly off, the two slide apart at a steady rate, and that rate is the error.&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;gap between the two files
 +  |               .  '
    |        .  '
 0  |  .  '
    +---------------------- time
the slope is how wrong the speed is&lt;/pre&gt;
&lt;p&gt;The script compares ten-second pieces every thirty seconds and finds, for each, how far the copy has to slide to line up. A straight line through those gaps gives the correction: multiply the speed by one plus the slope, render again, and repeat until the slope is under 0.01%. One round is normally enough.&lt;/p&gt;
&lt;h2 id=&quot;pitch-is-a-separate-question&quot;&gt;Pitch is a separate question&lt;/h2&gt;
&lt;p&gt;With the beats locked, the copy still sounded flat next to the old file. Speeding a song up by 1.1113 raises it by about 183 cents, hundredths of a semitone. The old edit was higher than that: its maker had added 82 cents on top.&lt;/p&gt;
&lt;p&gt;To measure it, the script turns a stretch of each file into a spectrum on a pitch scale, in steps of 2 cents between 150 and 7,000 Hz. It removes the broad shape of the sound, including the dullness of the MP3, and slides one spectrum along the other until they line up. An ear hears 80 cents at once, even when every beat lines up.&lt;/p&gt;
&lt;figure class=&quot;viz&quot; data-viz=&quot;bars&quot; data-rows=&quot;from the speed-up alone:183|added by whoever made the edit:82&quot; data-unit=&quot;cents of pitch&quot;&gt;&lt;div class=&quot;dots&quot;&gt;&lt;/div&gt;&lt;figcaption&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;h2 id=&quot;the-render&quot;&gt;The render&lt;/h2&gt;
&lt;p&gt;Pitch and tempo then have to be set apart. Resample the original by the total pitch, which makes it too fast, and slow it back to the measured tempo:&lt;/p&gt;
&lt;pre class=&quot;diagram&quot;&gt;pitch  = tempo * 2^(cents/1200)
       = 1.1113 * 2^(82/1200) = 1.1652
atempo = tempo / pitch        = 0.9537

ffmpeg -i original.flac -af
 &amp;quot;asetrate=44100*1.1652,
  aresample=44100:resampler=soxr,
  atempo=0.9537&amp;quot;  out.flac&lt;/pre&gt;
&lt;p&gt;A stretch that small, under 5%, is clean on dance music.&lt;/p&gt;
&lt;h2 id=&quot;how-close-it-got&quot;&gt;How close it got&lt;/h2&gt;
&lt;p&gt;Measured again against the old MP3, the final file drifts by +0.0009% in tempo and sits 0.14 cents away in pitch. The speed came out very near ten ninths, which may be what the edit's maker typed. I kept the measured value.&lt;/p&gt;</content>
  </entry>
</feed>
