Skip to content

Commit

Permalink
metal: profiling scopes, disable auto-capture
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Sep 25, 2024
1 parent 6856444 commit 5f2945f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
23 changes: 22 additions & 1 deletion blade-graphics/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ impl super::TimingData {
}

impl super::CommandEncoder {
fn begin_pass(&mut self, label: &str) {
if self.enable_debug_groups {
//HACK: close the previous group
if self.has_open_debug_group {
self.raw.as_mut().unwrap().pop_debug_group();
} else {
self.has_open_debug_group = true;
}
self.raw.as_mut().unwrap().push_debug_group(label);
}
}

pub(super) fn finish(&mut self) -> metal::CommandBuffer {
if self.has_open_debug_group {
self.raw.as_mut().unwrap().pop_debug_group();
}
self.raw.take().unwrap()
}

pub fn start(&mut self) {
if let Some(ref mut td_array) = self.timing_datas {
self.timings.clear();
Expand All @@ -121,6 +140,7 @@ impl super::CommandEncoder {
}
cmd_buf.to_owned()
}));
self.has_open_debug_group = false;
}

pub fn init_texture(&mut self, _texture: super::Texture) {}
Expand All @@ -130,6 +150,7 @@ impl super::CommandEncoder {
}

pub fn transfer(&mut self, label: &str) -> super::TransferCommandEncoder {
self.begin_pass(label);
let raw = objc::rc::autoreleasepool(|| {
let descriptor = metal::BlitPassDescriptor::new();

Expand Down Expand Up @@ -185,7 +206,7 @@ impl super::CommandEncoder {
pub fn compute(&mut self, label: &str) -> super::ComputeCommandEncoder {
let raw = objc::rc::autoreleasepool(|| {
let descriptor = metal::ComputePassDescriptor::new();
if self.supports_dispatch_type {
if self.enable_dispatch_type {
descriptor.set_dispatch_type(metal::MTLDispatchType::Concurrent);
}

Expand Down
19 changes: 13 additions & 6 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl Frame {
#[derive(Debug, Clone)]
struct PrivateInfo {
language_version: metal::MTLLanguageVersion,
supports_dispatch_type: bool,
enable_debug_groups: bool,
enable_dispatch_type: bool,
timestamp_counter_set: Option<metal::CounterSet>,
}

Expand Down Expand Up @@ -194,7 +195,9 @@ pub struct CommandEncoder {
raw: Option<metal::CommandBuffer>,
name: String,
queue: Arc<Mutex<metal::CommandQueue>>,
supports_dispatch_type: bool,
enable_debug_groups: bool,
enable_dispatch_type: bool,
has_open_debug_group: bool,
timing_datas: Option<Box<[TimingData]>>,
timings: Vec<(String, time::Duration)>,
}
Expand Down Expand Up @@ -417,7 +420,8 @@ impl Context {
.ok_or(super::NotSupportedError::NoSupportedDeviceFound)?;
let queue = device.new_command_queue();

let capture = if desc.capture {
let auto_capture_everything = false;
let capture = if desc.capture && auto_capture_everything {
objc::rc::autoreleasepool(|| {
let capture_manager = metal::CaptureManager::shared();
let default_capture_scope = capture_manager.new_capture_scope_with_device(&device);
Expand Down Expand Up @@ -461,7 +465,8 @@ impl Context {
info: PrivateInfo {
//TODO: determine based on OS version
language_version: metal::MTLLanguageVersion::V2_4,
supports_dispatch_type: true,
enable_debug_groups: desc.capture,
enable_dispatch_type: true,
timestamp_counter_set,
},
device_information,
Expand Down Expand Up @@ -559,7 +564,9 @@ impl crate::traits::CommandDevice for Context {
raw: None,
name: desc.name.to_string(),
queue: Arc::clone(&self.queue),
supports_dispatch_type: self.info.supports_dispatch_type,
enable_debug_groups: self.info.enable_debug_groups,
enable_dispatch_type: self.info.enable_dispatch_type,
has_open_debug_group: false,
timing_datas,
timings: Vec::new(),
}
Expand All @@ -568,7 +575,7 @@ impl crate::traits::CommandDevice for Context {
fn destroy_command_encoder(&self, _command_encoder: &mut CommandEncoder) {}

fn submit(&self, encoder: &mut CommandEncoder) -> SyncPoint {
let cmd_buf = encoder.raw.take().unwrap();
let cmd_buf = encoder.finish();
cmd_buf.commit();
SyncPoint { cmd_buf }
}
Expand Down

0 comments on commit 5f2945f

Please sign in to comment.