Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Add Tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Jun 22, 2020
1 parent 68461b1 commit 1ca2d04
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,39 @@ keywords = ["graphics"]
license = "MPL-2.0"
exclude = ["etc/**/*", "examples/**/*", "tests/**/*", "Cargo.lock", "target/**/*"]

[package.metadata.docs.rs]
all-features = true

[lib]

[features]
default = []
trace = ["wgc/trace"]
subscriber = ["wgc/subscriber"]
# Make Vulkan backend available on platforms where it is by default not, e.g. macOS
vulkan = ["wgc/gfx-backend-vulkan"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc]
package = "wgpu-core"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "c7be94047d156a3bde88d03cd5c229bedb6efe62"
git = "https://github.com/cwfitzgerald/wgpu"
rev = "c1f0021a05d608fbb7f91fba352024a89f65c6d0"
features = ["raw-window-handle"]

[dependencies.wgt]
package = "wgpu-types"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "c7be94047d156a3bde88d03cd5c229bedb6efe62"
git = "https://github.com/cwfitzgerald/wgpu"
rev = "c1f0021a05d608fbb7f91fba352024a89f65c6d0"

[dependencies]
arrayvec = "0.5"
futures = "0.3"
parking_lot = "0.10"
raw-window-handle = "0.3"
smallvec = "1"
tracing = { version = "0.1", default-features = false, features = ["std"] }
typed-arena = "2.0.1"
raw-window-handle = "0.3"
parking_lot = "0.10"

#Note: we may consider switching this to "dev-dependencies" if users
# want to opt into X11 explicitly.
Expand Down
12 changes: 9 additions & 3 deletions examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(

#[allow(dead_code)]
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
use std::mem::size_of;
use std::slice::from_raw_parts;
use std::{mem::size_of, slice::from_raw_parts};

unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::<T>()) }
}
Expand Down Expand Up @@ -191,7 +190,7 @@ pub fn run<E: Example>(title: &str) {
let event_loop = EventLoop::new();
let mut builder = winit::window::WindowBuilder::new();
builder = builder.with_title(title);
#[cfg(windows_OFF)] //TODO
#[cfg(windows_OFF)] // TODO
{
use winit::platform::windows::WindowBuilderExtWindows;
builder = builder.with_no_redirection_bitmap(true);
Expand All @@ -201,6 +200,13 @@ pub fn run<E: Example>(title: &str) {
#[cfg(not(target_arch = "wasm32"))]
{
env_logger::init();

#[cfg(feature = "subscriber")]
{
let chrome_tracing_dir = std::env::var("WGPU_CHROME_TRACING");
wgpu::util::initialize_default_subscriber(chrome_tracing_dir.ok());
};

futures::executor::block_on(run_async::<E>(event_loop, window));
}
#[cfg(target_arch = "wasm32")]
Expand Down
11 changes: 8 additions & 3 deletions examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ fn main() {
#[cfg(not(target_arch = "wasm32"))]
{
env_logger::init();

#[cfg(feature = "subscriber")]
{
let chrome_tracing_dir = std::env::var("WGPU_CHROME_TRACING");
wgpu::util::initialize_default_subscriber(chrome_tracing_dir.ok());
};

futures::executor::block_on(run());
}
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -165,9 +172,7 @@ mod tests {

#[test]
fn test_multithreaded_compute() {
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use std::{sync::mpsc, thread, time::Duration};

let thread_count = 8;

Expand Down
7 changes: 7 additions & 0 deletions examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ fn main() {
#[cfg(not(target_arch = "wasm32"))]
{
env_logger::init();

#[cfg(feature = "subscriber")]
{
let chrome_tracing_dir = std::env::var("WGPU_CHROME_TRACING");
wgpu::util::initialize_default_subscriber(chrome_tracing_dir.ok());
};

// Temporarily avoid srgb formats for the swapchain on the web
futures::executor::block_on(run(event_loop, window, wgpu::TextureFormat::Bgra8UnormSrgb));
}
Expand Down
7 changes: 7 additions & 0 deletions src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ mod pass_impl {
&mut self,
render_bundles: I,
) {
wgc::span!(_guard, TRACE, "RenderPass::execute_bundles wrapper");
let temp_render_bundles = render_bundles.cloned().collect::<SmallVec<[_; 4]>>();
unsafe {
wgpu_render_pass_execute_bundles(
Expand Down Expand Up @@ -450,6 +451,7 @@ impl crate::Context for Context {
device: &Self::DeviceId,
desc: &BindGroupDescriptor,
) -> Self::BindGroupId {
wgc::span!(_guard, TRACE, "Device::create_bind_group wrapper");
use wgc::binding_model as bm;

let texture_view_arena: Arena<wgc::id::TextureViewId> = Arena::new();
Expand Down Expand Up @@ -499,6 +501,7 @@ impl crate::Context for Context {
device: &Self::DeviceId,
desc: &PipelineLayoutDescriptor,
) -> Self::PipelineLayoutId {
wgc::span!(_guard, TRACE, "Device::create_pipeline_layout wrapper");
//TODO: avoid allocation here
let temp_layouts = desc
.bind_group_layouts
Expand All @@ -522,6 +525,7 @@ impl crate::Context for Context {
device: &Self::DeviceId,
desc: &RenderPipelineDescriptor,
) -> Self::RenderPipelineId {
wgc::span!(_guard, TRACE, "Device::create_render_pipeline wrapper");
use wgc::pipeline as pipe;

let vertex_entry_point = CString::new(desc.vertex_stage.entry_point).unwrap();
Expand Down Expand Up @@ -697,6 +701,8 @@ impl crate::Context for Context {
mode: MapMode,
range: Range<wgt::BufferAddress>,
) -> Self::MapAsyncFuture {
wgc::span!(_guard, TRACE, "Buffer::buffer_map_async wrapper");

let (future, completion) = native_gpu_future::new_gpu_future();

extern "C" fn buffer_map_future_wrapper(
Expand Down Expand Up @@ -911,6 +917,7 @@ impl crate::Context for Context {
encoder: &Self::CommandEncoderId,
desc: &crate::RenderPassDescriptor<'a, '_>,
) -> Self::RenderPassId {
wgc::span!(_guard, TRACE, "CommandEncoder::begin_render_pass wrapper");
let colors = desc
.color_attachments
.iter()
Expand Down
7 changes: 5 additions & 2 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(all(not(target_arch = "wasm32"), feature = "subscriber"))]
pub use wgc::logging::subscriber::{initialize_default_subscriber, ChromeTracingLayer};

/// Wrapper aligning contents to at least 4.
#[repr(align(4))]
pub struct WordAligned<Bytes: ?Sized>(pub Bytes);
Expand All @@ -15,8 +18,8 @@ pub fn make_spirv<'a>(data: &'a [u8]) -> super::ShaderModuleSource<'a> {
const MAGIC_NUMBER: u32 = 0x0723_0203;

let (pre, words, post) = unsafe { data.align_to::<u32>() };
assert_eq!(pre, &[], "data offset is not aligned to words!");
assert_eq!(post, &[], "data size is not aligned to words!");
assert!(pre.is_empty(), "data offset is not aligned to words!");
assert!(post.is_empty(), "data size is not aligned to words!");
assert_eq!(
words[0], MAGIC_NUMBER,
"wrong magic word {:x}. Make sure you are using a binary SPIRV file.",
Expand Down

0 comments on commit 1ca2d04

Please # to comment.