Skip to content

Commit 4a71277

Browse files
committed
Initial release: wgpu integration for Smithay compositors
0 parents  commit 4a71277

25 files changed

Lines changed: 9196 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
check:
15+
name: Check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: dtolnay/rust-toolchain@stable
20+
with:
21+
toolchain: "1.92"
22+
- name: Install system dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y libvulkan-dev libwayland-dev libudev-dev libinput-dev libseat-dev libgbm-dev libxkbcommon-dev
26+
- run: cargo check --all-features
27+
28+
fmt:
29+
name: Format
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: dtolnay/rust-toolchain@stable
34+
with:
35+
toolchain: "1.92"
36+
components: rustfmt
37+
- run: cargo fmt --check
38+
39+
clippy:
40+
name: Clippy
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: dtolnay/rust-toolchain@stable
45+
with:
46+
toolchain: "1.92"
47+
components: clippy
48+
- name: Install system dependencies
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y libvulkan-dev libwayland-dev libudev-dev libinput-dev libseat-dev libgbm-dev libxkbcommon-dev
52+
- run: cargo clippy --all-features -- -D warnings
53+
54+
test:
55+
name: Test
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v4
59+
- uses: dtolnay/rust-toolchain@stable
60+
with:
61+
toolchain: "1.92"
62+
- name: Install system dependencies
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install -y libvulkan-dev libwayland-dev libudev-dev libinput-dev libseat-dev libgbm-dev libxkbcommon-dev
66+
- run: cargo build --all-features
67+
- run: cargo test --all-features -- --test-threads=1
68+
69+
doc:
70+
name: Documentation
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v4
74+
- uses: dtolnay/rust-toolchain@stable
75+
with:
76+
toolchain: "1.92"
77+
- name: Install system dependencies
78+
run: |
79+
sudo apt-get update
80+
sudo apt-get install -y libvulkan-dev libwayland-dev libudev-dev libinput-dev libseat-dev libgbm-dev libxkbcommon-dev
81+
- run: cargo doc --all-features --no-deps

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] - 2026-02-XX
11+
12+
### Added
13+
14+
- `WgpuBridge`: Core bridge wrapping wgpu Device/Queue with Vulkan interop
15+
- `WgpuRenderer`: Full implementation of Smithay's `Renderer` trait
16+
- DMA-BUF import via raw Vulkan (`VK_KHR_external_memory_fd`)
17+
- Multi-planar YUV format support (NV12, P010) with hardware YCbCr conversion
18+
- Explicit sync support via `SyncManager` and `SyncBridge`
19+
- Binary semaphore export using wgpu's `add_signal_semaphore()` ([wgpu#6813])
20+
- CPU-side acquire point waiting (GPU-side blocked on [wgpu#8996])
21+
- Output scanout (DMA-BUF export for display)
22+
- Shared Vulkan context mode (`from_smithay_vulkan`)
23+
24+
### Notes
25+
26+
This is a foundation release demonstrating wgpu viability as a "guest renderer"
27+
for Smithay-based Wayland compositors. See README for current limitations and
28+
the architectural approach.
29+
30+
[wgpu#6813]: https://github.com/gfx-rs/wgpu/pull/6813
31+
[wgpu#8996]: https://github.com/gfx-rs/wgpu/issues/8996

Cargo.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[package]
2+
name = "lamco-wgpu"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.92"
6+
description = "wgpu integration for Smithay-based Wayland compositors"
7+
license = "MIT OR Apache-2.0"
8+
repository = "https://github.com/lamco-admin/lamco-wgpu"
9+
homepage = "https://lamco.ai"
10+
documentation = "https://docs.rs/lamco-wgpu"
11+
readme = "README.md"
12+
authors = ["Greg Lamberson <greg@lamco.io>"]
13+
keywords = ["wgpu", "smithay", "wayland", "compositor", "vulkan"]
14+
categories = ["graphics", "rendering::graphics-api"]
15+
16+
[package.metadata.docs.rs]
17+
all-features = true
18+
targets = ["x86_64-unknown-linux-gnu"]
19+
rustdoc-args = ["--cfg", "docsrs"]
20+
21+
[badges]
22+
maintenance = { status = "actively-developed" }
23+
24+
[dependencies]
25+
smithay = { git = "https://github.com/Smithay/smithay", rev = "94687f51cb7a4c57559f5f5f72aa1c68a60ea940", default-features = false, features = [
26+
"renderer_gl",
27+
"backend_drm",
28+
"backend_gbm",
29+
"backend_vulkan",
30+
"wayland_frontend",
31+
] }
32+
33+
wgpu = "28"
34+
wgpu-hal = { version = "28", features = ["vulkan"] }
35+
wgpu-types = "28"
36+
wgpu-core = "28"
37+
38+
ash = "0.38"
39+
thiserror = "2"
40+
tracing = "0.1"
41+
weak-table = "0.3"
42+
drm-fourcc = "2"
43+
wayland-server = "0.31"
44+
pollster = "0.4"
45+
libc = "0.2"
46+
bytemuck = { version = "1.14", features = ["derive"] }
47+
48+
[dev-dependencies]
49+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
50+
51+
[features]
52+
default = ["dmabuf", "explicit-sync"]
53+
dmabuf = []
54+
explicit-sync = []
55+
56+
[lints.rust]
57+
unused_unsafe = "warn"
58+
elided_lifetimes_in_paths = "warn"
59+
60+
[lints.clippy]
61+
undocumented_unsafe_blocks = "warn"
62+
multiple_unsafe_ops_per_block = "warn"
63+
missing_safety_doc = "warn"
64+
unwrap_used = "warn"
65+
similar_names = "warn"
66+
wildcard_imports = "warn"

LICENSE-APACHE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
Copyright 2026 Lamco Development
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.

LICENSE-MIT

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Lamco Development
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# lamco-wgpu
2+
3+
[![CI](https://github.com/lamco-admin/lamco-wgpu/actions/workflows/ci.yml/badge.svg)](https://github.com/lamco-admin/lamco-wgpu/actions)
4+
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](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

Comments
 (0)