anv: Align UBO sizes to 32B
[mesa.git] / src / intel / vulkan / anv_private.h
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef ANV_PRIVATE_H
25 #define ANV_PRIVATE_H
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdbool.h>
30 #include <pthread.h>
31 #include <assert.h>
32 #include <stdint.h>
33 #include "drm-uapi/i915_drm.h"
34
35 #ifdef HAVE_VALGRIND
36 #include <valgrind.h>
37 #include <memcheck.h>
38 #define VG(x) x
39 #ifndef NDEBUG
40 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
41 #endif
42 #else
43 #define VG(x) ((void)0)
44 #endif
45
46 #include "common/gen_clflush.h"
47 #include "common/gen_decoder.h"
48 #include "common/gen_gem.h"
49 #include "common/gen_l3_config.h"
50 #include "dev/gen_device_info.h"
51 #include "blorp/blorp.h"
52 #include "compiler/brw_compiler.h"
53 #include "util/bitset.h"
54 #include "util/macros.h"
55 #include "util/hash_table.h"
56 #include "util/list.h"
57 #include "util/sparse_array.h"
58 #include "util/u_atomic.h"
59 #include "util/u_vector.h"
60 #include "util/u_math.h"
61 #include "util/vma.h"
62 #include "util/xmlconfig.h"
63 #include "vk_alloc.h"
64 #include "vk_debug_report.h"
65
66 /* Pre-declarations needed for WSI entrypoints */
67 struct wl_surface;
68 struct wl_display;
69 typedef struct xcb_connection_t xcb_connection_t;
70 typedef uint32_t xcb_visualid_t;
71 typedef uint32_t xcb_window_t;
72
73 struct anv_batch;
74 struct anv_buffer;
75 struct anv_buffer_view;
76 struct anv_image_view;
77 struct anv_instance;
78
79 struct gen_aux_map_context;
80 struct gen_perf_config;
81
82 #include <vulkan/vulkan.h>
83 #include <vulkan/vulkan_intel.h>
84 #include <vulkan/vk_icd.h>
85
86 #include "anv_android.h"
87 #include "anv_entrypoints.h"
88 #include "anv_extensions.h"
89 #include "isl/isl.h"
90
91 #include "dev/gen_debug.h"
92 #include "common/intel_log.h"
93 #include "wsi_common.h"
94
95 #define NSEC_PER_SEC 1000000000ull
96
97 /* anv Virtual Memory Layout
98 * =========================
99 *
100 * When the anv driver is determining the virtual graphics addresses of memory
101 * objects itself using the softpin mechanism, the following memory ranges
102 * will be used.
103 *
104 * Three special considerations to notice:
105 *
106 * (1) the dynamic state pool is located within the same 4 GiB as the low
107 * heap. This is to work around a VF cache issue described in a comment in
108 * anv_physical_device_init_heaps.
109 *
110 * (2) the binding table pool is located at lower addresses than the surface
111 * state pool, within a 4 GiB range. This allows surface state base addresses
112 * to cover both binding tables (16 bit offsets) and surface states (32 bit
113 * offsets).
114 *
115 * (3) the last 4 GiB of the address space is withheld from the high
116 * heap. Various hardware units will read past the end of an object for
117 * various reasons. This healthy margin prevents reads from wrapping around
118 * 48-bit addresses.
119 */
120 #define LOW_HEAP_MIN_ADDRESS 0x000000001000ULL /* 4 KiB */
121 #define LOW_HEAP_MAX_ADDRESS 0x0000bfffffffULL
122 #define DYNAMIC_STATE_POOL_MIN_ADDRESS 0x0000c0000000ULL /* 3 GiB */
123 #define DYNAMIC_STATE_POOL_MAX_ADDRESS 0x0000ffffffffULL
124 #define BINDING_TABLE_POOL_MIN_ADDRESS 0x000100000000ULL /* 4 GiB */
125 #define BINDING_TABLE_POOL_MAX_ADDRESS 0x00013fffffffULL
126 #define SURFACE_STATE_POOL_MIN_ADDRESS 0x000140000000ULL /* 5 GiB */
127 #define SURFACE_STATE_POOL_MAX_ADDRESS 0x00017fffffffULL
128 #define INSTRUCTION_STATE_POOL_MIN_ADDRESS 0x000180000000ULL /* 6 GiB */
129 #define INSTRUCTION_STATE_POOL_MAX_ADDRESS 0x0001bfffffffULL
130 #define CLIENT_VISIBLE_HEAP_MIN_ADDRESS 0x0001c0000000ULL /* 7 GiB */
131 #define CLIENT_VISIBLE_HEAP_MAX_ADDRESS 0x0002bfffffffULL
132 #define HIGH_HEAP_MIN_ADDRESS 0x0002c0000000ULL /* 11 GiB */
133
134 #define LOW_HEAP_SIZE \
135 (LOW_HEAP_MAX_ADDRESS - LOW_HEAP_MIN_ADDRESS + 1)
136 #define DYNAMIC_STATE_POOL_SIZE \
137 (DYNAMIC_STATE_POOL_MAX_ADDRESS - DYNAMIC_STATE_POOL_MIN_ADDRESS + 1)
138 #define BINDING_TABLE_POOL_SIZE \
139 (BINDING_TABLE_POOL_MAX_ADDRESS - BINDING_TABLE_POOL_MIN_ADDRESS + 1)
140 #define SURFACE_STATE_POOL_SIZE \
141 (SURFACE_STATE_POOL_MAX_ADDRESS - SURFACE_STATE_POOL_MIN_ADDRESS + 1)
142 #define INSTRUCTION_STATE_POOL_SIZE \
143 (INSTRUCTION_STATE_POOL_MAX_ADDRESS - INSTRUCTION_STATE_POOL_MIN_ADDRESS + 1)
144 #define CLIENT_VISIBLE_HEAP_SIZE \
145 (CLIENT_VISIBLE_HEAP_MAX_ADDRESS - CLIENT_VISIBLE_HEAP_MIN_ADDRESS + 1)
146
147 /* Allowing different clear colors requires us to perform a depth resolve at
148 * the end of certain render passes. This is because while slow clears store
149 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
150 * See the PRMs for examples describing when additional resolves would be
151 * necessary. To enable fast clears without requiring extra resolves, we set
152 * the clear value to a globally-defined one. We could allow different values
153 * if the user doesn't expect coherent data during or after a render passes
154 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
155 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
156 * 1.0f seems to be the only value used. The only application that doesn't set
157 * this value does so through the usage of an seemingly uninitialized clear
158 * value.
159 */
160 #define ANV_HZ_FC_VAL 1.0f
161
162 #define MAX_VBS 28
163 #define MAX_XFB_BUFFERS 4
164 #define MAX_XFB_STREAMS 4
165 #define MAX_SETS 8
166 #define MAX_RTS 8
167 #define MAX_VIEWPORTS 16
168 #define MAX_SCISSORS 16
169 #define MAX_PUSH_CONSTANTS_SIZE 128
170 #define MAX_DYNAMIC_BUFFERS 16
171 #define MAX_IMAGES 64
172 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
173 #define MAX_INLINE_UNIFORM_BLOCK_SIZE 4096
174 #define MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS 32
175 #define ANV_UBO_BOUNDS_CHECK_ALIGNMENT 32
176 #define ANV_SSBO_BOUNDS_CHECK_ALIGNMENT 4
177
178 /* From the Skylake PRM Vol. 7 "Binding Table Surface State Model":
179 *
180 * "The surface state model is used when a Binding Table Index (specified
181 * in the message descriptor) of less than 240 is specified. In this model,
182 * the Binding Table Index is used to index into the binding table, and the
183 * binding table entry contains a pointer to the SURFACE_STATE."
184 *
185 * Binding table values above 240 are used for various things in the hardware
186 * such as stateless, stateless with incoherent cache, SLM, and bindless.
187 */
188 #define MAX_BINDING_TABLE_SIZE 240
189
190 /* The kernel relocation API has a limitation of a 32-bit delta value
191 * applied to the address before it is written which, in spite of it being
192 * unsigned, is treated as signed . Because of the way that this maps to
193 * the Vulkan API, we cannot handle an offset into a buffer that does not
194 * fit into a signed 32 bits. The only mechanism we have for dealing with
195 * this at the moment is to limit all VkDeviceMemory objects to a maximum
196 * of 2GB each. The Vulkan spec allows us to do this:
197 *
198 * "Some platforms may have a limit on the maximum size of a single
199 * allocation. For example, certain systems may fail to create
200 * allocations with a size greater than or equal to 4GB. Such a limit is
201 * implementation-dependent, and if such a failure occurs then the error
202 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
203 *
204 * We don't use vk_error here because it's not an error so much as an
205 * indication to the application that the allocation is too large.
206 */
207 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
208
209 #define ANV_SVGS_VB_INDEX MAX_VBS
210 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
211
212 /* We reserve this MI ALU register for the purpose of handling predication.
213 * Other code which uses the MI ALU should leave it alone.
214 */
215 #define ANV_PREDICATE_RESULT_REG 0x2678 /* MI_ALU_REG15 */
216
217 /* For gen12 we set the streamout buffers using 4 separate commands
218 * (3DSTATE_SO_BUFFER_INDEX_*) instead of 3DSTATE_SO_BUFFER. However the layout
219 * of the 3DSTATE_SO_BUFFER_INDEX_* commands is identical to that of
220 * 3DSTATE_SO_BUFFER apart from the SOBufferIndex field, so for now we use the
221 * 3DSTATE_SO_BUFFER command, but change the 3DCommandSubOpcode.
222 * SO_BUFFER_INDEX_0_CMD is actually the 3DCommandSubOpcode for
223 * 3DSTATE_SO_BUFFER_INDEX_0.
224 */
225 #define SO_BUFFER_INDEX_0_CMD 0x60
226 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
227
228 static inline uint32_t
229 align_down_npot_u32(uint32_t v, uint32_t a)
230 {
231 return v - (v % a);
232 }
233
234 static inline uint32_t
235 align_u32(uint32_t v, uint32_t a)
236 {
237 assert(a != 0 && a == (a & -a));
238 return (v + a - 1) & ~(a - 1);
239 }
240
241 static inline uint64_t
242 align_down_u64(uint64_t v, uint64_t a)
243 {
244 assert(a != 0 && a == (a & -a));
245 return v & ~(a - 1);
246 }
247
248 static inline uint64_t
249 align_u64(uint64_t v, uint64_t a)
250 {
251 return align_down_u64(v + a - 1, a);
252 }
253
254 static inline int32_t
255 align_i32(int32_t v, int32_t a)
256 {
257 assert(a != 0 && a == (a & -a));
258 return (v + a - 1) & ~(a - 1);
259 }
260
261 /** Alignment must be a power of 2. */
262 static inline bool
263 anv_is_aligned(uintmax_t n, uintmax_t a)
264 {
265 assert(a == (a & -a));
266 return (n & (a - 1)) == 0;
267 }
268
269 static inline uint32_t
270 anv_minify(uint32_t n, uint32_t levels)
271 {
272 if (unlikely(n == 0))
273 return 0;
274 else
275 return MAX2(n >> levels, 1);
276 }
277
278 static inline float
279 anv_clamp_f(float f, float min, float max)
280 {
281 assert(min < max);
282
283 if (f > max)
284 return max;
285 else if (f < min)
286 return min;
287 else
288 return f;
289 }
290
291 static inline bool
292 anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
293 {
294 if (*inout_mask & clear_mask) {
295 *inout_mask &= ~clear_mask;
296 return true;
297 } else {
298 return false;
299 }
300 }
301
302 static inline union isl_color_value
303 vk_to_isl_color(VkClearColorValue color)
304 {
305 return (union isl_color_value) {
306 .u32 = {
307 color.uint32[0],
308 color.uint32[1],
309 color.uint32[2],
310 color.uint32[3],
311 },
312 };
313 }
314
315 static inline void *anv_unpack_ptr(uintptr_t ptr, int bits, int *flags)
316 {
317 uintptr_t mask = (1ull << bits) - 1;
318 *flags = ptr & mask;
319 return (void *) (ptr & ~mask);
320 }
321
322 static inline uintptr_t anv_pack_ptr(void *ptr, int bits, int flags)
323 {
324 uintptr_t value = (uintptr_t) ptr;
325 uintptr_t mask = (1ull << bits) - 1;
326 return value | (mask & flags);
327 }
328
329 #define for_each_bit(b, dword) \
330 for (uint32_t __dword = (dword); \
331 (b) = __builtin_ffs(__dword) - 1, __dword; \
332 __dword &= ~(1 << (b)))
333
334 #define typed_memcpy(dest, src, count) ({ \
335 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
336 memcpy((dest), (src), (count) * sizeof(*(src))); \
337 })
338
339 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
340 * to be added here in order to utilize mapping in debug/error/perf macros.
341 */
342 #define REPORT_OBJECT_TYPE(o) \
343 __builtin_choose_expr ( \
344 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
345 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
346 __builtin_choose_expr ( \
347 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
348 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
349 __builtin_choose_expr ( \
350 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
351 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
352 __builtin_choose_expr ( \
353 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
354 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
355 __builtin_choose_expr ( \
356 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
357 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
358 __builtin_choose_expr ( \
359 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
360 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
361 __builtin_choose_expr ( \
362 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
363 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
364 __builtin_choose_expr ( \
365 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
366 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
367 __builtin_choose_expr ( \
368 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
369 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
370 __builtin_choose_expr ( \
371 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
372 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
373 __builtin_choose_expr ( \
374 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
375 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
376 __builtin_choose_expr ( \
377 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
378 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
379 __builtin_choose_expr ( \
380 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
381 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
382 __builtin_choose_expr ( \
383 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
384 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
385 __builtin_choose_expr ( \
386 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
387 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
388 __builtin_choose_expr ( \
389 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
390 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
391 __builtin_choose_expr ( \
392 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
393 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
394 __builtin_choose_expr ( \
395 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
396 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
397 __builtin_choose_expr ( \
398 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
399 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
400 __builtin_choose_expr ( \
401 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
402 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
403 __builtin_choose_expr ( \
404 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
405 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
406 __builtin_choose_expr ( \
407 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
408 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
409 __builtin_choose_expr ( \
410 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
411 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
412 __builtin_choose_expr ( \
413 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
414 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
415 __builtin_choose_expr ( \
416 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
417 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
418 __builtin_choose_expr ( \
419 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
420 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
421 __builtin_choose_expr ( \
422 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
423 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
424 __builtin_choose_expr ( \
425 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
426 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
427 __builtin_choose_expr ( \
428 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
429 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
430 __builtin_choose_expr ( \
431 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
432 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
433 __builtin_choose_expr ( \
434 __builtin_types_compatible_p (__typeof (o), void*), \
435 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
436 /* The void expression results in a compile-time error \
437 when assigning the result to something. */ \
438 (void)0)))))))))))))))))))))))))))))))
439
440 /* Whenever we generate an error, pass it through this function. Useful for
441 * debugging, where we can break on it. Only call at error site, not when
442 * propagating errors. Might be useful to plug in a stack trace here.
443 */
444
445 VkResult __vk_errorv(struct anv_instance *instance, const void *object,
446 VkDebugReportObjectTypeEXT type, VkResult error,
447 const char *file, int line, const char *format,
448 va_list args);
449
450 VkResult __vk_errorf(struct anv_instance *instance, const void *object,
451 VkDebugReportObjectTypeEXT type, VkResult error,
452 const char *file, int line, const char *format, ...)
453 anv_printflike(7, 8);
454
455 #ifdef DEBUG
456 #define vk_error(error) __vk_errorf(NULL, NULL,\
457 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
458 error, __FILE__, __LINE__, NULL)
459 #define vk_errorfi(instance, obj, error, format, ...)\
460 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
461 __FILE__, __LINE__, format, ## __VA_ARGS__)
462 #define vk_errorf(device, obj, error, format, ...)\
463 vk_errorfi(anv_device_instance_or_null(device),\
464 obj, error, format, ## __VA_ARGS__)
465 #else
466 #define vk_error(error) error
467 #define vk_errorfi(instance, obj, error, format, ...) error
468 #define vk_errorf(device, obj, error, format, ...) error
469 #endif
470
471 /**
472 * Warn on ignored extension structs.
473 *
474 * The Vulkan spec requires us to ignore unsupported or unknown structs in
475 * a pNext chain. In debug mode, emitting warnings for ignored structs may
476 * help us discover structs that we should not have ignored.
477 *
478 *
479 * From the Vulkan 1.0.38 spec:
480 *
481 * Any component of the implementation (the loader, any enabled layers,
482 * and drivers) must skip over, without processing (other than reading the
483 * sType and pNext members) any chained structures with sType values not
484 * defined by extensions supported by that component.
485 */
486 #define anv_debug_ignored_stype(sType) \
487 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
488
489 void __anv_perf_warn(struct anv_device *device, const void *object,
490 VkDebugReportObjectTypeEXT type, const char *file,
491 int line, const char *format, ...)
492 anv_printflike(6, 7);
493 void anv_loge(const char *format, ...) anv_printflike(1, 2);
494 void anv_loge_v(const char *format, va_list va);
495
496 /**
497 * Print a FINISHME message, including its source location.
498 */
499 #define anv_finishme(format, ...) \
500 do { \
501 static bool reported = false; \
502 if (!reported) { \
503 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
504 ##__VA_ARGS__); \
505 reported = true; \
506 } \
507 } while (0)
508
509 /**
510 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
511 */
512 #define anv_perf_warn(instance, obj, format, ...) \
513 do { \
514 static bool reported = false; \
515 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
516 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
517 format, ##__VA_ARGS__); \
518 reported = true; \
519 } \
520 } while (0)
521
522 /* A non-fatal assert. Useful for debugging. */
523 #ifdef DEBUG
524 #define anv_assert(x) ({ \
525 if (unlikely(!(x))) \
526 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
527 })
528 #else
529 #define anv_assert(x)
530 #endif
531
532 /* A multi-pointer allocator
533 *
534 * When copying data structures from the user (such as a render pass), it's
535 * common to need to allocate data for a bunch of different things. Instead
536 * of doing several allocations and having to handle all of the error checking
537 * that entails, it can be easier to do a single allocation. This struct
538 * helps facilitate that. The intended usage looks like this:
539 *
540 * ANV_MULTIALLOC(ma)
541 * anv_multialloc_add(&ma, &main_ptr, 1);
542 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
543 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
544 *
545 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
546 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
547 */
548 struct anv_multialloc {
549 size_t size;
550 size_t align;
551
552 uint32_t ptr_count;
553 void **ptrs[8];
554 };
555
556 #define ANV_MULTIALLOC_INIT \
557 ((struct anv_multialloc) { 0, })
558
559 #define ANV_MULTIALLOC(_name) \
560 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
561
562 __attribute__((always_inline))
563 static inline void
564 _anv_multialloc_add(struct anv_multialloc *ma,
565 void **ptr, size_t size, size_t align)
566 {
567 size_t offset = align_u64(ma->size, align);
568 ma->size = offset + size;
569 ma->align = MAX2(ma->align, align);
570
571 /* Store the offset in the pointer. */
572 *ptr = (void *)(uintptr_t)offset;
573
574 assert(ma->ptr_count < ARRAY_SIZE(ma->ptrs));
575 ma->ptrs[ma->ptr_count++] = ptr;
576 }
577
578 #define anv_multialloc_add_size(_ma, _ptr, _size) \
579 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
580
581 #define anv_multialloc_add(_ma, _ptr, _count) \
582 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
583
584 __attribute__((always_inline))
585 static inline void *
586 anv_multialloc_alloc(struct anv_multialloc *ma,
587 const VkAllocationCallbacks *alloc,
588 VkSystemAllocationScope scope)
589 {
590 void *ptr = vk_alloc(alloc, ma->size, ma->align, scope);
591 if (!ptr)
592 return NULL;
593
594 /* Fill out each of the pointers with their final value.
595 *
596 * for (uint32_t i = 0; i < ma->ptr_count; i++)
597 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
598 *
599 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
600 * constant, GCC is incapable of figuring this out and unrolling the loop
601 * so we have to give it a little help.
602 */
603 STATIC_ASSERT(ARRAY_SIZE(ma->ptrs) == 8);
604 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
605 if ((_i) < ma->ptr_count) \
606 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
607 _ANV_MULTIALLOC_UPDATE_POINTER(0);
608 _ANV_MULTIALLOC_UPDATE_POINTER(1);
609 _ANV_MULTIALLOC_UPDATE_POINTER(2);
610 _ANV_MULTIALLOC_UPDATE_POINTER(3);
611 _ANV_MULTIALLOC_UPDATE_POINTER(4);
612 _ANV_MULTIALLOC_UPDATE_POINTER(5);
613 _ANV_MULTIALLOC_UPDATE_POINTER(6);
614 _ANV_MULTIALLOC_UPDATE_POINTER(7);
615 #undef _ANV_MULTIALLOC_UPDATE_POINTER
616
617 return ptr;
618 }
619
620 __attribute__((always_inline))
621 static inline void *
622 anv_multialloc_alloc2(struct anv_multialloc *ma,
623 const VkAllocationCallbacks *parent_alloc,
624 const VkAllocationCallbacks *alloc,
625 VkSystemAllocationScope scope)
626 {
627 return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
628 }
629
630 struct anv_bo {
631 uint32_t gem_handle;
632
633 uint32_t refcount;
634
635 /* Index into the current validation list. This is used by the
636 * validation list building alrogithm to track which buffers are already
637 * in the validation list so that we can ensure uniqueness.
638 */
639 uint32_t index;
640
641 /* Index for use with util_sparse_array_free_list */
642 uint32_t free_index;
643
644 /* Last known offset. This value is provided by the kernel when we
645 * execbuf and is used as the presumed offset for the next bunch of
646 * relocations.
647 */
648 uint64_t offset;
649
650 /** Size of the buffer not including implicit aux */
651 uint64_t size;
652
653 /* Map for internally mapped BOs.
654 *
655 * If ANV_BO_WRAPPER is set in flags, map points to the wrapped BO.
656 */
657 void *map;
658
659 /** Size of the implicit CCS range at the end of the buffer
660 *
661 * On Gen12, CCS data is always a direct 1/256 scale-down. A single 64K
662 * page of main surface data maps to a 256B chunk of CCS data and that
663 * mapping is provided on TGL-LP by the AUX table which maps virtual memory
664 * addresses in the main surface to virtual memory addresses for CCS data.
665 *
666 * Because we can't change these maps around easily and because Vulkan
667 * allows two VkImages to be bound to overlapping memory regions (as long
668 * as the app is careful), it's not feasible to make this mapping part of
669 * the image. (On Gen11 and earlier, the mapping was provided via
670 * RENDER_SURFACE_STATE so each image had its own main -> CCS mapping.)
671 * Instead, we attach the CCS data directly to the buffer object and setup
672 * the AUX table mapping at BO creation time.
673 *
674 * This field is for internal tracking use by the BO allocator only and
675 * should not be touched by other parts of the code. If something wants to
676 * know if a BO has implicit CCS data, it should instead look at the
677 * has_implicit_ccs boolean below.
678 *
679 * This data is not included in maps of this buffer.
680 */
681 uint32_t _ccs_size;
682
683 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
684 uint32_t flags;
685
686 /** True if this BO may be shared with other processes */
687 bool is_external:1;
688
689 /** True if this BO is a wrapper
690 *
691 * When set to true, none of the fields in this BO are meaningful except
692 * for anv_bo::is_wrapper and anv_bo::map which points to the actual BO.
693 * See also anv_bo_unwrap(). Wrapper BOs are not allowed when use_softpin
694 * is set in the physical device.
695 */
696 bool is_wrapper:1;
697
698 /** See also ANV_BO_ALLOC_FIXED_ADDRESS */
699 bool has_fixed_address:1;
700
701 /** True if this BO wraps a host pointer */
702 bool from_host_ptr:1;
703
704 /** See also ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS */
705 bool has_client_visible_address:1;
706
707 /** True if this BO has implicit CCS data attached to it */
708 bool has_implicit_ccs:1;
709 };
710
711 static inline struct anv_bo *
712 anv_bo_ref(struct anv_bo *bo)
713 {
714 p_atomic_inc(&bo->refcount);
715 return bo;
716 }
717
718 static inline struct anv_bo *
719 anv_bo_unwrap(struct anv_bo *bo)
720 {
721 while (bo->is_wrapper)
722 bo = bo->map;
723 return bo;
724 }
725
726 /* Represents a lock-free linked list of "free" things. This is used by
727 * both the block pool and the state pools. Unfortunately, in order to
728 * solve the ABA problem, we can't use a single uint32_t head.
729 */
730 union anv_free_list {
731 struct {
732 uint32_t offset;
733
734 /* A simple count that is incremented every time the head changes. */
735 uint32_t count;
736 };
737 /* Make sure it's aligned to 64 bits. This will make atomic operations
738 * faster on 32 bit platforms.
739 */
740 uint64_t u64 __attribute__ ((aligned (8)));
741 };
742
743 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { UINT32_MAX, 0 } })
744
745 struct anv_block_state {
746 union {
747 struct {
748 uint32_t next;
749 uint32_t end;
750 };
751 /* Make sure it's aligned to 64 bits. This will make atomic operations
752 * faster on 32 bit platforms.
753 */
754 uint64_t u64 __attribute__ ((aligned (8)));
755 };
756 };
757
758 #define anv_block_pool_foreach_bo(bo, pool) \
759 for (struct anv_bo **_pp_bo = (pool)->bos, *bo; \
760 _pp_bo != &(pool)->bos[(pool)->nbos] && (bo = *_pp_bo, true); \
761 _pp_bo++)
762
763 #define ANV_MAX_BLOCK_POOL_BOS 20
764
765 struct anv_block_pool {
766 struct anv_device *device;
767 bool use_softpin;
768
769 /* Wrapper BO for use in relocation lists. This BO is simply a wrapper
770 * around the actual BO so that we grow the pool after the wrapper BO has
771 * been put in a relocation list. This is only used in the non-softpin
772 * case.
773 */
774 struct anv_bo wrapper_bo;
775
776 struct anv_bo *bos[ANV_MAX_BLOCK_POOL_BOS];
777 struct anv_bo *bo;
778 uint32_t nbos;
779
780 uint64_t size;
781
782 /* The address where the start of the pool is pinned. The various bos that
783 * are created as the pool grows will have addresses in the range
784 * [start_address, start_address + BLOCK_POOL_MEMFD_SIZE).
785 */
786 uint64_t start_address;
787
788 /* The offset from the start of the bo to the "center" of the block
789 * pool. Pointers to allocated blocks are given by
790 * bo.map + center_bo_offset + offsets.
791 */
792 uint32_t center_bo_offset;
793
794 /* Current memory map of the block pool. This pointer may or may not
795 * point to the actual beginning of the block pool memory. If
796 * anv_block_pool_alloc_back has ever been called, then this pointer
797 * will point to the "center" position of the buffer and all offsets
798 * (negative or positive) given out by the block pool alloc functions
799 * will be valid relative to this pointer.
800 *
801 * In particular, map == bo.map + center_offset
802 *
803 * DO NOT access this pointer directly. Use anv_block_pool_map() instead,
804 * since it will handle the softpin case as well, where this points to NULL.
805 */
806 void *map;
807 int fd;
808
809 /**
810 * Array of mmaps and gem handles owned by the block pool, reclaimed when
811 * the block pool is destroyed.
812 */
813 struct u_vector mmap_cleanups;
814
815 struct anv_block_state state;
816
817 struct anv_block_state back_state;
818 };
819
820 /* Block pools are backed by a fixed-size 1GB memfd */
821 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
822
823 /* The center of the block pool is also the middle of the memfd. This may
824 * change in the future if we decide differently for some reason.
825 */
826 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
827
828 static inline uint32_t
829 anv_block_pool_size(struct anv_block_pool *pool)
830 {
831 return pool->state.end + pool->back_state.end;
832 }
833
834 struct anv_state {
835 int32_t offset;
836 uint32_t alloc_size;
837 void *map;
838 uint32_t idx;
839 };
840
841 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
842
843 struct anv_fixed_size_state_pool {
844 union anv_free_list free_list;
845 struct anv_block_state block;
846 };
847
848 #define ANV_MIN_STATE_SIZE_LOG2 6
849 #define ANV_MAX_STATE_SIZE_LOG2 21
850
851 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
852
853 struct anv_free_entry {
854 uint32_t next;
855 struct anv_state state;
856 };
857
858 struct anv_state_table {
859 struct anv_device *device;
860 int fd;
861 struct anv_free_entry *map;
862 uint32_t size;
863 struct anv_block_state state;
864 struct u_vector cleanups;
865 };
866
867 struct anv_state_pool {
868 struct anv_block_pool block_pool;
869
870 struct anv_state_table table;
871
872 /* The size of blocks which will be allocated from the block pool */
873 uint32_t block_size;
874
875 /** Free list for "back" allocations */
876 union anv_free_list back_alloc_free_list;
877
878 struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
879 };
880
881 struct anv_state_stream_block;
882
883 struct anv_state_stream {
884 struct anv_state_pool *state_pool;
885
886 /* The size of blocks to allocate from the state pool */
887 uint32_t block_size;
888
889 /* Current block we're allocating from */
890 struct anv_state block;
891
892 /* Offset into the current block at which to allocate the next state */
893 uint32_t next;
894
895 /* List of all blocks allocated from this pool */
896 struct anv_state_stream_block *block_list;
897 };
898
899 /* The block_pool functions exported for testing only. The block pool should
900 * only be used via a state pool (see below).
901 */
902 VkResult anv_block_pool_init(struct anv_block_pool *pool,
903 struct anv_device *device,
904 uint64_t start_address,
905 uint32_t initial_size);
906 void anv_block_pool_finish(struct anv_block_pool *pool);
907 int32_t anv_block_pool_alloc(struct anv_block_pool *pool,
908 uint32_t block_size, uint32_t *padding);
909 int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool,
910 uint32_t block_size);
911 void* anv_block_pool_map(struct anv_block_pool *pool, int32_t offset, uint32_t
912 size);
913
914 VkResult anv_state_pool_init(struct anv_state_pool *pool,
915 struct anv_device *device,
916 uint64_t start_address,
917 uint32_t block_size);
918 void anv_state_pool_finish(struct anv_state_pool *pool);
919 struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool,
920 uint32_t state_size, uint32_t alignment);
921 struct anv_state anv_state_pool_alloc_back(struct anv_state_pool *pool);
922 void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state);
923 void anv_state_stream_init(struct anv_state_stream *stream,
924 struct anv_state_pool *state_pool,
925 uint32_t block_size);
926 void anv_state_stream_finish(struct anv_state_stream *stream);
927 struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
928 uint32_t size, uint32_t alignment);
929
930 VkResult anv_state_table_init(struct anv_state_table *table,
931 struct anv_device *device,
932 uint32_t initial_entries);
933 void anv_state_table_finish(struct anv_state_table *table);
934 VkResult anv_state_table_add(struct anv_state_table *table, uint32_t *idx,
935 uint32_t count);
936 void anv_free_list_push(union anv_free_list *list,
937 struct anv_state_table *table,
938 uint32_t idx, uint32_t count);
939 struct anv_state* anv_free_list_pop(union anv_free_list *list,
940 struct anv_state_table *table);
941
942
943 static inline struct anv_state *
944 anv_state_table_get(struct anv_state_table *table, uint32_t idx)
945 {
946 return &table->map[idx].state;
947 }
948 /**
949 * Implements a pool of re-usable BOs. The interface is identical to that
950 * of block_pool except that each block is its own BO.
951 */
952 struct anv_bo_pool {
953 struct anv_device *device;
954
955 struct util_sparse_array_free_list free_list[16];
956 };
957
958 void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device);
959 void anv_bo_pool_finish(struct anv_bo_pool *pool);
960 VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, uint32_t size,
961 struct anv_bo **bo_out);
962 void anv_bo_pool_free(struct anv_bo_pool *pool, struct anv_bo *bo);
963
964 struct anv_scratch_pool {
965 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
966 struct anv_bo *bos[16][MESA_SHADER_STAGES];
967 };
968
969 void anv_scratch_pool_init(struct anv_device *device,
970 struct anv_scratch_pool *pool);
971 void anv_scratch_pool_finish(struct anv_device *device,
972 struct anv_scratch_pool *pool);
973 struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
974 struct anv_scratch_pool *pool,
975 gl_shader_stage stage,
976 unsigned per_thread_scratch);
977
978 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
979 struct anv_bo_cache {
980 struct util_sparse_array bo_map;
981 pthread_mutex_t mutex;
982 };
983
984 VkResult anv_bo_cache_init(struct anv_bo_cache *cache);
985 void anv_bo_cache_finish(struct anv_bo_cache *cache);
986
987 struct anv_memory_type {
988 /* Standard bits passed on to the client */
989 VkMemoryPropertyFlags propertyFlags;
990 uint32_t heapIndex;
991 };
992
993 struct anv_memory_heap {
994 /* Standard bits passed on to the client */
995 VkDeviceSize size;
996 VkMemoryHeapFlags flags;
997
998 /* Driver-internal book-keeping */
999 VkDeviceSize used;
1000 };
1001
1002 struct anv_physical_device {
1003 VK_LOADER_DATA _loader_data;
1004
1005 /* Link in anv_instance::physical_devices */
1006 struct list_head link;
1007
1008 struct anv_instance * instance;
1009 bool no_hw;
1010 char path[20];
1011 const char * name;
1012 struct {
1013 uint16_t domain;
1014 uint8_t bus;
1015 uint8_t device;
1016 uint8_t function;
1017 } pci_info;
1018 struct gen_device_info info;
1019 /** Amount of "GPU memory" we want to advertise
1020 *
1021 * Clearly, this value is bogus since Intel is a UMA architecture. On
1022 * gen7 platforms, we are limited by GTT size unless we want to implement
1023 * fine-grained tracking and GTT splitting. On Broadwell and above we are
1024 * practically unlimited. However, we will never report more than 3/4 of
1025 * the total system ram to try and avoid running out of RAM.
1026 */
1027 bool supports_48bit_addresses;
1028 struct brw_compiler * compiler;
1029 struct isl_device isl_dev;
1030 struct gen_perf_config * perf;
1031 int cmd_parser_version;
1032 bool has_softpin;
1033 bool has_exec_async;
1034 bool has_exec_capture;
1035 bool has_exec_fence;
1036 bool has_syncobj;
1037 bool has_syncobj_wait;
1038 bool has_context_priority;
1039 bool has_context_isolation;
1040 bool has_mem_available;
1041 uint64_t gtt_size;
1042
1043 bool use_softpin;
1044 bool always_use_bindless;
1045
1046 /** True if we can access buffers using A64 messages */
1047 bool has_a64_buffer_access;
1048 /** True if we can use bindless access for images */
1049 bool has_bindless_images;
1050 /** True if we can use bindless access for samplers */
1051 bool has_bindless_samplers;
1052
1053 /** True if this device has implicit AUX
1054 *
1055 * If true, CCS is handled as an implicit attachment to the BO rather than
1056 * as an explicitly bound surface.
1057 */
1058 bool has_implicit_ccs;
1059
1060 bool always_flush_cache;
1061
1062 struct anv_device_extension_table supported_extensions;
1063
1064 uint32_t eu_total;
1065 uint32_t subslice_total;
1066
1067 struct {
1068 uint32_t type_count;
1069 struct anv_memory_type types[VK_MAX_MEMORY_TYPES];
1070 uint32_t heap_count;
1071 struct anv_memory_heap heaps[VK_MAX_MEMORY_HEAPS];
1072 } memory;
1073
1074 uint8_t driver_build_sha1[20];
1075 uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
1076 uint8_t driver_uuid[VK_UUID_SIZE];
1077 uint8_t device_uuid[VK_UUID_SIZE];
1078
1079 struct disk_cache * disk_cache;
1080
1081 struct wsi_device wsi_device;
1082 int local_fd;
1083 int master_fd;
1084 };
1085
1086 struct anv_app_info {
1087 const char* app_name;
1088 uint32_t app_version;
1089 const char* engine_name;
1090 uint32_t engine_version;
1091 uint32_t api_version;
1092 };
1093
1094 struct anv_instance {
1095 VK_LOADER_DATA _loader_data;
1096
1097 VkAllocationCallbacks alloc;
1098
1099 struct anv_app_info app_info;
1100
1101 struct anv_instance_extension_table enabled_extensions;
1102 struct anv_instance_dispatch_table dispatch;
1103 struct anv_physical_device_dispatch_table physical_device_dispatch;
1104 struct anv_device_dispatch_table device_dispatch;
1105
1106 bool physical_devices_enumerated;
1107 struct list_head physical_devices;
1108
1109 bool pipeline_cache_enabled;
1110
1111 struct vk_debug_report_instance debug_report_callbacks;
1112
1113 struct driOptionCache dri_options;
1114 struct driOptionCache available_dri_options;
1115 };
1116
1117 VkResult anv_init_wsi(struct anv_physical_device *physical_device);
1118 void anv_finish_wsi(struct anv_physical_device *physical_device);
1119
1120 uint32_t anv_physical_device_api_version(struct anv_physical_device *dev);
1121 bool anv_physical_device_extension_supported(struct anv_physical_device *dev,
1122 const char *name);
1123
1124 struct anv_queue_submit {
1125 struct anv_cmd_buffer * cmd_buffer;
1126
1127 uint32_t fence_count;
1128 uint32_t fence_array_length;
1129 struct drm_i915_gem_exec_fence * fences;
1130
1131 uint32_t temporary_semaphore_count;
1132 uint32_t temporary_semaphore_array_length;
1133 struct anv_semaphore_impl * temporary_semaphores;
1134
1135 /* Semaphores to be signaled with a SYNC_FD. */
1136 struct anv_semaphore ** sync_fd_semaphores;
1137 uint32_t sync_fd_semaphore_count;
1138 uint32_t sync_fd_semaphore_array_length;
1139
1140 /* Allocated only with non shareable timelines. */
1141 struct anv_timeline ** wait_timelines;
1142 uint32_t wait_timeline_count;
1143 uint32_t wait_timeline_array_length;
1144 uint64_t * wait_timeline_values;
1145
1146 struct anv_timeline ** signal_timelines;
1147 uint32_t signal_timeline_count;
1148 uint32_t signal_timeline_array_length;
1149 uint64_t * signal_timeline_values;
1150
1151 int in_fence;
1152 bool need_out_fence;
1153 int out_fence;
1154
1155 uint32_t fence_bo_count;
1156 uint32_t fence_bo_array_length;
1157 /* An array of struct anv_bo pointers with lower bit used as a flag to
1158 * signal we will wait on that BO (see anv_(un)pack_ptr).
1159 */
1160 uintptr_t * fence_bos;
1161
1162 const VkAllocationCallbacks * alloc;
1163 VkSystemAllocationScope alloc_scope;
1164
1165 struct anv_bo * simple_bo;
1166 uint32_t simple_bo_size;
1167
1168 struct list_head link;
1169 };
1170
1171 struct anv_queue {
1172 VK_LOADER_DATA _loader_data;
1173
1174 struct anv_device * device;
1175
1176 /*
1177 * A list of struct anv_queue_submit to be submitted to i915.
1178 */
1179 struct list_head queued_submits;
1180
1181 VkDeviceQueueCreateFlags flags;
1182 };
1183
1184 struct anv_pipeline_cache {
1185 struct anv_device * device;
1186 pthread_mutex_t mutex;
1187
1188 struct hash_table * nir_cache;
1189
1190 struct hash_table * cache;
1191 };
1192
1193 struct nir_xfb_info;
1194 struct anv_pipeline_bind_map;
1195
1196 void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
1197 struct anv_device *device,
1198 bool cache_enabled);
1199 void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
1200
1201 struct anv_shader_bin *
1202 anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
1203 const void *key, uint32_t key_size);
1204 struct anv_shader_bin *
1205 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
1206 const void *key_data, uint32_t key_size,
1207 const void *kernel_data, uint32_t kernel_size,
1208 const void *constant_data,
1209 uint32_t constant_data_size,
1210 const struct brw_stage_prog_data *prog_data,
1211 uint32_t prog_data_size,
1212 const struct brw_compile_stats *stats,
1213 uint32_t num_stats,
1214 const struct nir_xfb_info *xfb_info,
1215 const struct anv_pipeline_bind_map *bind_map);
1216
1217 struct anv_shader_bin *
1218 anv_device_search_for_kernel(struct anv_device *device,
1219 struct anv_pipeline_cache *cache,
1220 const void *key_data, uint32_t key_size,
1221 bool *user_cache_bit);
1222
1223 struct anv_shader_bin *
1224 anv_device_upload_kernel(struct anv_device *device,
1225 struct anv_pipeline_cache *cache,
1226 const void *key_data, uint32_t key_size,
1227 const void *kernel_data, uint32_t kernel_size,
1228 const void *constant_data,
1229 uint32_t constant_data_size,
1230 const struct brw_stage_prog_data *prog_data,
1231 uint32_t prog_data_size,
1232 const struct brw_compile_stats *stats,
1233 uint32_t num_stats,
1234 const struct nir_xfb_info *xfb_info,
1235 const struct anv_pipeline_bind_map *bind_map);
1236
1237 struct nir_shader;
1238 struct nir_shader_compiler_options;
1239
1240 struct nir_shader *
1241 anv_device_search_for_nir(struct anv_device *device,
1242 struct anv_pipeline_cache *cache,
1243 const struct nir_shader_compiler_options *nir_options,
1244 unsigned char sha1_key[20],
1245 void *mem_ctx);
1246
1247 void
1248 anv_device_upload_nir(struct anv_device *device,
1249 struct anv_pipeline_cache *cache,
1250 const struct nir_shader *nir,
1251 unsigned char sha1_key[20]);
1252
1253 struct anv_device {
1254 VK_LOADER_DATA _loader_data;
1255
1256 VkAllocationCallbacks alloc;
1257
1258 struct anv_physical_device * physical;
1259 bool no_hw;
1260 struct gen_device_info info;
1261 struct isl_device isl_dev;
1262 int context_id;
1263 int fd;
1264 bool can_chain_batches;
1265 bool robust_buffer_access;
1266 struct anv_device_extension_table enabled_extensions;
1267 struct anv_device_dispatch_table dispatch;
1268
1269 pthread_mutex_t vma_mutex;
1270 struct util_vma_heap vma_lo;
1271 struct util_vma_heap vma_cva;
1272 struct util_vma_heap vma_hi;
1273
1274 /** List of all anv_device_memory objects */
1275 struct list_head memory_objects;
1276
1277 struct anv_bo_pool batch_bo_pool;
1278
1279 struct anv_bo_cache bo_cache;
1280
1281 struct anv_state_pool dynamic_state_pool;
1282 struct anv_state_pool instruction_state_pool;
1283 struct anv_state_pool binding_table_pool;
1284 struct anv_state_pool surface_state_pool;
1285
1286 struct anv_bo * workaround_bo;
1287 struct anv_bo * trivial_batch_bo;
1288 struct anv_bo * hiz_clear_bo;
1289
1290 struct anv_pipeline_cache default_pipeline_cache;
1291 struct blorp_context blorp;
1292
1293 struct anv_state border_colors;
1294
1295 struct anv_state slice_hash;
1296
1297 struct anv_queue queue;
1298
1299 struct anv_scratch_pool scratch_pool;
1300
1301 pthread_mutex_t mutex;
1302 pthread_cond_t queue_submit;
1303 int _lost;
1304
1305 struct gen_batch_decode_ctx decoder_ctx;
1306 /*
1307 * When decoding a anv_cmd_buffer, we might need to search for BOs through
1308 * the cmd_buffer's list.
1309 */
1310 struct anv_cmd_buffer *cmd_buffer_being_decoded;
1311
1312 int perf_fd; /* -1 if no opened */
1313 uint64_t perf_metric; /* 0 if unset */
1314
1315 struct gen_aux_map_context *aux_map_ctx;
1316 };
1317
1318 static inline struct anv_instance *
1319 anv_device_instance_or_null(const struct anv_device *device)
1320 {
1321 return device ? device->physical->instance : NULL;
1322 }
1323
1324 static inline struct anv_state_pool *
1325 anv_binding_table_pool(struct anv_device *device)
1326 {
1327 if (device->physical->use_softpin)
1328 return &device->binding_table_pool;
1329 else
1330 return &device->surface_state_pool;
1331 }
1332
1333 static inline struct anv_state
1334 anv_binding_table_pool_alloc(struct anv_device *device) {
1335 if (device->physical->use_softpin)
1336 return anv_state_pool_alloc(&device->binding_table_pool,
1337 device->binding_table_pool.block_size, 0);
1338 else
1339 return anv_state_pool_alloc_back(&device->surface_state_pool);
1340 }
1341
1342 static inline void
1343 anv_binding_table_pool_free(struct anv_device *device, struct anv_state state) {
1344 anv_state_pool_free(anv_binding_table_pool(device), state);
1345 }
1346
1347 static inline uint32_t
1348 anv_mocs_for_bo(const struct anv_device *device, const struct anv_bo *bo)
1349 {
1350 if (bo->is_external)
1351 return device->isl_dev.mocs.external;
1352 else
1353 return device->isl_dev.mocs.internal;
1354 }
1355
1356 void anv_device_init_blorp(struct anv_device *device);
1357 void anv_device_finish_blorp(struct anv_device *device);
1358
1359 void _anv_device_set_all_queue_lost(struct anv_device *device);
1360 VkResult _anv_device_set_lost(struct anv_device *device,
1361 const char *file, int line,
1362 const char *msg, ...)
1363 anv_printflike(4, 5);
1364 VkResult _anv_queue_set_lost(struct anv_queue *queue,
1365 const char *file, int line,
1366 const char *msg, ...)
1367 anv_printflike(4, 5);
1368 #define anv_device_set_lost(dev, ...) \
1369 _anv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)
1370 #define anv_queue_set_lost(queue, ...) \
1371 _anv_queue_set_lost(queue, __FILE__, __LINE__, __VA_ARGS__)
1372
1373 static inline bool
1374 anv_device_is_lost(struct anv_device *device)
1375 {
1376 return unlikely(p_atomic_read(&device->_lost));
1377 }
1378
1379 VkResult anv_device_query_status(struct anv_device *device);
1380
1381
1382 enum anv_bo_alloc_flags {
1383 /** Specifies that the BO must have a 32-bit address
1384 *
1385 * This is the opposite of EXEC_OBJECT_SUPPORTS_48B_ADDRESS.
1386 */
1387 ANV_BO_ALLOC_32BIT_ADDRESS = (1 << 0),
1388
1389 /** Specifies that the BO may be shared externally */
1390 ANV_BO_ALLOC_EXTERNAL = (1 << 1),
1391
1392 /** Specifies that the BO should be mapped */
1393 ANV_BO_ALLOC_MAPPED = (1 << 2),
1394
1395 /** Specifies that the BO should be snooped so we get coherency */
1396 ANV_BO_ALLOC_SNOOPED = (1 << 3),
1397
1398 /** Specifies that the BO should be captured in error states */
1399 ANV_BO_ALLOC_CAPTURE = (1 << 4),
1400
1401 /** Specifies that the BO will have an address assigned by the caller
1402 *
1403 * Such BOs do not exist in any VMA heap.
1404 */
1405 ANV_BO_ALLOC_FIXED_ADDRESS = (1 << 5),
1406
1407 /** Enables implicit synchronization on the BO
1408 *
1409 * This is the opposite of EXEC_OBJECT_ASYNC.
1410 */
1411 ANV_BO_ALLOC_IMPLICIT_SYNC = (1 << 6),
1412
1413 /** Enables implicit synchronization on the BO
1414 *
1415 * This is equivalent to EXEC_OBJECT_WRITE.
1416 */
1417 ANV_BO_ALLOC_IMPLICIT_WRITE = (1 << 7),
1418
1419 /** Has an address which is visible to the client */
1420 ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS = (1 << 8),
1421
1422 /** This buffer has implicit CCS data attached to it */
1423 ANV_BO_ALLOC_IMPLICIT_CCS = (1 << 9),
1424 };
1425
1426 VkResult anv_device_alloc_bo(struct anv_device *device, uint64_t size,
1427 enum anv_bo_alloc_flags alloc_flags,
1428 uint64_t explicit_address,
1429 struct anv_bo **bo);
1430 VkResult anv_device_import_bo_from_host_ptr(struct anv_device *device,
1431 void *host_ptr, uint32_t size,
1432 enum anv_bo_alloc_flags alloc_flags,
1433 uint64_t client_address,
1434 struct anv_bo **bo_out);
1435 VkResult anv_device_import_bo(struct anv_device *device, int fd,
1436 enum anv_bo_alloc_flags alloc_flags,
1437 uint64_t client_address,
1438 struct anv_bo **bo);
1439 VkResult anv_device_export_bo(struct anv_device *device,
1440 struct anv_bo *bo, int *fd_out);
1441 void anv_device_release_bo(struct anv_device *device,
1442 struct anv_bo *bo);
1443
1444 static inline struct anv_bo *
1445 anv_device_lookup_bo(struct anv_device *device, uint32_t gem_handle)
1446 {
1447 return util_sparse_array_get(&device->bo_cache.bo_map, gem_handle);
1448 }
1449
1450 VkResult anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo);
1451 VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo,
1452 int64_t timeout);
1453
1454 VkResult anv_queue_init(struct anv_device *device, struct anv_queue *queue);
1455 void anv_queue_finish(struct anv_queue *queue);
1456
1457 VkResult anv_queue_execbuf_locked(struct anv_queue *queue, struct anv_queue_submit *submit);
1458 VkResult anv_queue_submit_simple_batch(struct anv_queue *queue,
1459 struct anv_batch *batch);
1460
1461 uint64_t anv_gettime_ns(void);
1462 uint64_t anv_get_absolute_timeout(uint64_t timeout);
1463
1464 void* anv_gem_mmap(struct anv_device *device,
1465 uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags);
1466 void anv_gem_munmap(void *p, uint64_t size);
1467 uint32_t anv_gem_create(struct anv_device *device, uint64_t size);
1468 void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
1469 uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
1470 int anv_gem_busy(struct anv_device *device, uint32_t gem_handle);
1471 int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns);
1472 int anv_gem_execbuffer(struct anv_device *device,
1473 struct drm_i915_gem_execbuffer2 *execbuf);
1474 int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
1475 uint32_t stride, uint32_t tiling);
1476 int anv_gem_create_context(struct anv_device *device);
1477 bool anv_gem_has_context_priority(int fd);
1478 int anv_gem_destroy_context(struct anv_device *device, int context);
1479 int anv_gem_set_context_param(int fd, int context, uint32_t param,
1480 uint64_t value);
1481 int anv_gem_get_context_param(int fd, int context, uint32_t param,
1482 uint64_t *value);
1483 int anv_gem_get_param(int fd, uint32_t param);
1484 int anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle);
1485 bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
1486 int anv_gem_get_aperture(int fd, uint64_t *size);
1487 int anv_gem_gpu_get_reset_stats(struct anv_device *device,
1488 uint32_t *active, uint32_t *pending);
1489 int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
1490 int anv_gem_reg_read(struct anv_device *device,
1491 uint32_t offset, uint64_t *result);
1492 uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
1493 int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
1494 int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
1495 uint32_t read_domains, uint32_t write_domain);
1496 int anv_gem_sync_file_merge(struct anv_device *device, int fd1, int fd2);
1497 uint32_t anv_gem_syncobj_create(struct anv_device *device, uint32_t flags);
1498 void anv_gem_syncobj_destroy(struct anv_device *device, uint32_t handle);
1499 int anv_gem_syncobj_handle_to_fd(struct anv_device *device, uint32_t handle);
1500 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device *device, int fd);
1501 int anv_gem_syncobj_export_sync_file(struct anv_device *device,
1502 uint32_t handle);
1503 int anv_gem_syncobj_import_sync_file(struct anv_device *device,
1504 uint32_t handle, int fd);
1505 void anv_gem_syncobj_reset(struct anv_device *device, uint32_t handle);
1506 bool anv_gem_supports_syncobj_wait(int fd);
1507 int anv_gem_syncobj_wait(struct anv_device *device,
1508 uint32_t *handles, uint32_t num_handles,
1509 int64_t abs_timeout_ns, bool wait_all);
1510
1511 uint64_t anv_vma_alloc(struct anv_device *device,
1512 uint64_t size, uint64_t align,
1513 enum anv_bo_alloc_flags alloc_flags,
1514 uint64_t client_address);
1515 void anv_vma_free(struct anv_device *device,
1516 uint64_t address, uint64_t size);
1517
1518 struct anv_reloc_list {
1519 uint32_t num_relocs;
1520 uint32_t array_length;
1521 struct drm_i915_gem_relocation_entry * relocs;
1522 struct anv_bo ** reloc_bos;
1523 uint32_t dep_words;
1524 BITSET_WORD * deps;
1525 };
1526
1527 VkResult anv_reloc_list_init(struct anv_reloc_list *list,
1528 const VkAllocationCallbacks *alloc);
1529 void anv_reloc_list_finish(struct anv_reloc_list *list,
1530 const VkAllocationCallbacks *alloc);
1531
1532 VkResult anv_reloc_list_add(struct anv_reloc_list *list,
1533 const VkAllocationCallbacks *alloc,
1534 uint32_t offset, struct anv_bo *target_bo,
1535 uint32_t delta, uint64_t *address_u64_out);
1536
1537 struct anv_batch_bo {
1538 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1539 struct list_head link;
1540
1541 struct anv_bo * bo;
1542
1543 /* Bytes actually consumed in this batch BO */
1544 uint32_t length;
1545
1546 struct anv_reloc_list relocs;
1547 };
1548
1549 struct anv_batch {
1550 const VkAllocationCallbacks * alloc;
1551
1552 void * start;
1553 void * end;
1554 void * next;
1555
1556 struct anv_reloc_list * relocs;
1557
1558 /* This callback is called (with the associated user data) in the event
1559 * that the batch runs out of space.
1560 */
1561 VkResult (*extend_cb)(struct anv_batch *, void *);
1562 void * user_data;
1563
1564 /**
1565 * Current error status of the command buffer. Used to track inconsistent
1566 * or incomplete command buffer states that are the consequence of run-time
1567 * errors such as out of memory scenarios. We want to track this in the
1568 * batch because the command buffer object is not visible to some parts
1569 * of the driver.
1570 */
1571 VkResult status;
1572 };
1573
1574 void *anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords);
1575 void anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other);
1576 uint64_t anv_batch_emit_reloc(struct anv_batch *batch,
1577 void *location, struct anv_bo *bo, uint32_t offset);
1578
1579 static inline VkResult
1580 anv_batch_set_error(struct anv_batch *batch, VkResult error)
1581 {
1582 assert(error != VK_SUCCESS);
1583 if (batch->status == VK_SUCCESS)
1584 batch->status = error;
1585 return batch->status;
1586 }
1587
1588 static inline bool
1589 anv_batch_has_error(struct anv_batch *batch)
1590 {
1591 return batch->status != VK_SUCCESS;
1592 }
1593
1594 struct anv_address {
1595 struct anv_bo *bo;
1596 uint32_t offset;
1597 };
1598
1599 #define ANV_NULL_ADDRESS ((struct anv_address) { NULL, 0 })
1600
1601 static inline bool
1602 anv_address_is_null(struct anv_address addr)
1603 {
1604 return addr.bo == NULL && addr.offset == 0;
1605 }
1606
1607 static inline uint64_t
1608 anv_address_physical(struct anv_address addr)
1609 {
1610 if (addr.bo && (addr.bo->flags & EXEC_OBJECT_PINNED))
1611 return gen_canonical_address(addr.bo->offset + addr.offset);
1612 else
1613 return gen_canonical_address(addr.offset);
1614 }
1615
1616 static inline struct anv_address
1617 anv_address_add(struct anv_address addr, uint64_t offset)
1618 {
1619 addr.offset += offset;
1620 return addr;
1621 }
1622
1623 static inline void
1624 write_reloc(const struct anv_device *device, void *p, uint64_t v, bool flush)
1625 {
1626 unsigned reloc_size = 0;
1627 if (device->info.gen >= 8) {
1628 reloc_size = sizeof(uint64_t);
1629 *(uint64_t *)p = gen_canonical_address(v);
1630 } else {
1631 reloc_size = sizeof(uint32_t);
1632 *(uint32_t *)p = v;
1633 }
1634
1635 if (flush && !device->info.has_llc)
1636 gen_flush_range(p, reloc_size);
1637 }
1638
1639 static inline uint64_t
1640 _anv_combine_address(struct anv_batch *batch, void *location,
1641 const struct anv_address address, uint32_t delta)
1642 {
1643 if (address.bo == NULL) {
1644 return address.offset + delta;
1645 } else {
1646 assert(batch->start <= location && location < batch->end);
1647
1648 return anv_batch_emit_reloc(batch, location, address.bo, address.offset + delta);
1649 }
1650 }
1651
1652 #define __gen_address_type struct anv_address
1653 #define __gen_user_data struct anv_batch
1654 #define __gen_combine_address _anv_combine_address
1655
1656 /* Wrapper macros needed to work around preprocessor argument issues. In
1657 * particular, arguments don't get pre-evaluated if they are concatenated.
1658 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1659 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1660 * We can work around this easily enough with these helpers.
1661 */
1662 #define __anv_cmd_length(cmd) cmd ## _length
1663 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1664 #define __anv_cmd_header(cmd) cmd ## _header
1665 #define __anv_cmd_pack(cmd) cmd ## _pack
1666 #define __anv_reg_num(reg) reg ## _num
1667
1668 #define anv_pack_struct(dst, struc, ...) do { \
1669 struct struc __template = { \
1670 __VA_ARGS__ \
1671 }; \
1672 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1673 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1674 } while (0)
1675
1676 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1677 void *__dst = anv_batch_emit_dwords(batch, n); \
1678 if (__dst) { \
1679 struct cmd __template = { \
1680 __anv_cmd_header(cmd), \
1681 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1682 __VA_ARGS__ \
1683 }; \
1684 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1685 } \
1686 __dst; \
1687 })
1688
1689 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1690 do { \
1691 uint32_t *dw; \
1692 \
1693 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1694 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1695 if (!dw) \
1696 break; \
1697 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1698 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1699 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1700 } while (0)
1701
1702 #define anv_batch_emit(batch, cmd, name) \
1703 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1704 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1705 __builtin_expect(_dst != NULL, 1); \
1706 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1707 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1708 _dst = NULL; \
1709 }))
1710
1711 struct anv_device_memory {
1712 struct list_head link;
1713
1714 struct anv_bo * bo;
1715 struct anv_memory_type * type;
1716 VkDeviceSize map_size;
1717 void * map;
1718
1719 /* If set, we are holding reference to AHardwareBuffer
1720 * which we must release when memory is freed.
1721 */
1722 struct AHardwareBuffer * ahw;
1723
1724 /* If set, this memory comes from a host pointer. */
1725 void * host_ptr;
1726 };
1727
1728 /**
1729 * Header for Vertex URB Entry (VUE)
1730 */
1731 struct anv_vue_header {
1732 uint32_t Reserved;
1733 uint32_t RTAIndex; /* RenderTargetArrayIndex */
1734 uint32_t ViewportIndex;
1735 float PointWidth;
1736 };
1737
1738 /** Struct representing a sampled image descriptor
1739 *
1740 * This descriptor layout is used for sampled images, bare sampler, and
1741 * combined image/sampler descriptors.
1742 */
1743 struct anv_sampled_image_descriptor {
1744 /** Bindless image handle
1745 *
1746 * This is expected to already be shifted such that the 20-bit
1747 * SURFACE_STATE table index is in the top 20 bits.
1748 */
1749 uint32_t image;
1750
1751 /** Bindless sampler handle
1752 *
1753 * This is assumed to be a 32B-aligned SAMPLER_STATE pointer relative
1754 * to the dynamic state base address.
1755 */
1756 uint32_t sampler;
1757 };
1758
1759 struct anv_texture_swizzle_descriptor {
1760 /** Texture swizzle
1761 *
1762 * See also nir_intrinsic_channel_select_intel
1763 */
1764 uint8_t swizzle[4];
1765
1766 /** Unused padding to ensure the struct is a multiple of 64 bits */
1767 uint32_t _pad;
1768 };
1769
1770 /** Struct representing a storage image descriptor */
1771 struct anv_storage_image_descriptor {
1772 /** Bindless image handles
1773 *
1774 * These are expected to already be shifted such that the 20-bit
1775 * SURFACE_STATE table index is in the top 20 bits.
1776 */
1777 uint32_t read_write;
1778 uint32_t write_only;
1779 };
1780
1781 /** Struct representing a address/range descriptor
1782 *
1783 * The fields of this struct correspond directly to the data layout of
1784 * nir_address_format_64bit_bounded_global addresses. The last field is the
1785 * offset in the NIR address so it must be zero so that when you load the
1786 * descriptor you get a pointer to the start of the range.
1787 */
1788 struct anv_address_range_descriptor {
1789 uint64_t address;
1790 uint32_t range;
1791 uint32_t zero;
1792 };
1793
1794 enum anv_descriptor_data {
1795 /** The descriptor contains a BTI reference to a surface state */
1796 ANV_DESCRIPTOR_SURFACE_STATE = (1 << 0),
1797 /** The descriptor contains a BTI reference to a sampler state */
1798 ANV_DESCRIPTOR_SAMPLER_STATE = (1 << 1),
1799 /** The descriptor contains an actual buffer view */
1800 ANV_DESCRIPTOR_BUFFER_VIEW = (1 << 2),
1801 /** The descriptor contains auxiliary image layout data */
1802 ANV_DESCRIPTOR_IMAGE_PARAM = (1 << 3),
1803 /** The descriptor contains auxiliary image layout data */
1804 ANV_DESCRIPTOR_INLINE_UNIFORM = (1 << 4),
1805 /** anv_address_range_descriptor with a buffer address and range */
1806 ANV_DESCRIPTOR_ADDRESS_RANGE = (1 << 5),
1807 /** Bindless surface handle */
1808 ANV_DESCRIPTOR_SAMPLED_IMAGE = (1 << 6),
1809 /** Storage image handles */
1810 ANV_DESCRIPTOR_STORAGE_IMAGE = (1 << 7),
1811 /** Storage image handles */
1812 ANV_DESCRIPTOR_TEXTURE_SWIZZLE = (1 << 8),
1813 };
1814
1815 struct anv_descriptor_set_binding_layout {
1816 #ifndef NDEBUG
1817 /* The type of the descriptors in this binding */
1818 VkDescriptorType type;
1819 #endif
1820
1821 /* Flags provided when this binding was created */
1822 VkDescriptorBindingFlagsEXT flags;
1823
1824 /* Bitfield representing the type of data this descriptor contains */
1825 enum anv_descriptor_data data;
1826
1827 /* Maximum number of YCbCr texture/sampler planes */
1828 uint8_t max_plane_count;
1829
1830 /* Number of array elements in this binding (or size in bytes for inline
1831 * uniform data)
1832 */
1833 uint16_t array_size;
1834
1835 /* Index into the flattend descriptor set */
1836 uint16_t descriptor_index;
1837
1838 /* Index into the dynamic state array for a dynamic buffer */
1839 int16_t dynamic_offset_index;
1840
1841 /* Index into the descriptor set buffer views */
1842 int16_t buffer_view_index;
1843
1844 /* Offset into the descriptor buffer where this descriptor lives */
1845 uint32_t descriptor_offset;
1846
1847 /* Immutable samplers (or NULL if no immutable samplers) */
1848 struct anv_sampler **immutable_samplers;
1849 };
1850
1851 unsigned anv_descriptor_size(const struct anv_descriptor_set_binding_layout *layout);
1852
1853 unsigned anv_descriptor_type_size(const struct anv_physical_device *pdevice,
1854 VkDescriptorType type);
1855
1856 bool anv_descriptor_supports_bindless(const struct anv_physical_device *pdevice,
1857 const struct anv_descriptor_set_binding_layout *binding,
1858 bool sampler);
1859
1860 bool anv_descriptor_requires_bindless(const struct anv_physical_device *pdevice,
1861 const struct anv_descriptor_set_binding_layout *binding,
1862 bool sampler);
1863
1864 struct anv_descriptor_set_layout {
1865 /* Descriptor set layouts can be destroyed at almost any time */
1866 uint32_t ref_cnt;
1867
1868 /* Number of bindings in this descriptor set */
1869 uint16_t binding_count;
1870
1871 /* Total size of the descriptor set with room for all array entries */
1872 uint16_t size;
1873
1874 /* Shader stages affected by this descriptor set */
1875 uint16_t shader_stages;
1876
1877 /* Number of buffer views in this descriptor set */
1878 uint16_t buffer_view_count;
1879
1880 /* Number of dynamic offsets used by this descriptor set */
1881 uint16_t dynamic_offset_count;
1882
1883 /* For each shader stage, which offsets apply to that stage */
1884 uint16_t stage_dynamic_offsets[MESA_SHADER_STAGES];
1885
1886 /* Size of the descriptor buffer for this descriptor set */
1887 uint32_t descriptor_buffer_size;
1888
1889 /* Bindings in this descriptor set */
1890 struct anv_descriptor_set_binding_layout binding[0];
1891 };
1892
1893 static inline void
1894 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout *layout)
1895 {
1896 assert(layout && layout->ref_cnt >= 1);
1897 p_atomic_inc(&layout->ref_cnt);
1898 }
1899
1900 static inline void
1901 anv_descriptor_set_layout_unref(struct anv_device *device,
1902 struct anv_descriptor_set_layout *layout)
1903 {
1904 assert(layout && layout->ref_cnt >= 1);
1905 if (p_atomic_dec_zero(&layout->ref_cnt))
1906 vk_free(&device->alloc, layout);
1907 }
1908
1909 struct anv_descriptor {
1910 VkDescriptorType type;
1911
1912 union {
1913 struct {
1914 VkImageLayout layout;
1915 struct anv_image_view *image_view;
1916 struct anv_sampler *sampler;
1917 };
1918
1919 struct {
1920 struct anv_buffer *buffer;
1921 uint64_t offset;
1922 uint64_t range;
1923 };
1924
1925 struct anv_buffer_view *buffer_view;
1926 };
1927 };
1928
1929 struct anv_descriptor_set {
1930 struct anv_descriptor_pool *pool;
1931 struct anv_descriptor_set_layout *layout;
1932 uint32_t size;
1933
1934 /* State relative to anv_descriptor_pool::bo */
1935 struct anv_state desc_mem;
1936 /* Surface state for the descriptor buffer */
1937 struct anv_state desc_surface_state;
1938
1939 uint32_t buffer_view_count;
1940 struct anv_buffer_view *buffer_views;
1941
1942 /* Link to descriptor pool's desc_sets list . */
1943 struct list_head pool_link;
1944
1945 struct anv_descriptor descriptors[0];
1946 };
1947
1948 struct anv_buffer_view {
1949 enum isl_format format; /**< VkBufferViewCreateInfo::format */
1950 uint64_t range; /**< VkBufferViewCreateInfo::range */
1951
1952 struct anv_address address;
1953
1954 struct anv_state surface_state;
1955 struct anv_state storage_surface_state;
1956 struct anv_state writeonly_storage_surface_state;
1957
1958 struct brw_image_param storage_image_param;
1959 };
1960
1961 struct anv_push_descriptor_set {
1962 struct anv_descriptor_set set;
1963
1964 /* Put this field right behind anv_descriptor_set so it fills up the
1965 * descriptors[0] field. */
1966 struct anv_descriptor descriptors[MAX_PUSH_DESCRIPTORS];
1967
1968 /** True if the descriptor set buffer has been referenced by a draw or
1969 * dispatch command.
1970 */
1971 bool set_used_on_gpu;
1972
1973 struct anv_buffer_view buffer_views[MAX_PUSH_DESCRIPTORS];
1974 };
1975
1976 struct anv_descriptor_pool {
1977 uint32_t size;
1978 uint32_t next;
1979 uint32_t free_list;
1980
1981 struct anv_bo *bo;
1982 struct util_vma_heap bo_heap;
1983
1984 struct anv_state_stream surface_state_stream;
1985 void *surface_state_free_list;
1986
1987 struct list_head desc_sets;
1988
1989 char data[0];
1990 };
1991
1992 enum anv_descriptor_template_entry_type {
1993 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
1994 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
1995 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1996 };
1997
1998 struct anv_descriptor_template_entry {
1999 /* The type of descriptor in this entry */
2000 VkDescriptorType type;
2001
2002 /* Binding in the descriptor set */
2003 uint32_t binding;
2004
2005 /* Offset at which to write into the descriptor set binding */
2006 uint32_t array_element;
2007
2008 /* Number of elements to write into the descriptor set binding */
2009 uint32_t array_count;
2010
2011 /* Offset into the user provided data */
2012 size_t offset;
2013
2014 /* Stride between elements into the user provided data */
2015 size_t stride;
2016 };
2017
2018 struct anv_descriptor_update_template {
2019 VkPipelineBindPoint bind_point;
2020
2021 /* The descriptor set this template corresponds to. This value is only
2022 * valid if the template was created with the templateType
2023 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET.
2024 */
2025 uint8_t set;
2026
2027 /* Number of entries in this template */
2028 uint32_t entry_count;
2029
2030 /* Entries of the template */
2031 struct anv_descriptor_template_entry entries[0];
2032 };
2033
2034 size_t
2035 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
2036
2037 void
2038 anv_descriptor_set_write_image_view(struct anv_device *device,
2039 struct anv_descriptor_set *set,
2040 const VkDescriptorImageInfo * const info,
2041 VkDescriptorType type,
2042 uint32_t binding,
2043 uint32_t element);
2044
2045 void
2046 anv_descriptor_set_write_buffer_view(struct anv_device *device,
2047 struct anv_descriptor_set *set,
2048 VkDescriptorType type,
2049 struct anv_buffer_view *buffer_view,
2050 uint32_t binding,
2051 uint32_t element);
2052
2053 void
2054 anv_descriptor_set_write_buffer(struct anv_device *device,
2055 struct anv_descriptor_set *set,
2056 struct anv_state_stream *alloc_stream,
2057 VkDescriptorType type,
2058 struct anv_buffer *buffer,
2059 uint32_t binding,
2060 uint32_t element,
2061 VkDeviceSize offset,
2062 VkDeviceSize range);
2063 void
2064 anv_descriptor_set_write_inline_uniform_data(struct anv_device *device,
2065 struct anv_descriptor_set *set,
2066 uint32_t binding,
2067 const void *data,
2068 size_t offset,
2069 size_t size);
2070
2071 void
2072 anv_descriptor_set_write_template(struct anv_device *device,
2073 struct anv_descriptor_set *set,
2074 struct anv_state_stream *alloc_stream,
2075 const struct anv_descriptor_update_template *template,
2076 const void *data);
2077
2078 VkResult
2079 anv_descriptor_set_create(struct anv_device *device,
2080 struct anv_descriptor_pool *pool,
2081 struct anv_descriptor_set_layout *layout,
2082 struct anv_descriptor_set **out_set);
2083
2084 void
2085 anv_descriptor_set_destroy(struct anv_device *device,
2086 struct anv_descriptor_pool *pool,
2087 struct anv_descriptor_set *set);
2088
2089 #define ANV_DESCRIPTOR_SET_NULL (UINT8_MAX - 5)
2090 #define ANV_DESCRIPTOR_SET_PUSH_CONSTANTS (UINT8_MAX - 4)
2091 #define ANV_DESCRIPTOR_SET_DESCRIPTORS (UINT8_MAX - 3)
2092 #define ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS (UINT8_MAX - 2)
2093 #define ANV_DESCRIPTOR_SET_SHADER_CONSTANTS (UINT8_MAX - 1)
2094 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
2095
2096 struct anv_pipeline_binding {
2097 /** Index in the descriptor set
2098 *
2099 * This is a flattened index; the descriptor set layout is already taken
2100 * into account.
2101 */
2102 uint32_t index;
2103
2104 /** The descriptor set this surface corresponds to.
2105 *
2106 * The special ANV_DESCRIPTOR_SET_* values above indicates that this
2107 * binding is not a normal descriptor set but something else.
2108 */
2109 uint8_t set;
2110
2111 union {
2112 /** Plane in the binding index for images */
2113 uint8_t plane;
2114
2115 /** Input attachment index (relative to the subpass) */
2116 uint8_t input_attachment_index;
2117
2118 /** Dynamic offset index (for dynamic UBOs and SSBOs) */
2119 uint8_t dynamic_offset_index;
2120 };
2121
2122 /** For a storage image, whether it is write-only */
2123 uint8_t write_only;
2124
2125 /** Pad to 64 bits so that there are no holes and we can safely memcmp
2126 * assuming POD zero-initialization.
2127 */
2128 uint8_t pad;
2129 };
2130
2131 struct anv_push_range {
2132 /** Index in the descriptor set */
2133 uint32_t index;
2134
2135 /** Descriptor set index */
2136 uint8_t set;
2137
2138 /** Dynamic offset index (for dynamic UBOs) */
2139 uint8_t dynamic_offset_index;
2140
2141 /** Start offset in units of 32B */
2142 uint8_t start;
2143
2144 /** Range in units of 32B */
2145 uint8_t length;
2146 };
2147
2148 struct anv_pipeline_layout {
2149 struct {
2150 struct anv_descriptor_set_layout *layout;
2151 uint32_t dynamic_offset_start;
2152 } set[MAX_SETS];
2153
2154 uint32_t num_sets;
2155
2156 unsigned char sha1[20];
2157 };
2158
2159 struct anv_buffer {
2160 struct anv_device * device;
2161 VkDeviceSize size;
2162
2163 VkBufferUsageFlags usage;
2164
2165 /* Set when bound */
2166 struct anv_address address;
2167 };
2168
2169 static inline uint64_t
2170 anv_buffer_get_range(struct anv_buffer *buffer, uint64_t offset, uint64_t range)
2171 {
2172 assert(offset <= buffer->size);
2173 if (range == VK_WHOLE_SIZE) {
2174 return buffer->size - offset;
2175 } else {
2176 assert(range + offset >= range);
2177 assert(range + offset <= buffer->size);
2178 return range;
2179 }
2180 }
2181
2182 enum anv_cmd_dirty_bits {
2183 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
2184 ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
2185 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
2186 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
2187 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
2188 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
2189 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
2190 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
2191 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
2192 ANV_CMD_DIRTY_PIPELINE = 1 << 9,
2193 ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
2194 ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
2195 ANV_CMD_DIRTY_XFB_ENABLE = 1 << 12,
2196 ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE = 1 << 13, /* VK_DYNAMIC_STATE_LINE_STIPPLE_EXT */
2197 };
2198 typedef uint32_t anv_cmd_dirty_mask_t;
2199
2200 #define ANV_CMD_DIRTY_DYNAMIC_ALL \
2201 (ANV_CMD_DIRTY_DYNAMIC_VIEWPORT | \
2202 ANV_CMD_DIRTY_DYNAMIC_SCISSOR | \
2203 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH | \
2204 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS | \
2205 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS | \
2206 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS | \
2207 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK | \
2208 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK | \
2209 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE | \
2210 ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE)
2211
2212 static inline enum anv_cmd_dirty_bits
2213 anv_cmd_dirty_bit_for_vk_dynamic_state(VkDynamicState vk_state)
2214 {
2215 switch (vk_state) {
2216 case VK_DYNAMIC_STATE_VIEWPORT:
2217 return ANV_CMD_DIRTY_DYNAMIC_VIEWPORT;
2218 case VK_DYNAMIC_STATE_SCISSOR:
2219 return ANV_CMD_DIRTY_DYNAMIC_SCISSOR;
2220 case VK_DYNAMIC_STATE_LINE_WIDTH:
2221 return ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH;
2222 case VK_DYNAMIC_STATE_DEPTH_BIAS:
2223 return ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS;
2224 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
2225 return ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS;
2226 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
2227 return ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS;
2228 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
2229 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK;
2230 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
2231 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK;
2232 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
2233 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE;
2234 case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT:
2235 return ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE;
2236 default:
2237 assert(!"Unsupported dynamic state");
2238 return 0;
2239 }
2240 }
2241
2242
2243 enum anv_pipe_bits {
2244 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
2245 ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
2246 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
2247 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
2248 ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
2249 ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
2250 ANV_PIPE_TILE_CACHE_FLUSH_BIT = (1 << 6),
2251 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
2252 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
2253 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
2254 ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
2255 ANV_PIPE_CS_STALL_BIT = (1 << 20),
2256 ANV_PIPE_END_OF_PIPE_SYNC_BIT = (1 << 21),
2257
2258 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
2259 * a flush has happened but not a CS stall. The next time we do any sort
2260 * of invalidation we need to insert a CS stall at that time. Otherwise,
2261 * we would have to CS stall on every flush which could be bad.
2262 */
2263 ANV_PIPE_NEEDS_END_OF_PIPE_SYNC_BIT = (1 << 22),
2264
2265 /* This bit does not exist directly in PIPE_CONTROL. It means that render
2266 * target operations related to transfer commands with VkBuffer as
2267 * destination are ongoing. Some operations like copies on the command
2268 * streamer might need to be aware of this to trigger the appropriate stall
2269 * before they can proceed with the copy.
2270 */
2271 ANV_PIPE_RENDER_TARGET_BUFFER_WRITES = (1 << 23),
2272
2273 /* This bit does not exist directly in PIPE_CONTROL. It means that Gen12
2274 * AUX-TT data has changed and we need to invalidate AUX-TT data. This is
2275 * done by writing the AUX-TT register.
2276 */
2277 ANV_PIPE_AUX_TABLE_INVALIDATE_BIT = (1 << 24),
2278
2279 /* This bit does not exist directly in PIPE_CONTROL. It means that a
2280 * PIPE_CONTROL with a post-sync operation will follow. This is used to
2281 * implement a workaround for Gen9.
2282 */
2283 ANV_PIPE_POST_SYNC_BIT = (1 << 25),
2284 };
2285
2286 #define ANV_PIPE_FLUSH_BITS ( \
2287 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
2288 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
2289 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT | \
2290 ANV_PIPE_TILE_CACHE_FLUSH_BIT)
2291
2292 #define ANV_PIPE_STALL_BITS ( \
2293 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
2294 ANV_PIPE_DEPTH_STALL_BIT | \
2295 ANV_PIPE_CS_STALL_BIT)
2296
2297 #define ANV_PIPE_INVALIDATE_BITS ( \
2298 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
2299 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
2300 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
2301 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
2302 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
2303 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT | \
2304 ANV_PIPE_AUX_TABLE_INVALIDATE_BIT)
2305
2306 static inline enum anv_pipe_bits
2307 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags)
2308 {
2309 enum anv_pipe_bits pipe_bits = 0;
2310
2311 unsigned b;
2312 for_each_bit(b, flags) {
2313 switch ((VkAccessFlagBits)(1 << b)) {
2314 case VK_ACCESS_SHADER_WRITE_BIT:
2315 /* We're transitioning a buffer that was previously used as write
2316 * destination through the data port. To make its content available
2317 * to future operations, flush the data cache.
2318 */
2319 pipe_bits |= ANV_PIPE_DATA_CACHE_FLUSH_BIT;
2320 break;
2321 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT:
2322 /* We're transitioning a buffer that was previously used as render
2323 * target. To make its content available to future operations, flush
2324 * the render target cache.
2325 */
2326 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
2327 break;
2328 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT:
2329 /* We're transitioning a buffer that was previously used as depth
2330 * buffer. To make its content available to future operations, flush
2331 * the depth cache.
2332 */
2333 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
2334 break;
2335 case VK_ACCESS_TRANSFER_WRITE_BIT:
2336 /* We're transitioning a buffer that was previously used as a
2337 * transfer write destination. Generic write operations include color
2338 * & depth operations as well as buffer operations like :
2339 * - vkCmdClearColorImage()
2340 * - vkCmdClearDepthStencilImage()
2341 * - vkCmdBlitImage()
2342 * - vkCmdCopy*(), vkCmdUpdate*(), vkCmdFill*()
2343 *
2344 * Most of these operations are implemented using Blorp which writes
2345 * through the render target, so flush that cache to make it visible
2346 * to future operations. And for depth related operations we also
2347 * need to flush the depth cache.
2348 */
2349 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
2350 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
2351 break;
2352 case VK_ACCESS_MEMORY_WRITE_BIT:
2353 /* We're transitioning a buffer for generic write operations. Flush
2354 * all the caches.
2355 */
2356 pipe_bits |= ANV_PIPE_FLUSH_BITS;
2357 break;
2358 default:
2359 break; /* Nothing to do */
2360 }
2361 }
2362
2363 return pipe_bits;
2364 }
2365
2366 static inline enum anv_pipe_bits
2367 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags)
2368 {
2369 enum anv_pipe_bits pipe_bits = 0;
2370
2371 unsigned b;
2372 for_each_bit(b, flags) {
2373 switch ((VkAccessFlagBits)(1 << b)) {
2374 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT:
2375 /* Indirect draw commands take a buffer as input that we're going to
2376 * read from the command streamer to load some of the HW registers
2377 * (see genX_cmd_buffer.c:load_indirect_parameters). This requires a
2378 * command streamer stall so that all the cache flushes have
2379 * completed before the command streamer loads from memory.
2380 */
2381 pipe_bits |= ANV_PIPE_CS_STALL_BIT;
2382 /* Indirect draw commands also set gl_BaseVertex & gl_BaseIndex
2383 * through a vertex buffer, so invalidate that cache.
2384 */
2385 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
2386 /* For CmdDipatchIndirect, we also load gl_NumWorkGroups through a
2387 * UBO from the buffer, so we need to invalidate constant cache.
2388 */
2389 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
2390 break;
2391 case VK_ACCESS_INDEX_READ_BIT:
2392 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT:
2393 /* We transitioning a buffer to be used for as input for vkCmdDraw*
2394 * commands, so we invalidate the VF cache to make sure there is no
2395 * stale data when we start rendering.
2396 */
2397 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
2398 break;
2399 case VK_ACCESS_UNIFORM_READ_BIT:
2400 /* We transitioning a buffer to be used as uniform data. Because
2401 * uniform is accessed through the data port & sampler, we need to
2402 * invalidate the texture cache (sampler) & constant cache (data
2403 * port) to avoid stale data.
2404 */
2405 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
2406 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
2407 break;
2408 case VK_ACCESS_SHADER_READ_BIT:
2409 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT:
2410 case VK_ACCESS_TRANSFER_READ_BIT:
2411 /* Transitioning a buffer to be read through the sampler, so
2412 * invalidate the texture cache, we don't want any stale data.
2413 */
2414 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
2415 break;
2416 case VK_ACCESS_MEMORY_READ_BIT:
2417 /* Transitioning a buffer for generic read, invalidate all the
2418 * caches.
2419 */
2420 pipe_bits |= ANV_PIPE_INVALIDATE_BITS;
2421 break;
2422 case VK_ACCESS_MEMORY_WRITE_BIT:
2423 /* Generic write, make sure all previously written things land in
2424 * memory.
2425 */
2426 pipe_bits |= ANV_PIPE_FLUSH_BITS;
2427 break;
2428 case VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT:
2429 /* Transitioning a buffer for conditional rendering. We'll load the
2430 * content of this buffer into HW registers using the command
2431 * streamer, so we need to stall the command streamer to make sure
2432 * any in-flight flush operations have completed.
2433 */
2434 pipe_bits |= ANV_PIPE_CS_STALL_BIT;
2435 break;
2436 default:
2437 break; /* Nothing to do */
2438 }
2439 }
2440
2441 return pipe_bits;
2442 }
2443
2444 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
2445 VK_IMAGE_ASPECT_COLOR_BIT | \
2446 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2447 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2448 VK_IMAGE_ASPECT_PLANE_2_BIT)
2449 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
2450 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2451 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2452 VK_IMAGE_ASPECT_PLANE_2_BIT)
2453
2454 struct anv_vertex_binding {
2455 struct anv_buffer * buffer;
2456 VkDeviceSize offset;
2457 };
2458
2459 struct anv_xfb_binding {
2460 struct anv_buffer * buffer;
2461 VkDeviceSize offset;
2462 VkDeviceSize size;
2463 };
2464
2465 struct anv_push_constants {
2466 /** Push constant data provided by the client through vkPushConstants */
2467 uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
2468
2469 /** Dynamic offsets for dynamic UBOs and SSBOs */
2470 uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS];
2471
2472 struct {
2473 /** Base workgroup ID
2474 *
2475 * Used for vkCmdDispatchBase.
2476 */
2477 uint32_t base_work_group_id[3];
2478
2479 /** Subgroup ID
2480 *
2481 * This is never set by software but is implicitly filled out when
2482 * uploading the push constants for compute shaders.
2483 */
2484 uint32_t subgroup_id;
2485
2486 /** Pad out to a multiple of 32 bytes */
2487 uint32_t pad[4];
2488 } cs;
2489 };
2490
2491 struct anv_dynamic_state {
2492 struct {
2493 uint32_t count;
2494 VkViewport viewports[MAX_VIEWPORTS];
2495 } viewport;
2496
2497 struct {
2498 uint32_t count;
2499 VkRect2D scissors[MAX_SCISSORS];
2500 } scissor;
2501
2502 float line_width;
2503
2504 struct {
2505 float bias;
2506 float clamp;
2507 float slope;
2508 } depth_bias;
2509
2510 float blend_constants[4];
2511
2512 struct {
2513 float min;
2514 float max;
2515 } depth_bounds;
2516
2517 struct {
2518 uint32_t front;
2519 uint32_t back;
2520 } stencil_compare_mask;
2521
2522 struct {
2523 uint32_t front;
2524 uint32_t back;
2525 } stencil_write_mask;
2526
2527 struct {
2528 uint32_t front;
2529 uint32_t back;
2530 } stencil_reference;
2531
2532 struct {
2533 uint32_t factor;
2534 uint16_t pattern;
2535 } line_stipple;
2536 };
2537
2538 extern const struct anv_dynamic_state default_dynamic_state;
2539
2540 uint32_t anv_dynamic_state_copy(struct anv_dynamic_state *dest,
2541 const struct anv_dynamic_state *src,
2542 uint32_t copy_mask);
2543
2544 struct anv_surface_state {
2545 struct anv_state state;
2546 /** Address of the surface referred to by this state
2547 *
2548 * This address is relative to the start of the BO.
2549 */
2550 struct anv_address address;
2551 /* Address of the aux surface, if any
2552 *
2553 * This field is ANV_NULL_ADDRESS if and only if no aux surface exists.
2554 *
2555 * With the exception of gen8, the bottom 12 bits of this address' offset
2556 * include extra aux information.
2557 */
2558 struct anv_address aux_address;
2559 /* Address of the clear color, if any
2560 *
2561 * This address is relative to the start of the BO.
2562 */
2563 struct anv_address clear_address;
2564 };
2565
2566 /**
2567 * Attachment state when recording a renderpass instance.
2568 *
2569 * The clear value is valid only if there exists a pending clear.
2570 */
2571 struct anv_attachment_state {
2572 enum isl_aux_usage aux_usage;
2573 enum isl_aux_usage input_aux_usage;
2574 struct anv_surface_state color;
2575 struct anv_surface_state input;
2576
2577 VkImageLayout current_layout;
2578 VkImageLayout current_stencil_layout;
2579 VkImageAspectFlags pending_clear_aspects;
2580 VkImageAspectFlags pending_load_aspects;
2581 bool fast_clear;
2582 VkClearValue clear_value;
2583 bool clear_color_is_zero_one;
2584 bool clear_color_is_zero;
2585
2586 /* When multiview is active, attachments with a renderpass clear
2587 * operation have their respective layers cleared on the first
2588 * subpass that uses them, and only in that subpass. We keep track
2589 * of this using a bitfield to indicate which layers of an attachment
2590 * have not been cleared yet when multiview is active.
2591 */
2592 uint32_t pending_clear_views;
2593 struct anv_image_view * image_view;
2594 };
2595
2596 /** State tracking for vertex buffer flushes
2597 *
2598 * On Gen8-9, the VF cache only considers the bottom 32 bits of memory
2599 * addresses. If you happen to have two vertex buffers which get placed
2600 * exactly 4 GiB apart and use them in back-to-back draw calls, you can get
2601 * collisions. In order to solve this problem, we track vertex address ranges
2602 * which are live in the cache and invalidate the cache if one ever exceeds 32
2603 * bits.
2604 */
2605 struct anv_vb_cache_range {
2606 /* Virtual address at which the live vertex buffer cache range starts for
2607 * this vertex buffer index.
2608 */
2609 uint64_t start;
2610
2611 /* Virtual address of the byte after where vertex buffer cache range ends.
2612 * This is exclusive such that end - start is the size of the range.
2613 */
2614 uint64_t end;
2615 };
2616
2617 /** State tracking for particular pipeline bind point
2618 *
2619 * This struct is the base struct for anv_cmd_graphics_state and
2620 * anv_cmd_compute_state. These are used to track state which is bound to a
2621 * particular type of pipeline. Generic state that applies per-stage such as
2622 * binding table offsets and push constants is tracked generically with a
2623 * per-stage array in anv_cmd_state.
2624 */
2625 struct anv_cmd_pipeline_state {
2626 struct anv_pipeline *pipeline;
2627
2628 struct anv_descriptor_set *descriptors[MAX_SETS];
2629 struct anv_push_descriptor_set *push_descriptors[MAX_SETS];
2630 };
2631
2632 /** State tracking for graphics pipeline
2633 *
2634 * This has anv_cmd_pipeline_state as a base struct to track things which get
2635 * bound to a graphics pipeline. Along with general pipeline bind point state
2636 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2637 * state which is graphics-specific.
2638 */
2639 struct anv_cmd_graphics_state {
2640 struct anv_cmd_pipeline_state base;
2641
2642 anv_cmd_dirty_mask_t dirty;
2643 uint32_t vb_dirty;
2644
2645 struct anv_vb_cache_range ib_bound_range;
2646 struct anv_vb_cache_range ib_dirty_range;
2647 struct anv_vb_cache_range vb_bound_ranges[33];
2648 struct anv_vb_cache_range vb_dirty_ranges[33];
2649
2650 struct anv_dynamic_state dynamic;
2651
2652 struct {
2653 struct anv_buffer *index_buffer;
2654 uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
2655 uint32_t index_offset;
2656 } gen7;
2657 };
2658
2659 /** State tracking for compute pipeline
2660 *
2661 * This has anv_cmd_pipeline_state as a base struct to track things which get
2662 * bound to a compute pipeline. Along with general pipeline bind point state
2663 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2664 * state which is compute-specific.
2665 */
2666 struct anv_cmd_compute_state {
2667 struct anv_cmd_pipeline_state base;
2668
2669 bool pipeline_dirty;
2670
2671 struct anv_address num_workgroups;
2672 };
2673
2674 /** State required while building cmd buffer */
2675 struct anv_cmd_state {
2676 /* PIPELINE_SELECT.PipelineSelection */
2677 uint32_t current_pipeline;
2678 const struct gen_l3_config * current_l3_config;
2679 uint32_t last_aux_map_state;
2680
2681 struct anv_cmd_graphics_state gfx;
2682 struct anv_cmd_compute_state compute;
2683
2684 enum anv_pipe_bits pending_pipe_bits;
2685 VkShaderStageFlags descriptors_dirty;
2686 VkShaderStageFlags push_constants_dirty;
2687
2688 struct anv_framebuffer * framebuffer;
2689 struct anv_render_pass * pass;
2690 struct anv_subpass * subpass;
2691 VkRect2D render_area;
2692 uint32_t restart_index;
2693 struct anv_vertex_binding vertex_bindings[MAX_VBS];
2694 bool xfb_enabled;
2695 struct anv_xfb_binding xfb_bindings[MAX_XFB_BUFFERS];
2696 VkShaderStageFlags push_constant_stages;
2697 struct anv_push_constants push_constants[MESA_SHADER_STAGES];
2698 struct anv_state binding_tables[MESA_SHADER_STAGES];
2699 struct anv_state samplers[MESA_SHADER_STAGES];
2700
2701 unsigned char sampler_sha1s[MESA_SHADER_STAGES][20];
2702 unsigned char surface_sha1s[MESA_SHADER_STAGES][20];
2703 unsigned char push_sha1s[MESA_SHADER_STAGES][20];
2704
2705 /**
2706 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
2707 * of any command buffer it is disabled by disabling it in EndCommandBuffer
2708 * and before invoking the secondary in ExecuteCommands.
2709 */
2710 bool pma_fix_enabled;
2711
2712 /**
2713 * Whether or not we know for certain that HiZ is enabled for the current
2714 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
2715 * enabled or not, this will be false.
2716 */
2717 bool hiz_enabled;
2718
2719 bool conditional_render_enabled;
2720
2721 /**
2722 * Last rendering scale argument provided to
2723 * genX(cmd_buffer_emit_hashing_mode)().
2724 */
2725 unsigned current_hash_scale;
2726
2727 /**
2728 * Array length is anv_cmd_state::pass::attachment_count. Array content is
2729 * valid only when recording a render pass instance.
2730 */
2731 struct anv_attachment_state * attachments;
2732
2733 /**
2734 * Surface states for color render targets. These are stored in a single
2735 * flat array. For depth-stencil attachments, the surface state is simply
2736 * left blank.
2737 */
2738 struct anv_state render_pass_states;
2739
2740 /**
2741 * A null surface state of the right size to match the framebuffer. This
2742 * is one of the states in render_pass_states.
2743 */
2744 struct anv_state null_surface_state;
2745 };
2746
2747 struct anv_cmd_pool {
2748 VkAllocationCallbacks alloc;
2749 struct list_head cmd_buffers;
2750 };
2751
2752 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
2753
2754 enum anv_cmd_buffer_exec_mode {
2755 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
2756 ANV_CMD_BUFFER_EXEC_MODE_EMIT,
2757 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
2758 ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
2759 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
2760 };
2761
2762 struct anv_cmd_buffer {
2763 VK_LOADER_DATA _loader_data;
2764
2765 struct anv_device * device;
2766
2767 struct anv_cmd_pool * pool;
2768 struct list_head pool_link;
2769
2770 struct anv_batch batch;
2771
2772 /* Fields required for the actual chain of anv_batch_bo's.
2773 *
2774 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
2775 */
2776 struct list_head batch_bos;
2777 enum anv_cmd_buffer_exec_mode exec_mode;
2778
2779 /* A vector of anv_batch_bo pointers for every batch or surface buffer
2780 * referenced by this command buffer
2781 *
2782 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2783 */
2784 struct u_vector seen_bbos;
2785
2786 /* A vector of int32_t's for every block of binding tables.
2787 *
2788 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2789 */
2790 struct u_vector bt_block_states;
2791 struct anv_state bt_next;
2792
2793 struct anv_reloc_list surface_relocs;
2794 /** Last seen surface state block pool center bo offset */
2795 uint32_t last_ss_pool_center;
2796
2797 /* Serial for tracking buffer completion */
2798 uint32_t serial;
2799
2800 /* Stream objects for storing temporary data */
2801 struct anv_state_stream surface_state_stream;
2802 struct anv_state_stream dynamic_state_stream;
2803
2804 VkCommandBufferUsageFlags usage_flags;
2805 VkCommandBufferLevel level;
2806
2807 struct anv_cmd_state state;
2808
2809 /* Set by SetPerformanceMarkerINTEL, written into queries by CmdBeginQuery */
2810 uint64_t intel_perf_marker;
2811 };
2812
2813 VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2814 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2815 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2816 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
2817 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
2818 struct anv_cmd_buffer *secondary);
2819 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
2820 VkResult anv_cmd_buffer_execbuf(struct anv_queue *queue,
2821 struct anv_cmd_buffer *cmd_buffer,
2822 const VkSemaphore *in_semaphores,
2823 const uint64_t *in_wait_values,
2824 uint32_t num_in_semaphores,
2825 const VkSemaphore *out_semaphores,
2826 const uint64_t *out_signal_values,
2827 uint32_t num_out_semaphores,
2828 VkFence fence);
2829
2830 VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
2831
2832 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
2833 const void *data, uint32_t size, uint32_t alignment);
2834 struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
2835 uint32_t *a, uint32_t *b,
2836 uint32_t dwords, uint32_t alignment);
2837
2838 struct anv_address
2839 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
2840 struct anv_state
2841 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
2842 uint32_t entries, uint32_t *state_offset);
2843 struct anv_state
2844 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
2845 struct anv_state
2846 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
2847 uint32_t size, uint32_t alignment);
2848
2849 VkResult
2850 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
2851
2852 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
2853 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
2854 bool depth_clamp_enable);
2855 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
2856
2857 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
2858 struct anv_render_pass *pass,
2859 struct anv_framebuffer *framebuffer,
2860 const VkClearValue *clear_values);
2861
2862 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
2863
2864 struct anv_state
2865 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
2866 gl_shader_stage stage);
2867 struct anv_state
2868 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
2869
2870 const struct anv_image_view *
2871 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
2872
2873 VkResult
2874 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
2875 uint32_t num_entries,
2876 uint32_t *state_offset,
2877 struct anv_state *bt_state);
2878
2879 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
2880
2881 void anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer *cmd_buffer);
2882
2883 enum anv_fence_type {
2884 ANV_FENCE_TYPE_NONE = 0,
2885 ANV_FENCE_TYPE_BO,
2886 ANV_FENCE_TYPE_WSI_BO,
2887 ANV_FENCE_TYPE_SYNCOBJ,
2888 ANV_FENCE_TYPE_WSI,
2889 };
2890
2891 enum anv_bo_fence_state {
2892 /** Indicates that this is a new (or newly reset fence) */
2893 ANV_BO_FENCE_STATE_RESET,
2894
2895 /** Indicates that this fence has been submitted to the GPU but is still
2896 * (as far as we know) in use by the GPU.
2897 */
2898 ANV_BO_FENCE_STATE_SUBMITTED,
2899
2900 ANV_BO_FENCE_STATE_SIGNALED,
2901 };
2902
2903 struct anv_fence_impl {
2904 enum anv_fence_type type;
2905
2906 union {
2907 /** Fence implementation for BO fences
2908 *
2909 * These fences use a BO and a set of CPU-tracked state flags. The BO
2910 * is added to the object list of the last execbuf call in a QueueSubmit
2911 * and is marked EXEC_WRITE. The state flags track when the BO has been
2912 * submitted to the kernel. We need to do this because Vulkan lets you
2913 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2914 * will say it's idle in this case.
2915 */
2916 struct {
2917 struct anv_bo *bo;
2918 enum anv_bo_fence_state state;
2919 } bo;
2920
2921 /** DRM syncobj handle for syncobj-based fences */
2922 uint32_t syncobj;
2923
2924 /** WSI fence */
2925 struct wsi_fence *fence_wsi;
2926 };
2927 };
2928
2929 struct anv_fence {
2930 /* Permanent fence state. Every fence has some form of permanent state
2931 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2932 * cross-process fences) or it could just be a dummy for use internally.
2933 */
2934 struct anv_fence_impl permanent;
2935
2936 /* Temporary fence state. A fence *may* have temporary state. That state
2937 * is added to the fence by an import operation and is reset back to
2938 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2939 * state cannot be signaled because the fence must already be signaled
2940 * before the temporary state can be exported from the fence in the other
2941 * process and imported here.
2942 */
2943 struct anv_fence_impl temporary;
2944 };
2945
2946 void anv_fence_reset_temporary(struct anv_device *device,
2947 struct anv_fence *fence);
2948
2949 struct anv_event {
2950 uint64_t semaphore;
2951 struct anv_state state;
2952 };
2953
2954 enum anv_semaphore_type {
2955 ANV_SEMAPHORE_TYPE_NONE = 0,
2956 ANV_SEMAPHORE_TYPE_DUMMY,
2957 ANV_SEMAPHORE_TYPE_BO,
2958 ANV_SEMAPHORE_TYPE_WSI_BO,
2959 ANV_SEMAPHORE_TYPE_SYNC_FILE,
2960 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ,
2961 ANV_SEMAPHORE_TYPE_TIMELINE,
2962 };
2963
2964 struct anv_timeline_point {
2965 struct list_head link;
2966
2967 uint64_t serial;
2968
2969 /* Number of waiter on this point, when > 0 the point should not be garbage
2970 * collected.
2971 */
2972 int waiting;
2973
2974 /* BO used for synchronization. */
2975 struct anv_bo *bo;
2976 };
2977
2978 struct anv_timeline {
2979 pthread_mutex_t mutex;
2980 pthread_cond_t cond;
2981
2982 uint64_t highest_past;
2983 uint64_t highest_pending;
2984
2985 struct list_head points;
2986 struct list_head free_points;
2987 };
2988
2989 struct anv_semaphore_impl {
2990 enum anv_semaphore_type type;
2991
2992 union {
2993 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO
2994 * or type == ANV_SEMAPHORE_TYPE_WSI_BO. This BO will be added to the
2995 * object list on any execbuf2 calls for which this semaphore is used as
2996 * a wait or signal fence. When used as a signal fence or when type ==
2997 * ANV_SEMAPHORE_TYPE_WSI_BO, the EXEC_OBJECT_WRITE flag will be set.
2998 */
2999 struct anv_bo *bo;
3000
3001 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
3002 * If the semaphore is in the unsignaled state due to either just being
3003 * created or because it has been used for a wait, fd will be -1.
3004 */
3005 int fd;
3006
3007 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
3008 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
3009 * import so we don't need to bother with a userspace cache.
3010 */
3011 uint32_t syncobj;
3012
3013 /* Non shareable timeline semaphore
3014 *
3015 * Used when kernel don't have support for timeline semaphores.
3016 */
3017 struct anv_timeline timeline;
3018 };
3019 };
3020
3021 struct anv_semaphore {
3022 uint32_t refcount;
3023
3024 /* Permanent semaphore state. Every semaphore has some form of permanent
3025 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
3026 * (for cross-process semaphores0 or it could just be a dummy for use
3027 * internally.
3028 */
3029 struct anv_semaphore_impl permanent;
3030
3031 /* Temporary semaphore state. A semaphore *may* have temporary state.
3032 * That state is added to the semaphore by an import operation and is reset
3033 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
3034 * semaphore with temporary state cannot be signaled because the semaphore
3035 * must already be signaled before the temporary state can be exported from
3036 * the semaphore in the other process and imported here.
3037 */
3038 struct anv_semaphore_impl temporary;
3039 };
3040
3041 void anv_semaphore_reset_temporary(struct anv_device *device,
3042 struct anv_semaphore *semaphore);
3043
3044 struct anv_shader_module {
3045 unsigned char sha1[20];
3046 uint32_t size;
3047 char data[0];
3048 };
3049
3050 static inline gl_shader_stage
3051 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
3052 {
3053 assert(__builtin_popcount(vk_stage) == 1);
3054 return ffs(vk_stage) - 1;
3055 }
3056
3057 static inline VkShaderStageFlagBits
3058 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
3059 {
3060 return (1 << mesa_stage);
3061 }
3062
3063 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
3064
3065 #define anv_foreach_stage(stage, stage_bits) \
3066 for (gl_shader_stage stage, \
3067 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
3068 stage = __builtin_ffs(__tmp) - 1, __tmp; \
3069 __tmp &= ~(1 << (stage)))
3070
3071 struct anv_pipeline_bind_map {
3072 unsigned char surface_sha1[20];
3073 unsigned char sampler_sha1[20];
3074 unsigned char push_sha1[20];
3075
3076 uint32_t surface_count;
3077 uint32_t sampler_count;
3078
3079 struct anv_pipeline_binding * surface_to_descriptor;
3080 struct anv_pipeline_binding * sampler_to_descriptor;
3081
3082 struct anv_push_range push_ranges[4];
3083 };
3084
3085 struct anv_shader_bin_key {
3086 uint32_t size;
3087 uint8_t data[0];
3088 };
3089
3090 struct anv_shader_bin {
3091 uint32_t ref_cnt;
3092
3093 const struct anv_shader_bin_key *key;
3094
3095 struct anv_state kernel;
3096 uint32_t kernel_size;
3097
3098 struct anv_state constant_data;
3099 uint32_t constant_data_size;
3100
3101 const struct brw_stage_prog_data *prog_data;
3102 uint32_t prog_data_size;
3103
3104 struct brw_compile_stats stats[3];
3105 uint32_t num_stats;
3106
3107 struct nir_xfb_info *xfb_info;
3108
3109 struct anv_pipeline_bind_map bind_map;
3110 };
3111
3112 struct anv_shader_bin *
3113 anv_shader_bin_create(struct anv_device *device,
3114 const void *key, uint32_t key_size,
3115 const void *kernel, uint32_t kernel_size,
3116 const void *constant_data, uint32_t constant_data_size,
3117 const struct brw_stage_prog_data *prog_data,
3118 uint32_t prog_data_size, const void *prog_data_param,
3119 const struct brw_compile_stats *stats, uint32_t num_stats,
3120 const struct nir_xfb_info *xfb_info,
3121 const struct anv_pipeline_bind_map *bind_map);
3122
3123 void
3124 anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
3125
3126 static inline void
3127 anv_shader_bin_ref(struct anv_shader_bin *shader)
3128 {
3129 assert(shader && shader->ref_cnt >= 1);
3130 p_atomic_inc(&shader->ref_cnt);
3131 }
3132
3133 static inline void
3134 anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
3135 {
3136 assert(shader && shader->ref_cnt >= 1);
3137 if (p_atomic_dec_zero(&shader->ref_cnt))
3138 anv_shader_bin_destroy(device, shader);
3139 }
3140
3141 /* 5 possible simultaneous shader stages and FS may have up to 3 binaries */
3142 #define MAX_PIPELINE_EXECUTABLES 7
3143
3144 struct anv_pipeline_executable {
3145 gl_shader_stage stage;
3146
3147 struct brw_compile_stats stats;
3148
3149 char *nir;
3150 char *disasm;
3151 };
3152
3153 struct anv_pipeline {
3154 struct anv_device * device;
3155 struct anv_batch batch;
3156 uint32_t batch_data[512];
3157 struct anv_reloc_list batch_relocs;
3158 anv_cmd_dirty_mask_t dynamic_state_mask;
3159 struct anv_dynamic_state dynamic_state;
3160
3161 void * mem_ctx;
3162
3163 VkPipelineCreateFlags flags;
3164 struct anv_subpass * subpass;
3165
3166 struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
3167
3168 uint32_t num_executables;
3169 struct anv_pipeline_executable executables[MAX_PIPELINE_EXECUTABLES];
3170
3171 const struct gen_l3_config * l3_config;
3172
3173 VkShaderStageFlags active_stages;
3174 struct anv_state blend_state;
3175
3176 uint32_t vb_used;
3177 struct anv_pipeline_vertex_binding {
3178 uint32_t stride;
3179 bool instanced;
3180 uint32_t instance_divisor;
3181 } vb[MAX_VBS];
3182
3183 bool primitive_restart;
3184 uint32_t topology;
3185
3186 uint32_t cs_right_mask;
3187
3188 bool writes_depth;
3189 bool depth_test_enable;
3190 bool writes_stencil;
3191 bool stencil_test_enable;
3192 bool depth_clamp_enable;
3193 bool depth_clip_enable;
3194 bool sample_shading_enable;
3195 bool kill_pixel;
3196 bool depth_bounds_test_enable;
3197
3198 struct {
3199 uint32_t sf[7];
3200 uint32_t depth_stencil_state[3];
3201 } gen7;
3202
3203 struct {
3204 uint32_t sf[4];
3205 uint32_t raster[5];
3206 uint32_t wm_depth_stencil[3];
3207 } gen8;
3208
3209 struct {
3210 uint32_t wm_depth_stencil[4];
3211 } gen9;
3212
3213 uint32_t interface_descriptor_data[8];
3214 };
3215
3216 static inline bool
3217 anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
3218 gl_shader_stage stage)
3219 {
3220 return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
3221 }
3222
3223 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
3224 static inline const struct brw_##prefix##_prog_data * \
3225 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
3226 { \
3227 if (anv_pipeline_has_stage(pipeline, stage)) { \
3228 return (const struct brw_##prefix##_prog_data *) \
3229 pipeline->shaders[stage]->prog_data; \
3230 } else { \
3231 return NULL; \
3232 } \
3233 }
3234
3235 ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
3236 ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
3237 ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
3238 ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
3239 ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
3240 ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
3241
3242 static inline const struct brw_vue_prog_data *
3243 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
3244 {
3245 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
3246 return &get_gs_prog_data(pipeline)->base;
3247 else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
3248 return &get_tes_prog_data(pipeline)->base;
3249 else
3250 return &get_vs_prog_data(pipeline)->base;
3251 }
3252
3253 VkResult
3254 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
3255 struct anv_pipeline_cache *cache,
3256 const VkGraphicsPipelineCreateInfo *pCreateInfo,
3257 const VkAllocationCallbacks *alloc);
3258
3259 VkResult
3260 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
3261 struct anv_pipeline_cache *cache,
3262 const VkComputePipelineCreateInfo *info,
3263 const struct anv_shader_module *module,
3264 const char *entrypoint,
3265 const VkSpecializationInfo *spec_info);
3266
3267 struct anv_format_plane {
3268 enum isl_format isl_format:16;
3269 struct isl_swizzle swizzle;
3270
3271 /* Whether this plane contains chroma channels */
3272 bool has_chroma;
3273
3274 /* For downscaling of YUV planes */
3275 uint8_t denominator_scales[2];
3276
3277 /* How to map sampled ycbcr planes to a single 4 component element. */
3278 struct isl_swizzle ycbcr_swizzle;
3279
3280 /* What aspect is associated to this plane */
3281 VkImageAspectFlags aspect;
3282 };
3283
3284
3285 struct anv_format {
3286 struct anv_format_plane planes[3];
3287 VkFormat vk_format;
3288 uint8_t n_planes;
3289 bool can_ycbcr;
3290 };
3291
3292 /**
3293 * Return the aspect's _format_ plane, not its _memory_ plane (using the
3294 * vocabulary of VK_EXT_image_drm_format_modifier). As a consequence, \a
3295 * aspect_mask may contain VK_IMAGE_ASPECT_PLANE_*, but must not contain
3296 * VK_IMAGE_ASPECT_MEMORY_PLANE_* .
3297 */
3298 static inline uint32_t
3299 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects,
3300 VkImageAspectFlags aspect_mask)
3301 {
3302 switch (aspect_mask) {
3303 case VK_IMAGE_ASPECT_COLOR_BIT:
3304 case VK_IMAGE_ASPECT_DEPTH_BIT:
3305 case VK_IMAGE_ASPECT_PLANE_0_BIT:
3306 return 0;
3307 case VK_IMAGE_ASPECT_STENCIL_BIT:
3308 if ((image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) == 0)
3309 return 0;
3310 /* Fall-through */
3311 case VK_IMAGE_ASPECT_PLANE_1_BIT:
3312 return 1;
3313 case VK_IMAGE_ASPECT_PLANE_2_BIT:
3314 return 2;
3315 default:
3316 /* Purposefully assert with depth/stencil aspects. */
3317 unreachable("invalid image aspect");
3318 }
3319 }
3320
3321 static inline VkImageAspectFlags
3322 anv_plane_to_aspect(VkImageAspectFlags image_aspects,
3323 uint32_t plane)
3324 {
3325 if (image_aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) {
3326 if (util_bitcount(image_aspects) > 1)
3327 return VK_IMAGE_ASPECT_PLANE_0_BIT << plane;
3328 return VK_IMAGE_ASPECT_COLOR_BIT;
3329 }
3330 if (image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT)
3331 return VK_IMAGE_ASPECT_DEPTH_BIT << plane;
3332 assert(image_aspects == VK_IMAGE_ASPECT_STENCIL_BIT);
3333 return VK_IMAGE_ASPECT_STENCIL_BIT;
3334 }
3335
3336 #define anv_foreach_image_aspect_bit(b, image, aspects) \
3337 for_each_bit(b, anv_image_expand_aspects(image, aspects))
3338
3339 const struct anv_format *
3340 anv_get_format(VkFormat format);
3341
3342 static inline uint32_t
3343 anv_get_format_planes(VkFormat vk_format)
3344 {
3345 const struct anv_format *format = anv_get_format(vk_format);
3346
3347 return format != NULL ? format->n_planes : 0;
3348 }
3349
3350 struct anv_format_plane
3351 anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
3352 VkImageAspectFlagBits aspect, VkImageTiling tiling);
3353
3354 static inline enum isl_format
3355 anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
3356 VkImageAspectFlags aspect, VkImageTiling tiling)
3357 {
3358 return anv_get_format_plane(devinfo, vk_format, aspect, tiling).isl_format;
3359 }
3360
3361 bool anv_formats_ccs_e_compatible(const struct gen_device_info *devinfo,
3362 VkImageCreateFlags create_flags,
3363 VkFormat vk_format,
3364 VkImageTiling vk_tiling,
3365 const VkImageFormatListCreateInfoKHR *fmt_list);
3366
3367 static inline struct isl_swizzle
3368 anv_swizzle_for_render(struct isl_swizzle swizzle)
3369 {
3370 /* Sometimes the swizzle will have alpha map to one. We do this to fake
3371 * RGB as RGBA for texturing
3372 */
3373 assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
3374 swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
3375
3376 /* But it doesn't matter what we render to that channel */
3377 swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
3378
3379 return swizzle;
3380 }
3381
3382 void
3383 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
3384
3385 /**
3386 * Subsurface of an anv_image.
3387 */
3388 struct anv_surface {
3389 /** Valid only if isl_surf::size_B > 0. */
3390 struct isl_surf isl;
3391
3392 /**
3393 * Offset from VkImage's base address, as bound by vkBindImageMemory().
3394 */
3395 uint32_t offset;
3396 };
3397
3398 struct anv_image {
3399 VkImageType type; /**< VkImageCreateInfo::imageType */
3400 /* The original VkFormat provided by the client. This may not match any
3401 * of the actual surface formats.
3402 */
3403 VkFormat vk_format;
3404 const struct anv_format *format;
3405
3406 VkImageAspectFlags aspects;
3407 VkExtent3D extent;
3408 uint32_t levels;
3409 uint32_t array_size;
3410 uint32_t samples; /**< VkImageCreateInfo::samples */
3411 uint32_t n_planes;
3412 VkImageUsageFlags usage; /**< VkImageCreateInfo::usage. */
3413 VkImageUsageFlags stencil_usage;
3414 VkImageCreateFlags create_flags; /* Flags used when creating image. */
3415 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
3416
3417 /** True if this is needs to be bound to an appropriately tiled BO.
3418 *
3419 * When not using modifiers, consumers such as X11, Wayland, and KMS need
3420 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
3421 * we require a dedicated allocation so that we can know to allocate a
3422 * tiled buffer.
3423 */
3424 bool needs_set_tiling;
3425
3426 /**
3427 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
3428 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
3429 */
3430 uint64_t drm_format_mod;
3431
3432 VkDeviceSize size;
3433 uint32_t alignment;
3434
3435 /* Whether the image is made of several underlying buffer objects rather a
3436 * single one with different offsets.
3437 */
3438 bool disjoint;
3439
3440 /* Image was created with external format. */
3441 bool external_format;
3442
3443 /**
3444 * Image subsurfaces
3445 *
3446 * For each foo, anv_image::planes[x].surface is valid if and only if
3447 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
3448 * to figure the number associated with a given aspect.
3449 *
3450 * The hardware requires that the depth buffer and stencil buffer be
3451 * separate surfaces. From Vulkan's perspective, though, depth and stencil
3452 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
3453 * allocate the depth and stencil buffers as separate surfaces in the same
3454 * bo.
3455 *
3456 * Memory layout :
3457 *
3458 * -----------------------
3459 * | surface0 | /|\
3460 * ----------------------- |
3461 * | shadow surface0 | |
3462 * ----------------------- | Plane 0
3463 * | aux surface0 | |
3464 * ----------------------- |
3465 * | fast clear colors0 | \|/
3466 * -----------------------
3467 * | surface1 | /|\
3468 * ----------------------- |
3469 * | shadow surface1 | |
3470 * ----------------------- | Plane 1
3471 * | aux surface1 | |
3472 * ----------------------- |
3473 * | fast clear colors1 | \|/
3474 * -----------------------
3475 * | ... |
3476 * | |
3477 * -----------------------
3478 */
3479 struct {
3480 /**
3481 * Offset of the entire plane (whenever the image is disjoint this is
3482 * set to 0).
3483 */
3484 uint32_t offset;
3485
3486 VkDeviceSize size;
3487 uint32_t alignment;
3488
3489 struct anv_surface surface;
3490
3491 /**
3492 * A surface which shadows the main surface and may have different
3493 * tiling. This is used for sampling using a tiling that isn't supported
3494 * for other operations.
3495 */
3496 struct anv_surface shadow_surface;
3497
3498 /**
3499 * The base aux usage for this image. For color images, this can be
3500 * either CCS_E or CCS_D depending on whether or not we can reliably
3501 * leave CCS on all the time.
3502 */
3503 enum isl_aux_usage aux_usage;
3504
3505 struct anv_surface aux_surface;
3506
3507 /**
3508 * Offset of the fast clear state (used to compute the
3509 * fast_clear_state_offset of the following planes).
3510 */
3511 uint32_t fast_clear_state_offset;
3512
3513 /**
3514 * BO associated with this plane, set when bound.
3515 */
3516 struct anv_address address;
3517
3518 /**
3519 * When destroying the image, also free the bo.
3520 * */
3521 bool bo_is_owned;
3522 } planes[3];
3523 };
3524
3525 /* The ordering of this enum is important */
3526 enum anv_fast_clear_type {
3527 /** Image does not have/support any fast-clear blocks */
3528 ANV_FAST_CLEAR_NONE = 0,
3529 /** Image has/supports fast-clear but only to the default value */
3530 ANV_FAST_CLEAR_DEFAULT_VALUE = 1,
3531 /** Image has/supports fast-clear with an arbitrary fast-clear value */
3532 ANV_FAST_CLEAR_ANY = 2,
3533 };
3534
3535 /* Returns the number of auxiliary buffer levels attached to an image. */
3536 static inline uint8_t
3537 anv_image_aux_levels(const struct anv_image * const image,
3538 VkImageAspectFlagBits aspect)
3539 {
3540 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3541 if (image->planes[plane].aux_usage == ISL_AUX_USAGE_NONE)
3542 return 0;
3543
3544 /* The Gen12 CCS aux surface is represented with only one level. */
3545 return image->planes[plane].aux_surface.isl.tiling == ISL_TILING_GEN12_CCS ?
3546 image->planes[plane].surface.isl.levels :
3547 image->planes[plane].aux_surface.isl.levels;
3548 }
3549
3550 /* Returns the number of auxiliary buffer layers attached to an image. */
3551 static inline uint32_t
3552 anv_image_aux_layers(const struct anv_image * const image,
3553 VkImageAspectFlagBits aspect,
3554 const uint8_t miplevel)
3555 {
3556 assert(image);
3557
3558 /* The miplevel must exist in the main buffer. */
3559 assert(miplevel < image->levels);
3560
3561 if (miplevel >= anv_image_aux_levels(image, aspect)) {
3562 /* There are no layers with auxiliary data because the miplevel has no
3563 * auxiliary data.
3564 */
3565 return 0;
3566 } else {
3567 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3568
3569 /* The Gen12 CCS aux surface is represented with only one layer. */
3570 const struct isl_extent4d *aux_logical_level0_px =
3571 image->planes[plane].aux_surface.isl.tiling == ISL_TILING_GEN12_CCS ?
3572 &image->planes[plane].surface.isl.logical_level0_px :
3573 &image->planes[plane].aux_surface.isl.logical_level0_px;
3574
3575 return MAX2(aux_logical_level0_px->array_len,
3576 aux_logical_level0_px->depth >> miplevel);
3577 }
3578 }
3579
3580 static inline struct anv_address
3581 anv_image_get_clear_color_addr(const struct anv_device *device,
3582 const struct anv_image *image,
3583 VkImageAspectFlagBits aspect)
3584 {
3585 assert(image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV);
3586
3587 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3588 return anv_address_add(image->planes[plane].address,
3589 image->planes[plane].fast_clear_state_offset);
3590 }
3591
3592 static inline struct anv_address
3593 anv_image_get_fast_clear_type_addr(const struct anv_device *device,
3594 const struct anv_image *image,
3595 VkImageAspectFlagBits aspect)
3596 {
3597 struct anv_address addr =
3598 anv_image_get_clear_color_addr(device, image, aspect);
3599
3600 const unsigned clear_color_state_size = device->info.gen >= 10 ?
3601 device->isl_dev.ss.clear_color_state_size :
3602 device->isl_dev.ss.clear_value_size;
3603 return anv_address_add(addr, clear_color_state_size);
3604 }
3605
3606 static inline struct anv_address
3607 anv_image_get_compression_state_addr(const struct anv_device *device,
3608 const struct anv_image *image,
3609 VkImageAspectFlagBits aspect,
3610 uint32_t level, uint32_t array_layer)
3611 {
3612 assert(level < anv_image_aux_levels(image, aspect));
3613 assert(array_layer < anv_image_aux_layers(image, aspect, level));
3614 UNUSED uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3615 assert(image->planes[plane].aux_usage == ISL_AUX_USAGE_CCS_E);
3616
3617 struct anv_address addr =
3618 anv_image_get_fast_clear_type_addr(device, image, aspect);
3619 addr.offset += 4; /* Go past the fast clear type */
3620
3621 if (image->type == VK_IMAGE_TYPE_3D) {
3622 for (uint32_t l = 0; l < level; l++)
3623 addr.offset += anv_minify(image->extent.depth, l) * 4;
3624 } else {
3625 addr.offset += level * image->array_size * 4;
3626 }
3627 addr.offset += array_layer * 4;
3628
3629 assert(addr.offset <
3630 image->planes[plane].address.offset + image->planes[plane].size);
3631 return addr;
3632 }
3633
3634 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
3635 static inline bool
3636 anv_can_sample_with_hiz(const struct gen_device_info * const devinfo,
3637 const struct anv_image *image)
3638 {
3639 if (!(image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT))
3640 return false;
3641
3642 /* Allow this feature on BDW even though it is disabled in the BDW devinfo
3643 * struct. There's documentation which suggests that this feature actually
3644 * reduces performance on BDW, but it has only been observed to help so
3645 * far. Sampling fast-cleared blocks on BDW must also be handled with care
3646 * (see depth_stencil_attachment_compute_aux_usage() for more info).
3647 */
3648 if (devinfo->gen != 8 && !devinfo->has_sample_with_hiz)
3649 return false;
3650
3651 return image->samples == 1;
3652 }
3653
3654 static inline bool
3655 anv_image_plane_uses_aux_map(const struct anv_device *device,
3656 const struct anv_image *image,
3657 uint32_t plane)
3658 {
3659 return device->info.has_aux_map &&
3660 isl_aux_usage_has_ccs(image->planes[plane].aux_usage);
3661 }
3662
3663 void
3664 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer *cmd_buffer,
3665 const struct anv_image *image,
3666 VkImageAspectFlagBits aspect,
3667 enum isl_aux_usage aux_usage,
3668 uint32_t level,
3669 uint32_t base_layer,
3670 uint32_t layer_count);
3671
3672 void
3673 anv_image_clear_color(struct anv_cmd_buffer *cmd_buffer,
3674 const struct anv_image *image,
3675 VkImageAspectFlagBits aspect,
3676 enum isl_aux_usage aux_usage,
3677 enum isl_format format, struct isl_swizzle swizzle,
3678 uint32_t level, uint32_t base_layer, uint32_t layer_count,
3679 VkRect2D area, union isl_color_value clear_color);
3680 void
3681 anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
3682 const struct anv_image *image,
3683 VkImageAspectFlags aspects,
3684 enum isl_aux_usage depth_aux_usage,
3685 uint32_t level,
3686 uint32_t base_layer, uint32_t layer_count,
3687 VkRect2D area,
3688 float depth_value, uint8_t stencil_value);
3689 void
3690 anv_image_msaa_resolve(struct anv_cmd_buffer *cmd_buffer,
3691 const struct anv_image *src_image,
3692 enum isl_aux_usage src_aux_usage,
3693 uint32_t src_level, uint32_t src_base_layer,
3694 const struct anv_image *dst_image,
3695 enum isl_aux_usage dst_aux_usage,
3696 uint32_t dst_level, uint32_t dst_base_layer,
3697 VkImageAspectFlagBits aspect,
3698 uint32_t src_x, uint32_t src_y,
3699 uint32_t dst_x, uint32_t dst_y,
3700 uint32_t width, uint32_t height,
3701 uint32_t layer_count,
3702 enum blorp_filter filter);
3703 void
3704 anv_image_hiz_op(struct anv_cmd_buffer *cmd_buffer,
3705 const struct anv_image *image,
3706 VkImageAspectFlagBits aspect, uint32_t level,
3707 uint32_t base_layer, uint32_t layer_count,
3708 enum isl_aux_op hiz_op);
3709 void
3710 anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
3711 const struct anv_image *image,
3712 VkImageAspectFlags aspects,
3713 uint32_t level,
3714 uint32_t base_layer, uint32_t layer_count,
3715 VkRect2D area, uint8_t stencil_value);
3716 void
3717 anv_image_mcs_op(struct anv_cmd_buffer *cmd_buffer,
3718 const struct anv_image *image,
3719 enum isl_format format,
3720 VkImageAspectFlagBits aspect,
3721 uint32_t base_layer, uint32_t layer_count,
3722 enum isl_aux_op mcs_op, union isl_color_value *clear_value,
3723 bool predicate);
3724 void
3725 anv_image_ccs_op(struct anv_cmd_buffer *cmd_buffer,
3726 const struct anv_image *image,
3727 enum isl_format format,
3728 VkImageAspectFlagBits aspect, uint32_t level,
3729 uint32_t base_layer, uint32_t layer_count,
3730 enum isl_aux_op ccs_op, union isl_color_value *clear_value,
3731 bool predicate);
3732
3733 void
3734 anv_image_copy_to_shadow(struct anv_cmd_buffer *cmd_buffer,
3735 const struct anv_image *image,
3736 VkImageAspectFlagBits aspect,
3737 uint32_t base_level, uint32_t level_count,
3738 uint32_t base_layer, uint32_t layer_count);
3739
3740 enum isl_aux_state
3741 anv_layout_to_aux_state(const struct gen_device_info * const devinfo,
3742 const struct anv_image *image,
3743 const VkImageAspectFlagBits aspect,
3744 const VkImageLayout layout);
3745
3746 enum isl_aux_usage
3747 anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
3748 const struct anv_image *image,
3749 const VkImageAspectFlagBits aspect,
3750 const VkImageUsageFlagBits usage,
3751 const VkImageLayout layout);
3752
3753 enum anv_fast_clear_type
3754 anv_layout_to_fast_clear_type(const struct gen_device_info * const devinfo,
3755 const struct anv_image * const image,
3756 const VkImageAspectFlagBits aspect,
3757 const VkImageLayout layout);
3758
3759 /* This is defined as a macro so that it works for both
3760 * VkImageSubresourceRange and VkImageSubresourceLayers
3761 */
3762 #define anv_get_layerCount(_image, _range) \
3763 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
3764 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
3765
3766 static inline uint32_t
3767 anv_get_levelCount(const struct anv_image *image,
3768 const VkImageSubresourceRange *range)
3769 {
3770 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
3771 image->levels - range->baseMipLevel : range->levelCount;
3772 }
3773
3774 static inline VkImageAspectFlags
3775 anv_image_expand_aspects(const struct anv_image *image,
3776 VkImageAspectFlags aspects)
3777 {
3778 /* If the underlying image has color plane aspects and
3779 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
3780 * the underlying image. */
3781 if ((image->aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) != 0 &&
3782 aspects == VK_IMAGE_ASPECT_COLOR_BIT)
3783 return image->aspects;
3784
3785 return aspects;
3786 }
3787
3788 static inline bool
3789 anv_image_aspects_compatible(VkImageAspectFlags aspects1,
3790 VkImageAspectFlags aspects2)
3791 {
3792 if (aspects1 == aspects2)
3793 return true;
3794
3795 /* Only 1 color aspects are compatibles. */
3796 if ((aspects1 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
3797 (aspects2 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
3798 util_bitcount(aspects1) == util_bitcount(aspects2))
3799 return true;
3800
3801 return false;
3802 }
3803
3804 struct anv_image_view {
3805 const struct anv_image *image; /**< VkImageViewCreateInfo::image */
3806
3807 VkImageAspectFlags aspect_mask;
3808 VkFormat vk_format;
3809 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
3810
3811 unsigned n_planes;
3812 struct {
3813 uint32_t image_plane;
3814
3815 struct isl_view isl;
3816
3817 /**
3818 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3819 * image layout of SHADER_READ_ONLY_OPTIMAL or
3820 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
3821 */
3822 struct anv_surface_state optimal_sampler_surface_state;
3823
3824 /**
3825 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3826 * image layout of GENERAL.
3827 */
3828 struct anv_surface_state general_sampler_surface_state;
3829
3830 /**
3831 * RENDER_SURFACE_STATE when using image as a storage image. Separate
3832 * states for write-only and readable, using the real format for
3833 * write-only and the lowered format for readable.
3834 */
3835 struct anv_surface_state storage_surface_state;
3836 struct anv_surface_state writeonly_storage_surface_state;
3837
3838 struct brw_image_param storage_image_param;
3839 } planes[3];
3840 };
3841
3842 enum anv_image_view_state_flags {
3843 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY = (1 << 0),
3844 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL = (1 << 1),
3845 };
3846
3847 void anv_image_fill_surface_state(struct anv_device *device,
3848 const struct anv_image *image,
3849 VkImageAspectFlagBits aspect,
3850 const struct isl_view *view,
3851 isl_surf_usage_flags_t view_usage,
3852 enum isl_aux_usage aux_usage,
3853 const union isl_color_value *clear_color,
3854 enum anv_image_view_state_flags flags,
3855 struct anv_surface_state *state_inout,
3856 struct brw_image_param *image_param_out);
3857
3858 struct anv_image_create_info {
3859 const VkImageCreateInfo *vk_info;
3860
3861 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
3862 isl_tiling_flags_t isl_tiling_flags;
3863
3864 /** These flags will be added to any derived from VkImageCreateInfo. */
3865 isl_surf_usage_flags_t isl_extra_usage_flags;
3866
3867 uint32_t stride;
3868 bool external_format;
3869 };
3870
3871 VkResult anv_image_create(VkDevice _device,
3872 const struct anv_image_create_info *info,
3873 const VkAllocationCallbacks* alloc,
3874 VkImage *pImage);
3875
3876 enum isl_format
3877 anv_isl_format_for_descriptor_type(VkDescriptorType type);
3878
3879 static inline VkExtent3D
3880 anv_sanitize_image_extent(const VkImageType imageType,
3881 const VkExtent3D imageExtent)
3882 {
3883 switch (imageType) {
3884 case VK_IMAGE_TYPE_1D:
3885 return (VkExtent3D) { imageExtent.width, 1, 1 };
3886 case VK_IMAGE_TYPE_2D:
3887 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
3888 case VK_IMAGE_TYPE_3D:
3889 return imageExtent;
3890 default:
3891 unreachable("invalid image type");
3892 }
3893 }
3894
3895 static inline VkOffset3D
3896 anv_sanitize_image_offset(const VkImageType imageType,
3897 const VkOffset3D imageOffset)
3898 {
3899 switch (imageType) {
3900 case VK_IMAGE_TYPE_1D:
3901 return (VkOffset3D) { imageOffset.x, 0, 0 };
3902 case VK_IMAGE_TYPE_2D:
3903 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
3904 case VK_IMAGE_TYPE_3D:
3905 return imageOffset;
3906 default:
3907 unreachable("invalid image type");
3908 }
3909 }
3910
3911 VkFormatFeatureFlags
3912 anv_get_image_format_features(const struct gen_device_info *devinfo,
3913 VkFormat vk_format,
3914 const struct anv_format *anv_format,
3915 VkImageTiling vk_tiling);
3916
3917 void anv_fill_buffer_surface_state(struct anv_device *device,
3918 struct anv_state state,
3919 enum isl_format format,
3920 struct anv_address address,
3921 uint32_t range, uint32_t stride);
3922
3923 static inline void
3924 anv_clear_color_from_att_state(union isl_color_value *clear_color,
3925 const struct anv_attachment_state *att_state,
3926 const struct anv_image_view *iview)
3927 {
3928 const struct isl_format_layout *view_fmtl =
3929 isl_format_get_layout(iview->planes[0].isl.format);
3930
3931 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
3932 if (view_fmtl->channels.c.bits) \
3933 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
3934
3935 COPY_CLEAR_COLOR_CHANNEL(r, 0);
3936 COPY_CLEAR_COLOR_CHANNEL(g, 1);
3937 COPY_CLEAR_COLOR_CHANNEL(b, 2);
3938 COPY_CLEAR_COLOR_CHANNEL(a, 3);
3939
3940 #undef COPY_CLEAR_COLOR_CHANNEL
3941 }
3942
3943
3944 struct anv_ycbcr_conversion {
3945 const struct anv_format * format;
3946 VkSamplerYcbcrModelConversion ycbcr_model;
3947 VkSamplerYcbcrRange ycbcr_range;
3948 VkComponentSwizzle mapping[4];
3949 VkChromaLocation chroma_offsets[2];
3950 VkFilter chroma_filter;
3951 bool chroma_reconstruction;
3952 };
3953
3954 struct anv_sampler {
3955 uint32_t state[3][4];
3956 uint32_t n_planes;
3957 struct anv_ycbcr_conversion *conversion;
3958
3959 /* Blob of sampler state data which is guaranteed to be 32-byte aligned
3960 * and with a 32-byte stride for use as bindless samplers.
3961 */
3962 struct anv_state bindless_state;
3963 };
3964
3965 struct anv_framebuffer {
3966 uint32_t width;
3967 uint32_t height;
3968 uint32_t layers;
3969
3970 uint32_t attachment_count;
3971 struct anv_image_view * attachments[0];
3972 };
3973
3974 struct anv_subpass_attachment {
3975 VkImageUsageFlagBits usage;
3976 uint32_t attachment;
3977 VkImageLayout layout;
3978
3979 /* Used only with attachment containing stencil data. */
3980 VkImageLayout stencil_layout;
3981 };
3982
3983 struct anv_subpass {
3984 uint32_t attachment_count;
3985
3986 /**
3987 * A pointer to all attachment references used in this subpass.
3988 * Only valid if ::attachment_count > 0.
3989 */
3990 struct anv_subpass_attachment * attachments;
3991 uint32_t input_count;
3992 struct anv_subpass_attachment * input_attachments;
3993 uint32_t color_count;
3994 struct anv_subpass_attachment * color_attachments;
3995 struct anv_subpass_attachment * resolve_attachments;
3996
3997 struct anv_subpass_attachment * depth_stencil_attachment;
3998 struct anv_subpass_attachment * ds_resolve_attachment;
3999 VkResolveModeFlagBitsKHR depth_resolve_mode;
4000 VkResolveModeFlagBitsKHR stencil_resolve_mode;
4001
4002 uint32_t view_mask;
4003
4004 /** Subpass has a depth/stencil self-dependency */
4005 bool has_ds_self_dep;
4006
4007 /** Subpass has at least one color resolve attachment */
4008 bool has_color_resolve;
4009 };
4010
4011 static inline unsigned
4012 anv_subpass_view_count(const struct anv_subpass *subpass)
4013 {
4014 return MAX2(1, util_bitcount(subpass->view_mask));
4015 }
4016
4017 struct anv_render_pass_attachment {
4018 /* TODO: Consider using VkAttachmentDescription instead of storing each of
4019 * its members individually.
4020 */
4021 VkFormat format;
4022 uint32_t samples;
4023 VkImageUsageFlags usage;
4024 VkAttachmentLoadOp load_op;
4025 VkAttachmentStoreOp store_op;
4026 VkAttachmentLoadOp stencil_load_op;
4027 VkImageLayout initial_layout;
4028 VkImageLayout final_layout;
4029 VkImageLayout first_subpass_layout;
4030
4031 VkImageLayout stencil_initial_layout;
4032 VkImageLayout stencil_final_layout;
4033
4034 /* The subpass id in which the attachment will be used last. */
4035 uint32_t last_subpass_idx;
4036 };
4037
4038 struct anv_render_pass {
4039 uint32_t attachment_count;
4040 uint32_t subpass_count;
4041 /* An array of subpass_count+1 flushes, one per subpass boundary */
4042 enum anv_pipe_bits * subpass_flushes;
4043 struct anv_render_pass_attachment * attachments;
4044 struct anv_subpass subpasses[0];
4045 };
4046
4047 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
4048
4049 struct anv_query_pool {
4050 VkQueryType type;
4051 VkQueryPipelineStatisticFlags pipeline_statistics;
4052 /** Stride between slots, in bytes */
4053 uint32_t stride;
4054 /** Number of slots in this query pool */
4055 uint32_t slots;
4056 struct anv_bo * bo;
4057 };
4058
4059 int anv_get_instance_entrypoint_index(const char *name);
4060 int anv_get_device_entrypoint_index(const char *name);
4061 int anv_get_physical_device_entrypoint_index(const char *name);
4062
4063 const char *anv_get_instance_entry_name(int index);
4064 const char *anv_get_physical_device_entry_name(int index);
4065 const char *anv_get_device_entry_name(int index);
4066
4067 bool
4068 anv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
4069 const struct anv_instance_extension_table *instance);
4070 bool
4071 anv_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
4072 const struct anv_instance_extension_table *instance);
4073 bool
4074 anv_device_entrypoint_is_enabled(int index, uint32_t core_version,
4075 const struct anv_instance_extension_table *instance,
4076 const struct anv_device_extension_table *device);
4077
4078 void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
4079 const char *name);
4080
4081 void anv_dump_image_to_ppm(struct anv_device *device,
4082 struct anv_image *image, unsigned miplevel,
4083 unsigned array_layer, VkImageAspectFlagBits aspect,
4084 const char *filename);
4085
4086 enum anv_dump_action {
4087 ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
4088 };
4089
4090 void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
4091 void anv_dump_finish(void);
4092
4093 void anv_dump_add_attachments(struct anv_cmd_buffer *cmd_buffer);
4094
4095 static inline uint32_t
4096 anv_get_subpass_id(const struct anv_cmd_state * const cmd_state)
4097 {
4098 /* This function must be called from within a subpass. */
4099 assert(cmd_state->pass && cmd_state->subpass);
4100
4101 const uint32_t subpass_id = cmd_state->subpass - cmd_state->pass->subpasses;
4102
4103 /* The id of this subpass shouldn't exceed the number of subpasses in this
4104 * render pass minus 1.
4105 */
4106 assert(subpass_id < cmd_state->pass->subpass_count);
4107 return subpass_id;
4108 }
4109
4110 struct gen_perf_config *anv_get_perf(const struct gen_device_info *devinfo, int fd);
4111 void anv_device_perf_init(struct anv_device *device);
4112
4113 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
4114 \
4115 static inline struct __anv_type * \
4116 __anv_type ## _from_handle(__VkType _handle) \
4117 { \
4118 return (struct __anv_type *) _handle; \
4119 } \
4120 \
4121 static inline __VkType \
4122 __anv_type ## _to_handle(struct __anv_type *_obj) \
4123 { \
4124 return (__VkType) _obj; \
4125 }
4126
4127 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
4128 \
4129 static inline struct __anv_type * \
4130 __anv_type ## _from_handle(__VkType _handle) \
4131 { \
4132 return (struct __anv_type *)(uintptr_t) _handle; \
4133 } \
4134 \
4135 static inline __VkType \
4136 __anv_type ## _to_handle(struct __anv_type *_obj) \
4137 { \
4138 return (__VkType)(uintptr_t) _obj; \
4139 }
4140
4141 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
4142 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
4143
4144 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
4145 ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
4146 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
4147 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
4148 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
4149
4150 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
4151 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
4152 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
4153 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
4154 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
4155 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
4156 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplate)
4157 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
4158 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
4159 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
4160 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
4161 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
4162 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
4163 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
4164 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
4165 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
4166 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
4167 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
4168 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
4169 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore, VkSemaphore)
4170 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
4171 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback, VkDebugReportCallbackEXT)
4172 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion, VkSamplerYcbcrConversion)
4173
4174 /* Gen-specific function declarations */
4175 #ifdef genX
4176 # include "anv_genX.h"
4177 #else
4178 # define genX(x) gen7_##x
4179 # include "anv_genX.h"
4180 # undef genX
4181 # define genX(x) gen75_##x
4182 # include "anv_genX.h"
4183 # undef genX
4184 # define genX(x) gen8_##x
4185 # include "anv_genX.h"
4186 # undef genX
4187 # define genX(x) gen9_##x
4188 # include "anv_genX.h"
4189 # undef genX
4190 # define genX(x) gen10_##x
4191 # include "anv_genX.h"
4192 # undef genX
4193 # define genX(x) gen11_##x
4194 # include "anv_genX.h"
4195 # undef genX
4196 # define genX(x) gen12_##x
4197 # include "anv_genX.h"
4198 # undef genX
4199 #endif
4200
4201 #endif /* ANV_PRIVATE_H */