mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-03-19 16:30:35 +01:00
radv: Use GLSL matrices for instance transforms in BVH.
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18692>
This commit is contained in:
parent
3c09681edd
commit
50bb0d6427
3 changed files with 17 additions and 17 deletions
|
|
@ -33,6 +33,11 @@
|
|||
#define VK_UUID_SIZE 16
|
||||
#else
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
typedef struct {
|
||||
float values[3][4];
|
||||
} mat3x4;
|
||||
|
||||
#endif
|
||||
|
||||
struct radv_accel_struct_serialization_header {
|
||||
|
|
@ -94,12 +99,13 @@ struct radv_bvh_instance_node {
|
|||
/* lower 24 bits are the sbt offset, upper 8 bits are VkGeometryInstanceFlagsKHR */
|
||||
uint32_t sbt_offset_and_flags;
|
||||
|
||||
float wto_matrix[3][4];
|
||||
mat3x4 wto_matrix;
|
||||
|
||||
uint32_t instance_id;
|
||||
uint32_t reserved[3];
|
||||
|
||||
/* Object to world matrix transposed from the initial transform. */
|
||||
float otw_matrix[3][4];
|
||||
mat3x4 otw_matrix;
|
||||
};
|
||||
|
||||
struct radv_bvh_box16_node {
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ load_vertices(VOID_REF vertices, triangle_indices indices, uint32_t vertex_forma
|
|||
|
||||
/* A GLSL-adapted copy of VkAccelerationStructureInstanceKHR. */
|
||||
struct AccelerationStructureInstance {
|
||||
float transform[12];
|
||||
mat3x4 transform;
|
||||
uint32_t custom_instance_and_mask;
|
||||
uint32_t sbt_offset_and_flags;
|
||||
uint64_t accelerationStructureReference;
|
||||
|
|
@ -191,19 +191,13 @@ build_instance(inout AABB bounds, VOID_REF src_ptr, VOID_REF dst_ptr, uint32_t g
|
|||
if (instance.accelerationStructureReference == 0)
|
||||
return false;
|
||||
|
||||
mat4 transform = mat4(1.0);
|
||||
for (uint32_t col = 0; col < 4; col++)
|
||||
for (uint32_t row = 0; row < 3; row++)
|
||||
transform[col][row] = instance.transform[col + row * 4];
|
||||
mat4 transform = mat4(instance.transform);
|
||||
|
||||
mat4 inv_transform = inverse(transform);
|
||||
for (uint32_t row = 0; row < 3; row++)
|
||||
for (uint32_t col = 0; col < 4; col++)
|
||||
DEREF(node).wto_matrix[row][col] = inv_transform[col][row];
|
||||
|
||||
for (uint32_t col = 0; col < 4; col++)
|
||||
for (uint32_t row = 0; row < 3; row++)
|
||||
DEREF(node).otw_matrix[row][col] = transform[col][row];
|
||||
/* We store everything as mat3x4 for layout reasons but the conceptual matrix
|
||||
* is really a mat4x3. So transpose it temporarily for the invertion. */
|
||||
mat4 inv_transform = transpose(inverse(transpose(transform)));
|
||||
DEREF(node).wto_matrix = mat3x4(inv_transform);
|
||||
DEREF(node).otw_matrix = mat3x4(transform);
|
||||
|
||||
radv_accel_struct_header instance_header =
|
||||
DEREF(REF(radv_accel_struct_header)(instance.accelerationStructureReference));
|
||||
|
|
|
|||
|
|
@ -510,8 +510,8 @@ rra_transcode_instance_node(struct rra_instance_node *dst, const struct radv_bvh
|
|||
dst->instance_id = src->instance_id;
|
||||
dst->blas_metadata_size = sizeof(struct rra_accel_struct_metadata);
|
||||
|
||||
memcpy(dst->wto_matrix, src->wto_matrix, sizeof(dst->wto_matrix));
|
||||
memcpy(dst->otw_matrix, src->otw_matrix, sizeof(dst->otw_matrix));
|
||||
memcpy(dst->wto_matrix, src->wto_matrix.values, sizeof(dst->wto_matrix));
|
||||
memcpy(dst->otw_matrix, src->otw_matrix.values, sizeof(dst->otw_matrix));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue