Skip to content

armgit / BUI

Public Imported from GitHub
0

Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI

merge svelte

Preetham Pemmasaniba07328159da
diff --cc CHANGELOG.md
index 1b59af7,ca2191a..a22d1a1
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -7,103 -7,67 +7,161 @@@ All notable changes to **blenderui** (B
## [Unreleased]
### Added
+- **Video, in every language** (`kit/intern/image`: `video.c`, `movie*.c`). One codec
+ interface for GIF, WebP and video (Blender's MovieReader shape: open, output size, next,
+ seek, close) and one clock (`play.c`: pause, seek, rate, loop, end). The OS decodes,
+ loaded at run time so a machine without it still starts: Windows Media Foundation
+ (`IMFSourceReader` with a DXVA Direct3D 11 device manager; decoding and scaling on the
+ GPU), Linux GStreamer (`decodebin ! videoconvert ! videoscale ! appsink`, `dlopen`ed;
+ VA-API through its `va` plugin), macOS AVFoundation (written, **untested**: no Mac).
+ Frames are NV12 at the size drawn, two per player reused (no allocation per frame), in
+ one GPU texture pair per player updated in place (YCbCr to RGB in the Direct3D 11 and
+ OpenGL shaders; the software raster converts what it draws); off screen, clipped or in a
+ window that isn't rendering, nothing is decoded. C: `BK_video_*` (new, play, pause,
+ seek, rate, loop, poster, controls, state, time, duration, size, listener, texture,
+ backends), the `"video"` node with Blender-style controls (play/pause button, scrubber
+ with the time; `BK_node_set_video`), canvas items' `video`. Rust: `<video src loop
+ poster autoplay>`, `video().video(handle)`, `blenderui::Video` (play, pause, seek,
+ set_rate, set_loop, time, duration, state, `on_state`, texture), `Painter::video`.
+ Python: `bui.Video` and the `Video` component (`controls`, `on_ended`). React /
+ @blender-ui/native / `bui build`: `<video>`. Dear ImGui: `BK_video_texture`. Muted
+ autoplay by default; no audio yet.
+- **GPU NV12 pixmaps and stream textures**: `BuiPixmap.format` (`BUI_PIXMAP_NV12_BT601`
+ / `_BT709`) and `.stream` (frames of one stream update one texture in place), and
+ `BUI_pixmap_read`. The GPU parity test covers them (Direct3D 11 and OpenGL).
+- **Pay only for what you use: one feature table** (`features.json`): image formats,
+ video, the GPU renderers, FreeType, the file browser and Dear ImGui are CMake options
+ (`features.cmake`), cargo features of `blenderui-sys` and `blenderui` (same names;
+ build.rs maps them and checks the list), and what `bui build` reads. Off, a part isn't
+ compiled; its API stays. `bui build` links the smallest prebuilt runtime (`base`,
+ `media`, `full`) with the features an app uses: `--features`, then package.json
+ `"bui": {"features": [...]}`, then detection in the bundle (`<video>`, media file
+ extensions, `gpu:`, file dialogs).
+- `bench/video` (`bui_video_bench`, `make_clips.sh`) and `tests/video_test.c`,
+ `bindings/rust/blenderui/tests/video.rs` (counting allocator), `features.rs`,
+ `bindings/python/tests/test_video.py`.
+- **Images, once in C for every binding** (`kit/intern/image`, after Blender's imbuf: one
+ image type, `BKImBuf`, and a format table): PNG, GIF (animated), BMP, TGA and QOI with
+ Wuffs (memory-safe), JPEG with libjpeg-turbo 3.1.2 (EXIF orientation, CMYK, DCT-scaled
+ thumbnails), WebP with libwebp 1.6.0 (lossy, lossless, animated), Radiance HDR (after
+ Blender's), PNM (ASCII and binary) and SVG (the kit's nanosvg; `BUI_IMAGE_SVG`, on).
+ Decoded at the size drawn into premultiplied pixels, on a worker pool (visible first,
+ prefetch, cancellation), into one memory-budgeted cache (`BK_image_set_budget`, 256 MiB);
+ an arriving image redraws only its rectangle, and layout uses the header's size.
+ C: `BK_imbuf_*`, `BK_image_*`, `BK_node_set_image_source`, `BK_node_set_imbuf`,
+ canvas items with `src` / `imbuf` / `fit`. Rust: `<img>` and CSS background images in
+ every format, `Image::open` / `decode` / `from_rgba` / `texture`,
+ `Painter::image_file(_cover)`, `image_stats`, `set_image_budget`, an image column in the
+ data table (`CellRender::Image`), chat-list media (`Record::media`), and a
+ `PaintSink::image`. Python: `blenderui.image_decode` / `image_probe` / `image_texture` /
+ `texture_free` / `image_stats` / `set_image_budget`, the `Image` component, and tkinter
+ `PhotoImage` reading JPEG, WebP, BMP, TGA, QOI, HDR and SVG too (`format="gif -index n"`
+ picks a frame). Dear ImGui: textures from images (`image_texture`, `BK_imbuf_texture`).
+- Blender's `MEM_get_memory_in_use` / `MEM_get_memory_blocks_in_use` leak counters, and
+ its condition variables and thread pool (`BLI_condition_*`, `BLI_threadpool_*`) in core.
+- `bench/images`: the decoder comparison and the thumbnail-grid benchmark (`bui_image_bench`).
+- **Animated GIF and WebP play**, decoded one frame at a time at the size drawn (the cache
+ holds the shown frame, the next one and the decoder; no all-frames limit), each frame for
+ its delay, looping as the file says (GIF disposal and blending, WebP's canvas). Frames
+ advance on the context's frame timer and repaint only their rectangle; an animation off
+ screen, clipped away, in a row that isn't shown or in a window that isn't rendering
+ pauses (no decoding, timers or renders). `frame` holds one frame: the `<img frame>`
+ attribute (Rust, React), `Painter::image_file_frame`, `Image(frame=)`,
+ `BK_node_set_image_frame`, canvas items' `frame`. Reduced motion holds them all:
+ `blenderui::set_reduced_motion` (CSS `prefers-reduced-motion: reduce` then matches),
+ `bui.set_reduced_motion`, `BK_set_animations(0)`. Stepping animations yourself (Dear
+ ImGui): `BK_anim_open` / `BK_anim_next` / `BK_imbuf_texture_update`, Rust
+ `blenderui::Animation` and `Image::update_texture`, Python `blenderui.AnimatedTexture`.
+ One frame alone: `BK_imbuf_decode_frame`, `image_decode_frame` (tkinter `-index n` uses it).
+- **Images over 2047 px on the GPU**: a texture of their own on Direct3D 11 and OpenGL
+ (tiled only past the device limit; `BUI_GPU_MAX_TEXTURE` forces it for tests), freed
+ when the kit frees the image (`BUI_image_forget`) or after 120 unused frames, within
+ 256 MiB. The parity test compares them with the CPU raster, whole and tiled.
+- `BKImageStats.decode_ms` (time the workers spent decoding) and `MEM_get_allocations_total`.
+- `bench/images`: `bui_image_bench <dir> anim <count>`, many animations at once.
+ - **Svelte** (new npm package `@blender-ui/svelte` 0.1.0, Svelte 5.57): Svelte 5 components in
+ native windows, with feature parity with `@blender-ui/react`: `render(Component, options)`,
+ `createRoot(window)`, `act(fn)`, Blender's ten widgets as components, BUI's signals (each a
+ Svelte store, `$count`), headless tests and screenshots, Node.js (`--import
+ @blender-ui/svelte/register`), Bun (`--preload`) and `bui build` / `bui run`. Runes, snippets,
+ bindings, keyed `{#each}`, `{#await}`, `{#key}`, context, lifecycle and scoped `<style>`
+ blocks work; transitions run their start and end without animating in between. Svelte has
+ no custom-renderer API, so its compiled components run on `@blender-ui/native`'s DOM.
+ - **`@blender-ui/native`, a fuller DOM:** a window-less `document` whose nodes are detached until
+ inserted into a window's tree (then created natively with their subtree), `DocumentFragment`,
+ `Comment` (an anchor that takes no space), `cloneNode`, `before` / `after` / `append` /
+ `prepend` / `replaceWith`, `contains`, `isConnected`, `el.style` with `cssText` /
+ `setProperty` / `removeProperty`, `el.classList`, DOM properties that reflect attributes
+ (`disabled`, `hidden`, `value`, `checked`, `type` ...) on `HTMLElement`, `dispatchEvent`,
+ `event.composedPath()` and `cancelBubble`. Nodes made by `document` are freed natively once
+ removed and dropped.
+ - **A shared layer for framework bindings:** `@blender-ui/native/host` (`open`, `blenderWidgets`,
+ `applyProps`: what React's binding did on its own), `@blender-ui/native/globals` (the browser
+ globals DOM frameworks read), and `bui build` bundling with the Bun plugin of every
+ `@blender-ui/*` package that declares one (`"bui": { "bunPlugin" }`). A binding for another
+ framework is a thin adapter over these.
+ - **Benchmarks:** `bench/cells.js --svelte [--signals]` and `bench/startup.js --svelte`;
+ `cells.js` also reports `js_us_per_update` (500 updates back to back, each applied by the
+ framework and sent to the UI thread: the JavaScript cost of an update alone) and `heap_mb`.
+ - **Svelte, faster updates:** compiled components import `@blender-ui/svelte/internal`, which
+ serves Svelte's runtime with `set_text`, `set_attribute`, `set_class`, `set_style` and `clsx`
+ writing straight into BUI's nodes (each used only while Svelte's own has the shape it was
+ written for; a test compares them on the same inputs). A BUI signal passed as a value
+ (`{label}`, `style={style}`, `class={cls}`) binds its node: a write updates it without Svelte
+ running, as React's signal props do.
+ - **Svelte, faster start on Node.js and Bun:** with Bun installed, `register` bundles Svelte's
+ client runtime once (per Svelte version) into `node_modules/.cache/@blender-ui/svelte` and
+ serves it from there; the compile cache is found from the working directory up, and cache
+ keys no longer load `node:crypto`.
+ - **`@blender-ui/native`, slimmer nodes:** attributes are a flat array made by the first one
+ (not a `Map` per element), `tagName` is derived from `localName`, and children, signal
+ bindings, listeners and form state live on the prototype until a node has them; a text node
+ is five fields. About 0.7 MB less JavaScript heap for a 3,000-cell grid, in React and Svelte
+ alike.
+ - **Measured** (3,000 cells, one session, Node 26 / Bun 1.4 / QuickJS): an update costs 17 / 19 /
+ 36 µs of JavaScript in Svelte with signals (was 87 / 86 / 793; React with signals 23 / 17 / 40),
+ 65 / 76 / 790 µs with runes (was 85 / 78 / 790); a Svelte app's first frame is 135 ms on Node.js
+ and 121 ms on Bun (was 393 / 203; React 125 / 107). Svelte still keeps 10–17 MB more than React
+ with signals at 3,000 cells: its own effects and each-block items. Details in
+ docs/javascript.md.
### Changed
+- `BUI_raster_image` takes a `BuiPixmap` (premultiplied pixels with a key), a source
+ rectangle and flags; it filters bilinearly (exact copies at 1:1) on the CPU and on both
+ GPU renderers, and the GPU atlas finds images by key instead of hashing their pixels
+ every frame.
+- `blenderui::Image` holds the kit's decoded image instead of a `Vec<u8>` (`width` and
+ `height` stay public; `from_png` is deprecated in favour of `open`; `image_rgba` takes any
+ `AsRef<[u8]>`). The automation `App::draw` waits for image decodes it started.
+- tkinter `PhotoImage` decodes through the kit (the Python PNG/PPM decoders and the
+ round trip through the real Tk for GIF are gone).
+- Images whose source rectangle is outside the canvas clip are neither decoded nor played.
+- **Builds**: every C file compiles with function and data sections (`-ffunction-sections
+ -fdata-sections`, MSVC `/Gy /Gw`) so linkers drop unused code, and MSVC Release builds
+ get `/O2` explicitly: under cmake-rs (`blenderui-sys`) the kit was compiled unoptimized.
+ The Node addon and the QuickJS runtime build with the new `dist` profile (fat LTO, one
+ codegen unit): `bui-runtime.exe` went from 8,693,760 to 7,097,856 bytes, and an app
+ made with `bui build` is about 7 MB (the docs said about 5 MB; that figure predated the
+ image decoders). The Node test now checks that `bui build` adds only the bundle and
+ holds the runtime to its measured size plus 5 %.
+ - **`@blender-ui/native`:** siblings are a linked list (insert, remove and `nextSibling` are
+ O(1); `childNodes` returns a new array), and listener maps are made on the first listener.
+ Re-rendering 3,000 cells per frame from React costs a little less CPU.
+ - **`@blender-ui/native`:** reading `el.style` returns the inline style object (its `cssText`
+ is the old string); setting it still takes a string, an object or a signal.
+ `addEventListener` accepts any event type (those BUI doesn't report only fire through
+ `dispatchEvent`) instead of throwing.
+ - **`@blender-ui/react`** uses `@blender-ui/native/host` for its props, events, widgets and
+ window options; its API and behaviour are unchanged.
+ - **`bui build`** bundles with `Bun.build` (and the framework plugins it finds) instead of the
+ `bun build` command line.
+ - **`bench/startup.js`** counts launches that fail at exit (after their first frame, a
+ sporadic crash on Bun at quit) instead of aborting.
+### Removed
+- The `png` crate as a dependency of `blenderui` (the website-screenshot examples still use
+ it to write PNGs, as a dev-dependency).
+
## [0.3.0] - 2026-11-06
### Added
diff --cc README.md
index 7ce2e66,1cb1c87..fc9dad6
--- a/README.md
+++ b/README.md
@@@ -1612,12 -1649,12 +1660,12 @@@ and on an NVIDIA GPU
**Packages:**
-| Package | Platforms | Notes |
-| ------------------------------------------------ | ---------------------------------------------------------------- | --------------------------------------------------------------------------------- |
-| `blenderui` on PyPI | Windows x86_64, Linux x86_64 (manylinux), macOS arm64 and x86_64 | CPython 3.11 to 3.14. No musllinux or 32-bit wheels. |
+| Package | Platforms | Notes |
+| ------------------------------------------------ | ---------------------------------------------------------------- | --------------------------------------------------------------- |
+| `blenderui` on PyPI | Windows x86_64, Linux x86_64 (manylinux), macOS arm64 and x86_64 | CPython 3.11 to 3.14. No musllinux or 32-bit wheels. |
| `blenderui` on crates.io | Any platform with CMake and a C compiler | Rust 1.88+. `blenderui-imgui` (Dear ImGui) is on crates.io too. |
- | `@blender-ui/native`, `@blender-ui/react` on npm | Windows x64 | Node.js 18+ or Bun. Elsewhere, build the addon from source. |
- | C and C++ (CMake) | Windows, Linux, macOS | CMake 3.20+, a C11 and C++20 compiler. |
+ | `@blender-ui/native`, `@blender-ui/react`, `@blender-ui/svelte` on npm | Windows x64 | Node.js 18+ (22.15+ for Svelte) or Bun. Elsewhere, build the addon from source. |
+ | C and C++ (CMake) | Windows, Linux, macOS | CMake 3.20+, a C11 and C++20 compiler. |
## 35. Environment variables
@@@ -1717,10 -1751,10 +1765,10 @@@ How each was counted: [Coverage](https:
| `api/` | Stable C ABI for render-sink hosts |
| `bindings/python/` | The `buipy` extension and the `bui` / `blenderui` packages (tkinter, Qt, components, ImGui) |
| `bindings/rust/` | `blenderui`, `blenderui-sys`, `blenderui-macros`, `blenderui-tailwind`, `blenderui-imgui`, `blenderui-jsview`, `blenderui-node`, `blenderui-qjs`, and the benchmark |
- | `bindings/node/`, `bindings/react/` | `@blender-ui/native` and `@blender-ui/react` |
+ | `bindings/node/`, `bindings/react/`, `bindings/svelte/` | `@blender-ui/native`, `@blender-ui/react` and `@blender-ui/svelte` |
| `bindings/imgui/` | Dear ImGui (vendored), the BUI backend, Blender style, the C API and its generator, the Blender-widgets build |
| `backends/qt/` | C++ Qt/QPainter render-sink backend |
-| `bench/` | The start time and battery benchmark |
+| `bench/` | The start time and battery benchmark; `bench/images/` (decoders, thumbnail grid) |
| `examples/`, `tools/` | Demos, the website's screenshot programs (`examples/site/`), the icon and theme generators, the docs screenshot generator |
| `website/` | The documentation website, [bui.preetham.top](https://bui.preetham.top) |
diff --cc bindings/node/cli.js
index 5687962,4483886..c8a0b43
--- a/bindings/node/cli.js
+++ b/bindings/node/cli.js
@@@ -9,10 -9,7 +9,10 @@@
// -o, --out <file> output file (default: the entry's name, .exe on Windows)
// --bun compile with `bun build --compile` instead of QuickJS
// --console keep a console window (Windows; default: none, for apps)
- // --dev React's development build (default: production)
+ // --dev development builds (React's, Svelte's dev mode)
+// --features a,b the kit features the app uses (default: package.json
+// "bui": {"features": [...]}, else detected in the bundle);
+// the smallest runtime with them is linked (features.js)
//
// Bundling uses Bun (https://bun.sh), which must be installed.
// SPDX-License-Identifier: GPL-2.0-or-later
@@@ -124,13 -100,10 +123,10 @@@ function build (o)
const out = path.resolve(o.out ?? `${name}${EXE}`)
const t0 = Date.now()
if (o.bun) {
- const args = ['build', '--compile', '--minify', o.entry, `--outfile=${out}`,
- `--define=process.env.NODE_ENV="${o.dev ? 'development' : 'production'}"`]
- if (process.platform === 'win32' && !o.console) args.push('--windows-hide-console')
- bun(args)
+ bundleWith({ entry: path.resolve(o.entry), out, bun: true, dev: o.dev, console: o.console || process.platform !== 'win32' })
} else {
const js = bundle(o.entry, o.dev)
- const runtime = fs.readFileSync(runtimePath())
+ const runtime = fs.readFileSync(runtimePath(chooseRuntime(o, js)))
if (process.platform === 'win32' && !o.console) setGuiSubsystem(runtime)
const trailer = Buffer.alloc(16)
MAGIC.copy(trailer, 0)
diff --cc bindings/node/package.json
index 4fc6640,e7fbd66..5812540
--- a/bindings/node/package.json
+++ b/bindings/node/package.json
@@@ -17,11 -25,15 +25,17 @@@
},
"files": [
"index.js",
+ "dom.js",
+ "host.js",
+ "globals.js",
+ "bundle.js",
"signals.js",
"index.d.ts",
+ "host.d.ts",
+ "globals.d.ts",
"cli.js",
+ "features.js",
+ "features.json",
"blenderui.*.node",
"bui-runtime.*",
"README.md",
diff --cc docs/javascript.md
index 1960e9f,0625aee..55787dc
--- a/docs/javascript.md
+++ b/docs/javascript.md
@@@ -236,10 -310,13 +310,13 @@@ Options
- `-o <file>`: the output file.
- `--console`: keep a console window for logs. By default, Windows builds open
no console.
- - `--dev`: use React's development build.
+ - `--dev`: development builds (React's, Svelte's dev mode).
+
+ Framework packages add their bundler plugins: with `@blender-ui/svelte`
+ installed, `.svelte` files bundle as they are.
**The default build** is `bui-runtime`, BUI with an embedded
-[QuickJS](https://github.com/quickjs-ng/quickjs) engine (4.9 MB), with your
+[QuickJS](https://github.com/quickjs-ng/quickjs) engine (7.1 MB), with your
app's bundle appended. Your code and both packages run unchanged:
- **JavaScript runs on the UI thread**, as in a browser: no Node.js, no Bun,
diff --cc website/src/content/docs/performance/benchmarks.mdx
index db8bde4,3f9adc5..0cbd97d
--- a/website/src/content/docs/performance/benchmarks.mdx
+++ b/website/src/content/docs/performance/benchmarks.mdx
@@@ -99,8 -99,23 +99,23 @@@ More results, at 100 and 1,000 cells
- **JavaScript costs little over Rust:** 0.4–2.4 ms per frame, for sending changes to BUI's UI thread.
- **Signals make React as cheap as the plain API:** the component doesn't re-render.
-- **QuickJS** starts fastest and uses the least memory, from a 5 MB file. It has no JIT, so re-rendering a 3,000-element list every frame drops it to 20 FPS. Keep big lists on signals, or build with `--bun`.
+- **QuickJS** starts fastest and uses the least memory, from a 7 MB file. It has no JIT, so re-rendering a 3,000-element list every frame drops it to 20 FPS. Keep big lists on signals, or build with `--bun`.
+ ### React and Svelte, side by side
+
+ **What was measured:** the same scenes from `@blender-ui/react` and `@blender-ui/svelte`, in one session, runs interleaved (`bench/cells.js --react | --svelte [--signals]`, `bench/startup.js [--svelte]`). This session's machine ran every variant at 26–29 FPS, so compare these rows with each other, not with the tables above. Besides CPU per frame (mostly BUI's own rendering here), `cells.js` reports the JavaScript cost of one update alone.
+
+ <BenchChart id="js-frameworks-update" />
+
+ <BenchTable id="jsFrameworksBefore" />
+
+ <BenchTable id="jsFrameworksStartup" />
+
+ - **Svelte with signals costs what React with signals does:** a BUI signal passed as a value binds its node, so an update skips Svelte entirely (17–36 µs, against 17–40 µs for React).
+ - **Svelte with runes** pays Svelte's flush, which walks the component's effects: 65–76 µs on Node.js and Bun, 790 µs on QuickJS (no JIT) for 3,000 cells. Per frame, that's within the noise of BUI's rendering.
+ - **Memory:** Svelte keeps 10–17 MB more than React with signals at 3,000 cells. A heap snapshot puts it in Svelte's own effects, closures and each-block items (about 1.9 KB per cell); BUI's nodes are the same objects for both.
+ - **Startup:** with its runtime bundled, a Svelte app reaches its first frame within 10–15 ms of a React one on Node.js and Bun (it was 0.1–0.3 s later), and as fast as React's when built with `bui build`.
+
<Callout type="joke">
Unlike a Cycles render, these numbers don't get any less noisy if you leave them running overnight. Run each benchmark a few times instead.
</Callout>