Manual Send and Sync for Hub and Command{Encoder,Buffer}

This commit is contained in:
Andy Leiserson committed 2026-09-01 12:34:12 -07:00
1 parent 9dcfed254b
commit 72e752090e
2 files changed
+98

No files matched your search

+40
View File
@@ -534,6 +534,26 @@ crate::impl_labeled!(CommandEncoder);
crate::impl_parent_device!(CommandEncoder);
crate::impl_storage_item!(CommandEncoder);
#[cfg(send_sync)]
const _: () = {
// SAFETY: Bounds checked below
unsafe impl Send for CommandEncoder {}
// SAFETY: Bounds checked below
unsafe impl Sync for CommandEncoder {}
fn _command_encoder_fields_are_send_sync(obj: &CommandEncoder) {
fn _check_bound<T: Send + Sync>(_: &T) {}
let CommandEncoder {
device,
label,
data,
} = obj;
_check_bound(device);
_check_bound(label);
_check_bound(data);
}
};
impl Drop for CommandEncoder {
fn drop(&mut self) {
resource_log!("Drop {}", self.error_ident());
@@ -902,6 +922,26 @@ pub struct CommandBuffer {
pub(crate) data: Mutex<CommandEncoderStatus>,
}
#[cfg(send_sync)]
const _: () = {
// SAFETY: Bounds checked below
unsafe impl Send for CommandBuffer {}
// SAFETY: Bounds checked below
unsafe impl Sync for CommandBuffer {}
fn _command_buffer_fields_are_send_sync(obj: &CommandBuffer) {
fn _check_bound<T: Send + Sync>(_: &T) {}
let CommandBuffer {
device,
label,
data,
} = obj;
_check_bound(device);
_check_bound(label);
_check_bound(data);
}
};
impl Drop for CommandBuffer {
fn drop(&mut self) {
resource_log!("Drop {}", self.error_ident());
+58
View File
@@ -259,3 +259,61 @@ impl Hub {
}
}
}
#[cfg(send_sync)]
const _: () = {
// SAFETY: Bounds checked below
unsafe impl Send for Hub {}
// SAFETY: Bounds checked below
unsafe impl Sync for Hub {}
fn _hub_fields_are_send_sync(hub: &Hub) {
fn _check_bound<T: Send + Sync>(_: &T) {}
let Hub {
adapters,
devices,
queues,
pipeline_layouts,
shader_modules,
bind_group_layouts,
bind_groups,
command_encoders,
command_buffers,
render_bundles,
render_pipelines,
compute_pipelines,
pipeline_caches,
query_sets,
buffers,
staging_buffers,
textures,
texture_views,
external_textures,
samplers,
blas_s,
tlas_s,
} = hub;
_check_bound(adapters);
_check_bound(devices);
_check_bound(queues);
_check_bound(pipeline_layouts);
_check_bound(shader_modules);
_check_bound(bind_group_layouts);
_check_bound(bind_groups);
_check_bound(command_encoders);
_check_bound(command_buffers);
_check_bound(render_bundles);
_check_bound(render_pipelines);
_check_bound(compute_pipelines);
_check_bound(pipeline_caches);
_check_bound(query_sets);
_check_bound(buffers);
_check_bound(staging_buffers);
_check_bound(textures);
_check_bound(texture_views);
_check_bound(external_textures);
_check_bound(samplers);
_check_bound(blas_s);
_check_bound(tlas_s);
}
};