diff --git a/docs/envvars.rst b/docs/envvars.rst index 113ed090f82..ab8b0ba9416 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -1196,6 +1196,7 @@ Rusticl environment variables - ``allow_invalid_spirv`` disables validation of any input SPIR-V - ``clc`` dumps all OpenCL C source being compiled + - ``memory`` enables debugging of memory objects - ``nir`` dumps nirs in various compilation stages. Might print nothing if shader caching is enabled. - ``no_reuse_context`` pipe_contexts are not recycled diff --git a/src/gallium/frontends/rusticl/core/context.rs b/src/gallium/frontends/rusticl/core/context.rs index 73efd2238fa..3b8ac469317 100644 --- a/src/gallium/frontends/rusticl/core/context.rs +++ b/src/gallium/frontends/rusticl/core/context.rs @@ -348,6 +348,10 @@ impl Context { let res = res.ok_or(CL_OUT_OF_RESOURCES)?; if !dev.system_svm_supported() { + if Platform::dbg().memory { + eprintln!("assigning {address:x} to {res:?}"); + } + if !dev.screen().resource_assign_vma(&res, address) { return Err(CL_OUT_OF_RESOURCES); } diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 5fb1b48ed0f..77a51e873d3 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -26,6 +26,7 @@ use std::collections::HashMap; use std::convert::TryInto; use std::env; use std::ffi::CStr; +use std::fmt::Debug; use std::mem::transmute; use std::num::NonZeroU64; use std::os::raw::*; @@ -1257,6 +1258,14 @@ impl Device { } } +impl Debug for Device { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct(&format!("Device@{:?}", self as *const _)) + .field("name", &self.screen().name()) + .finish() + } +} + pub fn devs() -> &'static [Device] { &Platform::get().devs } diff --git a/src/gallium/frontends/rusticl/core/memory.rs b/src/gallium/frontends/rusticl/core/memory.rs index 33c96d548f8..72486e0c102 100644 --- a/src/gallium/frontends/rusticl/core/memory.rs +++ b/src/gallium/frontends/rusticl/core/memory.rs @@ -5,6 +5,7 @@ use crate::core::context::*; use crate::core::device::*; use crate::core::format::*; use crate::core::gl::*; +use crate::core::platform::*; use crate::core::queue::*; use crate::core::util::*; use crate::impl_cl_type_trait; @@ -28,6 +29,7 @@ use std::cmp; use std::collections::btree_map::Entry; use std::collections::HashMap; use std::convert::TryInto; +use std::fmt::Debug; use std::mem; use std::mem::size_of; use std::num::NonZeroU64; @@ -109,6 +111,12 @@ impl ConstMemoryPtr { } } +impl Debug for ConstMemoryPtr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.ptr.fmt(f) + } +} + impl From for ConstMemoryPtr { fn from(value: MutMemoryPtr) -> Self { Self { @@ -125,6 +133,12 @@ pub struct MutMemoryPtr { unsafe impl Send for MutMemoryPtr {} unsafe impl Sync for MutMemoryPtr {} +impl Debug for MutMemoryPtr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.ptr.fmt(f) + } +} + impl MutMemoryPtr { pub fn as_ptr(&self) -> *mut c_void { self.ptr @@ -139,7 +153,7 @@ impl MutMemoryPtr { } } -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum ResourceValidityEntity { Host, Device(&'static Device), @@ -222,6 +236,10 @@ impl ResourceAllocation { let map; let flush; + if Platform::dbg().memory { + eprintln!("migrating {self:?} from {entity:?} to {dev_entity:?}"); + } + if to_res.is_buffer() { let ptr; match entity { @@ -391,6 +409,12 @@ impl ResourceAllocation { } } +impl Debug for ResourceAllocation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!("ResourceAllocation@{:?}", self as *const _)) + } +} + pub struct SubAllocation { mem: Mem, // offset relative to the actual resource, not relative to `mem`. This saves us a few diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index 190090ae907..bb0d4d98f62 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -56,6 +56,7 @@ pub struct PlatformDebug { pub allow_invalid_spirv: bool, pub clc: bool, pub max_grid_size: u32, + pub memory: bool, pub nir: bool, pub no_variants: bool, pub perf: PerfDebugLevel, @@ -85,6 +86,7 @@ static mut PLATFORM_DBG: PlatformDebug = PlatformDebug { allow_invalid_spirv: false, clc: false, max_grid_size: 0, + memory: false, nir: false, no_variants: false, perf: PerfDebugLevel::None, @@ -107,6 +109,7 @@ fn load_env() { match flag { "allow_invalid_spirv" => debug.allow_invalid_spirv = true, "clc" => debug.clc = true, + "memory" => debug.memory = true, "nir" => debug.nir = true, "no_reuse_context" => debug.reuse_context = false, "no_variants" => debug.no_variants = true, diff --git a/src/gallium/frontends/rusticl/mesa/pipe/resource.rs b/src/gallium/frontends/rusticl/mesa/pipe/resource.rs index 1482b6e08ff..b1ac290b923 100644 --- a/src/gallium/frontends/rusticl/mesa/pipe/resource.rs +++ b/src/gallium/frontends/rusticl/mesa/pipe/resource.rs @@ -9,7 +9,7 @@ use std::{ use super::context::PipeContext; -#[derive(PartialEq, Eq, Hash)] +#[derive(Debug, PartialEq, Eq, Hash)] #[repr(transparent)] pub struct PipeResource { pipe: NonNull,