Skip to content

Commit

Permalink
Move the api logging behind the api_log macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Nov 24, 2023
1 parent d4801c9 commit 18db609
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 91 deletions.
2 changes: 2 additions & 0 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ targets = [

[features]
default = ["link"]
# Log all API entry points at info instead of trace level.
api_log_info = []

# Backends, passed through to wgpu-hal
metal = ["hal/metal"]
Expand Down
5 changes: 3 additions & 2 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{ops::Range, sync::Arc};
#[cfg(feature = "trace")]
use crate::device::trace::Command as TraceCommand;
use crate::{
api_log,
command::CommandBuffer,
get_lowest_common_denom,
global::Global,
Expand Down Expand Up @@ -76,7 +77,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
size: Option<BufferAddress>,
) -> Result<(), ClearError> {
profiling::scope!("CommandEncoder::clear_buffer");
log::info!("CommandEncoder::clear_buffer {dst:?}");
api_log!("CommandEncoder::clear_buffer {dst:?}");

let hub = A::hub(self);

Expand Down Expand Up @@ -161,7 +162,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
subresource_range: &ImageSubresourceRange,
) -> Result<(), ClearError> {
profiling::scope!("CommandEncoder::clear_texture");
log::info!("CommandEncoder::clear_texture {dst:?}");
api_log!("CommandEncoder::clear_texture {dst:?}");

let hub = A::hub(self);

Expand Down
10 changes: 6 additions & 4 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use crate::id::CommandBufferId;
use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::{Resource, ResourceInfo, ResourceType};
use crate::track::{Tracker, UsageScope};
use crate::{global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, Label};
use crate::{
api_log, global::Global, hal_api::HalApi, id, identity::GlobalIdentityHandlerFactory, Label,
};

use hal::CommandEncoder as _;
use parking_lot::Mutex;
Expand Down Expand Up @@ -435,7 +437,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
label: &str,
) -> Result<(), CommandEncoderError> {
profiling::scope!("CommandEncoder::push_debug_group");
log::info!("CommandEncoder::push_debug_group {label}");
api_log!("CommandEncoder::push_debug_group {label}");

let hub = A::hub(self);

Expand Down Expand Up @@ -466,7 +468,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
label: &str,
) -> Result<(), CommandEncoderError> {
profiling::scope!("CommandEncoder::insert_debug_marker");
log::info!("CommandEncoder::insert_debug_marker {label}");
api_log!("CommandEncoder::insert_debug_marker {label}");

let hub = A::hub(self);

Expand Down Expand Up @@ -497,7 +499,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
encoder_id: id::CommandEncoderId,
) -> Result<(), CommandEncoderError> {
profiling::scope!("CommandEncoder::pop_debug_marker");
log::info!("CommandEncoder::pop_debug_group");
api_log!("CommandEncoder::pop_debug_group");

let hub = A::hub(self);

Expand Down
45 changes: 23 additions & 22 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::resource::Resource;
use crate::{
api_log,
binding_model::BindError,
command::{
self,
Expand Down Expand Up @@ -1410,7 +1411,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
num_dynamic_offsets,
bind_group_id,
} => {
log::info!("RenderPass::set_bind_group {index} {bind_group_id:?}");
api_log!("RenderPass::set_bind_group {index} {bind_group_id:?}");

let scope = PassErrorScope::SetBindGroup(bind_group_id);
let max_bind_groups = device.limits.max_bind_groups;
Expand Down Expand Up @@ -1493,7 +1494,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
RenderCommand::SetPipeline(pipeline_id) => {
log::info!("RenderPass::set_pipeline {pipeline_id:?}");
api_log!("RenderPass::set_pipeline {pipeline_id:?}");

let scope = PassErrorScope::SetPipelineRender(pipeline_id);
state.pipeline = Some(pipeline_id);
Expand Down Expand Up @@ -1621,7 +1622,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offset,
size,
} => {
log::info!("RenderPass::set_index_buffer {buffer_id:?}");
api_log!("RenderPass::set_index_buffer {buffer_id:?}");

let scope = PassErrorScope::SetIndexBuffer(buffer_id);
let buffer = info
Expand Down Expand Up @@ -1674,7 +1675,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offset,
size,
} => {
log::info!("RenderPass::set_vertex_buffer {slot} {buffer_id:?}");
api_log!("RenderPass::set_vertex_buffer {slot} {buffer_id:?}");

let scope = PassErrorScope::SetVertexBuffer(buffer_id);
let buffer = info
Expand Down Expand Up @@ -1737,7 +1738,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
state.vertex.update_limits();
}
RenderCommand::SetBlendConstant(ref color) => {
log::info!("RenderPass::set_blend_constant");
api_log!("RenderPass::set_blend_constant");

state.blend_constant = OptionalState::Set;
let array = [
Expand All @@ -1751,7 +1752,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
RenderCommand::SetStencilReference(value) => {
log::info!("RenderPass::set_stencil_reference {value}");
api_log!("RenderPass::set_stencil_reference {value}");

state.stencil_reference = value;
if state
Expand All @@ -1768,7 +1769,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
depth_min,
depth_max,
} => {
log::info!("RenderPass::set_viewport {rect:?}");
api_log!("RenderPass::set_viewport {rect:?}");

let scope = PassErrorScope::SetViewport;
if rect.x < 0.0
Expand Down Expand Up @@ -1806,7 +1807,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
size_bytes,
values_offset,
} => {
log::info!("RenderPass::set_push_constants");
api_log!("RenderPass::set_push_constants");

let scope = PassErrorScope::SetPushConstant;
let values_offset = values_offset
Expand Down Expand Up @@ -1841,7 +1842,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
RenderCommand::SetScissor(ref rect) => {
log::info!("RenderPass::set_scissor_rect {rect:?}");
api_log!("RenderPass::set_scissor_rect {rect:?}");

let scope = PassErrorScope::SetScissorRect;
if rect.x + rect.w > info.extent.width
Expand All @@ -1866,7 +1867,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
first_vertex,
first_instance,
} => {
log::info!(
api_log!(
"RenderPass::draw {vertex_count} {instance_count} {first_vertex} {first_instance}"
);

Expand Down Expand Up @@ -1910,7 +1911,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
base_vertex,
first_instance,
} => {
log::info!("RenderPass::draw_indexed {index_count} {instance_count} {first_index} {base_vertex} {first_instance}");
api_log!("RenderPass::draw_indexed {index_count} {instance_count} {first_index} {base_vertex} {first_instance}");

let indexed = true;
let scope = PassErrorScope::Draw {
Expand Down Expand Up @@ -1958,7 +1959,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
count,
indexed,
} => {
log::info!("RenderPass::draw_indirect (indexed:{indexed}) {buffer_id:?} {offset} {count:?}");
api_log!("RenderPass::draw_indirect (indexed:{indexed}) {buffer_id:?} {offset} {count:?}");

let scope = PassErrorScope::Draw {
indexed,
Expand Down Expand Up @@ -2032,7 +2033,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
max_count,
indexed,
} => {
log::info!("RenderPass::multi_draw_indirect_count (indexed:{indexed}) {buffer_id:?} {offset} {count_buffer_id:?} {count_buffer_offset:?} {max_count:?}");
api_log!("RenderPass::multi_draw_indirect_count (indexed:{indexed}) {buffer_id:?} {offset} {count_buffer_id:?} {count_buffer_offset:?} {max_count:?}");

let scope = PassErrorScope::Draw {
indexed,
Expand Down Expand Up @@ -2148,15 +2149,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
)
.unwrap();

log::info!("RenderPass::push_debug_group {label:?}");
api_log!("RenderPass::push_debug_group {label:?}");
unsafe {
raw.begin_debug_marker(label);
}
}
string_offset += len;
}
RenderCommand::PopDebugGroup => {
log::info!("RenderPass::pop_debug_group");
api_log!("RenderPass::pop_debug_group");

let scope = PassErrorScope::PopDebugGroup;
if state.debug_scope_depth == 0 {
Expand All @@ -2176,7 +2177,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&base.string_data[string_offset..string_offset + len],
)
.unwrap();
log::info!("RenderPass::insert_debug_marker {label:?}");
api_log!("RenderPass::insert_debug_marker {label:?}");
unsafe {
raw.insert_debug_marker(label);
}
Expand All @@ -2187,7 +2188,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
query_set_id,
query_index,
} => {
log::info!("RenderPass::write_timestamps {query_set_id:?} {query_index}");
api_log!("RenderPass::write_timestamps {query_set_id:?} {query_index}");
let scope = PassErrorScope::WriteTimestamp;

device
Expand All @@ -2210,7 +2211,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_pass_err(scope)?;
}
RenderCommand::BeginOcclusionQuery { query_index } => {
log::info!("RenderPass::begin_occlusion_query {query_index}");
api_log!("RenderPass::begin_occlusion_query {query_index}");
let scope = PassErrorScope::BeginOcclusionQuery;

let query_set_id = occlusion_query_set_id
Expand All @@ -2234,7 +2235,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_pass_err(scope)?;
}
RenderCommand::EndOcclusionQuery => {
log::info!("RenderPass::end_occlusion_query");
api_log!("RenderPass::end_occlusion_query");
let scope = PassErrorScope::EndOcclusionQuery;

end_occlusion_query(raw, &*query_set_guard, &mut active_query)
Expand All @@ -2244,7 +2245,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
query_set_id,
query_index,
} => {
log::info!("RenderPass::begin_pipeline_statistics_query {query_set_id:?} {query_index}");
api_log!("RenderPass::begin_pipeline_statistics_query {query_set_id:?} {query_index}");
let scope = PassErrorScope::BeginPipelineStatisticsQuery;

let query_set = tracker
Expand All @@ -2264,14 +2265,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.map_pass_err(scope)?;
}
RenderCommand::EndPipelineStatisticsQuery => {
log::info!("RenderPass::end_pipeline_statistics_query");
api_log!("RenderPass::end_pipeline_statistics_query");
let scope = PassErrorScope::EndPipelineStatisticsQuery;

end_pipeline_statistics_query(raw, &*query_set_guard, &mut active_query)
.map_pass_err(scope)?;
}
RenderCommand::ExecuteBundle(bundle_id) => {
log::info!("RenderPass::execute_bundle {bundle_id:?}");
api_log!("RenderPass::execute_bundle {bundle_id:?}");
let scope = PassErrorScope::ExecuteBundle;
let bundle: &command::RenderBundle<A> = tracker
.bundles
Expand Down
9 changes: 5 additions & 4 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[cfg(feature = "trace")]
use crate::device::trace::Command as TraceCommand;
use crate::{
api_log,
command::{clear_texture, CommandBuffer, CommandEncoderError},
conv,
device::{Device, MissingDownlevelFlags},
Expand Down Expand Up @@ -567,7 +568,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
size: BufferAddress,
) -> Result<(), CopyError> {
profiling::scope!("CommandEncoder::copy_buffer_to_buffer");
log::info!(
api_log!(
"CommandEncoder::copy_buffer_to_buffer {source:?} -> {destination:?} {size:?}bytes"
);

Expand Down Expand Up @@ -730,7 +731,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
copy_size: &Extent3d,
) -> Result<(), CopyError> {
profiling::scope!("CommandEncoder::copy_buffer_to_texture");
log::info!(
api_log!(
"CommandEncoder::copy_buffer_to_texture {:?} -> {:?} {copy_size:?}",
source.buffer,
destination.texture
Expand Down Expand Up @@ -893,7 +894,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
copy_size: &Extent3d,
) -> Result<(), CopyError> {
profiling::scope!("CommandEncoder::copy_texture_to_buffer");
log::info!(
api_log!(
"CommandEncoder::copy_texture_to_buffer {:?} -> {:?} {copy_size:?}",
source.texture,
destination.buffer
Expand Down Expand Up @@ -1068,7 +1069,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
copy_size: &Extent3d,
) -> Result<(), CopyError> {
profiling::scope!("CommandEncoder::copy_texture_to_texture");
log::info!(
api_log!(
"CommandEncoder::copy_texture_to_texture {:?} -> {:?} {copy_size:?}",
source.texture,
destination.texture
Expand Down
Loading

0 comments on commit 18db609

Please sign in to comment.