anv: add VK_KHR_descriptor_update_template 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 enum anv_descriptor_template_entry_type {
954 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
955 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
956 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
957 };
958
959 struct anv_descriptor_template_entry {
960 /* The type of descriptor in this entry */
961 VkDescriptorType type;
962
963 /* Binding in the descriptor set */
964 uint32_t binding;
965
966 /* Offset at which to write into the descriptor set binding */
967 uint32_t array_element;
968
969 /* Number of elements to write into the descriptor set binding */
970 uint32_t array_count;
971
972 /* Offset into the user provided data */
973 size_t offset;
974
975 /* Stride between elements into the user provided data */
976 size_t stride;
977 };
978
979 struct anv_descriptor_update_template {
980 /* The descriptor set this template corresponds to. This value is only
981 * valid if the template was created with the templateType
982 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
983 */
984 uint8_t set;
985
986 /* Number of entries in this template */
987 uint32_t entry_count;
988
989 /* Entries of the template */
990 struct anv_descriptor_template_entry entries[0];
991 };
992
993 size_t
994 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
995
996 void
997 anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
998 VkDescriptorType type,
999 VkImageView _image_view,
1000 VkSampler _sampler,
1001 uint32_t binding,
1002 uint32_t element);
1003
1004 void
1005 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set *set,
1006 VkDescriptorType type,
1007 struct anv_buffer_view *buffer_view,
1008 uint32_t binding,
1009 uint32_t element);
1010
1011 void
1012 anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
1013 struct anv_device *device,
1014 struct anv_state_stream *alloc_stream,
1015 VkDescriptorType type,
1016 struct anv_buffer *buffer,
1017 uint32_t binding,
1018 uint32_t element,
1019 VkDeviceSize offset,
1020 VkDeviceSize range);
1021
1022 void
1023 anv_descriptor_set_write_template(struct anv_descriptor_set *set,
1024 struct anv_device *device,
1025 struct anv_state_stream *alloc_stream,
1026 const struct anv_descriptor_update_template *template,
1027 const void *data);
1028
1029 VkResult
1030 anv_descriptor_set_create(struct anv_device *device,
1031 struct anv_descriptor_pool *pool,
1032 const struct anv_descriptor_set_layout *layout,
1033 struct anv_descriptor_set **out_set);
1034
1035 void
1036 anv_descriptor_set_destroy(struct anv_device *device,
1037 struct anv_descriptor_pool *pool,
1038 struct anv_descriptor_set *set);
1039
1040 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1041
1042 struct anv_pipeline_binding {
1043 /* The descriptor set this surface corresponds to. The special value of
1044 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1045 * to a color attachment and not a regular descriptor.
1046 */
1047 uint8_t set;
1048
1049 /* Binding in the descriptor set */
1050 uint8_t binding;
1051
1052 /* Index in the binding */
1053 uint8_t index;
1054
1055 /* Input attachment index (relative to the subpass) */
1056 uint8_t input_attachment_index;
1057
1058 /* For a storage image, whether it is write-only */
1059 bool write_only;
1060 };
1061
1062 struct anv_pipeline_layout {
1063 struct {
1064 struct anv_descriptor_set_layout *layout;
1065 uint32_t dynamic_offset_start;
1066 } set[MAX_SETS];
1067
1068 uint32_t num_sets;
1069
1070 struct {
1071 bool has_dynamic_offsets;
1072 } stage[MESA_SHADER_STAGES];
1073
1074 unsigned char sha1[20];
1075 };
1076
1077 struct anv_buffer {
1078 struct anv_device * device;
1079 VkDeviceSize size;
1080
1081 VkBufferUsageFlags usage;
1082
1083 /* Set when bound */
1084 struct anv_bo * bo;
1085 VkDeviceSize offset;
1086 };
1087
1088 enum anv_cmd_dirty_bits {
1089 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1090 ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1091 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1092 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1093 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1094 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1095 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1096 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1097 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1098 ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
1099 ANV_CMD_DIRTY_PIPELINE = 1 << 9,
1100 ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
1101 ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
1102 };
1103 typedef uint32_t anv_cmd_dirty_mask_t;
1104
1105 enum anv_pipe_bits {
1106 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
1107 ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
1108 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
1109 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
1110 ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
1111 ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
1112 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
1113 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
1114 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
1115 ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
1116 ANV_PIPE_CS_STALL_BIT = (1 << 20),
1117
1118 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1119 * a flush has happened but not a CS stall. The next time we do any sort
1120 * of invalidation we need to insert a CS stall at that time. Otherwise,
1121 * we would have to CS stall on every flush which could be bad.
1122 */
1123 ANV_PIPE_NEEDS_CS_STALL_BIT = (1 << 21),
1124 };
1125
1126 #define ANV_PIPE_FLUSH_BITS ( \
1127 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1128 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1129 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1130
1131 #define ANV_PIPE_STALL_BITS ( \
1132 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1133 ANV_PIPE_DEPTH_STALL_BIT | \
1134 ANV_PIPE_CS_STALL_BIT)
1135
1136 #define ANV_PIPE_INVALIDATE_BITS ( \
1137 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1138 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1139 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1140 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1141 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1142 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1143
1144 struct anv_vertex_binding {
1145 struct anv_buffer * buffer;
1146 VkDeviceSize offset;
1147 };
1148
1149 struct anv_push_constants {
1150 /* Current allocated size of this push constants data structure.
1151 * Because a decent chunk of it may not be used (images on SKL, for
1152 * instance), we won't actually allocate the entire structure up-front.
1153 */
1154 uint32_t size;
1155
1156 /* Push constant data provided by the client through vkPushConstants */
1157 uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
1158
1159 /* Our hardware only provides zero-based vertex and instance id so, in
1160 * order to satisfy the vulkan requirements, we may have to push one or
1161 * both of these into the shader.
1162 */
1163 uint32_t base_vertex;
1164 uint32_t base_instance;
1165
1166 /* Offsets and ranges for dynamically bound buffers */
1167 struct {
1168 uint32_t offset;
1169 uint32_t range;
1170 } dynamic[MAX_DYNAMIC_BUFFERS];
1171
1172 /* Image data for image_load_store on pre-SKL */
1173 struct brw_image_param images[MAX_IMAGES];
1174 };
1175
1176 struct anv_dynamic_state {
1177 struct {
1178 uint32_t count;
1179 VkViewport viewports[MAX_VIEWPORTS];
1180 } viewport;
1181
1182 struct {
1183 uint32_t count;
1184 VkRect2D scissors[MAX_SCISSORS];
1185 } scissor;
1186
1187 float line_width;
1188
1189 struct {
1190 float bias;
1191 float clamp;
1192 float slope;
1193 } depth_bias;
1194
1195 float blend_constants[4];
1196
1197 struct {
1198 float min;
1199 float max;
1200 } depth_bounds;
1201
1202 struct {
1203 uint32_t front;
1204 uint32_t back;
1205 } stencil_compare_mask;
1206
1207 struct {
1208 uint32_t front;
1209 uint32_t back;
1210 } stencil_write_mask;
1211
1212 struct {
1213 uint32_t front;
1214 uint32_t back;
1215 } stencil_reference;
1216 };
1217
1218 extern const struct anv_dynamic_state default_dynamic_state;
1219
1220 void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
1221 const struct anv_dynamic_state *src,
1222 uint32_t copy_mask);
1223
1224 /**
1225 * Attachment state when recording a renderpass instance.
1226 *
1227 * The clear value is valid only if there exists a pending clear.
1228 */
1229 struct anv_attachment_state {
1230 enum isl_aux_usage aux_usage;
1231 enum isl_aux_usage input_aux_usage;
1232 struct anv_state color_rt_state;
1233 struct anv_state input_att_state;
1234
1235 VkImageLayout current_layout;
1236 VkImageAspectFlags pending_clear_aspects;
1237 bool fast_clear;
1238 VkClearValue clear_value;
1239 bool clear_color_is_zero_one;
1240 };
1241
1242 /** State required while building cmd buffer */
1243 struct anv_cmd_state {
1244 /* PIPELINE_SELECT.PipelineSelection */
1245 uint32_t current_pipeline;
1246 const struct gen_l3_config * current_l3_config;
1247 uint32_t vb_dirty;
1248 anv_cmd_dirty_mask_t dirty;
1249 anv_cmd_dirty_mask_t compute_dirty;
1250 enum anv_pipe_bits pending_pipe_bits;
1251 uint32_t num_workgroups_offset;
1252 struct anv_bo *num_workgroups_bo;
1253 VkShaderStageFlags descriptors_dirty;
1254 VkShaderStageFlags push_constants_dirty;
1255 uint32_t scratch_size;
1256 struct anv_pipeline * pipeline;
1257 struct anv_pipeline * compute_pipeline;
1258 struct anv_framebuffer * framebuffer;
1259 struct anv_render_pass * pass;
1260 struct anv_subpass * subpass;
1261 VkRect2D render_area;
1262 uint32_t restart_index;
1263 struct anv_vertex_binding vertex_bindings[MAX_VBS];
1264 struct anv_descriptor_set * descriptors[MAX_SETS];
1265 VkShaderStageFlags push_constant_stages;
1266 struct anv_push_constants * push_constants[MESA_SHADER_STAGES];
1267 struct anv_state binding_tables[MESA_SHADER_STAGES];
1268 struct anv_state samplers[MESA_SHADER_STAGES];
1269 struct anv_dynamic_state dynamic;
1270 bool need_query_wa;
1271
1272 struct anv_push_descriptor_set push_descriptor;
1273
1274 /**
1275 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1276 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1277 * and before invoking the secondary in ExecuteCommands.
1278 */
1279 bool pma_fix_enabled;
1280
1281 /**
1282 * Whether or not we know for certain that HiZ is enabled for the current
1283 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1284 * enabled or not, this will be false.
1285 */
1286 bool hiz_enabled;
1287
1288 /**
1289 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1290 * valid only when recording a render pass instance.
1291 */
1292 struct anv_attachment_state * attachments;
1293
1294 /**
1295 * Surface states for color render targets. These are stored in a single
1296 * flat array. For depth-stencil attachments, the surface state is simply
1297 * left blank.
1298 */
1299 struct anv_state render_pass_states;
1300
1301 /**
1302 * A null surface state of the right size to match the framebuffer. This
1303 * is one of the states in render_pass_states.
1304 */
1305 struct anv_state null_surface_state;
1306
1307 struct {
1308 struct anv_buffer * index_buffer;
1309 uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1310 uint32_t index_offset;
1311 } gen7;
1312 };
1313
1314 struct anv_cmd_pool {
1315 VkAllocationCallbacks alloc;
1316 struct list_head cmd_buffers;
1317 };
1318
1319 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1320
1321 enum anv_cmd_buffer_exec_mode {
1322 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
1323 ANV_CMD_BUFFER_EXEC_MODE_EMIT,
1324 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
1325 ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
1326 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
1327 };
1328
1329 struct anv_cmd_buffer {
1330 VK_LOADER_DATA _loader_data;
1331
1332 struct anv_device * device;
1333
1334 struct anv_cmd_pool * pool;
1335 struct list_head pool_link;
1336
1337 struct anv_batch batch;
1338
1339 /* Fields required for the actual chain of anv_batch_bo's.
1340 *
1341 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1342 */
1343 struct list_head batch_bos;
1344 enum anv_cmd_buffer_exec_mode exec_mode;
1345
1346 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1347 * referenced by this command buffer
1348 *
1349 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1350 */
1351 struct u_vector seen_bbos;
1352
1353 /* A vector of int32_t's for every block of binding tables.
1354 *
1355 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1356 */
1357 struct u_vector bt_blocks;
1358 uint32_t bt_next;
1359
1360 struct anv_reloc_list surface_relocs;
1361 /** Last seen surface state block pool center bo offset */
1362 uint32_t last_ss_pool_center;
1363
1364 /* Serial for tracking buffer completion */
1365 uint32_t serial;
1366
1367 /* Stream objects for storing temporary data */
1368 struct anv_state_stream surface_state_stream;
1369 struct anv_state_stream dynamic_state_stream;
1370
1371 VkCommandBufferUsageFlags usage_flags;
1372 VkCommandBufferLevel level;
1373
1374 struct anv_cmd_state state;
1375 };
1376
1377 VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1378 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1379 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
1380 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
1381 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
1382 struct anv_cmd_buffer *secondary);
1383 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
1384 VkResult anv_cmd_buffer_execbuf(struct anv_device *device,
1385 struct anv_cmd_buffer *cmd_buffer);
1386
1387 VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
1388
1389 VkResult
1390 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
1391 gl_shader_stage stage, uint32_t size);
1392 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1393 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1394 (offsetof(struct anv_push_constants, field) + \
1395 sizeof(cmd_buffer->state.push_constants[0]->field)))
1396
1397 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
1398 const void *data, uint32_t size, uint32_t alignment);
1399 struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
1400 uint32_t *a, uint32_t *b,
1401 uint32_t dwords, uint32_t alignment);
1402
1403 struct anv_address
1404 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
1405 struct anv_state
1406 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
1407 uint32_t entries, uint32_t *state_offset);
1408 struct anv_state
1409 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
1410 struct anv_state
1411 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
1412 uint32_t size, uint32_t alignment);
1413
1414 VkResult
1415 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
1416
1417 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
1418 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
1419 bool depth_clamp_enable);
1420 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
1421
1422 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
1423 struct anv_render_pass *pass,
1424 struct anv_framebuffer *framebuffer,
1425 const VkClearValue *clear_values);
1426
1427 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
1428
1429 struct anv_state
1430 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
1431 gl_shader_stage stage);
1432 struct anv_state
1433 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
1434
1435 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer *cmd_buffer);
1436 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer);
1437
1438 const struct anv_image_view *
1439 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
1440
1441 struct anv_state
1442 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
1443 uint32_t num_entries,
1444 uint32_t *state_offset);
1445
1446 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
1447
1448 enum anv_fence_state {
1449 /** Indicates that this is a new (or newly reset fence) */
1450 ANV_FENCE_STATE_RESET,
1451
1452 /** Indicates that this fence has been submitted to the GPU but is still
1453 * (as far as we know) in use by the GPU.
1454 */
1455 ANV_FENCE_STATE_SUBMITTED,
1456
1457 ANV_FENCE_STATE_SIGNALED,
1458 };
1459
1460 struct anv_fence {
1461 struct anv_bo bo;
1462 struct drm_i915_gem_execbuffer2 execbuf;
1463 struct drm_i915_gem_exec_object2 exec2_objects[1];
1464 enum anv_fence_state state;
1465 };
1466
1467 struct anv_event {
1468 uint64_t semaphore;
1469 struct anv_state state;
1470 };
1471
1472 struct anv_shader_module {
1473 unsigned char sha1[20];
1474 uint32_t size;
1475 char data[0];
1476 };
1477
1478 void anv_hash_shader(unsigned char *hash, const void *key, size_t key_size,
1479 struct anv_shader_module *module,
1480 const char *entrypoint,
1481 const struct anv_pipeline_layout *pipeline_layout,
1482 const VkSpecializationInfo *spec_info);
1483
1484 static inline gl_shader_stage
1485 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
1486 {
1487 assert(__builtin_popcount(vk_stage) == 1);
1488 return ffs(vk_stage) - 1;
1489 }
1490
1491 static inline VkShaderStageFlagBits
1492 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
1493 {
1494 return (1 << mesa_stage);
1495 }
1496
1497 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1498
1499 #define anv_foreach_stage(stage, stage_bits) \
1500 for (gl_shader_stage stage, \
1501 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1502 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1503 __tmp &= ~(1 << (stage)))
1504
1505 struct anv_pipeline_bind_map {
1506 uint32_t surface_count;
1507 uint32_t sampler_count;
1508 uint32_t image_count;
1509
1510 struct anv_pipeline_binding * surface_to_descriptor;
1511 struct anv_pipeline_binding * sampler_to_descriptor;
1512 };
1513
1514 struct anv_shader_bin_key {
1515 uint32_t size;
1516 uint8_t data[0];
1517 };
1518
1519 struct anv_shader_bin {
1520 uint32_t ref_cnt;
1521
1522 const struct anv_shader_bin_key *key;
1523
1524 struct anv_state kernel;
1525 uint32_t kernel_size;
1526
1527 const struct brw_stage_prog_data *prog_data;
1528 uint32_t prog_data_size;
1529
1530 struct anv_pipeline_bind_map bind_map;
1531
1532 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1533 };
1534
1535 struct anv_shader_bin *
1536 anv_shader_bin_create(struct anv_device *device,
1537 const void *key, uint32_t key_size,
1538 const void *kernel, uint32_t kernel_size,
1539 const struct brw_stage_prog_data *prog_data,
1540 uint32_t prog_data_size, const void *prog_data_param,
1541 const struct anv_pipeline_bind_map *bind_map);
1542
1543 void
1544 anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
1545
1546 static inline void
1547 anv_shader_bin_ref(struct anv_shader_bin *shader)
1548 {
1549 assert(shader->ref_cnt >= 1);
1550 __sync_fetch_and_add(&shader->ref_cnt, 1);
1551 }
1552
1553 static inline void
1554 anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
1555 {
1556 assert(shader->ref_cnt >= 1);
1557 if (__sync_fetch_and_add(&shader->ref_cnt, -1) == 1)
1558 anv_shader_bin_destroy(device, shader);
1559 }
1560
1561 struct anv_pipeline {
1562 struct anv_device * device;
1563 struct anv_batch batch;
1564 uint32_t batch_data[512];
1565 struct anv_reloc_list batch_relocs;
1566 uint32_t dynamic_state_mask;
1567 struct anv_dynamic_state dynamic_state;
1568
1569 struct anv_pipeline_layout * layout;
1570
1571 bool needs_data_cache;
1572
1573 struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
1574
1575 struct {
1576 const struct gen_l3_config * l3_config;
1577 uint32_t total_size;
1578 } urb;
1579
1580 VkShaderStageFlags active_stages;
1581 struct anv_state blend_state;
1582
1583 uint32_t vb_used;
1584 uint32_t binding_stride[MAX_VBS];
1585 bool instancing_enable[MAX_VBS];
1586 bool primitive_restart;
1587 uint32_t topology;
1588
1589 uint32_t cs_right_mask;
1590
1591 bool writes_depth;
1592 bool depth_test_enable;
1593 bool writes_stencil;
1594 bool stencil_test_enable;
1595 bool depth_clamp_enable;
1596 bool kill_pixel;
1597
1598 struct {
1599 uint32_t sf[7];
1600 uint32_t depth_stencil_state[3];
1601 } gen7;
1602
1603 struct {
1604 uint32_t sf[4];
1605 uint32_t raster[5];
1606 uint32_t wm_depth_stencil[3];
1607 } gen8;
1608
1609 struct {
1610 uint32_t wm_depth_stencil[4];
1611 } gen9;
1612
1613 uint32_t interface_descriptor_data[8];
1614 };
1615
1616 static inline bool
1617 anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
1618 gl_shader_stage stage)
1619 {
1620 return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
1621 }
1622
1623 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1624 static inline const struct brw_##prefix##_prog_data * \
1625 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
1626 { \
1627 if (anv_pipeline_has_stage(pipeline, stage)) { \
1628 return (const struct brw_##prefix##_prog_data *) \
1629 pipeline->shaders[stage]->prog_data; \
1630 } else { \
1631 return NULL; \
1632 } \
1633 }
1634
1635 ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
1636 ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
1637 ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
1638 ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
1639 ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
1640 ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
1641
1642 static inline const struct brw_vue_prog_data *
1643 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
1644 {
1645 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
1646 return &get_gs_prog_data(pipeline)->base;
1647 else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
1648 return &get_tes_prog_data(pipeline)->base;
1649 else
1650 return &get_vs_prog_data(pipeline)->base;
1651 }
1652
1653 VkResult
1654 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
1655 struct anv_pipeline_cache *cache,
1656 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1657 const VkAllocationCallbacks *alloc);
1658
1659 VkResult
1660 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
1661 struct anv_pipeline_cache *cache,
1662 const VkComputePipelineCreateInfo *info,
1663 struct anv_shader_module *module,
1664 const char *entrypoint,
1665 const VkSpecializationInfo *spec_info);
1666
1667 struct anv_format {
1668 enum isl_format isl_format:16;
1669 struct isl_swizzle swizzle;
1670 };
1671
1672 struct anv_format
1673 anv_get_format(const struct gen_device_info *devinfo, VkFormat format,
1674 VkImageAspectFlags aspect, VkImageTiling tiling);
1675
1676 static inline enum isl_format
1677 anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
1678 VkImageAspectFlags aspect, VkImageTiling tiling)
1679 {
1680 return anv_get_format(devinfo, vk_format, aspect, tiling).isl_format;
1681 }
1682
1683 static inline struct isl_swizzle
1684 anv_swizzle_for_render(struct isl_swizzle swizzle)
1685 {
1686 /* Sometimes the swizzle will have alpha map to one. We do this to fake
1687 * RGB as RGBA for texturing
1688 */
1689 assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
1690 swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
1691
1692 /* But it doesn't matter what we render to that channel */
1693 swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
1694
1695 return swizzle;
1696 }
1697
1698 void
1699 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
1700
1701 /**
1702 * Subsurface of an anv_image.
1703 */
1704 struct anv_surface {
1705 /** Valid only if isl_surf::size > 0. */
1706 struct isl_surf isl;
1707
1708 /**
1709 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1710 */
1711 uint32_t offset;
1712 };
1713
1714 struct anv_image {
1715 VkImageType type;
1716 /* The original VkFormat provided by the client. This may not match any
1717 * of the actual surface formats.
1718 */
1719 VkFormat vk_format;
1720 VkImageAspectFlags aspects;
1721 VkExtent3D extent;
1722 uint32_t levels;
1723 uint32_t array_size;
1724 uint32_t samples; /**< VkImageCreateInfo::samples */
1725 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1726 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
1727
1728 VkDeviceSize size;
1729 uint32_t alignment;
1730
1731 /* Set when bound */
1732 struct anv_bo *bo;
1733 VkDeviceSize offset;
1734
1735 /**
1736 * Image subsurfaces
1737 *
1738 * For each foo, anv_image::foo_surface is valid if and only if
1739 * anv_image::aspects has a foo aspect.
1740 *
1741 * The hardware requires that the depth buffer and stencil buffer be
1742 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1743 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1744 * allocate the depth and stencil buffers as separate surfaces in the same
1745 * bo.
1746 */
1747 union {
1748 struct anv_surface color_surface;
1749
1750 struct {
1751 struct anv_surface depth_surface;
1752 struct anv_surface stencil_surface;
1753 };
1754 };
1755
1756 /**
1757 * For color images, this is the aux usage for this image when not used as a
1758 * color attachment.
1759 *
1760 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the image
1761 * has a HiZ buffer.
1762 */
1763 enum isl_aux_usage aux_usage;
1764
1765 struct anv_surface aux_surface;
1766 };
1767
1768 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
1769 static inline bool
1770 anv_can_sample_with_hiz(uint8_t gen, uint32_t samples)
1771 {
1772 return gen >= 8 && samples == 1;
1773 }
1774
1775 void
1776 anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,
1777 const struct anv_image *image,
1778 enum blorp_hiz_op op);
1779
1780 static inline uint32_t
1781 anv_get_layerCount(const struct anv_image *image,
1782 const VkImageSubresourceRange *range)
1783 {
1784 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
1785 image->array_size - range->baseArrayLayer : range->layerCount;
1786 }
1787
1788 static inline uint32_t
1789 anv_get_levelCount(const struct anv_image *image,
1790 const VkImageSubresourceRange *range)
1791 {
1792 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
1793 image->levels - range->baseMipLevel : range->levelCount;
1794 }
1795
1796
1797 struct anv_image_view {
1798 const struct anv_image *image; /**< VkImageViewCreateInfo::image */
1799 struct anv_bo *bo;
1800 uint32_t offset; /**< Offset into bo. */
1801
1802 struct isl_view isl;
1803
1804 VkImageAspectFlags aspect_mask;
1805 VkFormat vk_format;
1806 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1807
1808 /** RENDER_SURFACE_STATE when using image as a sampler surface. */
1809 struct anv_state sampler_surface_state;
1810
1811 /**
1812 * RENDER_SURFACE_STATE when using image as a storage image. Separate states
1813 * for write-only and readable, using the real format for write-only and the
1814 * lowered format for readable.
1815 */
1816 struct anv_state storage_surface_state;
1817 struct anv_state writeonly_storage_surface_state;
1818
1819 struct brw_image_param storage_image_param;
1820 };
1821
1822 struct anv_image_create_info {
1823 const VkImageCreateInfo *vk_info;
1824
1825 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
1826 isl_tiling_flags_t isl_tiling_flags;
1827
1828 uint32_t stride;
1829 };
1830
1831 VkResult anv_image_create(VkDevice _device,
1832 const struct anv_image_create_info *info,
1833 const VkAllocationCallbacks* alloc,
1834 VkImage *pImage);
1835
1836 const struct anv_surface *
1837 anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
1838 VkImageAspectFlags aspect_mask);
1839
1840 enum isl_format
1841 anv_isl_format_for_descriptor_type(VkDescriptorType type);
1842
1843 static inline struct VkExtent3D
1844 anv_sanitize_image_extent(const VkImageType imageType,
1845 const struct VkExtent3D imageExtent)
1846 {
1847 switch (imageType) {
1848 case VK_IMAGE_TYPE_1D:
1849 return (VkExtent3D) { imageExtent.width, 1, 1 };
1850 case VK_IMAGE_TYPE_2D:
1851 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1852 case VK_IMAGE_TYPE_3D:
1853 return imageExtent;
1854 default:
1855 unreachable("invalid image type");
1856 }
1857 }
1858
1859 static inline struct VkOffset3D
1860 anv_sanitize_image_offset(const VkImageType imageType,
1861 const struct VkOffset3D imageOffset)
1862 {
1863 switch (imageType) {
1864 case VK_IMAGE_TYPE_1D:
1865 return (VkOffset3D) { imageOffset.x, 0, 0 };
1866 case VK_IMAGE_TYPE_2D:
1867 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1868 case VK_IMAGE_TYPE_3D:
1869 return imageOffset;
1870 default:
1871 unreachable("invalid image type");
1872 }
1873 }
1874
1875
1876 void anv_fill_buffer_surface_state(struct anv_device *device,
1877 struct anv_state state,
1878 enum isl_format format,
1879 uint32_t offset, uint32_t range,
1880 uint32_t stride);
1881
1882 void anv_image_view_fill_image_param(struct anv_device *device,
1883 struct anv_image_view *view,
1884 struct brw_image_param *param);
1885 void anv_buffer_view_fill_image_param(struct anv_device *device,
1886 struct anv_buffer_view *view,
1887 struct brw_image_param *param);
1888
1889 struct anv_sampler {
1890 uint32_t state[4];
1891 };
1892
1893 struct anv_framebuffer {
1894 uint32_t width;
1895 uint32_t height;
1896 uint32_t layers;
1897
1898 uint32_t attachment_count;
1899 struct anv_image_view * attachments[0];
1900 };
1901
1902 struct anv_subpass {
1903 uint32_t input_count;
1904 uint32_t * input_attachments;
1905 uint32_t color_count;
1906 uint32_t * color_attachments;
1907 uint32_t * resolve_attachments;
1908
1909 /* TODO: Consider storing the depth/stencil VkAttachmentReference
1910 * instead of its two structure members (below) individually.
1911 */
1912 uint32_t depth_stencil_attachment;
1913 VkImageLayout depth_stencil_layout;
1914
1915 /** Subpass has a depth/stencil self-dependency */
1916 bool has_ds_self_dep;
1917
1918 /** Subpass has at least one resolve attachment */
1919 bool has_resolve;
1920 };
1921
1922 enum anv_subpass_usage {
1923 ANV_SUBPASS_USAGE_DRAW = (1 << 0),
1924 ANV_SUBPASS_USAGE_INPUT = (1 << 1),
1925 ANV_SUBPASS_USAGE_RESOLVE_SRC = (1 << 2),
1926 ANV_SUBPASS_USAGE_RESOLVE_DST = (1 << 3),
1927 };
1928
1929 struct anv_render_pass_attachment {
1930 /* TODO: Consider using VkAttachmentDescription instead of storing each of
1931 * its members individually.
1932 */
1933 VkFormat format;
1934 uint32_t samples;
1935 VkImageUsageFlags usage;
1936 VkAttachmentLoadOp load_op;
1937 VkAttachmentStoreOp store_op;
1938 VkAttachmentLoadOp stencil_load_op;
1939 VkImageLayout initial_layout;
1940 VkImageLayout final_layout;
1941
1942 /* An array, indexed by subpass id, of how the attachment will be used. */
1943 enum anv_subpass_usage * subpass_usage;
1944
1945 /* The subpass id in which the attachment will be used last. */
1946 uint32_t last_subpass_idx;
1947 };
1948
1949 struct anv_render_pass {
1950 uint32_t attachment_count;
1951 uint32_t subpass_count;
1952 uint32_t * subpass_attachments;
1953 enum anv_subpass_usage * subpass_usages;
1954 struct anv_render_pass_attachment * attachments;
1955 struct anv_subpass subpasses[0];
1956 };
1957
1958 struct anv_query_pool_slot {
1959 uint64_t begin;
1960 uint64_t end;
1961 uint64_t available;
1962 };
1963
1964 struct anv_query_pool {
1965 VkQueryType type;
1966 uint32_t slots;
1967 struct anv_bo bo;
1968 };
1969
1970 void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
1971 const char *name);
1972
1973 void anv_dump_image_to_ppm(struct anv_device *device,
1974 struct anv_image *image, unsigned miplevel,
1975 unsigned array_layer, VkImageAspectFlagBits aspect,
1976 const char *filename);
1977
1978 enum anv_dump_action {
1979 ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
1980 };
1981
1982 void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
1983 void anv_dump_finish(void);
1984
1985 void anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
1986 struct anv_framebuffer *fb);
1987
1988 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1989 \
1990 static inline struct __anv_type * \
1991 __anv_type ## _from_handle(__VkType _handle) \
1992 { \
1993 return (struct __anv_type *) _handle; \
1994 } \
1995 \
1996 static inline __VkType \
1997 __anv_type ## _to_handle(struct __anv_type *_obj) \
1998 { \
1999 return (__VkType) _obj; \
2000 }
2001
2002 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
2003 \
2004 static inline struct __anv_type * \
2005 __anv_type ## _from_handle(__VkType _handle) \
2006 { \
2007 return (struct __anv_type *)(uintptr_t) _handle; \
2008 } \
2009 \
2010 static inline __VkType \
2011 __anv_type ## _to_handle(struct __anv_type *_obj) \
2012 { \
2013 return (__VkType)(uintptr_t) _obj; \
2014 }
2015
2016 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
2017 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
2018
2019 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
2020 ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
2021 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
2022 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
2023 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
2024
2025 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
2026 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
2027 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
2028 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
2029 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
2030 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
2031 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
2032 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
2033 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
2034 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
2035 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
2036 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
2037 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
2038 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
2039 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
2040 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
2041 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
2042 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
2043 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
2044 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
2045
2046 /* Gen-specific function declarations */
2047 #ifdef genX
2048 # include "anv_genX.h"
2049 #else
2050 # define genX(x) gen7_##x
2051 # include "anv_genX.h"
2052 # undef genX
2053 # define genX(x) gen75_##x
2054 # include "anv_genX.h"
2055 # undef genX
2056 # define genX(x) gen8_##x
2057 # include "anv_genX.h"
2058 # undef genX
2059 # define genX(x) gen9_##x
2060 # include "anv_genX.h"
2061 # undef genX
2062 #endif
2063
2064 #endif /* ANV_PRIVATE_H */