rutabaga_gfx: unstable, gfxstream-only fence passing APIs

As we iterate on the virtio-spec, it probably makes sense
to explore various options at the same time given the different
use cases.

To not trip over one another, add the gfxstream_unstable flag
in case someone wants to experiment with other methods of
fence passing.

Someone else with different ideas may add their own expermental
preprocessor.

The main success criteria for all projects: passing the fence
from the rendering context to the display context [or virtio-gpu
KMS].

With this method, we may reach the success criteria faster and
compare notes before we pitch something less experimental.

BUG=328083772
TEST=export RUSTFLAGS="--cfg gfxstream_unstable"
     cargo build

Change-Id: I2011456e1207f84ea2d12b8877e5af66cf69d591
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5341729
Reviewed-by: Kaiyi Li <kaiyili@google.com>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Jason Macnak <natsu@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Gurchetan Singh 2024-05-08 18:57:20 -07:00 committed by crosvm LUCI
parent 6586b48673
commit 56a1afb873
2 changed files with 46 additions and 4 deletions

View file

@ -848,7 +848,7 @@ impl VirtioGpu {
}
/// If supported, export the fence with the given `fence_id` to a file.
pub fn export_fence(&self, fence_id: u64) -> ResourceResponse {
pub fn export_fence(&mut self, fence_id: u64) -> ResourceResponse {
match self.rutabaga.export_fence(fence_id) {
Ok(handle) => ResourceResponse::Resource(ResourceInfo::Fence {
handle: to_safe_descriptor(handle.os_handle),

View file

@ -349,6 +349,8 @@ fn calculate_component(component_mask: u8) -> RutabagaResult<RutabagaComponentTy
/// thread-safe is more difficult.
pub struct Rutabaga {
resources: Map<u32, RutabagaResource>,
#[cfg(gfxstream_unstable)]
shareable_fences: Map<u64, RutabagaHandle>,
contexts: Map<u32, Box<dyn RutabagaContext>>,
// Declare components after resources and contexts such that it is dropped last.
components: Map<RutabagaComponentType, Box<dyn RutabagaComponent>>,
@ -540,7 +542,14 @@ impl Rutabaga {
.get_mut(&fence.ctx_id)
.ok_or(RutabagaError::InvalidContextId)?;
ctx.context_create_fence(fence)?;
#[allow(unused_variables)]
let handle_opt = ctx.context_create_fence(fence)?;
#[cfg(gfxstream_unstable)]
if fence.flags & RUTABAGA_FLAG_FENCE_HOST_SHAREABLE != 0 {
let handle = handle_opt.unwrap();
self.shareable_fences.insert(fence.fence_id, handle);
}
} else {
let component = self
.components
@ -880,7 +889,12 @@ impl Rutabaga {
}
/// Exports the given fence for import into other processes.
pub fn export_fence(&self, fence_id: u64) -> RutabagaResult<RutabagaHandle> {
pub fn export_fence(&mut self, fence_id: u64) -> RutabagaResult<RutabagaHandle> {
#[cfg(gfxstream_unstable)]
if let Some(handle) = self.shareable_fences.get_mut(&fence_id) {
return handle.try_clone();
}
let component = self
.components
.get(&self.default_component)
@ -975,7 +989,33 @@ impl Rutabaga {
.get_mut(&ctx_id)
.ok_or(RutabagaError::InvalidContextId)?;
ctx.submit_cmd(commands, fence_ids, Vec::new())
#[allow(unused_mut)]
let mut shareable_fences: Vec<RutabagaHandle> = Vec::with_capacity(fence_ids.len());
#[cfg(gfxstream_unstable)]
for (i, fence_id) in fence_ids.iter().enumerate() {
let handle = self
.shareable_fences
.get_mut(&fence_id)
.ok_or(RutabagaError::InvalidRutabagaHandle)?;
let clone = handle.try_clone()?;
shareable_fences.insert(i, clone);
}
ctx.submit_cmd(commands, fence_ids, shareable_fences)
}
/// destroy fences that are still outstanding
#[cfg(gfxstream_unstable)]
pub fn destroy_fences(&mut self, fence_ids: &[u64]) -> RutabagaResult<()> {
for fence_id in fence_ids {
self.shareable_fences
.remove(&fence_id)
.ok_or(RutabagaError::InvalidRutabagaHandle)?;
}
Ok(())
}
}
@ -1241,6 +1281,8 @@ impl RutabagaBuilder {
Ok(Rutabaga {
resources: Default::default(),
#[cfg(gfxstream_unstable)]
shareable_fences: Default::default(),
contexts: Default::default(),
components: rutabaga_components,
default_component: self.default_component,