anv: descriptor: make descriptor writing take a stream allocator
[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_device_info.h"
45 #include "blorp/blorp.h"
46 #include "brw_compiler.h"
47 #include "util/macros.h"
48 #include "util/list.h"
49 #include "util/u_vector.h"
50 #include "util/vk_alloc.h"
51
52 /* Pre-declarations needed for WSI entrypoints */
53 struct wl_surface;
54 struct wl_display;
55 typedef struct xcb_connection_t xcb_connection_t;
56 typedef uint32_t xcb_visualid_t;
57 typedef uint32_t xcb_window_t;
58
59 struct anv_buffer;
60 struct anv_buffer_view;
61 struct anv_image_view;
62
63 struct gen_l3_config;
64
65 #include <vulkan/vulkan.h>
66 #include <vulkan/vulkan_intel.h>
67 #include <vulkan/vk_icd.h>
68
69 #include "anv_entrypoints.h"
70 #include "brw_context.h"
71 #include "isl/isl.h"
72
73 #include "wsi_common.h"
74
75 /* Allowing different clear colors requires us to perform a depth resolve at
76 * the end of certain render passes. This is because while slow clears store
77 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
78 * See the PRMs for examples describing when additional resolves would be
79 * necessary. To enable fast clears without requiring extra resolves, we set
80 * the clear value to a globally-defined one. We could allow different values
81 * if the user doesn't expect coherent data during or after a render passes
82 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
83 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
84 * 1.0f seems to be the only value used. The only application that doesn't set
85 * this value does so through the usage of an seemingly uninitialized clear
86 * value.
87 */
88 #define ANV_HZ_FC_VAL 1.0f
89
90 #define MAX_VBS 31
91 #define MAX_SETS 8
92 #define MAX_RTS 8
93 #define MAX_VIEWPORTS 16
94 #define MAX_SCISSORS 16
95 #define MAX_PUSH_CONSTANTS_SIZE 128
96 #define MAX_DYNAMIC_BUFFERS 16
97 #define MAX_IMAGES 8
98
99 #define ANV_SVGS_VB_INDEX MAX_VBS
100 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
101
102 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
103
104 static inline uint32_t
105 align_down_npot_u32(uint32_t v, uint32_t a)
106 {
107 return v - (v % a);
108 }
109
110 static inline uint32_t
111 align_u32(uint32_t v, uint32_t a)
112 {
113 assert(a != 0 && a == (a & -a));
114 return (v + a - 1) & ~(a - 1);
115 }
116
117 static inline uint64_t
118 align_u64(uint64_t v, uint64_t a)
119 {
120 assert(a != 0 && a == (a & -a));
121 return (v + a - 1) & ~(a - 1);
122 }
123
124 static inline int32_t
125 align_i32(int32_t v, int32_t a)
126 {
127 assert(a != 0 && a == (a & -a));
128 return (v + a - 1) & ~(a - 1);
129 }
130
131 /** Alignment must be a power of 2. */
132 static inline bool
133 anv_is_aligned(uintmax_t n, uintmax_t a)
134 {
135 assert(a == (a & -a));
136 return (n & (a - 1)) == 0;
137 }
138
139 static inline uint32_t
140 anv_minify(uint32_t n, uint32_t levels)
141 {
142 if (unlikely(n == 0))
143 return 0;
144 else
145 return MAX2(n >> levels, 1);
146 }
147
148 static inline float
149 anv_clamp_f(float f, float min, float max)
150 {
151 assert(min < max);
152
153 if (f > max)
154 return max;
155 else if (f < min)
156 return min;
157 else
158 return f;
159 }
160
161 static inline bool
162 anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
163 {
164 if (*inout_mask & clear_mask) {
165 *inout_mask &= ~clear_mask;
166 return true;
167 } else {
168 return false;
169 }
170 }
171
172 static inline union isl_color_value
173 vk_to_isl_color(VkClearColorValue color)
174 {
175 return (union isl_color_value) {
176 .u32 = {
177 color.uint32[0],
178 color.uint32[1],
179 color.uint32[2],
180 color.uint32[3],
181 },
182 };
183 }
184
185 #define for_each_bit(b, dword) \
186 for (uint32_t __dword = (dword); \
187 (b) = __builtin_ffs(__dword) - 1, __dword; \
188 __dword &= ~(1 << (b)))
189
190 #define typed_memcpy(dest, src, count) ({ \
191 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
192 memcpy((dest), (src), (count) * sizeof(*(src))); \
193 })
194
195 /* Whenever we generate an error, pass it through this function. Useful for
196 * debugging, where we can break on it. Only call at error site, not when
197 * propagating errors. Might be useful to plug in a stack trace here.
198 */
199
200 VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
201
202 #ifdef DEBUG
203 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
204 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
205 #define anv_debug(format, ...) fprintf(stderr, "debug: " format, ##__VA_ARGS__)
206 #else
207 #define vk_error(error) error
208 #define vk_errorf(error, format, ...) error
209 #define anv_debug(format, ...)
210 #endif
211
212 /**
213 * Warn on ignored extension structs.
214 *
215 * The Vulkan spec requires us to ignore unsupported or unknown structs in
216 * a pNext chain. In debug mode, emitting warnings for ignored structs may
217 * help us discover structs that we should not have ignored.
218 *
219 *
220 * From the Vulkan 1.0.38 spec:
221 *
222 * Any component of the implementation (the loader, any enabled layers,
223 * and drivers) must skip over, without processing (other than reading the
224 * sType and pNext members) any chained structures with sType values not
225 * defined by extensions supported by that component.
226 */
227 #define anv_debug_ignored_stype(sType) \
228 anv_debug("debug: %s: ignored VkStructureType %u\n", __func__, (sType))
229
230 void __anv_finishme(const char *file, int line, const char *format, ...)
231 anv_printflike(3, 4);
232 void anv_loge(const char *format, ...) anv_printflike(1, 2);
233 void anv_loge_v(const char *format, va_list va);
234
235 /**
236 * Print a FINISHME message, including its source location.
237 */
238 #define anv_finishme(format, ...) \
239 do { \
240 static bool reported = false; \
241 if (!reported) { \
242 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
243 reported = true; \
244 } \
245 } while (0)
246
247 /* A non-fatal assert. Useful for debugging. */
248 #ifdef DEBUG
249 #define anv_assert(x) ({ \
250 if (unlikely(!(x))) \
251 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
252 })
253 #else
254 #define anv_assert(x)
255 #endif
256
257 /**
258 * If a block of code is annotated with anv_validate, then the block runs only
259 * in debug builds.
260 */
261 #ifdef DEBUG
262 #define anv_validate if (1)
263 #else
264 #define anv_validate if (0)
265 #endif
266
267 #define stub_return(v) \
268 do { \
269 anv_finishme("stub %s", __func__); \
270 return (v); \
271 } while (0)
272
273 #define stub() \
274 do { \
275 anv_finishme("stub %s", __func__); \
276 return; \
277 } while (0)
278
279 /**
280 * A dynamically growable, circular buffer. Elements are added at head and
281 * removed from tail. head and tail are free-running uint32_t indices and we
282 * only compute the modulo with size when accessing the array. This way,
283 * number of bytes in the queue is always head - tail, even in case of
284 * wraparound.
285 */
286
287 struct anv_bo {
288 uint32_t gem_handle;
289
290 /* Index into the current validation list. This is used by the
291 * validation list building alrogithm to track which buffers are already
292 * in the validation list so that we can ensure uniqueness.
293 */
294 uint32_t index;
295
296 /* Last known offset. This value is provided by the kernel when we
297 * execbuf and is used as the presumed offset for the next bunch of
298 * relocations.
299 */
300 uint64_t offset;
301
302 uint64_t size;
303 void *map;
304
305 /* We need to set the WRITE flag on winsys bos so GEM will know we're
306 * writing to them and synchronize uses on other rings (eg if the display
307 * server uses the blitter ring).
308 */
309 bool is_winsys_bo;
310 };
311
312 static inline void
313 anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
314 {
315 bo->gem_handle = gem_handle;
316 bo->index = 0;
317 bo->offset = -1;
318 bo->size = size;
319 bo->map = NULL;
320 bo->is_winsys_bo = false;
321 }
322
323 /* Represents a lock-free linked list of "free" things. This is used by
324 * both the block pool and the state pools. Unfortunately, in order to
325 * solve the ABA problem, we can't use a single uint32_t head.
326 */
327 union anv_free_list {
328 struct {
329 int32_t offset;
330
331 /* A simple count that is incremented every time the head changes. */
332 uint32_t count;
333 };
334 uint64_t u64;
335 };
336
337 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
338
339 struct anv_block_state {
340 union {
341 struct {
342 uint32_t next;
343 uint32_t end;
344 };
345 uint64_t u64;
346 };
347 };
348
349 struct anv_block_pool {
350 struct anv_device *device;
351
352 struct anv_bo bo;
353
354 /* The offset from the start of the bo to the "center" of the block
355 * pool. Pointers to allocated blocks are given by
356 * bo.map + center_bo_offset + offsets.
357 */
358 uint32_t center_bo_offset;
359
360 /* Current memory map of the block pool. This pointer may or may not
361 * point to the actual beginning of the block pool memory. If
362 * anv_block_pool_alloc_back has ever been called, then this pointer
363 * will point to the "center" position of the buffer and all offsets
364 * (negative or positive) given out by the block pool alloc functions
365 * will be valid relative to this pointer.
366 *
367 * In particular, map == bo.map + center_offset
368 */
369 void *map;
370 int fd;
371
372 /**
373 * Array of mmaps and gem handles owned by the block pool, reclaimed when
374 * the block pool is destroyed.
375 */
376 struct u_vector mmap_cleanups;
377
378 uint32_t block_size;
379
380 union anv_free_list free_list;
381 struct anv_block_state state;
382
383 union anv_free_list back_free_list;
384 struct anv_block_state back_state;
385 };
386
387 /* Block pools are backed by a fixed-size 2GB memfd */
388 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
389
390 /* The center of the block pool is also the middle of the memfd. This may
391 * change in the future if we decide differently for some reason.
392 */
393 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
394
395 static inline uint32_t
396 anv_block_pool_size(struct anv_block_pool *pool)
397 {
398 return pool->state.end + pool->back_state.end;
399 }
400
401 struct anv_state {
402 int32_t offset;
403 uint32_t alloc_size;
404 void *map;
405 };
406
407 struct anv_fixed_size_state_pool {
408 size_t state_size;
409 union anv_free_list free_list;
410 struct anv_block_state block;
411 };
412
413 #define ANV_MIN_STATE_SIZE_LOG2 6
414 #define ANV_MAX_STATE_SIZE_LOG2 20
415
416 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
417
418 struct anv_state_pool {
419 struct anv_block_pool *block_pool;
420 struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
421 };
422
423 struct anv_state_stream_block;
424
425 struct anv_state_stream {
426 struct anv_block_pool *block_pool;
427
428 /* The current working block */
429 struct anv_state_stream_block *block;
430
431 /* Offset at which the current block starts */
432 uint32_t start;
433 /* Offset at which to allocate the next state */
434 uint32_t next;
435 /* Offset at which the current block ends */
436 uint32_t end;
437 };
438
439 #define CACHELINE_SIZE 64
440 #define CACHELINE_MASK 63
441
442 static inline void
443 anv_clflush_range(void *start, size_t size)
444 {
445 void *p = (void *) (((uintptr_t) start) & ~CACHELINE_MASK);
446 void *end = start + size;
447
448 while (p < end) {
449 __builtin_ia32_clflush(p);
450 p += CACHELINE_SIZE;
451 }
452 }
453
454 static inline void
455 anv_flush_range(void *start, size_t size)
456 {
457 __builtin_ia32_mfence();
458 anv_clflush_range(start, size);
459 }
460
461 static inline void
462 anv_invalidate_range(void *start, size_t size)
463 {
464 anv_clflush_range(start, size);
465 __builtin_ia32_mfence();
466 }
467
468 VkResult anv_block_pool_init(struct anv_block_pool *pool,
469 struct anv_device *device, uint32_t block_size);
470 void anv_block_pool_finish(struct anv_block_pool *pool);
471 int32_t anv_block_pool_alloc(struct anv_block_pool *pool);
472 int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool);
473 void anv_block_pool_free(struct anv_block_pool *pool, int32_t offset);
474 void anv_state_pool_init(struct anv_state_pool *pool,
475 struct anv_block_pool *block_pool);
476 void anv_state_pool_finish(struct anv_state_pool *pool);
477 struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool,
478 size_t state_size, size_t alignment);
479 void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state);
480 void anv_state_stream_init(struct anv_state_stream *stream,
481 struct anv_block_pool *block_pool);
482 void anv_state_stream_finish(struct anv_state_stream *stream);
483 struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
484 uint32_t size, uint32_t alignment);
485
486 /**
487 * Implements a pool of re-usable BOs. The interface is identical to that
488 * of block_pool except that each block is its own BO.
489 */
490 struct anv_bo_pool {
491 struct anv_device *device;
492
493 void *free_list[16];
494 };
495
496 void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device);
497 void anv_bo_pool_finish(struct anv_bo_pool *pool);
498 VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo,
499 uint32_t size);
500 void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
501
502 struct anv_scratch_bo {
503 bool exists;
504 struct anv_bo bo;
505 };
506
507 struct anv_scratch_pool {
508 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
509 struct anv_scratch_bo bos[16][MESA_SHADER_STAGES];
510 };
511
512 void anv_scratch_pool_init(struct anv_device *device,
513 struct anv_scratch_pool *pool);
514 void anv_scratch_pool_finish(struct anv_device *device,
515 struct anv_scratch_pool *pool);
516 struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
517 struct anv_scratch_pool *pool,
518 gl_shader_stage stage,
519 unsigned per_thread_scratch);
520
521 struct anv_physical_device {
522 VK_LOADER_DATA _loader_data;
523
524 struct anv_instance * instance;
525 uint32_t chipset_id;
526 char path[20];
527 const char * name;
528 struct gen_device_info info;
529 uint64_t aperture_size;
530 struct brw_compiler * compiler;
531 struct isl_device isl_dev;
532 int cmd_parser_version;
533
534 uint32_t eu_total;
535 uint32_t subslice_total;
536
537 uint8_t uuid[VK_UUID_SIZE];
538
539 struct wsi_device wsi_device;
540 int local_fd;
541 };
542
543 struct anv_instance {
544 VK_LOADER_DATA _loader_data;
545
546 VkAllocationCallbacks alloc;
547
548 uint32_t apiVersion;
549 int physicalDeviceCount;
550 struct anv_physical_device physicalDevice;
551 };
552
553 VkResult anv_init_wsi(struct anv_physical_device *physical_device);
554 void anv_finish_wsi(struct anv_physical_device *physical_device);
555
556 struct anv_queue {
557 VK_LOADER_DATA _loader_data;
558
559 struct anv_device * device;
560
561 struct anv_state_pool * pool;
562 };
563
564 struct anv_pipeline_cache {
565 struct anv_device * device;
566 pthread_mutex_t mutex;
567
568 struct hash_table * cache;
569 };
570
571 struct anv_pipeline_bind_map;
572
573 void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
574 struct anv_device *device,
575 bool cache_enabled);
576 void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
577
578 struct anv_shader_bin *
579 anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
580 const void *key, uint32_t key_size);
581 struct anv_shader_bin *
582 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
583 const void *key_data, uint32_t key_size,
584 const void *kernel_data, uint32_t kernel_size,
585 const struct brw_stage_prog_data *prog_data,
586 uint32_t prog_data_size,
587 const struct anv_pipeline_bind_map *bind_map);
588
589 struct anv_device {
590 VK_LOADER_DATA _loader_data;
591
592 VkAllocationCallbacks alloc;
593
594 struct anv_instance * instance;
595 uint32_t chipset_id;
596 struct gen_device_info info;
597 struct isl_device isl_dev;
598 int context_id;
599 int fd;
600 bool can_chain_batches;
601 bool robust_buffer_access;
602
603 struct anv_bo_pool batch_bo_pool;
604
605 struct anv_block_pool dynamic_state_block_pool;
606 struct anv_state_pool dynamic_state_pool;
607
608 struct anv_block_pool instruction_block_pool;
609 struct anv_state_pool instruction_state_pool;
610
611 struct anv_block_pool surface_state_block_pool;
612 struct anv_state_pool surface_state_pool;
613
614 struct anv_bo workaround_bo;
615
616 struct anv_pipeline_cache blorp_shader_cache;
617 struct blorp_context blorp;
618
619 struct anv_state border_colors;
620
621 struct anv_queue queue;
622
623 struct anv_scratch_pool scratch_pool;
624
625 uint32_t default_mocs;
626
627 pthread_mutex_t mutex;
628 pthread_cond_t queue_submit;
629 };
630
631 static void inline
632 anv_state_flush(struct anv_device *device, struct anv_state state)
633 {
634 if (device->info.has_llc)
635 return;
636
637 anv_flush_range(state.map, state.alloc_size);
638 }
639
640 void anv_device_init_blorp(struct anv_device *device);
641 void anv_device_finish_blorp(struct anv_device *device);
642
643 VkResult anv_device_execbuf(struct anv_device *device,
644 struct drm_i915_gem_execbuffer2 *execbuf,
645 struct anv_bo **execbuf_bos);
646
647 void* anv_gem_mmap(struct anv_device *device,
648 uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags);
649 void anv_gem_munmap(void *p, uint64_t size);
650 uint32_t anv_gem_create(struct anv_device *device, size_t size);
651 void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
652 uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
653 int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns);
654 int anv_gem_execbuffer(struct anv_device *device,
655 struct drm_i915_gem_execbuffer2 *execbuf);
656 int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
657 uint32_t stride, uint32_t tiling);
658 int anv_gem_create_context(struct anv_device *device);
659 int anv_gem_destroy_context(struct anv_device *device, int context);
660 int anv_gem_get_param(int fd, uint32_t param);
661 bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
662 int anv_gem_get_aperture(int fd, uint64_t *size);
663 int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
664 uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
665 int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
666 int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
667 uint32_t read_domains, uint32_t write_domain);
668
669 VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size);
670
671 struct anv_reloc_list {
672 size_t num_relocs;
673 size_t array_length;
674 struct drm_i915_gem_relocation_entry * relocs;
675 struct anv_bo ** reloc_bos;
676 };
677
678 VkResult anv_reloc_list_init(struct anv_reloc_list *list,
679 const VkAllocationCallbacks *alloc);
680 void anv_reloc_list_finish(struct anv_reloc_list *list,
681 const VkAllocationCallbacks *alloc);
682
683 uint64_t anv_reloc_list_add(struct anv_reloc_list *list,
684 const VkAllocationCallbacks *alloc,
685 uint32_t offset, struct anv_bo *target_bo,
686 uint32_t delta);
687
688 struct anv_batch_bo {
689 /* Link in the anv_cmd_buffer.owned_batch_bos list */
690 struct list_head link;
691
692 struct anv_bo bo;
693
694 /* Bytes actually consumed in this batch BO */
695 size_t length;
696
697 struct anv_reloc_list relocs;
698 };
699
700 struct anv_batch {
701 const VkAllocationCallbacks * alloc;
702
703 void * start;
704 void * end;
705 void * next;
706
707 struct anv_reloc_list * relocs;
708
709 /* This callback is called (with the associated user data) in the event
710 * that the batch runs out of space.
711 */
712 VkResult (*extend_cb)(struct anv_batch *, void *);
713 void * user_data;
714 };
715
716 void *anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords);
717 void anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other);
718 uint64_t anv_batch_emit_reloc(struct anv_batch *batch,
719 void *location, struct anv_bo *bo, uint32_t offset);
720 VkResult anv_device_submit_simple_batch(struct anv_device *device,
721 struct anv_batch *batch);
722
723 struct anv_address {
724 struct anv_bo *bo;
725 uint32_t offset;
726 };
727
728 static inline uint64_t
729 _anv_combine_address(struct anv_batch *batch, void *location,
730 const struct anv_address address, uint32_t delta)
731 {
732 if (address.bo == NULL) {
733 return address.offset + delta;
734 } else {
735 assert(batch->start <= location && location < batch->end);
736
737 return anv_batch_emit_reloc(batch, location, address.bo, address.offset + delta);
738 }
739 }
740
741 #define __gen_address_type struct anv_address
742 #define __gen_user_data struct anv_batch
743 #define __gen_combine_address _anv_combine_address
744
745 /* Wrapper macros needed to work around preprocessor argument issues. In
746 * particular, arguments don't get pre-evaluated if they are concatenated.
747 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
748 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
749 * We can work around this easily enough with these helpers.
750 */
751 #define __anv_cmd_length(cmd) cmd ## _length
752 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
753 #define __anv_cmd_header(cmd) cmd ## _header
754 #define __anv_cmd_pack(cmd) cmd ## _pack
755 #define __anv_reg_num(reg) reg ## _num
756
757 #define anv_pack_struct(dst, struc, ...) do { \
758 struct struc __template = { \
759 __VA_ARGS__ \
760 }; \
761 __anv_cmd_pack(struc)(NULL, dst, &__template); \
762 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
763 } while (0)
764
765 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
766 void *__dst = anv_batch_emit_dwords(batch, n); \
767 struct cmd __template = { \
768 __anv_cmd_header(cmd), \
769 .DWordLength = n - __anv_cmd_length_bias(cmd), \
770 __VA_ARGS__ \
771 }; \
772 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
773 __dst; \
774 })
775
776 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
777 do { \
778 uint32_t *dw; \
779 \
780 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
781 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
782 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
783 dw[i] = (dwords0)[i] | (dwords1)[i]; \
784 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
785 } while (0)
786
787 #define anv_batch_emit(batch, cmd, name) \
788 for (struct cmd name = { __anv_cmd_header(cmd) }, \
789 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
790 __builtin_expect(_dst != NULL, 1); \
791 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
792 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
793 _dst = NULL; \
794 }))
795
796 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
797 .GraphicsDataTypeGFDT = 0, \
798 .LLCCacheabilityControlLLCCC = 0, \
799 .L3CacheabilityControlL3CC = 1, \
800 }
801
802 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
803 .LLCeLLCCacheabilityControlLLCCC = 0, \
804 .L3CacheabilityControlL3CC = 1, \
805 }
806
807 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
808 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
809 .TargetCache = L3DefertoPATforLLCeLLCselection, \
810 .AgeforQUADLRU = 0 \
811 }
812
813 /* Skylake: MOCS is now an index into an array of 62 different caching
814 * configurations programmed by the kernel.
815 */
816
817 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
818 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
819 .IndextoMOCSTables = 2 \
820 }
821
822 #define GEN9_MOCS_PTE { \
823 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
824 .IndextoMOCSTables = 1 \
825 }
826
827 struct anv_device_memory {
828 struct anv_bo bo;
829 uint32_t type_index;
830 VkDeviceSize map_size;
831 void * map;
832 };
833
834 /**
835 * Header for Vertex URB Entry (VUE)
836 */
837 struct anv_vue_header {
838 uint32_t Reserved;
839 uint32_t RTAIndex; /* RenderTargetArrayIndex */
840 uint32_t ViewportIndex;
841 float PointWidth;
842 };
843
844 struct anv_descriptor_set_binding_layout {
845 #ifndef NDEBUG
846 /* The type of the descriptors in this binding */
847 VkDescriptorType type;
848 #endif
849
850 /* Number of array elements in this binding */
851 uint16_t array_size;
852
853 /* Index into the flattend descriptor set */
854 uint16_t descriptor_index;
855
856 /* Index into the dynamic state array for a dynamic buffer */
857 int16_t dynamic_offset_index;
858
859 /* Index into the descriptor set buffer views */
860 int16_t buffer_index;
861
862 struct {
863 /* Index into the binding table for the associated surface */
864 int16_t surface_index;
865
866 /* Index into the sampler table for the associated sampler */
867 int16_t sampler_index;
868
869 /* Index into the image table for the associated image */
870 int16_t image_index;
871 } stage[MESA_SHADER_STAGES];
872
873 /* Immutable samplers (or NULL if no immutable samplers) */
874 struct anv_sampler **immutable_samplers;
875 };
876
877 struct anv_descriptor_set_layout {
878 /* Number of bindings in this descriptor set */
879 uint16_t binding_count;
880
881 /* Total size of the descriptor set with room for all array entries */
882 uint16_t size;
883
884 /* Shader stages affected by this descriptor set */
885 uint16_t shader_stages;
886
887 /* Number of buffers in this descriptor set */
888 uint16_t buffer_count;
889
890 /* Number of dynamic offsets used by this descriptor set */
891 uint16_t dynamic_offset_count;
892
893 /* Bindings in this descriptor set */
894 struct anv_descriptor_set_binding_layout binding[0];
895 };
896
897 struct anv_descriptor {
898 VkDescriptorType type;
899
900 union {
901 struct {
902 struct anv_image_view *image_view;
903 struct anv_sampler *sampler;
904 };
905
906 struct anv_buffer_view *buffer_view;
907 };
908 };
909
910 struct anv_descriptor_set {
911 const struct anv_descriptor_set_layout *layout;
912 uint32_t size;
913 uint32_t buffer_count;
914 struct anv_buffer_view *buffer_views;
915 struct anv_descriptor descriptors[0];
916 };
917
918 struct anv_buffer_view {
919 enum isl_format format; /**< VkBufferViewCreateInfo::format */
920 struct anv_bo *bo;
921 uint32_t offset; /**< Offset into bo. */
922 uint64_t range; /**< VkBufferViewCreateInfo::range */
923
924 struct anv_state surface_state;
925 struct anv_state storage_surface_state;
926 struct anv_state writeonly_storage_surface_state;
927
928 struct brw_image_param storage_image_param;
929 };
930
931 struct anv_descriptor_pool {
932 uint32_t size;
933 uint32_t next;
934 uint32_t free_list;
935
936 struct anv_state_stream surface_state_stream;
937 void *surface_state_free_list;
938
939 char data[0];
940 };
941
942 size_t
943 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
944
945 void
946 anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
947 VkDescriptorType type,
948 VkImageView _image_view,
949 VkSampler _sampler,
950 uint32_t binding,
951 uint32_t element);
952
953 void
954 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set *set,
955 VkDescriptorType type,
956 struct anv_buffer_view *buffer_view,
957 uint32_t binding,
958 uint32_t element);
959
960 void
961 anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
962 struct anv_device *device,
963 struct anv_state_stream *alloc_stream,
964 VkDescriptorType type,
965 struct anv_buffer *buffer,
966 uint32_t binding,
967 uint32_t element,
968 VkDeviceSize offset,
969 VkDeviceSize range);
970
971 VkResult
972 anv_descriptor_set_create(struct anv_device *device,
973 struct anv_descriptor_pool *pool,
974 const struct anv_descriptor_set_layout *layout,
975 struct anv_descriptor_set **out_set);
976
977 void
978 anv_descriptor_set_destroy(struct anv_device *device,
979 struct anv_descriptor_pool *pool,
980 struct anv_descriptor_set *set);
981
982 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
983
984 struct anv_pipeline_binding {
985 /* The descriptor set this surface corresponds to. The special value of
986 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
987 * to a color attachment and not a regular descriptor.
988 */
989 uint8_t set;
990
991 /* Binding in the descriptor set */
992 uint8_t binding;
993
994 /* Index in the binding */
995 uint8_t index;
996
997 /* Input attachment index (relative to the subpass) */
998 uint8_t input_attachment_index;
999
1000 /* For a storage image, whether it is write-only */
1001 bool write_only;
1002 };
1003
1004 struct anv_pipeline_layout {
1005 struct {
1006 struct anv_descriptor_set_layout *layout;
1007 uint32_t dynamic_offset_start;
1008 } set[MAX_SETS];
1009
1010 uint32_t num_sets;
1011
1012 struct {
1013 bool has_dynamic_offsets;
1014 } stage[MESA_SHADER_STAGES];
1015
1016 unsigned char sha1[20];
1017 };
1018
1019 struct anv_buffer {
1020 struct anv_device * device;
1021 VkDeviceSize size;
1022
1023 VkBufferUsageFlags usage;
1024
1025 /* Set when bound */
1026 struct anv_bo * bo;
1027 VkDeviceSize offset;
1028 };
1029
1030 enum anv_cmd_dirty_bits {
1031 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1032 ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1033 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1034 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1035 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1036 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1037 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1038 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1039 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1040 ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
1041 ANV_CMD_DIRTY_PIPELINE = 1 << 9,
1042 ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
1043 ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
1044 };
1045 typedef uint32_t anv_cmd_dirty_mask_t;
1046
1047 enum anv_pipe_bits {
1048 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
1049 ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
1050 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
1051 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
1052 ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
1053 ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
1054 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
1055 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
1056 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
1057 ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
1058 ANV_PIPE_CS_STALL_BIT = (1 << 20),
1059
1060 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1061 * a flush has happened but not a CS stall. The next time we do any sort
1062 * of invalidation we need to insert a CS stall at that time. Otherwise,
1063 * we would have to CS stall on every flush which could be bad.
1064 */
1065 ANV_PIPE_NEEDS_CS_STALL_BIT = (1 << 21),
1066 };
1067
1068 #define ANV_PIPE_FLUSH_BITS ( \
1069 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1070 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1071 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1072
1073 #define ANV_PIPE_STALL_BITS ( \
1074 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1075 ANV_PIPE_DEPTH_STALL_BIT | \
1076 ANV_PIPE_CS_STALL_BIT)
1077
1078 #define ANV_PIPE_INVALIDATE_BITS ( \
1079 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1080 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1081 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1082 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1083 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1084 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1085
1086 struct anv_vertex_binding {
1087 struct anv_buffer * buffer;
1088 VkDeviceSize offset;
1089 };
1090
1091 struct anv_push_constants {
1092 /* Current allocated size of this push constants data structure.
1093 * Because a decent chunk of it may not be used (images on SKL, for
1094 * instance), we won't actually allocate the entire structure up-front.
1095 */
1096 uint32_t size;
1097
1098 /* Push constant data provided by the client through vkPushConstants */
1099 uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
1100
1101 /* Our hardware only provides zero-based vertex and instance id so, in
1102 * order to satisfy the vulkan requirements, we may have to push one or
1103 * both of these into the shader.
1104 */
1105 uint32_t base_vertex;
1106 uint32_t base_instance;
1107
1108 /* Offsets and ranges for dynamically bound buffers */
1109 struct {
1110 uint32_t offset;
1111 uint32_t range;
1112 } dynamic[MAX_DYNAMIC_BUFFERS];
1113
1114 /* Image data for image_load_store on pre-SKL */
1115 struct brw_image_param images[MAX_IMAGES];
1116 };
1117
1118 struct anv_dynamic_state {
1119 struct {
1120 uint32_t count;
1121 VkViewport viewports[MAX_VIEWPORTS];
1122 } viewport;
1123
1124 struct {
1125 uint32_t count;
1126 VkRect2D scissors[MAX_SCISSORS];
1127 } scissor;
1128
1129 float line_width;
1130
1131 struct {
1132 float bias;
1133 float clamp;
1134 float slope;
1135 } depth_bias;
1136
1137 float blend_constants[4];
1138
1139 struct {
1140 float min;
1141 float max;
1142 } depth_bounds;
1143
1144 struct {
1145 uint32_t front;
1146 uint32_t back;
1147 } stencil_compare_mask;
1148
1149 struct {
1150 uint32_t front;
1151 uint32_t back;
1152 } stencil_write_mask;
1153
1154 struct {
1155 uint32_t front;
1156 uint32_t back;
1157 } stencil_reference;
1158 };
1159
1160 extern const struct anv_dynamic_state default_dynamic_state;
1161
1162 void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
1163 const struct anv_dynamic_state *src,
1164 uint32_t copy_mask);
1165
1166 /**
1167 * Attachment state when recording a renderpass instance.
1168 *
1169 * The clear value is valid only if there exists a pending clear.
1170 */
1171 struct anv_attachment_state {
1172 enum isl_aux_usage aux_usage;
1173 enum isl_aux_usage input_aux_usage;
1174 struct anv_state color_rt_state;
1175 struct anv_state input_att_state;
1176
1177 VkImageLayout current_layout;
1178 VkImageAspectFlags pending_clear_aspects;
1179 bool fast_clear;
1180 VkClearValue clear_value;
1181 bool clear_color_is_zero_one;
1182 };
1183
1184 /** State required while building cmd buffer */
1185 struct anv_cmd_state {
1186 /* PIPELINE_SELECT.PipelineSelection */
1187 uint32_t current_pipeline;
1188 const struct gen_l3_config * current_l3_config;
1189 uint32_t vb_dirty;
1190 anv_cmd_dirty_mask_t dirty;
1191 anv_cmd_dirty_mask_t compute_dirty;
1192 enum anv_pipe_bits pending_pipe_bits;
1193 uint32_t num_workgroups_offset;
1194 struct anv_bo *num_workgroups_bo;
1195 VkShaderStageFlags descriptors_dirty;
1196 VkShaderStageFlags push_constants_dirty;
1197 uint32_t scratch_size;
1198 struct anv_pipeline * pipeline;
1199 struct anv_pipeline * compute_pipeline;
1200 struct anv_framebuffer * framebuffer;
1201 struct anv_render_pass * pass;
1202 struct anv_subpass * subpass;
1203 VkRect2D render_area;
1204 uint32_t restart_index;
1205 struct anv_vertex_binding vertex_bindings[MAX_VBS];
1206 struct anv_descriptor_set * descriptors[MAX_SETS];
1207 VkShaderStageFlags push_constant_stages;
1208 struct anv_push_constants * push_constants[MESA_SHADER_STAGES];
1209 struct anv_state binding_tables[MESA_SHADER_STAGES];
1210 struct anv_state samplers[MESA_SHADER_STAGES];
1211 struct anv_dynamic_state dynamic;
1212 bool need_query_wa;
1213
1214 /**
1215 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1216 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1217 * and before invoking the secondary in ExecuteCommands.
1218 */
1219 bool pma_fix_enabled;
1220
1221 /**
1222 * Whether or not we know for certain that HiZ is enabled for the current
1223 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1224 * enabled or not, this will be false.
1225 */
1226 bool hiz_enabled;
1227
1228 /**
1229 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1230 * valid only when recording a render pass instance.
1231 */
1232 struct anv_attachment_state * attachments;
1233
1234 /**
1235 * Surface states for color render targets. These are stored in a single
1236 * flat array. For depth-stencil attachments, the surface state is simply
1237 * left blank.
1238 */
1239 struct anv_state render_pass_states;
1240
1241 /**
1242 * A null surface state of the right size to match the framebuffer. This
1243 * is one of the states in render_pass_states.
1244 */
1245 struct anv_state null_surface_state;
1246
1247 struct {
1248 struct anv_buffer * index_buffer;
1249 uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1250 uint32_t index_offset;
1251 } gen7;
1252 };
1253
1254 struct anv_cmd_pool {
1255 VkAllocationCallbacks alloc;
1256 struct list_head cmd_buffers;
1257 };
1258
1259 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1260
1261 enum anv_cmd_buffer_exec_mode {
1262 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
1263 ANV_CMD_BUFFER_EXEC_MODE_EMIT,
1264 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
1265 ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
1266 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
1267 };
1268
1269 struct anv_cmd_buffer {
1270 VK_LOADER_DATA _loader_data;
1271
1272 struct anv_device * device;
1273
1274 struct anv_cmd_pool * pool;
1275 struct list_head pool_link;
1276
1277 struct anv_batch batch;
1278
1279 /* Fields required for the actual chain of anv_batch_bo's.
1280 *
1281 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1282 */
1283 struct list_head batch_bos;
1284 enum anv_cmd_buffer_exec_mode exec_mode;
1285
1286 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1287 * referenced by this command buffer
1288 *
1289 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1290 */
1291 struct u_vector seen_bbos;
1292
1293 /* A vector of int32_t's for every block of binding tables.
1294 *
1295 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1296 */
1297 struct u_vector bt_blocks;
1298 uint32_t bt_next;
1299
1300 struct anv_reloc_list surface_relocs;
1301 /** Last seen surface state block pool center bo offset */
1302 uint32_t last_ss_pool_center;
1303
1304 /* Serial for tracking buffer completion */
1305 uint32_t serial;
1306
1307 /* Stream objects for storing temporary data */
1308 struct anv_state_stream surface_state_stream;
1309 struct anv_state_stream dynamic_state_stream;
1310
1311 VkCommandBufferUsageFlags usage_flags;
1312 VkCommandBufferLevel level;
1313
1314 struct anv_cmd_state state;
1315 };
1316
1317 VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1318 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1319 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1320 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
1321 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
1322 struct anv_cmd_buffer *secondary);
1323 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
1324 VkResult anv_cmd_buffer_execbuf(struct anv_device *device,
1325 struct anv_cmd_buffer *cmd_buffer);
1326
1327 VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
1328
1329 VkResult
1330 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
1331 gl_shader_stage stage, uint32_t size);
1332 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1333 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1334 (offsetof(struct anv_push_constants, field) + \
1335 sizeof(cmd_buffer->state.push_constants[0]->field)))
1336
1337 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
1338 const void *data, uint32_t size, uint32_t alignment);
1339 struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
1340 uint32_t *a, uint32_t *b,
1341 uint32_t dwords, uint32_t alignment);
1342
1343 struct anv_address
1344 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
1345 struct anv_state
1346 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
1347 uint32_t entries, uint32_t *state_offset);
1348 struct anv_state
1349 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
1350 struct anv_state
1351 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
1352 uint32_t size, uint32_t alignment);
1353
1354 VkResult
1355 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
1356
1357 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
1358 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
1359 bool depth_clamp_enable);
1360 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
1361
1362 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
1363 struct anv_render_pass *pass,
1364 struct anv_framebuffer *framebuffer,
1365 const VkClearValue *clear_values);
1366
1367 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
1368
1369 struct anv_state
1370 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
1371 gl_shader_stage stage);
1372 struct anv_state
1373 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
1374
1375 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer *cmd_buffer);
1376 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer);
1377
1378 const struct anv_image_view *
1379 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
1380
1381 struct anv_state
1382 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
1383 uint32_t num_entries,
1384 uint32_t *state_offset);
1385
1386 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
1387
1388 enum anv_fence_state {
1389 /** Indicates that this is a new (or newly reset fence) */
1390 ANV_FENCE_STATE_RESET,
1391
1392 /** Indicates that this fence has been submitted to the GPU but is still
1393 * (as far as we know) in use by the GPU.
1394 */
1395 ANV_FENCE_STATE_SUBMITTED,
1396
1397 ANV_FENCE_STATE_SIGNALED,
1398 };
1399
1400 struct anv_fence {
1401 struct anv_bo bo;
1402 struct drm_i915_gem_execbuffer2 execbuf;
1403 struct drm_i915_gem_exec_object2 exec2_objects[1];
1404 enum anv_fence_state state;
1405 };
1406
1407 struct anv_event {
1408 uint64_t semaphore;
1409 struct anv_state state;
1410 };
1411
1412 struct anv_shader_module {
1413 unsigned char sha1[20];
1414 uint32_t size;
1415 char data[0];
1416 };
1417
1418 void anv_hash_shader(unsigned char *hash, const void *key, size_t key_size,
1419 struct anv_shader_module *module,
1420 const char *entrypoint,
1421 const struct anv_pipeline_layout *pipeline_layout,
1422 const VkSpecializationInfo *spec_info);
1423
1424 static inline gl_shader_stage
1425 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1426 {
1427 assert(__builtin_popcount(vk_stage) == 1);
1428 return ffs(vk_stage) - 1;
1429 }
1430
1431 static inline VkShaderStageFlagBits
1432 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1433 {
1434 return (1 << mesa_stage);
1435 }
1436
1437 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1438
1439 #define anv_foreach_stage(stage, stage_bits) \
1440 for (gl_shader_stage stage, \
1441 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1442 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1443 __tmp &= ~(1 << (stage)))
1444
1445 struct anv_pipeline_bind_map {
1446 uint32_t surface_count;
1447 uint32_t sampler_count;
1448 uint32_t image_count;
1449
1450 struct anv_pipeline_binding * surface_to_descriptor;
1451 struct anv_pipeline_binding * sampler_to_descriptor;
1452 };
1453
1454 struct anv_shader_bin_key {
1455 uint32_t size;
1456 uint8_t data[0];
1457 };
1458
1459 struct anv_shader_bin {
1460 uint32_t ref_cnt;
1461
1462 const struct anv_shader_bin_key *key;
1463
1464 struct anv_state kernel;
1465 uint32_t kernel_size;
1466
1467 const struct brw_stage_prog_data *prog_data;
1468 uint32_t prog_data_size;
1469
1470 struct anv_pipeline_bind_map bind_map;
1471
1472 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1473 };
1474
1475 struct anv_shader_bin *
1476 anv_shader_bin_create(struct anv_device *device,
1477 const void *key, uint32_t key_size,
1478 const void *kernel, uint32_t kernel_size,
1479 const struct brw_stage_prog_data *prog_data,
1480 uint32_t prog_data_size, const void *prog_data_param,
1481 const struct anv_pipeline_bind_map *bind_map);
1482
1483 void
1484 anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
1485
1486 static inline void
1487 anv_shader_bin_ref(struct anv_shader_bin *shader)
1488 {
1489 assert(shader->ref_cnt >= 1);
1490 __sync_fetch_and_add(&shader->ref_cnt, 1);
1491 }
1492
1493 static inline void
1494 anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
1495 {
1496 assert(shader->ref_cnt >= 1);
1497 if (__sync_fetch_and_add(&shader->ref_cnt, -1) == 1)
1498 anv_shader_bin_destroy(device, shader);
1499 }
1500
1501 struct anv_pipeline {
1502 struct anv_device * device;
1503 struct anv_batch batch;
1504 uint32_t batch_data[512];
1505 struct anv_reloc_list batch_relocs;
1506 uint32_t dynamic_state_mask;
1507 struct anv_dynamic_state dynamic_state;
1508
1509 struct anv_pipeline_layout * layout;
1510
1511 bool needs_data_cache;
1512
1513 struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
1514
1515 struct {
1516 const struct gen_l3_config * l3_config;
1517 uint32_t total_size;
1518 } urb;
1519
1520 VkShaderStageFlags active_stages;
1521 struct anv_state blend_state;
1522
1523 uint32_t vb_used;
1524 uint32_t binding_stride[MAX_VBS];
1525 bool instancing_enable[MAX_VBS];
1526 bool primitive_restart;
1527 uint32_t topology;
1528
1529 uint32_t cs_right_mask;
1530
1531 bool writes_depth;
1532 bool depth_test_enable;
1533 bool writes_stencil;
1534 bool stencil_test_enable;
1535 bool depth_clamp_enable;
1536 bool kill_pixel;
1537
1538 struct {
1539 uint32_t sf[7];
1540 uint32_t depth_stencil_state[3];
1541 } gen7;
1542
1543 struct {
1544 uint32_t sf[4];
1545 uint32_t raster[5];
1546 uint32_t wm_depth_stencil[3];
1547 } gen8;
1548
1549 struct {
1550 uint32_t wm_depth_stencil[4];
1551 } gen9;
1552
1553 uint32_t interface_descriptor_data[8];
1554 };
1555
1556 static inline bool
1557 anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
1558 gl_shader_stage stage)
1559 {
1560 return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
1561 }
1562
1563 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1564 static inline const struct brw_##prefix##_prog_data * \
1565 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
1566 { \
1567 if (anv_pipeline_has_stage(pipeline, stage)) { \
1568 return (const struct brw_##prefix##_prog_data *) \
1569 pipeline->shaders[stage]->prog_data; \
1570 } else { \
1571 return NULL; \
1572 } \
1573 }
1574
1575 ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
1576 ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
1577 ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
1578 ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
1579 ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
1580 ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
1581
1582 static inline const struct brw_vue_prog_data *
1583 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
1584 {
1585 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
1586 return &get_gs_prog_data(pipeline)->base;
1587 else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
1588 return &get_tes_prog_data(pipeline)->base;
1589 else
1590 return &get_vs_prog_data(pipeline)->base;
1591 }
1592
1593 VkResult
1594 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
1595 struct anv_pipeline_cache *cache,
1596 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1597 const VkAllocationCallbacks *alloc);
1598
1599 VkResult
1600 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
1601 struct anv_pipeline_cache *cache,
1602 const VkComputePipelineCreateInfo *info,
1603 struct anv_shader_module *module,
1604 const char *entrypoint,
1605 const VkSpecializationInfo *spec_info);
1606
1607 struct anv_format {
1608 enum isl_format isl_format:16;
1609 struct isl_swizzle swizzle;
1610 };
1611
1612 struct anv_format
1613 anv_get_format(const struct gen_device_info *devinfo, VkFormat format,
1614 VkImageAspectFlags aspect, VkImageTiling tiling);
1615
1616 static inline enum isl_format
1617 anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
1618 VkImageAspectFlags aspect, VkImageTiling tiling)
1619 {
1620 return anv_get_format(devinfo, vk_format, aspect, tiling).isl_format;
1621 }
1622
1623 static inline struct isl_swizzle
1624 anv_swizzle_for_render(struct isl_swizzle swizzle)
1625 {
1626 /* Sometimes the swizzle will have alpha map to one. We do this to fake
1627 * RGB as RGBA for texturing
1628 */
1629 assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
1630 swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
1631
1632 /* But it doesn't matter what we render to that channel */
1633 swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
1634
1635 return swizzle;
1636 }
1637
1638 void
1639 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
1640
1641 /**
1642 * Subsurface of an anv_image.
1643 */
1644 struct anv_surface {
1645 /** Valid only if isl_surf::size > 0. */
1646 struct isl_surf isl;
1647
1648 /**
1649 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1650 */
1651 uint32_t offset;
1652 };
1653
1654 struct anv_image {
1655 VkImageType type;
1656 /* The original VkFormat provided by the client. This may not match any
1657 * of the actual surface formats.
1658 */
1659 VkFormat vk_format;
1660 VkImageAspectFlags aspects;
1661 VkExtent3D extent;
1662 uint32_t levels;
1663 uint32_t array_size;
1664 uint32_t samples; /**< VkImageCreateInfo::samples */
1665 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1666 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1667
1668 VkDeviceSize size;
1669 uint32_t alignment;
1670
1671 /* Set when bound */
1672 struct anv_bo *bo;
1673 VkDeviceSize offset;
1674
1675 /**
1676 * Image subsurfaces
1677 *
1678 * For each foo, anv_image::foo_surface is valid if and only if
1679 * anv_image::aspects has a foo aspect.
1680 *
1681 * The hardware requires that the depth buffer and stencil buffer be
1682 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1683 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1684 * allocate the depth and stencil buffers as separate surfaces in the same
1685 * bo.
1686 */
1687 union {
1688 struct anv_surface color_surface;
1689
1690 struct {
1691 struct anv_surface depth_surface;
1692 struct anv_surface stencil_surface;
1693 };
1694 };
1695
1696 /**
1697 * For color images, this is the aux usage for this image when not used as a
1698 * color attachment.
1699 *
1700 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the image
1701 * has a HiZ buffer.
1702 */
1703 enum isl_aux_usage aux_usage;
1704
1705 struct anv_surface aux_surface;
1706 };
1707
1708 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
1709 static inline bool
1710 anv_can_sample_with_hiz(uint8_t gen, uint32_t samples)
1711 {
1712 return gen >= 8 && samples == 1;
1713 }
1714
1715 void
1716 anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,
1717 const struct anv_image *image,
1718 enum blorp_hiz_op op);
1719
1720 static inline uint32_t
1721 anv_get_layerCount(const struct anv_image *image,
1722 const VkImageSubresourceRange *range)
1723 {
1724 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1725 image->array_size - range->baseArrayLayer : range->layerCount;
1726 }
1727
1728 static inline uint32_t
1729 anv_get_levelCount(const struct anv_image *image,
1730 const VkImageSubresourceRange *range)
1731 {
1732 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1733 image->levels - range->baseMipLevel : range->levelCount;
1734 }
1735
1736
1737 struct anv_image_view {
1738 const struct anv_image *image; /**< VkImageViewCreateInfo::image */
1739 struct anv_bo *bo;
1740 uint32_t offset; /**< Offset into bo. */
1741
1742 struct isl_view isl;
1743
1744 VkImageAspectFlags aspect_mask;
1745 VkFormat vk_format;
1746 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1747
1748 /** RENDER_SURFACE_STATE when using image as a sampler surface. */
1749 struct anv_state sampler_surface_state;
1750
1751 /**
1752 * RENDER_SURFACE_STATE when using image as a storage image. Separate states
1753 * for write-only and readable, using the real format for write-only and the
1754 * lowered format for readable.
1755 */
1756 struct anv_state storage_surface_state;
1757 struct anv_state writeonly_storage_surface_state;
1758
1759 struct brw_image_param storage_image_param;
1760 };
1761
1762 struct anv_image_create_info {
1763 const VkImageCreateInfo *vk_info;
1764
1765 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
1766 isl_tiling_flags_t isl_tiling_flags;
1767
1768 uint32_t stride;
1769 };
1770
1771 VkResult anv_image_create(VkDevice _device,
1772 const struct anv_image_create_info *info,
1773 const VkAllocationCallbacks* alloc,
1774 VkImage *pImage);
1775
1776 const struct anv_surface *
1777 anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
1778 VkImageAspectFlags aspect_mask);
1779
1780 enum isl_format
1781 anv_isl_format_for_descriptor_type(VkDescriptorType type);
1782
1783 static inline struct VkExtent3D
1784 anv_sanitize_image_extent(const VkImageType imageType,
1785 const struct VkExtent3D imageExtent)
1786 {
1787 switch (imageType) {
1788 case VK_IMAGE_TYPE_1D:
1789 return (VkExtent3D) { imageExtent.width, 1, 1 };
1790 case VK_IMAGE_TYPE_2D:
1791 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1792 case VK_IMAGE_TYPE_3D:
1793 return imageExtent;
1794 default:
1795 unreachable("invalid image type");
1796 }
1797 }
1798
1799 static inline struct VkOffset3D
1800 anv_sanitize_image_offset(const VkImageType imageType,
1801 const struct VkOffset3D imageOffset)
1802 {
1803 switch (imageType) {
1804 case VK_IMAGE_TYPE_1D:
1805 return (VkOffset3D) { imageOffset.x, 0, 0 };
1806 case VK_IMAGE_TYPE_2D:
1807 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1808 case VK_IMAGE_TYPE_3D:
1809 return imageOffset;
1810 default:
1811 unreachable("invalid image type");
1812 }
1813 }
1814
1815
1816 void anv_fill_buffer_surface_state(struct anv_device *device,
1817 struct anv_state state,
1818 enum isl_format format,
1819 uint32_t offset, uint32_t range,
1820 uint32_t stride);
1821
1822 void anv_image_view_fill_image_param(struct anv_device *device,
1823 struct anv_image_view *view,
1824 struct brw_image_param *param);
1825 void anv_buffer_view_fill_image_param(struct anv_device *device,
1826 struct anv_buffer_view *view,
1827 struct brw_image_param *param);
1828
1829 struct anv_sampler {
1830 uint32_t state[4];
1831 };
1832
1833 struct anv_framebuffer {
1834 uint32_t width;
1835 uint32_t height;
1836 uint32_t layers;
1837
1838 uint32_t attachment_count;
1839 struct anv_image_view * attachments[0];
1840 };
1841
1842 struct anv_subpass {
1843 uint32_t input_count;
1844 uint32_t * input_attachments;
1845 uint32_t color_count;
1846 uint32_t * color_attachments;
1847 uint32_t * resolve_attachments;
1848
1849 /* TODO: Consider storing the depth/stencil VkAttachmentReference
1850 * instead of its two structure members (below) individually.
1851 */
1852 uint32_t depth_stencil_attachment;
1853 VkImageLayout depth_stencil_layout;
1854
1855 /** Subpass has a depth/stencil self-dependency */
1856 bool has_ds_self_dep;
1857
1858 /** Subpass has at least one resolve attachment */
1859 bool has_resolve;
1860 };
1861
1862 enum anv_subpass_usage {
1863 ANV_SUBPASS_USAGE_DRAW = (1 << 0),
1864 ANV_SUBPASS_USAGE_INPUT = (1 << 1),
1865 ANV_SUBPASS_USAGE_RESOLVE_SRC = (1 << 2),
1866 ANV_SUBPASS_USAGE_RESOLVE_DST = (1 << 3),
1867 };
1868
1869 struct anv_render_pass_attachment {
1870 /* TODO: Consider using VkAttachmentDescription instead of storing each of
1871 * its members individually.
1872 */
1873 VkFormat format;
1874 uint32_t samples;
1875 VkImageUsageFlags usage;
1876 VkAttachmentLoadOp load_op;
1877 VkAttachmentStoreOp store_op;
1878 VkAttachmentLoadOp stencil_load_op;
1879 VkImageLayout initial_layout;
1880 VkImageLayout final_layout;
1881
1882 /* An array, indexed by subpass id, of how the attachment will be used. */
1883 enum anv_subpass_usage * subpass_usage;
1884
1885 /* The subpass id in which the attachment will be used last. */
1886 uint32_t last_subpass_idx;
1887 };
1888
1889 struct anv_render_pass {
1890 uint32_t attachment_count;
1891 uint32_t subpass_count;
1892 uint32_t * subpass_attachments;
1893 enum anv_subpass_usage * subpass_usages;
1894 struct anv_render_pass_attachment * attachments;
1895 struct anv_subpass subpasses[0];
1896 };
1897
1898 struct anv_query_pool_slot {
1899 uint64_t begin;
1900 uint64_t end;
1901 uint64_t available;
1902 };
1903
1904 struct anv_query_pool {
1905 VkQueryType type;
1906 uint32_t slots;
1907 struct anv_bo bo;
1908 };
1909
1910 void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
1911 const char *name);
1912
1913 void anv_dump_image_to_ppm(struct anv_device *device,
1914 struct anv_image *image, unsigned miplevel,
1915 unsigned array_layer, VkImageAspectFlagBits aspect,
1916 const char *filename);
1917
1918 enum anv_dump_action {
1919 ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
1920 };
1921
1922 void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
1923 void anv_dump_finish(void);
1924
1925 void anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
1926 struct anv_framebuffer *fb);
1927
1928 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1929 \
1930 static inline struct __anv_type * \
1931 __anv_type ## _from_handle(__VkType _handle) \
1932 { \
1933 return (struct __anv_type *) _handle; \
1934 } \
1935 \
1936 static inline __VkType \
1937 __anv_type ## _to_handle(struct __anv_type *_obj) \
1938 { \
1939 return (__VkType) _obj; \
1940 }
1941
1942 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1943 \
1944 static inline struct __anv_type * \
1945 __anv_type ## _from_handle(__VkType _handle) \
1946 { \
1947 return (struct __anv_type *)(uintptr_t) _handle; \
1948 } \
1949 \
1950 static inline __VkType \
1951 __anv_type ## _to_handle(struct __anv_type *_obj) \
1952 { \
1953 return (__VkType)(uintptr_t) _obj; \
1954 }
1955
1956 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1957 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1958
1959 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
1960 ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
1961 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
1962 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
1963 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
1964
1965 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
1966 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
1967 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
1968 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
1969 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
1970 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
1971 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
1972 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
1973 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
1974 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
1975 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
1976 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
1977 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
1978 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
1979 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
1980 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
1981 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
1982 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
1983 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
1984
1985 /* Gen-specific function declarations */
1986 #ifdef genX
1987 # include "anv_genX.h"
1988 #else
1989 # define genX(x) gen7_##x
1990 # include "anv_genX.h"
1991 # undef genX
1992 # define genX(x) gen75_##x
1993 # include "anv_genX.h"
1994 # undef genX
1995 # define genX(x) gen8_##x
1996 # include "anv_genX.h"
1997 # undef genX
1998 # define genX(x) gen9_##x
1999 # include "anv_genX.h"
2000 # undef genX
2001 #endif
2002
2003 #endif /* ANV_PRIVATE_H */