1 /* 2 * Copyright © 2016 Red Hat. 3 * Copyright © 2016 Bas Nieuwenhuizen 4 * SPDX-License-Identifier: MIT 5 * 6 * based in part on anv driver which is: 7 * Copyright © 2015 Intel Corporation 8 */ 9 10 #ifndef TU_COMMON_H 11 #define TU_COMMON_H 12 13 #include <assert.h> 14 #include <pthread.h> 15 #include <stdbool.h> 16 #include <stdint.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <string.h> 20 #include <tuple> 21 #ifdef HAVE_VALGRIND 22 #include <memcheck.h> 23 #include <valgrind.h> 24 #define VG(x) x 25 #else 26 #define VG(x) ((void)0) 27 #endif 28 29 #define MESA_LOG_TAG "TU" 30 31 #include "c11/threads.h" 32 #include "util/rounding.h" 33 #include "util/bitscan.h" 34 #include "util/detect_os.h" 35 #include "util/list.h" 36 #include "util/log.h" 37 #include "util/macros.h" 38 #include "util/perf/cpu_trace.h" 39 #include "util/sparse_array.h" 40 #include "util/u_atomic.h" 41 #include "util/u_dynarray.h" 42 #include "util/xmlconfig.h" 43 #include "util/perf/u_trace.h" 44 #include "vk_alloc.h" 45 #include "vk_debug_report.h" 46 #include "vk_device.h" 47 #include "vk_dispatch_table.h" 48 #include "vk_extensions.h" 49 #include "vk_instance.h" 50 #include "vk_log.h" 51 #include "vk_physical_device.h" 52 #include "vk_pipeline_cache.h" 53 #include "wsi_common.h" 54 55 #include "ir3/ir3_compiler.h" 56 #include "ir3/ir3_shader.h" 57 58 #include "adreno_common.xml.h" 59 #include "adreno_pm4.xml.h" 60 #include "a6xx.xml.h" 61 #include "fdl/freedreno_layout.h" 62 #include "common/freedreno_dev_info.h" 63 #include "common/freedreno_common.h" 64 #include "perfcntrs/freedreno_perfcntr.h" 65 66 #include <vulkan/vk_android_native_buffer.h> 67 #include <vulkan/vk_icd.h> 68 #include <vulkan/vulkan.h> 69 70 #include "tu_entrypoints.h" 71 #include "vulkan/runtime/vk_common_entrypoints.h" 72 73 #include "vk_format.h" 74 #include "vk_image.h" 75 #include "vk_command_buffer.h" 76 #include "vk_command_pool.h" 77 #include "vk_queue.h" 78 #include "vk_object.h" 79 #include "vk_sync.h" 80 #include "vk_drm_syncobj.h" 81 #include "vk_sync_timeline.h" 82 83 #define MAX_VBS 32 84 #define MAX_VERTEX_ATTRIBS 32 85 #define MAX_RTS 8 86 #define MAX_VSC_PIPES 32 87 #define MAX_VIEWPORTS 16 88 #define MAX_VIEWPORT_SIZE (1 << 14) 89 #define MAX_SCISSORS 16 90 #define MAX_DISCARD_RECTANGLES 4 91 #define MAX_PUSH_CONSTANTS_SIZE 256 92 #define MAX_PUSH_DESCRIPTORS 32 93 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16 94 #define MAX_DYNAMIC_STORAGE_BUFFERS 8 95 #define MAX_DYNAMIC_BUFFERS_SIZE \ 96 (MAX_DYNAMIC_UNIFORM_BUFFERS + 2 * MAX_DYNAMIC_STORAGE_BUFFERS) * \ 97 A6XX_TEX_CONST_DWORDS 98 99 #define SAMPLE_LOCATION_MIN 0.f 100 #define SAMPLE_LOCATION_MAX 0.9375f 101 102 #define TU_MAX_DRM_DEVICES 8 103 #define MAX_VIEWS 16 104 #define MAX_BIND_POINTS 2 /* compute + graphics */ 105 /* match the latest Qualcomm driver which is also a hw limit on later gens */ 106 #define MAX_STORAGE_BUFFER_RANGE (1u << 27) 107 /* We use ldc for uniform buffer loads, just like the Qualcomm driver, so 108 * expose the same maximum range. 109 * TODO: The SIZE bitfield is 15 bits, and in 4-dword units, so the actual 110 * range might be higher. 111 */ 112 #define MAX_UNIFORM_BUFFER_RANGE 0x10000 113 114 /* Use the minimum maximum to guarantee that it can always fit in the safe 115 * const file size, even with maximum push constant usage and driver params. 116 */ 117 #define MAX_INLINE_UBO_RANGE 256 118 #define MAX_INLINE_UBOS 4 119 120 #define A6XX_TEX_CONST_DWORDS 16 121 #define A6XX_TEX_SAMP_DWORDS 4 122 123 /* We sample the fragment density map on the CPU, so technically the 124 * minimum/maximum texel size is arbitrary. However sizes smaller than the 125 * minimum tile width alignment of 32 are likely pointless, so we use that as 126 * the minimum value. For the maximum just pick a value larger than anyone 127 * would reasonably need. 128 */ 129 #define MIN_FDM_TEXEL_SIZE_LOG2 5 130 #define MIN_FDM_TEXEL_SIZE (1u << MIN_FDM_TEXEL_SIZE_LOG2) 131 #define MAX_FDM_TEXEL_SIZE_LOG2 10 132 #define MAX_FDM_TEXEL_SIZE (1u << MAX_FDM_TEXEL_SIZE_LOG2) 133 134 #define TU_FROM_HANDLE(__tu_type, __name, __handle) \ 135 VK_FROM_HANDLE(__tu_type, __name, __handle) 136 137 #define TU_GPU_GENS A6XX, A7XX 138 #define TU_GENX(FUNC_NAME) \ 139 template <chip... CHIPs> constexpr auto FUNC_NAME##instantiate() \ 140 { \ 141 return std::tuple_cat(std::make_tuple(FUNC_NAME<CHIPs>)...); \ 142 } \ 143 static constexpr auto FUNC_NAME##tmpl __attribute__((used)) = \ 144 FUNC_NAME##instantiate<TU_GPU_GENS>(); 145 146 #define TU_CALLX(device, thing) \ 147 ({ \ 148 decltype(&thing<A6XX>) genX_thing; \ 149 switch ((device)->physical_device->info->chip) { \ 150 case 6: \ 151 genX_thing = &thing<A6XX>; \ 152 break; \ 153 case 7: \ 154 genX_thing = &thing<A7XX>; \ 155 break; \ 156 default: \ 157 unreachable("Unknown hardware generation"); \ 158 } \ 159 genX_thing; \ 160 }) 161 162 /* vk object types */ 163 struct tu_buffer; 164 struct tu_buffer_view; 165 struct tu_cmd_buffer; 166 struct tu_cmd_pool; 167 struct tu_descriptor_pool; 168 struct tu_descriptor_set; 169 struct tu_descriptor_set_layout; 170 struct tu_descriptor_update_template; 171 struct tu_device; 172 struct tu_device_memory; 173 struct tu_event; 174 struct tu_framebuffer; 175 struct tu_image; 176 struct tu_image_view; 177 struct tu_instance; 178 struct tu_physical_device; 179 struct tu_pipeline_layout; 180 struct tu_query_pool; 181 struct tu_queue; 182 struct tu_render_pass; 183 struct tu_sampler; 184 struct tu_sampler_ycbcr_conversion; 185 186 struct breadcrumbs_context; 187 struct tu_bo; 188 struct tu_cs; 189 struct tu_cs_entry; 190 struct tu_suballoc_bo; 191 struct tu_suballocator; 192 struct tu_subpass; 193 struct tu_u_trace_submission_data; 194 195 #endif /* TU_COMMON_H */ 196