1 /* 2 * Copyright © 2022 Konstantin Seurer 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #ifndef VK_BVH_BUILD_INTERFACE_H 25 #define VK_BVH_BUILD_INTERFACE_H 26 27 #ifdef VULKAN 28 #include "vk_build_helpers.h" 29 #else 30 #include <stdint.h> 31 #include "vk_bvh.h" 32 #define REF(type) uint64_t 33 #define VOID_REF uint64_t 34 #endif 35 36 #define SUBGROUP_SIZE_ID 0 37 #define BVH_BOUNDS_OFFSET_ID 1 38 #ifdef VULKAN 39 layout (constant_id = SUBGROUP_SIZE_ID) const int SUBGROUP_SIZE = 64; 40 layout (constant_id = BVH_BOUNDS_OFFSET_ID) const int BVH_BOUNDS_OFFSET = 0; 41 #endif 42 43 struct leaf_args { 44 VOID_REF bvh; 45 REF(vk_ir_header) header; 46 REF(key_id_pair) ids; 47 48 vk_bvh_geometry_data geom_data; 49 }; 50 51 struct morton_args { 52 VOID_REF bvh; 53 REF(vk_ir_header) header; 54 REF(key_id_pair) ids; 55 }; 56 57 #define LBVH_RIGHT_CHILD_BIT_SHIFT 29 58 #define LBVH_RIGHT_CHILD_BIT (1 << LBVH_RIGHT_CHILD_BIT_SHIFT) 59 60 struct lbvh_node_info { 61 /* Number of children that have been processed (or are invalid/leaves) in 62 * the lbvh_generate_ir pass. 63 */ 64 uint32_t path_count; 65 66 uint32_t children[2]; 67 uint32_t parent; 68 }; 69 70 struct lbvh_main_args { 71 VOID_REF bvh; 72 REF(key_id_pair) src_ids; 73 VOID_REF node_info; 74 uint32_t id_count; 75 uint32_t internal_node_base; 76 }; 77 78 struct lbvh_generate_ir_args { 79 VOID_REF bvh; 80 VOID_REF node_info; 81 VOID_REF header; 82 uint32_t internal_node_base; 83 }; 84 85 struct ploc_prefix_scan_partition { 86 uint32_t aggregate; 87 uint32_t inclusive_sum; 88 }; 89 90 #define PLOC_WORKGROUP_SIZE 1024 91 #define PLOC_SUBGROUPS_PER_WORKGROUP \ 92 (DIV_ROUND_UP(PLOC_WORKGROUP_SIZE, SUBGROUP_SIZE)) 93 94 struct ploc_args { 95 VOID_REF bvh; 96 VOID_REF prefix_scan_partitions; 97 REF(vk_ir_header) header; 98 VOID_REF ids_0; 99 VOID_REF ids_1; 100 uint32_t internal_node_offset; 101 }; 102 103 #endif 104