mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 15:00:57 +01:00
Implement Send for WriteOnly<T> even when T is not Sized. (#10163)
This commit is contained in:
1 parent
454703a968
commit
f25209582c
2 files changed
+15
-2
No files matched your search
@@ -68,6 +68,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
|
||||
- Many types now offer `pub const fn default()` in addition to implementing the `Default` trait, allowing constants to make use of default values. By @kpreid in [#9929](https://github.com/gfx-rs/wgpu/pull/9929).
|
||||
- `wgpu-core` now exposes `validate_device_descriptor` and `validate_texture_descriptor` functions that perform the same descriptor validation the corresponding resource creation APIs would, without actually creating a resource. This may be useful in conjunction with hal raw APIs. By @andyleiserson in [#9967](https://github.com/gfx-rs/wgpu/pull/9967) and [#9979](https://github.com/gfx-rs/wgpu/pull/9979).
|
||||
- Added `TextureDescriptor::theoretical_memory_footprint` to estimate memory footprint of a texture. By @sagudev in [#10032](https://github.com/gfx-rs/wgpu/pull/10032).
|
||||
- `wgpu::WriteOnly<[_]>` now implements `Send`. By @kpreid in [#10163](https://github.com/gfx-rs/wgpu/pull/10163).
|
||||
|
||||
#### Hal
|
||||
|
||||
|
||||
@@ -65,10 +65,11 @@ pub struct WriteOnly<'a, T: ?Sized> {
|
||||
// `WriteOnly<T>` is like `&mut T` in that
|
||||
// * It provides only exclusive access to the memory it points to, so `T: Sync` is not required.
|
||||
// * Sending it creates the opportunity to send a `T`, so `T: Send` is required.
|
||||
unsafe impl<T: Send> Send for WriteOnly<'_, T> {}
|
||||
unsafe impl<T: ?Sized + Send> Send for WriteOnly<'_, T> {}
|
||||
|
||||
// SAFETY:
|
||||
// `WriteOnly<T>` does not ever expose any `&T`, and therefore may unconditionally implement `Sync`.
|
||||
// `WriteOnly<T>` does not offer interior mutability itself, and does not ever expose any `&T`,
|
||||
// so there is no possibility of unsynchronized access for `!Sync` to protect against.
|
||||
unsafe impl<T: ?Sized> Sync for WriteOnly<'_, T> {}
|
||||
|
||||
impl<'a, T: ?Sized> WriteOnly<'a, T> {
|
||||
@@ -855,6 +856,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
// Check trait impls, particularly for a `!Sized` pointee type.
|
||||
static_assertions::assert_not_impl_any!(WriteOnly<'static, [u8]>: Clone, Copy);
|
||||
static_assertions::assert_impl_all!(WriteOnly<'static, [u8]>: Send, Sync);
|
||||
|
||||
#[test]
|
||||
fn debug() {
|
||||
let mut arr = [1u8, 2, 3];
|
||||
@@ -870,6 +875,13 @@ mod tests {
|
||||
format!("{:#?}", WriteOnly::from_mut(&mut arr[0])),
|
||||
"WriteOnly(u8)"
|
||||
);
|
||||
|
||||
struct NotImplDebug;
|
||||
let mut not = NotImplDebug;
|
||||
assert_eq!(
|
||||
format!("{:#?}", WriteOnly::from_mut(&mut not)),
|
||||
"WriteOnly(wgpu_types::write_only::tests::debug::NotImplDebug)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user