-
Notifications
You must be signed in to change notification settings - Fork 73
vhost-device-gpu: Add support for GPU device path #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,11 @@ pub mod renderer; | |
| #[cfg(test)] | ||
| pub(crate) mod testutils; | ||
|
|
||
| #[cfg(feature = "backend-virgl")] | ||
| use std::os::fd::OwnedFd; | ||
| use std::{ | ||
| fmt::{Display, Formatter}, | ||
| path::Path, | ||
| path::{Path, PathBuf}, | ||
| }; | ||
|
|
||
| use bitflags::bitflags; | ||
|
|
@@ -117,20 +119,22 @@ impl GpuCapset { | |
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| #[derive(Debug)] | ||
| /// This structure holds the configuration for the GPU backend | ||
| pub struct GpuConfig { | ||
| gpu_mode: GpuMode, | ||
| capset: GpuCapset, | ||
| flags: GpuFlags, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| #[derive(Debug)] | ||
| pub struct GpuFlags { | ||
| pub use_egl: bool, | ||
| pub use_glx: bool, | ||
| pub use_gles: bool, | ||
| pub use_surfaceless: bool, | ||
| #[cfg(feature = "backend-virgl")] | ||
| pub render_server_fd: Option<OwnedFd>, | ||
| } | ||
|
|
||
| impl GpuFlags { | ||
|
|
@@ -141,6 +145,8 @@ impl GpuFlags { | |
| use_glx: false, | ||
| use_gles: true, | ||
| use_surfaceless: true, | ||
| #[cfg(feature = "backend-virgl")] | ||
| render_server_fd: None, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -157,6 +163,10 @@ pub enum GpuConfigError { | |
| CapsetUnsupportedByMode(GpuMode, GpuCapset), | ||
| #[error("Requested gfxstream-gles capset, but gles is disabled")] | ||
| GlesRequiredByGfxstream, | ||
| #[error("GPU path can only be specified when using virglrenderer mode")] | ||
| GpuPathNotSupportedByMode, | ||
| #[error("Failed to open GPU device '{0}'")] | ||
| InvalidGpuDevice(PathBuf), | ||
| } | ||
|
|
||
| impl GpuConfig { | ||
|
|
@@ -208,6 +218,12 @@ impl GpuConfig { | |
| return Err(GpuConfigError::GlesRequiredByGfxstream); | ||
| } | ||
|
|
||
| // Validate that render_server_fd is only used with virglrenderer | ||
| #[cfg(feature = "backend-virgl")] | ||
stefano-garzarella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if flags.render_server_fd.is_some() && !matches!(gpu_mode, GpuMode::VirglRenderer) { | ||
| return Err(GpuConfigError::GpuPathNotSupportedByMode); | ||
| } | ||
|
|
||
|
Comment on lines
+223
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I must insist on using a builder pattern, so the validation can be higher in the caller
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created an issue here - #910
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not fix it now?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned previously, the builder pattern refactor is out of scope for this PR. This PR adds the --gpu-device feature following the existing GpuConfig::new() pattern used throughout the codebase. Changing to a builder pattern would require refactoring how all backends instantiate GpuConfig and is a separate architectural change.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a rush to merge this PR though? It'd make sense to first make the builder pattern change (in another PR or in a commit in this PR), then add the device path logic. There's no need to add something that you know you will remove. I don't think it's out of scope btw, for what it's worth.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree that this is in scope. The builder pattern would be a significant refactoring affecting the entire GpuConfig API and all three backends. The current implementation follows the existing pattern already in the codebase. This is a much bigger change than adding the --gpu-device feature alone. But if you feel strongly about it, I can implement the builder pattern first in another PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly disagree, I'm 100% with @epilys here, it doesn't make any sense to add something to be removed later. I also don't think it will require lots of changes most places will change from As a side note, the description on issue #910 is unhelpful, adding a link to this thread is ok, but it should have more context There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok of doing it in another PR first, thanks |
||
| Ok(Self { | ||
| gpu_mode, | ||
| capset, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.