From 7e2fc3432b96f419d22534d41d8ad80edf1fa572 Mon Sep 17 00:00:00 2001 From: Vecvec Date: Wed, 11 Sep 2024 16:43:05 +1200 Subject: [PATCH] fix clippy warnings --- wgpu-hal/src/dx12/command.rs | 106 ++++++++++++++++------------- wgpu-hal/src/dx12/device.rs | 16 +++-- wgpu-hal/src/dx12/suballocation.rs | 2 +- 3 files changed, 70 insertions(+), 54 deletions(-) diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index 5229a17fdc..8e17fbf04c 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -1256,12 +1256,14 @@ impl crate::CommandEncoder for super::CommandEncoder { Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL, Direct3D12::D3D12_ELEMENTS_LAYOUT::default(), Direct3D12::D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS_0 { - InstanceDescs: instances - .buffer - .expect("needs buffer to build") - .resource - .GetGPUVirtualAddress() - + instances.offset as u64, + InstanceDescs: unsafe { + instances + .buffer + .expect("needs buffer to build") + .resource + .GetGPUVirtualAddress() + + instances.offset as u64 + }, }, instances.count, ), @@ -1275,7 +1277,7 @@ impl crate::CommandEncoder for super::CommandEncoder { Triangles: Direct3D12::D3D12_RAYTRACING_GEOMETRY_TRIANGLES_DESC { Transform3x4: triangle.transform.as_ref().map_or( 0, - |transform| { + |transform| unsafe { transform.buffer.resource.GetGPUVirtualAddress() + transform.offset as u64 }, @@ -1295,22 +1297,26 @@ impl crate::CommandEncoder for super::CommandEncoder { .map_or(0, |indices| indices.count), VertexCount: triangle.vertex_count, IndexBuffer: triangle.indices.as_ref().map_or(0, |indices| { - indices - .buffer - .expect("needs buffer to build") - .resource - .GetGPUVirtualAddress() - + indices.offset as u64 - }), - VertexBuffer: - Direct3D12::D3D12_GPU_VIRTUAL_ADDRESS_AND_STRIDE { - StartAddress: triangle - .vertex_buffer + unsafe { + indices + .buffer .expect("needs buffer to build") .resource .GetGPUVirtualAddress() - + (triangle.first_vertex as u64 - * triangle.vertex_stride), + + indices.offset as u64 + } + }), + VertexBuffer: + Direct3D12::D3D12_GPU_VIRTUAL_ADDRESS_AND_STRIDE { + StartAddress: unsafe { + triangle + .vertex_buffer + .expect("needs buffer to build") + .resource + .GetGPUVirtualAddress() + + (triangle.first_vertex as u64 + * triangle.vertex_stride) + }, StrideInBytes: triangle.vertex_stride, }, }, @@ -1336,12 +1342,14 @@ impl crate::CommandEncoder for super::CommandEncoder { AABBs: Direct3D12::D3D12_RAYTRACING_GEOMETRY_AABBS_DESC { AABBCount: aabb.count as u64, AABBs: Direct3D12::D3D12_GPU_VIRTUAL_ADDRESS_AND_STRIDE { - StartAddress: aabb - .buffer - .expect("needs buffer to build") - .resource - .GetGPUVirtualAddress() - + (aabb.offset as u64 * aabb.stride), + StartAddress: unsafe { + aabb + .buffer + .expect("needs buffer to build") + .resource + .GetGPUVirtualAddress() + + (aabb.offset as u64 * aabb.stride) + }, StrideInBytes: aabb.stride, }, }, @@ -1367,22 +1375,26 @@ impl crate::CommandEncoder for super::CommandEncoder { Anonymous: inputs0, }; let desc = Direct3D12::D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC { - DestAccelerationStructureData: descriptor - .destination_acceleration_structure - .resource - .GetGPUVirtualAddress(), + DestAccelerationStructureData: unsafe { + descriptor + .destination_acceleration_structure + .resource + .GetGPUVirtualAddress() + }, Inputs: acceleration_structure_inputs, SourceAccelerationStructureData: descriptor .source_acceleration_structure .as_ref() - .map_or(0, |source| source.resource.GetGPUVirtualAddress()), - ScratchAccelerationStructureData: descriptor - .scratch_buffer - .resource - .GetGPUVirtualAddress() - + descriptor.scratch_buffer_offset, + .map_or(0, |source| unsafe { source.resource.GetGPUVirtualAddress() }), + ScratchAccelerationStructureData: unsafe { + descriptor + .scratch_buffer + .resource + .GetGPUVirtualAddress() + + descriptor.scratch_buffer_offset + }, }; - list.BuildRaytracingAccelerationStructure(&desc, None); + unsafe { list.BuildRaytracingAccelerationStructure(&desc, None) }; } } @@ -1396,14 +1408,16 @@ impl crate::CommandEncoder for super::CommandEncoder { .unwrap() .cast::() .unwrap(); - list.ResourceBarrier(&[Direct3D12::D3D12_RESOURCE_BARRIER { - Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, - Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, - Anonymous: Direct3D12::D3D12_RESOURCE_BARRIER_0 { - UAV: ManuallyDrop::new(Direct3D12::D3D12_RESOURCE_UAV_BARRIER { - pResource: Default::default(), - }), - }, - }]) + unsafe { + list.ResourceBarrier(&[Direct3D12::D3D12_RESOURCE_BARRIER { + Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, + Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, + Anonymous: Direct3D12::D3D12_RESOURCE_BARRIER_0 { + UAV: ManuallyDrop::new(Direct3D12::D3D12_RESOURCE_UAV_BARRIER { + pResource: Default::default(), + }), + }, + }]) + } } } diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 3857089a57..10f87222e3 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -17,7 +17,7 @@ use windows::{ }, }; -use super::{conv, descriptor, Buffer, D3D12Lib}; +use super::{conv, descriptor, D3D12Lib}; use crate::{ auxil::{self, dxgi::result::HResult}, dx12::{borrow_optional_interface_temporarily, shader_compilation, Event}, @@ -1872,10 +1872,12 @@ impl crate::Device for super::Device { Anonymous: inputs0, }; let mut info = Direct3D12::D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO::default(); - device5.GetRaytracingAccelerationStructurePrebuildInfo( - &acceleration_structure_inputs, - &mut info, - ); + unsafe { + device5.GetRaytracingAccelerationStructurePrebuildInfo( + &acceleration_structure_inputs, + &mut info, + ) + }; crate::AccelerationStructureBuildSizes { acceleration_structure_size: info.ResultDataMaxSizeInBytes, update_scratch_size: info.UpdateScratchDataSizeInBytes, @@ -1887,7 +1889,7 @@ impl crate::Device for super::Device { &self, acceleration_structure: &super::AccelerationStructure, ) -> wgt::BufferAddress { - acceleration_structure.resource.GetGPUVirtualAddress() + unsafe { acceleration_structure.resource.GetGPUVirtualAddress() } } unsafe fn create_acceleration_structure( @@ -1895,7 +1897,7 @@ impl crate::Device for super::Device { desc: &crate::AccelerationStructureDescriptor, ) -> Result { // Create a D3D12 resource as per-usual. - let mut size = desc.size; + let size = desc.size; let raw_desc = Direct3D12::D3D12_RESOURCE_DESC { Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER, diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index f8877e9229..864633d187 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -355,7 +355,7 @@ pub(crate) fn create_committed_texture_resource( pub(crate) fn create_committed_acceleration_structure_resource( device: &crate::dx12::Device, - desc: &crate::AccelerationStructureDescriptor, + _desc: &crate::AccelerationStructureDescriptor, raw_desc: Direct3D12::D3D12_RESOURCE_DESC, ) -> Result { let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES {