Skip to content

Commit 5098c0c

Browse files
kaiwenjonMarge Bot
authored and
Marge Bot
committed
anv: Add INTEL_DEBUG for bvh dump and visualization tools
This commit allows you to dump different regions of memory related to bvh building. An additional script to decode the memory dump is also added, and you're able to view the built bvh in 3D view in html. See the included README.md for usage. Rework: - you can now view the actual child_coord in internalNode in html - change exponent to be int8_t in the interpreter - fix the actual coordinates using an updated formula - now you can have 3D view of the bvh - blockIncr could be 2 and vk_aabb should be first - Now, if any bvh dump is enabled, we will zero out tlas, to prevent gpu hang caused by incorrect tlas traversal - rootNodeOffset is back to the beginning - Add INTEL_DEBUG=bvh_no_build. - Fix type of dump_size - add assertion for a 4B alignment - when clearing out bvh, only clear out everything after (header+bvh_offset) - TODO: instead of dumping on destory, track in the command buffer Acked-by: Lionel Landwerlin <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31588>
1 parent 5561db6 commit 5098c0c

7 files changed

+1120
-0
lines changed

src/intel/dev/intel_debug.c

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ static const struct debug_control debug_control[] = {
9494
DEBUG_TES | DEBUG_GS | DEBUG_CS |
9595
DEBUG_RT | DEBUG_TASK | DEBUG_MESH },
9696
{ "rt", DEBUG_RT },
97+
{ "bvh_blas", DEBUG_BVH_BLAS},
98+
{ "bvh_tlas", DEBUG_BVH_TLAS},
99+
{ "bvh_blas_ir_hdr", DEBUG_BVH_BLAS_IR_HDR},
100+
{ "bvh_tlas_ir_hdr", DEBUG_BVH_TLAS_IR_HDR},
101+
{ "bvh_blas_ir_as", DEBUG_BVH_BLAS_IR_AS},
102+
{ "bvh_tlas_ir_as", DEBUG_BVH_TLAS_IR_AS},
103+
{ "bvh_no_build", DEBUG_BVH_NO_BUILD},
97104
{ "task", DEBUG_TASK },
98105
{ "mesh", DEBUG_MESH },
99106
{ "stall", DEBUG_STALL },

src/intel/dev/intel_debug.h

+13
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ extern uint64_t intel_debug;
9999
#define DEBUG_REG_PRESSURE (1ull << 51)
100100
#define DEBUG_SHADER_PRINT (1ull << 52)
101101
#define DEBUG_CL_QUIET (1ull << 53)
102+
#define DEBUG_BVH_BLAS (1ull << 54)
103+
#define DEBUG_BVH_TLAS (1ull << 55)
104+
#define DEBUG_BVH_BLAS_IR_HDR (1ull << 56)
105+
#define DEBUG_BVH_TLAS_IR_HDR (1ull << 57)
106+
#define DEBUG_BVH_BLAS_IR_AS (1ull << 58)
107+
#define DEBUG_BVH_TLAS_IR_AS (1ull << 59)
108+
#define DEBUG_BVH_NO_BUILD (1ull << 60)
102109

103110
#define DEBUG_ANY (~0ull)
104111

@@ -110,6 +117,12 @@ extern uint64_t intel_debug;
110117
(DEBUG_NO_DUAL_OBJECT_GS | DEBUG_SPILL_FS | \
111118
DEBUG_SPILL_VEC4 | DEBUG_NO_COMPACTION | DEBUG_DO32 | DEBUG_SOFT64)
112119

120+
/* Flags to determine what bvh to dump out */
121+
#define DEBUG_BVH_ANV (DEBUG_BVH_BLAS | DEBUG_BVH_TLAS)
122+
#define DEBUG_BVH_IR_HDR (DEBUG_BVH_BLAS_IR_HDR | DEBUG_BVH_TLAS_IR_HDR)
123+
#define DEBUG_BVH_IR_AS (DEBUG_BVH_BLAS_IR_AS | DEBUG_BVH_TLAS_IR_AS)
124+
#define DEBUG_BVH_ANY (DEBUG_BVH_ANV | DEBUG_BVH_IR_HDR | DEBUG_BVH_IR_AS)
125+
113126
extern uint64_t intel_simd;
114127
extern uint32_t intel_debug_bkp_before_draw_count;
115128
extern uint32_t intel_debug_bkp_after_draw_count;

src/intel/vulkan/anv_private.h

+14
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,20 @@ enum anv_rt_bvh_build_method {
18341834
*/
18351835
#define ANV_RT_UUID_MACRO "ANV_RT_BVH_0001"
18361836

1837+
enum bvh_dump_type {
1838+
BVH_ANV,
1839+
BVH_IR_HDR,
1840+
BVH_IR_AS
1841+
};
1842+
1843+
struct bvh_dump_struct {
1844+
struct anv_bo *bo;
1845+
uint32_t bvh_id;
1846+
uint64_t dump_size;
1847+
VkGeometryTypeKHR geometry_type;
1848+
enum bvh_dump_type dump_type;
1849+
};
1850+
18371851
struct anv_device_astc_emu {
18381852
struct vk_texcompress_astc_state *texcompress;
18391853

src/intel/vulkan/bvh/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## BVH Debug
2+
3+
1. `INTEL_DEBUG=bvh_tlas,bvh_blas` will generate `tlas_{id}.txt` or `blas_{id}.txt` in `bvh_dump/BVH_ANV` directory.
4+
2. `INTEL_DEBUG=bvh_tlas_ir_hdr,bvh_blas_ir_hdr` will generate `tlas_{id}.txt` or `blas_{id}.txt` in `bvh_dump/BVH_IR_HDR` directory.
5+
3. `INTEL_DEBUG=bvh_tlas_ir_as,bvh_blas_ir_as` will generate `tlas_{id}.txt` or `blas_{id}.txt` in `bvh_dump/BVH_IR_AS` directory.
6+
4. `INTEL_DEBUG=bvh_no_build` will skip the intel-specific-encoding part. If gpu hang is seen, this is the first step to isolate the problem. If toggled on and gpu doesn't hang anymore, that means it was either encode.comp was spinning, or the built bvh has issues so gpu hung during bvh traversal.
7+
8+
The dumped text file contains memory dump, byte-by-byte in hex. The contents are contiguous memory of a certain region.
9+
1. The dump in `BVH_ANV` starts from the beginning of `anv_accel_struct_header` to the end of the bvh. Nodes/leaves are packed tightly after the header, encoded in a way that our HW expects.
10+
2. The dump in `BVH_IR_HDR` records the contents of `vk_ir_header` sitting at the beginning of ir bvh.
11+
3. The dump in `BVH_IR_AS` records all `vk_ir_{leaf_type}_node` and `vk_ir_box_node` in ir bvh. The region starts from where leaves are encoded to the end of ir bvh.
12+
13+
### Decode the dump
14+
15+
We have a way to decode the dump in `BVH_ANV`.
16+
- To decode this memory dump, use a python script to parse the file and generate a human-readable json.
17+
- To further visualize the tree, there is a html that parses the json and draws the tree topology and 3D views of bounding boxes.
18+
19+
```
20+
# Using blas_0 as an example
21+
xxd -r -p bvh_dump/BVH_ANV/blas_0.txt > input.bin
22+
23+
# Use a python script to generate a human-readable json file
24+
cd mesa/src/intel/vulkan/bvh/
25+
python3 interpret.py <path/to/input.bin>
26+
27+
# To further visualize the tree, the html parses the json and draws it in 3D.
28+
cd mesa/src/intel/vulkan/bvh/
29+
python3 -m http.server 8000
30+
# go to localhost:8000/visualize_json.html
31+
32+
```
33+
34+
### Note and Limitations:
35+
1. The python script use `ctypes` to interpret the memory dump, so the structure defined in the script should match the structure defined in the driver.
36+
2. The memory dump is a snapshot of a VkBuffer captured at the end of `CmdBuildAccelerationStructure` call. It won't capture any bvh obtained from `CmdCopy`.
37+
3. The memory dump of captured bvhs so far are saved to files at the moment when `DestroyAccelerationStructure` is called every time.
38+
4. If ANY dump is enabled, we will nullify anv tlas bvh and send all 0s to the gpu. Doing this can prevent gpu hang caused by incorrect bvh traversal. However, the actual contents are still saved to files for debugging.

0 commit comments

Comments
 (0)