Debian Codegraph @

src/asahi/vulkan/hk_device.h

raw
1 /*
2 * Copyright 2024 Valve Corporation
3 * Copyright 2024 Alyssa Rosenzweig
4 * Copyright 2022-2023 Collabora Ltd. and Red Hat Inc.
5 * SPDX-License-Identifier: MIT
6 */
7
8 #pragma once
9
10 #include "asahi/lib/agx_device.h"
11 #include "util/rwlock.h"
12 #include "util/simple_mtx.h"
13 #include "util/u_dynarray.h"
14 #include "agx_bg_eot.h"
15 #include "agx_pack.h"
16 #include "agx_scratch.h"
17 #include "decode.h"
18 #include "vk_cmd_queue.h"
19 #include "vk_dispatch_table.h"
20
21 #include "hk_private.h"
22
23 #include "hk_descriptor_table.h"
24 #include "hk_queue.h"
25 #include "vk_device.h"
26 #include "vk_meta.h"
27 #include "vk_queue.h"
28
29 struct hk_physical_device;
30 struct vk_pipeline_cache;
31
32 typedef void (*hk_internal_builder_t)(struct nir_builder *b, const void *key);
33
34 struct hk_internal_key {
35 hk_internal_builder_t builder;
36 size_t key_size;
37 uint8_t key[];
38 };
39
40 struct hk_internal_shaders {
41 simple_mtx_t lock;
42 struct hash_table *ht;
43 };
44
45 struct hk_rc_sampler {
46 struct agx_sampler_packed key;
47
48 /* Reference count for this hardware sampler, protected by the heap mutex */
49 uint16_t refcount;
50
51 /* Index of this hardware sampler in the hardware sampler heap */
52 uint16_t index;
53 };
54
55 struct hk_sampler_heap {
56 simple_mtx_t lock;
57
58 struct hk_descriptor_table table;
59
60 /* Map of agx_sampler_packed to hk_rc_sampler */
61 struct hash_table *ht;
62 };
63
64 struct hk_device {
65 struct vk_device vk;
66 struct agx_device dev;
67 struct agxdecode_ctx *decode_ctx;
68
69 struct hk_descriptor_table occlusion_queries;
70 struct hk_sampler_heap samplers;
71
72 struct vk_meta_device meta;
73 struct agx_bg_eot_cache bg_eot;
74
75 struct {
76 struct agx_bo *bo;
77 uint64_t heap;
78 } rodata;
79
80 struct hk_internal_shaders prolog_epilog;
81 struct hk_internal_shaders kernels;
82 struct hk_api_shader *null_fs;
83
84 /* Indirected for common secondary emulation */
85 struct vk_device_dispatch_table cmd_dispatch;
86
87 /* Heap used for GPU-side memory allocation for geometry/tessellation.
88 *
89 * Control streams accessing the heap must be serialized. This is not
90 * expected to be a legitimate problem. If it is, we can rework later.
91 */
92 struct agx_bo *heap;
93 util_once_flag heap_init_once;
94
95 struct {
96 struct agx_scratch vs, fs, cs;
97 simple_mtx_t lock;
98 } scratch;
99
100 uint32_t perftest;
101
102 struct {
103 struct u_rwlock lock;
104 struct util_dynarray list;
105 struct util_dynarray counts;
106 } external_bos;
107 };
108
109 VK_DEFINE_HANDLE_CASTS(hk_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE)
110
111 enum hk_perftest {
112 HK_PERF_NOTESS = BITFIELD_BIT(0),
113 HK_PERF_NOBORDER = BITFIELD_BIT(1),
114 HK_PERF_NOBARRIER = BITFIELD_BIT(2),
115 HK_PERF_BATCH = BITFIELD_BIT(3),
116 HK_PERF_NOROBUST = BITFIELD_BIT(4),
117 };
118
119 #define HK_PERF(dev, flag) unlikely((dev)->perftest &HK_PERF_##flag)
120
121 static inline struct hk_physical_device *
122 hk_device_physical(struct hk_device *dev)
123 {
124 return (struct hk_physical_device *)dev->vk.physical;
125 }
126
127 VkResult hk_device_init_meta(struct hk_device *dev);
128 void hk_device_finish_meta(struct hk_device *dev);
129
130 VkResult hk_sampler_heap_add(struct hk_device *dev,
131 struct agx_sampler_packed desc,
132 struct hk_rc_sampler **out);
133
134 void hk_sampler_heap_remove(struct hk_device *dev, struct hk_rc_sampler *rc);
135
136 static inline struct agx_scratch *
137 hk_device_scratch_locked(struct hk_device *dev, mesa_shader_stage stage)
138 {
139 simple_mtx_assert_locked(&dev->scratch.lock);
140
141 switch (stage) {
142 case MESA_SHADER_FRAGMENT:
143 return &dev->scratch.fs;
144 case MESA_SHADER_VERTEX:
145 return &dev->scratch.vs;
146 default:
147 return &dev->scratch.cs;
148 }
149 }
150
151 static inline void
152 hk_device_alloc_scratch(struct hk_device *dev, mesa_shader_stage stage,
153 unsigned size)
154 {
155 simple_mtx_lock(&dev->scratch.lock);
156 agx_scratch_alloc(hk_device_scratch_locked(dev, stage), size, 0);
157 simple_mtx_unlock(&dev->scratch.lock);
158 }