Skip to content

Commit 41baeb3

Browse files
sagarghuge20kaiwenjon
authored and
Marge Bot
committed
anv: Implement acceleration structure API
Rework: (Kevin) - Properly setup bvh_layout Our bvh resides in contiguous memory and can be divided into two sections: 1. anv_accel_struct_header, tightly followed by 2. actual bvh, which starts with root node, followed by interleaving leaves or internal nodes. - Update comments for some fields for BVH and nodes. - Properly populate the UUIDs in serialization header - separate header func into completely two paths based on compaction bit - Encode rt_uuid at second VK_UUID_SIZE. - Write query result at correct slot - add assertion for a 4B alignment - move bvh_layout to anv_bvh - Use meson option to decide which files to compile - The alignment of serialization size is not needed - Change static_assert to STATIC_ASSERT and move them inside functions Rework (Sagar) - Use anv_cmd_buffer_update_buffer instead of MI to copy data Rework (Lionel) - Remove flush after builds, and add flush in copy before dispatch - Handle the flushes in CmdWriteAccelerationStructuresPropertiesKHR properly Co-authored-by: Kevin Chuang <[email protected]> Co-authored-by: Sagar Ghuge <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31588>
1 parent 9002e52 commit 41baeb3

9 files changed

+799
-62
lines changed

meson.build

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ with_intel_vk_rt = get_option('intel-rt') \
316316
.disable_if(host_machine.cpu_family() != 'x86_64', error_message : 'Intel Ray Tracing is only supported on x86_64') \
317317
.allowed()
318318

319+
if with_intel_vk_rt
320+
with_intel_bvh_grl = get_option('intel-bvh-grl')
321+
endif
322+
319323
with_any_intel = [
320324
with_gallium_crocus,
321325
with_gallium_i915,

meson_options.txt

+7
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,13 @@ option(
657657
description : 'Build the intel-clc compiler or use a system version.'
658658
)
659659

660+
option(
661+
'intel-bvh-grl',
662+
type : 'boolean',
663+
value : true,
664+
description : 'Build the BVH structure using GRL.'
665+
)
666+
660667
option(
661668
'install-intel-clc',
662669
type : 'boolean',

src/intel/vulkan/anv_device.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -985,14 +985,22 @@ VkResult anv_CreateDevice(
985985

986986
anv_device_utrace_init(device);
987987

988-
result = anv_genX(device->info, init_device_state)(device);
988+
result = vk_meta_device_init(&device->vk, &device->meta_device);
989989
if (result != VK_SUCCESS)
990990
goto fail_utrace;
991991

992+
result = anv_genX(device->info, init_device_state)(device);
993+
if (result != VK_SUCCESS)
994+
goto fail_meta_device;
995+
996+
simple_mtx_init(&device->accel_struct_build.mutex, mtx_plain);
997+
992998
*pDevice = anv_device_to_handle(device);
993999

9941000
return VK_SUCCESS;
9951001

1002+
fail_meta_device:
1003+
vk_meta_device_finish(&device->vk, &device->meta_device);
9961004
fail_utrace:
9971005
anv_device_utrace_finish(device);
9981006
fail_queues:
@@ -1118,6 +1126,12 @@ void anv_DestroyDevice(
11181126
/* Do TRTT batch garbage collection before destroying queues. */
11191127
anv_device_finish_trtt(device);
11201128

1129+
if (device->accel_struct_build.radix_sort) {
1130+
radix_sort_vk_destroy(device->accel_struct_build.radix_sort,
1131+
_device, &device->vk.alloc);
1132+
}
1133+
vk_meta_device_finish(&device->vk, &device->meta_device);
1134+
11211135
anv_device_utrace_finish(device);
11221136

11231137
for (uint32_t i = 0; i < device->queue_count; i++)
@@ -1218,6 +1232,8 @@ void anv_DestroyDevice(
12181232
pthread_cond_destroy(&device->queue_submit);
12191233
pthread_mutex_destroy(&device->mutex);
12201234

1235+
simple_mtx_destroy(&device->accel_struct_build.mutex);
1236+
12211237
ralloc_free(device->fp64_nir);
12221238

12231239
anv_device_destroy_context_or_vm(device);

src/intel/vulkan/anv_private.h

+14
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#include "vk_log.h"
103103
#include "vk_ycbcr_conversion.h"
104104
#include "vk_video.h"
105+
#include "vk_meta.h"
105106

106107
#ifdef __cplusplus
107108
extern "C" {
@@ -1828,6 +1829,11 @@ enum anv_rt_bvh_build_method {
18281829
ANV_BVH_BUILD_METHOD_NEW_SAH,
18291830
};
18301831

1832+
/* If serialization-breaking or algorithm-breaking changes are made,
1833+
* increment the digits at the end
1834+
*/
1835+
#define ANV_RT_UUID_MACRO "ANV_RT_BVH_0001"
1836+
18311837
struct anv_device_astc_emu {
18321838
struct vk_texcompress_astc_state *texcompress;
18331839

@@ -2102,6 +2108,14 @@ struct anv_device {
21022108
*/
21032109
struct util_dynarray prints;
21042110
} printf;
2111+
2112+
struct {
2113+
simple_mtx_t mutex;
2114+
struct radix_sort_vk *radix_sort;
2115+
struct vk_acceleration_structure_build_args build_args;
2116+
} accel_struct_build;
2117+
2118+
struct vk_meta_device meta_device;
21052119
};
21062120

21072121
static inline uint32_t

src/intel/vulkan/bvh/meson.build

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright © 2022 Konstantin Seurer
2+
# Copyright © 2024 Intel Corporation
3+
# SPDX-License-Identifier: MIT
4+
5+
# source file, output name, defines
6+
bvh_shaders = [
7+
[
8+
'encode.comp',
9+
'encode',
10+
[],
11+
],
12+
[
13+
'header.comp',
14+
'header',
15+
[],
16+
],
17+
[
18+
'copy.comp',
19+
'copy',
20+
[]
21+
],
22+
]
23+
24+
anv_bvh_include_dir = dir_source_root + '/src/intel/vulkan/bvh'
25+
26+
anv_bvh_includes = files(
27+
'anv_build_helpers.h',
28+
'anv_build_interface.h',
29+
'anv_bvh.h',
30+
)
31+
32+
bvh_spv = []
33+
foreach s : bvh_shaders
34+
command = [
35+
prog_glslang, '-V', '-I' + vk_bvh_include_dir, '-I' + anv_bvh_include_dir, '--target-env', 'spirv1.5', '-x', '-o', '@OUTPUT@', '@INPUT@'
36+
]
37+
command += glslang_quiet
38+
39+
foreach define : s[2]
40+
command += '-D' + define
41+
endforeach
42+
43+
bvh_spv += custom_target(
44+
s[1] + '.spv.h',
45+
input : s[0],
46+
output : s[1] + '.spv.h',
47+
command : command,
48+
depend_files: [vk_bvh_includes, anv_bvh_includes],
49+
)
50+
endforeach

0 commit comments

Comments
 (0)