Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hal acceleration structures #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion wgpu-hal/examples/ray-traced-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,19 @@ impl<A: hal::Api> Example<A> {
unsafe { adapter.open(features, &wgt::Limits::default()).unwrap() };

let window_size: (u32, u32) = window.inner_size().into();
dbg!(&surface_caps.formats);
let surface_format = if surface_caps.formats.contains(&wgt::TextureFormat::Rgba8Snorm) {
wgt::TextureFormat::Rgba8Unorm
}else{
*surface_caps.formats.first().unwrap()
};
let surface_config = hal::SurfaceConfiguration {
swap_chain_size: DESIRED_FRAMES
.max(*surface_caps.swap_chain_sizes.start())
.min(*surface_caps.swap_chain_sizes.end()),
present_mode: wgt::PresentMode::Fifo,
composite_alpha_mode: hal::CompositeAlphaMode::Opaque,
format: wgt::TextureFormat::Rgba8Unorm,
format: surface_format,
extent: wgt::Extent3d {
width: window_size.0,
height: window_size.1,
Expand Down
6 changes: 4 additions & 2 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,11 @@ bitflags::bitflags! {
/// The combination of states that a buffer may be in _at the same time_.
const INCLUSIVE = Self::MAP_READ.bits | Self::COPY_SRC.bits |
Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits |
Self::STORAGE_READ.bits | Self::INDIRECT.bits;
Self::STORAGE_READ.bits | Self::INDIRECT.bits |
Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits;
/// The combination of states that a buffer must exclusively be in.
const EXCLUSIVE = Self::MAP_WRITE.bits | Self::COPY_DST.bits | Self::STORAGE_READ_WRITE.bits;
const EXCLUSIVE = Self::MAP_WRITE.bits | Self::COPY_DST.bits |
Self::STORAGE_READ_WRITE.bits | Self::ACCELERATION_STRUCTURE_SCRATCH.bits;
/// The combination of all usages that the are guaranteed to be be ordered by the hardware.
/// If a usage is ordered, then if the buffer state doesn't change between draw calls, there
/// are no barriers needed for synchronization.
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {

let geometry_info = geometry_info.build();

let range = &[range][..];
let range = &[range][..];
let geometry_info = &[geometry_info];
//each geometry has multiple ranges; building requires a vector of geometry_infos and a vector of vectors of ranges
let ranges : &[&[vk::AccelerationStructureBuildRangeInfoKHR]] = &[&[range]];
let geometry_infos = &[geometry_info];

ray_tracing_functions
.acceleration_structure
.cmd_build_acceleration_structures(self.active, geometry_info, range);
.cmd_build_acceleration_structures(self.active, geometry_infos, ranges);
}

// render
Expand Down
17 changes: 9 additions & 8 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,18 +784,18 @@ impl crate::Device<super::Api> for super::Device {
desc.memory_flags.contains(crate::MemoryFlags::TRANSIENT),
);

let alignment_mask = if desc.usage
.contains(crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT){
16
} else {
req.alignment
} - 1;

let block = self.mem_allocator.lock().alloc(
&*self.shared,
gpu_alloc::Request {
size: req.size,
align_mask: if desc
.usage
.contains(crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT)
{
16
} else {
req.alignment
} - 1,
align_mask: alignment_mask,
usage: alloc_usage,
memory_types: req.memory_type_bits & self.valid_ash_memory_types,
},
Expand Down Expand Up @@ -1429,6 +1429,7 @@ impl crate::Device<super::Api> for super::Device {
// `raw_acceleration_structures`.
let acceleration_structure_info: vk::WriteDescriptorSetAccelerationStructureKHR = *acceleration_structure_info;

assert!(index < desc.acceleration_structures.len(), "Encountered more acceleration structures then expected");
acceleration_structure_infos.push(acceleration_structure_info);

extra_descriptor_count += 1;
Expand Down