diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index f0e4a0a1ad0..8d70f4c659f 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -39,6 +39,7 @@ libradv_files = files( 'winsys/null/radv_null_winsys.c', 'winsys/null/radv_null_winsys_public.h', 'radv_acceleration_structure.c', + 'radv_acceleration_structure.h', 'radv_android.c', 'radv_cmd_buffer.c', 'radv_cs.h', diff --git a/src/amd/vulkan/radv_acceleration_structure.c b/src/amd/vulkan/radv_acceleration_structure.c index 2d22785fce6..27a67c44f68 100644 --- a/src/amd/vulkan/radv_acceleration_structure.c +++ b/src/amd/vulkan/radv_acceleration_structure.c @@ -20,6 +20,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ +#include "radv_acceleration_structure.h" #include "radv_private.h" #include "util/format/format_utils.h" @@ -28,64 +29,6 @@ #include "radv_cs.h" #include "radv_meta.h" -struct radv_accel_struct_header { - uint32_t root_node_offset; - uint32_t reserved; - float aabb[2][3]; - uint64_t compacted_size; - uint64_t serialization_size; -}; - -struct radv_bvh_triangle_node { - float coords[3][3]; - uint32_t reserved[3]; - uint32_t triangle_id; - /* flags in upper 4 bits */ - uint32_t geometry_id_and_flags; - uint32_t reserved2; - uint32_t id; -}; - -struct radv_bvh_aabb_node { - float aabb[2][3]; - uint32_t primitive_id; - /* flags in upper 4 bits */ - uint32_t geometry_id_and_flags; - uint32_t reserved[8]; -}; - -struct radv_bvh_instance_node { - uint64_t base_ptr; - /* lower 24 bits are the custom instance index, upper 8 bits are the visibility mask */ - uint32_t custom_instance_and_mask; - /* lower 24 bits are the sbt offset, upper 8 bits are VkGeometryInstanceFlagsKHR */ - uint32_t sbt_offset_and_flags; - - /* The translation component is actually a pre-translation instead of a post-translation. If you - * want to get a proper matrix out of it you need to apply the directional component of the - * matrix to it. The pre-translation of the world->object matrix is the same as the - * post-translation of the object->world matrix so this way we can share data between both - * matrices. */ - float wto_matrix[12]; - float aabb[2][3]; - uint32_t instance_id; - - /* Object to world matrix transposed from the initial transform. Translate part is store in the - * wto_matrix. */ - float otw_matrix[9]; -}; - -struct radv_bvh_box16_node { - uint32_t children[4]; - uint32_t coords[4][3]; -}; - -struct radv_bvh_box32_node { - uint32_t children[4]; - float coords[4][2][3]; - uint32_t reserved[4]; -}; - void radv_GetAccelerationStructureBuildSizesKHR( VkDevice _device, VkAccelerationStructureBuildTypeKHR buildType, @@ -94,6 +37,12 @@ radv_GetAccelerationStructureBuildSizesKHR( { uint64_t triangles = 0, boxes = 0, instances = 0; + STATIC_ASSERT(sizeof(struct radv_bvh_triangle_node) == 64); + STATIC_ASSERT(sizeof(struct radv_bvh_aabb_node) == 64); + STATIC_ASSERT(sizeof(struct radv_bvh_instance_node) == 128); + STATIC_ASSERT(sizeof(struct radv_bvh_box16_node) == 64); + STATIC_ASSERT(sizeof(struct radv_bvh_box32_node) == 128); + for (uint32_t i = 0; i < pBuildInfo->geometryCount; ++i) { const VkAccelerationStructureGeometryKHR *geometry; if (pBuildInfo->pGeometries) diff --git a/src/amd/vulkan/radv_acceleration_structure.h b/src/amd/vulkan/radv_acceleration_structure.h new file mode 100644 index 00000000000..63d6ed29eb8 --- /dev/null +++ b/src/amd/vulkan/radv_acceleration_structure.h @@ -0,0 +1,87 @@ +/* + * Copyright © 2021 Bas Nieuwenhuizen + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef RADV_ACCELERATION_STRUCTURE_H +#define RADV_ACCELERATION_STRUCTURE_H + +#include + +struct radv_accel_struct_header { + uint32_t root_node_offset; + uint32_t reserved; + float aabb[2][3]; + uint64_t compacted_size; + uint64_t serialization_size; +}; + +struct radv_bvh_triangle_node { + float coords[3][3]; + uint32_t reserved[3]; + uint32_t triangle_id; + /* flags in upper 4 bits */ + uint32_t geometry_id_and_flags; + uint32_t reserved2; + uint32_t id; +}; + +struct radv_bvh_aabb_node { + float aabb[2][3]; + uint32_t primitive_id; + /* flags in upper 4 bits */ + uint32_t geometry_id_and_flags; + uint32_t reserved[8]; +}; + +struct radv_bvh_instance_node { + uint64_t base_ptr; + /* lower 24 bits are the custom instance index, upper 8 bits are the visibility mask */ + uint32_t custom_instance_and_mask; + /* lower 24 bits are the sbt offset, upper 8 bits are VkGeometryInstanceFlagsKHR */ + uint32_t sbt_offset_and_flags; + + /* The translation component is actually a pre-translation instead of a post-translation. If you + * want to get a proper matrix out of it you need to apply the directional component of the + * matrix to it. The pre-translation of the world->object matrix is the same as the + * post-translation of the object->world matrix so this way we can share data between both + * matrices. */ + float wto_matrix[12]; + float aabb[2][3]; + uint32_t instance_id; + + /* Object to world matrix transposed from the initial transform. Translate part is store in the + * wto_matrix. */ + float otw_matrix[9]; +}; + +struct radv_bvh_box16_node { + uint32_t children[4]; + uint32_t coords[4][3]; +}; + +struct radv_bvh_box32_node { + uint32_t children[4]; + float coords[4][2][3]; + uint32_t reserved[4]; +}; + +#endif \ No newline at end of file