# OpenLogi GPUI Asset Source Cached Device Renders: Embedded Asset Pipeline Architecture

> Learn how OpenLogi uses GPUI's AssetSource to embed SVGs and cache rasterized textures, eliminating I/O overhead for device renders. Optimize your asset pipeline.

- Repository: [Xuan Zhang/OpenLogi](https://github.com/AprilNEA/OpenLogi)
- Tags: architecture
- Published: 2026-08-24

---

**OpenLogi implements a zero-cost asset pipeline using GPUI's AssetSource trait to embed SVG icons directly into the binary, caching rasterized textures in a lazy-loaded HashMap to eliminate I/O overhead across device renders.**

The OpenLogi project is a native, local-first replacement for Logitech Options+ built on the GPUI framework. Its asset system relies on the `openlogi-assets` crate to provide a custom **GPUI asset source** that caches device renders for instant UI updates. This architecture ensures that SVG icons are compiled into the executable and reused efficiently across all supported Logitech devices.

## How OpenLogi Implements GPUI Asset Sources

### The AssetSource Trait in openlogi-assets

In [`crates/openlogi-assets/src/source.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/source.rs), the `Source` struct implements GPUI's `AssetSource` trait. This implementation registers virtual paths (e.g., `"openlogi-assets://..."`) and uses `include_bytes!` to embed SVG files directly into the compiled binary. By serving assets from memory rather than the filesystem, the system removes runtime I/O bottlenecks.

### Virtual Path Resolution

The asset source maps logical icon identifiers to embedded byte arrays via a manifest. When the UI layer requests an asset using its virtual path, the source returns the pre-compiled bytes instantly. This design ensures that **cached device renders** begin with raw binary data already resident in memory.

## Cached Device Renders and the ActionIcons Cache

### Lazy-Loaded Asset Storage

In [`crates/openlogi-ui/src/action_icons.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-ui/src/action_icons.rs), the `ActionIcons` struct maintains a static `Lazy<HashMap<Icon, LoadedAsset>>` cache. The first call to `ActionIcons::load(icon.asset_path())` parses the embedded SVG into a GPUI `Image` object and stores the result. Subsequent calls retrieve the cached texture handle without re-parsing, ensuring that drawing the Actions Ring for any device incurs zero decode cost after the first frame.

### Cross-Device Render Reuse

When the agent detects a new Logitech device, the UI creates a device profile referencing standard icons such as DPI controls or SmartShift symbols. Because the **GPUI asset source** caches textures globally, every device render reuses the same GPU-resident textures. This minimizes memory allocations and maintains consistent frame times regardless of how many devices are connected.

## Code Implementation Examples

The following pattern demonstrates loading an icon through the cached asset pipeline:

```rust
use openlogi_ui::action_icons::{ActionIcons, Icon};

/// Retrieves the DPI-up icon from cache or loads it on first use.
fn get_dpi_icon() -> openlogi_ui::image::Image {
    // asset_path() returns the virtual path registered in source.rs
    ActionIcons.load(Icon::DpiUp.asset_path())
}

```

The Actions Ring component consumes the cached asset in its draw routine:

```rust
// Located in crates/openlogi-desktop/src/features/action_ring/action_ring.rs
impl gpui::View for ActionRing {
    fn draw(&mut self, cx: &mut gpui::Canvas) {
        let icon = get_dpi_icon(); // Zero-cost after first frame
        cx.draw_image(&icon, gpui::Rect::from_xywh(0.0, 0.0, 24.0, 24.0));
    }
}

```

## Key Source Files and Responsibilities

- **[`crates/openlogi-assets/src/source.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/source.rs)** – Implements the `AssetSource` trait and embeds SVG data via `include_bytes!`.
- **[`crates/openlogi-ui/src/action_icons.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-ui/src/action_icons.rs)** – Manages the `ActionIcons` cache and maps `Icon` enums to virtual asset paths.
- **[`crates/openlogi-ui/src/lib.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-ui/src/lib.rs)** – Re-exports UI utilities including the asset loader types.
- **[`crates/openlogi-desktop/src/features/action_ring/action_ring.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-desktop/src/features/action_ring/action_ring.rs)** – GPUI component that renders the Actions Ring using cached textures.
- **[`crates/openlogi-assets/src/manifest.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/manifest.rs)** – Declares which SVG files are packaged into the binary.

## Summary

- The `openlogi-assets` crate implements GPUI's `AssetSource` to serve embedded SVGs via virtual paths.
- **`ActionIcons::load`** caches rasterized textures in a lazy-initialized HashMap, eliminating decode time after the first frame.
- **Cached device renders** across all Logitech hardware reuse the same GPU textures, ensuring consistent performance.
- Assets are compiled into the binary with `include_bytes!`, removing filesystem dependencies in production builds.

## Frequently Asked Questions

### What is GPUI's role in OpenLogi's asset system?

GPUI provides the `AssetSource` trait and internal texture caching layer. OpenLogi implements this trait in [`crates/openlogi-assets/src/source.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/source.rs) to bridge embedded SVG data with GPUI's rendering pipeline, enabling GPU-accelerated icon display without runtime file access.

### How does OpenLogi cache device renders?

The system uses a global `Lazy<HashMap<Icon, LoadedAsset>>` inside `ActionIcons` to store decoded GPUI `Image` objects. After the first call to `load()`, subsequent render calls retrieve the cached texture handle, ensuring that rendering the Actions Ring for any device incurs zero parse overhead.

### Where are the SVG icon files stored?

Raw SVG assets are declared in [`crates/openlogi-assets/src/manifest.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/manifest.rs) and embedded into the binary via `include_bytes!` in [`crates/openlogi-assets/src/source.rs`](https://github.com/AprilNEA/OpenLogi/blob/main/crates/openlogi-assets/src/source.rs). This eliminates external file dependencies and ensures assets are available offline.

### Can assets be modified without recompiling the entire application?

Yes. In development builds, the `openlogi-assets` crate supports watch mode where filesystem changes trigger cache invalidation. GPUI detects the update and refreshes the texture, allowing designers to iterate on SVG files without restarting the application.