xref: /aosp_15_r20/external/mesa3d/src/panfrost/vulkan/panvk_device.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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_device.h"
12 #include "vk_meta.h"
13 
14 #include "panvk_blend.h"
15 #include "panvk_instance.h"
16 #include "panvk_macros.h"
17 #include "panvk_mempool.h"
18 #include "panvk_meta.h"
19 #include "panvk_physical_device.h"
20 
21 #include "kmod/pan_kmod.h"
22 #include "util/pan_ir.h"
23 #include "pan_blend.h"
24 #include "pan_blitter.h"
25 
26 #include "util/vma.h"
27 
28 #define PANVK_MAX_QUEUE_FAMILIES 1
29 
30 struct panvk_device {
31    struct vk_device vk;
32 
33    struct {
34       struct util_vma_heap heap;
35    } as;
36 
37    struct {
38       struct pan_kmod_vm *vm;
39       struct pan_kmod_dev *dev;
40       struct pan_kmod_allocator allocator;
41    } kmod;
42 
43    struct panvk_priv_bo *tiler_heap;
44    struct panvk_priv_bo *sample_positions;
45 
46    /* Access to the blitter pools are protected by the blitter
47     * shader/rsd locks. They can't be merged with other binary/desc
48     * pools unless we patch pan_blitter.c to support external pool locks.
49     *
50     * FIXME: The blitter infrastructure is only needed for FB preload.
51     * We should probably consider getting rid of the dependency we have
52     * on pan_desc.c and implement preload ourselves so we don't have
53     * to duplicate caches.
54     */
55    struct {
56       struct panvk_pool bin_pool;
57       struct panvk_pool desc_pool;
58       struct pan_blitter_cache cache;
59       struct pan_blend_shader_cache blend_shader_cache;
60    } blitter;
61 
62    struct panvk_blend_shader_cache blend_shader_cache;
63    struct vk_meta_device meta;
64 
65    struct {
66       struct panvk_priv_mem shader;
67       struct panvk_priv_mem rsd;
68    } desc_copy;
69 
70    struct {
71       struct panvk_pool rw;
72       struct panvk_pool rw_nc;
73       struct panvk_pool exec;
74    } mempools;
75 
76    struct vk_device_dispatch_table cmd_dispatch;
77 
78    struct panvk_queue *queues[PANVK_MAX_QUEUE_FAMILIES];
79    int queue_count[PANVK_MAX_QUEUE_FAMILIES];
80 
81    struct {
82       struct pandecode_context *decode_ctx;
83    } debug;
84 };
85 
86 VK_DEFINE_HANDLE_CASTS(panvk_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE)
87 
88 static inline struct panvk_device *
to_panvk_device(struct vk_device * dev)89 to_panvk_device(struct vk_device *dev)
90 {
91    return container_of(dev, struct panvk_device, vk);
92 }
93 
94 static inline uint32_t
panvk_device_adjust_bo_flags(const struct panvk_device * device,uint32_t bo_flags)95 panvk_device_adjust_bo_flags(const struct panvk_device *device,
96                              uint32_t bo_flags)
97 {
98    struct panvk_instance *instance =
99       to_panvk_instance(device->vk.physical->instance);
100 
101    if (instance->debug_flags & (PANVK_DEBUG_DUMP | PANVK_DEBUG_TRACE))
102       bo_flags &= ~PAN_KMOD_BO_FLAG_NO_MMAP;
103 
104    return bo_flags;
105 }
106 
107 #if PAN_ARCH
108 VkResult
109 panvk_per_arch(create_device)(struct panvk_physical_device *physical_device,
110                               const VkDeviceCreateInfo *pCreateInfo,
111                               const VkAllocationCallbacks *pAllocator,
112                               VkDevice *pDevice);
113 
114 void panvk_per_arch(destroy_device)(struct panvk_device *device,
115                                     const VkAllocationCallbacks *pAllocator);
116 #endif
117 
118 #endif
119