Skip to content

Commit

Permalink
Add inital debug labels
Browse files Browse the repository at this point in the history
- bind group
- bind group layout
- command encoder
- texture
  • Loading branch information
aloucks committed Mar 20, 2020
1 parent cbc18c8 commit 3f6e7be
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
8 changes: 6 additions & 2 deletions examples/compute/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -124,7 +128,7 @@ int main(

WGPUCommandEncoderId encoder = wgpu_device_create_command_encoder(
device, &(WGPUCommandEncoderDescriptor){
.todo = 0
.label = "command encoder",
});

WGPUComputePassId command_pass =
Expand Down
4 changes: 3 additions & 1 deletion examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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] = {
Expand Down
6 changes: 5 additions & 1 deletion ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ typedef struct {
} WGPUBindGroupEntry;

typedef struct {
const char *label;
WGPUBindGroupLayoutId layout;
const WGPUBindGroupEntry *entries;
uintptr_t entries_length;
Expand All @@ -493,6 +494,7 @@ typedef struct {
} WGPUBindGroupLayoutEntry;

typedef struct {
const char *label;
const WGPUBindGroupLayoutEntry *entries;
uintptr_t entries_length;
} WGPUBindGroupLayoutDescriptor;
Expand All @@ -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;
Expand Down Expand Up @@ -671,6 +674,7 @@ typedef struct {
} WGPUSwapChainDescriptor;

typedef struct {
const char *label;
WGPUExtent3d size;
uint32_t array_layer_count;
uint32_t mip_level_count;
Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -113,6 +114,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,
Expand Down
51 changes: 38 additions & 13 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ impl<B: GfxBackend> Device<B> {
};

let mut buffer = unsafe { self.raw.create_buffer(desc.size, usage).unwrap() };
if let Some(label) = desc.label {
unsafe { self.raw.set_buffer_name(&mut buffer, label) };
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
Expand Down Expand Up @@ -398,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
Expand Down Expand Up @@ -913,10 +920,16 @@ impl<F: IdentityFilter<id::BindGroupLayoutId>> Global<F> {

let raw = unsafe {
let (device_guard, _) = hub.devices.read(&mut token);
device_guard[device_id]
let device = &device_guard[device_id];
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 {
Expand Down Expand Up @@ -1005,7 +1018,7 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
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
Expand All @@ -1021,6 +1034,13 @@ impl<F: IdentityFilter<id::BindGroupId>> Global<F> {
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);
{
Expand Down Expand Up @@ -1238,7 +1258,7 @@ impl<F: IdentityFilter<id::CommandEncoderId>> Global<F> {
pub fn device_create_command_encoder<B: GfxBackend>(
&self,
device_id: id::DeviceId,
_desc: &wgt::CommandEncoderDescriptor,
desc: &wgt::CommandEncoderDescriptor,
id_in: F::Input,
) -> id::CommandEncoderId {
let hub = B::hub(self);
Expand All @@ -1256,17 +1276,22 @@ impl<F: IdentityFilter<id::CommandEncoderId>> Global<F> {
.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>(
Expand Down
17 changes: 12 additions & 5 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,26 @@ bitflags::bitflags! {
}

#[repr(C)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct BufferDescriptor<'a> {
pub label: Option<&'a str>,
pub struct BufferDescriptor {
pub label: *const std::os::raw::c_char,
pub size: BufferAddress,
pub usage: BufferUsage,
}

#[repr(C)]
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
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 {
unsafe { std::mem::zeroed() }
}
}

pub type DynamicOffset = u32;
Expand Down Expand Up @@ -734,6 +740,7 @@ pub struct Extent3d {
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
pub struct TextureDescriptor {
pub label: *const std::os::raw::c_char,
pub size: Extent3d,
pub array_layer_count: u32,
pub mip_level_count: u32,
Expand Down

0 comments on commit 3f6e7be

Please sign in to comment.