Problem
I wanted to run a raytracer I have written quite some time ago, however it didn't run anymore (possibly due to a toolchain update).
It doesn't work in 0.34.1 as well as 0.35.1
The issue has to do with memory alignment of acceleration structures.
Error
I get the error
called `Result::unwrap()` on an `Err` value: info.geometries.data: is `AccelerationStructureGeometryInstancesDataType::Values`, and the buffer's device address is not a multiple of 16
Vulkan VUIDs:
VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03715
|
return Err(Box::new(ValidationError { |
Used code
This code creates a buffer of acceleration structures (taken from #2314)
let values = Buffer::from_iter(
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY
| BufferUsage::SHADER_DEVICE_ADDRESS,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
instances,
)
.unwrap();
The layout of AccelerationStructureInstance is
BufferContentsLayout(
Sized(
DeviceLayout {
size: 64,
alignment: 8 (1 << 3),
},
),
)
The alignment is incorrect (according Vulkan Docs)
geometry.instances.data.deviceAddress must be aligned to 16 bytes
I guess the buffer had been over-aligned previously, thus never triggering any errors.
My quick fix without having to patch vulkano is to wrap the instances when allocating and then casting the buffer
#[derive(BufferContents)]
#[repr(C, align(16))]
struct InstanceWrapper(AccelerationStructureInstance);
Problem
I wanted to run a raytracer I have written quite some time ago, however it didn't run anymore (possibly due to a toolchain update).
It doesn't work in
0.34.1as well as0.35.1The issue has to do with memory alignment of acceleration structures.
Error
I get the error
vulkano/vulkano/src/command_buffer/commands/acceleration_structure.rs
Line 1378 in c9af075
Used code
This code creates a buffer of acceleration structures (taken from #2314)
The layout of
AccelerationStructureInstanceisThe alignment is incorrect (according Vulkan Docs)
I guess the buffer had been over-aligned previously, thus never triggering any errors.
My quick fix without having to patch vulkano is to wrap the instances when allocating and then casting the buffer