|
| 1 | +# lamco-wgpu |
| 2 | + |
| 3 | +[](https://github.com/lamco-admin/lamco-wgpu/actions) |
| 4 | +[](LICENSE-MIT) |
| 5 | + |
| 6 | +wgpu integration for Smithay-based Wayland compositors. |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +This crate enables [wgpu](https://wgpu.rs/) as a "guest renderer" on top of [Smithay](https://github.com/Smithay/smithay)'s Wayland compositor infrastructure. It provides: |
| 11 | + |
| 12 | +- **WgpuBridge** - Core bridge wrapping wgpu with Vulkan interop for DMA-BUF import |
| 13 | +- **WgpuRenderer** - Full implementation of Smithay's `Renderer` trait |
| 14 | +- **Explicit sync** - Support for `linux-drm-syncobj-v1` protocol (required for NVIDIA) |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +- **Rust 1.92+** (required by wgpu 28) |
| 19 | +- Vulkan 1.2+ driver |
| 20 | +- Linux with DMA-BUF support |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +This crate requires Smithay features (`backend_vulkan`, `drm_syncobj`) only available in git master, |
| 25 | +not in any published crates.io version. Install via git: |
| 26 | + |
| 27 | +```toml |
| 28 | +[dependencies] |
| 29 | +lamco-wgpu = { git = "https://github.com/lamco-admin/lamco-wgpu" } |
| 30 | +``` |
| 31 | + |
| 32 | +Once Smithay publishes a compatible version, this crate will be available on crates.io. |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +``` |
| 37 | +┌─────────────────────────────────────────────────────────────────────┐ |
| 38 | +│ SMITHAY HOST LAYER │ |
| 39 | +│ (Owns Vulkan instance & GPU resources) │ |
| 40 | +└─────────────────────────────────────────────────────────────────────┘ |
| 41 | + │ |
| 42 | + ┌───────────────┼───────────────┐ |
| 43 | + │ lamco-wgpu (this crate) │ |
| 44 | + └───────────────────────────────┘ |
| 45 | + │ |
| 46 | +┌─────────────────────────────────────────────────────────────────────┐ |
| 47 | +│ WGPU GUEST LAYER │ |
| 48 | +│ (High-level rendering via shared context) │ |
| 49 | +└─────────────────────────────────────────────────────────────────────┘ |
| 50 | +``` |
| 51 | + |
| 52 | +Smithay owns the Vulkan instance and handles low-level GPU resource management. |
| 53 | +wgpu operates as a "guest" using the shared Vulkan context for high-level rendering. |
| 54 | + |
| 55 | +## Quick Start |
| 56 | + |
| 57 | +```rust |
| 58 | +use lamco_wgpu::{WgpuBridge, WgpuRenderer}; |
| 59 | +use std::sync::Arc; |
| 60 | + |
| 61 | +// Create bridge (standalone mode) |
| 62 | +let bridge = Arc::new(WgpuBridge::new()?); |
| 63 | + |
| 64 | +// Or share Smithay's Vulkan context (production) |
| 65 | +let bridge = Arc::new(unsafe { |
| 66 | + WgpuBridge::from_smithay_vulkan( |
| 67 | + &smithay_instance, |
| 68 | + smithay_physical_device, |
| 69 | + &smithay_device, |
| 70 | + smithay_queue, |
| 71 | + queue_family_index, |
| 72 | + )? |
| 73 | +}); |
| 74 | + |
| 75 | +// Create renderer implementing Smithay's Renderer trait |
| 76 | +let mut renderer = WgpuRenderer::new(bridge.clone()); |
| 77 | +``` |
| 78 | + |
| 79 | +## Features |
| 80 | + |
| 81 | +| Feature | Default | Description | |
| 82 | +|---------|---------|-------------| |
| 83 | +| `dmabuf` | ✓ | DMA-BUF import via raw Vulkan | |
| 84 | +| `explicit-sync` | ✓ | Smithay explicit sync integration | |
| 85 | + |
| 86 | +## Explicit Sync |
| 87 | + |
| 88 | +For compositors implementing `linux-drm-syncobj-v1` (required for NVIDIA): |
| 89 | + |
| 90 | +```rust |
| 91 | +use lamco_wgpu::{SyncManager, SyncBridge}; |
| 92 | + |
| 93 | +let sync_manager = SyncManager::new(&bridge)?; |
| 94 | +let sync_bridge = SyncBridge::new(&sync_manager); |
| 95 | + |
| 96 | +// Before sampling client buffer |
| 97 | +if let Some(acquire) = surface.acquire_point() { |
| 98 | + sync_bridge.wait_acquire_point(acquire, 5000)?; |
| 99 | +} |
| 100 | + |
| 101 | +// Signal release after rendering |
| 102 | +let pending = sync_bridge.prepare_release_signal(&queue)?; |
| 103 | +queue.submit([encoder.finish()]); |
| 104 | +sync_bridge.complete_release_signal(pending, &release_point, &device)?; |
| 105 | +``` |
| 106 | + |
| 107 | +### Semaphore Limitations |
| 108 | + |
| 109 | +Release point signaling uses wgpu's `add_signal_semaphore()` API ([wgpu#6813]). |
| 110 | +GPU-side acquire waiting is not yet possible because wgpu lacks `add_wait_semaphore()` ([wgpu#8996]). |
| 111 | +Current implementation uses CPU-side waiting via `poll()` on the exported sync_file. |
| 112 | + |
| 113 | +## wgpu Ecosystem Context |
| 114 | + |
| 115 | +This crate exists because wgpu does not natively support the low-level Vulkan |
| 116 | +interop required for Wayland compositors. Relevant upstream issues: |
| 117 | + |
| 118 | +- [wgpu#2320] - Texture memory import API (open since 2021) |
| 119 | +- [wgpu#6813] - `add_signal_semaphore()` for external semaphore signaling (merged) |
| 120 | +- [wgpu#8996] - `add_wait_semaphore()` for external semaphore waiting (open) |
| 121 | + |
| 122 | +The Smithay maintainers concluded that wgpu is "too abstract for internal |
| 123 | +compositor work" but suitable as a guest renderer ([Smithay#431], [Smithay#928]). |
| 124 | +This crate implements that pattern. |
| 125 | + |
| 126 | +## Status |
| 127 | + |
| 128 | +This is a foundation release. Working: |
| 129 | + |
| 130 | +- DMA-BUF import (single-plane and multi-planar YUV) |
| 131 | +- Smithay Renderer trait implementation |
| 132 | +- Explicit sync release signaling |
| 133 | +- Shared Vulkan context with Smithay |
| 134 | + |
| 135 | +Not yet production-tested: |
| 136 | + |
| 137 | +- Real compositor integration at scale |
| 138 | +- All multi-planar format variants |
| 139 | +- DMA-BUF export (scanout) |
| 140 | + |
| 141 | +## About |
| 142 | + |
| 143 | +Developed by [Lamco](https://lamco.ai) as part of the Wayland compositor ecosystem. |
| 144 | + |
| 145 | +## License |
| 146 | + |
| 147 | +Licensed under either of: |
| 148 | + |
| 149 | +- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 150 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 151 | + |
| 152 | +at your option. |
| 153 | + |
| 154 | +### Contribution |
| 155 | + |
| 156 | +Unless you explicitly state otherwise, any contribution intentionally submitted |
| 157 | +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 158 | +dual licensed as above, without any additional terms or conditions. |
| 159 | + |
| 160 | +## Links |
| 161 | + |
| 162 | +- [Documentation](https://docs.rs/lamco-wgpu) |
| 163 | +- [Repository](https://github.com/lamco-admin/lamco-wgpu) |
| 164 | +- [Smithay](https://github.com/Smithay/smithay) |
| 165 | +- [wgpu](https://wgpu.rs/) |
| 166 | + |
| 167 | +[wgpu#2320]: https://github.com/gfx-rs/wgpu/issues/2320 |
| 168 | +[wgpu#6813]: https://github.com/gfx-rs/wgpu/pull/6813 |
| 169 | +[wgpu#8996]: https://github.com/gfx-rs/wgpu/issues/8996 |
| 170 | +[Smithay#431]: https://github.com/Smithay/smithay/discussions/431 |
| 171 | +[Smithay#928]: https://github.com/Smithay/smithay/issues/928 |
0 commit comments