From 46b121667bf8b5830fd4b76877f98187ddd4582e Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 30 Nov 2022 14:48:03 -0700 Subject: [PATCH] refactor(dx12): remove `unsafe` ops in `Adapter::texture_format_capabilities` (#3194) --- wgpu-hal/src/dx12/adapter.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 236fec49c3..60efdffab4 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -2,9 +2,9 @@ use crate::{ auxil::{self, dxgi::result::HResult as _}, dx12::SurfaceTarget, }; -use std::{mem, sync::Arc, thread}; +use std::{mem, ptr, sync::Arc, thread}; use winapi::{ - shared::{dxgi, dxgi1_2, windef, winerror}, + shared::{dxgi, dxgi1_2, minwindef::DWORD, windef, winerror}, um::{d3d12, d3d12sdklayers, winuser}, }; @@ -382,16 +382,17 @@ impl crate::Adapter for super::Adapter { // the features that use SRV/UAVs using the no-depth format. let mut data_no_depth = d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: no_depth_format, - Support1: unsafe { mem::zeroed() }, - Support2: unsafe { mem::zeroed() }, + Support1: d3d12::D3D12_FORMAT_SUPPORT1_NONE, + Support2: d3d12::D3D12_FORMAT_SUPPORT2_NONE, }; if raw_format != no_depth_format { // Only-recheck if we're using a different format assert_eq!(winerror::S_OK, unsafe { self.device.CheckFeatureSupport( d3d12::D3D12_FEATURE_FORMAT_SUPPORT, - &mut data_no_depth as *mut _ as *mut _, - mem::size_of::() as _, + ptr::addr_of_mut!(data_no_depth).cast(), + DWORD::try_from(mem::size_of::()) + .unwrap(), ) }); } else {