Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec committed Sep 11, 2024
1 parent 6a2f362 commit 7e2fc34
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 54 deletions.
106 changes: 60 additions & 46 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand All @@ -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
},
Expand All @@ -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,
},
},
Expand All @@ -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,
},
},
Expand All @@ -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) };
}
}

Expand All @@ -1396,14 +1408,16 @@ impl crate::CommandEncoder for super::CommandEncoder {
.unwrap()
.cast::<Direct3D12::ID3D12GraphicsCommandList4>()
.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(),
}),
},
}])
}
}
}
16 changes: 9 additions & 7 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand All @@ -1887,15 +1889,15 @@ 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(
&self,
desc: &crate::AccelerationStructureDescriptor,
) -> Result<super::AccelerationStructure, crate::DeviceError> {
// 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,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/suballocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Direct3D12::ID3D12Resource, crate::DeviceError> {
let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES {
Expand Down

0 comments on commit 7e2fc34

Please sign in to comment.