mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-25 05:03:05 +00:00
rutabaga_gfx: Query cachability from minigbm
Drop the hack hard-coding cachability based on driver name, and replace with querying from minigbm. This allows other drivers to use cached minigbm/gralloc allocated buffers in cases where it is beneficial (such as with sw encoders) BUG=b:239718180, b:306548532 TEST=cts-tradefed run cts -m CtsVideoTestCases -t android.video.cts.VideoEncoderDecoderTest#testAvcGoog0Perf0320x0240 no artifact in Camera FOV Calibration of CtsVerifier on rex Change-Id: I854e2f00b993310716f64a3c568ed8c6f2665469 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3780218 Reviewed-by: Dawn Han <dawnhan@google.com> Reviewed-by: Ryan Neph <ryanneph@google.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Chia-I Wu <olv@google.com>
This commit is contained in:
parent
0c80abfa27
commit
2f9fe25b9c
3 changed files with 26 additions and 21 deletions
|
@ -8,13 +8,11 @@
|
|||
|
||||
#![cfg(feature = "minigbm")]
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::fs::File;
|
||||
use std::io::Error;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
use std::os::fd::FromRawFd;
|
||||
use std::os::raw::c_char;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::rutabaga_gralloc::formats::DrmFormat;
|
||||
|
@ -52,7 +50,6 @@ impl Drop for MinigbmDeviceInner {
|
|||
pub struct MinigbmDevice {
|
||||
minigbm_device: Arc<MinigbmDeviceInner>,
|
||||
last_buffer: Option<Arc<MinigbmBuffer>>,
|
||||
device_name: &'static str,
|
||||
}
|
||||
|
||||
impl MinigbmDevice {
|
||||
|
@ -60,7 +57,6 @@ impl MinigbmDevice {
|
|||
/// the minigbm library.
|
||||
pub fn init() -> RutabagaResult<Box<dyn Gralloc>> {
|
||||
let descriptor: File;
|
||||
let device_name: &str;
|
||||
let gbm: *mut gbm_device;
|
||||
// SAFETY:
|
||||
// Safe because minigbm_create_default_device is safe to call with an unused fd,
|
||||
|
@ -76,22 +72,12 @@ impl MinigbmDevice {
|
|||
descriptor = File::from_raw_fd(fd);
|
||||
}
|
||||
|
||||
// SAFETY:
|
||||
// Safe because the string returned by gbm_device_get_backend_name() exists at least
|
||||
// as long as the associated gbm_device.
|
||||
unsafe {
|
||||
let backend_name: *const c_char = gbm_device_get_backend_name(gbm);
|
||||
let c_str: &CStr = CStr::from_ptr(backend_name);
|
||||
device_name = c_str.to_str()?;
|
||||
}
|
||||
|
||||
Ok(Box::new(MinigbmDevice {
|
||||
minigbm_device: Arc::new(MinigbmDeviceInner {
|
||||
_fd: descriptor,
|
||||
gbm,
|
||||
}),
|
||||
last_buffer: None,
|
||||
device_name,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -127,11 +113,7 @@ impl Gralloc for MinigbmDevice {
|
|||
let mut reqs: ImageMemoryRequirements = Default::default();
|
||||
let gbm_buffer = MinigbmBuffer(bo, self.clone());
|
||||
|
||||
// Intel GPUs typically only use cached memory buffers. This will change with dGPUs, but
|
||||
// perhaps minigbm will be deprecated by then. Other display drivers (rockchip, mediatek,
|
||||
// amdgpu) typically use write combine memory. We can also consider use flags too if this
|
||||
// heuristic proves insufficient.
|
||||
if self.device_name == "i915" {
|
||||
if gbm_buffer.cached() {
|
||||
reqs.map_info = RUTABAGA_MAP_CACHE_CACHED;
|
||||
} else {
|
||||
reqs.map_info = RUTABAGA_MAP_CACHE_WC;
|
||||
|
@ -261,6 +243,14 @@ impl MinigbmBuffer {
|
|||
unsafe { gbm_bo_get_stride_for_plane(self.0, plane) }
|
||||
}
|
||||
|
||||
/// Should buffer use cached mapping to guest
|
||||
pub fn cached(&self) -> bool {
|
||||
// SAFETY:
|
||||
// This is always safe to call with a valid gbm_bo pointer.
|
||||
let mode = unsafe { gbm_bo_get_map_info(self.0) };
|
||||
mode == gbm_bo_map_cache_mode::GBM_BO_MAP_CACHE_CACHED
|
||||
}
|
||||
|
||||
/// Exports a new dmabuf/prime file descriptor.
|
||||
pub fn export(&self) -> RutabagaResult<File> {
|
||||
// SAFETY:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Generated with bindgen --allowlist-function='gbm_.*' --allowlist-type='gbm_.*' minigbm/gbm.h
|
||||
// Generated with bindgen --default-enum-style=rust --allowlist-function='gbm_.*' --allowlist-type='gbm_.*' minigbm/gbm.h
|
||||
// Then modified manually
|
||||
|
||||
#![cfg(feature = "minigbm")]
|
||||
|
@ -149,6 +149,21 @@ pub type gbm_bo_transfer_flags = u32;
|
|||
extern "C" {
|
||||
pub fn gbm_bo_unmap(bo: *mut gbm_bo, map_data: *mut c_void);
|
||||
}
|
||||
#[repr(u32)]
|
||||
#[doc = " Enum to indicate the cache attributes of CPU mapping returned by"]
|
||||
#[doc = " gbm_bo_map()"]
|
||||
#[doc = ""]
|
||||
#[doc = " Note that definition aligns with VIRTIO_GPU_MAP_CACHE_*, RUTABAGA_MAP_CACHE_*,"]
|
||||
#[doc = " and VIRGL_RENDERER_MAP_CACHE_* (but skipping the _NONE and _UNCACHED values as"]
|
||||
#[doc = " those don't actually make sense to use)."]
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum gbm_bo_map_cache_mode {
|
||||
GBM_BO_MAP_CACHE_CACHED = 1,
|
||||
GBM_BO_MAP_CACHE_WC = 3,
|
||||
}
|
||||
extern "C" {
|
||||
pub fn gbm_bo_get_map_info(bo: *mut gbm_bo) -> gbm_bo_map_cache_mode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn gbm_bo_get_width(bo: *mut gbm_bo) -> u32;
|
||||
}
|
||||
|
|
2
third_party/minigbm
vendored
2
third_party/minigbm
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 90b2d4773273b3ea180aff8f995d58e7b7604eb5
|
||||
Subproject commit e701ddbf02a6d590586f813a2ee9a132cfc1ea40
|
Loading…
Reference in a new issue