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

Downgrade resource lifetime management log level to trace. #4772

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ By @gents83 in [#3626](https://github.com/gfx-rs/wgpu/pull/3626) and tnx also to
- `TextureFormat::block_size` is deprecated, use `TextureFormat::block_copy_size` instead: By @wumpf in [#4647](https://github.com/gfx-rs/wgpu/pull/4647)
- Rename of `DispatchIndirect`, `DrawIndexedIndirect`, and `DrawIndirect` types in the `wgpu::util` module to `DispatchIndirectArgs`, `DrawIndexedIndirectArgs`, and `DrawIndirectArgs`. By @cwfitzgerald in [#4723](https://github.com/gfx-rs/wgpu/pull/4723).
- Make the size parameter of `encoder.clear_buffer` an `Option<u64>` instead of `Option<NonZero<u64>>`. By @nical in [#4737](https://github.com/gfx-rs/wgpu/pull/4737)
- Reduce the `info` log level noise. By @nical in [#4769](https://github.com/gfx-rs/wgpu/pull/4769), [#4711](https://github.com/gfx-rs/wgpu/pull/4711) and [#4772](https://github.com/gfx-rs/wgpu/pull/4772)

#### Safe `Surface` creation

Expand Down
2 changes: 1 addition & 1 deletion examples/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn init_logger() {
env_logger::builder()
.filter_level(log::LevelFilter::Info)
// We keep wgpu at Error level, as it's very noisy.
.filter_module("wgpu_core", log::LevelFilter::Error)
.filter_module("wgpu_core", log::LevelFilter::Info)
.filter_module("wgpu_hal", log::LevelFilter::Error)
.filter_module("naga", log::LevelFilter::Error)
.parse_default_env()
Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ targets = [
default = ["link"]
# Log all API entry points at info instead of trace level.
api_log_info = []
# Log resource lifecycle management at info instead of trace level.
resource_log_info = []

# Backends, passed through to wgpu-hal
metal = ["hal/metal"]
Expand Down
7 changes: 4 additions & 3 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
},
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
resource::{Resource, ResourceInfo, ResourceType},
resource_log,
track::{BindGroupStates, UsageConflict},
validation::{MissingBufferUsageError, MissingTextureUsageError},
FastHashMap, Label,
Expand Down Expand Up @@ -465,8 +466,8 @@ pub struct BindGroupLayout<A: HalApi> {

impl<A: HalApi> Drop for BindGroupLayout<A> {
fn drop(&mut self) {
log::info!("Destroying BindGroupLayout {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw BindGroupLayout {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_bind_group_layout(raw);
Expand Down Expand Up @@ -606,8 +607,8 @@ pub struct PipelineLayout<A: HalApi> {

impl<A: HalApi> Drop for PipelineLayout<A> {
fn drop(&mut self) {
log::info!("Destroying PipelineLayout {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw PipelineLayout {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_pipeline_layout(raw);
Expand Down Expand Up @@ -827,8 +828,8 @@ pub struct BindGroup<A: HalApi> {

impl<A: HalApi> Drop for BindGroup<A> {
fn drop(&mut self) {
log::info!("Destroying BindGroup {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw BindGroup {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_bind_group(raw);
Expand Down
5 changes: 3 additions & 2 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::{Resource, ResourceInfo, ResourceType};
use crate::track::{Tracker, UsageScope};
use crate::{
api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, Label,
api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory,
resource_log, Label,
};

use hal::CommandEncoder as _;
Expand Down Expand Up @@ -137,7 +138,7 @@ impl<A: HalApi> Drop for CommandBuffer<A> {
if self.data.lock().is_none() {
return;
}
log::info!("Destroying CommandBuffer {:?}", self.info.label());
resource_log!("resource::CommandBuffer::drop {}", self.info.label());
let mut baked = self.extract_baked_commands();
unsafe {
baked.encoder.reset_all(baked.list.into_iter());
Expand Down
7 changes: 5 additions & 2 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
identity::{GlobalIdentityHandlerFactory, Input},
resource::{Buffer, BufferAccessResult},
resource::{BufferAccessError, BufferMapOperation},
Label, DOWNLEVEL_ERROR_MESSAGE,
resource_log, Label, DOWNLEVEL_ERROR_MESSAGE,
};

use arrayvec::ArrayVec;
Expand Down Expand Up @@ -372,7 +372,10 @@ impl<A: HalApi> CommandAllocator<A> {
}

fn dispose(self, device: &A::Device) {
log::info!("Destroying {} command encoders", self.free_encoders.len());
resource_log!(
"CommandAllocator::dispose encoders {}",
self.free_encoders.len()
);
for cmd_encoder in self.free_encoders {
unsafe {
device.destroy_command_encoder(cmd_encoder);
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
Buffer, BufferAccessError, BufferMapState, Resource, ResourceInfo, ResourceType,
StagingBuffer, Texture, TextureInner,
},
track, FastHashMap, SubmissionIndex,
resource_log, track, FastHashMap, SubmissionIndex,
};

use hal::{CommandEncoder as _, Device as _, Queue as _};
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let fid = hub.staging_buffers.prepare::<G>(id_in);
let (id, _) = fid.assign(staging_buffer);
log::info!("Created StagingBuffer {:?}", id);
resource_log!("Queue::create_staging_buffer {id:?}");

Ok((id, staging_buffer_ptr))
}
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
self, Buffer, QuerySet, Resource, ResourceType, Sampler, Texture, TextureView,
TextureViewNotRenderableReason,
},
resource_log,
storage::Storage,
track::{BindGroupStates, TextureSelector, Tracker},
validation::{self, check_buffer_usage, check_texture_usage},
Expand Down Expand Up @@ -140,7 +141,7 @@ impl<A: HalApi> std::fmt::Debug for Device<A> {

impl<A: HalApi> Drop for Device<A> {
fn drop(&mut self) {
log::info!("Destroying Device {:?}", self.info.label());
resource_log!("Destroy raw Device {}", self.info.label());
let raw = self.raw.take().unwrap();
let pending_writes = self.pending_writes.lock().take().unwrap();
pending_writes.dispose(&raw);
Expand Down
3 changes: 2 additions & 1 deletion wgpu-core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
identity::GlobalIdentityHandlerFactory,
instance::{Instance, Surface},
registry::{Registry, RegistryReport},
resource_log,
storage::Element,
};

Expand Down Expand Up @@ -150,7 +151,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
fn drop(&mut self) {
profiling::scope!("Global::drop");
log::info!("Destroying Global");
resource_log!("Global::drop");
let mut surfaces_locked = self.surfaces.write();

// destroy hubs before the instance gets dropped
Expand Down
12 changes: 6 additions & 6 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
identity::{GlobalIdentityHandlerFactory, Input},
present::Presentation,
resource::{Resource, ResourceInfo, ResourceType},
LabelHelpers, DOWNLEVEL_WARNING_MESSAGE,
resource_log, LabelHelpers, DOWNLEVEL_WARNING_MESSAGE,
};

use parking_lot::Mutex;
Expand Down Expand Up @@ -1082,7 +1082,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Backend::Gl => fid.assign(Adapter::new(hal_adapter)),
_ => unreachable!(),
};
log::info!("Created Adapter {:?}", id);
resource_log!("Created Adapter {:?}", id);
id
}

Expand Down Expand Up @@ -1203,13 +1203,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(e) => break e,
};
let (device_id, _) = device_fid.assign(device);
log::info!("Created Device {:?}", device_id);
resource_log!("Created Device {:?}", device_id);

let device = hub.devices.get(device_id).unwrap();
queue.device = Some(device.clone());

let (queue_id, _) = queue_fid.assign(queue);
log::info!("Created Queue {:?}", queue_id);
resource_log!("Created Queue {:?}", queue_id);

device.queue_id.write().replace(queue_id);

Expand Down Expand Up @@ -1255,13 +1255,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Err(e) => break e,
};
let (device_id, _) = devices_fid.assign(device);
log::info!("Created Device {:?}", device_id);
resource_log!("Created Device {:?}", device_id);

let device = hub.devices.get(device_id).unwrap();
queue.device = Some(device.clone());

let (queue_id, _) = queues_fid.assign(queue);
log::info!("Created Queue {:?}", queue_id);
resource_log!("Created Queue {:?}", queue_id);

device.queue_id.write().replace(queue_id);

Expand Down
10 changes: 10 additions & 0 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ macro_rules! api_log {
}
pub(crate) use api_log;

#[cfg(feature = "resource_log_info")]
macro_rules! resource_log {
($($arg:tt)+) => (log::info!($($arg)+))
}
#[cfg(not(feature = "resource_log_info"))]
macro_rules! resource_log {
($($arg:tt)+) => (log::trace!($($arg)+))
}
pub(crate) use resource_log;

/// Fast hash map used internally.
type FastHashMap<K, V> =
std::collections::HashMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
hal_api::HalApi,
id::{ComputePipelineId, PipelineLayoutId, RenderPipelineId, ShaderModuleId},
resource::{Resource, ResourceInfo, ResourceType},
validation, Label,
resource_log, validation, Label,
};
use arrayvec::ArrayVec;
use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32, sync::Arc};
Expand Down Expand Up @@ -54,8 +54,8 @@ pub struct ShaderModule<A: HalApi> {

impl<A: HalApi> Drop for ShaderModule<A> {
fn drop(&mut self) {
log::info!("Destroying ShaderModule {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw ShaderModule {}", self.info.label());
#[cfg(feature = "trace")]
if let Some(ref mut trace) = *self.device.trace.lock() {
trace.add(trace::Action::DestroyShaderModule(self.info.id()));
Expand Down Expand Up @@ -253,8 +253,8 @@ pub struct ComputePipeline<A: HalApi> {

impl<A: HalApi> Drop for ComputePipeline<A> {
fn drop(&mut self) {
log::info!("Destroying ComputePipeline {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw ComputePipeline {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_compute_pipeline(raw);
Expand Down Expand Up @@ -494,8 +494,8 @@ pub struct RenderPipeline<A: HalApi> {

impl<A: HalApi> Drop for RenderPipeline<A> {
fn drop(&mut self) {
log::info!("Destroying RenderPipeline {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw RenderPipeline {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_render_pipeline(raw);
Expand Down
15 changes: 7 additions & 8 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
},
identity::{GlobalIdentityHandlerFactory, IdentityManager},
init_tracker::{BufferInitTracker, TextureInitTracker},
resource,
resource, resource_log,
track::TextureSelector,
validation::MissingBufferUsageError,
Label, SubmissionIndex,
Expand Down Expand Up @@ -79,7 +79,6 @@ impl<Id: TypedId> Drop for ResourceInfo<Id> {
if let Some(identity) = self.identity.as_ref() {
let id = self.id.as_ref().unwrap();
identity.free(*id);
log::info!("Freeing {:?}", self.label());
}
}
}
Expand Down Expand Up @@ -418,8 +417,8 @@ pub struct Buffer<A: HalApi> {

impl<A: HalApi> Drop for Buffer<A> {
fn drop(&mut self) {
log::info!("Destroying Buffer {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw Buffer {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_buffer(raw);
Expand Down Expand Up @@ -639,8 +638,8 @@ pub struct StagingBuffer<A: HalApi> {

impl<A: HalApi> Drop for StagingBuffer<A> {
fn drop(&mut self) {
log::info!("Destroying StagingBuffer {:?}", self.info.label());
if let Some(raw) = self.raw.lock().take() {
resource_log!("Destroy raw StagingBuffer {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_buffer(raw);
Expand Down Expand Up @@ -722,7 +721,7 @@ pub struct Texture<A: HalApi> {

impl<A: HalApi> Drop for Texture<A> {
fn drop(&mut self) {
log::info!("Destroying Texture {:?}", self.info.label());
resource_log!("Destroy raw Texture {}", self.info.label());
use hal::Device;
let mut clear_mode = self.clear_mode.write();
let clear_mode = &mut *clear_mode;
Expand Down Expand Up @@ -1038,8 +1037,8 @@ pub struct TextureView<A: HalApi> {

impl<A: HalApi> Drop for TextureView<A> {
fn drop(&mut self) {
log::info!("Destroying TextureView {:?}", self.info.label());
if let Some(raw) = self.raw.take() {
resource_log!("Destroy raw TextureView {}", self.info.label());
unsafe {
use hal::Device;
self.device.raw().destroy_texture_view(raw);
Expand Down Expand Up @@ -1160,7 +1159,7 @@ pub struct Sampler<A: HalApi> {

impl<A: HalApi> Drop for Sampler<A> {
fn drop(&mut self) {
log::info!("Destroying Sampler {:?}", self.info.label());
resource_log!("Destroy raw Sampler {}", self.info.label());
if let Some(raw) = self.raw.take() {
unsafe {
use hal::Device;
Expand Down Expand Up @@ -1257,7 +1256,7 @@ pub struct QuerySet<A: HalApi> {

impl<A: HalApi> Drop for QuerySet<A> {
fn drop(&mut self) {
log::info!("Destroying QuerySet {:?}", self.info.label());
resource_log!("Destroy raw QuerySet {}", self.info.label());
if let Some(raw) = self.raw.take() {
unsafe {
use hal::Device;
Expand Down
5 changes: 4 additions & 1 deletion wgpu-core/src/track/stateless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use std::{marker::PhantomData, sync::Arc};
use parking_lot::Mutex;

use crate::{
hal_api::HalApi, id::TypedId, resource::Resource, storage::Storage, track::ResourceMetadata,
hal_api::HalApi, id::TypedId, resource::Resource, resource_log, storage::Storage,
track::ResourceMetadata,
};

use super::ResourceTracker;
Expand Down Expand Up @@ -91,6 +92,8 @@ impl<A: HalApi, Id: TypedId, T: Resource<Id>> ResourceTracker<Id, T>
return false;
}

resource_log!("StatelessTracker::remove_abandoned {id:?}");

self.tracker_assert_in_bounds(index);

unsafe {
Expand Down
Loading