warp.bvh_query_next_tiled#

warp.bvh_query_next_tiled(
query: BvhQueryTiled,
) Tile[int32, tuple[int]]#
  • Kernel

Move to the next bound in a thread-block parallel BVH query and return results as a tile.

Each thread in the block receives one result index in the returned tile, or -1 if no result for that thread. The function returns a register tile of shape (block_dim,) containing the result indices, where block_dim is the kernel’s block dimension. All threads in the block must call this function cooperatively.

Call it in a loop guarded by tile_query_valid() (which returns False once the query is exhausted); within an iteration, check whether any tile element is >= 0 to see if this step produced any results.

Parameters:

query – The thread-block BVH query object, from bvh_query_aabb_tiled() or bvh_query_ray_tiled()

Returns:

A register tile of shape (block_dim,) with dtype int, where each element contains

the result index for that thread (-1 if no result)

Example

@wp.kernel
def tiled_query(bvh_id: wp.uint64, lowers: wp.array[wp.vec3], uppers: wp.array[wp.vec3],
                lo: wp.vec3, hi: wp.vec3, centers: wp.array[wp.vec3]):
    query = wp.bvh_query_aabb_tiled(bvh_id, lo, hi)
    while wp.tile_query_valid(query):
        result = wp.bvh_query_next_tiled(query)
        item = wp.untile(result)
        if item >= 0:
            centers[item] = 0.5 * (lowers[item] + uppers[item])

lowers = wp.array([[0, 0, 0], [2, 0, 0], [4, 0, 0]], dtype=wp.vec3)
uppers = wp.array([[1, 1, 1], [3, 1, 1], [5, 1, 1]], dtype=wp.vec3)
bvh = wp.Bvh(lowers=lowers, uppers=uppers)

centers = wp.zeros(3, dtype=wp.vec3)
wp.launch_tiled(tiled_query, dim=[1], inputs=[bvh.id, lowers, uppers, wp.vec3(0.5, 0.5, 0.5), wp.vec3(4.5, 0.5, 0.5)], outputs=[centers], block_dim=32)
print(centers.numpy().tolist())
[[0.5, 0.5, 0.5], [2.5, 0.5, 0.5], [4.5, 0.5, 0.5]]