Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 9ed9987

Browse files
committed
Add labels to mapped descriptors where possible
1 parent ab86d7c commit 9ed9987

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

src/backend/web.rs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ pub(crate) async fn request_device_and_queue(
6363
) -> (DeviceId, QueueId) {
6464
let device_promise = match desc {
6565
Some(d) => {
66-
let mut mapped_descriptor = web_sys::GpuDeviceDescriptor::new();
67-
// TODO: Extensions
66+
let mut mapped_desc = web_sys::GpuDeviceDescriptor::new();
67+
// TODO: label, extensions
6868
let mut mapped_limits = web_sys::GpuLimits::new();
6969
mapped_limits.max_bind_groups(d.limits.max_bind_groups);
70-
mapped_descriptor.limits(&mapped_limits);
71-
adapter.request_device_with_descriptor(&mapped_descriptor)
70+
mapped_desc.limits(&mapped_limits);
71+
adapter.request_device_with_descriptor(&mapped_desc)
7272
}
7373
None => adapter.request_device(),
7474
};
@@ -82,6 +82,7 @@ pub(crate) async fn request_device_and_queue(
8282

8383
pub(crate) fn create_shader_module(device: &DeviceId, spv: &[u32]) -> ShaderModuleId {
8484
let desc = web_sys::GpuShaderModuleDescriptor::new(&js_sys::Uint32Array::from(spv));
85+
// TODO: label
8586
device.create_shader_module(&desc)
8687
}
8788

@@ -150,7 +151,10 @@ pub(crate) fn create_bind_group_layout(
150151
})
151152
.collect::<js_sys::Array>();
152153

153-
let mapped_desc = web_sys::GpuBindGroupLayoutDescriptor::new(&mapped_bindings);
154+
let mut mapped_desc = web_sys::GpuBindGroupLayoutDescriptor::new(&mapped_bindings);
155+
if let Some(label) = desc.label {
156+
mapped_desc.label(label);
157+
}
154158
device.create_bind_group_layout(&mapped_desc)
155159
}
156160

@@ -179,7 +183,10 @@ pub(crate) fn create_bind_group(device: &DeviceId, desc: &BindGroupDescriptor) -
179183
})
180184
.collect::<js_sys::Array>();
181185

182-
let mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &desc.layout.id);
186+
let mut mapped_desc = web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &desc.layout.id);
187+
if let Some(label) = desc.label {
188+
mapped_desc.label(label);
189+
}
183190
device.create_bind_group(&mapped_desc)
184191
}
185192

@@ -193,6 +200,7 @@ pub(crate) fn create_pipeline_layout(
193200
.map(|bgl| bgl.id.clone())
194201
.collect::<js_sys::Array>();
195202
let mapped_desc = web_sys::GpuPipelineLayoutDescriptor::new(&temp_layouts);
203+
// TODO: label
196204
device.create_pipeline_layout(&mapped_desc)
197205
}
198206

@@ -591,6 +599,8 @@ pub(crate) fn create_render_pipeline(
591599
&mapped_vertex_stage,
592600
);
593601

602+
// TODO: label
603+
594604
if let Some(ref frag) = desc.fragment_stage {
595605
mapped_desc.fragment_stage(&map_stage_descriptor(frag));
596606
}
@@ -618,7 +628,7 @@ pub(crate) fn create_compute_pipeline(
618628
let mapped_compute_stage = map_stage_descriptor(&desc.compute_stage);
619629
let mapped_desc =
620630
web_sys::GpuComputePipelineDescriptor::new(&desc.layout.id, &mapped_compute_stage);
621-
631+
// TODO: label
622632
device.create_compute_pipeline(&mapped_desc)
623633
}
624634

@@ -633,7 +643,10 @@ pub(crate) fn device_create_buffer_mapped<'a>(
633643
device: &DeviceId,
634644
desc: &BufferDescriptor,
635645
) -> crate::CreateBufferMapped<'a> {
636-
let mapped_desc = web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
646+
let mut mapped_desc = web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
647+
if let Some(label) = desc.label {
648+
mapped_desc.label(label);
649+
}
637650
unsafe {
638651
let pair = device.create_buffer_mapped(&mapped_desc);
639652
let id = pair.get(0).into();
@@ -690,7 +703,10 @@ pub(crate) fn buffer_drop(_buffer: &BufferId) {
690703
}
691704

692705
pub(crate) fn device_create_buffer(device: &DeviceId, desc: &BufferDescriptor) -> crate::Buffer {
693-
let mapped_desc = web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
706+
let mut mapped_desc = web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
707+
if let Some(label) = desc.label {
708+
mapped_desc.label(label);
709+
}
694710
crate::Buffer {
695711
id: device.create_buffer(&mapped_desc),
696712
detail: (),
@@ -703,6 +719,9 @@ pub(crate) fn device_create_texture(device: &DeviceId, desc: &TextureDescriptor)
703719
&map_extent_3d(desc.size),
704720
desc.usage.bits(),
705721
);
722+
if let Some(label) = desc.label {
723+
mapped_desc.label(label);
724+
}
706725
mapped_desc.dimension(map_texture_dimension(desc.dimension));
707726
mapped_desc.mip_level_count(desc.mip_level_count);
708727
mapped_desc.sample_count(desc.sample_count);
@@ -711,6 +730,7 @@ pub(crate) fn device_create_texture(device: &DeviceId, desc: &TextureDescriptor)
711730

712731
pub(crate) fn device_create_sampler(device: &DeviceId, desc: &SamplerDescriptor) -> SamplerId {
713732
let mut mapped_desc = web_sys::GpuSamplerDescriptor::new();
733+
// TODO: label
714734
mapped_desc.address_mode_u(map_address_mode(desc.address_mode_u));
715735
mapped_desc.address_mode_v(map_address_mode(desc.address_mode_v));
716736
mapped_desc.address_mode_w(map_address_mode(desc.address_mode_w));
@@ -727,9 +747,12 @@ pub(crate) fn device_create_sampler(device: &DeviceId, desc: &SamplerDescriptor)
727747

728748
pub(crate) fn create_command_encoder(
729749
device: &DeviceId,
730-
_desc: &CommandEncoderDescriptor,
750+
desc: &CommandEncoderDescriptor,
731751
) -> CommandEncoderId {
732-
let mapped_desc = web_sys::GpuCommandEncoderDescriptor::new();
752+
let mut mapped_desc = web_sys::GpuCommandEncoderDescriptor::new();
753+
if let Some(label) = desc.label {
754+
mapped_desc.label(label);
755+
}
733756
device.create_command_encoder_with_descriptor(&mapped_desc)
734757
}
735758

@@ -790,7 +813,10 @@ pub(crate) fn command_encoder_copy_texture_to_texture(
790813
}
791814

792815
pub(crate) fn begin_compute_pass(command_encoder: &CommandEncoderId) -> ComputePassId {
793-
let mapped_desc = web_sys::GpuComputePassDescriptor::new();
816+
let mut mapped_desc = web_sys::GpuComputePassDescriptor::new();
817+
if let Some(ref label) = command_encoder.label() {
818+
mapped_desc.label(label);
819+
}
794820
command_encoder.begin_compute_pass_with_descriptor(&mapped_desc)
795821
}
796822

@@ -833,7 +859,10 @@ pub(crate) fn compute_pass_end_pass(compute_pass: &ComputePassId) {
833859
}
834860

835861
pub(crate) fn command_encoder_finish(command_encoder: &CommandEncoderId) -> CommandBufferId {
836-
let mapped_desc = web_sys::GpuCommandBufferDescriptor::new();
862+
let mut mapped_desc = web_sys::GpuCommandBufferDescriptor::new();
863+
if let Some(ref label) = command_encoder.label() {
864+
mapped_desc.label(label);
865+
}
837866
command_encoder.finish_with_descriptor(&mapped_desc)
838867
}
839868

@@ -996,7 +1025,9 @@ pub(crate) fn command_encoder_begin_render_pass<'a>(
9961025
})
9971026
.collect::<js_sys::Array>();
9981027

999-
let mut mapped = web_sys::GpuRenderPassDescriptor::new(&mapped_color_attachments);
1028+
let mut mapped_desc = web_sys::GpuRenderPassDescriptor::new(&mapped_color_attachments);
1029+
1030+
// TODO: label
10001031

10011032
if let Some(dsa) = &desc.depth_stencil_attachment {
10021033
let mapped_depth_stencil_attachment =
@@ -1014,10 +1045,10 @@ pub(crate) fn command_encoder_begin_render_pass<'a>(
10141045
map_store_op(dsa.stencil_store_op),
10151046
);
10161047

1017-
mapped.depth_stencil_attachment(&mapped_depth_stencil_attachment);
1048+
mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment);
10181049
}
10191050

1020-
command_encoder.begin_render_pass(&mapped)
1051+
command_encoder.begin_render_pass(&mapped_desc)
10211052
}
10221053

10231054
pub(crate) fn render_pass_set_pipeline(
@@ -1154,6 +1185,7 @@ pub(crate) fn texture_create_view(
11541185
mapped_desc.dimension(map_texture_view_dimension(d.dimension));
11551186
mapped_desc.format(map_texture_format(d.format));
11561187
mapped_desc.mip_level_count(d.level_count);
1188+
// TODO: label
11571189
texture.create_view_with_descriptor(&mapped_desc)
11581190
}
11591191
None => texture.create_view(),

0 commit comments

Comments
 (0)