Skip to content

Commit 6224f59

Browse files
author
Dorinda Bassey
committed
vhost-device-gpu: Refactor vhost-device-gpu
This commit refactors vhost-device-gpu by separating virglrenderer from rutabaga, and using gfxstream via rutabaga, Simplifying future backend development. This commit introduces a significant refactor of the virtio-gpu backend architecture: - Transition `gfxstream` support to use `Rutabaga` abstraction. - Decouple `virglrenderer` from `Rutabaga`, allowing it to be used as standalone. - Unify backend handling using thread-local storage and macro-based runtime dispatch. Key Changes: VirglRenderer Backend: - `virgl.rs` is now a standalone backend that directly calls `libvirglrenderer` functions. - Removed reliance on `rutabaga` for virgl path. Gfxstream Backend via Rutabaga: - Introduced `gfxstream.rs` backend using `rutabaga` - Thread-local `GfxstreamAdapter` manages its own `Rutabaga` instance, initialized lazily. - Preserved internal `GfxstreamResource` tracking with scanout support and memory handling. Renderer Selection Logic: - In `device.rs`, `lazy_init_and_handle_event()` now: - Dispatches `VirglRendererAdapter` and `GfxstreamAdapter` using thread-local storage(TLS) - Introduced `extract_backend_and_vring()` helper for reusing backend setup logic. Code Deduplication: - Abstracted common logic for both backends to common.rs. - Shared helpers reused between gfxstream and virgl. - Improved modularity with fewer duplicated error handling branches. Testing and Validation: - Replaced `virtio_gpu.rs` testing paths with new unit tests for `gfxstream.rs` and `virgl.rs`. - Added code coverage for the new refactored crate. Signed-off-by: Dorinda Bassey <[email protected]>
1 parent f8e1a62 commit 6224f59

File tree

14 files changed

+3330
-1762
lines changed

14 files changed

+3330
-1762
lines changed

vhost-device-gpu/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
### Changed
77

8+
- [[#852]] (https://github.com/rust-vmm/vhost-device/pull/890) vhost-device-gpu: Refactor vhost-device-gpu
9+
810
### Fixed
911

1012
### Deprecated

vhost-device-gpu/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ edition = "2021"
1414
resolver = "2"
1515

1616
[features]
17-
default = ["gfxstream"]
17+
default = ["backend-virgl", "backend-gfxstream"]
1818
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]
19-
gfxstream = ["rutabaga_gfx/gfxstream"]
19+
backend-gfxstream = ["rutabaga_gfx/gfxstream"]
20+
backend-virgl = ["dep:virglrenderer"]
2021

2122
[dependencies]
2223
clap = { version = "4.5", features = ["derive"] }
@@ -25,8 +26,9 @@ libc = "0.2"
2526
log = "0.4"
2627

2728
[target.'cfg(not(target_env = "musl"))'.dependencies]
28-
rutabaga_gfx = { version = "0.1.71", features = ["virgl_renderer"] }
29-
thiserror = "2.0.17"
29+
virglrenderer = {version = "0.1.2", optional = true }
30+
rutabaga_gfx = { version = "0.1.71"}
31+
thiserror = "2.0.12"
3032
vhost = { version = "0.14.0", features = ["vhost-user-backend"] }
3133
vhost-user-backend = "0.20"
3234
virtio-bindings = "0.2.5"

0 commit comments

Comments
 (0)