mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
refactor: satisfy clippy::missing_transmute_annotations
(#6024)
* refactor(metal): satisfy `clippy::missing_transmute_annotations` * refactor(gles): satisfy `clippy::missing_transmute_annotations` * refactor(metal): `metal::Surface::view`: use `ptr::cast` instead of `as`
This commit is contained in:
parent
9b680e6997
commit
7b2e08fb94
@ -577,9 +577,20 @@ impl Global {
|
||||
metal: Some(self.instance.metal.as_ref().map_or(
|
||||
Err(CreateSurfaceError::BackendNotEnabled(Backend::Metal)),
|
||||
|inst| {
|
||||
// we don't want to link to metal-rs for this
|
||||
#[allow(clippy::transmute_ptr_to_ref)]
|
||||
Ok(inst.create_surface_from_layer(unsafe { std::mem::transmute(layer) }))
|
||||
let layer = layer.cast();
|
||||
// SAFETY: We do this cast and deref. (rather than using `metal` to get the
|
||||
// object we want) to avoid direct coupling on the `metal` crate.
|
||||
//
|
||||
// To wit, this pointer…
|
||||
//
|
||||
// - …is properly aligned.
|
||||
// - …is dereferenceable to a `MetalLayerRef` as an invariant of the `metal`
|
||||
// field.
|
||||
// - …points to an _initialized_ `MetalLayerRef`.
|
||||
// - …is only ever aliased via an immutable reference that lives within this
|
||||
// lexical scope.
|
||||
let layer = unsafe { &*layer };
|
||||
Ok(inst.create_surface_from_layer(layer))
|
||||
},
|
||||
)?),
|
||||
#[cfg(dx12)]
|
||||
|
@ -9,8 +9,6 @@ use std::{
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
#[cfg(native)]
|
||||
use std::mem;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
type ShaderStage<'a> = (
|
||||
@ -178,9 +176,7 @@ impl super::Device {
|
||||
let raw = unsafe { gl.create_shader(target) }.unwrap();
|
||||
#[cfg(native)]
|
||||
if gl.supports_debug() {
|
||||
//TODO: remove all transmutes from `object_label`
|
||||
// https://github.com/grovesNL/glow/issues/186
|
||||
let name = unsafe { mem::transmute(raw) };
|
||||
let name = raw.0.get();
|
||||
unsafe { gl.object_label(glow::SHADER, name, label) };
|
||||
}
|
||||
|
||||
@ -366,7 +362,7 @@ impl super::Device {
|
||||
#[cfg(native)]
|
||||
if let Some(label) = label {
|
||||
if private_caps.contains(PrivateCapabilities::DEBUG_FNS) {
|
||||
let name = unsafe { mem::transmute(program) };
|
||||
let name = program.0.get();
|
||||
unsafe { gl.object_label(glow::PROGRAM, name, Some(label)) };
|
||||
}
|
||||
}
|
||||
@ -621,7 +617,7 @@ impl crate::Device for super::Device {
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::DEBUG_FNS)
|
||||
{
|
||||
let name = unsafe { mem::transmute(raw) };
|
||||
let name = raw.map_or(0, |buf| buf.0.get());
|
||||
unsafe { gl.object_label(glow::BUFFER, name, Some(label)) };
|
||||
}
|
||||
}
|
||||
@ -768,7 +764,7 @@ impl crate::Device for super::Device {
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::DEBUG_FNS)
|
||||
{
|
||||
let name = unsafe { mem::transmute(raw) };
|
||||
let name = raw.0.get();
|
||||
unsafe { gl.object_label(glow::RENDERBUFFER, name, Some(label)) };
|
||||
}
|
||||
}
|
||||
@ -936,7 +932,7 @@ impl crate::Device for super::Device {
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::DEBUG_FNS)
|
||||
{
|
||||
let name = unsafe { mem::transmute(raw) };
|
||||
let name = raw.0.get();
|
||||
unsafe { gl.object_label(glow::TEXTURE, name, Some(label)) };
|
||||
}
|
||||
}
|
||||
@ -1088,7 +1084,7 @@ impl crate::Device for super::Device {
|
||||
.private_caps
|
||||
.contains(PrivateCapabilities::DEBUG_FNS)
|
||||
{
|
||||
let name = unsafe { mem::transmute(raw) };
|
||||
let name = raw.0.get();
|
||||
unsafe { gl.object_label(glow::SAMPLER, name, Some(label)) };
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(clippy::let_unit_value)] // `let () =` being used to constrain result type
|
||||
|
||||
use std::{mem, os::raw::c_void, ptr::NonNull, sync::Once, thread};
|
||||
use std::{os::raw::c_void, ptr::NonNull, sync::Once, thread};
|
||||
|
||||
use core_graphics_types::{
|
||||
base::CGFloat,
|
||||
@ -82,10 +82,19 @@ impl super::Surface {
|
||||
view: *mut c_void,
|
||||
delegate: Option<&HalManagedMetalLayerDelegate>,
|
||||
) -> Self {
|
||||
let view = view as *mut Object;
|
||||
let view = view.cast::<Object>();
|
||||
let render_layer = {
|
||||
let layer = unsafe { Self::get_metal_layer(view, delegate) };
|
||||
unsafe { mem::transmute::<_, &metal::MetalLayerRef>(layer) }
|
||||
let layer = layer.cast::<metal::MetalLayerRef>();
|
||||
// SAFETY: This pointer…
|
||||
//
|
||||
// - …is properly aligned.
|
||||
// - …is dereferenceable to a `MetalLayerRef` as an invariant of the `metal`
|
||||
// field.
|
||||
// - …points to an _initialized_ `MetalLayerRef`.
|
||||
// - …is only ever aliased via an immutable reference that lives within this
|
||||
// lexical scope.
|
||||
unsafe { &*layer }
|
||||
}
|
||||
.to_owned();
|
||||
let _: *mut c_void = msg_send![view, retain];
|
||||
|
Loading…
Reference in New Issue
Block a user