crosvm/rutabaga_gfx/src/renderer_utils.rs

75 lines
1.9 KiB
Rust
Raw Normal View History

rutabaga_gfx: an electrifying possibility rutabaga_gfx is a cross platform, Rust-based, Wayland and Vulkan-centric Virtual Graphics Interface (VGI). Apologies for the mega-change, but it was hard to do this piece by piece. The rationale for this change is: 1) Android graphics virtualization experts have been proposing for a VGI for many months (years?). Their goal is to boot Android anywhere, everywhere. 2) For the {wayland, cross-domain} context type prototype, it's desirable to create a {wayland, camera} connection at the appropriate time. Details can be found in the code, though the RutabagaChannels have yet to be hooked up. There's a high chance neither effort will work. As such, rutabaga is just a prototype. However, even (1) and (2) don't end up working, this refactor/cleanup by itself makes a ton of sense. Here's a summary of revelant changes: * Removed auto-generated {p_defines, p_format, virgl_protocol}. These files were added for tests when bringing up crosvm-gpu, and AFAICT these tests are not run. There's actually now a commit queue for virglrenderer changes and container boot tests that provides excellent coverage. * Removed command_buffer.rs. Used only for the previously mentioned tests. It's quite nice, but couldn't determine the right place to put it. Maybe data_model? But removed it in the interim. * Removed {write_from_guest_memory, read_to_volatile}. The same basic functionality has been moved into {transfer_write, transfer_read} in Rutabaga. * Removed VirtioResource, Virtio3DResource, Virtio2DResource, and VirtioGfxStreamResource in favor of VirtioGpuResource and RutabagaResource. This leads to less duplication and clearer separation between external library functions and VMM functions. * Moved display and hypervisor memory management functions to virtio_gpu.rs. This is because external components do not interface with this functionality, and there was a lot of duplication (for example map/unmap blob). * Added context management between gfxstream and virglrenderer. * Added separate gfxstream and virglrenderer flags. * Clearer naming. * Added simple implementations for context init and multiple timelines. These changes have no effect since all Google kernels don't pass the revelant flags, but are useful for theoretical {wayland, cross-domain} prototype. * Unify RESOURCE_CREATE_3D and RESOURCE_CREATE_2D handling. * Better error handling. BUG=b:146066070, b:173630595, b:150239451 TEST=launch virtual machine with 2D mode TEST=launch virtual machine with 3D mode TEST=boot ARCVM Change-Id: I240b0c134a3b562cbc65981837a41f6db7767c92 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2522452 Tested-by: Gurchetan Singh <gurchetansingh@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org> Reviewed-by: Lingfeng Yang <lfy@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
2020-10-20 01:31:13 +00:00
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//! renderer_utils: Utility functions and structs used by virgl_renderer and gfxstream.
use std::cell::RefCell;
use std::os::raw::c_void;
use std::rc::Rc;
use crate::generated::virgl_renderer_bindings::__va_list_tag;
use crate::rutabaga_utils::{RutabagaError, RutabagaResult};
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct VirglBox {
pub x: u32,
pub y: u32,
pub z: u32,
pub w: u32,
pub h: u32,
pub d: u32,
}
/*
* automatically generated by rust-bindgen
* $ bindgen /usr/include/stdio.h \
* --no-layout-tests \
* --whitelist-function vsnprintf \
* -o vsnprintf.rs
*/
#[allow(dead_code, non_snake_case, non_camel_case_types)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
extern "C" {
pub fn vsnprintf(
__s: *mut ::std::os::raw::c_char,
__maxlen: ::std::os::raw::c_ulong,
__format: *const ::std::os::raw::c_char,
__arg: *mut __va_list_tag,
) -> ::std::os::raw::c_int;
}
pub fn ret_to_res(ret: i32) -> RutabagaResult<()> {
match ret {
0 => Ok(()),
_ => Err(RutabagaError::RutabagaComponentError(ret)),
}
}
pub struct FenceState {
pub latest_fence: u32,
}
impl FenceState {
pub fn write(&mut self, latest_fence: u32) {
if latest_fence > self.latest_fence {
self.latest_fence = latest_fence;
}
}
}
pub struct VirglCookie {
pub fence_state: Rc<RefCell<FenceState>>,
}
pub extern "C" fn write_fence(cookie: *mut c_void, fence: u32) {
assert!(!cookie.is_null());
let cookie = unsafe { &*(cookie as *mut VirglCookie) };
// Track the most recent fence.
let mut fence_state = cookie.fence_state.borrow_mut();
fence_state.write(fence);
}