Skip to content

Optimise TLAS building. #9946

Description

@Vecvec

Is your request related to a problem? Please describe.
Currently large TLASes (on the order of hundreds of thousands of instances) can take multiple milliseconds on the CPU. Ideally TLASes should be able to be built each frame as they may have things like players in them which can change each frame.

Currently a TLAS build loops over every TlasInstance, validates it, converts it to a hal RawTlasInstance which gets mapped into the raw bytes by the hal device and then appended each time to the bytes vector. This is not ideal as call times can add up even if most instances are not changing due to them being re-converted.

Describe solutions you've considered
The ideal solution would probably be to upload the instances early and convert them on the GPU because they can have more memory bandwidth (on discrete only) and can do it in parallel. However, shaders would require the wgsl feature which might not be able to be relied on (or exposing the ray tracing feature would be dependent on wgsl).

There are a few things that could probably improve performance before uploading everything to the GPU. It should be possible to not call a dyn function on each instance (either by sending up a layout or by taking an array of instances to convert).

Additional context
A quick benchmark suggests that an average TLAS build + submission (I used a single duplicated BLAS so this is only build speed) takes 60-80 ms with 100,000 instances and scales roughly linearly (9ms for 10,000 and 1ms for 1,000)

cc @JMS55

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions