Restore tracing support in wgpu

The loop/break changes in `play.rs` are reverting changes made in #4202.

Fixes #5974
This commit is contained in:
Andy Leiserson authored and Teodor Tanasoaia committed 2026-01-09 15:55:33 +01:00
1 parent d6b788829e
commit cd7958561a
12 files changed
+56 -55

No files matched your search

+1
View File
@@ -51,6 +51,7 @@ Bottom level categories:
- BREAKING: Migrated from the `maxInterStageShaderComponents` limit to `maxInterStageShaderVariables`, which changes validation in a way that should not affect most programs. This follows the latest changes of the WebGPU spec. By @ErichDonGubler in [#8652](https://github.com/gfx-rs/wgpu/pull/8652), [#8792](https://github.com/gfx-rs/wgpu/pull/8792).
- Fixed validation of the texture format in GPUDepthStencilState when neither depth nor stencil is actually enabled. By @andyleiserson in [#8766](https://github.com/gfx-rs/wgpu/pull/8766).
- Tracing support has been restored. By @andyleiserson in [#8429](https://github.com/gfx-rs/wgpu/pull/8429).
#### naga
Generated
+1 -1
View File
@@ -4816,6 +4816,7 @@ dependencies = [
"obj",
"png",
"pollster",
"tempfile",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",
@@ -4823,7 +4824,6 @@ dependencies = [
"web-time 1.1.0",
"wgpu",
"wgpu-test",
"wgpu-types",
"winit 0.29.15",
]
+4 -6
View File
@@ -45,11 +45,8 @@ noise.workspace = true
obj.workspace = true
png.workspace = true
pollster.workspace = true
tempfile.workspace = true
web-time.workspace = true
wgpu-types = { workspace = true, features = [
"std",
"trace", # TODO(#5974): this should be a dep on wgpu/trace and not wgpu-types at all
] }
winit.workspace = true
[dev-dependencies]
@@ -57,7 +54,7 @@ wgpu-test.workspace = true
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger.workspace = true
wgpu.workspace = true
wgpu = { workspace = true, features = ["trace"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook.workspace = true
@@ -65,9 +62,10 @@ console_log.workspace = true
fern.workspace = true
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
wgpu = { path = "../../wgpu", default-features = false, features = [
wgpu = { workspace = true, default-features = false, features = [
"wgsl",
"std",
"trace",
] }
# We need these features in the framework examples and tests
web-sys = { workspace = true, features = [
+4 -1
View File
@@ -1,4 +1,5 @@
use std::{borrow::Cow, sync::Arc};
use tempfile::tempdir;
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
@@ -28,6 +29,8 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
.await
.expect("Failed to find an appropriate adapter");
let trace_dir = tempdir().expect("Failed to create temporary directory for trace");
// Create the logical device and command queue
let (device, queue) = adapter
.request_device(&wgpu::DeviceDescriptor {
@@ -38,7 +41,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
.using_resolution(adapter.limits()),
experimental_features: wgpu::ExperimentalFeatures::disabled(),
memory_hints: wgpu::MemoryHints::MemoryUsage,
trace: wgpu::Trace::Off,
trace: wgpu::Trace::Directory(trace_dir.path().to_path_buf()),
})
.await
.expect("Failed to create device");
+2 -3
View File
@@ -95,9 +95,8 @@ pub(crate) const FREXP_FUNCTION: &str = "naga_frexp";
// Must match code in glsl_built_in
pub const FIRST_INSTANCE_BINDING: &str = "naga_vs_first_instance";
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg(feature = "deserialize")]
#[derive(serde::Deserialize)]
struct BindingMapSerialization {
resource_binding: crate::ResourceBinding,
bind_target: u8,
+8 -12
View File
@@ -216,9 +216,8 @@ pub struct OffsetsBindTarget {
pub size: u32,
}
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg(feature = "deserialize")]
#[derive(serde::Deserialize)]
struct BindingMapSerialization {
resource_binding: crate::ResourceBinding,
bind_target: BindTarget,
@@ -337,9 +336,8 @@ impl Default for SamplerHeapBindTargets {
}
}
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg(feature = "deserialize")]
#[derive(serde::Deserialize)]
struct SamplerIndexBufferBindingSerialization {
group: u32,
bind_target: BindTarget,
@@ -369,9 +367,8 @@ where
pub type SamplerIndexBufferBindingMap =
alloc::collections::BTreeMap<SamplerIndexBufferKey, BindTarget>;
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg(feature = "deserialize")]
#[derive(serde::Deserialize)]
struct DynamicStorageBufferOffsetTargetSerialization {
index: u32,
bind_target: OffsetsBindTarget,
@@ -425,9 +422,8 @@ pub struct ExternalTextureBindTarget {
pub params: BindTarget,
}
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
#[cfg(feature = "deserialize")]
#[derive(serde::Deserialize)]
struct ExternalTextureBindingMapSerialization {
resource_binding: crate::ResourceBinding,
bind_target: ExternalTextureBindTarget,
+18 -7
View File
@@ -86,6 +86,8 @@ fn main() {
)
}
.unwrap();
#[cfg(feature = "winit")]
let mut configured_surface_id = None;
let (backends, device_desc) =
match actions.pop_if(|action| matches!(action, trace::Action::Init { .. })) {
@@ -149,9 +151,9 @@ fn main() {
match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::RedrawRequested if resize_config.is_none() => {
WindowEvent::RedrawRequested if resize_config.is_none() => loop {
match actions.pop() {
Some(trace::Action::ConfigureSurface(_device_id, config)) => {
Some(trace::Action::ConfigureSurface(surface_id, config)) => {
log::info!("Configuring the surface");
let current_size: (u32, u32) = window.inner_size().into();
let size = (config.width, config.height);
@@ -163,24 +165,33 @@ fn main() {
),
);
resize_config = Some(config);
target.exit();
break;
} else {
let error = device.configure_surface(&surface, &config);
configured_surface_id = Some(surface_id);
if let Some(e) = error {
panic!("{e:?}");
}
}
}
Some(trace::Action::GetSurfaceTexture { id, parent }) => {
log::debug!("Get surface texture for frame {frame_count}");
assert!(
configured_surface_id == Some(parent),
"rendering to an unexpected surface"
);
player.get_surface_texture(id, &surface);
}
Some(trace::Action::Present(_id)) => {
frame_count += 1;
log::debug!("Presenting frame {frame_count}");
surface.present().unwrap();
target.exit();
break;
}
Some(trace::Action::DiscardSurfaceTexture(_id)) => {
log::debug!("Discarding frame {frame_count}");
surface.discard().unwrap();
target.exit();
break;
}
Some(action) => {
player.process(
@@ -195,10 +206,10 @@ fn main() {
println!("Finished the end at frame {frame_count}");
done = true;
}
target.exit();
break;
}
}
}
},
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = device.configure_surface(&surface, &config);
+15
View File
@@ -428,6 +428,21 @@ impl Player {
}
}
// This one is a little strange because the surface is held by the
// `player` application but we want to insert the texture into our
// map so we can find it for rendering.
pub fn get_surface_texture(
&mut self,
id: wgc::id::PointerId<wgc::id::markers::Texture>,
surface: &wgc::instance::Surface,
) {
let frame = surface
.get_current_texture()
.expect("get_current_texture error");
let texture = frame.texture.expect("did not obtain a surface texture");
self.textures.insert(id, texture);
}
pub fn resolve_buffer_id(
&self,
id: wgc::id::PointerId<wgc::id::markers::Buffer>,
+2 -2
View File
@@ -368,6 +368,8 @@ impl Global {
let fid = self.hub.textures.prepare(texture_id_in);
let output = surface.get_current_texture()?;
#[cfg(feature = "trace")]
if let Some(present) = surface.presentation.lock().as_ref() {
if let Some(ref mut trace) = *present.device.trace.lock() {
@@ -380,8 +382,6 @@ impl Global {
}
}
let output = surface.get_current_texture()?;
let status = output.status;
let texture_id = output
.texture
-3
View File
@@ -83,9 +83,6 @@ pub enum MemoryHints {
}
/// Controls API call tracing and specifies where the trace is written.
///
/// **Note:** Tracing is currently unavailable.
/// See [issue 5974](https://github.com/gfx-rs/wgpu/issues/5974) for updates.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// This enum must be non-exhaustive so that enabling the "trace" feature is not a semver break.
+1 -2
View File
@@ -120,9 +120,8 @@ strict_asserts = ["wgpu-core?/strict_asserts", "wgpu-types/strict_asserts"]
## Enables serialization via `serde` on common wgpu types.
serde = ["wgpu-core?/serde", "wgpu-types/serde"]
# Uncomment once we get to https://github.com/gfx-rs/wgpu/issues/5974
# ## Allow writing of trace capture files. See [`Adapter::request_device`].
# trace = ["serde", "wgpu-core/trace"]
trace = ["serde", "wgpu-core?/trace"]
#! ### External libraries
# --------------------------------------------------------------------
-18
View File
@@ -110,15 +110,6 @@ impl ContextWgpuCore {
hal_device: hal::OpenDevice<A>,
desc: &crate::DeviceDescriptor<'_>,
) -> Result<(CoreDevice, CoreQueue), crate::RequestDeviceError> {
if !matches!(desc.trace, wgt::Trace::Off) {
log::error!(
"
Feature 'trace' has been removed temporarily; \
see https://github.com/gfx-rs/wgpu/issues/5974. \
The `trace` parameter will have no effect."
);
}
let (device_id, queue_id) = unsafe {
self.0.create_device_from_hal(
adapter.id,
@@ -930,15 +921,6 @@ impl dispatch::AdapterInterface for CoreAdapter {
&self,
desc: &crate::DeviceDescriptor<'_>,
) -> Pin<Box<dyn dispatch::RequestDeviceFuture>> {
if !matches!(desc.trace, wgt::Trace::Off) {
log::error!(
"
Feature 'trace' has been removed temporarily; \
see https://github.com/gfx-rs/wgpu/issues/5974. \
The `trace` parameter will have no effect."
);
}
let res = self.context.0.adapter_request_device(
self.id,
&desc.map_label(|l| l.map(Borrowed)),