anv/gem: Add support for syncobj wait and reset
[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 <i915_drm.h>
34
35 #ifdef HAVE_VALGRIND
36 #include <valgrind.h>
37 #include <memcheck.h>
38 #define VG(x) x
39 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
40 #else
41 #define VG(x)
42 #endif
43
44 #include "common/gen_clflush.h"
45 #include "common/gen_device_info.h"
46 #include "blorp/blorp.h"
47 #include "compiler/brw_compiler.h"
48 #include "util/macros.h"
49 #include "util/list.h"
50 #include "util/u_atomic.h"
51 #include "util/u_vector.h"
52 #include "vk_alloc.h"
53
54 /* Pre-declarations needed for WSI entrypoints */
55 struct wl_surface;
56 struct wl_display;
57 typedef struct xcb_connection_t xcb_connection_t;
58 typedef uint32_t xcb_visualid_t;
59 typedef uint32_t xcb_window_t;
60
61 struct anv_buffer;
62 struct anv_buffer_view;
63 struct anv_image_view;
64
65 struct gen_l3_config;
66
67 #include <vulkan/vulkan.h>
68 #include <vulkan/vulkan_intel.h>
69 #include <vulkan/vk_icd.h>
70
71 #include "anv_entrypoints.h"
72 #include "isl/isl.h"
73
74 #include "common/gen_debug.h"
75 #include "wsi_common.h"
76
77 /* Allowing different clear colors requires us to perform a depth resolve at
78 * the end of certain render passes. This is because while slow clears store
79 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
80 * See the PRMs for examples describing when additional resolves would be
81 * necessary. To enable fast clears without requiring extra resolves, we set
82 * the clear value to a globally-defined one. We could allow different values
83 * if the user doesn't expect coherent data during or after a render passes
84 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
85 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
86 * 1.0f seems to be the only value used. The only application that doesn't set
87 * this value does so through the usage of an seemingly uninitialized clear
88 * value.
89 */
90 #define ANV_HZ_FC_VAL 1.0f
91
92 #define MAX_VBS 28
93 #define MAX_SETS 8
94 #define MAX_RTS 8
95 #define MAX_VIEWPORTS 16
96 #define MAX_SCISSORS 16
97 #define MAX_PUSH_CONSTANTS_SIZE 128
98 #define MAX_DYNAMIC_BUFFERS 16
99 #define MAX_IMAGES 8
100 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
101
102 #define ANV_SVGS_VB_INDEX MAX_VBS
103 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
104
105 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
106
107 static inline uint32_t
108 align_down_npot_u32(uint32_t v, uint32_t a)
109 {
110 return v - (v % a);
111 }
112
113 static inline uint32_t
114 align_u32(uint32_t v, uint32_t a)
115 {
116 assert(a != 0 && a == (a & -a));
117 return (v + a - 1) & ~(a - 1);
118 }
119
120 static inline uint64_t
121 align_u64(uint64_t v, uint64_t a)
122 {
123 assert(a != 0 && a == (a & -a));
124 return (v + a - 1) & ~(a - 1);
125 }
126
127 static inline int32_t
128 align_i32(int32_t v, int32_t a)
129 {
130 assert(a != 0 && a == (a & -a));
131 return (v + a - 1) & ~(a - 1);
132 }
133
134 /** Alignment must be a power of 2. */
135 static inline bool
136 anv_is_aligned(uintmax_t n, uintmax_t a)
137 {
138 assert(a == (a & -a));
139 return (n & (a - 1)) == 0;
140 }
141
142 static inline uint32_t
143 anv_minify(uint32_t n, uint32_t levels)
144 {
145 if (unlikely(n == 0))
146 return 0;
147 else
148 return MAX2(n >> levels, 1);
149 }
150
151 static inline float
152 anv_clamp_f(float f, float min, float max)
153 {
154 assert(min < max);
155
156 if (f > max)
157 return max;
158 else if (f < min)
159 return min;
160 else
161 return f;
162 }
163
164 static inline bool
165 anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
166 {
167 if (*inout_mask & clear_mask) {
168 *inout_mask &= ~clear_mask;
169 return true;
170 } else {
171 return false;
172 }
173 }
174
175 static inline union isl_color_value
176 vk_to_isl_color(VkClearColorValue color)
177 {
178 return (union isl_color_value) {
179 .u32 = {
180 color.uint32[0],
181 color.uint32[1],
182 color.uint32[2],
183 color.uint32[3],
184 },
185 };
186 }
187
188 #define for_each_bit(b, dword) \
189 for (uint32_t __dword = (dword); \
190 (b) = __builtin_ffs(__dword) - 1, __dword; \
191 __dword &= ~(1 << (b)))
192
193 #define typed_memcpy(dest, src, count) ({ \
194 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
195 memcpy((dest), (src), (count) * sizeof(*(src))); \
196 })
197
198 /* Whenever we generate an error, pass it through this function. Useful for
199 * debugging, where we can break on it. Only call at error site, not when
200 * propagating errors. Might be useful to plug in a stack trace here.
201 */
202
203 VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
204
205 #ifdef DEBUG
206 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
207 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
208 #define anv_debug(format, ...) fprintf(stderr, "debug: " format, ##__VA_ARGS__)
209 #else
210 #define vk_error(error) error
211 #define vk_errorf(error, format, ...) error
212 #define anv_debug(format, ...)
213 #endif
214
215 /**
216 * Warn on ignored extension structs.
217 *
218 * The Vulkan spec requires us to ignore unsupported or unknown structs in
219 * a pNext chain. In debug mode, emitting warnings for ignored structs may
220 * help us discover structs that we should not have ignored.
221 *
222 *
223 * From the Vulkan 1.0.38 spec:
224 *
225 * Any component of the implementation (the loader, any enabled layers,
226 * and drivers) must skip over, without processing (other than reading the
227 * sType and pNext members) any chained structures with sType values not
228 * defined by extensions supported by that component.
229 */
230 #define anv_debug_ignored_stype(sType) \
231 anv_debug("debug: %s: ignored VkStructureType %u\n", __func__, (sType))
232
233 void __anv_finishme(const char *file, int line, const char *format, ...)
234 anv_printflike(3, 4);
235 void __anv_perf_warn(const char *file, int line, const char *format, ...)
236 anv_printflike(3, 4);
237 void anv_loge(const char *format, ...) anv_printflike(1, 2);
238 void anv_loge_v(const char *format, va_list va);
239
240 /**
241 * Print a FINISHME message, including its source location.
242 */
243 #define anv_finishme(format, ...) \
244 do { \
245 static bool reported = false; \
246 if (!reported) { \
247 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
248 reported = true; \
249 } \
250 } while (0)
251
252 /**
253 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
254 */
255 #define anv_perf_warn(format, ...) \
256 do { \
257 static bool reported = false; \
258 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
259 __anv_perf_warn(__FILE__, __LINE__, format, ##__VA_ARGS__); \
260 reported = true; \
261 } \
262 } while (0)
263
264 /* A non-fatal assert. Useful for debugging. */
265 #ifdef DEBUG
266 #define anv_assert(x) ({ \
267 if (unlikely(!(x))) \
268 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
269 })
270 #else
271 #define anv_assert(x)
272 #endif
273
274 /* A multi-pointer allocator
275 *
276 * When copying data structures from the user (such as a render pass), it's
277 * common to need to allocate data for a bunch of different things. Instead
278 * of doing several allocations and having to handle all of the error checking
279 * that entails, it can be easier to do a single allocation. This struct
280 * helps facilitate that. The intended usage looks like this:
281 *
282 * ANV_MULTIALLOC(ma)
283 * anv_multialloc_add(&ma, &main_ptr, 1);
284 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
285 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
286 *
287 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
288 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
289 */
290 struct anv_multialloc {
291 size_t size;
292 size_t align;
293
294 uint32_t ptr_count;
295 void **ptrs[8];
296 };
297
298 #define ANV_MULTIALLOC_INIT \
299 ((struct anv_multialloc) { 0, })
300
301 #define ANV_MULTIALLOC(_name) \
302 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
303
304 __attribute__((always_inline))
305 static inline void
306 _anv_multialloc_add(struct anv_multialloc *ma,
307 void **ptr, size_t size, size_t align)
308 {
309 size_t offset = align_u64(ma->size, align);
310 ma->size = offset + size;
311 ma->align = MAX2(ma->align, align);
312
313 /* Store the offset in the pointer. */
314 *ptr = (void *)(uintptr_t)offset;
315
316 assert(ma->ptr_count < ARRAY_SIZE(ma->ptrs));
317 ma->ptrs[ma->ptr_count++] = ptr;
318 }
319
320 #define anv_multialloc_add(_ma, _ptr, _count) \
321 _anv_multialloc_add((_ma), (void **)(_ptr), \
322 (_count) * sizeof(**(_ptr)), __alignof__(**(_ptr)))
323
324 __attribute__((always_inline))
325 static inline void *
326 anv_multialloc_alloc(struct anv_multialloc *ma,
327 const VkAllocationCallbacks *alloc,
328 VkSystemAllocationScope scope)
329 {
330 void *ptr = vk_alloc(alloc, ma->size, ma->align, scope);
331 if (!ptr)
332 return NULL;
333
334 /* Fill out each of the pointers with their final value.
335 *
336 * for (uint32_t i = 0; i < ma->ptr_count; i++)
337 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
338 *
339 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
340 * constant, GCC is incapable of figuring this out and unrolling the loop
341 * so we have to give it a little help.
342 */
343 STATIC_ASSERT(ARRAY_SIZE(ma->ptrs) == 8);
344 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
345 if ((_i) < ma->ptr_count) \
346 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
347 _ANV_MULTIALLOC_UPDATE_POINTER(0);
348 _ANV_MULTIALLOC_UPDATE_POINTER(1);
349 _ANV_MULTIALLOC_UPDATE_POINTER(2);
350 _ANV_MULTIALLOC_UPDATE_POINTER(3);
351 _ANV_MULTIALLOC_UPDATE_POINTER(4);
352 _ANV_MULTIALLOC_UPDATE_POINTER(5);
353 _ANV_MULTIALLOC_UPDATE_POINTER(6);
354 _ANV_MULTIALLOC_UPDATE_POINTER(7);
355 #undef _ANV_MULTIALLOC_UPDATE_POINTER
356
357 return ptr;
358 }
359
360 __attribute__((always_inline))
361 static inline void *
362 anv_multialloc_alloc2(struct anv_multialloc *ma,
363 const VkAllocationCallbacks *parent_alloc,
364 const VkAllocationCallbacks *alloc,
365 VkSystemAllocationScope scope)
366 {
367 return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
368 }
369
370 struct anv_bo {
371 uint32_t gem_handle;
372
373 /* Index into the current validation list. This is used by the
374 * validation list building alrogithm to track which buffers are already
375 * in the validation list so that we can ensure uniqueness.
376 */
377 uint32_t index;
378
379 /* Last known offset. This value is provided by the kernel when we
380 * execbuf and is used as the presumed offset for the next bunch of
381 * relocations.
382 */
383 uint64_t offset;
384
385 uint64_t size;
386 void *map;
387
388 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
389 uint32_t flags;
390 };
391
392 static inline void
393 anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
394 {
395 bo->gem_handle = gem_handle;
396 bo->index = 0;
397 bo->offset = -1;
398 bo->size = size;
399 bo->map = NULL;
400 bo->flags = 0;
401 }
402
403 /* Represents a lock-free linked list of "free" things. This is used by
404 * both the block pool and the state pools. Unfortunately, in order to
405 * solve the ABA problem, we can't use a single uint32_t head.
406 */
407 union anv_free_list {
408 struct {
409 int32_t offset;
410
411 /* A simple count that is incremented every time the head changes. */
412 uint32_t count;
413 };
414 uint64_t u64;
415 };
416
417 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
418
419 struct anv_block_state {
420 union {
421 struct {
422 uint32_t next;
423 uint32_t end;
424 };
425 uint64_t u64;
426 };
427 };
428
429 struct anv_block_pool {
430 struct anv_device *device;
431
432 struct anv_bo bo;
433
434 /* The offset from the start of the bo to the "center" of the block
435 * pool. Pointers to allocated blocks are given by
436 * bo.map + center_bo_offset + offsets.
437 */
438 uint32_t center_bo_offset;
439
440 /* Current memory map of the block pool. This pointer may or may not
441 * point to the actual beginning of the block pool memory. If
442 * anv_block_pool_alloc_back has ever been called, then this pointer
443 * will point to the "center" position of the buffer and all offsets
444 * (negative or positive) given out by the block pool alloc functions
445 * will be valid relative to this pointer.
446 *
447 * In particular, map == bo.map + center_offset
448 */
449 void *map;
450 int fd;
451
452 /**
453 * Array of mmaps and gem handles owned by the block pool, reclaimed when
454 * the block pool is destroyed.
455 */
456 struct u_vector mmap_cleanups;
457
458 struct anv_block_state state;
459
460 struct anv_block_state back_state;
461 };
462
463 /* Block pools are backed by a fixed-size 1GB memfd */
464 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
465
466 /* The center of the block pool is also the middle of the memfd. This may
467 * change in the future if we decide differently for some reason.
468 */
469 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
470
471 static inline uint32_t
472 anv_block_pool_size(struct anv_block_pool *pool)
473 {
474 return pool->state.end + pool->back_state.end;
475 }
476
477 struct anv_state {
478 int32_t offset;
479 uint32_t alloc_size;
480 void *map;
481 };
482
483 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
484
485 struct anv_fixed_size_state_pool {
486 union anv_free_list free_list;
487 struct anv_block_state block;
488 };
489
490 #define ANV_MIN_STATE_SIZE_LOG2 6
491 #define ANV_MAX_STATE_SIZE_LOG2 20
492
493 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
494
495 struct anv_state_pool {
496 struct anv_block_pool block_pool;
497
498 /* The size of blocks which will be allocated from the block pool */
499 uint32_t block_size;
500
501 /** Free list for "back" allocations */
502 union anv_free_list back_alloc_free_list;
503
504 struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
505 };
506
507 struct anv_state_stream_block;
508
509 struct anv_state_stream {
510 struct anv_state_pool *state_pool;
511
512 /* The size of blocks to allocate from the state pool */
513 uint32_t block_size;
514
515 /* Current block we're allocating from */
516 struct anv_state block;
517
518 /* Offset into the current block at which to allocate the next state */
519 uint32_t next;
520
521 /* List of all blocks allocated from this pool */
522 struct anv_state_stream_block *block_list;
523 };
524
525 /* The block_pool functions exported for testing only. The block pool should
526 * only be used via a state pool (see below).
527 */
528 VkResult anv_block_pool_init(struct anv_block_pool *pool,
529 struct anv_device *device,
530 uint32_t initial_size);
531 void anv_block_pool_finish(struct anv_block_pool *pool);
532 int32_t anv_block_pool_alloc(struct anv_block_pool *pool,
533 uint32_t block_size);
534 int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool,
535 uint32_t block_size);
536
537 VkResult anv_state_pool_init(struct anv_state_pool *pool,
538 struct anv_device *device,
539 uint32_t block_size);
540 void anv_state_pool_finish(struct anv_state_pool *pool);
541 struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool,
542 uint32_t state_size, uint32_t alignment);
543 struct anv_state anv_state_pool_alloc_back(struct anv_state_pool *pool);
544 void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state);
545 void anv_state_stream_init(struct anv_state_stream *stream,
546 struct anv_state_pool *state_pool,
547 uint32_t block_size);
548 void anv_state_stream_finish(struct anv_state_stream *stream);
549 struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
550 uint32_t size, uint32_t alignment);
551
552 /**
553 * Implements a pool of re-usable BOs. The interface is identical to that
554 * of block_pool except that each block is its own BO.
555 */
556 struct anv_bo_pool {
557 struct anv_device *device;
558
559 void *free_list[16];
560 };
561
562 void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device);
563 void anv_bo_pool_finish(struct anv_bo_pool *pool);
564 VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo,
565 uint32_t size);
566 void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
567
568 struct anv_scratch_bo {
569 bool exists;
570 struct anv_bo bo;
571 };
572
573 struct anv_scratch_pool {
574 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
575 struct anv_scratch_bo bos[16][MESA_SHADER_STAGES];
576 };
577
578 void anv_scratch_pool_init(struct anv_device *device,
579 struct anv_scratch_pool *pool);
580 void anv_scratch_pool_finish(struct anv_device *device,
581 struct anv_scratch_pool *pool);
582 struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
583 struct anv_scratch_pool *pool,
584 gl_shader_stage stage,
585 unsigned per_thread_scratch);
586
587 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
588 struct anv_bo_cache {
589 struct hash_table *bo_map;
590 pthread_mutex_t mutex;
591 };
592
593 VkResult anv_bo_cache_init(struct anv_bo_cache *cache);
594 void anv_bo_cache_finish(struct anv_bo_cache *cache);
595 VkResult anv_bo_cache_alloc(struct anv_device *device,
596 struct anv_bo_cache *cache,
597 uint64_t size, struct anv_bo **bo);
598 VkResult anv_bo_cache_import(struct anv_device *device,
599 struct anv_bo_cache *cache,
600 int fd, uint64_t size, struct anv_bo **bo);
601 VkResult anv_bo_cache_export(struct anv_device *device,
602 struct anv_bo_cache *cache,
603 struct anv_bo *bo_in, int *fd_out);
604 void anv_bo_cache_release(struct anv_device *device,
605 struct anv_bo_cache *cache,
606 struct anv_bo *bo);
607
608 struct anv_memory_type {
609 /* Standard bits passed on to the client */
610 VkMemoryPropertyFlags propertyFlags;
611 uint32_t heapIndex;
612
613 /* Driver-internal book-keeping */
614 VkBufferUsageFlags valid_buffer_usage;
615 };
616
617 struct anv_memory_heap {
618 /* Standard bits passed on to the client */
619 VkDeviceSize size;
620 VkMemoryHeapFlags flags;
621
622 /* Driver-internal book-keeping */
623 bool supports_48bit_addresses;
624 };
625
626 struct anv_physical_device {
627 VK_LOADER_DATA _loader_data;
628
629 struct anv_instance * instance;
630 uint32_t chipset_id;
631 char path[20];
632 const char * name;
633 struct gen_device_info info;
634 /** Amount of "GPU memory" we want to advertise
635 *
636 * Clearly, this value is bogus since Intel is a UMA architecture. On
637 * gen7 platforms, we are limited by GTT size unless we want to implement
638 * fine-grained tracking and GTT splitting. On Broadwell and above we are
639 * practically unlimited. However, we will never report more than 3/4 of
640 * the total system ram to try and avoid running out of RAM.
641 */
642 bool supports_48bit_addresses;
643 struct brw_compiler * compiler;
644 struct isl_device isl_dev;
645 int cmd_parser_version;
646 bool has_exec_async;
647 bool has_exec_fence;
648 bool has_syncobj;
649
650 uint32_t eu_total;
651 uint32_t subslice_total;
652
653 struct {
654 uint32_t type_count;
655 struct anv_memory_type types[VK_MAX_MEMORY_TYPES];
656 uint32_t heap_count;
657 struct anv_memory_heap heaps[VK_MAX_MEMORY_HEAPS];
658 } memory;
659
660 uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
661 uint8_t driver_uuid[VK_UUID_SIZE];
662 uint8_t device_uuid[VK_UUID_SIZE];
663
664 struct wsi_device wsi_device;
665 int local_fd;
666 };
667
668 struct anv_instance {
669 VK_LOADER_DATA _loader_data;
670
671 VkAllocationCallbacks alloc;
672
673 uint32_t apiVersion;
674 int physicalDeviceCount;
675 struct anv_physical_device physicalDevice;
676 };
677
678 VkResult anv_init_wsi(struct anv_physical_device *physical_device);
679 void anv_finish_wsi(struct anv_physical_device *physical_device);
680
681 bool anv_instance_extension_supported(const char *name);
682 uint32_t anv_physical_device_api_version(struct anv_physical_device *dev);
683 bool anv_physical_device_extension_supported(struct anv_physical_device *dev,
684 const char *name);
685
686 struct anv_queue {
687 VK_LOADER_DATA _loader_data;
688
689 struct anv_device * device;
690
691 struct anv_state_pool * pool;
692 };
693
694 struct anv_pipeline_cache {
695 struct anv_device * device;
696 pthread_mutex_t mutex;
697
698 struct hash_table * cache;
699 };
700
701 struct anv_pipeline_bind_map;
702
703 void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
704 struct anv_device *device,
705 bool cache_enabled);
706 void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
707
708 struct anv_shader_bin *
709 anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
710 const void *key, uint32_t key_size);
711 struct anv_shader_bin *
712 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
713 const void *key_data, uint32_t key_size,
714 const void *kernel_data, uint32_t kernel_size,
715 const struct brw_stage_prog_data *prog_data,
716 uint32_t prog_data_size,
717 const struct anv_pipeline_bind_map *bind_map);
718
719 struct anv_device {
720 VK_LOADER_DATA _loader_data;
721
722 VkAllocationCallbacks alloc;
723
724 struct anv_instance * instance;
725 uint32_t chipset_id;
726 struct gen_device_info info;
727 struct isl_device isl_dev;
728 int context_id;
729 int fd;
730 bool can_chain_batches;
731 bool robust_buffer_access;
732
733 struct anv_bo_pool batch_bo_pool;
734
735 struct anv_bo_cache bo_cache;
736
737 struct anv_state_pool dynamic_state_pool;
738 struct anv_state_pool instruction_state_pool;
739 struct anv_state_pool surface_state_pool;
740
741 struct anv_bo workaround_bo;
742 struct anv_bo trivial_batch_bo;
743
744 struct anv_pipeline_cache blorp_shader_cache;
745 struct blorp_context blorp;
746
747 struct anv_state border_colors;
748
749 struct anv_queue queue;
750
751 struct anv_scratch_pool scratch_pool;
752
753 uint32_t default_mocs;
754
755 pthread_mutex_t mutex;
756 pthread_cond_t queue_submit;
757 bool lost;
758 };
759
760 static void inline
761 anv_state_flush(struct anv_device *device, struct anv_state state)
762 {
763 if (device->info.has_llc)
764 return;
765
766 gen_flush_range(state.map, state.alloc_size);
767 }
768
769 void anv_device_init_blorp(struct anv_device *device);
770 void anv_device_finish_blorp(struct anv_device *device);
771
772 VkResult anv_device_execbuf(struct anv_device *device,
773 struct drm_i915_gem_execbuffer2 *execbuf,
774 struct anv_bo **execbuf_bos);
775 VkResult anv_device_query_status(struct anv_device *device);
776 VkResult anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo);
777 VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo,
778 int64_t timeout);
779
780 void* anv_gem_mmap(struct anv_device *device,
781 uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags);
782 void anv_gem_munmap(void *p, uint64_t size);
783 uint32_t anv_gem_create(struct anv_device *device, uint64_t size);
784 void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
785 uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
786 int anv_gem_busy(struct anv_device *device, uint32_t gem_handle);
787 int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns);
788 int anv_gem_execbuffer(struct anv_device *device,
789 struct drm_i915_gem_execbuffer2 *execbuf);
790 int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
791 uint32_t stride, uint32_t tiling);
792 int anv_gem_create_context(struct anv_device *device);
793 int anv_gem_destroy_context(struct anv_device *device, int context);
794 int anv_gem_get_context_param(int fd, int context, uint32_t param,
795 uint64_t *value);
796 int anv_gem_get_param(int fd, uint32_t param);
797 bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
798 int anv_gem_get_aperture(int fd, uint64_t *size);
799 bool anv_gem_supports_48b_addresses(int fd);
800 int anv_gem_gpu_get_reset_stats(struct anv_device *device,
801 uint32_t *active, uint32_t *pending);
802 int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
803 uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
804 int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
805 int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
806 uint32_t read_domains, uint32_t write_domain);
807 int anv_gem_sync_file_merge(struct anv_device *device, int fd1, int fd2);
808 uint32_t anv_gem_syncobj_create(struct anv_device *device, uint32_t flags);
809 void anv_gem_syncobj_destroy(struct anv_device *device, uint32_t handle);
810 int anv_gem_syncobj_handle_to_fd(struct anv_device *device, uint32_t handle);
811 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device *device, int fd);
812 void anv_gem_syncobj_reset(struct anv_device *device, uint32_t handle);
813 bool anv_gem_supports_syncobj_wait(int fd);
814 int anv_gem_syncobj_wait(struct anv_device *device,
815 uint32_t *handles, uint32_t num_handles,
816 int64_t abs_timeout_ns, bool wait_all);
817
818 VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size);
819
820 struct anv_reloc_list {
821 uint32_t num_relocs;
822 uint32_t array_length;
823 struct drm_i915_gem_relocation_entry * relocs;
824 struct anv_bo ** reloc_bos;
825 };
826
827 VkResult anv_reloc_list_init(struct anv_reloc_list *list,
828 const VkAllocationCallbacks *alloc);
829 void anv_reloc_list_finish(struct anv_reloc_list *list,
830 const VkAllocationCallbacks *alloc);
831
832 VkResult anv_reloc_list_add(struct anv_reloc_list *list,
833 const VkAllocationCallbacks *alloc,
834 uint32_t offset, struct anv_bo *target_bo,
835 uint32_t delta);
836
837 struct anv_batch_bo {
838 /* Link in the anv_cmd_buffer.owned_batch_bos list */
839 struct list_head link;
840
841 struct anv_bo bo;
842
843 /* Bytes actually consumed in this batch BO */
844 uint32_t length;
845
846 struct anv_reloc_list relocs;
847 };
848
849 struct anv_batch {
850 const VkAllocationCallbacks * alloc;
851
852 void * start;
853 void * end;
854 void * next;
855
856 struct anv_reloc_list * relocs;
857
858 /* This callback is called (with the associated user data) in the event
859 * that the batch runs out of space.
860 */
861 VkResult (*extend_cb)(struct anv_batch *, void *);
862 void * user_data;
863
864 /**
865 * Current error status of the command buffer. Used to track inconsistent
866 * or incomplete command buffer states that are the consequence of run-time
867 * errors such as out of memory scenarios. We want to track this in the
868 * batch because the command buffer object is not visible to some parts
869 * of the driver.
870 */
871 VkResult status;
872 };
873
874 void *anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords);
875 void anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other);
876 uint64_t anv_batch_emit_reloc(struct anv_batch *batch,
877 void *location, struct anv_bo *bo, uint32_t offset);
878 VkResult anv_device_submit_simple_batch(struct anv_device *device,
879 struct anv_batch *batch);
880
881 static inline VkResult
882 anv_batch_set_error(struct anv_batch *batch, VkResult error)
883 {
884 assert(error != VK_SUCCESS);
885 if (batch->status == VK_SUCCESS)
886 batch->status = error;
887 return batch->status;
888 }
889
890 static inline bool
891 anv_batch_has_error(struct anv_batch *batch)
892 {
893 return batch->status != VK_SUCCESS;
894 }
895
896 struct anv_address {
897 struct anv_bo *bo;
898 uint32_t offset;
899 };
900
901 static inline uint64_t
902 _anv_combine_address(struct anv_batch *batch, void *location,
903 const struct anv_address address, uint32_t delta)
904 {
905 if (address.bo == NULL) {
906 return address.offset + delta;
907 } else {
908 assert(batch->start <= location && location < batch->end);
909
910 return anv_batch_emit_reloc(batch, location, address.bo, address.offset + delta);
911 }
912 }
913
914 #define __gen_address_type struct anv_address
915 #define __gen_user_data struct anv_batch
916 #define __gen_combine_address _anv_combine_address
917
918 /* Wrapper macros needed to work around preprocessor argument issues. In
919 * particular, arguments don't get pre-evaluated if they are concatenated.
920 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
921 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
922 * We can work around this easily enough with these helpers.
923 */
924 #define __anv_cmd_length(cmd) cmd ## _length
925 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
926 #define __anv_cmd_header(cmd) cmd ## _header
927 #define __anv_cmd_pack(cmd) cmd ## _pack
928 #define __anv_reg_num(reg) reg ## _num
929
930 #define anv_pack_struct(dst, struc, ...) do { \
931 struct struc __template = { \
932 __VA_ARGS__ \
933 }; \
934 __anv_cmd_pack(struc)(NULL, dst, &__template); \
935 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
936 } while (0)
937
938 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
939 void *__dst = anv_batch_emit_dwords(batch, n); \
940 if (__dst) { \
941 struct cmd __template = { \
942 __anv_cmd_header(cmd), \
943 .DWordLength = n - __anv_cmd_length_bias(cmd), \
944 __VA_ARGS__ \
945 }; \
946 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
947 } \
948 __dst; \
949 })
950
951 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
952 do { \
953 uint32_t *dw; \
954 \
955 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
956 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
957 if (!dw) \
958 break; \
959 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
960 dw[i] = (dwords0)[i] | (dwords1)[i]; \
961 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
962 } while (0)
963
964 #define anv_batch_emit(batch, cmd, name) \
965 for (struct cmd name = { __anv_cmd_header(cmd) }, \
966 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
967 __builtin_expect(_dst != NULL, 1); \
968 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
969 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
970 _dst = NULL; \
971 }))
972
973 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
974 .GraphicsDataTypeGFDT = 0, \
975 .LLCCacheabilityControlLLCCC = 0, \
976 .L3CacheabilityControlL3CC = 1, \
977 }
978
979 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
980 .LLCeLLCCacheabilityControlLLCCC = 0, \
981 .L3CacheabilityControlL3CC = 1, \
982 }
983
984 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
985 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
986 .TargetCache = L3DefertoPATforLLCeLLCselection, \
987 .AgeforQUADLRU = 0 \
988 }
989
990 /* Skylake: MOCS is now an index into an array of 62 different caching
991 * configurations programmed by the kernel.
992 */
993
994 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
995 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
996 .IndextoMOCSTables = 2 \
997 }
998
999 #define GEN9_MOCS_PTE { \
1000 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1001 .IndextoMOCSTables = 1 \
1002 }
1003
1004 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1005 #define GEN10_MOCS (struct GEN10_MEMORY_OBJECT_CONTROL_STATE) { \
1006 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1007 .IndextoMOCSTables = 2 \
1008 }
1009
1010 #define GEN10_MOCS_PTE { \
1011 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1012 .IndextoMOCSTables = 1 \
1013 }
1014
1015 struct anv_device_memory {
1016 struct anv_bo * bo;
1017 struct anv_memory_type * type;
1018 VkDeviceSize map_size;
1019 void * map;
1020 };
1021
1022 /**
1023 * Header for Vertex URB Entry (VUE)
1024 */
1025 struct anv_vue_header {
1026 uint32_t Reserved;
1027 uint32_t RTAIndex; /* RenderTargetArrayIndex */
1028 uint32_t ViewportIndex;
1029 float PointWidth;
1030 };
1031
1032 struct anv_descriptor_set_binding_layout {
1033 #ifndef NDEBUG
1034 /* The type of the descriptors in this binding */
1035 VkDescriptorType type;
1036 #endif
1037
1038 /* Number of array elements in this binding */
1039 uint16_t array_size;
1040
1041 /* Index into the flattend descriptor set */
1042 uint16_t descriptor_index;
1043
1044 /* Index into the dynamic state array for a dynamic buffer */
1045 int16_t dynamic_offset_index;
1046
1047 /* Index into the descriptor set buffer views */
1048 int16_t buffer_index;
1049
1050 struct {
1051 /* Index into the binding table for the associated surface */
1052 int16_t surface_index;
1053
1054 /* Index into the sampler table for the associated sampler */
1055 int16_t sampler_index;
1056
1057 /* Index into the image table for the associated image */
1058 int16_t image_index;
1059 } stage[MESA_SHADER_STAGES];
1060
1061 /* Immutable samplers (or NULL if no immutable samplers) */
1062 struct anv_sampler **immutable_samplers;
1063 };
1064
1065 struct anv_descriptor_set_layout {
1066 /* Number of bindings in this descriptor set */
1067 uint16_t binding_count;
1068
1069 /* Total size of the descriptor set with room for all array entries */
1070 uint16_t size;
1071
1072 /* Shader stages affected by this descriptor set */
1073 uint16_t shader_stages;
1074
1075 /* Number of buffers in this descriptor set */
1076 uint16_t buffer_count;
1077
1078 /* Number of dynamic offsets used by this descriptor set */
1079 uint16_t dynamic_offset_count;
1080
1081 /* Bindings in this descriptor set */
1082 struct anv_descriptor_set_binding_layout binding[0];
1083 };
1084
1085 struct anv_descriptor {
1086 VkDescriptorType type;
1087
1088 union {
1089 struct {
1090 VkImageLayout layout;
1091 struct anv_image_view *image_view;
1092 struct anv_sampler *sampler;
1093 };
1094
1095 struct {
1096 struct anv_buffer *buffer;
1097 uint64_t offset;
1098 uint64_t range;
1099 };
1100
1101 struct anv_buffer_view *buffer_view;
1102 };
1103 };
1104
1105 struct anv_descriptor_set {
1106 const struct anv_descriptor_set_layout *layout;
1107 uint32_t size;
1108 uint32_t buffer_count;
1109 struct anv_buffer_view *buffer_views;
1110 struct anv_descriptor descriptors[0];
1111 };
1112
1113 struct anv_buffer_view {
1114 enum isl_format format; /**< VkBufferViewCreateInfo::format */
1115 struct anv_bo *bo;
1116 uint32_t offset; /**< Offset into bo. */
1117 uint64_t range; /**< VkBufferViewCreateInfo::range */
1118
1119 struct anv_state surface_state;
1120 struct anv_state storage_surface_state;
1121 struct anv_state writeonly_storage_surface_state;
1122
1123 struct brw_image_param storage_image_param;
1124 };
1125
1126 struct anv_push_descriptor_set {
1127 struct anv_descriptor_set set;
1128
1129 /* Put this field right behind anv_descriptor_set so it fills up the
1130 * descriptors[0] field. */
1131 struct anv_descriptor descriptors[MAX_PUSH_DESCRIPTORS];
1132
1133 struct anv_buffer_view buffer_views[MAX_PUSH_DESCRIPTORS];
1134 };
1135
1136 struct anv_descriptor_pool {
1137 uint32_t size;
1138 uint32_t next;
1139 uint32_t free_list;
1140
1141 struct anv_state_stream surface_state_stream;
1142 void *surface_state_free_list;
1143
1144 char data[0];
1145 };
1146
1147 enum anv_descriptor_template_entry_type {
1148 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
1149 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
1150 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1151 };
1152
1153 struct anv_descriptor_template_entry {
1154 /* The type of descriptor in this entry */
1155 VkDescriptorType type;
1156
1157 /* Binding in the descriptor set */
1158 uint32_t binding;
1159
1160 /* Offset at which to write into the descriptor set binding */
1161 uint32_t array_element;
1162
1163 /* Number of elements to write into the descriptor set binding */
1164 uint32_t array_count;
1165
1166 /* Offset into the user provided data */
1167 size_t offset;
1168
1169 /* Stride between elements into the user provided data */
1170 size_t stride;
1171 };
1172
1173 struct anv_descriptor_update_template {
1174 /* The descriptor set this template corresponds to. This value is only
1175 * valid if the template was created with the templateType
1176 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
1177 */
1178 uint8_t set;
1179
1180 /* Number of entries in this template */
1181 uint32_t entry_count;
1182
1183 /* Entries of the template */
1184 struct anv_descriptor_template_entry entries[0];
1185 };
1186
1187 size_t
1188 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
1189
1190 void
1191 anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
1192 const struct gen_device_info * const devinfo,
1193 const VkDescriptorImageInfo * const info,
1194 VkDescriptorType type,
1195 uint32_t binding,
1196 uint32_t element);
1197
1198 void
1199 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set *set,
1200 VkDescriptorType type,
1201 struct anv_buffer_view *buffer_view,
1202 uint32_t binding,
1203 uint32_t element);
1204
1205 void
1206 anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
1207 struct anv_device *device,
1208 struct anv_state_stream *alloc_stream,
1209 VkDescriptorType type,
1210 struct anv_buffer *buffer,
1211 uint32_t binding,
1212 uint32_t element,
1213 VkDeviceSize offset,
1214 VkDeviceSize range);
1215
1216 void
1217 anv_descriptor_set_write_template(struct anv_descriptor_set *set,
1218 struct anv_device *device,
1219 struct anv_state_stream *alloc_stream,
1220 const struct anv_descriptor_update_template *template,
1221 const void *data);
1222
1223 VkResult
1224 anv_descriptor_set_create(struct anv_device *device,
1225 struct anv_descriptor_pool *pool,
1226 const struct anv_descriptor_set_layout *layout,
1227 struct anv_descriptor_set **out_set);
1228
1229 void
1230 anv_descriptor_set_destroy(struct anv_device *device,
1231 struct anv_descriptor_pool *pool,
1232 struct anv_descriptor_set *set);
1233
1234 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1235
1236 struct anv_pipeline_binding {
1237 /* The descriptor set this surface corresponds to. The special value of
1238 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1239 * to a color attachment and not a regular descriptor.
1240 */
1241 uint8_t set;
1242
1243 /* Binding in the descriptor set */
1244 uint8_t binding;
1245
1246 /* Index in the binding */
1247 uint8_t index;
1248
1249 /* Input attachment index (relative to the subpass) */
1250 uint8_t input_attachment_index;
1251
1252 /* For a storage image, whether it is write-only */
1253 bool write_only;
1254 };
1255
1256 struct anv_pipeline_layout {
1257 struct {
1258 struct anv_descriptor_set_layout *layout;
1259 uint32_t dynamic_offset_start;
1260 } set[MAX_SETS];
1261
1262 uint32_t num_sets;
1263
1264 struct {
1265 bool has_dynamic_offsets;
1266 } stage[MESA_SHADER_STAGES];
1267
1268 unsigned char sha1[20];
1269 };
1270
1271 struct anv_buffer {
1272 struct anv_device * device;
1273 VkDeviceSize size;
1274
1275 VkBufferUsageFlags usage;
1276
1277 /* Set when bound */
1278 struct anv_bo * bo;
1279 VkDeviceSize offset;
1280 };
1281
1282 static inline uint64_t
1283 anv_buffer_get_range(struct anv_buffer *buffer, uint64_t offset, uint64_t range)
1284 {
1285 assert(offset <= buffer->size);
1286 if (range == VK_WHOLE_SIZE) {
1287 return buffer->size - offset;
1288 } else {
1289 assert(range <= buffer->size);
1290 return range;
1291 }
1292 }
1293
1294 enum anv_cmd_dirty_bits {
1295 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1296 ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1297 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1298 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1299 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1300 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1301 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1302 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1303 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1304 ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
1305 ANV_CMD_DIRTY_PIPELINE = 1 << 9,
1306 ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
1307 ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
1308 };
1309 typedef uint32_t anv_cmd_dirty_mask_t;
1310
1311 enum anv_pipe_bits {
1312 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
1313 ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
1314 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
1315 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
1316 ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
1317 ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
1318 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
1319 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
1320 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
1321 ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
1322 ANV_PIPE_CS_STALL_BIT = (1 << 20),
1323
1324 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1325 * a flush has happened but not a CS stall. The next time we do any sort
1326 * of invalidation we need to insert a CS stall at that time. Otherwise,
1327 * we would have to CS stall on every flush which could be bad.
1328 */
1329 ANV_PIPE_NEEDS_CS_STALL_BIT = (1 << 21),
1330 };
1331
1332 #define ANV_PIPE_FLUSH_BITS ( \
1333 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1334 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1335 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1336
1337 #define ANV_PIPE_STALL_BITS ( \
1338 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1339 ANV_PIPE_DEPTH_STALL_BIT | \
1340 ANV_PIPE_CS_STALL_BIT)
1341
1342 #define ANV_PIPE_INVALIDATE_BITS ( \
1343 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1344 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1345 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1346 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1347 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1348 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1349
1350 static inline enum anv_pipe_bits
1351 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags)
1352 {
1353 enum anv_pipe_bits pipe_bits = 0;
1354
1355 unsigned b;
1356 for_each_bit(b, flags) {
1357 switch ((VkAccessFlagBits)(1 << b)) {
1358 case VK_ACCESS_SHADER_WRITE_BIT:
1359 pipe_bits |= ANV_PIPE_DATA_CACHE_FLUSH_BIT;
1360 break;
1361 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT:
1362 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
1363 break;
1364 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT:
1365 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
1366 break;
1367 case VK_ACCESS_TRANSFER_WRITE_BIT:
1368 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
1369 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
1370 break;
1371 default:
1372 break; /* Nothing to do */
1373 }
1374 }
1375
1376 return pipe_bits;
1377 }
1378
1379 static inline enum anv_pipe_bits
1380 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags)
1381 {
1382 enum anv_pipe_bits pipe_bits = 0;
1383
1384 unsigned b;
1385 for_each_bit(b, flags) {
1386 switch ((VkAccessFlagBits)(1 << b)) {
1387 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT:
1388 case VK_ACCESS_INDEX_READ_BIT:
1389 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT:
1390 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
1391 break;
1392 case VK_ACCESS_UNIFORM_READ_BIT:
1393 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
1394 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
1395 break;
1396 case VK_ACCESS_SHADER_READ_BIT:
1397 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT:
1398 case VK_ACCESS_TRANSFER_READ_BIT:
1399 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
1400 break;
1401 default:
1402 break; /* Nothing to do */
1403 }
1404 }
1405
1406 return pipe_bits;
1407 }
1408
1409 struct anv_vertex_binding {
1410 struct anv_buffer * buffer;
1411 VkDeviceSize offset;
1412 };
1413
1414 struct anv_push_constants {
1415 /* Current allocated size of this push constants data structure.
1416 * Because a decent chunk of it may not be used (images on SKL, for
1417 * instance), we won't actually allocate the entire structure up-front.
1418 */
1419 uint32_t size;
1420
1421 /* Push constant data provided by the client through vkPushConstants */
1422 uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
1423
1424 /* Our hardware only provides zero-based vertex and instance id so, in
1425 * order to satisfy the vulkan requirements, we may have to push one or
1426 * both of these into the shader.
1427 */
1428 uint32_t base_vertex;
1429 uint32_t base_instance;
1430
1431 /* Image data for image_load_store on pre-SKL */
1432 struct brw_image_param images[MAX_IMAGES];
1433 };
1434
1435 struct anv_dynamic_state {
1436 struct {
1437 uint32_t count;
1438 VkViewport viewports[MAX_VIEWPORTS];
1439 } viewport;
1440
1441 struct {
1442 uint32_t count;
1443 VkRect2D scissors[MAX_SCISSORS];
1444 } scissor;
1445
1446 float line_width;
1447
1448 struct {
1449 float bias;
1450 float clamp;
1451 float slope;
1452 } depth_bias;
1453
1454 float blend_constants[4];
1455
1456 struct {
1457 float min;
1458 float max;
1459 } depth_bounds;
1460
1461 struct {
1462 uint32_t front;
1463 uint32_t back;
1464 } stencil_compare_mask;
1465
1466 struct {
1467 uint32_t front;
1468 uint32_t back;
1469 } stencil_write_mask;
1470
1471 struct {
1472 uint32_t front;
1473 uint32_t back;
1474 } stencil_reference;
1475 };
1476
1477 extern const struct anv_dynamic_state default_dynamic_state;
1478
1479 void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
1480 const struct anv_dynamic_state *src,
1481 uint32_t copy_mask);
1482
1483 /**
1484 * Attachment state when recording a renderpass instance.
1485 *
1486 * The clear value is valid only if there exists a pending clear.
1487 */
1488 struct anv_attachment_state {
1489 enum isl_aux_usage aux_usage;
1490 enum isl_aux_usage input_aux_usage;
1491 struct anv_state color_rt_state;
1492 struct anv_state input_att_state;
1493
1494 VkImageLayout current_layout;
1495 VkImageAspectFlags pending_clear_aspects;
1496 bool fast_clear;
1497 VkClearValue clear_value;
1498 bool clear_color_is_zero_one;
1499 bool clear_color_is_zero;
1500 };
1501
1502 /** State required while building cmd buffer */
1503 struct anv_cmd_state {
1504 /* PIPELINE_SELECT.PipelineSelection */
1505 uint32_t current_pipeline;
1506 const struct gen_l3_config * current_l3_config;
1507 uint32_t vb_dirty;
1508 anv_cmd_dirty_mask_t dirty;
1509 anv_cmd_dirty_mask_t compute_dirty;
1510 enum anv_pipe_bits pending_pipe_bits;
1511 uint32_t num_workgroups_offset;
1512 struct anv_bo *num_workgroups_bo;
1513 VkShaderStageFlags descriptors_dirty;
1514 VkShaderStageFlags push_constants_dirty;
1515 uint32_t scratch_size;
1516 struct anv_pipeline * pipeline;
1517 struct anv_pipeline * compute_pipeline;
1518 struct anv_framebuffer * framebuffer;
1519 struct anv_render_pass * pass;
1520 struct anv_subpass * subpass;
1521 VkRect2D render_area;
1522 uint32_t restart_index;
1523 struct anv_vertex_binding vertex_bindings[MAX_VBS];
1524 struct anv_descriptor_set * descriptors[MAX_SETS];
1525 uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS];
1526 VkShaderStageFlags push_constant_stages;
1527 struct anv_push_constants * push_constants[MESA_SHADER_STAGES];
1528 struct anv_state binding_tables[MESA_SHADER_STAGES];
1529 struct anv_state samplers[MESA_SHADER_STAGES];
1530 struct anv_dynamic_state dynamic;
1531 bool need_query_wa;
1532
1533 struct anv_push_descriptor_set push_descriptor;
1534
1535 /**
1536 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1537 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1538 * and before invoking the secondary in ExecuteCommands.
1539 */
1540 bool pma_fix_enabled;
1541
1542 /**
1543 * Whether or not we know for certain that HiZ is enabled for the current
1544 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1545 * enabled or not, this will be false.
1546 */
1547 bool hiz_enabled;
1548
1549 /**
1550 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1551 * valid only when recording a render pass instance.
1552 */
1553 struct anv_attachment_state * attachments;
1554
1555 /**
1556 * Surface states for color render targets. These are stored in a single
1557 * flat array. For depth-stencil attachments, the surface state is simply
1558 * left blank.
1559 */
1560 struct anv_state render_pass_states;
1561
1562 /**
1563 * A null surface state of the right size to match the framebuffer. This
1564 * is one of the states in render_pass_states.
1565 */
1566 struct anv_state null_surface_state;
1567
1568 struct {
1569 struct anv_buffer * index_buffer;
1570 uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1571 uint32_t index_offset;
1572 } gen7;
1573 };
1574
1575 struct anv_cmd_pool {
1576 VkAllocationCallbacks alloc;
1577 struct list_head cmd_buffers;
1578 };
1579
1580 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1581
1582 enum anv_cmd_buffer_exec_mode {
1583 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
1584 ANV_CMD_BUFFER_EXEC_MODE_EMIT,
1585 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
1586 ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
1587 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
1588 };
1589
1590 struct anv_cmd_buffer {
1591 VK_LOADER_DATA _loader_data;
1592
1593 struct anv_device * device;
1594
1595 struct anv_cmd_pool * pool;
1596 struct list_head pool_link;
1597
1598 struct anv_batch batch;
1599
1600 /* Fields required for the actual chain of anv_batch_bo's.
1601 *
1602 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1603 */
1604 struct list_head batch_bos;
1605 enum anv_cmd_buffer_exec_mode exec_mode;
1606
1607 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1608 * referenced by this command buffer
1609 *
1610 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1611 */
1612 struct u_vector seen_bbos;
1613
1614 /* A vector of int32_t's for every block of binding tables.
1615 *
1616 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1617 */
1618 struct u_vector bt_block_states;
1619 uint32_t bt_next;
1620
1621 struct anv_reloc_list surface_relocs;
1622 /** Last seen surface state block pool center bo offset */
1623 uint32_t last_ss_pool_center;
1624
1625 /* Serial for tracking buffer completion */
1626 uint32_t serial;
1627
1628 /* Stream objects for storing temporary data */
1629 struct anv_state_stream surface_state_stream;
1630 struct anv_state_stream dynamic_state_stream;
1631
1632 VkCommandBufferUsageFlags usage_flags;
1633 VkCommandBufferLevel level;
1634
1635 struct anv_cmd_state state;
1636 };
1637
1638 VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1639 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1640 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1641 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
1642 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
1643 struct anv_cmd_buffer *secondary);
1644 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
1645 VkResult anv_cmd_buffer_execbuf(struct anv_device *device,
1646 struct anv_cmd_buffer *cmd_buffer,
1647 const VkSemaphore *in_semaphores,
1648 uint32_t num_in_semaphores,
1649 const VkSemaphore *out_semaphores,
1650 uint32_t num_out_semaphores,
1651 VkFence fence);
1652
1653 VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
1654
1655 VkResult
1656 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
1657 gl_shader_stage stage, uint32_t size);
1658 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1659 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1660 (offsetof(struct anv_push_constants, field) + \
1661 sizeof(cmd_buffer->state.push_constants[0]->field)))
1662
1663 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
1664 const void *data, uint32_t size, uint32_t alignment);
1665 struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
1666 uint32_t *a, uint32_t *b,
1667 uint32_t dwords, uint32_t alignment);
1668
1669 struct anv_address
1670 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
1671 struct anv_state
1672 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
1673 uint32_t entries, uint32_t *state_offset);
1674 struct anv_state
1675 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
1676 struct anv_state
1677 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
1678 uint32_t size, uint32_t alignment);
1679
1680 VkResult
1681 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
1682
1683 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
1684 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
1685 bool depth_clamp_enable);
1686 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
1687
1688 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
1689 struct anv_render_pass *pass,
1690 struct anv_framebuffer *framebuffer,
1691 const VkClearValue *clear_values);
1692
1693 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
1694
1695 struct anv_state
1696 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
1697 gl_shader_stage stage);
1698 struct anv_state
1699 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
1700
1701 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer *cmd_buffer);
1702 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer);
1703
1704 const struct anv_image_view *
1705 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
1706
1707 VkResult
1708 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
1709 uint32_t num_entries,
1710 uint32_t *state_offset,
1711 struct anv_state *bt_state);
1712
1713 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
1714
1715 enum anv_fence_type {
1716 ANV_FENCE_TYPE_NONE = 0,
1717 ANV_FENCE_TYPE_BO,
1718 ANV_FENCE_TYPE_SYNCOBJ,
1719 };
1720
1721 enum anv_bo_fence_state {
1722 /** Indicates that this is a new (or newly reset fence) */
1723 ANV_BO_FENCE_STATE_RESET,
1724
1725 /** Indicates that this fence has been submitted to the GPU but is still
1726 * (as far as we know) in use by the GPU.
1727 */
1728 ANV_BO_FENCE_STATE_SUBMITTED,
1729
1730 ANV_BO_FENCE_STATE_SIGNALED,
1731 };
1732
1733 struct anv_fence_impl {
1734 enum anv_fence_type type;
1735
1736 union {
1737 /** Fence implementation for BO fences
1738 *
1739 * These fences use a BO and a set of CPU-tracked state flags. The BO
1740 * is added to the object list of the last execbuf call in a QueueSubmit
1741 * and is marked EXEC_WRITE. The state flags track when the BO has been
1742 * submitted to the kernel. We need to do this because Vulkan lets you
1743 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
1744 * will say it's idle in this case.
1745 */
1746 struct {
1747 struct anv_bo bo;
1748 enum anv_bo_fence_state state;
1749 } bo;
1750 };
1751 };
1752
1753 struct anv_fence {
1754 /* Permanent fence state. Every fence has some form of permanent state
1755 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
1756 * cross-process fences0 or it could just be a dummy for use internally.
1757 */
1758 struct anv_fence_impl permanent;
1759
1760 /* Temporary fence state. A fence *may* have temporary state. That state
1761 * is added to the fence by an import operation and is reset back to
1762 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
1763 * state cannot be signaled because the fence must already be signaled
1764 * before the temporary state can be exported from the fence in the other
1765 * process and imported here.
1766 */
1767 struct anv_fence_impl temporary;
1768 };
1769
1770 struct anv_event {
1771 uint64_t semaphore;
1772 struct anv_state state;
1773 };
1774
1775 enum anv_semaphore_type {
1776 ANV_SEMAPHORE_TYPE_NONE = 0,
1777 ANV_SEMAPHORE_TYPE_DUMMY,
1778 ANV_SEMAPHORE_TYPE_BO,
1779 ANV_SEMAPHORE_TYPE_SYNC_FILE,
1780 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ,
1781 };
1782
1783 struct anv_semaphore_impl {
1784 enum anv_semaphore_type type;
1785
1786 union {
1787 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
1788 * This BO will be added to the object list on any execbuf2 calls for
1789 * which this semaphore is used as a wait or signal fence. When used as
1790 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
1791 */
1792 struct anv_bo *bo;
1793
1794 /* The sync file descriptor when type == AKV_SEMAPHORE_TYPE_SYNC_FILE.
1795 * If the semaphore is in the unsignaled state due to either just being
1796 * created or because it has been used for a wait, fd will be -1.
1797 */
1798 int fd;
1799
1800 /* Sync object handle when type == AKV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
1801 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
1802 * import so we don't need to bother with a userspace cache.
1803 */
1804 uint32_t syncobj;
1805 };
1806 };
1807
1808 struct anv_semaphore {
1809 /* Permanent semaphore state. Every semaphore has some form of permanent
1810 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
1811 * (for cross-process semaphores0 or it could just be a dummy for use
1812 * internally.
1813 */
1814 struct anv_semaphore_impl permanent;
1815
1816 /* Temporary semaphore state. A semaphore *may* have temporary state.
1817 * That state is added to the semaphore by an import operation and is reset
1818 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
1819 * semaphore with temporary state cannot be signaled because the semaphore
1820 * must already be signaled before the temporary state can be exported from
1821 * the semaphore in the other process and imported here.
1822 */
1823 struct anv_semaphore_impl temporary;
1824 };
1825
1826 void anv_semaphore_reset_temporary(struct anv_device *device,
1827 struct anv_semaphore *semaphore);
1828
1829 struct anv_shader_module {
1830 unsigned char sha1[20];
1831 uint32_t size;
1832 char data[0];
1833 };
1834
1835 static inline gl_shader_stage
1836 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1837 {
1838 assert(__builtin_popcount(vk_stage) == 1);
1839 return ffs(vk_stage) - 1;
1840 }
1841
1842 static inline VkShaderStageFlagBits
1843 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1844 {
1845 return (1 << mesa_stage);
1846 }
1847
1848 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1849
1850 #define anv_foreach_stage(stage, stage_bits) \
1851 for (gl_shader_stage stage, \
1852 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1853 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1854 __tmp &= ~(1 << (stage)))
1855
1856 struct anv_pipeline_bind_map {
1857 uint32_t surface_count;
1858 uint32_t sampler_count;
1859 uint32_t image_count;
1860
1861 struct anv_pipeline_binding * surface_to_descriptor;
1862 struct anv_pipeline_binding * sampler_to_descriptor;
1863 };
1864
1865 struct anv_shader_bin_key {
1866 uint32_t size;
1867 uint8_t data[0];
1868 };
1869
1870 struct anv_shader_bin {
1871 uint32_t ref_cnt;
1872
1873 const struct anv_shader_bin_key *key;
1874
1875 struct anv_state kernel;
1876 uint32_t kernel_size;
1877
1878 const struct brw_stage_prog_data *prog_data;
1879 uint32_t prog_data_size;
1880
1881 struct anv_pipeline_bind_map bind_map;
1882
1883 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1884 };
1885
1886 struct anv_shader_bin *
1887 anv_shader_bin_create(struct anv_device *device,
1888 const void *key, uint32_t key_size,
1889 const void *kernel, uint32_t kernel_size,
1890 const struct brw_stage_prog_data *prog_data,
1891 uint32_t prog_data_size, const void *prog_data_param,
1892 const struct anv_pipeline_bind_map *bind_map);
1893
1894 void
1895 anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
1896
1897 static inline void
1898 anv_shader_bin_ref(struct anv_shader_bin *shader)
1899 {
1900 assert(shader && shader->ref_cnt >= 1);
1901 p_atomic_inc(&shader->ref_cnt);
1902 }
1903
1904 static inline void
1905 anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
1906 {
1907 assert(shader && shader->ref_cnt >= 1);
1908 if (p_atomic_dec_zero(&shader->ref_cnt))
1909 anv_shader_bin_destroy(device, shader);
1910 }
1911
1912 struct anv_pipeline {
1913 struct anv_device * device;
1914 struct anv_batch batch;
1915 uint32_t batch_data[512];
1916 struct anv_reloc_list batch_relocs;
1917 uint32_t dynamic_state_mask;
1918 struct anv_dynamic_state dynamic_state;
1919
1920 struct anv_subpass * subpass;
1921 struct anv_pipeline_layout * layout;
1922
1923 bool needs_data_cache;
1924
1925 struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
1926
1927 struct {
1928 const struct gen_l3_config * l3_config;
1929 uint32_t total_size;
1930 } urb;
1931
1932 VkShaderStageFlags active_stages;
1933 struct anv_state blend_state;
1934
1935 uint32_t vb_used;
1936 uint32_t binding_stride[MAX_VBS];
1937 bool instancing_enable[MAX_VBS];
1938 bool primitive_restart;
1939 uint32_t topology;
1940
1941 uint32_t cs_right_mask;
1942
1943 bool writes_depth;
1944 bool depth_test_enable;
1945 bool writes_stencil;
1946 bool stencil_test_enable;
1947 bool depth_clamp_enable;
1948 bool sample_shading_enable;
1949 bool kill_pixel;
1950
1951 struct {
1952 uint32_t sf[7];
1953 uint32_t depth_stencil_state[3];
1954 } gen7;
1955
1956 struct {
1957 uint32_t sf[4];
1958 uint32_t raster[5];
1959 uint32_t wm_depth_stencil[3];
1960 } gen8;
1961
1962 struct {
1963 uint32_t wm_depth_stencil[4];
1964 } gen9;
1965
1966 uint32_t interface_descriptor_data[8];
1967 };
1968
1969 static inline bool
1970 anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
1971 gl_shader_stage stage)
1972 {
1973 return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
1974 }
1975
1976 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1977 static inline const struct brw_##prefix##_prog_data * \
1978 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
1979 { \
1980 if (anv_pipeline_has_stage(pipeline, stage)) { \
1981 return (const struct brw_##prefix##_prog_data *) \
1982 pipeline->shaders[stage]->prog_data; \
1983 } else { \
1984 return NULL; \
1985 } \
1986 }
1987
1988 ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
1989 ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
1990 ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
1991 ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
1992 ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
1993 ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
1994
1995 static inline const struct brw_vue_prog_data *
1996 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
1997 {
1998 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
1999 return &get_gs_prog_data(pipeline)->base;
2000 else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
2001 return &get_tes_prog_data(pipeline)->base;
2002 else
2003 return &get_vs_prog_data(pipeline)->base;
2004 }
2005
2006 VkResult
2007 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
2008 struct anv_pipeline_cache *cache,
2009 const VkGraphicsPipelineCreateInfo *pCreateInfo,
2010 const VkAllocationCallbacks *alloc);
2011
2012 VkResult
2013 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
2014 struct anv_pipeline_cache *cache,
2015 const VkComputePipelineCreateInfo *info,
2016 struct anv_shader_module *module,
2017 const char *entrypoint,
2018 const VkSpecializationInfo *spec_info);
2019
2020 struct anv_format {
2021 enum isl_format isl_format:16;
2022 struct isl_swizzle swizzle;
2023 };
2024
2025 struct anv_format
2026 anv_get_format(const struct gen_device_info *devinfo, VkFormat format,
2027 VkImageAspectFlags aspect, VkImageTiling tiling);
2028
2029 static inline enum isl_format
2030 anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
2031 VkImageAspectFlags aspect, VkImageTiling tiling)
2032 {
2033 return anv_get_format(devinfo, vk_format, aspect, tiling).isl_format;
2034 }
2035
2036 static inline struct isl_swizzle
2037 anv_swizzle_for_render(struct isl_swizzle swizzle)
2038 {
2039 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2040 * RGB as RGBA for texturing
2041 */
2042 assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
2043 swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
2044
2045 /* But it doesn't matter what we render to that channel */
2046 swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
2047
2048 return swizzle;
2049 }
2050
2051 void
2052 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
2053
2054 /**
2055 * Subsurface of an anv_image.
2056 */
2057 struct anv_surface {
2058 /** Valid only if isl_surf::size > 0. */
2059 struct isl_surf isl;
2060
2061 /**
2062 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2063 */
2064 uint32_t offset;
2065 };
2066
2067 struct anv_image {
2068 VkImageType type;
2069 /* The original VkFormat provided by the client. This may not match any
2070 * of the actual surface formats.
2071 */
2072 VkFormat vk_format;
2073 VkImageAspectFlags aspects;
2074 VkExtent3D extent;
2075 uint32_t levels;
2076 uint32_t array_size;
2077 uint32_t samples; /**< VkImageCreateInfo::samples */
2078 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
2079 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
2080
2081 VkDeviceSize size;
2082 uint32_t alignment;
2083
2084 /* Set when bound */
2085 struct anv_bo *bo;
2086 VkDeviceSize offset;
2087
2088 /**
2089 * Image subsurfaces
2090 *
2091 * For each foo, anv_image::foo_surface is valid if and only if
2092 * anv_image::aspects has a foo aspect.
2093 *
2094 * The hardware requires that the depth buffer and stencil buffer be
2095 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2096 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2097 * allocate the depth and stencil buffers as separate surfaces in the same
2098 * bo.
2099 */
2100 union {
2101 struct anv_surface color_surface;
2102
2103 struct {
2104 struct anv_surface depth_surface;
2105 struct anv_surface stencil_surface;
2106 };
2107 };
2108
2109 /**
2110 * For color images, this is the aux usage for this image when not used as a
2111 * color attachment.
2112 *
2113 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the image
2114 * has a HiZ buffer.
2115 */
2116 enum isl_aux_usage aux_usage;
2117
2118 struct anv_surface aux_surface;
2119 };
2120
2121 /* Returns the number of auxiliary buffer levels attached to an image. */
2122 static inline uint8_t
2123 anv_image_aux_levels(const struct anv_image * const image)
2124 {
2125 assert(image);
2126 return image->aux_surface.isl.size > 0 ? image->aux_surface.isl.levels : 0;
2127 }
2128
2129 /* Returns the number of auxiliary buffer layers attached to an image. */
2130 static inline uint32_t
2131 anv_image_aux_layers(const struct anv_image * const image,
2132 const uint8_t miplevel)
2133 {
2134 assert(image);
2135
2136 /* The miplevel must exist in the main buffer. */
2137 assert(miplevel < image->levels);
2138
2139 if (miplevel >= anv_image_aux_levels(image)) {
2140 /* There are no layers with auxiliary data because the miplevel has no
2141 * auxiliary data.
2142 */
2143 return 0;
2144 } else {
2145 return MAX2(image->aux_surface.isl.logical_level0_px.array_len,
2146 image->aux_surface.isl.logical_level0_px.depth >> miplevel);
2147 }
2148 }
2149
2150 static inline unsigned
2151 anv_fast_clear_state_entry_size(const struct anv_device *device)
2152 {
2153 assert(device);
2154 /* Entry contents:
2155 * +--------------------------------------------+
2156 * | clear value dword(s) | needs resolve dword |
2157 * +--------------------------------------------+
2158 */
2159
2160 /* Ensure that the needs resolve dword is in fact dword-aligned to enable
2161 * GPU memcpy operations.
2162 */
2163 assert(device->isl_dev.ss.clear_value_size % 4 == 0);
2164 return device->isl_dev.ss.clear_value_size + 4;
2165 }
2166
2167 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
2168 static inline bool
2169 anv_can_sample_with_hiz(const struct gen_device_info * const devinfo,
2170 const VkImageAspectFlags aspect_mask,
2171 const uint32_t samples)
2172 {
2173 /* Validate the inputs. */
2174 assert(devinfo && aspect_mask && samples);
2175 return devinfo->gen >= 8 && (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) &&
2176 samples == 1;
2177 }
2178
2179 void
2180 anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,
2181 const struct anv_image *image,
2182 enum blorp_hiz_op op);
2183 void
2184 anv_ccs_resolve(struct anv_cmd_buffer * const cmd_buffer,
2185 const struct anv_state surface_state,
2186 const struct anv_image * const image,
2187 const uint8_t level, const uint32_t layer_count,
2188 const enum blorp_fast_clear_op op);
2189
2190 void
2191 anv_image_fast_clear(struct anv_cmd_buffer *cmd_buffer,
2192 const struct anv_image *image,
2193 const uint32_t base_level, const uint32_t level_count,
2194 const uint32_t base_layer, uint32_t layer_count);
2195
2196 enum isl_aux_usage
2197 anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
2198 const struct anv_image *image,
2199 const VkImageAspectFlags aspects,
2200 const VkImageLayout layout);
2201
2202 /* This is defined as a macro so that it works for both
2203 * VkImageSubresourceRange and VkImageSubresourceLayers
2204 */
2205 #define anv_get_layerCount(_image, _range) \
2206 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
2207 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
2208
2209 static inline uint32_t
2210 anv_get_levelCount(const struct anv_image *image,
2211 const VkImageSubresourceRange *range)
2212 {
2213 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
2214 image->levels - range->baseMipLevel : range->levelCount;
2215 }
2216
2217
2218 struct anv_image_view {
2219 const struct anv_image *image; /**< VkImageViewCreateInfo::image */
2220 struct anv_bo *bo;
2221 uint32_t offset; /**< Offset into bo. */
2222
2223 struct isl_view isl;
2224
2225 VkImageAspectFlags aspect_mask;
2226 VkFormat vk_format;
2227 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2228
2229 /**
2230 * RENDER_SURFACE_STATE when using image as a sampler surface with an image
2231 * layout of SHADER_READ_ONLY_OPTIMAL or DEPTH_STENCIL_READ_ONLY_OPTIMAL.
2232 */
2233 enum isl_aux_usage optimal_sampler_aux_usage;
2234 struct anv_state optimal_sampler_surface_state;
2235
2236 /**
2237 * RENDER_SURFACE_STATE when using image as a sampler surface with an image
2238 * layout of GENERAL.
2239 */
2240 enum isl_aux_usage general_sampler_aux_usage;
2241 struct anv_state general_sampler_surface_state;
2242
2243 /**
2244 * RENDER_SURFACE_STATE when using image as a storage image. Separate states
2245 * for write-only and readable, using the real format for write-only and the
2246 * lowered format for readable.
2247 */
2248 struct anv_state storage_surface_state;
2249 struct anv_state writeonly_storage_surface_state;
2250
2251 struct brw_image_param storage_image_param;
2252 };
2253
2254 struct anv_image_create_info {
2255 const VkImageCreateInfo *vk_info;
2256
2257 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
2258 isl_tiling_flags_t isl_tiling_flags;
2259
2260 uint32_t stride;
2261 };
2262
2263 VkResult anv_image_create(VkDevice _device,
2264 const struct anv_image_create_info *info,
2265 const VkAllocationCallbacks* alloc,
2266 VkImage *pImage);
2267
2268 const struct anv_surface *
2269 anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
2270 VkImageAspectFlags aspect_mask);
2271
2272 enum isl_format
2273 anv_isl_format_for_descriptor_type(VkDescriptorType type);
2274
2275 static inline struct VkExtent3D
2276 anv_sanitize_image_extent(const VkImageType imageType,
2277 const struct VkExtent3D imageExtent)
2278 {
2279 switch (imageType) {
2280 case VK_IMAGE_TYPE_1D:
2281 return (VkExtent3D) { imageExtent.width, 1, 1 };
2282 case VK_IMAGE_TYPE_2D:
2283 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
2284 case VK_IMAGE_TYPE_3D:
2285 return imageExtent;
2286 default:
2287 unreachable("invalid image type");
2288 }
2289 }
2290
2291 static inline struct VkOffset3D
2292 anv_sanitize_image_offset(const VkImageType imageType,
2293 const struct VkOffset3D imageOffset)
2294 {
2295 switch (imageType) {
2296 case VK_IMAGE_TYPE_1D:
2297 return (VkOffset3D) { imageOffset.x, 0, 0 };
2298 case VK_IMAGE_TYPE_2D:
2299 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
2300 case VK_IMAGE_TYPE_3D:
2301 return imageOffset;
2302 default:
2303 unreachable("invalid image type");
2304 }
2305 }
2306
2307
2308 void anv_fill_buffer_surface_state(struct anv_device *device,
2309 struct anv_state state,
2310 enum isl_format format,
2311 uint32_t offset, uint32_t range,
2312 uint32_t stride);
2313
2314 struct anv_sampler {
2315 uint32_t state[4];
2316 };
2317
2318 struct anv_framebuffer {
2319 uint32_t width;
2320 uint32_t height;
2321 uint32_t layers;
2322
2323 uint32_t attachment_count;
2324 struct anv_image_view * attachments[0];
2325 };
2326
2327 struct anv_subpass {
2328 uint32_t attachment_count;
2329
2330 /**
2331 * A pointer to all attachment references used in this subpass.
2332 * Only valid if ::attachment_count > 0.
2333 */
2334 VkAttachmentReference * attachments;
2335 uint32_t input_count;
2336 VkAttachmentReference * input_attachments;
2337 uint32_t color_count;
2338 VkAttachmentReference * color_attachments;
2339 VkAttachmentReference * resolve_attachments;
2340
2341 VkAttachmentReference depth_stencil_attachment;
2342
2343 uint32_t view_mask;
2344
2345 /** Subpass has a depth/stencil self-dependency */
2346 bool has_ds_self_dep;
2347
2348 /** Subpass has at least one resolve attachment */
2349 bool has_resolve;
2350 };
2351
2352 static inline unsigned
2353 anv_subpass_view_count(const struct anv_subpass *subpass)
2354 {
2355 return MAX2(1, _mesa_bitcount(subpass->view_mask));
2356 }
2357
2358 struct anv_render_pass_attachment {
2359 /* TODO: Consider using VkAttachmentDescription instead of storing each of
2360 * its members individually.
2361 */
2362 VkFormat format;
2363 uint32_t samples;
2364 VkImageUsageFlags usage;
2365 VkAttachmentLoadOp load_op;
2366 VkAttachmentStoreOp store_op;
2367 VkAttachmentLoadOp stencil_load_op;
2368 VkImageLayout initial_layout;
2369 VkImageLayout final_layout;
2370 VkImageLayout first_subpass_layout;
2371
2372 /* The subpass id in which the attachment will be used last. */
2373 uint32_t last_subpass_idx;
2374 };
2375
2376 struct anv_render_pass {
2377 uint32_t attachment_count;
2378 uint32_t subpass_count;
2379 /* An array of subpass_count+1 flushes, one per subpass boundary */
2380 enum anv_pipe_bits * subpass_flushes;
2381 struct anv_render_pass_attachment * attachments;
2382 struct anv_subpass subpasses[0];
2383 };
2384
2385 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
2386
2387 struct anv_query_pool {
2388 VkQueryType type;
2389 VkQueryPipelineStatisticFlags pipeline_statistics;
2390 /** Stride between slots, in bytes */
2391 uint32_t stride;
2392 /** Number of slots in this query pool */
2393 uint32_t slots;
2394 struct anv_bo bo;
2395 };
2396
2397 void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
2398 const char *name);
2399
2400 void anv_dump_image_to_ppm(struct anv_device *device,
2401 struct anv_image *image, unsigned miplevel,
2402 unsigned array_layer, VkImageAspectFlagBits aspect,
2403 const char *filename);
2404
2405 enum anv_dump_action {
2406 ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
2407 };
2408
2409 void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
2410 void anv_dump_finish(void);
2411
2412 void anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
2413 struct anv_framebuffer *fb);
2414
2415 static inline uint32_t
2416 anv_get_subpass_id(const struct anv_cmd_state * const cmd_state)
2417 {
2418 /* This function must be called from within a subpass. */
2419 assert(cmd_state->pass && cmd_state->subpass);
2420
2421 const uint32_t subpass_id = cmd_state->subpass - cmd_state->pass->subpasses;
2422
2423 /* The id of this subpass shouldn't exceed the number of subpasses in this
2424 * render pass minus 1.
2425 */
2426 assert(subpass_id < cmd_state->pass->subpass_count);
2427 return subpass_id;
2428 }
2429
2430 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
2431 \
2432 static inline struct __anv_type * \
2433 __anv_type ## _from_handle(__VkType _handle) \
2434 { \
2435 return (struct __anv_type *) _handle; \
2436 } \
2437 \
2438 static inline __VkType \
2439 __anv_type ## _to_handle(struct __anv_type *_obj) \
2440 { \
2441 return (__VkType) _obj; \
2442 }
2443
2444 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
2445 \
2446 static inline struct __anv_type * \
2447 __anv_type ## _from_handle(__VkType _handle) \
2448 { \
2449 return (struct __anv_type *)(uintptr_t) _handle; \
2450 } \
2451 \
2452 static inline __VkType \
2453 __anv_type ## _to_handle(struct __anv_type *_obj) \
2454 { \
2455 return (__VkType)(uintptr_t) _obj; \
2456 }
2457
2458 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
2459 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
2460
2461 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
2462 ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
2463 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
2464 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
2465 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
2466
2467 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
2468 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
2469 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
2470 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
2471 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
2472 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
2473 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
2474 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
2475 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
2476 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
2477 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
2478 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
2479 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
2480 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
2481 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
2482 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
2483 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
2484 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
2485 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
2486 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore, VkSemaphore)
2487 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
2488
2489 /* Gen-specific function declarations */
2490 #ifdef genX
2491 # include "anv_genX.h"
2492 #else
2493 # define genX(x) gen7_##x
2494 # include "anv_genX.h"
2495 # undef genX
2496 # define genX(x) gen75_##x
2497 # include "anv_genX.h"
2498 # undef genX
2499 # define genX(x) gen8_##x
2500 # include "anv_genX.h"
2501 # undef genX
2502 # define genX(x) gen9_##x
2503 # include "anv_genX.h"
2504 # undef genX
2505 # define genX(x) gen10_##x
2506 # include "anv_genX.h"
2507 # undef genX
2508 #endif
2509
2510 #endif /* ANV_PRIVATE_H */