diff --git a/CHANGELOG.md b/CHANGELOG.md index 83aa4a68b..5c9688eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,12 @@ Bottom level categories: ### Changes +#### Refactored internal trace path parameter + +Refactored some functions to handle the internal trace path as a string to avoid possible issues with `no_std` support. + +By @brodycj in [#6924](https://github.com/gfx-rs/wgpu/pull/6924). + #### Start using `hashbrown` Use `hashbrown` in `wgpu-core`, `wgpu-hal` & `wgpu-info` to simplify no-std support. (This may help improve performance as well.) diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 56c475cd8..11cab12b4 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -662,13 +662,12 @@ pub fn op_webgpu_request_device( memory_hints: wgpu_types::MemoryHints::default(), }; + let webgpu_trace = std::env::var("DENO_WEBGPU_TRACE").unwrap(); + let res = instance.adapter_request_device( adapter, &descriptor, - std::env::var("DENO_WEBGPU_TRACE") - .ok() - .as_ref() - .map(std::path::Path::new), + Some(webgpu_trace.as_str()), None, None, ); diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 2d326a392..1d6ef946e 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -193,11 +193,11 @@ impl Device { raw_device: Box, adapter: &Arc, desc: &DeviceDescriptor, - trace_path: Option<&std::path::Path>, + trace_dir_name: Option<&str>, instance_flags: wgt::InstanceFlags, ) -> Result { #[cfg(not(feature = "trace"))] - if let Some(_) = trace_path { + if let Some(_) = trace_dir_name { log::error!("Feature 'trace' is not enabled"); } let fence = unsafe { raw_device.create_fence() }.map_err(DeviceError::from_hal)?; @@ -256,7 +256,7 @@ impl Device { #[cfg(feature = "trace")] trace: Mutex::new( rank::DEVICE_TRACE, - trace_path.and_then(|path| match trace::Trace::new(path) { + trace_dir_name.and_then(|dir_path_name| match trace::Trace::new(dir_path_name) { Ok(mut trace) => { trace.add(trace::Action::Init { desc: desc.clone(), @@ -265,7 +265,7 @@ impl Device { Some(trace) } Err(e) => { - log::error!("Unable to start a trace in '{path:?}': {e}"); + log::error!("Unable to start a trace in '{dir_path_name:?}': {e}"); None } }), diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 16902ea86..a5f849cb8 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -220,7 +220,8 @@ pub struct Trace { #[cfg(feature = "trace")] impl Trace { - pub fn new(path: &std::path::Path) -> Result { + pub fn new(dir_path_name: &str) -> Result { + let path = std::path::Path::new(dir_path_name); log::info!("Tracing into '{:?}'", path); let mut file = std::fs::File::create(path.join(FILE_NAME))?; file.write_all(b"[\n")?; diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index dff1106be..549bff786 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -622,11 +622,17 @@ impl Adapter { hal_device: hal::DynOpenDevice, desc: &DeviceDescriptor, instance_flags: wgt::InstanceFlags, - trace_path: Option<&std::path::Path>, + trace_dir_name: Option<&str>, ) -> Result<(Arc, Arc), RequestDeviceError> { api_log!("Adapter::create_device"); - let device = Device::new(hal_device.device, self, desc, trace_path, instance_flags)?; + let device = Device::new( + hal_device.device, + self, + desc, + trace_dir_name, + instance_flags, + )?; let device = Arc::new(device); let queue = Queue::new(device.clone(), hal_device.queue)?; @@ -641,7 +647,7 @@ impl Adapter { self: &Arc, desc: &DeviceDescriptor, instance_flags: wgt::InstanceFlags, - trace_path: Option<&std::path::Path>, + trace_dir_name: Option<&str>, ) -> Result<(Arc, Arc), RequestDeviceError> { // Verify all features were exposed by the adapter if !self.raw.features.contains(desc.required_features) { @@ -688,7 +694,7 @@ impl Adapter { } .map_err(DeviceError::from_hal)?; - self.create_device_and_queue_from_hal(open, desc, instance_flags, trace_path) + self.create_device_and_queue_from_hal(open, desc, instance_flags, trace_dir_name) } } @@ -929,7 +935,7 @@ impl Global { &self, adapter_id: AdapterId, desc: &DeviceDescriptor, - trace_path: Option<&std::path::Path>, + trace_dir_name: Option<&str>, device_id_in: Option, queue_id_in: Option, ) -> Result<(DeviceId, QueueId), RequestDeviceError> { @@ -941,7 +947,7 @@ impl Global { let adapter = self.hub.adapters.get(adapter_id); let (device, queue) = - adapter.create_device_and_queue(desc, self.instance.flags, trace_path)?; + adapter.create_device_and_queue(desc, self.instance.flags, trace_dir_name)?; let device_id = device_fid.assign(device); resource_log!("Created Device {:?}", device_id); @@ -961,7 +967,7 @@ impl Global { adapter_id: AdapterId, hal_device: hal::DynOpenDevice, desc: &DeviceDescriptor, - trace_path: Option<&std::path::Path>, + trace_dir_name: Option<&str>, device_id_in: Option, queue_id_in: Option, ) -> Result<(DeviceId, QueueId), RequestDeviceError> { @@ -975,7 +981,7 @@ impl Global { hal_device, desc, self.instance.flags, - trace_path, + trace_dir_name, )?; let device_id = devices_fid.assign(device);