mesa/src/amd/vulkan/bvh/invocation_cluster.h
Konstantin Seurer 76031ba53d radv: Optimize the gfx12 encode shader
Reviewed-by: Natalie Vock <natalie.vock@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34273>
2025-04-17 20:20:40 +00:00

39 lines
1.2 KiB
C

/*
* Copyright © 2025 Valve Corporation
*
* SPDX-License-Identifier: MIT
*/
/* Helpers for encoding BVH nodes on different HW generations. */
#ifndef RADV_BVH_INVOCATION_CLUSTER_H
#define RADV_BVH_INVOCATION_CLUSTER_H
struct radv_invocation_cluster {
uint32_t invocation_index;
uint32_t cluster_index;
uint32_t cluster_size;
};
/* cluster_size has to be a power of two and <32. */
void
radv_invocation_cluster_init(out radv_invocation_cluster cluster, uint32_t cluster_size)
{
cluster.invocation_index = gl_SubgroupInvocationID & (cluster_size - 1);
cluster.cluster_index = gl_SubgroupInvocationID / cluster_size;
cluster.cluster_size = cluster_size;
}
#define radv_read_invocation(cluster, index, value) \
subgroupShuffle(value, (gl_SubgroupInvocationID & (~(cluster.cluster_size - 1))) + index)
uint32_t
radv_ballot(radv_invocation_cluster cluster, bool value)
{
uvec4 ballot = subgroupBallot(value);
uint64_t ballot64 = uint64_t(ballot.x) | (uint64_t(ballot.y) << 32ul);
uint32_t cluster_shift = gl_SubgroupInvocationID & (~(cluster.cluster_size - 1));
return uint32_t((ballot64 >> cluster_shift) & ((1u << cluster.cluster_size) - 1));
}
#endif