Skip to content

Acceleration structure alignment issue #2703

Description

@mergmann

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions