Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to expose core and hal internal debugging information #5546

Open
nical opened this issue Apr 17, 2024 · 0 comments · May be fixed by #5708
Open

Add an API to expose core and hal internal debugging information #5546

nical opened this issue Apr 17, 2024 · 0 comments · May be fixed by #5708

Comments

@nical
Copy link
Contributor

nical commented Apr 17, 2024

I have a work-in-progress debug-overlay for wgpu which I would like to use to investigate wgpu issues such as resource leaks. The overlay can display simple ascii text and graphs in a render pass.

While I'm polishing the overlay, one of the missing pieces is to surface wgpu's vitals in a way that is useful for debugging.

To feed the data to the overlay I would need some way to pull it out of wgpu-core at least. I propose that we keep track of useful info in a per-device struct that could be pulled The API could look like this:

pub struct HalCounters {
    // whatever information we want to get out of hal.
}

/// A structure that contains whatever debugging information is useful for wgpu developers and/or users.
pub struct InternalCounters {
    pub hal: HalCounters,
    pub allocated_textures: u32,
    pub allocated_buffers: u32,
    // ...
    // Option::None represents the case where a counter is "not set" for example if the information is about something that may not have happened.
    pub render_pass_encoding_time_ns: Option<u64>
    // ...
    // Also things that are more complicated than scalars, for example a data structure that describes the contents of the GPU memory allocator.
    // etc.
}

// Extracted this way:
let mut counters = wgpu_core::InternalCounters::default();
device.get_and_reset_internal_counters(&mut counters);
// or 
let counters = device.get_internal_counters(&mut counters);

Or

pub struct CountderId(usize);

pub struct InternalCounters {
    // The bulk of the data
    counters: Vec<Option<f32>>,
    // other more complicated data.
    // ...
}

impl InternalCounters {
    pub fn reset(&mut self) { ... }
    pub fn set(id: CounterId, value: Into<f32>) { ... }
    pub fn scalars(&self) -> impl Iterator<Item=Option<(CounterId, f32)>> { ... }
}

pub const ALLOCATED_TEXTURES: CounterId = CounterId(0);
pub const ALLOCATED_BUFFERS: CounterId = CounterId(1);
// etc.

// Extracted this way:
let mut counters = wgpu_core::InternalCounters::default();
device.get_and_reset_internal_counters(&mut counters);
// or 
let counters = device.get_internal_counters(&mut counters);

The second version seems more convoluted at first but doing it this way makes it possible to add counters in wgpu and have them integrate in the overlay automatically without manual intervention in the code that pulls the counters and feeds the overlay. That's how WebRender handles a similar functionality in Firefox.

@nical nical linked a pull request May 16, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant