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