tlas build options

This commit is contained in:
Jorijn van der Graaf 2026-06-16 15:49:17 +02:00
commit 00d14d67cb
3 changed files with 50 additions and 13 deletions

View file

@ -52,6 +52,12 @@ export namespace Crafter {
// reconstructs the topology from scratch. A change in count forces
// a fresh rebuild because the AS is sized for that primitive count.
std::uint32_t builtInstanceCount = 0;
// Build flags the current AS was created with — ALLOW_UPDATE (always
// set, since BuildTLAS refits in place) plus the chosen
// FAST_TRACE/FAST_BUILD preference bit. A refit (UPDATE mode) must
// use flags identical to the originating build, so a change in the
// requested preference forces a full rebuild rather than a refit.
VkBuildAccelerationStructureFlagsKHR builtFlags = 0;
};
class RenderingElement3D {
@ -78,7 +84,17 @@ export namespace Crafter {
static std::vector<RenderingElement3D*> elements;
inline static TlasWithBuffer tlases[Window::numFrames];
static void BuildTLAS(VkCommandBuffer cmd, std::uint32_t index);
// Build (or in-place refit) the TLAS for frame `index`. `preference`
// maps onto the FAST_TRACE/FAST_BUILD bits exactly as Mesh::Build
// does for a BLAS: FastTrace (the default) spends more build time for
// faster traversal — right for a TLAS rebuilt at most once per frame
// and traced many times; FastBuild trades traversal speed for cheaper
// builds, for scenes whose instance set churns hard every frame.
// ALLOW_UPDATE is always set (refit is intrinsic to this path), so it
// is not exposed as an option. Changing `preference` between frames
// forces a full rebuild on the next call, since a refit must inherit
// the original build's flags.
static void BuildTLAS(VkCommandBuffer cmd, std::uint32_t index, RTBuildPreference preference = RTBuildPreference::FastTrace);
// Register / unregister with `elements`. Use these instead of touching
// the vector directly: linear find+erase is O(n) and pathological at
@ -183,7 +199,11 @@ export namespace Crafter {
// interleave a compute pass (e.g. the ctor-time first build).
static void BuildTLASUpload(WebGPUCommandEncoderRef cmd, std::uint32_t index);
static void BuildTLASBuild(WebGPUCommandEncoderRef cmd, std::uint32_t index);
static void BuildTLAS(WebGPUCommandEncoderRef cmd, std::uint32_t index);
// `preference` mirrors the Vulkan signature for portability but has
// no effect here: the software LBVH-for-TLAS path has no hardware
// FAST_TRACE/FAST_BUILD knob (same as Mesh::Build on WebGPU). The
// parameter exists purely so portable code compiles unchanged.
static void BuildTLAS(WebGPUCommandEncoderRef cmd, std::uint32_t index, RTBuildPreference preference = RTBuildPreference::FastTrace);
static void Add(RenderingElement3D* e);
static void Remove(RenderingElement3D* e);