vulkan: move internal_node_count to vk_acceleration_structure_build_state

Reviewed-by: Natalie Vock <natalie.vock@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39752>
This commit is contained in:
Konstantin Seurer 2026-02-06 21:14:14 +01:00 committed by Marge Bot
parent 63daa4e731
commit 50b1becdde
3 changed files with 12 additions and 20 deletions

View file

@ -185,7 +185,6 @@ radv_get_update_scratch_layout(struct radv_device *device, const struct vk_accel
struct update_scratch_layout *scratch)
{
const struct radv_physical_device *pdev = radv_device_physical(device);
uint32_t internal_count = MAX2(state->leaf_node_count, 2) - 1;
uint32_t offset = 0;
memset(scratch, 0, sizeof(*scratch));
@ -195,11 +194,11 @@ radv_get_update_scratch_layout(struct radv_device *device, const struct vk_accel
offset += sizeof(struct vk_bvh_geometry_data) * state->build_info->geometryCount;
scratch->bounds_offsets = offset;
offset += sizeof(vk_aabb) * internal_count;
offset += sizeof(vk_aabb) * state->internal_node_count;
}
scratch->internal_ready_count_offset = offset;
offset += sizeof(uint32_t) * internal_count;
offset += sizeof(uint32_t) * state->internal_node_count;
scratch->size = offset;
}
@ -509,11 +508,9 @@ radv_encode_as_gfx12(VkCommandBuffer commandBuffer, const struct vk_acceleration
};
radv_bvh_build_set_args(commandBuffer, &args, sizeof(args));
uint32_t internal_count = MAX2(state->leaf_node_count, 2) - 1;
struct radv_dispatch_info dispatch = {
.ordered = true,
.blocks = {DIV_ROUND_UP(internal_count * 8, 64), 1, 1},
.blocks = {DIV_ROUND_UP(state->internal_node_count * 8, 64), 1, 1},
};
radv_compute_dispatch(cmd_buffer, &dispatch);

View file

@ -149,6 +149,7 @@ vk_acceleration_structure_build_state_init(struct vk_acceleration_structure_buil
{
state->build_info = build_info;
state->leaf_node_count = leaf_count;
state->internal_node_count = MAX2(leaf_count, 2) - 1;
if (leaf_count <= 4)
state->config.internal_type = VK_INTERNAL_BUILD_TYPE_LBVH;
@ -173,8 +174,6 @@ vk_acceleration_structure_build_state_init(struct vk_acceleration_structure_buil
if (device->as_build_ops->get_build_config)
device->as_build_ops->get_build_config(vk_device_to_handle(device), state);
uint32_t internal_count = MAX2(leaf_count, 2) - 1;
radix_sort_vk_memory_requirements_t requirements = {
0,
};
@ -205,9 +204,9 @@ vk_acceleration_structure_build_state_init(struct vk_acceleration_structure_buil
if (state->config.internal_type == VK_INTERNAL_BUILD_TYPE_PLOC)
ploc_scratch_space = DIV_ROUND_UP(leaf_count, PLOC_WORKGROUP_SIZE) * sizeof(struct ploc_prefix_scan_partition);
else if (state->config.internal_type == VK_INTERNAL_BUILD_TYPE_HPLOC)
hploc_scratch_space = sizeof(uint32_t) * internal_count;
hploc_scratch_space = sizeof(uint32_t) * state->internal_node_count;
else
lbvh_node_space = sizeof(struct lbvh_node_info) * internal_count;
lbvh_node_space = sizeof(struct lbvh_node_info) * state->internal_node_count;
uint32_t encode_scratch_size = 0;
if (device->as_build_ops->get_encode_scratch_size)
@ -242,7 +241,7 @@ vk_acceleration_structure_build_state_init(struct vk_acceleration_structure_buil
offset += ir_leaf_size * leaf_count;
state->scratch.internal_node_offset = offset;
offset += sizeof(struct vk_ir_box_node) * internal_count;
offset += sizeof(struct vk_ir_box_node) * state->internal_node_count;
state->scratch.size = offset;
@ -261,8 +260,6 @@ struct bvh_state {
uint32_t scratch_offset;
uint32_t internal_node_count;
/* Radix sort state */
uint32_t scatter_blocks;
uint32_t count_ru_scatter;
@ -983,7 +980,6 @@ lbvh_build_internal(VkCommandBuffer commandBuffer, struct vk_device *device,
continue;
uint32_t src_scratch_offset = bvh_states[i].scratch_offset;
uint32_t internal_node_count = MAX2(bvh_states[i].vk.leaf_node_count, 2) - 1;
uint64_t scratch_addr = bvh_states[i].vk.build_info->scratchData.deviceAddress;
const struct lbvh_main_args consts = {
@ -996,8 +992,7 @@ lbvh_build_internal(VkCommandBuffer commandBuffer, struct vk_device *device,
disp->CmdPushConstants(commandBuffer, layout,
VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(consts), &consts);
device->cmd_dispatch_unaligned(commandBuffer, internal_node_count, 1, 1);
bvh_states[i].internal_node_count = internal_node_count;
device->cmd_dispatch_unaligned(commandBuffer, bvh_states[i].vk.internal_node_count, 1, 1);
}
vk_barrier_compute_w_to_compute_r(commandBuffer);
@ -1030,7 +1025,7 @@ lbvh_build_internal(VkCommandBuffer commandBuffer, struct vk_device *device,
disp->CmdPushConstants(commandBuffer, layout,
VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(consts), &consts);
device->cmd_dispatch_unaligned(commandBuffer, bvh_states[i].internal_node_count, 1, 1);
device->cmd_dispatch_unaligned(commandBuffer, bvh_states[i].vk.internal_node_count, 1, 1);
}
if (args->emit_markers) {
@ -1326,10 +1321,9 @@ vk_cmd_build_acceleration_structures(VkCommandBuffer commandBuffer,
if (batch_state.any_hploc) {
for (uint32_t i = 0; i < infoCount; ++i) {
uint32_t internal_count = MAX2(bvh_states[i].vk.leaf_node_count, 2) - 1;
if (bvh_states[i].vk.config.internal_type == VK_INTERNAL_BUILD_TYPE_HPLOC) {
device->cmd_fill_buffer_addr(commandBuffer, pInfos[i].scratchData.deviceAddress + bvh_states[i].vk.scratch.hploc_ranges_offset,
sizeof(uint32_t) * internal_count, 0xffffffff);
sizeof(uint32_t) * bvh_states[i].vk.internal_node_count, 0xffffffff);
}
}
vk_barrier_transfer_w_to_compute_r(commandBuffer);
@ -1430,7 +1424,7 @@ vk_cmd_build_acceleration_structures(VkCommandBuffer commandBuffer,
continue;
encode_marker.encode.leaf_node_count += bvh_states[j].vk.leaf_node_count;
encode_marker.encode.internal_node_count += bvh_states[j].internal_node_count;
encode_marker.encode.internal_node_count += bvh_states[i].vk.internal_node_count;
}
device->as_build_ops->begin_debug_marker(commandBuffer, &encode_marker);

View file

@ -128,6 +128,7 @@ struct vk_acceleration_structure_build_state {
const VkAccelerationStructureBuildGeometryInfoKHR *build_info;
const VkAccelerationStructureBuildRangeInfoKHR *build_range_infos;
uint32_t leaf_node_count;
uint32_t internal_node_count;
struct vk_scratch_layout scratch;
struct vk_build_config config;
};