Skip to content

Commit

Permalink
Use zero buffer as transform buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec committed Feb 6, 2025
1 parent 0585918 commit 44f7fd7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
15 changes: 14 additions & 1 deletion wgpu-core/src/device/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,27 @@ impl Device {
self.features.allowed_vertex_formats_for_blas(),
));
}

let mut transform = None;

if blas_desc
.flags
.contains(wgt::AccelerationStructureFlags::USE_TRANSFORM)
{
transform = Some(wgpu_hal::AccelerationStructureTriangleTransform {
buffer: self.zero_buffer.as_ref(),
offset: 0,
})
}

entries.push(hal::AccelerationStructureTriangles::<dyn hal::DynBuffer> {
vertex_buffer: None,
vertex_format: desc.vertex_format,
first_vertex: 0,
vertex_count: desc.vertex_count,
vertex_stride: 0,
indices,
transform: None,
transform,
flags: desc.flags,
});
}
Expand Down
4 changes: 3 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ impl Device {
raw_device.create_buffer(&hal::BufferDescriptor {
label: hal_label(Some("(wgpu internal) zero init buffer"), instance_flags),
size: ZERO_BUFFER_SIZE,
usage: wgt::BufferUses::COPY_SRC | wgt::BufferUses::COPY_DST,
usage: wgt::BufferUses::COPY_SRC
| wgt::BufferUses::COPY_DST
| wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT,
memory_flags: hal::MemoryFlags::empty(),
})
}
Expand Down
10 changes: 9 additions & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,15 @@ impl crate::Device for super::Device {
.flags
.contains(wgt::AccelerationStructureFlags::USE_TRANSFORM)
{
1
unsafe {
triangle
.transform
.as_ref()
.unwrap()
.buffer
.resource
.GetGPUVirtualAddress()
}
} else {
0
},
Expand Down
15 changes: 14 additions & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,20 @@ impl crate::Device for super::Device {
.flags
.contains(wgt::AccelerationStructureFlags::USE_TRANSFORM)
{
1
unsafe {
ray_tracing_functions
.buffer_device_address
.get_buffer_device_address(
&vk::BufferDeviceAddressInfo::default().buffer(
triangles
.transform
.as_ref()
.unwrap()
.buffer
.raw,
),
)
}
} else {
0
},
Expand Down

0 comments on commit 44f7fd7

Please sign in to comment.