Skip to content

Commit

Permalink
trace directory path updates (#6924)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
brody4hire and cwfitzgerald authored Jan 16, 2025
1 parent 623f143 commit beb3341
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
7 changes: 3 additions & 4 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ impl Device {
raw_device: Box<dyn hal::DynDevice>,
adapter: &Arc<Adapter>,
desc: &DeviceDescriptor,
trace_path: Option<&std::path::Path>,
trace_dir_name: Option<&str>,
instance_flags: wgt::InstanceFlags,
) -> Result<Self, DeviceError> {
#[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)?;
Expand Down Expand Up @@ -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(),
Expand All @@ -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
}
}),
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/device/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ pub struct Trace {

#[cfg(feature = "trace")]
impl Trace {
pub fn new(path: &std::path::Path) -> Result<Self, std::io::Error> {
pub fn new(dir_path_name: &str) -> Result<Self, std::io::Error> {
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")?;
Expand Down
22 changes: 14 additions & 8 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Device>, Arc<Queue>), 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)?;
Expand All @@ -641,7 +647,7 @@ impl Adapter {
self: &Arc<Self>,
desc: &DeviceDescriptor,
instance_flags: wgt::InstanceFlags,
trace_path: Option<&std::path::Path>,
trace_dir_name: Option<&str>,
) -> Result<(Arc<Device>, Arc<Queue>), RequestDeviceError> {
// Verify all features were exposed by the adapter
if !self.raw.features.contains(desc.required_features) {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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<DeviceId>,
queue_id_in: Option<QueueId>,
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
Expand All @@ -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);
Expand All @@ -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<DeviceId>,
queue_id_in: Option<QueueId>,
) -> Result<(DeviceId, QueueId), RequestDeviceError> {
Expand All @@ -975,7 +981,7 @@ impl Global {
hal_device,
desc,
self.instance.flags,
trace_path,
trace_dir_name,
)?;

let device_id = devices_fid.assign(device);
Expand Down

0 comments on commit beb3341

Please sign in to comment.