*/
#include "bvh/bvh.h"
+#include "util/half_float.h"
#include "amd_family.h"
#include "radv_private.h"
#include "vk_acceleration_structure.h"
}
static void
-rra_transcode_aabb_node(struct rra_transcoding_context *ctx, const struct radv_bvh_aabb_node *src)
+rra_transcode_aabb_node(struct rra_transcoding_context *ctx, const struct radv_bvh_aabb_node *src,
+ radv_aabb bounds)
{
struct rra_aabb_node *dst = (struct rra_aabb_node *)(ctx->dst + ctx->dst_leaf_offset);
ctx->dst_leaf_offset += sizeof(struct rra_aabb_node);
- dst->aabb[0][0] = src->aabb.min.x;
- dst->aabb[0][1] = src->aabb.min.y;
- dst->aabb[0][2] = src->aabb.min.z;
- dst->aabb[1][0] = src->aabb.max.x;
- dst->aabb[1][1] = src->aabb.max.y;
- dst->aabb[1][2] = src->aabb.max.z;
+ dst->aabb[0][0] = bounds.min.x;
+ dst->aabb[0][1] = bounds.min.y;
+ dst->aabb[0][2] = bounds.min.z;
+ dst->aabb[1][0] = bounds.max.x;
+ dst->aabb[1][1] = bounds.max.y;
+ dst->aabb[1][2] = bounds.max.z;
dst->geometry_id = src->geometry_id_and_flags & 0xfffffff;
dst->flags = src->geometry_id_and_flags >> 28;
}
static uint32_t rra_transcode_node(struct rra_transcoding_context *ctx, uint32_t parent_id,
- uint32_t src_id);
+ uint32_t src_id, radv_aabb bounds);
static void
rra_transcode_box16_node(struct rra_transcoding_context *ctx, const struct radv_bvh_box16_node *src)
continue;
}
+ radv_aabb bounds = {
+ .min =
+ {
+ _mesa_half_to_float(src->coords[i][0][0]),
+ _mesa_half_to_float(src->coords[i][0][1]),
+ _mesa_half_to_float(src->coords[i][0][2]),
+ },
+ .max =
+ {
+ _mesa_half_to_float(src->coords[i][1][0]),
+ _mesa_half_to_float(src->coords[i][1][1]),
+ _mesa_half_to_float(src->coords[i][1][2]),
+ },
+ };
+
dst->children[i] =
- rra_transcode_node(ctx, radv_bvh_node_box16 | (dst_offset >> 3), src->children[i]);
+ rra_transcode_node(ctx, radv_bvh_node_box16 | (dst_offset >> 3), src->children[i], bounds);
}
}
continue;
}
- dst->children[i] =
- rra_transcode_node(ctx, radv_bvh_node_box32 | (dst_offset >> 3), src->children[i]);
+ dst->children[i] = rra_transcode_node(ctx, radv_bvh_node_box32 | (dst_offset >> 3),
+ src->children[i], src->coords[i]);
}
}
}
static uint32_t
-rra_transcode_node(struct rra_transcoding_context *ctx, uint32_t parent_id, uint32_t src_id)
+rra_transcode_node(struct rra_transcoding_context *ctx, uint32_t parent_id, uint32_t src_id,
+ radv_aabb bounds)
{
uint32_t node_type = src_id & 7;
uint32_t src_offset = (src_id & (~7u)) << 3;
if (node_type == radv_bvh_node_triangle)
rra_transcode_triangle_node(ctx, src_child_node);
else if (node_type == radv_bvh_node_aabb)
- rra_transcode_aabb_node(ctx, src_child_node);
+ rra_transcode_aabb_node(ctx, src_child_node, bounds);
else if (node_type == radv_bvh_node_instance)
rra_transcode_instance_node(ctx, src_child_node);
}
.leaf_indices = leaf_indices,
};
- rra_transcode_node(&ctx, 0xFFFFFFFF, RADV_BVH_ROOT_NODE);
+ rra_transcode_node(&ctx, 0xFFFFFFFF, RADV_BVH_ROOT_NODE, header->aabb);
struct rra_accel_struct_chunk_header chunk_header = {
.metadata_offset = 0,
struct radv_leaf_intersection intersection;
intersection.node_addr = build_node_to_addr(device, b, bvh_node, false);
- nir_ssa_def *triangle_info =
- nir_build_load_global(b, 2, 32, nir_iadd_imm(b, intersection.node_addr, 24));
+ nir_ssa_def *triangle_info = nir_build_load_global(
+ b, 2, 32,
+ nir_iadd_imm(b, intersection.node_addr, offsetof(struct radv_bvh_aabb_node, primitive_id)));
intersection.primitive_id = nir_channel(b, triangle_info, 0);
intersection.geometry_id_and_flags = nir_channel(b, triangle_info, 1);
intersection.opaque = hit_is_opaque(b, nir_load_deref(b, args->vars.sbt_offset_and_flags),