Skip to content

Commit

Permalink
Fix validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Sep 25, 2024
1 parent cec6896 commit e31b0b5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
4 changes: 2 additions & 2 deletions examples/ray_omni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn create_blas(
device: &Arc<Device>,
models: &[&Model],
) -> Result<Arc<AccelerationStructure>, DriverError> {
let info = AccelerationStructureGeometryInfo::new_blas(
let info = AccelerationStructureGeometryInfo::blas(
models
.iter()
.map(|model| {
Expand Down Expand Up @@ -351,7 +351,7 @@ fn create_tlas(
buffer
});

let info = AccelerationStructureGeometryInfo::new_tlas([(
let info = AccelerationStructureGeometryInfo::tlas([(
AccelerationStructureGeometry::opaque(
2,
AccelerationStructureGeometryData::instances(Buffer::device_address(&instance_buf)),
Expand Down
50 changes: 28 additions & 22 deletions examples/ray_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,18 @@ fn main() -> anyhow::Result<()> {
// Setup a shader binding table
// ------------------------------------------------------------------------------------------ //

let sbt_handle_size = shader_group_handle_size.next_multiple_of(shader_group_handle_alignment);
let sbt_rgen_size = sbt_handle_size;
let sbt_hit_size = sbt_handle_size;
let sbt_miss_size = 2 * sbt_handle_size;
let sbt_rgen_size = shader_group_handle_size;
let sbt_hit_start = sbt_rgen_size.next_multiple_of(shader_group_base_alignment);
let sbt_hit_size = shader_group_handle_size;
let sbt_miss_start =
(sbt_hit_start + sbt_hit_size).next_multiple_of(shader_group_base_alignment);
let sbt_miss_size =
2 * shader_group_handle_size.next_multiple_of(shader_group_handle_alignment);
let sbt_buf = Arc::new({
let mut buf = Buffer::create(
&window.device,
BufferInfo::host_mem(
(sbt_rgen_size + sbt_hit_size + sbt_miss_size) as _,
(sbt_miss_start + sbt_miss_size) as _,
vk::BufferUsageFlags::SHADER_BINDING_TABLE_KHR
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS,
)
Expand All @@ -527,36 +530,39 @@ fn main() -> anyhow::Result<()> {
)
.unwrap();

let mut data = Buffer::mapped_slice_mut(&mut buf);
data.fill(0);

let data = Buffer::mapped_slice_mut(&mut buf);
let rgen_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 0)?;
data[0..rgen_handle.len()].copy_from_slice(rgen_handle);
data = &mut data[sbt_rgen_size as _..];

// If hit/miss had different strides we would need to iterate each here
for idx in 1..4 {
let handle = RayTracePipeline::group_handle(&ray_trace_pipeline, idx)?;
data[0..handle.len()].copy_from_slice(handle);
data = &mut data[sbt_handle_size as _..];
}
let hit_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 1)?;
data[sbt_hit_start as usize..sbt_hit_start as usize + hit_handle.len()]
.copy_from_slice(hit_handle);

let miss_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 2)?;
data[sbt_miss_start as usize..sbt_miss_start as usize + miss_handle.len()]
.copy_from_slice(miss_handle);
let miss_shadow_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 3)?;
let sbt_miss_shadow_start = sbt_miss_start + shader_group_handle_alignment;
data[sbt_miss_shadow_start as usize
..sbt_miss_shadow_start as usize + miss_shadow_handle.len()]
.copy_from_slice(miss_shadow_handle);

buf
});
let sbt_address = Buffer::device_address(&sbt_buf);
let sbt_rgen = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_address,
stride: sbt_rgen_size as _,
stride: shader_group_handle_size as _,
size: sbt_rgen_size as _,
};
let sbt_hit = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_rgen.device_address + sbt_rgen_size as vk::DeviceAddress,
stride: sbt_handle_size as _,
device_address: sbt_address + sbt_hit_start as vk::DeviceAddress,
stride: shader_group_handle_size as _,
size: sbt_hit_size as _,
};
let sbt_miss = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_hit.device_address + sbt_hit_size as vk::DeviceAddress,
stride: sbt_handle_size as _,
device_address: sbt_address + sbt_miss_start as vk::DeviceAddress,
stride: shader_group_handle_size as _,
size: sbt_miss_size as _,
};
let sbt_callable = vk::StridedDeviceAddressRegionKHR::default();
Expand All @@ -572,7 +578,7 @@ fn main() -> anyhow::Result<()> {
// Create the bottom level acceleration structure
// ------------------------------------------------------------------------------------------ //

let blas_geometry_info = AccelerationStructureGeometryInfo::new_blas([(
let blas_geometry_info = AccelerationStructureGeometryInfo::blas([(
AccelerationStructureGeometry::opaque(
triangle_count,
AccelerationStructureGeometryData::triangles(
Expand Down Expand Up @@ -634,7 +640,7 @@ fn main() -> anyhow::Result<()> {
// Create the top level acceleration structure
// ------------------------------------------------------------------------------------------ //

let tlas_geometry_info = AccelerationStructureGeometryInfo::new_tlas([(
let tlas_geometry_info = AccelerationStructureGeometryInfo::tlas([(
AccelerationStructureGeometry::opaque(
1,
AccelerationStructureGeometryData::instances(Buffer::device_address(&instance_buf)),
Expand Down
40 changes: 20 additions & 20 deletions examples/rt_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ fn main() -> anyhow::Result<()> {

let &RayTraceProperties {
shader_group_base_alignment,
shader_group_handle_alignment,
shader_group_handle_size,
..
} = window
Expand All @@ -121,15 +120,17 @@ fn main() -> anyhow::Result<()> {
// Setup a shader binding table
// ------------------------------------------------------------------------------------------ //

let sbt_handle_size = shader_group_handle_size.next_multiple_of(shader_group_handle_alignment);
let sbt_rgen_size = sbt_handle_size;
let sbt_hit_size = sbt_handle_size;
let sbt_miss_size = 2 * sbt_handle_size;
let sbt_rgen_size = shader_group_handle_size;
let sbt_hit_start = sbt_rgen_size.next_multiple_of(shader_group_base_alignment);
let sbt_hit_size = shader_group_handle_size;
let sbt_miss_start =
(sbt_hit_start + sbt_hit_size).next_multiple_of(shader_group_base_alignment);
let sbt_miss_size = shader_group_handle_size;
let sbt_buf = Arc::new({
let mut buf = Buffer::create(
&window.device,
BufferInfo::host_mem(
(sbt_rgen_size + sbt_hit_size + sbt_miss_size) as _,
(sbt_miss_start + sbt_miss_size) as _,
vk::BufferUsageFlags::SHADER_BINDING_TABLE_KHR
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS,
)
Expand All @@ -138,36 +139,35 @@ fn main() -> anyhow::Result<()> {
)
.unwrap();

let mut data = Buffer::mapped_slice_mut(&mut buf);
data.fill(0);
let data = Buffer::mapped_slice_mut(&mut buf);

let rgen_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 0)?;
data[0..rgen_handle.len()].copy_from_slice(rgen_handle);
data = &mut data[sbt_rgen_size as _..];

// If hit/miss had different strides we would need to iterate each here
for idx in 1..3 {
let handle = RayTracePipeline::group_handle(&ray_trace_pipeline, idx)?;
data[0..handle.len()].copy_from_slice(handle);
data = &mut data[sbt_handle_size as _..];
}
let hit_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 1)?;
data[sbt_hit_start as usize..sbt_hit_start as usize + hit_handle.len()]
.copy_from_slice(hit_handle);

let miss_handle = RayTracePipeline::group_handle(&ray_trace_pipeline, 2)?;
data[sbt_miss_start as usize..sbt_miss_start as usize + miss_handle.len()]
.copy_from_slice(miss_handle);

buf
});
let sbt_address = Buffer::device_address(&sbt_buf);
let sbt_rgen = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_address,
stride: sbt_rgen_size as _,
stride: shader_group_handle_size as _,
size: sbt_rgen_size as _,
};
let sbt_hit = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_rgen.device_address + sbt_rgen_size as vk::DeviceAddress,
stride: sbt_handle_size as _,
device_address: sbt_address + sbt_hit_start as vk::DeviceAddress,
stride: shader_group_handle_size as _,
size: sbt_hit_size as _,
};
let sbt_miss = vk::StridedDeviceAddressRegionKHR {
device_address: sbt_hit.device_address + sbt_hit_size as vk::DeviceAddress,
stride: sbt_handle_size as _,
device_address: sbt_address + sbt_miss_start as vk::DeviceAddress,
stride: shader_group_handle_size as _,
size: sbt_miss_size as _,
};
let sbt_callable = vk::StridedDeviceAddressRegionKHR::default();
Expand Down

0 comments on commit e31b0b5

Please sign in to comment.