1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2020 Advanced Micro Devices, Inc. 3bf215546Sopenharmony_ci * Copyright 2020 Valve Corporation 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 10bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 11bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 12bf215546Sopenharmony_ci * 13bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 14bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 15bf215546Sopenharmony_ci * Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 21bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 22bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 23bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef AC_RGP_H 27bf215546Sopenharmony_ci#define AC_RGP_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include <stdint.h> 30bf215546Sopenharmony_ci#include "compiler/shader_enums.h" 31bf215546Sopenharmony_ci#include "util/list.h" 32bf215546Sopenharmony_ci#include "util/simple_mtx.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct radeon_info; 35bf215546Sopenharmony_cistruct ac_thread_trace; 36bf215546Sopenharmony_cistruct ac_thread_trace_data; 37bf215546Sopenharmony_cistruct ac_spm_trace_data; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cienum rgp_hardware_stages { 40bf215546Sopenharmony_ci RGP_HW_STAGE_VS = 0, 41bf215546Sopenharmony_ci RGP_HW_STAGE_LS, 42bf215546Sopenharmony_ci RGP_HW_STAGE_HS, 43bf215546Sopenharmony_ci RGP_HW_STAGE_ES, 44bf215546Sopenharmony_ci RGP_HW_STAGE_GS, 45bf215546Sopenharmony_ci RGP_HW_STAGE_PS, 46bf215546Sopenharmony_ci RGP_HW_STAGE_CS, 47bf215546Sopenharmony_ci RGP_HW_STAGE_MAX, 48bf215546Sopenharmony_ci}; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cistruct rgp_shader_data { 51bf215546Sopenharmony_ci uint64_t hash[2]; 52bf215546Sopenharmony_ci uint32_t code_size; 53bf215546Sopenharmony_ci uint8_t *code; 54bf215546Sopenharmony_ci uint32_t vgpr_count; 55bf215546Sopenharmony_ci uint32_t sgpr_count; 56bf215546Sopenharmony_ci uint32_t scratch_memory_size; 57bf215546Sopenharmony_ci uint32_t wavefront_size; 58bf215546Sopenharmony_ci uint64_t base_address; 59bf215546Sopenharmony_ci uint32_t elf_symbol_offset; 60bf215546Sopenharmony_ci uint32_t hw_stage; 61bf215546Sopenharmony_ci uint32_t is_combined; 62bf215546Sopenharmony_ci}; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_cistruct rgp_code_object_record { 65bf215546Sopenharmony_ci uint32_t shader_stages_mask; 66bf215546Sopenharmony_ci struct rgp_shader_data shader_data[MESA_VULKAN_SHADER_STAGES]; 67bf215546Sopenharmony_ci uint32_t num_shaders_combined; /* count combined shaders as one count */ 68bf215546Sopenharmony_ci uint64_t pipeline_hash[2]; 69bf215546Sopenharmony_ci struct list_head list; 70bf215546Sopenharmony_ci}; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_cistruct rgp_code_object { 73bf215546Sopenharmony_ci uint32_t record_count; 74bf215546Sopenharmony_ci struct list_head record; 75bf215546Sopenharmony_ci simple_mtx_t lock; 76bf215546Sopenharmony_ci}; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_cienum rgp_loader_event_type 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci RGP_LOAD_TO_GPU_MEMORY = 0, 81bf215546Sopenharmony_ci RGP_UNLOAD_FROM_GPU_MEMORY, 82bf215546Sopenharmony_ci}; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_cistruct rgp_loader_events_record { 85bf215546Sopenharmony_ci uint32_t loader_event_type; 86bf215546Sopenharmony_ci uint32_t reserved; 87bf215546Sopenharmony_ci uint64_t base_address; 88bf215546Sopenharmony_ci uint64_t code_object_hash[2]; 89bf215546Sopenharmony_ci uint64_t time_stamp; 90bf215546Sopenharmony_ci struct list_head list; 91bf215546Sopenharmony_ci}; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_cistruct rgp_loader_events { 94bf215546Sopenharmony_ci uint32_t record_count; 95bf215546Sopenharmony_ci struct list_head record; 96bf215546Sopenharmony_ci simple_mtx_t lock; 97bf215546Sopenharmony_ci}; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_cistruct rgp_pso_correlation_record { 100bf215546Sopenharmony_ci uint64_t api_pso_hash; 101bf215546Sopenharmony_ci uint64_t pipeline_hash[2]; 102bf215546Sopenharmony_ci char api_level_obj_name[64]; 103bf215546Sopenharmony_ci struct list_head list; 104bf215546Sopenharmony_ci}; 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_cistruct rgp_pso_correlation { 107bf215546Sopenharmony_ci uint32_t record_count; 108bf215546Sopenharmony_ci struct list_head record; 109bf215546Sopenharmony_ci simple_mtx_t lock; 110bf215546Sopenharmony_ci}; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_cienum sqtt_queue_type { 113bf215546Sopenharmony_ci SQTT_QUEUE_TYPE_UNKNOWN = 0x0, 114bf215546Sopenharmony_ci SQTT_QUEUE_TYPE_UNIVERSAL = 0x1, 115bf215546Sopenharmony_ci SQTT_QUEUE_TYPE_COMPUTE = 0x2, 116bf215546Sopenharmony_ci SQTT_QUEUE_TYPE_DMA = 0x3, 117bf215546Sopenharmony_ci}; 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_cienum sqtt_engine_type { 120bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_UNKNOWN = 0x0, 121bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_UNIVERSAL = 0x1, 122bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_COMPUTE = 0x2, 123bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_EXCLUSIVE_COMPUTE = 0x3, 124bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_DMA = 0x4, 125bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_HIGH_PRIORITY_UNIVERSAL = 0x7, 126bf215546Sopenharmony_ci SQTT_ENGINE_TYPE_HIGH_PRIORITY_GRAPHICS = 0x8, 127bf215546Sopenharmony_ci}; 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_cistruct sqtt_queue_hardware_info { 130bf215546Sopenharmony_ci union { 131bf215546Sopenharmony_ci struct { 132bf215546Sopenharmony_ci enum sqtt_queue_type queue_type : 8; 133bf215546Sopenharmony_ci enum sqtt_engine_type engine_type : 8; 134bf215546Sopenharmony_ci uint32_t reserved : 16; 135bf215546Sopenharmony_ci }; 136bf215546Sopenharmony_ci uint32_t value; 137bf215546Sopenharmony_ci }; 138bf215546Sopenharmony_ci}; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_cistruct rgp_queue_info_record { 141bf215546Sopenharmony_ci uint64_t queue_id; 142bf215546Sopenharmony_ci uint64_t queue_context; 143bf215546Sopenharmony_ci struct sqtt_queue_hardware_info hardware_info; 144bf215546Sopenharmony_ci uint32_t reserved; 145bf215546Sopenharmony_ci struct list_head list; 146bf215546Sopenharmony_ci}; 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_cistruct rgp_queue_info { 149bf215546Sopenharmony_ci uint32_t record_count; 150bf215546Sopenharmony_ci struct list_head record; 151bf215546Sopenharmony_ci simple_mtx_t lock; 152bf215546Sopenharmony_ci}; 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_cienum sqtt_queue_event_type { 155bf215546Sopenharmony_ci SQTT_QUEUE_TIMING_EVENT_CMDBUF_SUBMIT, 156bf215546Sopenharmony_ci SQTT_QUEUE_TIMING_EVENT_SIGNAL_SEMAPHORE, 157bf215546Sopenharmony_ci SQTT_QUEUE_TIMING_EVENT_WAIT_SEMAPHORE, 158bf215546Sopenharmony_ci SQTT_QUEUE_TIMING_EVENT_PRESENT 159bf215546Sopenharmony_ci}; 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_cistruct rgp_queue_event_record { 162bf215546Sopenharmony_ci enum sqtt_queue_event_type event_type; 163bf215546Sopenharmony_ci uint32_t sqtt_cb_id; 164bf215546Sopenharmony_ci uint64_t frame_index; 165bf215546Sopenharmony_ci uint32_t queue_info_index; 166bf215546Sopenharmony_ci uint32_t submit_sub_index; 167bf215546Sopenharmony_ci uint64_t api_id; 168bf215546Sopenharmony_ci uint64_t cpu_timestamp; 169bf215546Sopenharmony_ci uint64_t gpu_timestamps[2]; 170bf215546Sopenharmony_ci struct list_head list; 171bf215546Sopenharmony_ci}; 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_cistruct rgp_queue_event { 174bf215546Sopenharmony_ci uint32_t record_count; 175bf215546Sopenharmony_ci struct list_head record; 176bf215546Sopenharmony_ci simple_mtx_t lock; 177bf215546Sopenharmony_ci}; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_cistruct rgp_clock_calibration_record { 180bf215546Sopenharmony_ci uint64_t cpu_timestamp; 181bf215546Sopenharmony_ci uint64_t gpu_timestamp; 182bf215546Sopenharmony_ci struct list_head list; 183bf215546Sopenharmony_ci}; 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_cistruct rgp_clock_calibration { 186bf215546Sopenharmony_ci uint32_t record_count; 187bf215546Sopenharmony_ci struct list_head record; 188bf215546Sopenharmony_ci simple_mtx_t lock; 189bf215546Sopenharmony_ci}; 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ciint 192bf215546Sopenharmony_ciac_dump_rgp_capture(struct radeon_info *info, 193bf215546Sopenharmony_ci struct ac_thread_trace *thread_trace, 194bf215546Sopenharmony_ci const struct ac_spm_trace_data *spm_trace); 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_civoid 197bf215546Sopenharmony_ciac_rgp_file_write_elf_object(FILE *output, size_t file_elf_start, 198bf215546Sopenharmony_ci struct rgp_code_object_record *record, 199bf215546Sopenharmony_ci uint32_t *written_size, uint32_t flags); 200bf215546Sopenharmony_ci 201bf215546Sopenharmony_ci#endif 202