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