528: Add buffer debug labels r=kvark a=aloucks

Related #404 

@kvark Is this what you had in mind? The webgpu headers have labels on all the descriptor structs and I didn't see any specific functions for altering/adding labels after creation. I'll add the rest if this looks good to you. 

I also went looking for [command buffer marker support](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/chap41.html#debugging-command-buffer-markers) in [gfx-hal](https://docs.rs/gfx-hal/0.4.1/gfx_hal/command/trait.CommandBuffer.html) so that I could add [group labels and markers](https://gpuweb.github.io/gpuweb/#dom-gpuprogrammablepassencoder-pushdebuggroup).  Is this functionality absent in `hal` or did I miss it?





Co-authored-by: Aaron Loucks <aloucks@cofront.net>
This commit is contained in:
bors[bot]andAaron Loucks authored and GitHub committed 2020-03-27 00:27:52 +00:00
commit 86981d9a80
6 files changed
+68 -19

No files matched your search

+6 -2
View File
@@ -69,6 +69,7 @@ int main(
WGPUBufferId buffer = wgpu_device_create_buffer_mapped(device,
&(WGPUBufferDescriptor){
.label = "buffer",
.size = size,
.usage = WGPUBufferUsage_STORAGE | WGPUBufferUsage_MAP_READ},
&staging_memory);
@@ -80,6 +81,7 @@ int main(
WGPUBindGroupLayoutId bind_group_layout =
wgpu_device_create_bind_group_layout(device,
&(WGPUBindGroupLayoutDescriptor){
.label = "bind group layout",
.entries = &(WGPUBindGroupLayoutEntry){
.binding = 0,
.visibility = WGPUShaderStage_COMPUTE,
@@ -94,7 +96,9 @@ int main(
.offset = 0}}};
WGPUBindGroupId bind_group = wgpu_device_create_bind_group(device,
&(WGPUBindGroupDescriptor){.layout = bind_group_layout,
&(WGPUBindGroupDescriptor){
.label = "bind group",
.layout = bind_group_layout,
.entries = &(WGPUBindGroupEntry){
.binding = 0,
.resource = resource},
@@ -124,7 +128,7 @@ int main(
WGPUCommandEncoderId encoder = wgpu_device_create_command_encoder(
device, &(WGPUCommandEncoderDescriptor){
.todo = 0
.label = "command encoder",
});
WGPUComputePassId command_pass =
+3 -1
View File
@@ -79,12 +79,14 @@ int main() {
WGPUBindGroupLayoutId bind_group_layout =
wgpu_device_create_bind_group_layout(device,
&(WGPUBindGroupLayoutDescriptor){
.label = "bind group layout",
.entries = NULL,
.entries_length = 0,
});
WGPUBindGroupId bind_group =
wgpu_device_create_bind_group(device,
&(WGPUBindGroupDescriptor){
.label = "bind group",
.layout = bind_group_layout,
.entries = NULL,
.entries_length = 0,
@@ -237,7 +239,7 @@ int main() {
}
WGPUCommandEncoderId cmd_encoder = wgpu_device_create_command_encoder(
device, &(WGPUCommandEncoderDescriptor){.todo = 0});
device, &(WGPUCommandEncoderDescriptor){.label = "command encoder"});
WGPURenderPassColorAttachmentDescriptor
color_attachments[ATTACHMENTS_LENGTH] = {
+5 -1
View File
@@ -470,6 +470,7 @@ typedef struct {
} WGPUBindGroupEntry;
typedef struct {
const char *label;
WGPUBindGroupLayoutId layout;
const WGPUBindGroupEntry *entries;
uintptr_t entries_length;
@@ -493,6 +494,7 @@ typedef struct {
} WGPUBindGroupLayoutEntry;
typedef struct {
const char *label;
const WGPUBindGroupLayoutEntry *entries;
uintptr_t entries_length;
} WGPUBindGroupLayoutDescriptor;
@@ -511,12 +513,13 @@ typedef uint32_t WGPUBufferUsage;
#define WGPUBufferUsage_NONE 0
typedef struct {
const char *label;
WGPUBufferAddress size;
WGPUBufferUsage usage;
} WGPUBufferDescriptor;
typedef struct {
uint32_t todo;
const char *label;
} WGPUCommandEncoderDescriptor;
typedef uint64_t WGPUId_PipelineLayout_Dummy;
@@ -671,6 +674,7 @@ typedef struct {
} WGPUSwapChainDescriptor;
typedef struct {
const char *label;
WGPUExtent3d size;
uint32_t array_layer_count;
uint32_t mip_level_count;
+2
View File
@@ -59,6 +59,7 @@ pub struct BindGroupLayoutEntry {
#[repr(C)]
#[derive(Debug)]
pub struct BindGroupLayoutDescriptor {
pub label: *const std::os::raw::c_char,
pub entries: *const BindGroupLayoutEntry,
pub entries_length: usize,
}
@@ -115,6 +116,7 @@ pub struct BindGroupEntry {
#[repr(C)]
#[derive(Debug)]
pub struct BindGroupDescriptor {
pub label: *const std::os::raw::c_char,
pub layout: BindGroupLayoutId,
pub entries: *const BindGroupEntry,
pub entries_length: usize,
+38 -11
View File
@@ -321,6 +321,12 @@ impl<B: GfxBackend> Device<B> {
};
let mut buffer = unsafe { self.raw.create_buffer(desc.size, usage).unwrap() };
if !desc.label.is_null() {
unsafe {
let label = ffi::CStr::from_ptr(desc.label).to_string_lossy();
self.raw.set_buffer_name(&mut buffer, &label)
};
}
let requirements = unsafe { self.raw.get_buffer_requirements(&buffer) };
let memory = self
.mem_allocator
@@ -395,16 +401,20 @@ impl<B: GfxBackend> Device<B> {
// TODO: 2D arrays, cubemap arrays
let mut image = unsafe {
self.raw.create_image(
let mut image = self.raw.create_image(
kind,
desc.mip_level_count as hal::image::Level,
format,
hal::image::Tiling::Optimal,
usage,
view_capabilities,
)
}
.unwrap();
).unwrap();
if !desc.label.is_null() {
let label = ffi::CStr::from_ptr(desc.label).to_string_lossy();
self.raw.set_image_name(&mut image, &label);
}
image
};
let requirements = unsafe { self.raw.get_image_requirements(&image) };
let memory = self
@@ -904,10 +914,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let raw = unsafe {
device
let mut raw_layout = device
.raw
.create_descriptor_set_layout(&raw_bindings, &[])
.unwrap()
.unwrap();
if !desc.label.is_null() {
let label = ffi::CStr::from_ptr(desc.label).to_string_lossy();
device.raw.set_descriptor_set_layout_name(&mut raw_layout, &label);
}
raw_layout
};
let layout = binding_model::BindGroupLayout {
@@ -1006,7 +1021,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
unsafe { slice::from_raw_parts(desc.entries, desc.entries_length as usize) };
assert_eq!(entries.len(), bind_group_layout.entries.len());
let desc_set = unsafe {
let mut desc_set = unsafe {
let mut desc_sets = ArrayVec::<[_; 1]>::new();
device
.desc_allocator
@@ -1022,6 +1037,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc_sets.pop().unwrap()
};
if !desc.label.is_null() {
unsafe {
let label = ffi::CStr::from_ptr(desc.label).to_string_lossy();
device.raw.set_descriptor_set_name(desc_set.raw_mut(), &label);
}
}
// fill out the descriptors
let mut used = TrackerSet::new(B::VARIANT);
{
@@ -1243,7 +1265,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn device_create_command_encoder<B: GfxBackend>(
&self,
device_id: id::DeviceId,
_desc: &wgt::CommandEncoderDescriptor,
desc: &wgt::CommandEncoderDescriptor,
id_in: Input<G, id::CommandEncoderId>,
) -> id::CommandEncoderId {
let hub = B::hub(self);
@@ -1261,17 +1283,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.lock_life(&mut token)
.lowest_active_submission();
let mut comb = device
let mut command_buffer = device
.com_allocator
.allocate(dev_stored, &device.raw, device.features, lowest_active_index);
unsafe {
comb.raw.last_mut().unwrap().begin_primary(
let raw_command_buffer = command_buffer.raw.last_mut().unwrap();
if !desc.label.is_null() {
let label = ffi::CStr::from_ptr(desc.label).to_string_lossy();
device.raw.set_command_buffer_name(raw_command_buffer, &label);
}
raw_command_buffer.begin_primary(
hal::command::CommandBufferFlags::ONE_TIME_SUBMIT,
);
}
hub.command_buffers
.register_identity(id_in, comb, &mut token)
.register_identity(id_in, command_buffer, &mut token)
}
pub fn command_encoder_destroy<B: GfxBackend>(
+14 -4
View File
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::{io, slice};
use std::{io, slice, ptr};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
#[cfg(feature = "peek-poke")]
@@ -536,19 +536,28 @@ bitflags::bitflags! {
}
#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct BufferDescriptor {
pub label: *const std::os::raw::c_char,
pub size: BufferAddress,
pub usage: BufferUsage,
}
#[repr(C)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CommandEncoderDescriptor {
// MSVC doesn't allow zero-sized structs
// We can remove this when we actually have a field
pub todo: u32,
// pub todo: u32,
pub label: *const std::os::raw::c_char,
}
impl Default for CommandEncoderDescriptor {
fn default() -> CommandEncoderDescriptor {
CommandEncoderDescriptor {
label: ptr::null(),
}
}
}
pub type DynamicOffset = u32;
@@ -734,6 +743,7 @@ pub struct Extent3d {
#[repr(C)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct TextureDescriptor {
pub label: *const std::os::raw::c_char,
pub size: Extent3d,
pub array_layer_count: u32,
pub mip_level_count: u32,