| 1 |
/* |
| 2 |
* Copyright © 2021 Collabora Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef PANVK_DEVICE_H |
| 7 |
#define PANVK_DEVICE_H |
| 8 |
|
| 9 |
#include <stdint.h> |
| 10 |
|
| 11 |
#include "vk_debug_utils.h" |
| 12 |
#include "vk_device.h" |
| 13 |
#include "vk_meta.h" |
| 14 |
|
| 15 |
#include "panvk_blend.h" |
| 16 |
#include "panvk_instance.h" |
| 17 |
#include "panvk_macros.h" |
| 18 |
#include "panvk_mempool.h" |
| 19 |
#include "panvk_physical_device.h" |
| 20 |
#include "panvk_utrace_perfetto.h" |
| 21 |
|
| 22 |
#include "kmod/pan_kmod.h" |
| 23 |
#include "util/perf/u_trace.h" |
| 24 |
|
| 25 |
#include "util/simple_mtx.h" |
| 26 |
#include "util/u_call_once.h" |
| 27 |
#include "util/u_printf.h" |
| 28 |
#include "util/vma.h" |
| 29 |
|
| 30 |
/* On JM hardware, we need to allocate a buffer depending on vertex count. |
| 31 |
* |
| 32 |
* As a result, for indirect and indexed draw we allocate a large buffer with |
| 33 |
* alloc on fault set. |
| 34 |
* |
| 35 |
* The size of that buffer is calculated assuming a max of 2 millions vertices |
| 36 |
* and 18 attributes per vertex (16 user attributes, 2 specials) |
| 37 |
*/ |
| 38 |
|
| 39 |
#define PANVK_JM_MAX_VERTICES_INDIRECT (2000000) |
| 40 |
#define PANVK_JM_MAX_PER_VTX_ATTRIBUTES_INDIRECT_SIZE (18 * 4) |
| 41 |
|
| 42 |
struct panvk_precomp_cache; |
| 43 |
struct panvk_device_draw_context; |
| 44 |
|
| 45 |
enum panvk_queue_family { |
| 46 |
PANVK_QUEUE_FAMILY_GPU, |
| 47 |
PANVK_QUEUE_FAMILY_BIND, |
| 48 |
PANVK_QUEUE_FAMILY_COUNT, |
| 49 |
}; |
| 50 |
|
| 51 |
struct panvk_device_queue_family { |
| 52 |
struct vk_queue **queues; |
| 53 |
int queue_count; |
| 54 |
}; |
| 55 |
|
| 56 |
struct panvk_device { |
| 57 |
struct vk_device vk; |
| 58 |
|
| 59 |
struct { |
| 60 |
simple_mtx_t lock; |
| 61 |
struct util_vma_heap heap; |
| 62 |
struct util_vma_heap fixed_heap; |
| 63 |
struct util_vma_heap *priv_heap; |
| 64 |
bool split_heap; |
| 65 |
bool extended_range; |
| 66 |
} as; |
| 67 |
|
| 68 |
struct { |
| 69 |
struct pan_kmod_vm *vm; |
| 70 |
struct pan_kmod_dev *dev; |
| 71 |
struct pan_kmod_allocator allocator; |
| 72 |
} kmod; |
| 73 |
|
| 74 |
struct panvk_priv_bo *tiler_heap; |
| 75 |
struct panvk_priv_bo *indirect_varying_buffer; |
| 76 |
struct panvk_priv_bo *sample_positions; |
| 77 |
|
| 78 |
struct { |
| 79 |
struct panvk_priv_bo *handlers_bo; |
| 80 |
uint32_t handler_stride; |
| 81 |
} tiler_oom; |
| 82 |
|
| 83 |
struct vk_meta_device meta; |
| 84 |
|
| 85 |
struct { |
| 86 |
struct panvk_pool rw; |
| 87 |
struct panvk_pool rw_nc; |
| 88 |
struct panvk_pool exec; |
| 89 |
} mempools; |
| 90 |
|
| 91 |
struct { |
| 92 |
util_once_flag blackhole_once; |
| 93 |
struct pan_kmod_bo *blackhole; |
| 94 |
} sparse_mem; |
| 95 |
|
| 96 |
/* For each subqueue, maximum size of the register dump region needed by |
| 97 |
* exception handlers or functions */ |
| 98 |
uint32_t *dump_region_size; |
| 99 |
|
| 100 |
struct vk_device_dispatch_table cmd_dispatch; |
| 101 |
|
| 102 |
struct panvk_device_queue_family queue_families[PANVK_QUEUE_FAMILY_COUNT]; |
| 103 |
|
| 104 |
struct panvk_precomp_cache *precomp_cache; |
| 105 |
|
| 106 |
struct { |
| 107 |
struct u_trace_context utctx; |
| 108 |
#ifdef HAVE_PERFETTO |
| 109 |
struct panvk_utrace_perfetto utp; |
| 110 |
#endif |
| 111 |
/* Timestamp + indirect data storage */ |
| 112 |
struct util_vma_heap copy_buf_heap; |
| 113 |
struct panvk_priv_bo *copy_buf_heap_bo; |
| 114 |
simple_mtx_t copy_buf_heap_lock; |
| 115 |
} utrace; |
| 116 |
|
| 117 |
struct panvk_device_draw_context* draw_ctx; |
| 118 |
|
| 119 |
struct { |
| 120 |
struct pandecode_context *decode_ctx; |
| 121 |
} debug; |
| 122 |
|
| 123 |
struct { |
| 124 |
struct u_printf_ctx ctx; |
| 125 |
struct panvk_priv_bo *bo; |
| 126 |
} printf; |
| 127 |
|
| 128 |
union { |
| 129 |
struct { |
| 130 |
struct { |
| 131 |
uint8_t count; |
| 132 |
uint8_t iter_count; |
| 133 |
uint16_t all_mask; |
| 134 |
uint16_t all_iters_mask; |
| 135 |
} sb; |
| 136 |
} csf; |
| 137 |
}; |
| 138 |
|
| 139 |
int drm_fd; |
| 140 |
}; |
| 141 |
|
| 142 |
VK_DEFINE_HANDLE_CASTS(panvk_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE) |
| 143 |
|
| 144 |
static inline struct panvk_device * |
| 145 |
to_panvk_device(struct vk_device *dev) |
| 146 |
{ |
| 147 |
return container_of(dev, struct panvk_device, vk); |
| 148 |
} |
| 149 |
|
| 150 |
static inline uint32_t |
| 151 |
panvk_device_adjust_bo_flags(const struct panvk_device *device, |
| 152 |
uint32_t bo_flags) |
| 153 |
{ |
| 154 |
struct panvk_physical_device *pdev = |
| 155 |
to_panvk_physical_device(device->vk.physical); |
| 156 |
|
| 157 |
/* Dumping of GPU buffers messes up with CPU caches by loading buffers |
| 158 |
* into cachelines which are sometimes assumed to be invalidated by the |
| 159 |
* rest of the code. We could explicitly invalidate after a dump, but |
| 160 |
* this is simpler to just disable cached-mappings when PANVK_DEBUG="dump". |
| 161 |
* Tracing has the same fundamental issue, but we'll take care of that |
| 162 |
* at the desc/CS pools level. |
| 163 |
*/ |
| 164 |
const bool allow_wb_mmap = |
| 165 |
(pdev->kmod.dev->props.supported_bo_flags & PAN_KMOD_BO_FLAG_WB_MMAP) && |
| 166 |
!PANVK_DEBUG(DUMP) && !PANVK_DEBUG(NO_WB_MMAP); |
| 167 |
|
| 168 |
if (!allow_wb_mmap) |
| 169 |
bo_flags &= ~PAN_KMOD_BO_FLAG_WB_MMAP; |
| 170 |
|
| 171 |
if (PANVK_DEBUG(DUMP) || PANVK_DEBUG(TRACE)) |
| 172 |
bo_flags &= ~PAN_KMOD_BO_FLAG_NO_MMAP; |
| 173 |
|
| 174 |
if (!(device->kmod.dev->props.supported_bo_flags & |
| 175 |
PAN_KMOD_BO_FLAG_GPU_UNCACHED)) |
| 176 |
bo_flags &= ~PAN_KMOD_BO_FLAG_GPU_UNCACHED; |
| 177 |
|
| 178 |
return bo_flags; |
| 179 |
} |
| 180 |
|
| 181 |
static inline uint64_t |
| 182 |
panvk_get_gpu_page_size(const struct panvk_device *device) |
| 183 |
{ |
| 184 |
return (uint64_t)1 << (ffsll(device->kmod.vm->pgsize_bitmap) - 1); |
| 185 |
} |
| 186 |
|
| 187 |
static inline uint64_t |
| 188 |
panvk_as_alloc(struct panvk_device *device, struct util_vma_heap *heap, |
| 189 |
uint64_t size, uint64_t alignment) |
| 190 |
{ |
| 191 |
simple_mtx_lock(&device->as.lock); |
| 192 |
uint64_t address = util_vma_heap_alloc(heap, size, alignment); |
| 193 |
simple_mtx_unlock(&device->as.lock); |
| 194 |
return address; |
| 195 |
} |
| 196 |
|
| 197 |
static inline uint64_t |
| 198 |
panvk_as_alloc_fixed_address(struct panvk_device *device, |
| 199 |
struct util_vma_heap *heap, uint64_t address, |
| 200 |
uint64_t size) |
| 201 |
{ |
| 202 |
simple_mtx_lock(&device->as.lock); |
| 203 |
bool alloc_result = util_vma_heap_alloc_addr(heap, address, size); |
| 204 |
simple_mtx_unlock(&device->as.lock); |
| 205 |
return alloc_result ? address : 0; |
| 206 |
} |
| 207 |
|
| 208 |
static inline void |
| 209 |
panvk_as_free(struct panvk_device *device, struct util_vma_heap *heap, |
| 210 |
uint64_t address, uint64_t size) |
| 211 |
{ |
| 212 |
simple_mtx_lock(&device->as.lock); |
| 213 |
util_vma_heap_free(heap, address, size); |
| 214 |
simple_mtx_unlock(&device->as.lock); |
| 215 |
} |
| 216 |
|
| 217 |
#if PAN_ARCH |
| 218 |
VkResult |
| 219 |
panvk_per_arch(create_device)(struct panvk_physical_device *physical_device, |
| 220 |
const VkDeviceCreateInfo *pCreateInfo, |
| 221 |
const VkAllocationCallbacks *pAllocator, |
| 222 |
VkDevice *pDevice); |
| 223 |
|
| 224 |
void panvk_per_arch(destroy_device)(struct panvk_device *device, |
| 225 |
const VkAllocationCallbacks *pAllocator); |
| 226 |
|
| 227 |
static inline VkResult |
| 228 |
panvk_common_check_status(struct panvk_device *dev) |
| 229 |
{ |
| 230 |
return vk_check_printf_status(&dev->vk, &dev->printf.ctx); |
| 231 |
} |
| 232 |
|
| 233 |
VkResult panvk_per_arch(device_check_status)(struct vk_device *vk_dev); |
| 234 |
|
| 235 |
#if PAN_ARCH >= 10 |
| 236 |
VkResult panvk_per_arch(init_tiler_oom)(struct panvk_device *device); |
| 237 |
#endif |
| 238 |
#endif |
| 239 |
|
| 240 |
#endif |