diff --git a/blade-graphics/src/metal/command.rs b/blade-graphics/src/metal/command.rs index 5391678..b2d0f27 100644 --- a/blade-graphics/src/metal/command.rs +++ b/blade-graphics/src/metal/command.rs @@ -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(); @@ -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) {} @@ -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(); @@ -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); } diff --git a/blade-graphics/src/metal/mod.rs b/blade-graphics/src/metal/mod.rs index a15f0e6..b508f01 100644 --- a/blade-graphics/src/metal/mod.rs +++ b/blade-graphics/src/metal/mod.rs @@ -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, } @@ -194,7 +195,9 @@ pub struct CommandEncoder { raw: Option, name: String, queue: Arc>, - supports_dispatch_type: bool, + enable_debug_groups: bool, + enable_dispatch_type: bool, + has_open_debug_group: bool, timing_datas: Option>, timings: Vec<(String, time::Duration)>, } @@ -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); @@ -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, @@ -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(), } @@ -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 } }