1 /* 2 * Copyright © 2022 Friedrich Vock 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_RMV_COMMON_H 25 #define VK_RMV_COMMON_H 26 27 #include <stdbool.h> 28 #include "util/hash_table.h" 29 #include "util/simple_mtx.h" 30 #include "util/u_debug.h" 31 #include "util/u_dynarray.h" 32 #include <vulkan/vulkan_core.h> 33 #include "vk_rmv_tokens.h" 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 struct vk_memory_trace_data; 40 41 /* 42 * The different memory domains RMV supports. 43 */ 44 enum vk_rmv_memory_location { 45 /* DEVICE_LOCAL | HOST_VISIBLE */ 46 VK_RMV_MEMORY_LOCATION_DEVICE, 47 /* DEVICE_LOCAL */ 48 VK_RMV_MEMORY_LOCATION_DEVICE_INVISIBLE, 49 /* HOST_VISIBLE | HOST_COHERENT */ 50 VK_RMV_MEMORY_LOCATION_HOST, 51 52 /* add above here */ 53 VK_RMV_MEMORY_LOCATION_COUNT 54 }; 55 56 /* 57 * Information about a memory domain. 58 */ 59 struct vk_rmv_memory_info { 60 uint64_t size; 61 uint64_t physical_base_address; 62 }; 63 64 enum vk_rmv_memory_type { 65 VK_RMV_MEMORY_TYPE_UNKNOWN, 66 VK_RMV_MEMORY_TYPE_DDR2, 67 VK_RMV_MEMORY_TYPE_DDR3, 68 VK_RMV_MEMORY_TYPE_DDR4, 69 VK_RMV_MEMORY_TYPE_GDDR5, 70 VK_RMV_MEMORY_TYPE_GDDR6, 71 VK_RMV_MEMORY_TYPE_HBM, 72 VK_RMV_MEMORY_TYPE_HBM2, 73 VK_RMV_MEMORY_TYPE_HBM3, 74 VK_RMV_MEMORY_TYPE_LPDDR4, 75 VK_RMV_MEMORY_TYPE_LPDDR5, 76 VK_RMV_MEMORY_TYPE_DDR5 77 }; 78 79 /* 80 * Device information for RMV traces. 81 */ 82 struct vk_rmv_device_info { 83 struct vk_rmv_memory_info memory_infos[VK_RMV_MEMORY_LOCATION_COUNT]; 84 85 /* The memory type of dedicated VRAM. */ 86 enum vk_rmv_memory_type vram_type; 87 88 char device_name[128]; 89 90 uint32_t pcie_family_id; 91 uint32_t pcie_revision_id; 92 uint32_t pcie_device_id; 93 /* The minimum shader clock, in MHz. */ 94 uint32_t minimum_shader_clock; 95 /* The maximum shader clock, in MHz. */ 96 uint32_t maximum_shader_clock; 97 uint32_t vram_operations_per_clock; 98 uint32_t vram_bus_width; 99 /* The VRAM bandwidth, in GB/s (1 GB/s = 1000 MB/s). */ 100 uint32_t vram_bandwidth; 101 /* The minimum memory clock, in MHz. */ 102 uint32_t minimum_memory_clock; 103 /* The maximum memory clock, in MHz. */ 104 uint32_t maximum_memory_clock; 105 }; 106 107 struct vk_device; 108 109 struct vk_memory_trace_data { 110 struct util_dynarray tokens; 111 simple_mtx_t token_mtx; 112 113 bool is_enabled; 114 115 struct vk_rmv_device_info device_info; 116 117 struct hash_table_u64 *handle_table; 118 uint32_t next_resource_id; 119 }; 120 121 struct vk_device; 122 123 void vk_memory_trace_init(struct vk_device *device, const struct vk_rmv_device_info *device_info); 124 125 void vk_memory_trace_finish(struct vk_device *device); 126 127 int vk_dump_rmv_capture(struct vk_memory_trace_data *data); 128 129 void vk_rmv_emit_token(struct vk_memory_trace_data *data, enum vk_rmv_token_type type, 130 void *token_data); 131 void vk_rmv_log_buffer_create(struct vk_device *device, bool is_internal, VkBuffer _buffer); 132 void vk_rmv_log_cpu_map(struct vk_device *device, uint64_t va, bool is_unmap); 133 void vk_rmv_log_misc_token(struct vk_device *device, enum vk_rmv_misc_event_type type); 134 135 /* Retrieves the unique resource id for the resource specified by handle. 136 * Allocates a new id if none exists already. 137 * The memory trace mutex should be locked when entering this function. */ 138 uint32_t vk_rmv_get_resource_id_locked(struct vk_device *device, uint64_t handle); 139 /* Destroys a resource id. If the same handle is allocated again, a new resource 140 * id is given to it. 141 * The memory trace mutex should be locked when entering this function. */ 142 void vk_rmv_destroy_resource_id_locked(struct vk_device *device, uint64_t handle); 143 144 #ifdef __cplusplus 145 } 146 #endif 147 148 #endif 149