1 /* 2 * Copyright © 2016 Red Hat. 3 * Copyright © 2016 Bas Nieuwenhuizen 4 * 5 * based in part on anv driver which is: 6 * Copyright © 2015 Intel Corporation 7 * 8 * SPDX-License-Identifier: MIT 9 */ 10 11 #ifndef RADV_RRA_H 12 #define RADV_RRA_H 13 14 #include "util/simple_mtx.h" 15 #include "util/u_dynarray.h" 16 17 #include <vulkan/vulkan.h> 18 19 #include <assert.h> 20 #include <stdbool.h> 21 22 struct radv_device; 23 24 struct radv_rra_accel_struct_data { 25 VkEvent build_event; 26 uint64_t va; 27 uint64_t size; 28 struct radv_rra_accel_struct_buffer *buffer; 29 VkAccelerationStructureTypeKHR type; 30 bool is_dead; 31 }; 32 33 struct radv_rra_accel_struct_buffer { 34 VkBuffer buffer; 35 VkDeviceMemory memory; 36 uint32_t ref_cnt; 37 }; 38 39 enum radv_rra_ray_history_metadata_type { 40 RADV_RRA_COUNTER_INFO = 1, 41 RADV_RRA_DISPATCH_SIZE = 2, 42 RADV_RRA_TRAVERSAL_FLAGS = 3, 43 }; 44 45 struct radv_rra_ray_history_metadata_info { 46 enum radv_rra_ray_history_metadata_type type : 32; 47 uint32_t padding; 48 uint64_t size; 49 }; 50 51 enum radv_rra_pipeline_type { 52 RADV_RRA_PIPELINE_RAY_TRACING, 53 }; 54 55 struct radv_rra_ray_history_counter { 56 uint32_t dispatch_size[3]; 57 uint32_t hit_shader_count; 58 uint32_t miss_shader_count; 59 uint32_t shader_count; 60 uint64_t pipeline_api_hash; 61 uint32_t mode; 62 uint32_t mask; 63 uint32_t stride; 64 uint32_t data_size; 65 uint32_t lost_token_size; 66 uint32_t ray_id_begin; 67 uint32_t ray_id_end; 68 enum radv_rra_pipeline_type pipeline_type : 32; 69 }; 70 71 struct radv_rra_ray_history_dispatch_size { 72 uint32_t size[3]; 73 uint32_t padding; 74 }; 75 76 struct radv_rra_ray_history_traversal_flags { 77 uint32_t box_sort_mode : 1; 78 uint32_t node_ptr_flags : 1; 79 uint32_t reserved : 30; 80 uint32_t padding; 81 }; 82 83 struct radv_rra_ray_history_metadata { 84 struct radv_rra_ray_history_metadata_info counter_info; 85 struct radv_rra_ray_history_counter counter; 86 87 struct radv_rra_ray_history_metadata_info dispatch_size_info; 88 struct radv_rra_ray_history_dispatch_size dispatch_size; 89 90 struct radv_rra_ray_history_metadata_info traversal_flags_info; 91 struct radv_rra_ray_history_traversal_flags traversal_flags; 92 }; 93 static_assert(sizeof(struct radv_rra_ray_history_metadata) == 136, 94 "radv_rra_ray_history_metadata does not match RRA expectations"); 95 96 struct radv_rra_ray_history_data { 97 struct radv_rra_ray_history_metadata metadata; 98 }; 99 100 struct radv_rra_trace_data { 101 struct hash_table *accel_structs; 102 struct hash_table_u64 *accel_struct_vas; 103 simple_mtx_t data_mtx; 104 bool validate_as; 105 bool copy_after_build; 106 bool triggered; 107 uint32_t copy_memory_index; 108 109 struct util_dynarray ray_history; 110 VkBuffer ray_history_buffer; 111 VkDeviceMemory ray_history_memory; 112 void *ray_history_data; 113 uint64_t ray_history_addr; 114 uint32_t ray_history_buffer_size; 115 uint32_t ray_history_resolution_scale; 116 }; 117 118 struct radv_ray_history_header { 119 uint32_t offset; 120 uint32_t dispatch_index; 121 uint32_t submit_base_index; 122 }; 123 124 enum radv_packed_token_type { 125 radv_packed_token_end_trace, 126 }; 127 128 struct radv_packed_token_header { 129 uint32_t launch_index : 29; 130 uint32_t hit : 1; 131 uint32_t token_type : 2; 132 }; 133 134 struct radv_packed_end_trace_token { 135 struct radv_packed_token_header header; 136 137 uint32_t accel_struct_lo; 138 uint32_t accel_struct_hi; 139 140 uint32_t flags : 16; 141 uint32_t dispatch_index : 16; 142 143 uint32_t sbt_offset : 4; 144 uint32_t sbt_stride : 4; 145 uint32_t miss_index : 16; 146 uint32_t cull_mask : 8; 147 148 float origin[3]; 149 float tmin; 150 float direction[3]; 151 float tmax; 152 153 uint32_t iteration_count : 16; 154 uint32_t instance_count : 16; 155 156 uint32_t ahit_count : 16; 157 uint32_t isec_count : 16; 158 159 uint32_t primitive_id; 160 uint32_t geometry_id; 161 162 uint32_t instance_id : 24; 163 uint32_t hit_kind : 8; 164 165 float t; 166 }; 167 static_assert(sizeof(struct radv_packed_end_trace_token) == 76, "Unexpected radv_packed_end_trace_token size"); 168 169 VkResult radv_rra_trace_init(struct radv_device *device); 170 171 void radv_rra_trace_clear_ray_history(VkDevice _device, struct radv_rra_trace_data *data); 172 173 void radv_radv_rra_accel_struct_buffer_ref(struct radv_rra_accel_struct_buffer *buffer); 174 175 void radv_rra_accel_struct_buffer_unref(struct radv_device *device, struct radv_rra_accel_struct_buffer *buffer); 176 177 struct set; 178 void radv_rra_accel_struct_buffers_unref(struct radv_device *device, struct set *buffers); 179 180 void radv_rra_trace_finish(VkDevice vk_device, struct radv_rra_trace_data *data); 181 182 void radv_destroy_rra_accel_struct_data(VkDevice device, struct radv_rra_accel_struct_data *data); 183 184 VkResult radv_rra_dump_trace(VkQueue vk_queue, char *filename); 185 186 #endif /* RADV_RRA_H */ 187