Remove gfx_select.

This commit is contained in:
Andreas Reich 2024-08-06 23:17:47 +02:00
parent 9794f33823
commit 0287eaf022
16 changed files with 431 additions and 640 deletions

View File

@ -21,7 +21,7 @@ impl Resource for WebGpuBindGroupLayout {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.bind_group_layout_drop(self.1)); self.0.bind_group_layout_drop(self.1);
} }
} }
@ -35,7 +35,7 @@ impl Resource for WebGpuBindGroup {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.bind_group_drop(self.1)); self.0.bind_group_drop(self.1);
} }
} }
@ -191,7 +191,7 @@ pub fn op_webgpu_create_bind_group_layout(
entries: Cow::from(entries), entries: Cow::from(entries),
}; };
gfx_put!(device => instance.device_create_bind_group_layout( gfx_put!(instance.device_create_bind_group_layout(
device, device,
&descriptor, &descriptor,
None None
@ -226,7 +226,7 @@ pub fn op_webgpu_create_pipeline_layout(
push_constant_ranges: Default::default(), push_constant_ranges: Default::default(),
}; };
gfx_put!(device => instance.device_create_pipeline_layout( gfx_put!(instance.device_create_pipeline_layout(
device, device,
&descriptor, &descriptor,
None None
@ -305,7 +305,7 @@ pub fn op_webgpu_create_bind_group(
entries: Cow::from(entries), entries: Cow::from(entries),
}; };
gfx_put!(device => instance.device_create_bind_group( gfx_put!(instance.device_create_bind_group(
device, device,
&descriptor, &descriptor,
None None

View File

@ -27,7 +27,7 @@ impl Resource for WebGpuBuffer {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.buffer_drop(self.1)); self.0.buffer_drop(self.1);
} }
} }
@ -62,7 +62,7 @@ pub fn op_webgpu_create_buffer(
mapped_at_creation, mapped_at_creation,
}; };
gfx_put!(device => instance.device_create_buffer( gfx_put!(instance.device_create_buffer(
device, device,
&descriptor, &descriptor,
None None
@ -97,20 +97,21 @@ pub async fn op_webgpu_buffer_get_map_async(
}); });
// TODO(lucacasonato): error handling // TODO(lucacasonato): error handling
let maybe_err = gfx_select!(buffer => instance.buffer_map_async( let maybe_err = instance
buffer, .buffer_map_async(
offset, buffer,
Some(size), offset,
wgpu_core::resource::BufferMapOperation { Some(size),
host: match mode { wgpu_core::resource::BufferMapOperation {
1 => wgpu_core::device::HostMap::Read, host: match mode {
2 => wgpu_core::device::HostMap::Write, 1 => wgpu_core::device::HostMap::Read,
_ => unreachable!(), 2 => wgpu_core::device::HostMap::Write,
_ => unreachable!(),
},
callback: Some(wgpu_core::resource::BufferMapCallback::from_rust(callback)),
}, },
callback: Some(wgpu_core::resource::BufferMapCallback::from_rust(callback)), )
} .err();
))
.err();
if maybe_err.is_some() { if maybe_err.is_some() {
return Ok(WebGpuResult::maybe_err(maybe_err)); return Ok(WebGpuResult::maybe_err(maybe_err));
@ -124,7 +125,8 @@ pub async fn op_webgpu_buffer_get_map_async(
{ {
let state = state.borrow(); let state = state.borrow();
let instance = state.borrow::<super::Instance>(); let instance = state.borrow::<super::Instance>();
gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::wait())) instance
.device_poll(device, wgpu_types::Maintain::wait())
.unwrap(); .unwrap();
} }
tokio::time::sleep(Duration::from_millis(10)).await; tokio::time::sleep(Duration::from_millis(10)).await;
@ -157,12 +159,9 @@ pub fn op_webgpu_buffer_get_mapped_range(
let buffer_resource = state.resource_table.get::<WebGpuBuffer>(buffer_rid)?; let buffer_resource = state.resource_table.get::<WebGpuBuffer>(buffer_rid)?;
let buffer = buffer_resource.1; let buffer = buffer_resource.1;
let (slice_pointer, range_size) = gfx_select!(buffer => instance.buffer_get_mapped_range( let (slice_pointer, range_size) = instance
buffer, .buffer_get_mapped_range(buffer, offset, size)
offset, .map_err(|e| DomExceptionOperationError::new(&e.to_string()))?;
size
))
.map_err(|e| DomExceptionOperationError::new(&e.to_string()))?;
// SAFETY: guarantee to be safe from wgpu // SAFETY: guarantee to be safe from wgpu
let slice = let slice =
@ -199,5 +198,5 @@ pub fn op_webgpu_buffer_unmap(
slice.copy_from_slice(buf); slice.copy_from_slice(buf);
} }
gfx_ok!(buffer => instance.buffer_unmap(buffer)) gfx_ok!(instance.buffer_unmap(buffer))
} }

View File

@ -30,7 +30,7 @@ impl Resource for WebGpuRenderBundle {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.render_bundle_drop(self.1)); self.0.render_bundle_drop(self.1);
} }
} }
@ -108,7 +108,7 @@ pub fn op_webgpu_render_bundle_encoder_finish(
.into_inner(); .into_inner();
let instance = state.borrow::<super::Instance>(); let instance = state.borrow::<super::Instance>();
gfx_put!(render_bundle_encoder.parent() => instance.render_bundle_encoder_finish( gfx_put!(instance.render_bundle_encoder_finish(
render_bundle_encoder, render_bundle_encoder,
&wgpu_core::command::RenderBundleDescriptor { &wgpu_core::command::RenderBundleDescriptor {
label: Some(label), label: Some(label),

View File

@ -23,7 +23,7 @@ impl Resource for WebGpuCommandEncoder {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.command_encoder_drop(self.1)); self.0.command_encoder_drop(self.1);
} }
} }
@ -38,7 +38,7 @@ impl Resource for WebGpuCommandBuffer {
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
if let Some(id) = *self.1.borrow() { if let Some(id) = *self.1.borrow() {
gfx_select!(id => self.0.command_buffer_drop(id)); self.0.command_buffer_drop(id);
} }
} }
} }
@ -58,7 +58,7 @@ pub fn op_webgpu_create_command_encoder(
let descriptor = wgpu_types::CommandEncoderDescriptor { label: Some(label) }; let descriptor = wgpu_types::CommandEncoderDescriptor { label: Some(label) };
gfx_put!(device => instance.device_create_command_encoder( gfx_put!(instance.device_create_command_encoder(
device, device,
&descriptor, &descriptor,
None None
@ -210,7 +210,8 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
occlusion_query_set: occlusion_query_set_resource, occlusion_query_set: occlusion_query_set_resource,
}; };
let (render_pass, error) = gfx_select!(command_encoder => instance.command_encoder_create_render_pass_dyn(*command_encoder, &descriptor)); let (render_pass, error) =
instance.command_encoder_create_render_pass_dyn(*command_encoder, &descriptor);
let rid = state let rid = state
.resource_table .resource_table
.add(super::render_pass::WebGpuRenderPass(RefCell::new( .add(super::render_pass::WebGpuRenderPass(RefCell::new(
@ -262,7 +263,8 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
timestamp_writes: timestamp_writes.as_ref(), timestamp_writes: timestamp_writes.as_ref(),
}; };
let (compute_pass, error) = gfx_select!(command_encoder => instance.command_encoder_create_compute_pass_dyn(*command_encoder, &descriptor)); let (compute_pass, error) =
instance.command_encoder_create_compute_pass_dyn(*command_encoder, &descriptor);
let rid = state let rid = state
.resource_table .resource_table
.add(super::compute_pass::WebGpuComputePass(RefCell::new( .add(super::compute_pass::WebGpuComputePass(RefCell::new(
@ -297,13 +299,13 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
.get::<super::buffer::WebGpuBuffer>(destination)?; .get::<super::buffer::WebGpuBuffer>(destination)?;
let destination_buffer = destination_buffer_resource.1; let destination_buffer = destination_buffer_resource.1;
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_buffer( gfx_ok!(instance.command_encoder_copy_buffer_to_buffer(
command_encoder, command_encoder,
source_buffer, source_buffer,
source_offset, source_offset,
destination_buffer, destination_buffer,
destination_offset, destination_offset,
size size
)) ))
} }
@ -360,11 +362,11 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
origin: destination.origin, origin: destination.origin,
aspect: destination.aspect, aspect: destination.aspect,
}; };
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_texture( gfx_ok!(instance.command_encoder_copy_buffer_to_texture(
command_encoder, command_encoder,
&source, &source,
&destination, &destination,
&copy_size &copy_size
)) ))
} }
@ -403,11 +405,11 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
rows_per_image: destination.rows_per_image, rows_per_image: destination.rows_per_image,
}, },
}; };
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_buffer( gfx_ok!(instance.command_encoder_copy_texture_to_buffer(
command_encoder, command_encoder,
&source, &source,
&destination, &destination,
&copy_size &copy_size
)) ))
} }
@ -444,11 +446,11 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture(
origin: destination.origin, origin: destination.origin,
aspect: destination.aspect, aspect: destination.aspect,
}; };
gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_texture( gfx_ok!(instance.command_encoder_copy_texture_to_texture(
command_encoder, command_encoder,
&source, &source,
&destination, &destination,
&copy_size &copy_size
)) ))
} }
@ -470,11 +472,11 @@ pub fn op_webgpu_command_encoder_clear_buffer(
.resource_table .resource_table
.get::<super::buffer::WebGpuBuffer>(buffer_rid)?; .get::<super::buffer::WebGpuBuffer>(buffer_rid)?;
gfx_ok!(command_encoder => instance.command_encoder_clear_buffer( gfx_ok!(instance.command_encoder_clear_buffer(
command_encoder, command_encoder,
destination_resource.1, destination_resource.1,
offset, offset,
Some(size) Some(size)
)) ))
} }
@ -491,7 +493,7 @@ pub fn op_webgpu_command_encoder_push_debug_group(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?; .get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1; let command_encoder = command_encoder_resource.1;
gfx_ok!(command_encoder => instance.command_encoder_push_debug_group(command_encoder, group_label)) gfx_ok!(instance.command_encoder_push_debug_group(command_encoder, group_label))
} }
#[op2] #[op2]
@ -506,7 +508,7 @@ pub fn op_webgpu_command_encoder_pop_debug_group(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?; .get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1; let command_encoder = command_encoder_resource.1;
gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder)) gfx_ok!(instance.command_encoder_pop_debug_group(command_encoder))
} }
#[op2] #[op2]
@ -522,10 +524,7 @@ pub fn op_webgpu_command_encoder_insert_debug_marker(
.get::<WebGpuCommandEncoder>(command_encoder_rid)?; .get::<WebGpuCommandEncoder>(command_encoder_rid)?;
let command_encoder = command_encoder_resource.1; let command_encoder = command_encoder_resource.1;
gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker( gfx_ok!(instance.command_encoder_insert_debug_marker(command_encoder, marker_label))
command_encoder,
marker_label
))
} }
#[op2] #[op2]
@ -545,10 +544,10 @@ pub fn op_webgpu_command_encoder_write_timestamp(
.resource_table .resource_table
.get::<super::WebGpuQuerySet>(query_set)?; .get::<super::WebGpuQuerySet>(query_set)?;
gfx_ok!(command_encoder => instance.command_encoder_write_timestamp( gfx_ok!(instance.command_encoder_write_timestamp(
command_encoder, command_encoder,
query_set_resource.1, query_set_resource.1,
query_index query_index
)) ))
} }
@ -575,13 +574,13 @@ pub fn op_webgpu_command_encoder_resolve_query_set(
.resource_table .resource_table
.get::<super::buffer::WebGpuBuffer>(destination)?; .get::<super::buffer::WebGpuBuffer>(destination)?;
gfx_ok!(command_encoder => instance.command_encoder_resolve_query_set( gfx_ok!(instance.command_encoder_resolve_query_set(
command_encoder, command_encoder,
query_set_resource.1, query_set_resource.1,
first_query, first_query,
query_count, query_count,
destination_resource.1, destination_resource.1,
destination_offset destination_offset
)) ))
} }
@ -600,10 +599,7 @@ pub fn op_webgpu_command_encoder_finish(
let descriptor = wgpu_types::CommandBufferDescriptor { label: Some(label) }; let descriptor = wgpu_types::CommandBufferDescriptor { label: Some(label) };
let (val, maybe_err) = gfx_select!(command_encoder => instance.command_encoder_finish( let (val, maybe_err) = instance.command_encoder_finish(command_encoder, &descriptor);
command_encoder,
&descriptor
));
let rid = state.resource_table.add(WebGpuCommandBuffer( let rid = state.resource_table.add(WebGpuCommandBuffer(
instance.clone(), instance.clone(),

View File

@ -23,32 +23,17 @@ pub const UNSTABLE_FEATURE_NAME: &str = "webgpu";
#[macro_use] #[macro_use]
mod macros { mod macros {
// TODO(#5124): remove this macro.
macro_rules! gfx_select {
($id:expr => $p0:ident.$p1:tt.$method:ident $params:tt) => {
gfx_select!($id => {$p0.$p1}, $method $params)
};
($id:expr => $p0:ident.$method:ident $params:tt) => {
gfx_select!($id => {$p0}, $method $params)
};
($id:expr => {$($c:tt)*}, $method:ident $params:tt) => {
$($c)*.$method $params
};
}
macro_rules! gfx_put { macro_rules! gfx_put {
($id:expr => $global:ident.$method:ident( $($param:expr),* ) => $state:expr, $rc:expr) => {{ ($global:ident.$method:ident( $($param:expr),* ) => $state:expr, $rc:expr) => {{
let (val, maybe_err) = gfx_select!($id => $global.$method($($param),*)); let (val, maybe_err) = $global.$method($($param),*);
let rid = $state.resource_table.add($rc($global.clone(), val)); let rid = $state.resource_table.add($rc($global.clone(), val));
Ok(WebGpuResult::rid_err(rid, maybe_err)) Ok(WebGpuResult::rid_err(rid, maybe_err))
}}; }};
} }
macro_rules! gfx_ok { macro_rules! gfx_ok {
($id:expr => $global:ident.$method:ident( $($param:expr),* )) => {{ ($global:ident.$method:ident( $($param:expr),* )) => {{
let maybe_err = gfx_select!($id => $global.$method($($param),*)).err(); let maybe_err = $global.$method($($param),*).err();
Ok(WebGpuResult::maybe_err(maybe_err)) Ok(WebGpuResult::maybe_err(maybe_err))
}}; }};
} }
@ -78,7 +63,7 @@ impl Resource for WebGpuAdapter {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.adapter_drop(self.1)); self.0.adapter_drop(self.1);
} }
} }
@ -89,7 +74,7 @@ impl Resource for WebGpuDevice {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.device_drop(self.1)); self.0.device_drop(self.1);
} }
} }
@ -100,7 +85,7 @@ impl Resource for WebGpuQuerySet {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.query_set_drop(self.1)); self.0.query_set_drop(self.1);
} }
} }
@ -429,9 +414,9 @@ pub fn op_webgpu_request_adapter(
}) })
} }
}; };
let adapter_features = gfx_select!(adapter => instance.adapter_features(adapter))?; let adapter_features = instance.adapter_features(adapter)?;
let features = deserialize_features(&adapter_features); let features = deserialize_features(&adapter_features);
let adapter_limits = gfx_select!(adapter => instance.adapter_limits(adapter))?; let adapter_limits = instance.adapter_limits(adapter)?;
let instance = instance.clone(); let instance = instance.clone();
@ -664,21 +649,24 @@ pub fn op_webgpu_request_device(
memory_hints: wgpu_types::MemoryHints::default(), memory_hints: wgpu_types::MemoryHints::default(),
}; };
let (device, queue, maybe_err) = gfx_select!(adapter => instance.adapter_request_device( let (device, queue, maybe_err) = instance.adapter_request_device(
adapter, adapter,
&descriptor, &descriptor,
std::env::var("DENO_WEBGPU_TRACE").ok().as_ref().map(std::path::Path::new), std::env::var("DENO_WEBGPU_TRACE")
None, .ok()
None .as_ref()
)); .map(std::path::Path::new),
None,
None,
);
adapter_resource.close(); adapter_resource.close();
if let Some(err) = maybe_err { if let Some(err) = maybe_err {
return Err(DomExceptionOperationError::new(&err.to_string()).into()); return Err(DomExceptionOperationError::new(&err.to_string()).into());
} }
let device_features = gfx_select!(device => instance.device_features(device))?; let device_features = instance.device_features(device)?;
let features = deserialize_features(&device_features); let features = deserialize_features(&device_features);
let limits = gfx_select!(device => instance.device_limits(device))?; let limits = instance.device_limits(device)?;
let instance = instance.clone(); let instance = instance.clone();
let instance2 = instance.clone(); let instance2 = instance.clone();
@ -717,7 +705,7 @@ pub fn op_webgpu_request_adapter_info(
let adapter = adapter_resource.1; let adapter = adapter_resource.1;
let instance = state.borrow::<Instance>(); let instance = state.borrow::<Instance>();
let info = gfx_select!(adapter => instance.adapter_get_info(adapter))?; let info = instance.adapter_get_info(adapter)?;
adapter_resource.close(); adapter_resource.close();
Ok(GPUAdapterInfo { Ok(GPUAdapterInfo {
@ -770,7 +758,7 @@ pub fn op_webgpu_create_query_set(
count: args.count, count: args.count,
}; };
gfx_put!(device => instance.device_create_query_set( gfx_put!(instance.device_create_query_set(
device, device,
&descriptor, &descriptor,
None None

View File

@ -24,7 +24,7 @@ impl Resource for WebGpuPipelineLayout {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.pipeline_layout_drop(self.1)); self.0.pipeline_layout_drop(self.1);
} }
} }
@ -38,7 +38,7 @@ impl Resource for WebGpuComputePipeline {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.compute_pipeline_drop(self.1)); self.0.compute_pipeline_drop(self.1);
} }
} }
@ -52,7 +52,7 @@ impl Resource for WebGpuRenderPipeline {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.render_pipeline_drop(self.1)); self.0.render_pipeline_drop(self.1);
} }
} }
@ -116,12 +116,8 @@ pub fn op_webgpu_create_compute_pipeline(
cache: None, cache: None,
}; };
let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline( let (compute_pipeline, maybe_err) =
device, instance.device_create_compute_pipeline(device, &descriptor, None, None);
&descriptor,
None,
None,
));
let rid = state let rid = state
.resource_table .resource_table
@ -150,7 +146,8 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
.get::<WebGpuComputePipeline>(compute_pipeline_rid)?; .get::<WebGpuComputePipeline>(compute_pipeline_rid)?;
let compute_pipeline = compute_pipeline_resource.1; let compute_pipeline = compute_pipeline_resource.1;
let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, None)); let (bind_group_layout, maybe_err) =
instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, None);
let rid = state let rid = state
.resource_table .resource_table
@ -383,12 +380,8 @@ pub fn op_webgpu_create_render_pipeline(
cache: None, cache: None,
}; };
let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline( let (render_pipeline, maybe_err) =
device, instance.device_create_render_pipeline(device, &descriptor, None, None);
&descriptor,
None,
None,
));
let rid = state let rid = state
.resource_table .resource_table
@ -410,7 +403,8 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
.get::<WebGpuRenderPipeline>(render_pipeline_rid)?; .get::<WebGpuRenderPipeline>(render_pipeline_rid)?;
let render_pipeline = render_pipeline_resource.1; let render_pipeline = render_pipeline_resource.1;
let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, None)); let (bind_group_layout, maybe_err) =
instance.render_pipeline_get_bind_group_layout(render_pipeline, index, None);
let rid = state let rid = state
.resource_table .resource_table

View File

@ -20,7 +20,7 @@ impl Resource for WebGpuQueue {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.queue_drop(self.1)); self.0.queue_drop(self.1);
} }
} }
@ -44,7 +44,7 @@ pub fn op_webgpu_queue_submit(
}) })
.collect::<Result<Vec<_>, AnyError>>()?; .collect::<Result<Vec<_>, AnyError>>()?;
let maybe_err = gfx_select!(queue => instance.queue_submit(queue, &ids)).err(); let maybe_err = instance.queue_submit(queue, &ids).err();
for rid in command_buffers { for rid in command_buffers {
let resource = state.resource_table.take::<WebGpuCommandBuffer>(rid)?; let resource = state.resource_table.take::<WebGpuCommandBuffer>(rid)?;
@ -95,13 +95,9 @@ pub fn op_webgpu_write_buffer(
Some(size) => &buf[data_offset..(data_offset + size)], Some(size) => &buf[data_offset..(data_offset + size)],
None => &buf[data_offset..], None => &buf[data_offset..],
}; };
let maybe_err = gfx_select!(queue => instance.queue_write_buffer( let maybe_err = instance
queue, .queue_write_buffer(queue, buffer, buffer_offset, data)
buffer, .err();
buffer_offset,
data
))
.err();
Ok(WebGpuResult::maybe_err(maybe_err)) Ok(WebGpuResult::maybe_err(maybe_err))
} }
@ -131,11 +127,5 @@ pub fn op_webgpu_write_texture(
}; };
let data_layout = data_layout.into(); let data_layout = data_layout.into();
gfx_ok!(queue => instance.queue_write_texture( gfx_ok!(instance.queue_write_texture(queue, &destination, buf, &data_layout, &size))
queue,
&destination,
buf,
&data_layout,
&size
))
} }

View File

@ -21,7 +21,7 @@ impl Resource for WebGpuSampler {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.sampler_drop(self.1)); self.0.sampler_drop(self.1);
} }
} }
@ -71,7 +71,7 @@ pub fn op_webgpu_create_sampler(
border_color: None, // native-only border_color: None, // native-only
}; };
gfx_put!(device => instance.device_create_sampler( gfx_put!(instance.device_create_sampler(
device, device,
&descriptor, &descriptor,
None None

View File

@ -20,7 +20,7 @@ impl Resource for WebGpuShaderModule {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.shader_module_drop(self.1)); self.0.shader_module_drop(self.1);
} }
} }
@ -45,7 +45,7 @@ pub fn op_webgpu_create_shader_module(
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(), shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
}; };
gfx_put!(device => instance.device_create_shader_module( gfx_put!(instance.device_create_shader_module(
device, device,
&descriptor, &descriptor,
source, source,

View File

@ -63,7 +63,7 @@ pub fn op_webgpu_surface_configure(
desired_maximum_frame_latency: 2, desired_maximum_frame_latency: 2,
}; };
let err = gfx_select!(device => instance.surface_configure(surface, device, &conf)); let err = instance.surface_configure(surface, device, &conf);
Ok(WebGpuResult::maybe_err(err)) Ok(WebGpuResult::maybe_err(err))
} }
@ -79,7 +79,7 @@ pub fn op_webgpu_surface_get_current_texture(
let surface_resource = state.resource_table.get::<WebGpuSurface>(surface_rid)?; let surface_resource = state.resource_table.get::<WebGpuSurface>(surface_rid)?;
let surface = surface_resource.1; let surface = surface_resource.1;
let output = gfx_select!(device => instance.surface_get_current_texture(surface, None))?; let output = instance.surface_get_current_texture(surface, None)?;
match output.status { match output.status {
SurfaceStatus::Good | SurfaceStatus::Suboptimal => { SurfaceStatus::Good | SurfaceStatus::Suboptimal => {

View File

@ -24,7 +24,7 @@ impl Resource for WebGpuTexture {
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
if self.owned { if self.owned {
let instance = &self.instance; let instance = &self.instance;
gfx_select!(self.id => instance.texture_drop(self.id)); instance.texture_drop(self.id);
} }
} }
} }
@ -39,7 +39,7 @@ impl Resource for WebGpuTextureView {
} }
fn close(self: Rc<Self>) { fn close(self: Rc<Self>) {
gfx_select!(self.1 => self.0.texture_view_drop(self.1)).unwrap(); self.0.texture_view_drop(self.1).unwrap();
} }
} }
@ -80,11 +80,7 @@ pub fn op_webgpu_create_texture(
view_formats: args.view_formats, view_formats: args.view_formats,
}; };
let (val, maybe_err) = gfx_select!(device => instance.device_create_texture( let (val, maybe_err) = instance.device_create_texture(device, &descriptor, None);
device,
&descriptor,
None
));
let rid = state.resource_table.add(WebGpuTexture { let rid = state.resource_table.add(WebGpuTexture {
instance: instance.clone(), instance: instance.clone(),
@ -125,9 +121,9 @@ pub fn op_webgpu_create_texture_view(
range: args.range, range: args.range,
}; };
gfx_put!(texture => instance.texture_create_view( gfx_put!(instance.texture_create_view(
texture, texture,
&descriptor, &descriptor,
None None
) => state, WebGpuTextureView) ) => state, WebGpuTextureView)
} }

View File

@ -3,7 +3,7 @@
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
fn main() { fn main() {
use player::GlobalPlay as _; use player::GlobalPlay as _;
use wgc::{device::trace, gfx_select}; use wgc::device::trace;
use std::{ use std::{
fs, fs,
@ -78,17 +78,17 @@ fn main() {
) )
.expect("Unable to find an adapter for selected backend"); .expect("Unable to find an adapter for selected backend");
let info = gfx_select!(adapter => global.adapter_get_info(adapter)).unwrap(); let info = global.adapter_get_info(adapter).unwrap();
log::info!("Picked '{}'", info.name); log::info!("Picked '{}'", info.name);
let device_id = wgc::id::Id::zip(1, 0, backend); let device_id = wgc::id::Id::zip(1, 0, backend);
let queue_id = wgc::id::Id::zip(1, 0, backend); let queue_id = wgc::id::Id::zip(1, 0, backend);
let (_, _, error) = gfx_select!(adapter => global.adapter_request_device( let (_, _, error) = global.adapter_request_device(
adapter, adapter,
&desc, &desc,
None, None,
Some(device_id), Some(device_id),
Some(queue_id) Some(queue_id),
)); );
if let Some(e) = error { if let Some(e) = error {
panic!("{:?}", e); panic!("{:?}", e);
} }
@ -100,14 +100,14 @@ fn main() {
log::info!("Executing actions"); log::info!("Executing actions");
#[cfg(not(feature = "winit"))] #[cfg(not(feature = "winit"))]
{ {
gfx_select!(device => global.device_start_capture(device)); global.device_start_capture(device);
while let Some(action) = actions.pop() { while let Some(action) = actions.pop() {
gfx_select!(device => global.process(device, queue, action, &dir, &mut command_buffer_id_manager)); global.process(device, queue, action, &dir, &mut command_buffer_id_manager);
} }
gfx_select!(device => global.device_stop_capture(device)); global.device_stop_capture(device);
gfx_select!(device => global.device_poll(device, wgt::Maintain::wait())).unwrap(); global.device_poll(device, wgt::Maintain::wait()).unwrap();
} }
#[cfg(feature = "winit")] #[cfg(feature = "winit")]
{ {
@ -119,81 +119,92 @@ fn main() {
let mut resize_config = None; let mut resize_config = None;
let mut frame_count = 0; let mut frame_count = 0;
let mut done = false; let mut done = false;
event_loop.run(move |event, target| { event_loop
target.set_control_flow(ControlFlow::Poll); .run(move |event, target| {
target.set_control_flow(ControlFlow::Poll);
match event { match event {
Event::WindowEvent { event, .. } => match event { Event::WindowEvent { event, .. } => match event {
WindowEvent::RedrawRequested if resize_config.is_none() => { WindowEvent::RedrawRequested if resize_config.is_none() => {
match actions.pop() {
match actions.pop() { Some(trace::Action::ConfigureSurface(_device_id, config)) => {
Some(trace::Action::ConfigureSurface(_device_id, config)) => { log::info!("Configuring the surface");
log::info!("Configuring the surface"); let current_size: (u32, u32) = window.inner_size().into();
let current_size: (u32, u32) = window.inner_size().into(); let size = (config.width, config.height);
let size = (config.width, config.height); if current_size != size {
if current_size != size { let _ = window.request_inner_size(
let _ = window.request_inner_size(winit::dpi::PhysicalSize::new( winit::dpi::PhysicalSize::new(
config.width, config.width,
config.height, config.height,
)); ),
resize_config = Some(config); );
target.exit(); resize_config = Some(config);
} else { target.exit();
let error = gfx_select!(device => global.surface_configure(surface, device, &config)); } else {
let error =
global.surface_configure(surface, device, &config);
if let Some(e) = error {
panic!("{:?}", e);
}
}
}
Some(trace::Action::Present(id)) => {
frame_count += 1;
log::debug!("Presenting frame {}", frame_count);
global.surface_present(id).unwrap();
target.exit();
}
Some(trace::Action::DiscardSurfaceTexture(id)) => {
log::debug!("Discarding frame {}", frame_count);
global.surface_texture_discard(id).unwrap();
target.exit();
}
Some(action) => {
global.process(
device,
queue,
action,
&dir,
&mut command_buffer_id_manager,
);
}
None => {
if !done {
println!("Finished the end at frame {}", frame_count);
done = true;
}
target.exit();
}
}
}
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = global.surface_configure(surface, device, &config);
if let Some(e) = error { if let Some(e) = error {
panic!("{:?}", e); panic!("{:?}", e);
} }
} }
} }
Some(trace::Action::Present(id)) => { WindowEvent::KeyboardInput {
frame_count += 1; event:
log::debug!("Presenting frame {}", frame_count); KeyEvent {
gfx_select!(device => global.surface_present(id)).unwrap(); logical_key: Key::Named(NamedKey::Escape),
target.exit(); state: ElementState::Pressed,
} ..
Some(trace::Action::DiscardSurfaceTexture(id)) => { },
log::debug!("Discarding frame {}", frame_count);
gfx_select!(device => global.surface_texture_discard(id)).unwrap();
target.exit();
}
Some(action) => {
gfx_select!(device => global.process(device, queue, action, &dir, &mut command_buffer_id_manager));
}
None => {
if !done {
println!("Finished the end at frame {}", frame_count);
done = true;
}
target.exit();
}
}
},
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = gfx_select!(device => global.surface_configure(surface, device, &config));
if let Some(e) = error {
panic!("{:?}", e);
}
}
}
WindowEvent::KeyboardInput {
event: KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
state: ElementState::Pressed,
.. ..
}, }
.. | WindowEvent::CloseRequested => target.exit(),
_ => {}
},
Event::LoopExiting => {
log::info!("Closing");
global.device_poll(device, wgt::Maintain::wait()).unwrap();
} }
| WindowEvent::CloseRequested => target.exit(),
_ => {} _ => {}
},
Event::LoopExiting => {
log::info!("Closing");
gfx_select!(device => global.device_poll(device, wgt::Maintain::wait())).unwrap();
} }
_ => {} })
} .unwrap();
}).unwrap();
} }
} }

View File

@ -107,7 +107,7 @@ impl Test<'_> {
let backend = adapter.backend(); let backend = adapter.backend();
let device_id = wgc::id::Id::zip(test_num, 0, backend); let device_id = wgc::id::Id::zip(test_num, 0, backend);
let queue_id = wgc::id::Id::zip(test_num, 0, backend); let queue_id = wgc::id::Id::zip(test_num, 0, backend);
let (_, _, error) = wgc::gfx_select!(adapter => global.adapter_request_device( let (_, _, error) = global.adapter_request_device(
adapter, adapter,
&wgt::DeviceDescriptor { &wgt::DeviceDescriptor {
label: None, label: None,
@ -117,8 +117,8 @@ impl Test<'_> {
}, },
None, None,
Some(device_id), Some(device_id),
Some(queue_id) Some(queue_id),
)); );
if let Some(e) = error { if let Some(e) = error {
panic!("{:?}", e); panic!("{:?}", e);
} }
@ -126,35 +126,47 @@ impl Test<'_> {
let mut command_buffer_id_manager = wgc::identity::IdentityManager::new(); let mut command_buffer_id_manager = wgc::identity::IdentityManager::new();
println!("\t\t\tRunning..."); println!("\t\t\tRunning...");
for action in self.actions { for action in self.actions {
wgc::gfx_select!(device_id => global.process(device_id, queue_id, action, dir, &mut command_buffer_id_manager)); global.process(
device_id,
queue_id,
action,
dir,
&mut command_buffer_id_manager,
);
} }
println!("\t\t\tMapping..."); println!("\t\t\tMapping...");
for expect in &self.expectations { for expect in &self.expectations {
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend); let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend);
wgc::gfx_select!(device_id => global.buffer_map_async( global
buffer, .buffer_map_async(
expect.offset, buffer,
Some(expect.data.len() as u64), expect.offset,
wgc::resource::BufferMapOperation { Some(expect.data.len() as u64),
host: wgc::device::HostMap::Read, wgc::resource::BufferMapOperation {
callback: Some(wgc::resource::BufferMapCallback::from_rust( host: wgc::device::HostMap::Read,
Box::new(map_callback) callback: Some(wgc::resource::BufferMapCallback::from_rust(Box::new(
)), map_callback,
} ))),
)) },
.unwrap(); )
.unwrap();
} }
println!("\t\t\tWaiting..."); println!("\t\t\tWaiting...");
wgc::gfx_select!(device_id => global.device_poll(device_id, wgt::Maintain::wait())) global
.device_poll(device_id, wgt::Maintain::wait())
.unwrap(); .unwrap();
for expect in self.expectations { for expect in self.expectations {
println!("\t\t\tChecking {}", expect.name); println!("\t\t\tChecking {}", expect.name);
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend); let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend);
let (ptr, size) = let (ptr, size) = global
wgc::gfx_select!(device_id => global.buffer_get_mapped_range(buffer, expect.offset, Some(expect.data.len() as wgt::BufferAddress))) .buffer_get_mapped_range(
.unwrap(); buffer,
expect.offset,
Some(expect.data.len() as wgt::BufferAddress),
)
.unwrap();
let contents = unsafe { slice::from_raw_parts(ptr.as_ptr(), size as usize) }; let contents = unsafe { slice::from_raw_parts(ptr.as_ptr(), size as usize) };
let expected_data = match expect.data { let expected_data = match expect.data {
ExpectedData::Raw(vec) => vec, ExpectedData::Raw(vec) => vec,
@ -231,11 +243,8 @@ impl Corpus {
}; };
println!("\tBackend {:?}", backend); println!("\tBackend {:?}", backend);
let supported_features = let supported_features = global.adapter_features(adapter).unwrap();
wgc::gfx_select!(adapter => global.adapter_features(adapter)).unwrap(); let downlevel_caps = global.adapter_downlevel_capabilities(adapter).unwrap();
let downlevel_caps =
wgc::gfx_select!(adapter => global.adapter_downlevel_capabilities(adapter))
.unwrap();
let test = Test::load(dir.join(test_path), adapter.backend()); let test = Test::load(dir.join(test_path), adapter.backend());
if !supported_features.contains(test.features) { if !supported_features.contains(test.features) {

View File

@ -10,10 +10,7 @@ of course `Debug`.
[`id::BufferId`]: crate::id::BufferId [`id::BufferId`]: crate::id::BufferId
Each `Id` contains not only an index for the resource it denotes but Each `Id` contains not only an index for the resource it denotes but
also a Backend indicating which `wgpu` backend it belongs to. You also a Backend indicating which `wgpu` backend it belongs to.
can use the [`gfx_select`] macro to dynamically dispatch on an id's
backend to a function specialized at compile time for a specific
backend. See that macro's documentation for details.
`Id`s also incorporate a generation number, for additional validation. `Id`s also incorporate a generation number, for additional validation.
@ -96,7 +93,6 @@ creation fails, the id supplied for that resource is marked to indicate
as much, allowing subsequent operations using that id to be properly as much, allowing subsequent operations using that id to be properly
flagged as errors as well. flagged as errors as well.
[`gfx_select`]: crate::gfx_select
[`process`]: crate::identity::IdentityManager::process [`process`]: crate::identity::IdentityManager::process
[`Id<R>`]: crate::id::Id [`Id<R>`]: crate::id::Id
[wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E [wrapped in a mutex]: trait.IdentityHandler.html#impl-IdentityHandler%3CI%3E-for-Mutex%3CIdentityManager%3E

View File

@ -153,169 +153,6 @@ If you are running this program on native and not in a browser and wish to work
Adapter::downlevel_properties or Device::downlevel_properties to get a listing of the features the current \ Adapter::downlevel_properties or Device::downlevel_properties to get a listing of the features the current \
platform supports."; platform supports.";
// #[cfg] attributes in exported macros are interesting!
//
// The #[cfg] conditions in a macro's expansion are evaluated using the
// configuration options (features, target architecture and os, etc.) in force
// where the macro is *used*, not where it is *defined*. That is, if crate A
// defines a macro like this:
//
// #[macro_export]
// macro_rules! if_bleep {
// { } => {
// #[cfg(feature = "bleep")]
// bleep();
// }
// }
//
// and then crate B uses it like this:
//
// fn f() {
// if_bleep! { }
// }
//
// then it is crate B's `"bleep"` feature, not crate A's, that determines
// whether the macro expands to a function call or an empty statement. The
// entire configuration predicate is evaluated in the use's context, not the
// definition's.
//
// Since `wgpu-core` selects back ends using features, we need to make sure the
// arms of the `gfx_select!` macro are pruned according to `wgpu-core`'s
// features, not those of whatever crate happens to be using `gfx_select!`. This
// means we can't use `#[cfg]` attributes in `gfx_select!`s definition itself.
// Instead, for each backend, `gfx_select!` must use a macro whose definition is
// selected by `#[cfg]` in `wgpu-core`. The configuration predicate is still
// evaluated when the macro is used; we've just moved the `#[cfg]` into a macro
// used by `wgpu-core` itself.
/// Define an exported macro named `$public` that expands to an expression if
/// the feature `$feature` is enabled, or to a panic otherwise.
///
/// This is used in the definition of `gfx_select!`, to dispatch the
/// call to the appropriate backend, but panic if that backend was not
/// compiled in.
///
/// For a call like this:
///
/// ```ignore
/// define_backend_caller! { name, private, "feature" if cfg_condition }
/// ```
///
/// define a macro `name`, used like this:
///
/// ```ignore
/// name!(expr)
/// ```
///
/// that expands to `expr` if `#[cfg(cfg_condition)]` is enabled, or a
/// panic otherwise. The panic message complains that `"feature"` is
/// not enabled.
///
/// Because of odd technical limitations on exporting macros expanded
/// by other macros, you must supply both a public-facing name for the
/// macro and a private name, `$private`, which is never used
/// outside this macro. For details:
/// <https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997>
macro_rules! define_backend_caller {
{ $public:ident, $private:ident, $feature:literal if $cfg:meta } => {
#[cfg($cfg)]
#[macro_export]
macro_rules! $private {
( $call:expr ) => ( $call )
}
#[cfg(not($cfg))]
#[macro_export]
macro_rules! $private {
( $call:expr ) => (
panic!("Identifier refers to disabled backend feature {:?}", $feature)
)
}
// See note about rust-lang#52234 above.
#[doc(hidden)] pub use $private as $public;
}
}
// Define a macro for each `gfx_select!` match arm. For example,
//
// gfx_if_vulkan!(expr)
//
// expands to `expr` if the `"vulkan"` feature is enabled, or to a panic
// otherwise.
define_backend_caller! { gfx_if_vulkan, gfx_if_vulkan_hidden, "vulkan" if all(feature = "vulkan", not(target_arch = "wasm32")) }
define_backend_caller! { gfx_if_metal, gfx_if_metal_hidden, "metal" if all(feature = "metal", any(target_os = "macos", target_os = "ios")) }
define_backend_caller! { gfx_if_dx12, gfx_if_dx12_hidden, "dx12" if all(feature = "dx12", windows) }
define_backend_caller! { gfx_if_gles, gfx_if_gles_hidden, "gles" if feature = "gles" }
define_backend_caller! { gfx_if_empty, gfx_if_empty_hidden, "empty" if all(
not(any(feature = "metal", feature = "vulkan", feature = "gles")),
any(target_os = "macos", target_os = "ios"),
) }
/// Dispatch on an [`Id`]'s backend to a backend-generic method.
///
/// Uses of this macro have the form:
///
/// ```ignore
///
/// gfx_select!(id => value.method(args...))
///
/// ```
///
/// This expands to an expression that calls `value.method::<A>(args...)` for
/// the backend `A` selected by `id`. The expansion matches on `id.backend()`,
/// with an arm for each backend type in [`wgpu_types::Backend`] which calls the
/// specialization of `method` for the given backend. This allows resource
/// identifiers to select backends dynamically, even though many `wgpu_core`
/// methods are compiled and optimized for a specific back end.
///
/// This macro is typically used to call methods on [`wgpu_core::global::Global`],
/// many of which take a single `hal::Api` type parameter. For example, to
/// create a new buffer on the device indicated by `device_id`, one would say:
///
/// ```ignore
/// gfx_select!(device_id => global.device_create_buffer(device_id, ...))
/// ```
///
/// where the `device_create_buffer` method is defined like this:
///
/// ```ignore
/// impl Global {
/// pub fn device_create_buffer<A: HalApi>(&self, ...) -> ...
/// { ... }
/// }
/// ```
///
/// That `gfx_select!` call uses `device_id`'s backend to select the right
/// backend type `A` for a call to `Global::device_create_buffer<A>`.
///
/// However, there's nothing about this macro that is specific to `hub::Global`.
/// For example, Firefox's embedding of `wgpu_core` defines its own types with
/// methods that take `hal::Api` type parameters. Firefox uses `gfx_select!` to
/// dynamically dispatch to the right specialization based on the resource's id.
///
/// [`wgpu_types::Backend`]: wgt::Backend
/// [`wgpu_core::global::Global`]: crate::global::Global
/// [`Id`]: id::Id
//
// TODO(#5124): Remove this altogether.
#[macro_export]
macro_rules! gfx_select {
// Simple two-component expression, like `self.0.method(..)`.
($id:expr => $c0:ident.$c1:tt.$method:ident $params:tt) => {
$crate::gfx_select!($id => {$c0.$c1}, $method $params)
};
// Simple identifier-only expression, like `global.method(..)`.
($id:expr => $c0:ident.$method:ident $params:tt) => {
$crate::gfx_select!($id => {$c0}, $method $params)
};
($id:expr => {$($c:tt)*}, $method:ident $params:tt) => {
$($c)*.$method $params
};
}
#[cfg(feature = "api_log_info")] #[cfg(feature = "api_log_info")]
macro_rules! api_log { macro_rules! api_log {
($($arg:tt)+) => (log::info!($($arg)+)) ($($arg:tt)+) => (log::info!($($arg)+))

View File

@ -25,8 +25,8 @@ use std::{
sync::Arc, sync::Arc,
}; };
use wgc::{ use wgc::{
command::bundle_ffi::*, device::DeviceLostClosure, gfx_select, id::CommandEncoderId, command::bundle_ffi::*, device::DeviceLostClosure, id::CommandEncoderId, id::TextureViewId,
id::TextureViewId, pipeline::CreateShaderModuleError, pipeline::CreateShaderModuleError,
}; };
use wgt::WasmNotSendSync; use wgt::WasmNotSendSync;
@ -646,13 +646,13 @@ impl crate::Context for ContextWgpuCore {
if trace_dir.is_some() { if trace_dir.is_some() {
log::error!("Feature 'trace' has been removed temporarily, see https://github.com/gfx-rs/wgpu/issues/5974"); log::error!("Feature 'trace' has been removed temporarily, see https://github.com/gfx-rs/wgpu/issues/5974");
} }
let (device_id, queue_id, error) = wgc::gfx_select!(*adapter => self.0.adapter_request_device( let (device_id, queue_id, error) = self.0.adapter_request_device(
*adapter, *adapter,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
None, None,
None, None,
None None,
)); );
if let Some(err) = error { if let Some(err) = error {
return ready(Err(err.into())); return ready(Err(err.into()));
} }
@ -683,7 +683,7 @@ impl crate::Context for ContextWgpuCore {
surface: &Self::SurfaceId, surface: &Self::SurfaceId,
_surface_data: &Self::SurfaceData, _surface_data: &Self::SurfaceData,
) -> bool { ) -> bool {
match wgc::gfx_select!(adapter => self.0.adapter_is_surface_supported(*adapter, *surface)) { match self.0.adapter_is_surface_supported(*adapter, *surface) {
Ok(result) => result, Ok(result) => result,
Err(err) => self.handle_error_fatal(err, "Adapter::is_surface_supported"), Err(err) => self.handle_error_fatal(err, "Adapter::is_surface_supported"),
} }
@ -694,7 +694,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &Self::AdapterId, adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> Features { ) -> Features {
match wgc::gfx_select!(*adapter => self.0.adapter_features(*adapter)) { match self.0.adapter_features(*adapter) {
Ok(features) => features, Ok(features) => features,
Err(err) => self.handle_error_fatal(err, "Adapter::features"), Err(err) => self.handle_error_fatal(err, "Adapter::features"),
} }
@ -705,7 +705,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &Self::AdapterId, adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> Limits { ) -> Limits {
match wgc::gfx_select!(*adapter => self.0.adapter_limits(*adapter)) { match self.0.adapter_limits(*adapter) {
Ok(limits) => limits, Ok(limits) => limits,
Err(err) => self.handle_error_fatal(err, "Adapter::limits"), Err(err) => self.handle_error_fatal(err, "Adapter::limits"),
} }
@ -716,7 +716,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &Self::AdapterId, adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> DownlevelCapabilities { ) -> DownlevelCapabilities {
match wgc::gfx_select!(*adapter => self.0.adapter_downlevel_capabilities(*adapter)) { match self.0.adapter_downlevel_capabilities(*adapter) {
Ok(downlevel) => downlevel, Ok(downlevel) => downlevel,
Err(err) => self.handle_error_fatal(err, "Adapter::downlevel_properties"), Err(err) => self.handle_error_fatal(err, "Adapter::downlevel_properties"),
} }
@ -727,7 +727,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &wgc::id::AdapterId, adapter: &wgc::id::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> AdapterInfo { ) -> AdapterInfo {
match wgc::gfx_select!(*adapter => self.0.adapter_get_info(*adapter)) { match self.0.adapter_get_info(*adapter) {
Ok(info) => info, Ok(info) => info,
Err(err) => self.handle_error_fatal(err, "Adapter::get_info"), Err(err) => self.handle_error_fatal(err, "Adapter::get_info"),
} }
@ -739,8 +739,7 @@ impl crate::Context for ContextWgpuCore {
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
format: wgt::TextureFormat, format: wgt::TextureFormat,
) -> wgt::TextureFormatFeatures { ) -> wgt::TextureFormatFeatures {
match wgc::gfx_select!(*adapter => self.0.adapter_get_texture_format_features(*adapter, format)) match self.0.adapter_get_texture_format_features(*adapter, format) {
{
Ok(info) => info, Ok(info) => info,
Err(err) => self.handle_error_fatal(err, "Adapter::get_texture_format_features"), Err(err) => self.handle_error_fatal(err, "Adapter::get_texture_format_features"),
} }
@ -751,7 +750,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &Self::AdapterId, adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> wgt::PresentationTimestamp { ) -> wgt::PresentationTimestamp {
match wgc::gfx_select!(*adapter => self.0.adapter_get_presentation_timestamp(*adapter)) { match self.0.adapter_get_presentation_timestamp(*adapter) {
Ok(timestamp) => timestamp, Ok(timestamp) => timestamp,
Err(err) => self.handle_error_fatal(err, "Adapter::correlate_presentation_timestamp"), Err(err) => self.handle_error_fatal(err, "Adapter::correlate_presentation_timestamp"),
} }
@ -764,7 +763,7 @@ impl crate::Context for ContextWgpuCore {
adapter: &Self::AdapterId, adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData, _adapter_data: &Self::AdapterData,
) -> wgt::SurfaceCapabilities { ) -> wgt::SurfaceCapabilities {
match wgc::gfx_select!(adapter => self.0.surface_get_capabilities(*surface, *adapter)) { match self.0.surface_get_capabilities(*surface, *adapter) {
Ok(caps) => caps, Ok(caps) => caps,
Err(wgc::instance::GetSurfaceSupportError::Unsupported) => { Err(wgc::instance::GetSurfaceSupportError::Unsupported) => {
wgt::SurfaceCapabilities::default() wgt::SurfaceCapabilities::default()
@ -781,7 +780,7 @@ impl crate::Context for ContextWgpuCore {
_device_data: &Self::DeviceData, _device_data: &Self::DeviceData,
config: &crate::SurfaceConfiguration, config: &crate::SurfaceConfiguration,
) { ) {
let error = wgc::gfx_select!(device => self.0.surface_configure(*surface, *device, config)); let error = self.0.surface_configure(*surface, *device, config);
if let Some(e) = error { if let Some(e) = error {
self.handle_error_fatal(e, "Surface::configure"); self.handle_error_fatal(e, "Surface::configure");
} else { } else {
@ -843,14 +842,14 @@ impl crate::Context for ContextWgpuCore {
device: &Self::DeviceId, device: &Self::DeviceId,
_device_data: &Self::DeviceData, _device_data: &Self::DeviceData,
) -> Features { ) -> Features {
match wgc::gfx_select!(device => self.0.device_features(*device)) { match self.0.device_features(*device) {
Ok(features) => features, Ok(features) => features,
Err(err) => self.handle_error_fatal(err, "Device::features"), Err(err) => self.handle_error_fatal(err, "Device::features"),
} }
} }
fn device_limits(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) -> Limits { fn device_limits(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) -> Limits {
match wgc::gfx_select!(device => self.0.device_limits(*device)) { match self.0.device_limits(*device) {
Ok(limits) => limits, Ok(limits) => limits,
Err(err) => self.handle_error_fatal(err, "Device::limits"), Err(err) => self.handle_error_fatal(err, "Device::limits"),
} }
@ -861,7 +860,7 @@ impl crate::Context for ContextWgpuCore {
device: &Self::DeviceId, device: &Self::DeviceId,
_device_data: &Self::DeviceData, _device_data: &Self::DeviceData,
) -> DownlevelCapabilities { ) -> DownlevelCapabilities {
match wgc::gfx_select!(device => self.0.device_downlevel_properties(*device)) { match self.0.device_downlevel_properties(*device) {
Ok(limits) => limits, Ok(limits) => limits,
Err(err) => self.handle_error_fatal(err, "Device::downlevel_properties"), Err(err) => self.handle_error_fatal(err, "Device::downlevel_properties"),
} }
@ -913,9 +912,9 @@ impl crate::Context for ContextWgpuCore {
ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module), ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module),
ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"), ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"),
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = self
device => self.0.device_create_shader_module(*device, &descriptor, source, None) .0
); .device_create_shader_module(*device, &descriptor, source, None);
let compilation_info = match error { let compilation_info = match error {
Some(cause) => { Some(cause) => {
self.handle_error( self.handle_error(
@ -944,9 +943,14 @@ impl crate::Context for ContextWgpuCore {
// runtime checks // runtime checks
shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() }, shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() },
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = unsafe {
device => self.0.device_create_shader_module_spirv(*device, &descriptor, Borrowed(&desc.source), None) self.0.device_create_shader_module_spirv(
); *device,
&descriptor,
Borrowed(&desc.source),
None,
)
};
let compilation_info = match error { let compilation_info = match error {
Some(cause) => { Some(cause) => {
self.handle_error( self.handle_error(
@ -972,9 +976,9 @@ impl crate::Context for ContextWgpuCore {
label: desc.label.map(Borrowed), label: desc.label.map(Borrowed),
entries: Borrowed(desc.entries), entries: Borrowed(desc.entries),
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = self
device => self.0.device_create_bind_group_layout(*device, &descriptor, None) .0
); .device_create_bind_group_layout(*device, &descriptor, None);
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1083,11 +1087,7 @@ impl crate::Context for ContextWgpuCore {
entries: Borrowed(&entries), entries: Borrowed(&entries),
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_bind_group( let (id, error) = self.0.device_create_bind_group(*device, &descriptor, None);
*device,
&descriptor,
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1124,11 +1124,9 @@ impl crate::Context for ContextWgpuCore {
push_constant_ranges: Borrowed(desc.push_constant_ranges), push_constant_ranges: Borrowed(desc.push_constant_ranges),
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_pipeline_layout( let (id, error) = self
*device, .0
&descriptor, .device_create_pipeline_layout(*device, &descriptor, None);
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1191,12 +1189,9 @@ impl crate::Context for ContextWgpuCore {
cache: desc.cache.map(|c| c.id.into()), cache: desc.cache.map(|c| c.id.into()),
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_render_pipeline( let (id, error) = self
*device, .0
&descriptor, .device_create_render_pipeline(*device, &descriptor, None, None);
None,
None,
));
if let Some(cause) = error { if let Some(cause) = error {
if let wgc::pipeline::CreateRenderPipelineError::Internal { stage, ref error } = cause { if let wgc::pipeline::CreateRenderPipelineError::Internal { stage, ref error } = cause {
log::error!("Shader translation error for stage {:?}: {}", stage, error); log::error!("Shader translation error for stage {:?}: {}", stage, error);
@ -1233,12 +1228,9 @@ impl crate::Context for ContextWgpuCore {
cache: desc.cache.map(|c| c.id.into()), cache: desc.cache.map(|c| c.id.into()),
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_compute_pipeline( let (id, error) = self
*device, .0
&descriptor, .device_create_compute_pipeline(*device, &descriptor, None, None);
None,
None,
));
if let Some(cause) = error { if let Some(cause) = error {
if let wgc::pipeline::CreateComputePipelineError::Internal(ref error) = cause { if let wgc::pipeline::CreateComputePipelineError::Internal(ref error) = cause {
log::error!( log::error!(
@ -1271,11 +1263,10 @@ impl crate::Context for ContextWgpuCore {
data: desc.data.map(Borrowed), data: desc.data.map(Borrowed),
fallback: desc.fallback, fallback: desc.fallback,
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_pipeline_cache( let (id, error) = unsafe {
*device, self.0
&descriptor, .device_create_pipeline_cache(*device, &descriptor, None)
None };
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1293,11 +1284,9 @@ impl crate::Context for ContextWgpuCore {
device_data: &Self::DeviceData, device_data: &Self::DeviceData,
desc: &crate::BufferDescriptor<'_>, desc: &crate::BufferDescriptor<'_>,
) -> (Self::BufferId, Self::BufferData) { ) -> (Self::BufferId, Self::BufferData) {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_buffer( let (id, error) =
*device, self.0
&desc.map_label(|l| l.map(Borrowed)), .device_create_buffer(*device, &desc.map_label(|l| l.map(Borrowed)), None);
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1320,11 +1309,7 @@ impl crate::Context for ContextWgpuCore {
desc: &TextureDescriptor<'_>, desc: &TextureDescriptor<'_>,
) -> (Self::TextureId, Self::TextureData) { ) -> (Self::TextureId, Self::TextureData) {
let wgt_desc = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec()); let wgt_desc = desc.map_label_and_view_formats(|l| l.map(Borrowed), |v| v.to_vec());
let (id, error) = wgc::gfx_select!(device => self.0.device_create_texture( let (id, error) = self.0.device_create_texture(*device, &wgt_desc, None);
*device,
&wgt_desc,
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1364,11 +1349,7 @@ impl crate::Context for ContextWgpuCore {
border_color: desc.border_color, border_color: desc.border_color,
}; };
let (id, error) = wgc::gfx_select!(device => self.0.device_create_sampler( let (id, error) = self.0.device_create_sampler(*device, &descriptor, None);
*device,
&descriptor,
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1385,11 +1366,9 @@ impl crate::Context for ContextWgpuCore {
device_data: &Self::DeviceData, device_data: &Self::DeviceData,
desc: &wgt::QuerySetDescriptor<Label<'_>>, desc: &wgt::QuerySetDescriptor<Label<'_>>,
) -> (Self::QuerySetId, Self::QuerySetData) { ) -> (Self::QuerySetId, Self::QuerySetData) {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_query_set( let (id, error) =
*device, self.0
&desc.map_label(|l| l.map(Borrowed)), .device_create_query_set(*device, &desc.map_label(|l| l.map(Borrowed)), None);
None
));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error_nolabel(&device_data.error_sink, cause, "Device::create_query_set"); self.handle_error_nolabel(&device_data.error_sink, cause, "Device::create_query_set");
} }
@ -1401,11 +1380,11 @@ impl crate::Context for ContextWgpuCore {
device_data: &Self::DeviceData, device_data: &Self::DeviceData,
desc: &CommandEncoderDescriptor<'_>, desc: &CommandEncoderDescriptor<'_>,
) -> (Self::CommandEncoderId, Self::CommandEncoderData) { ) -> (Self::CommandEncoderId, Self::CommandEncoderData) {
let (id, error) = wgc::gfx_select!(device => self.0.device_create_command_encoder( let (id, error) = self.0.device_create_command_encoder(
*device, *device,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
None None,
)); );
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&device_data.error_sink, &device_data.error_sink,
@ -1442,7 +1421,7 @@ impl crate::Context for ContextWgpuCore {
} }
#[doc(hidden)] #[doc(hidden)]
fn device_make_invalid(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_make_invalid(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
wgc::gfx_select!(device => self.0.device_make_invalid(*device)); self.0.device_make_invalid(*device);
} }
#[cfg_attr(not(any(native, Emscripten)), allow(unused))] #[cfg_attr(not(any(native, Emscripten)), allow(unused))]
fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
@ -1450,13 +1429,13 @@ impl crate::Context for ContextWgpuCore {
{ {
// Call device_poll, but don't check for errors. We have to use its // Call device_poll, but don't check for errors. We have to use its
// return value, but we just drop it. // return value, but we just drop it.
let _ = wgc::gfx_select!(device => self.0.device_poll(*device, wgt::Maintain::wait())); let _ = self.0.device_poll(*device, wgt::Maintain::wait());
wgc::gfx_select!(device => self.0.device_drop(*device)); self.0.device_drop(*device);
} }
} }
#[cfg_attr(target_arch = "wasm32", allow(unused))] #[cfg_attr(target_arch = "wasm32", allow(unused))]
fn queue_drop(&self, queue: &Self::QueueId, _device_data: &Self::QueueData) { fn queue_drop(&self, queue: &Self::QueueId, _device_data: &Self::QueueData) {
wgc::gfx_select!(queue => self.0.queue_drop(*queue)); self.0.queue_drop(*queue);
} }
fn device_set_device_lost_callback( fn device_set_device_lost_callback(
&self, &self,
@ -1465,10 +1444,11 @@ impl crate::Context for ContextWgpuCore {
device_lost_callback: crate::context::DeviceLostCallback, device_lost_callback: crate::context::DeviceLostCallback,
) { ) {
let device_lost_closure = DeviceLostClosure::from_rust(device_lost_callback); let device_lost_closure = DeviceLostClosure::from_rust(device_lost_callback);
wgc::gfx_select!(device => self.0.device_set_device_lost_closure(*device, device_lost_closure)); self.0
.device_set_device_lost_closure(*device, device_lost_closure);
} }
fn device_destroy(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_destroy(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
wgc::gfx_select!(device => self.0.device_destroy(*device)); self.0.device_destroy(*device);
} }
fn device_mark_lost( fn device_mark_lost(
&self, &self,
@ -1478,7 +1458,7 @@ impl crate::Context for ContextWgpuCore {
) { ) {
// We do not provide a reason to device_lose, because all reasons other than // We do not provide a reason to device_lose, because all reasons other than
// destroyed (which this is not) are "unknown". // destroyed (which this is not) are "unknown".
wgc::gfx_select!(device => self.0.device_mark_lost(*device, message)); self.0.device_mark_lost(*device, message);
} }
fn device_poll( fn device_poll(
&self, &self,
@ -1487,10 +1467,7 @@ impl crate::Context for ContextWgpuCore {
maintain: crate::Maintain, maintain: crate::Maintain,
) -> wgt::MaintainResult { ) -> wgt::MaintainResult {
let maintain_inner = maintain.map_index(|i| *i.0.as_ref().downcast_ref().unwrap()); let maintain_inner = maintain.map_index(|i| *i.0.as_ref().downcast_ref().unwrap());
match wgc::gfx_select!(device => self.0.device_poll( match self.0.device_poll(*device, maintain_inner) {
*device,
maintain_inner
)) {
Ok(done) => match done { Ok(done) => match done {
true => wgt::MaintainResult::SubmissionQueueEmpty, true => wgt::MaintainResult::SubmissionQueueEmpty,
false => wgt::MaintainResult::Ok, false => wgt::MaintainResult::Ok,
@ -1550,8 +1527,12 @@ impl crate::Context for ContextWgpuCore {
))), ))),
}; };
match wgc::gfx_select!(buffer => self.0.buffer_map_async(*buffer, range.start, Some(range.end-range.start), operation)) match self.0.buffer_map_async(
{ *buffer,
range.start,
Some(range.end - range.start),
operation,
) {
Ok(()) => (), Ok(()) => (),
Err(cause) => { Err(cause) => {
self.handle_error_nolabel(&buffer_data.error_sink, cause, "Buffer::map_async") self.handle_error_nolabel(&buffer_data.error_sink, cause, "Buffer::map_async")
@ -1565,11 +1546,10 @@ impl crate::Context for ContextWgpuCore {
sub_range: Range<wgt::BufferAddress>, sub_range: Range<wgt::BufferAddress>,
) -> Box<dyn crate::context::BufferMappedRange> { ) -> Box<dyn crate::context::BufferMappedRange> {
let size = sub_range.end - sub_range.start; let size = sub_range.end - sub_range.start;
match wgc::gfx_select!(buffer => self.0.buffer_get_mapped_range( match self
*buffer, .0
sub_range.start, .buffer_get_mapped_range(*buffer, sub_range.start, Some(size))
Some(size) {
)) {
Ok((ptr, size)) => Box::new(BufferMappedRange { Ok((ptr, size)) => Box::new(BufferMappedRange {
ptr, ptr,
size: size as usize, size: size as usize,
@ -1579,7 +1559,7 @@ impl crate::Context for ContextWgpuCore {
} }
fn buffer_unmap(&self, buffer: &Self::BufferId, buffer_data: &Self::BufferData) { fn buffer_unmap(&self, buffer: &Self::BufferId, buffer_data: &Self::BufferData) {
match wgc::gfx_select!(buffer => self.0.buffer_unmap(*buffer)) { match self.0.buffer_unmap(*buffer) {
Ok(()) => (), Ok(()) => (),
Err(cause) => { Err(cause) => {
self.handle_error_nolabel(&buffer_data.error_sink, cause, "Buffer::buffer_unmap") self.handle_error_nolabel(&buffer_data.error_sink, cause, "Buffer::buffer_unmap")
@ -1613,9 +1593,7 @@ impl crate::Context for ContextWgpuCore {
array_layer_count: desc.array_layer_count, array_layer_count: desc.array_layer_count,
}, },
}; };
let (id, error) = wgc::gfx_select!( let (id, error) = self.0.texture_create_view(*texture, &descriptor, None);
texture => self.0.texture_create_view(*texture, &descriptor, None)
);
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error( self.handle_error(
&texture_data.error_sink, &texture_data.error_sink,
@ -1632,25 +1610,25 @@ impl crate::Context for ContextWgpuCore {
} }
fn adapter_drop(&self, adapter: &Self::AdapterId, _adapter_data: &Self::AdapterData) { fn adapter_drop(&self, adapter: &Self::AdapterId, _adapter_data: &Self::AdapterData) {
wgc::gfx_select!(*adapter => self.0.adapter_drop(*adapter)) self.0.adapter_drop(*adapter)
} }
fn buffer_destroy(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) { fn buffer_destroy(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) {
// Per spec, no error to report. Even calling destroy multiple times is valid. // Per spec, no error to report. Even calling destroy multiple times is valid.
let _ = wgc::gfx_select!(buffer => self.0.buffer_destroy(*buffer)); let _ = self.0.buffer_destroy(*buffer);
} }
fn buffer_drop(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) { fn buffer_drop(&self, buffer: &Self::BufferId, _buffer_data: &Self::BufferData) {
wgc::gfx_select!(buffer => self.0.buffer_drop(*buffer)) self.0.buffer_drop(*buffer)
} }
fn texture_destroy(&self, texture: &Self::TextureId, _texture_data: &Self::TextureData) { fn texture_destroy(&self, texture: &Self::TextureId, _texture_data: &Self::TextureData) {
// Per spec, no error to report. Even calling destroy multiple times is valid. // Per spec, no error to report. Even calling destroy multiple times is valid.
let _ = wgc::gfx_select!(texture => self.0.texture_destroy(*texture)); let _ = self.0.texture_destroy(*texture);
} }
fn texture_drop(&self, texture: &Self::TextureId, _texture_data: &Self::TextureData) { fn texture_drop(&self, texture: &Self::TextureId, _texture_data: &Self::TextureData) {
wgc::gfx_select!(texture => self.0.texture_drop(*texture)) self.0.texture_drop(*texture)
} }
fn texture_view_drop( fn texture_view_drop(
@ -1658,15 +1636,15 @@ impl crate::Context for ContextWgpuCore {
texture_view: &Self::TextureViewId, texture_view: &Self::TextureViewId,
__texture_view_data: &Self::TextureViewData, __texture_view_data: &Self::TextureViewData,
) { ) {
let _ = wgc::gfx_select!(*texture_view => self.0.texture_view_drop(*texture_view)); let _ = self.0.texture_view_drop(*texture_view);
} }
fn sampler_drop(&self, sampler: &Self::SamplerId, _sampler_data: &Self::SamplerData) { fn sampler_drop(&self, sampler: &Self::SamplerId, _sampler_data: &Self::SamplerData) {
wgc::gfx_select!(*sampler => self.0.sampler_drop(*sampler)) self.0.sampler_drop(*sampler)
} }
fn query_set_drop(&self, query_set: &Self::QuerySetId, _query_set_data: &Self::QuerySetData) { fn query_set_drop(&self, query_set: &Self::QuerySetId, _query_set_data: &Self::QuerySetData) {
wgc::gfx_select!(*query_set => self.0.query_set_drop(*query_set)) self.0.query_set_drop(*query_set)
} }
fn bind_group_drop( fn bind_group_drop(
@ -1674,7 +1652,7 @@ impl crate::Context for ContextWgpuCore {
bind_group: &Self::BindGroupId, bind_group: &Self::BindGroupId,
_bind_group_data: &Self::BindGroupData, _bind_group_data: &Self::BindGroupData,
) { ) {
wgc::gfx_select!(*bind_group => self.0.bind_group_drop(*bind_group)) self.0.bind_group_drop(*bind_group)
} }
fn bind_group_layout_drop( fn bind_group_layout_drop(
@ -1682,7 +1660,7 @@ impl crate::Context for ContextWgpuCore {
bind_group_layout: &Self::BindGroupLayoutId, bind_group_layout: &Self::BindGroupLayoutId,
_bind_group_layout_data: &Self::BindGroupLayoutData, _bind_group_layout_data: &Self::BindGroupLayoutData,
) { ) {
wgc::gfx_select!(*bind_group_layout => self.0.bind_group_layout_drop(*bind_group_layout)) self.0.bind_group_layout_drop(*bind_group_layout)
} }
fn pipeline_layout_drop( fn pipeline_layout_drop(
@ -1690,14 +1668,14 @@ impl crate::Context for ContextWgpuCore {
pipeline_layout: &Self::PipelineLayoutId, pipeline_layout: &Self::PipelineLayoutId,
_pipeline_layout_data: &Self::PipelineLayoutData, _pipeline_layout_data: &Self::PipelineLayoutData,
) { ) {
wgc::gfx_select!(*pipeline_layout => self.0.pipeline_layout_drop(*pipeline_layout)) self.0.pipeline_layout_drop(*pipeline_layout)
} }
fn shader_module_drop( fn shader_module_drop(
&self, &self,
shader_module: &Self::ShaderModuleId, shader_module: &Self::ShaderModuleId,
_shader_module_data: &Self::ShaderModuleData, _shader_module_data: &Self::ShaderModuleData,
) { ) {
wgc::gfx_select!(*shader_module => self.0.shader_module_drop(*shader_module)) self.0.shader_module_drop(*shader_module)
} }
fn command_encoder_drop( fn command_encoder_drop(
&self, &self,
@ -1705,7 +1683,7 @@ impl crate::Context for ContextWgpuCore {
command_encoder_data: &Self::CommandEncoderData, command_encoder_data: &Self::CommandEncoderData,
) { ) {
if command_encoder_data.open { if command_encoder_data.open {
wgc::gfx_select!(command_encoder => self.0.command_encoder_drop(*command_encoder)) self.0.command_encoder_drop(*command_encoder)
} }
} }
@ -1714,7 +1692,7 @@ impl crate::Context for ContextWgpuCore {
command_buffer: &Self::CommandBufferId, command_buffer: &Self::CommandBufferId,
_command_buffer_data: &Self::CommandBufferData, _command_buffer_data: &Self::CommandBufferData,
) { ) {
wgc::gfx_select!(*command_buffer => self.0.command_buffer_drop(*command_buffer)) self.0.command_buffer_drop(*command_buffer)
} }
fn render_bundle_drop( fn render_bundle_drop(
@ -1722,7 +1700,7 @@ impl crate::Context for ContextWgpuCore {
render_bundle: &Self::RenderBundleId, render_bundle: &Self::RenderBundleId,
_render_bundle_data: &Self::RenderBundleData, _render_bundle_data: &Self::RenderBundleData,
) { ) {
wgc::gfx_select!(*render_bundle => self.0.render_bundle_drop(*render_bundle)) self.0.render_bundle_drop(*render_bundle)
} }
fn compute_pipeline_drop( fn compute_pipeline_drop(
@ -1730,7 +1708,7 @@ impl crate::Context for ContextWgpuCore {
pipeline: &Self::ComputePipelineId, pipeline: &Self::ComputePipelineId,
_pipeline_data: &Self::ComputePipelineData, _pipeline_data: &Self::ComputePipelineData,
) { ) {
wgc::gfx_select!(*pipeline => self.0.compute_pipeline_drop(*pipeline)) self.0.compute_pipeline_drop(*pipeline)
} }
fn render_pipeline_drop( fn render_pipeline_drop(
@ -1738,7 +1716,7 @@ impl crate::Context for ContextWgpuCore {
pipeline: &Self::RenderPipelineId, pipeline: &Self::RenderPipelineId,
_pipeline_data: &Self::RenderPipelineData, _pipeline_data: &Self::RenderPipelineData,
) { ) {
wgc::gfx_select!(*pipeline => self.0.render_pipeline_drop(*pipeline)) self.0.render_pipeline_drop(*pipeline)
} }
fn pipeline_cache_drop( fn pipeline_cache_drop(
@ -1746,7 +1724,7 @@ impl crate::Context for ContextWgpuCore {
cache: &Self::PipelineCacheId, cache: &Self::PipelineCacheId,
_cache_data: &Self::PipelineCacheData, _cache_data: &Self::PipelineCacheData,
) { ) {
wgc::gfx_select!(*cache => self.0.pipeline_cache_drop(*cache)) self.0.pipeline_cache_drop(*cache)
} }
fn compute_pipeline_get_bind_group_layout( fn compute_pipeline_get_bind_group_layout(
@ -1755,7 +1733,9 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::ComputePipelineData, _pipeline_data: &Self::ComputePipelineData,
index: u32, index: u32,
) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) {
let (id, error) = wgc::gfx_select!(*pipeline => self.0.compute_pipeline_get_bind_group_layout(*pipeline, index, None)); let (id, error) = self
.0
.compute_pipeline_get_bind_group_layout(*pipeline, index, None);
if let Some(err) = error { if let Some(err) = error {
panic!("Error reflecting bind group {index}: {err}"); panic!("Error reflecting bind group {index}: {err}");
} }
@ -1768,7 +1748,9 @@ impl crate::Context for ContextWgpuCore {
_pipeline_data: &Self::RenderPipelineData, _pipeline_data: &Self::RenderPipelineData,
index: u32, index: u32,
) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) { ) -> (Self::BindGroupLayoutId, Self::BindGroupLayoutData) {
let (id, error) = wgc::gfx_select!(*pipeline => self.0.render_pipeline_get_bind_group_layout(*pipeline, index, None)); let (id, error) = self
.0
.render_pipeline_get_bind_group_layout(*pipeline, index, None);
if let Some(err) = error { if let Some(err) = error {
panic!("Error reflecting bind group {index}: {err}"); panic!("Error reflecting bind group {index}: {err}");
} }
@ -1787,14 +1769,14 @@ impl crate::Context for ContextWgpuCore {
destination_offset: wgt::BufferAddress, destination_offset: wgt::BufferAddress,
copy_size: wgt::BufferAddress, copy_size: wgt::BufferAddress,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_copy_buffer_to_buffer( if let Err(cause) = self.0.command_encoder_copy_buffer_to_buffer(
*encoder, *encoder,
*source, *source,
source_offset, source_offset,
*destination, *destination,
destination_offset, destination_offset,
copy_size copy_size,
)) { ) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -1811,12 +1793,12 @@ impl crate::Context for ContextWgpuCore {
destination: crate::ImageCopyTexture<'_>, destination: crate::ImageCopyTexture<'_>,
copy_size: wgt::Extent3d, copy_size: wgt::Extent3d,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_copy_buffer_to_texture( if let Err(cause) = self.0.command_encoder_copy_buffer_to_texture(
*encoder, *encoder,
&map_buffer_copy_view(source), &map_buffer_copy_view(source),
&map_texture_copy_view(destination), &map_texture_copy_view(destination),
&copy_size &copy_size,
)) { ) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -1833,12 +1815,12 @@ impl crate::Context for ContextWgpuCore {
destination: crate::ImageCopyBuffer<'_>, destination: crate::ImageCopyBuffer<'_>,
copy_size: wgt::Extent3d, copy_size: wgt::Extent3d,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_copy_texture_to_buffer( if let Err(cause) = self.0.command_encoder_copy_texture_to_buffer(
*encoder, *encoder,
&map_texture_copy_view(source), &map_texture_copy_view(source),
&map_buffer_copy_view(destination), &map_buffer_copy_view(destination),
&copy_size &copy_size,
)) { ) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -1855,12 +1837,12 @@ impl crate::Context for ContextWgpuCore {
destination: crate::ImageCopyTexture<'_>, destination: crate::ImageCopyTexture<'_>,
copy_size: wgt::Extent3d, copy_size: wgt::Extent3d,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_copy_texture_to_texture( if let Err(cause) = self.0.command_encoder_copy_texture_to_texture(
*encoder, *encoder,
&map_texture_copy_view(source), &map_texture_copy_view(source),
&map_texture_copy_view(destination), &map_texture_copy_view(destination),
&copy_size &copy_size,
)) { ) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -1884,10 +1866,13 @@ impl crate::Context for ContextWgpuCore {
end_of_pass_write_index: tw.end_of_pass_write_index, end_of_pass_write_index: tw.end_of_pass_write_index,
}); });
let (pass, err) = gfx_select!(encoder => self.0.command_encoder_create_compute_pass_dyn(*encoder, &wgc::command::ComputePassDescriptor { let (pass, err) = self.0.command_encoder_create_compute_pass_dyn(
label: desc.label.map(Borrowed), *encoder,
timestamp_writes: timestamp_writes.as_ref(), &wgc::command::ComputePassDescriptor {
})); label: desc.label.map(Borrowed),
timestamp_writes: timestamp_writes.as_ref(),
},
);
if let Some(cause) = err { if let Some(cause) = err {
self.handle_error( self.handle_error(
@ -1943,13 +1928,18 @@ impl crate::Context for ContextWgpuCore {
end_of_pass_write_index: tw.end_of_pass_write_index, end_of_pass_write_index: tw.end_of_pass_write_index,
}); });
let (pass, err) = gfx_select!(encoder => self.0.command_encoder_create_render_pass_dyn(*encoder, &wgc::command::RenderPassDescriptor { let (pass, err) = self.0.command_encoder_create_render_pass_dyn(
label: desc.label.map(Borrowed), *encoder,
timestamp_writes: timestamp_writes.as_ref(), &wgc::command::RenderPassDescriptor {
color_attachments: std::borrow::Cow::Borrowed(&colors), label: desc.label.map(Borrowed),
depth_stencil_attachment: depth_stencil.as_ref(), timestamp_writes: timestamp_writes.as_ref(),
occlusion_query_set: desc.occlusion_query_set.map(|query_set| query_set.id.into()), color_attachments: std::borrow::Cow::Borrowed(&colors),
})); depth_stencil_attachment: depth_stencil.as_ref(),
occlusion_query_set: desc
.occlusion_query_set
.map(|query_set| query_set.id.into()),
},
);
if let Some(cause) = err { if let Some(cause) = err {
self.handle_error( self.handle_error(
@ -1976,8 +1966,7 @@ impl crate::Context for ContextWgpuCore {
) -> (Self::CommandBufferId, Self::CommandBufferData) { ) -> (Self::CommandBufferId, Self::CommandBufferData) {
let descriptor = wgt::CommandBufferDescriptor::default(); let descriptor = wgt::CommandBufferDescriptor::default();
encoder_data.open = false; // prevent the drop encoder_data.open = false; // prevent the drop
let (id, error) = let (id, error) = self.0.command_encoder_finish(encoder, &descriptor);
wgc::gfx_select!(encoder => self.0.command_encoder_finish(encoder, &descriptor));
if let Some(cause) = error { if let Some(cause) = error {
self.handle_error_nolabel(&encoder_data.error_sink, cause, "a CommandEncoder"); self.handle_error_nolabel(&encoder_data.error_sink, cause, "a CommandEncoder");
} }
@ -1991,11 +1980,10 @@ impl crate::Context for ContextWgpuCore {
texture: &crate::Texture, texture: &crate::Texture,
subresource_range: &wgt::ImageSubresourceRange, subresource_range: &wgt::ImageSubresourceRange,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_clear_texture( if let Err(cause) =
*encoder, self.0
texture.id.into(), .command_encoder_clear_texture(*encoder, texture.id.into(), subresource_range)
subresource_range {
)) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2012,11 +2000,10 @@ impl crate::Context for ContextWgpuCore {
offset: wgt::BufferAddress, offset: wgt::BufferAddress,
size: Option<wgt::BufferAddress>, size: Option<wgt::BufferAddress>,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_clear_buffer( if let Err(cause) =
*encoder, self.0
buffer.id.into(), .command_encoder_clear_buffer(*encoder, buffer.id.into(), offset, size)
offset, size {
)) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2031,9 +2018,7 @@ impl crate::Context for ContextWgpuCore {
encoder_data: &Self::CommandEncoderData, encoder_data: &Self::CommandEncoderData,
label: &str, label: &str,
) { ) {
if let Err(cause) = if let Err(cause) = self.0.command_encoder_insert_debug_marker(*encoder, label) {
wgc::gfx_select!(encoder => self.0.command_encoder_insert_debug_marker(*encoder, label))
{
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2048,9 +2033,7 @@ impl crate::Context for ContextWgpuCore {
encoder_data: &Self::CommandEncoderData, encoder_data: &Self::CommandEncoderData,
label: &str, label: &str,
) { ) {
if let Err(cause) = if let Err(cause) = self.0.command_encoder_push_debug_group(*encoder, label) {
wgc::gfx_select!(encoder => self.0.command_encoder_push_debug_group(*encoder, label))
{
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2064,9 +2047,7 @@ impl crate::Context for ContextWgpuCore {
encoder: &Self::CommandEncoderId, encoder: &Self::CommandEncoderId,
encoder_data: &Self::CommandEncoderData, encoder_data: &Self::CommandEncoderData,
) { ) {
if let Err(cause) = if let Err(cause) = self.0.command_encoder_pop_debug_group(*encoder) {
wgc::gfx_select!(encoder => self.0.command_encoder_pop_debug_group(*encoder))
{
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2083,11 +2064,10 @@ impl crate::Context for ContextWgpuCore {
_query_set_data: &Self::QuerySetData, _query_set_data: &Self::QuerySetData,
query_index: u32, query_index: u32,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_write_timestamp( if let Err(cause) =
*encoder, self.0
*query_set, .command_encoder_write_timestamp(*encoder, *query_set, query_index)
query_index {
)) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2108,14 +2088,14 @@ impl crate::Context for ContextWgpuCore {
_destination_data: &Self::BufferData, _destination_data: &Self::BufferData,
destination_offset: wgt::BufferAddress, destination_offset: wgt::BufferAddress,
) { ) {
if let Err(cause) = wgc::gfx_select!(encoder => self.0.command_encoder_resolve_query_set( if let Err(cause) = self.0.command_encoder_resolve_query_set(
*encoder, *encoder,
*query_set, *query_set,
first_query, first_query,
query_count, query_count,
*destination, *destination,
destination_offset destination_offset,
)) { ) {
self.handle_error_nolabel( self.handle_error_nolabel(
&encoder_data.error_sink, &encoder_data.error_sink,
cause, cause,
@ -2130,11 +2110,11 @@ impl crate::Context for ContextWgpuCore {
encoder_data: Self::RenderBundleEncoderData, encoder_data: Self::RenderBundleEncoderData,
desc: &crate::RenderBundleDescriptor<'_>, desc: &crate::RenderBundleDescriptor<'_>,
) -> (Self::RenderBundleId, Self::RenderBundleData) { ) -> (Self::RenderBundleId, Self::RenderBundleData) {
let (id, error) = wgc::gfx_select!(encoder_data.parent() => self.0.render_bundle_encoder_finish( let (id, error) = self.0.render_bundle_encoder_finish(
encoder_data, encoder_data,
&desc.map_label(|l| l.map(Borrowed)), &desc.map_label(|l| l.map(Borrowed)),
None None,
)); );
if let Some(err) = error { if let Some(err) = error {
self.handle_error_fatal(err, "RenderBundleEncoder::finish"); self.handle_error_fatal(err, "RenderBundleEncoder::finish");
} }
@ -2150,9 +2130,7 @@ impl crate::Context for ContextWgpuCore {
offset: wgt::BufferAddress, offset: wgt::BufferAddress,
data: &[u8], data: &[u8],
) { ) {
match wgc::gfx_select!( match self.0.queue_write_buffer(*queue, *buffer, offset, data) {
*queue => self.0.queue_write_buffer(*queue, *buffer, offset, data)
) {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer") self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer")
@ -2169,9 +2147,10 @@ impl crate::Context for ContextWgpuCore {
offset: wgt::BufferAddress, offset: wgt::BufferAddress,
size: wgt::BufferSize, size: wgt::BufferSize,
) -> Option<()> { ) -> Option<()> {
match wgc::gfx_select!( match self
*queue => self.0.queue_validate_write_buffer(*queue, *buffer, offset, size) .0
) { .queue_validate_write_buffer(*queue, *buffer, offset, size)
{
Ok(()) => Some(()), Ok(()) => Some(()),
Err(err) => { Err(err) => {
self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with"); self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with");
@ -2186,9 +2165,7 @@ impl crate::Context for ContextWgpuCore {
queue_data: &Self::QueueData, queue_data: &Self::QueueData,
size: wgt::BufferSize, size: wgt::BufferSize,
) -> Option<Box<dyn crate::context::QueueWriteBuffer>> { ) -> Option<Box<dyn crate::context::QueueWriteBuffer>> {
match wgc::gfx_select!( match self.0.queue_create_staging_buffer(*queue, size, None) {
*queue => self.0.queue_create_staging_buffer(*queue, size, None)
) {
Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer { Ok((buffer_id, ptr)) => Some(Box::new(QueueWriteBuffer {
buffer_id, buffer_id,
mapping: BufferMappedRange { mapping: BufferMappedRange {
@ -2216,9 +2193,10 @@ impl crate::Context for ContextWgpuCore {
.as_any() .as_any()
.downcast_ref::<QueueWriteBuffer>() .downcast_ref::<QueueWriteBuffer>()
.unwrap(); .unwrap();
match wgc::gfx_select!( match self
*queue => self.0.queue_write_staging_buffer(*queue, *buffer, offset, staging_buffer.buffer_id) .0
) { .queue_write_staging_buffer(*queue, *buffer, offset, staging_buffer.buffer_id)
{
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with"); self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_buffer_with");
@ -2235,13 +2213,13 @@ impl crate::Context for ContextWgpuCore {
data_layout: wgt::ImageDataLayout, data_layout: wgt::ImageDataLayout,
size: wgt::Extent3d, size: wgt::Extent3d,
) { ) {
match wgc::gfx_select!(*queue => self.0.queue_write_texture( match self.0.queue_write_texture(
*queue, *queue,
&map_texture_copy_view(texture), &map_texture_copy_view(texture),
data, data,
&data_layout, &data_layout,
&size &size,
)) { ) {
Ok(()) => (), Ok(()) => (),
Err(err) => { Err(err) => {
self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_texture") self.handle_error_nolabel(&queue_data.error_sink, err, "Queue::write_texture")
@ -2258,12 +2236,12 @@ impl crate::Context for ContextWgpuCore {
dest: crate::ImageCopyTextureTagged<'_>, dest: crate::ImageCopyTextureTagged<'_>,
size: wgt::Extent3d, size: wgt::Extent3d,
) { ) {
match wgc::gfx_select!(*queue => self.0.queue_copy_external_image_to_texture( match self.0.queue_copy_external_image_to_texture(
*queue, *queue,
source, source,
map_texture_tagged_copy_view(dest), map_texture_tagged_copy_view(dest),
size size,
)) { ) {
Ok(()) => (), Ok(()) => (),
Err(err) => self.handle_error_nolabel( Err(err) => self.handle_error_nolabel(
&queue_data.error_sink, &queue_data.error_sink,
@ -2283,14 +2261,13 @@ impl crate::Context for ContextWgpuCore {
.map(|(i, _)| i) .map(|(i, _)| i)
.collect::<SmallVec<[_; 4]>>(); .collect::<SmallVec<[_; 4]>>();
let index = match wgc::gfx_select!(*queue => self.0.queue_submit(*queue, &temp_command_buffers)) let index = match self.0.queue_submit(*queue, &temp_command_buffers) {
{
Ok(index) => index, Ok(index) => index,
Err(err) => self.handle_error_fatal(err, "Queue::submit"), Err(err) => self.handle_error_fatal(err, "Queue::submit"),
}; };
for cmdbuf in &temp_command_buffers { for cmdbuf in &temp_command_buffers {
wgc::gfx_select!(*queue => self.0.command_buffer_drop(*cmdbuf)); self.0.command_buffer_drop(*cmdbuf);
} }
index index
@ -2301,9 +2278,7 @@ impl crate::Context for ContextWgpuCore {
queue: &Self::QueueId, queue: &Self::QueueId,
_queue_data: &Self::QueueData, _queue_data: &Self::QueueData,
) -> f32 { ) -> f32 {
let res = wgc::gfx_select!(queue => self.0.queue_get_timestamp_period( let res = self.0.queue_get_timestamp_period(*queue);
*queue
));
match res { match res {
Ok(v) => v, Ok(v) => v,
Err(cause) => { Err(cause) => {
@ -2320,18 +2295,18 @@ impl crate::Context for ContextWgpuCore {
) { ) {
let closure = wgc::device::queue::SubmittedWorkDoneClosure::from_rust(callback); let closure = wgc::device::queue::SubmittedWorkDoneClosure::from_rust(callback);
let res = wgc::gfx_select!(queue => self.0.queue_on_submitted_work_done(*queue, closure)); let res = self.0.queue_on_submitted_work_done(*queue, closure);
if let Err(cause) = res { if let Err(cause) = res {
self.handle_error_fatal(cause, "Queue::on_submitted_work_done"); self.handle_error_fatal(cause, "Queue::on_submitted_work_done");
} }
} }
fn device_start_capture(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_start_capture(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
wgc::gfx_select!(device => self.0.device_start_capture(*device)); self.0.device_start_capture(*device);
} }
fn device_stop_capture(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_stop_capture(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
wgc::gfx_select!(device => self.0.device_stop_capture(*device)); self.0.device_stop_capture(*device);
} }
fn device_get_internal_counters( fn device_get_internal_counters(
@ -2339,7 +2314,7 @@ impl crate::Context for ContextWgpuCore {
device: &Self::DeviceId, device: &Self::DeviceId,
_device_data: &Self::DeviceData, _device_data: &Self::DeviceData,
) -> wgt::InternalCounters { ) -> wgt::InternalCounters {
wgc::gfx_select!(device => self.0.device_get_internal_counters(*device)) self.0.device_get_internal_counters(*device)
} }
fn device_generate_allocator_report( fn device_generate_allocator_report(
@ -2347,7 +2322,7 @@ impl crate::Context for ContextWgpuCore {
device: &Self::DeviceId, device: &Self::DeviceId,
_device_data: &Self::DeviceData, _device_data: &Self::DeviceData,
) -> Option<wgt::AllocatorReport> { ) -> Option<wgt::AllocatorReport> {
wgc::gfx_select!(device => self.0.device_generate_allocator_report(*device)) self.0.device_generate_allocator_report(*device)
} }
fn pipeline_cache_get_data( fn pipeline_cache_get_data(
@ -2356,7 +2331,7 @@ impl crate::Context for ContextWgpuCore {
// TODO: Used for error handling? // TODO: Used for error handling?
_cache_data: &Self::PipelineCacheData, _cache_data: &Self::PipelineCacheData,
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
wgc::gfx_select!(cache => self.0.pipeline_cache_get_data(*cache)) self.0.pipeline_cache_get_data(*cache)
} }
fn compute_pass_set_pipeline( fn compute_pass_set_pipeline(