1 // 2 // Copyright (C) 2009-2021 Intel Corporation 3 // 4 // SPDX-License-Identifier: MIT 5 // 6 // 7 8 // 9 // This file is to contain structure definitions for RTAS-related meta-deta. 10 // The structures here should be generic enough to apply to any acceleration structure. 11 // If we ever move to KD-Trees or Octrees, this file should not need to change. 12 // 13 14 //******************************************************************************************** 15 // WARNING!!!!! 16 // 17 // This file is shared by OpenCL and C++ source code and must be a pure C header 18 // There should only be C structure definitions and trivial inline functions here 19 // 20 //******************************************************************************************** 21 22 23 #pragma once 24 #include "GRLIntTypes.h" 25 26 GRL_NAMESPACE_BEGIN(GRL) 27 GRL_NAMESPACE_BEGIN(RTAS) 28 29 typedef struct SerializationIdentifier 30 { 31 uint8_t Bytes[16]; 32 } SerializationIdentifier; 33 34 GRL_STATIC_ASSERT(sizeof(SerializationIdentifier) == 16, "Wrong size!"); 35 36 37 // Header structure for RTAS serialization. 38 // This structure is binary-compatible with the DXR and Vulkan API definitions 39 typedef struct SerializationHeader 40 { 41 SerializationIdentifier DriverID; // DXR 'DriverOpaqueGUID'. Vulkan: 'driverUUID' 42 SerializationIdentifier GRLID; // DXR 'DriverOpaqueVersioningData'. Vulkan: 'accelerationStructureUUID' 43 44 uint64_t SerializedSizeInBytesIncludingHeader; 45 uint64_t DeserializedSizeInBytes; 46 uint64_t InstanceHandleCount; 47 } SerializationHeader; 48 49 GRL_STATIC_ASSERT(sizeof(SerializationHeader) == 56, "Wrong size!"); 50 51 // This structure is binary-compatible with DXR and Vulkan 'InstanceDesc' structures 52 typedef struct InstanceDesc { 53 float Transform[3][4]; 54 uint32_t InstanceIDAndMask; // mask in 8 msbs 55 uint32_t InstanceContributionToHitGroupIndexAndFlags; // flags in 8 msbs 56 gpuva_t AccelerationStructureGPUVA; // NOTE: In GRL this is always a VA. Vulkan CPU builds use handles here, and these may need to be translated 57 } InstanceDesc; 58 GRL_STATIC_ASSERT(sizeof(InstanceDesc) == 64, "Wrong size!"); 59 60 typedef struct GeoMetaData{ 61 uint32_t PrimitiveCount; 62 uint16_t Type; 63 uint16_t Flags; 64 } GeoMetaData; 65 GRL_STATIC_ASSERT(sizeof(GeoMetaData) == 8, "Wrong size!"); 66 67 typedef struct AABB3f { 68 float lower[3]; 69 float upper[3]; 70 } AABB3f; 71 GRL_STATIC_ASSERT(sizeof(AABB3f) == 24, "Wrong size!"); 72 enum_uint32(error_t_)73 enum_uint32(error_t_) { 74 error_t_no_error = 0x0, 75 error_t_internal_node_child_OOB = 0x1, 76 error_t_leaf_node_child_OOB = 0x2, 77 error_t_unrecognised_node_t = 0x4, 78 error_t_mixed_node_unsupported = 0x8, 79 error_t_instance_pointers_inconsistent = 0x10, 80 error_t_instance_pointed_root_not_internal = 0x20, 81 error_t_leaf_node_instance_child_missed_by_64B = 0x40, 82 error_t_internal_node_child_cycle = 0x80, 83 error_t_input_geo_insane = 0x100, 84 error_t_quad_leaf_broken = 0x200, 85 error_t_backpointer_not_reset = 0x400, 86 error_t_backpointer_wrong_children_num = 0x500, 87 error_t_backpointer_inconsitent_parent_child = 0x600, 88 error_t_backpointer_root_not_root_error = 0x700, 89 error_t_backpointer_OOB = 0x800, 90 error_t_backpointers_buffer_too_small = 0x900, 91 error_t_atomic_update_struct_fatleaf_count_oob = 0x1000, // for this and following: 92 error_t_atomic_update_struct_fatleaf_node_idx_oob = 0x2000, // offset_in_BVH is just index in fatleaf or inner node arrays 93 error_t_atomic_update_struct_fatleaf_backpointer_mismatch = 0x3000, 94 error_t_atomic_update_struct_fatleaf_num_children_error = 0x4000, 95 error_t_atomic_update_struct_fatleaf_children_non_leaf = 0x5000, 96 error_t_atomic_update_struct_inner_count_oob = 0x6000, 97 error_t_atomic_update_struct_inner_node_idx_oob = 0x7000, 98 error_t_atomic_update_struct_inner_node_child_idx_error = 0x8000, 99 error_t_atomic_update_struct_inner_num_children_error = 0x9000, 100 error_t_atomic_update_struct_inner_children_non_internal = 0xA000, 101 error_t_unknown = 1u << 31, 102 }; 103 enum_uint32(error_phase_t)104 enum_uint32(error_phase_t) { 105 error_phase_t_unknown = 0, 106 error_phase_t_post_build_Morton = 1, 107 error_phase_t_post_build_Trivial = 2, 108 error_phase_t_post_build_NewSAH = 3, 109 error_phase_t_post_update = 4, 110 error_phase_t_pre_update = 5, 111 error_phase_t_post_copy_op = 6, 112 }; 113 114 typedef struct ERROR_INFO { 115 error_t_ type; 116 uint offset_in_BVH; //in 64B units 117 error_phase_t when; 118 uint reserved; 119 } ERROR_INFO; 120 121 // Meta-data common to all acceleration structures, which is needed to implement required functionality 122 // All RTAS structures must contain a struct of this type named 'Meta' 123 typedef struct RTASMetaData { 124 struct AABB3f bounds; 125 126 uint32_t instanceDescsStart; // byte offset to array of original instance_descs used for build. Required for DXR visualization and serialization 127 uint32_t instanceCount; 128 129 uint32_t geoDescsStart; // byte offset to array of 'GeoMetaData' matching input geos. Required for DXR visualization 130 uint32_t geoCount; 131 132 uint64_t allocationSize; // Size of the memory allocation containing this RTAS 133 // This is the size given to the app in the prebuild info when the RTAS was first created 134 // If RTAS was compacted, this will be the compacted size 135 136 ERROR_INFO errors; // only used in debug mode 137 } RTASMetaData; 138 139 GRL_STATIC_ASSERT( sizeof(RTASMetaData) == 64, "Wrong size!"); 140 141 GRL_NAMESPACE_END(RTAS) 142 GRL_NAMESPACE_END(GRL) 143