Add Tracing and Instrument Entry Points

This commit is contained in:
Connor Fitzgerald 2020-06-18 22:19:08 -04:00
parent c7be94047d
commit 1b2cf3cd22
15 changed files with 213 additions and 9 deletions

29
Cargo.lock generated
View File

@ -1250,6 +1250,34 @@ dependencies = [
"serde",
]
[[package]]
name = "tracing"
version = "0.1.15"
source = "git+https://github.com/tokio-rs/tracing?rev=845746a2a302f0dfac88ba56ea37dc1e1cb0cd85#845746a2a302f0dfac88ba56ea37dc1e1cb0cd85"
dependencies = [
"cfg-if",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.8"
source = "git+https://github.com/tokio-rs/tracing?rev=845746a2a302f0dfac88ba56ea37dc1e1cb0cd85#845746a2a302f0dfac88ba56ea37dc1e1cb0cd85"
dependencies = [
"proc-macro2 1.0.18",
"quote 1.0.7",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.10"
source = "git+https://github.com/tokio-rs/tracing?rev=845746a2a302f0dfac88ba56ea37dc1e1cb0cd85#845746a2a302f0dfac88ba56ea37dc1e1cb0cd85"
dependencies = [
"lazy_static",
]
[[package]]
name = "typenum"
version = "1.12.0"
@ -1441,6 +1469,7 @@ dependencies = [
"serde",
"smallvec",
"spirv_headers",
"tracing",
"vec_map",
"wgpu-types",
]

View File

@ -441,7 +441,7 @@ fn main() {
env_logger::init();
#[cfg(feature = "renderdoc")]
let mut rd = renderdoc::RenderDoc::<renderdoc::V110>::new()
let mut _rd = renderdoc::RenderDoc::<renderdoc::V110>::new()
.expect("Failed to connect to RenderDoc: are you running without it?");
//TODO: setting for the backend bits
@ -514,14 +514,14 @@ fn main() {
#[cfg(not(feature = "winit"))]
{
#[cfg(feature = "renderdoc")]
rd.start_frame_capture(ptr::null(), ptr::null());
_rd.start_frame_capture(ptr::null(), ptr::null());
while let Some(action) = actions.pop() {
gfx_select!(device => global.process(device, action, &dir, &mut command_buffer_id_manager));
}
#[cfg(feature = "renderdoc")]
rd.end_frame_capture(ptr::null(), ptr::null());
_rd.end_frame_capture(ptr::null(), ptr::null());
gfx_select!(device => global.device_poll(device, true));
}
#[cfg(feature = "winit")]

View File

@ -34,6 +34,7 @@ ron = { version = "0.5", optional = true }
serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "1"
spirv_headers = { version = "1.4.2" }
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "845746a2a302f0dfac88ba56ea37dc1e1cb0cd85" }
vec_map = "0.8.1"
[dependencies.naga]

View File

@ -43,6 +43,7 @@ use crate::{
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Storage, Token},
id,
resource::BufferUse,
span,
track::TrackerSet,
LifeGuard, RefCount, Stored, MAX_BIND_GROUPS,
};
@ -62,6 +63,7 @@ impl RenderBundleEncoder {
parent_id: id::DeviceId,
base: Option<BasePass<RenderCommand>>,
) -> Self {
span!(_guard, TRACE, "RenderBundleEncoder::new");
RenderBundleEncoder {
base: base.unwrap_or_else(BasePass::new),
parent_id,
@ -481,6 +483,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::RenderBundleDescriptor<Label>,
id_in: Input<G, id::RenderBundleId>,
) -> id::RenderBundleId {
span!(_guard, TRACE, "RenderBundleEncoder::finish");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -752,7 +755,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub mod bundle_ffi {
use super::{RenderBundleEncoder, RenderCommand};
use crate::{id, RawString};
use crate::{id, RawString, span};
use std::{convert::TryInto, slice};
use wgt::{BufferAddress, BufferSize, DynamicOffset};
@ -770,6 +773,7 @@ pub mod bundle_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
span!(_guard, TRACE, "RenderBundle::set_bind_group");
bundle.base.commands.push(RenderCommand::SetBindGroup {
index: index.try_into().unwrap(),
num_dynamic_offsets: offset_length.try_into().unwrap(),
@ -786,6 +790,7 @@ pub mod bundle_ffi {
bundle: &mut RenderBundleEncoder,
pipeline_id: id::RenderPipelineId,
) {
span!(_guard, TRACE, "RenderBundle::set_pipeline");
bundle
.base
.commands
@ -799,6 +804,7 @@ pub mod bundle_ffi {
offset: BufferAddress,
size: Option<BufferSize>,
) {
span!(_guard, TRACE, "RenderBundle::set_index_buffer");
bundle.base.commands.push(RenderCommand::SetIndexBuffer {
buffer_id,
offset,
@ -814,6 +820,7 @@ pub mod bundle_ffi {
offset: BufferAddress,
size: Option<BufferSize>,
) {
span!(_guard, TRACE, "RenderBundle::set_vertex_buffer");
bundle.base.commands.push(RenderCommand::SetVertexBuffer {
slot,
buffer_id,
@ -830,6 +837,7 @@ pub mod bundle_ffi {
first_vertex: u32,
first_instance: u32,
) {
span!(_guard, TRACE, "RenderBundle::draw");
bundle.base.commands.push(RenderCommand::Draw {
vertex_count,
instance_count,
@ -847,6 +855,7 @@ pub mod bundle_ffi {
base_vertex: i32,
first_instance: u32,
) {
span!(_guard, TRACE, "RenderBundle::draw_indexed");
bundle.base.commands.push(RenderCommand::DrawIndexed {
index_count,
instance_count,
@ -862,6 +871,7 @@ pub mod bundle_ffi {
buffer_id: id::BufferId,
offset: BufferAddress,
) {
span!(_guard, TRACE, "RenderBundle::draw_indirect");
bundle
.base
.commands
@ -874,6 +884,7 @@ pub mod bundle_ffi {
buffer_id: id::BufferId,
offset: BufferAddress,
) {
span!(_guard, TRACE, "RenderBundle::draw_indexed_indirect");
bundle
.base
.commands
@ -885,11 +896,13 @@ pub mod bundle_ffi {
_bundle: &mut RenderBundleEncoder,
_label: RawString,
) {
span!(_guard, TRACE, "RenderBundle::push_debug_group");
//TODO
}
#[no_mangle]
pub unsafe extern "C" fn wgpu_render_bundle_pop_debug_group(_bundle: &mut RenderBundleEncoder) {
span!(_guard, TRACE, "RenderBundle::pop_debug_group");
//TODO
}
@ -898,6 +911,7 @@ pub mod bundle_ffi {
_bundle: &mut RenderBundleEncoder,
_label: RawString,
) {
span!(_guard, TRACE, "RenderBundle::insert_debug_marker");
//TODO
}
}

View File

@ -11,6 +11,7 @@ use crate::{
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
id,
resource::BufferUse,
span,
};
use hal::command::CommandBuffer as _;
@ -106,6 +107,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
encoder_id: id::CommandEncoderId,
mut base: BasePassRef<ComputeCommand>,
) {
span!(_guard, TRACE, "CommandEncoder::run_compute_pass");
let hub = B::hub(self);
let mut token = Token::root();
@ -314,7 +316,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub mod compute_ffi {
use super::{ComputeCommand, ComputePass};
use crate::{id, RawString};
use crate::{id, RawString, span};
use std::{convert::TryInto, ffi, slice};
use wgt::{BufferAddress, DynamicOffset};
@ -332,6 +334,7 @@ pub mod compute_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
span!(_guard, TRACE, "ComputePass::set_bind_group");
pass.base.commands.push(ComputeCommand::SetBindGroup {
index: index.try_into().unwrap(),
num_dynamic_offsets: offset_length.try_into().unwrap(),
@ -347,6 +350,7 @@ pub mod compute_ffi {
pass: &mut ComputePass,
pipeline_id: id::ComputePipelineId,
) {
span!(_guard, TRACE, "ComputePass::set_pipeline");
pass.base
.commands
.push(ComputeCommand::SetPipeline(pipeline_id));
@ -359,6 +363,7 @@ pub mod compute_ffi {
groups_y: u32,
groups_z: u32,
) {
span!(_guard, TRACE, "ComputePass::dispatch");
pass.base
.commands
.push(ComputeCommand::Dispatch([groups_x, groups_y, groups_z]));
@ -370,6 +375,7 @@ pub mod compute_ffi {
buffer_id: id::BufferId,
offset: BufferAddress,
) {
span!(_guard, TRACE, "ComputePass::dispatch_indirect");
pass.base
.commands
.push(ComputeCommand::DispatchIndirect { buffer_id, offset });
@ -381,6 +387,7 @@ pub mod compute_ffi {
label: RawString,
color: u32,
) {
span!(_guard, TRACE, "ComputePass::push_debug_group");
let bytes = ffi::CStr::from_ptr(label).to_bytes();
pass.base.string_data.extend_from_slice(bytes);
@ -392,6 +399,7 @@ pub mod compute_ffi {
#[no_mangle]
pub extern "C" fn wgpu_compute_pass_pop_debug_group(pass: &mut ComputePass) {
span!(_guard, TRACE, "ComputePass::pop_debug_group");
pass.base.commands.push(ComputeCommand::PopDebugGroup);
}
@ -401,6 +409,7 @@ pub mod compute_ffi {
label: RawString,
color: u32,
) {
span!(_guard, TRACE, "ComputePass::insert_debug_marker");
let bytes = ffi::CStr::from_ptr(label).to_bytes();
pass.base.string_data.extend_from_slice(bytes);

View File

@ -20,6 +20,7 @@ use crate::{
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Storage, Token},
id,
resource::{Buffer, Texture},
span,
track::TrackerSet,
PrivateFeatures, Stored,
};
@ -139,6 +140,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
encoder_id: id::CommandEncoderId,
_desc: &wgt::CommandBufferDescriptor,
) -> id::CommandBufferId {
span!(_guard, TRACE, "CommandEncoder::finish");
let hub = B::hub(self);
let mut token = Token::root();
let (swap_chain_guard, mut token) = hub.swap_chains.read(&mut token);
@ -164,6 +167,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
encoder_id: id::CommandEncoderId,
label: &str,
) {
span!(_guard, TRACE, "CommandEncoder::push_debug_group");
let hub = B::hub(self);
let mut token = Token::root();
@ -181,6 +186,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
encoder_id: id::CommandEncoderId,
label: &str,
) {
span!(_guard, TRACE, "CommandEncoder::insert_debug_marker");
let hub = B::hub(self);
let mut token = Token::root();
@ -194,6 +201,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn command_encoder_pop_debug_group<B: GfxBackend>(&self, encoder_id: id::CommandEncoderId) {
span!(_guard, TRACE, "CommandEncoder::pop_debug_marker");
let hub = B::hub(self);
let mut token = Token::root();

View File

@ -16,6 +16,7 @@ use crate::{
id,
pipeline::PipelineFlags,
resource::{BufferUse, TextureUse, TextureViewInner},
span,
track::TrackerSet,
Stored,
};
@ -341,6 +342,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
color_attachments: &[ColorAttachmentDescriptor],
depth_stencil_attachment: Option<&DepthStencilAttachmentDescriptor>,
) {
span!(_guard, TRACE, "CommandEncoder::run_render_pass");
let hub = B::hub(self);
let mut token = Token::root();
@ -1296,7 +1299,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub mod render_ffi {
use super::{super::Rect, RenderCommand, RenderPass};
use crate::{id, RawString};
use crate::{id, span, RawString};
use std::{convert::TryInto, ffi, slice};
use wgt::{BufferAddress, BufferSize, Color, DynamicOffset};
@ -1314,6 +1317,7 @@ pub mod render_ffi {
offsets: *const DynamicOffset,
offset_length: usize,
) {
span!(_guard, TRACE, "RenderPass::set_bind_group");
pass.base.commands.push(RenderCommand::SetBindGroup {
index: index.try_into().unwrap(),
num_dynamic_offsets: offset_length.try_into().unwrap(),
@ -1329,6 +1333,7 @@ pub mod render_ffi {
pass: &mut RenderPass,
pipeline_id: id::RenderPipelineId,
) {
span!(_guard, TRACE, "RenderPass::set_pipeline");
pass.base
.commands
.push(RenderCommand::SetPipeline(pipeline_id));
@ -1341,6 +1346,7 @@ pub mod render_ffi {
offset: BufferAddress,
size: Option<BufferSize>,
) {
span!(_guard, TRACE, "RenderPass::set_index_buffer");
pass.base.commands.push(RenderCommand::SetIndexBuffer {
buffer_id,
offset,
@ -1356,6 +1362,7 @@ pub mod render_ffi {
offset: BufferAddress,
size: Option<BufferSize>,
) {
span!(_guard, TRACE, "RenderPass::set_vertex_buffer");
pass.base.commands.push(RenderCommand::SetVertexBuffer {
slot,
buffer_id,
@ -1366,6 +1373,7 @@ pub mod render_ffi {
#[no_mangle]
pub extern "C" fn wgpu_render_pass_set_blend_color(pass: &mut RenderPass, color: &Color) {
span!(_guard, TRACE, "RenderPass::set_blend_color");
pass.base
.commands
.push(RenderCommand::SetBlendColor(*color));
@ -1373,6 +1381,7 @@ pub mod render_ffi {
#[no_mangle]
pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass: &mut RenderPass, value: u32) {
span!(_guard, TRACE, "RenderPass::set_stencil_buffer");
pass.base
.commands
.push(RenderCommand::SetStencilReference(value));
@ -1388,6 +1397,7 @@ pub mod render_ffi {
depth_min: f32,
depth_max: f32,
) {
span!(_guard, TRACE, "RenderPass::set_viewport");
pass.base.commands.push(RenderCommand::SetViewport {
rect: Rect { x, y, w, h },
depth_min,
@ -1403,6 +1413,7 @@ pub mod render_ffi {
w: u32,
h: u32,
) {
span!(_guard, TRACE, "RenderPass::set_scissor_rect");
pass.base
.commands
.push(RenderCommand::SetScissor(Rect { x, y, w, h }));
@ -1416,6 +1427,7 @@ pub mod render_ffi {
first_vertex: u32,
first_instance: u32,
) {
span!(_guard, TRACE, "RenderPass::draw");
pass.base.commands.push(RenderCommand::Draw {
vertex_count,
instance_count,
@ -1433,6 +1445,7 @@ pub mod render_ffi {
base_vertex: i32,
first_instance: u32,
) {
span!(_guard, TRACE, "RenderPass::draw_indexed");
pass.base.commands.push(RenderCommand::DrawIndexed {
index_count,
instance_count,
@ -1448,6 +1461,7 @@ pub mod render_ffi {
buffer_id: id::BufferId,
offset: BufferAddress,
) {
span!(_guard, TRACE, "RenderPass::draw_indirect");
pass.base
.commands
.push(RenderCommand::DrawIndirect { buffer_id, offset });
@ -1459,6 +1473,7 @@ pub mod render_ffi {
buffer_id: id::BufferId,
offset: BufferAddress,
) {
span!(_guard, TRACE, "RenderPass::draw_indexed_indirect");
pass.base
.commands
.push(RenderCommand::DrawIndexedIndirect { buffer_id, offset });
@ -1470,6 +1485,7 @@ pub mod render_ffi {
label: RawString,
color: u32,
) {
span!(_guard, TRACE, "RenderPass::push_debug_group");
let bytes = ffi::CStr::from_ptr(label).to_bytes();
pass.base.string_data.extend_from_slice(bytes);
@ -1481,6 +1497,7 @@ pub mod render_ffi {
#[no_mangle]
pub extern "C" fn wgpu_render_pass_pop_debug_group(pass: &mut RenderPass) {
span!(_guard, TRACE, "RenderPass::pop_debug_group");
pass.base.commands.push(RenderCommand::PopDebugGroup);
}
@ -1490,6 +1507,7 @@ pub mod render_ffi {
label: RawString,
color: u32,
) {
span!(_guard, TRACE, "RenderPass::insert_debug_marker");
let bytes = ffi::CStr::from_ptr(label).to_bytes();
pass.base.string_data.extend_from_slice(bytes);
@ -1505,6 +1523,7 @@ pub mod render_ffi {
render_bundle_ids: *const id::RenderBundleId,
render_bundle_ids_length: usize,
) {
span!(_guard, TRACE, "RenderPass::execute_bundles");
for &bundle_id in slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) {
pass.base
.commands

View File

@ -10,6 +10,7 @@ use crate::{
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Storage, Token},
id::{BufferId, CommandEncoderId, TextureId},
resource::{BufferUse, Texture, TextureUse},
span,
};
use hal::command::CommandBuffer as _;
@ -266,6 +267,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
destination_offset: BufferAddress,
size: BufferAddress,
) {
span!(_guard, TRACE, "CommandEncoder::copy_buffer_to_buffer");
let hub = B::hub(self);
let mut token = Token::root();
@ -379,6 +382,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
destination: &TextureCopyView,
copy_size: &Extent3d,
) {
span!(_guard, TRACE, "CommandEncoder::copy_buffer_to_texture");
let hub = B::hub(self);
let mut token = Token::root();
let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token);
@ -472,6 +477,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
destination: &BufferCopyView,
copy_size: &Extent3d,
) {
span!(_guard, TRACE, "CommandEncoder::copy_texture_to_buffer");
let hub = B::hub(self);
let mut token = Token::root();
let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token);
@ -573,6 +580,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
destination: &TextureCopyView,
copy_size: &Extent3d,
) {
span!(_guard, TRACE, "CommandEncoder::copy_texture_to_texture");
let hub = B::hub(self);
let mut token = Token::root();

View File

@ -6,7 +6,7 @@ use crate::{
binding_model::{self, BindGroupError},
command, conv,
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Hub, Input, Token},
id, pipeline, resource, swap_chain,
id, pipeline, resource, span, swap_chain,
track::{BufferState, TextureState, TrackerSet},
validation, FastHashMap, LifeGuard, PrivateFeatures, Stored, SubmissionIndex, MAX_BIND_GROUPS,
};
@ -635,6 +635,8 @@ impl<B: hal::Backend> Device<B> {
impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn device_extensions<B: GfxBackend>(&self, device_id: id::DeviceId) -> wgt::Extensions {
span!(_guard, TRACE, "Device::extensions");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, _) = hub.devices.read(&mut token);
@ -644,6 +646,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn device_limits<B: GfxBackend>(&self, device_id: id::DeviceId) -> wgt::Limits {
span!(_guard, TRACE, "Device::limits");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, _) = hub.devices.read(&mut token);
@ -653,6 +657,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn device_capabilities<B: GfxBackend>(&self, device_id: id::DeviceId) -> wgt::Capabilities {
span!(_guard, TRACE, "Device::capabilities");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, _) = hub.devices.read(&mut token);
@ -667,6 +673,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::BufferDescriptor<Label>,
id_in: Input<G, id::BufferId>,
) -> id::BufferId {
span!(_guard, TRACE, "Device::create_buffer");
let hub = B::hub(self);
let mut token = Token::root();
@ -785,6 +793,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offset: BufferAddress,
data: &[u8],
) {
span!(_guard, TRACE, "Device::set_buffer_sub_data");
let hub = B::hub(self);
let mut token = Token::root();
@ -842,6 +852,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offset: BufferAddress,
data: &mut [u8],
) {
span!(_guard, TRACE, "Device::get_buffer_sub_data");
let hub = B::hub(self);
let mut token = Token::root();
@ -878,6 +890,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn buffer_destroy<B: GfxBackend>(&self, buffer_id: id::BufferId) {
span!(_guard, TRACE, "Buffer::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -902,6 +916,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::TextureDescriptor<Label>,
id_in: Input<G, id::TextureId>,
) -> id::TextureId {
span!(_guard, TRACE, "Device::create_texture");
let hub = B::hub(self);
let mut token = Token::root();
@ -931,6 +947,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn texture_destroy<B: GfxBackend>(&self, texture_id: id::TextureId) {
span!(_guard, TRACE, "Texture::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -954,6 +972,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: Option<&wgt::TextureViewDescriptor<Label>>,
id_in: Input<G, id::TextureViewId>,
) -> id::TextureViewId {
span!(_guard, TRACE, "Texture::create_view");
let hub = B::hub(self);
let mut token = Token::root();
@ -1044,6 +1064,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn texture_view_destroy<B: GfxBackend>(&self, texture_view_id: id::TextureViewId) {
span!(_guard, TRACE, "Texture::view_destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -1077,6 +1099,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::SamplerDescriptor<Label>,
id_in: Input<G, id::SamplerId>,
) -> id::SamplerId {
span!(_guard, TRACE, "Device::create_sampler");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -1142,6 +1166,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn sampler_destroy<B: GfxBackend>(&self, sampler_id: id::SamplerId) {
span!(_guard, TRACE, "Sampler::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -1166,6 +1192,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::BindGroupLayoutDescriptor,
id_in: Input<G, id::BindGroupLayoutId>,
) -> Result<id::BindGroupLayoutId, binding_model::BindGroupLayoutError> {
span!(_guard, TRACE, "Device::create_bind_group_layout");
let mut token = Token::root();
let hub = B::hub(self);
let mut entry_map = FastHashMap::default();
@ -1284,6 +1312,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self,
bind_group_layout_id: id::BindGroupLayoutId,
) {
span!(_guard, TRACE, "BindGroupLayout::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (device_id, ref_count) = {
@ -1312,6 +1342,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &binding_model::PipelineLayoutDescriptor,
id_in: Input<G, id::PipelineLayoutId>,
) -> Result<id::PipelineLayoutId, binding_model::PipelineLayoutError> {
span!(_guard, TRACE, "Device::create_pipeline_layout");
let hub = B::hub(self);
let mut token = Token::root();
@ -1375,6 +1407,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn pipeline_layout_destroy<B: GfxBackend>(&self, pipeline_layout_id: id::PipelineLayoutId) {
span!(_guard, TRACE, "PipelineLayout::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (device_id, ref_count) = {
@ -1405,6 +1439,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
) -> Result<id::BindGroupId, BindGroupError> {
use crate::binding_model::BindingResource as Br;
span!(_guard, TRACE, "Device::create_bind_group");
let hub = B::hub(self);
let mut token = Token::root();
@ -1773,6 +1809,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn bind_group_destroy<B: GfxBackend>(&self, bind_group_id: id::BindGroupId) {
span!(_guard, TRACE, "BindGroup::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -1797,6 +1835,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
source: pipeline::ShaderModuleSource,
id_in: Input<G, id::ShaderModuleId>,
) -> id::ShaderModuleId {
span!(_guard, TRACE, "Device::create_shader_module");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -1877,6 +1917,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn shader_module_destroy<B: GfxBackend>(&self, shader_module_id: id::ShaderModuleId) {
span!(_guard, TRACE, "ShaderModule::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -1901,6 +1943,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &wgt::CommandEncoderDescriptor<Label>,
id_in: Input<G, id::CommandEncoderId>,
) -> id::CommandEncoderId {
span!(_guard, TRACE, "Device::create_command_encoder");
let hub = B::hub(self);
let mut token = Token::root();
@ -1937,6 +1981,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn command_encoder_destroy<B: GfxBackend>(&self, command_encoder_id: id::CommandEncoderId) {
span!(_guard, TRACE, "CommandEncoder::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -1952,6 +1998,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn command_buffer_destroy<B: GfxBackend>(&self, command_buffer_id: id::CommandBufferId) {
span!(_guard, TRACE, "CommandBuffer::destroy");
self.command_encoder_destroy::<B>(command_buffer_id)
}
@ -1960,11 +2007,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
device_id: id::DeviceId,
desc: &wgt::RenderBundleEncoderDescriptor,
) -> id::RenderBundleEncoderId {
span!(_guard, TRACE, "Device::create_render_bundle_encoder");
let encoder = command::RenderBundleEncoder::new(desc, device_id, None);
Box::into_raw(Box::new(encoder))
}
pub fn render_bundle_destroy<B: GfxBackend>(&self, render_bundle_id: id::RenderBundleId) {
span!(_guard, TRACE, "RenderBundle::destroy");
let hub = B::hub(self);
let mut token = Token::root();
@ -1989,6 +2038,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &pipeline::RenderPipelineDescriptor,
id_in: Input<G, id::RenderPipelineId>,
) -> Result<id::RenderPipelineId, pipeline::RenderPipelineError> {
span!(_guard, TRACE, "Device::create_render_pipeline");
let hub = B::hub(self);
let mut token = Token::root();
@ -2363,6 +2414,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn render_pipeline_destroy<B: GfxBackend>(&self, render_pipeline_id: id::RenderPipelineId) {
span!(_guard, TRACE, "RenderPipeline::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -2391,6 +2443,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc: &pipeline::ComputePipelineDescriptor,
id_in: Input<G, id::ComputePipelineId>,
) -> Result<id::ComputePipelineId, pipeline::ComputePipelineError> {
span!(_guard, TRACE, "Device::create_compute_pipeline");
let hub = B::hub(self);
let mut token = Token::root();
@ -2489,6 +2543,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&self,
compute_pipeline_id: id::ComputePipelineId,
) {
span!(_guard, TRACE, "ComputePipeline::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -2517,6 +2572,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
surface_id: id::SurfaceId,
desc: &wgt::SwapChainDescriptor,
) -> id::SwapChainId {
span!(_guard, TRACE, "Device::create_swap_chain");
fn validate_swap_chain_descriptor(
config: &mut hal::window::SwapchainConfig,
caps: &hal::window::SurfaceCapabilities,
@ -2644,6 +2701,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn device_poll<B: GfxBackend>(&self, device_id: id::DeviceId, force_wait: bool) {
span!(_guard, TRACE, "Device::poll");
let hub = B::hub(self);
let mut token = Token::root();
let callbacks = {
@ -2658,6 +2717,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
force_wait: bool,
callbacks: &mut Vec<BufferMapPendingCallback>,
) {
span!(_guard, TRACE, "Device::poll_devices");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -2687,6 +2748,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn device_destroy<B: GfxBackend>(&self, device_id: id::DeviceId) {
span!(_guard, TRACE, "Device::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let device = {
@ -2710,6 +2773,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
range: Range<BufferAddress>,
op: resource::BufferMapOperation,
) {
span!(_guard, TRACE, "Device::buffer_map_async");
let hub = B::hub(self);
let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
@ -2768,6 +2833,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offset: BufferAddress,
_size: Option<BufferSize>,
) -> *mut u8 {
span!(_guard, TRACE, "Device::buffer_get_mapped_range");
let hub = B::hub(self);
let mut token = Token::root();
let (buffer_guard, _) = hub.buffers.read(&mut token);
@ -2786,6 +2853,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn buffer_unmap<B: GfxBackend>(&self, buffer_id: id::BufferId) {
span!(_guard, TRACE, "Device::buffer_unmap");
let hub = B::hub(self);
let mut token = Token::root();

View File

@ -10,6 +10,7 @@ use crate::{
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token},
id,
resource::{BufferMapState, BufferUse, TextureUse},
span,
};
use gfx_memory::{Block, Heaps, MemoryBlock};
@ -130,6 +131,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
buffer_offset: wgt::BufferAddress,
data: &[u8],
) {
span!(_guard, TRACE, "Queue::write_buffer");
let hub = B::hub(self);
let mut token = Token::root();
let (mut device_guard, mut token) = hub.devices.write(&mut token);
@ -238,6 +241,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
data_layout: &wgt::TextureDataLayout,
size: &wgt::Extent3d,
) {
span!(_guard, TRACE, "Queue::write_texture");
let hub = B::hub(self);
let mut token = Token::root();
let (mut device_guard, mut token) = hub.devices.write(&mut token);
@ -365,6 +370,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
queue_id: id::QueueId,
command_buffer_ids: &[id::CommandBufferId],
) {
span!(_guard, TRACE, "Queue::submit");
let hub = B::hub(self);
let callbacks = {

View File

@ -15,6 +15,7 @@ use crate::{
instance::{Adapter, Instance, Surface},
pipeline::{ComputePipeline, RenderPipeline, ShaderModule},
resource::{Buffer, Sampler, Texture, TextureView},
span,
swap_chain::SwapChain,
Epoch, Index,
};
@ -577,6 +578,7 @@ pub struct Global<G: GlobalIdentityHandlerFactory> {
impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn new(name: &str, factory: G, backends: wgt::BackendBit) -> Self {
span!(_guard, TRACE, "Global::new");
Global {
instance: Instance::new(name, 1, backends),
surfaces: Registry::without_backend(&factory, "Surface"),

View File

@ -7,7 +7,7 @@ use crate::{
device::Device,
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
id::{AdapterId, DeviceId, SurfaceId},
power, LifeGuard, PrivateFeatures, Stored, MAX_BIND_GROUPS,
power, span, LifeGuard, PrivateFeatures, Stored, MAX_BIND_GROUPS,
};
use wgt::{Backend, BackendBit, DeviceDescriptor, PowerPreference, BIND_BUFFER_ALIGNMENT};
@ -147,6 +147,8 @@ pub struct Adapter<B: hal::Backend> {
impl<B: hal::Backend> Adapter<B> {
fn new(raw: hal::adapter::Adapter<B>, unsafe_extensions: wgt::UnsafeExtensions) -> Self {
span!(_guard, TRACE, "Adapter::new");
let adapter_features = raw.physical_device.features();
let mut extensions = wgt::Extensions::default() | wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS;
@ -295,6 +297,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
handle: &impl raw_window_handle::HasRawWindowHandle,
id_in: Input<G, SurfaceId>,
) -> SurfaceId {
span!(_guard, TRACE, "Instance::create_surface");
let surface = unsafe {
Surface {
#[cfg(any(
@ -337,6 +341,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe_extensions: wgt::UnsafeExtensions,
inputs: AdapterInputs<Input<G, AdapterId>>,
) -> Vec<AdapterId> {
span!(_guard, TRACE, "Instance::enumerate_adapters");
let instance = &self.instance;
let mut token = Token::root();
let mut adapters = Vec::new();
@ -415,6 +421,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe_extensions: wgt::UnsafeExtensions,
inputs: AdapterInputs<Input<G, AdapterId>>,
) -> Option<AdapterId> {
span!(_guard, TRACE, "Instance::pick_adapter");
let instance = &self.instance;
let mut token = Token::root();
let (surface_guard, mut token) = self.surfaces.read(&mut token);
@ -618,6 +626,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn adapter_get_info<B: GfxBackend>(&self, adapter_id: AdapterId) -> AdapterInfo {
span!(_guard, TRACE, "Adapter::get_info");
let hub = B::hub(self);
let mut token = Token::root();
let (adapter_guard, _) = hub.adapters.read(&mut token);
@ -626,6 +636,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn adapter_extensions<B: GfxBackend>(&self, adapter_id: AdapterId) -> wgt::Extensions {
span!(_guard, TRACE, "Adapter::extensions");
let hub = B::hub(self);
let mut token = Token::root();
let (adapter_guard, _) = hub.adapters.read(&mut token);
@ -635,6 +647,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn adapter_limits<B: GfxBackend>(&self, adapter_id: AdapterId) -> wgt::Limits {
span!(_guard, TRACE, "Adapter::limits");
let hub = B::hub(self);
let mut token = Token::root();
let (adapter_guard, _) = hub.adapters.read(&mut token);
@ -644,6 +658,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn adapter_capabilities<B: GfxBackend>(&self, adapter_id: AdapterId) -> wgt::Capabilities {
span!(_guard, TRACE, "Adapter::capabilities");
let hub = B::hub(self);
let mut token = Token::root();
let (adapter_guard, _) = hub.adapters.read(&mut token);
@ -653,6 +669,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn adapter_destroy<B: GfxBackend>(&self, adapter_id: AdapterId) {
span!(_guard, TRACE, "Adapter::destroy");
let hub = B::hub(self);
let mut token = Token::root();
let (mut guard, _) = hub.adapters.write(&mut token);
@ -679,6 +697,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
trace_path: Option<&std::path::Path>,
id_in: Input<G, DeviceId>,
) -> DeviceId {
span!(_guard, TRACE, "Adapter::request_device");
let hub = B::hub(self);
let mut token = Token::root();
let device = {

View File

@ -31,6 +31,7 @@ pub mod device;
pub mod hub;
pub mod id;
pub mod instance;
mod logging;
pub mod pipeline;
pub mod power;
pub mod resource;

View File

@ -0,0 +1,11 @@
#[macro_export]
macro_rules! span {
($guard_name:tt, $level:ident, $name:expr, $($fields:tt)*) => {
let span = tracing::span!(tracing::Level::$level, $name, $($fields)*);
let $guard_name = span.enter();
};
($guard_name:tt, $level:ident, $name:expr) => {
let span = tracing::span!(tracing::Level::$level, $name);
let $guard_name = span.enter();
};
}

View File

@ -38,7 +38,7 @@ use crate::{
conv,
hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Input, Token},
id::{DeviceId, SwapChainId, TextureViewId},
resource, LifeGuard, PrivateFeatures, Stored, SubmissionIndex,
resource, span, LifeGuard, PrivateFeatures, Stored, SubmissionIndex,
};
use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _};
@ -94,6 +94,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
swap_chain_id: SwapChainId,
view_id_in: Input<G, TextureViewId>,
) -> SwapChainOutput {
span!(_guard, TRACE, "SwapChain::get_next_texture");
let hub = B::hub(self);
let mut token = Token::root();
@ -177,6 +179,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
pub fn swap_chain_present<B: GfxBackend>(&self, swap_chain_id: SwapChainId) {
span!(_guard, TRACE, "SwapChain::present");
let hub = B::hub(self);
let mut token = Token::root();