From 8484870660d0bca3f4897eb27702afd4520dab77 Mon Sep 17 00:00:00 2001 From: itycodes Date: Tue, 3 Dec 2024 12:50:11 +0100 Subject: [PATCH] Working on fixing the GEM offset code --- src/gpu/i915/mod.rs | 2 ++ src/uapi/i915/mod.rs | 2 +- tests/tests_uapi.rs | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/gpu/i915/mod.rs b/src/gpu/i915/mod.rs index 4792585..52866e6 100644 --- a/src/gpu/i915/mod.rs +++ b/src/gpu/i915/mod.rs @@ -58,6 +58,8 @@ impl From for GemTileInfo { } /// An owned GEM handle that will be closed when dropped +/// Scoped to a file descriptor - +/// this means that it is inherited by `fork` children and can be shared with sendfd impl GemHandle<'_> { pub fn new(node: &DrmDeviceNode, size: u64) -> Option { uapi::i915::make_gem(node.fd.as_raw_fd(), size).map(|handle| GemHandle { diff --git a/src/uapi/i915/mod.rs b/src/uapi/i915/mod.rs index b6c5911..adcc3ba 100644 --- a/src/uapi/i915/mod.rs +++ b/src/uapi/i915/mod.rs @@ -284,7 +284,7 @@ pub unsafe fn gem_offset(fd: RawFd, handle: &DrmGemHandle) -> Result 0); + for node in nodes { + let gem = i915::make_gem(node.fd.as_raw_fd(), 4096).expect("Failed to make gem"); + let offset = i915::gem_offset(node.fd.as_raw_fd(), &gem); + println!("gem: {:?}, node: {:?}, offset: {:?}", gem, node, offset); + assert!(offset.unwrap() > 0); + i915::close_gem(node.fd.as_raw_fd(), gem).expect("Failed to close gem"); + } + } +} + // TODO: Fix this test // Shared mem needs to be used to communicate the gem handle between parent and child // Test both a shared fd and separate fd