From 36804705732819b962dcb1f8cbb705128ea6dd0f Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Wed, 1 Sep 2021 15:54:44 -0400 Subject: [PATCH] Implement Debug Markers for Vulkan --- wgpu-hal/src/vulkan/command.rs | 22 ++++++++++++++++++++-- wgpu-hal/src/vulkan/device.rs | 1 + wgpu-hal/src/vulkan/mod.rs | 3 +++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/vulkan/command.rs b/wgpu-hal/src/vulkan/command.rs index 02a1a29b8..b0c9960d3 100644 --- a/wgpu-hal/src/vulkan/command.rs +++ b/wgpu-hal/src/vulkan/command.rs @@ -62,6 +62,9 @@ impl crate::CommandEncoder for super::CommandEncoder { label.unwrap_or_default(), ); + // Reset this in case the last renderpass was never ended. + self.rpass_debug_marker_active = false; + let vk_info = vk::CommandBufferBeginInfo::builder() .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT) .build(); @@ -427,6 +430,11 @@ impl crate::CommandEncoder for super::CommandEncoder { vk_info = vk_info.push_next(&mut vk_attachment_info); } + if let Some(label) = desc.label { + self.begin_debug_marker(label); + self.rpass_debug_marker_active = true; + } + self.device .raw .cmd_set_viewport(self.active, 0, &vk_viewports); @@ -441,6 +449,10 @@ impl crate::CommandEncoder for super::CommandEncoder { } unsafe fn end_render_pass(&mut self) { self.device.raw.cmd_end_render_pass(self.active); + if self.rpass_debug_marker_active { + self.end_debug_marker(); + self.rpass_debug_marker_active = false; + } } unsafe fn set_bind_group( @@ -703,10 +715,16 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn begin_compute_pass(&mut self, desc: &crate::ComputePassDescriptor) { self.bind_point = vk::PipelineBindPoint::COMPUTE; - self.begin_debug_marker(desc.label.unwrap_or_default()); + if let Some(label) = desc.label { + self.begin_debug_marker(label); + self.rpass_debug_marker_active = true; + } } unsafe fn end_compute_pass(&mut self) { - self.end_debug_marker(); + if self.rpass_debug_marker_active { + self.end_debug_marker(); + self.rpass_debug_marker_active = false + } } unsafe fn set_compute_pipeline(&mut self, pipeline: &super::ComputePipeline) { diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 619dffb7a..6d84a7d4a 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -868,6 +868,7 @@ impl crate::Device for super::Device { temp: super::Temp::default(), free: Vec::new(), discarded: Vec::new(), + rpass_debug_marker_active: false, }) } unsafe fn destroy_command_encoder(&self, cmd_encoder: super::CommandEncoder) { diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index 9dc3546a8..ddb350c60 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -335,6 +335,9 @@ pub struct CommandEncoder { temp: Temp, free: Vec, discarded: Vec, + /// If this is true, the active renderpass enabled a debug span, + /// and needs to be disabled on renderpass close. + rpass_debug_marker_active: bool, } pub struct CommandBuffer {