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