drm-uapi: use local files, not system libdrm
[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 "drm-uapi/i915_drm.h"
34
35 #ifdef HAVE_VALGRIND
36 #include <valgrind.h>
37 #include <memcheck.h>
38 #define VG(x) x
39 #ifndef NDEBUG
40 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
41 #endif
42 #else
43 #define VG(x)
44 #endif
45
46 #include "common/gen_clflush.h"
47 #include "common/gen_gem.h"
48 #include "dev/gen_device_info.h"
49 #include "blorp/blorp.h"
50 #include "compiler/brw_compiler.h"
51 #include "util/macros.h"
52 #include "util/hash_table.h"
53 #include "util/list.h"
54 #include "util/set.h"
55 #include "util/u_atomic.h"
56 #include "util/u_vector.h"
57 #include "util/u_math.h"
58 #include "util/vma.h"
59 #include "vk_alloc.h"
60 #include "vk_debug_report.h"
61
62 /* Pre-declarations needed for WSI entrypoints */
63 struct wl_surface;
64 struct wl_display;
65 typedef struct xcb_connection_t xcb_connection_t;
66 typedef uint32_t xcb_visualid_t;
67 typedef uint32_t xcb_window_t;
68
69 struct anv_buffer;
70 struct anv_buffer_view;
71 struct anv_image_view;
72 struct anv_instance;
73
74 struct gen_l3_config;
75
76 #include <vulkan/vulkan.h>
77 #include <vulkan/vulkan_intel.h>
78 #include <vulkan/vk_icd.h>
79
80 #include "anv_android.h"
81 #include "anv_entrypoints.h"
82 #include "anv_extensions.h"
83 #include "isl/isl.h"
84
85 #include "common/gen_debug.h"
86 #include "common/intel_log.h"
87 #include "wsi_common.h"
88
89 /* anv Virtual Memory Layout
90 * =========================
91 *
92 * When the anv driver is determining the virtual graphics addresses of memory
93 * objects itself using the softpin mechanism, the following memory ranges
94 * will be used.
95 *
96 * Three special considerations to notice:
97 *
98 * (1) the dynamic state pool is located within the same 4 GiB as the low
99 * heap. This is to work around a VF cache issue described in a comment in
100 * anv_physical_device_init_heaps.
101 *
102 * (2) the binding table pool is located at lower addresses than the surface
103 * state pool, within a 4 GiB range. This allows surface state base addresses
104 * to cover both binding tables (16 bit offsets) and surface states (32 bit
105 * offsets).
106 *
107 * (3) the last 4 GiB of the address space is withheld from the high
108 * heap. Various hardware units will read past the end of an object for
109 * various reasons. This healthy margin prevents reads from wrapping around
110 * 48-bit addresses.
111 */
112 #define LOW_HEAP_MIN_ADDRESS 0x000000001000ULL /* 4 KiB */
113 #define LOW_HEAP_MAX_ADDRESS 0x0000bfffffffULL
114 #define DYNAMIC_STATE_POOL_MIN_ADDRESS 0x0000c0000000ULL /* 3 GiB */
115 #define DYNAMIC_STATE_POOL_MAX_ADDRESS 0x0000ffffffffULL
116 #define BINDING_TABLE_POOL_MIN_ADDRESS 0x000100000000ULL /* 4 GiB */
117 #define BINDING_TABLE_POOL_MAX_ADDRESS 0x00013fffffffULL
118 #define SURFACE_STATE_POOL_MIN_ADDRESS 0x000140000000ULL /* 5 GiB */
119 #define SURFACE_STATE_POOL_MAX_ADDRESS 0x00017fffffffULL
120 #define INSTRUCTION_STATE_POOL_MIN_ADDRESS 0x000180000000ULL /* 6 GiB */
121 #define INSTRUCTION_STATE_POOL_MAX_ADDRESS 0x0001bfffffffULL
122 #define HIGH_HEAP_MIN_ADDRESS 0x0001c0000000ULL /* 7 GiB */
123 #define HIGH_HEAP_MAX_ADDRESS 0xfffeffffffffULL
124
125 #define LOW_HEAP_SIZE \
126 (LOW_HEAP_MAX_ADDRESS - LOW_HEAP_MIN_ADDRESS + 1)
127 #define HIGH_HEAP_SIZE \
128 (HIGH_HEAP_MAX_ADDRESS - HIGH_HEAP_MIN_ADDRESS + 1)
129 #define DYNAMIC_STATE_POOL_SIZE \
130 (DYNAMIC_STATE_POOL_MAX_ADDRESS - DYNAMIC_STATE_POOL_MIN_ADDRESS + 1)
131 #define BINDING_TABLE_POOL_SIZE \
132 (BINDING_TABLE_POOL_MAX_ADDRESS - BINDING_TABLE_POOL_MIN_ADDRESS + 1)
133 #define SURFACE_STATE_POOL_SIZE \
134 (SURFACE_STATE_POOL_MAX_ADDRESS - SURFACE_STATE_POOL_MIN_ADDRESS + 1)
135 #define INSTRUCTION_STATE_POOL_SIZE \
136 (INSTRUCTION_STATE_POOL_MAX_ADDRESS - INSTRUCTION_STATE_POOL_MIN_ADDRESS + 1)
137
138 /* Allowing different clear colors requires us to perform a depth resolve at
139 * the end of certain render passes. This is because while slow clears store
140 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
141 * See the PRMs for examples describing when additional resolves would be
142 * necessary. To enable fast clears without requiring extra resolves, we set
143 * the clear value to a globally-defined one. We could allow different values
144 * if the user doesn't expect coherent data during or after a render passes
145 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
146 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
147 * 1.0f seems to be the only value used. The only application that doesn't set
148 * this value does so through the usage of an seemingly uninitialized clear
149 * value.
150 */
151 #define ANV_HZ_FC_VAL 1.0f
152
153 #define MAX_VBS 28
154 #define MAX_XFB_BUFFERS 4
155 #define MAX_XFB_STREAMS 4
156 #define MAX_SETS 8
157 #define MAX_RTS 8
158 #define MAX_VIEWPORTS 16
159 #define MAX_SCISSORS 16
160 #define MAX_PUSH_CONSTANTS_SIZE 128
161 #define MAX_DYNAMIC_BUFFERS 16
162 #define MAX_IMAGES 64
163 #define MAX_GEN8_IMAGES 8
164 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
165
166 /* The kernel relocation API has a limitation of a 32-bit delta value
167 * applied to the address before it is written which, in spite of it being
168 * unsigned, is treated as signed . Because of the way that this maps to
169 * the Vulkan API, we cannot handle an offset into a buffer that does not
170 * fit into a signed 32 bits. The only mechanism we have for dealing with
171 * this at the moment is to limit all VkDeviceMemory objects to a maximum
172 * of 2GB each. The Vulkan spec allows us to do this:
173 *
174 * "Some platforms may have a limit on the maximum size of a single
175 * allocation. For example, certain systems may fail to create
176 * allocations with a size greater than or equal to 4GB. Such a limit is
177 * implementation-dependent, and if such a failure occurs then the error
178 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
179 *
180 * We don't use vk_error here because it's not an error so much as an
181 * indication to the application that the allocation is too large.
182 */
183 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
184
185 #define ANV_SVGS_VB_INDEX MAX_VBS
186 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
187
188 /* We reserve this MI ALU register for the purpose of handling predication.
189 * Other code which uses the MI ALU should leave it alone.
190 */
191 #define ANV_PREDICATE_RESULT_REG MI_ALU_REG15
192
193 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
194
195 static inline uint32_t
196 align_down_npot_u32(uint32_t v, uint32_t a)
197 {
198 return v - (v % a);
199 }
200
201 static inline uint32_t
202 align_u32(uint32_t v, uint32_t a)
203 {
204 assert(a != 0 && a == (a & -a));
205 return (v + a - 1) & ~(a - 1);
206 }
207
208 static inline uint64_t
209 align_u64(uint64_t v, uint64_t a)
210 {
211 assert(a != 0 && a == (a & -a));
212 return (v + a - 1) & ~(a - 1);
213 }
214
215 static inline int32_t
216 align_i32(int32_t v, int32_t a)
217 {
218 assert(a != 0 && a == (a & -a));
219 return (v + a - 1) & ~(a - 1);
220 }
221
222 /** Alignment must be a power of 2. */
223 static inline bool
224 anv_is_aligned(uintmax_t n, uintmax_t a)
225 {
226 assert(a == (a & -a));
227 return (n & (a - 1)) == 0;
228 }
229
230 static inline uint32_t
231 anv_minify(uint32_t n, uint32_t levels)
232 {
233 if (unlikely(n == 0))
234 return 0;
235 else
236 return MAX2(n >> levels, 1);
237 }
238
239 static inline float
240 anv_clamp_f(float f, float min, float max)
241 {
242 assert(min < max);
243
244 if (f > max)
245 return max;
246 else if (f < min)
247 return min;
248 else
249 return f;
250 }
251
252 static inline bool
253 anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
254 {
255 if (*inout_mask & clear_mask) {
256 *inout_mask &= ~clear_mask;
257 return true;
258 } else {
259 return false;
260 }
261 }
262
263 static inline union isl_color_value
264 vk_to_isl_color(VkClearColorValue color)
265 {
266 return (union isl_color_value) {
267 .u32 = {
268 color.uint32[0],
269 color.uint32[1],
270 color.uint32[2],
271 color.uint32[3],
272 },
273 };
274 }
275
276 #define for_each_bit(b, dword) \
277 for (uint32_t __dword = (dword); \
278 (b) = __builtin_ffs(__dword) - 1, __dword; \
279 __dword &= ~(1 << (b)))
280
281 #define typed_memcpy(dest, src, count) ({ \
282 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
283 memcpy((dest), (src), (count) * sizeof(*(src))); \
284 })
285
286 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
287 * to be added here in order to utilize mapping in debug/error/perf macros.
288 */
289 #define REPORT_OBJECT_TYPE(o) \
290 __builtin_choose_expr ( \
291 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
292 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
293 __builtin_choose_expr ( \
294 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
295 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
296 __builtin_choose_expr ( \
297 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
298 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
299 __builtin_choose_expr ( \
300 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
301 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
302 __builtin_choose_expr ( \
303 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
304 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
305 __builtin_choose_expr ( \
306 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
307 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
308 __builtin_choose_expr ( \
309 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
310 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
311 __builtin_choose_expr ( \
312 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
313 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
314 __builtin_choose_expr ( \
315 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
316 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
317 __builtin_choose_expr ( \
318 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
319 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
320 __builtin_choose_expr ( \
321 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
322 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
323 __builtin_choose_expr ( \
324 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
325 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
326 __builtin_choose_expr ( \
327 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
328 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
329 __builtin_choose_expr ( \
330 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
331 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
332 __builtin_choose_expr ( \
333 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
334 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
335 __builtin_choose_expr ( \
336 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
337 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
338 __builtin_choose_expr ( \
339 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
340 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
341 __builtin_choose_expr ( \
342 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
343 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
344 __builtin_choose_expr ( \
345 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
346 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
347 __builtin_choose_expr ( \
348 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
349 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
350 __builtin_choose_expr ( \
351 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
352 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
353 __builtin_choose_expr ( \
354 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
355 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
356 __builtin_choose_expr ( \
357 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
358 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
359 __builtin_choose_expr ( \
360 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
361 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
362 __builtin_choose_expr ( \
363 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
364 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
365 __builtin_choose_expr ( \
366 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
367 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
368 __builtin_choose_expr ( \
369 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
370 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
371 __builtin_choose_expr ( \
372 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
373 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
374 __builtin_choose_expr ( \
375 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
376 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
377 __builtin_choose_expr ( \
378 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
379 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
380 __builtin_choose_expr ( \
381 __builtin_types_compatible_p (__typeof (o), void*), \
382 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
383 /* The void expression results in a compile-time error \
384 when assigning the result to something. */ \
385 (void)0)))))))))))))))))))))))))))))))
386
387 /* Whenever we generate an error, pass it through this function. Useful for
388 * debugging, where we can break on it. Only call at error site, not when
389 * propagating errors. Might be useful to plug in a stack trace here.
390 */
391
392 VkResult __vk_errorv(struct anv_instance *instance, const void *object,
393 VkDebugReportObjectTypeEXT type, VkResult error,
394 const char *file, int line, const char *format,
395 va_list args);
396
397 VkResult __vk_errorf(struct anv_instance *instance, const void *object,
398 VkDebugReportObjectTypeEXT type, VkResult error,
399 const char *file, int line, const char *format, ...);
400
401 #ifdef DEBUG
402 #define vk_error(error) __vk_errorf(NULL, NULL,\
403 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
404 error, __FILE__, __LINE__, NULL)
405 #define vk_errorv(instance, obj, error, format, args)\
406 __vk_errorv(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
407 __FILE__, __LINE__, format, args)
408 #define vk_errorf(instance, obj, error, format, ...)\
409 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
410 __FILE__, __LINE__, format, ## __VA_ARGS__)
411 #else
412 #define vk_error(error) error
413 #define vk_errorf(instance, obj, error, format, ...) error
414 #endif
415
416 /**
417 * Warn on ignored extension structs.
418 *
419 * The Vulkan spec requires us to ignore unsupported or unknown structs in
420 * a pNext chain. In debug mode, emitting warnings for ignored structs may
421 * help us discover structs that we should not have ignored.
422 *
423 *
424 * From the Vulkan 1.0.38 spec:
425 *
426 * Any component of the implementation (the loader, any enabled layers,
427 * and drivers) must skip over, without processing (other than reading the
428 * sType and pNext members) any chained structures with sType values not
429 * defined by extensions supported by that component.
430 */
431 #define anv_debug_ignored_stype(sType) \
432 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
433
434 void __anv_perf_warn(struct anv_instance *instance, const void *object,
435 VkDebugReportObjectTypeEXT type, const char *file,
436 int line, const char *format, ...)
437 anv_printflike(6, 7);
438 void anv_loge(const char *format, ...) anv_printflike(1, 2);
439 void anv_loge_v(const char *format, va_list va);
440
441 /**
442 * Print a FINISHME message, including its source location.
443 */
444 #define anv_finishme(format, ...) \
445 do { \
446 static bool reported = false; \
447 if (!reported) { \
448 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
449 ##__VA_ARGS__); \
450 reported = true; \
451 } \
452 } while (0)
453
454 /**
455 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
456 */
457 #define anv_perf_warn(instance, obj, format, ...) \
458 do { \
459 static bool reported = false; \
460 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
461 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
462 format, ##__VA_ARGS__); \
463 reported = true; \
464 } \
465 } while (0)
466
467 /* A non-fatal assert. Useful for debugging. */
468 #ifdef DEBUG
469 #define anv_assert(x) ({ \
470 if (unlikely(!(x))) \
471 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
472 })
473 #else
474 #define anv_assert(x)
475 #endif
476
477 /* A multi-pointer allocator
478 *
479 * When copying data structures from the user (such as a render pass), it's
480 * common to need to allocate data for a bunch of different things. Instead
481 * of doing several allocations and having to handle all of the error checking
482 * that entails, it can be easier to do a single allocation. This struct
483 * helps facilitate that. The intended usage looks like this:
484 *
485 * ANV_MULTIALLOC(ma)
486 * anv_multialloc_add(&ma, &main_ptr, 1);
487 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
488 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
489 *
490 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
491 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
492 */
493 struct anv_multialloc {
494 size_t size;
495 size_t align;
496
497 uint32_t ptr_count;
498 void **ptrs[8];
499 };
500
501 #define ANV_MULTIALLOC_INIT \
502 ((struct anv_multialloc) { 0, })
503
504 #define ANV_MULTIALLOC(_name) \
505 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
506
507 __attribute__((always_inline))
508 static inline void
509 _anv_multialloc_add(struct anv_multialloc *ma,
510 void **ptr, size_t size, size_t align)
511 {
512 size_t offset = align_u64(ma->size, align);
513 ma->size = offset + size;
514 ma->align = MAX2(ma->align, align);
515
516 /* Store the offset in the pointer. */
517 *ptr = (void *)(uintptr_t)offset;
518
519 assert(ma->ptr_count < ARRAY_SIZE(ma->ptrs));
520 ma->ptrs[ma->ptr_count++] = ptr;
521 }
522
523 #define anv_multialloc_add_size(_ma, _ptr, _size) \
524 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
525
526 #define anv_multialloc_add(_ma, _ptr, _count) \
527 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
528
529 __attribute__((always_inline))
530 static inline void *
531 anv_multialloc_alloc(struct anv_multialloc *ma,
532 const VkAllocationCallbacks *alloc,
533 VkSystemAllocationScope scope)
534 {
535 void *ptr = vk_alloc(alloc, ma->size, ma->align, scope);
536 if (!ptr)
537 return NULL;
538
539 /* Fill out each of the pointers with their final value.
540 *
541 * for (uint32_t i = 0; i < ma->ptr_count; i++)
542 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
543 *
544 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
545 * constant, GCC is incapable of figuring this out and unrolling the loop
546 * so we have to give it a little help.
547 */
548 STATIC_ASSERT(ARRAY_SIZE(ma->ptrs) == 8);
549 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
550 if ((_i) < ma->ptr_count) \
551 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
552 _ANV_MULTIALLOC_UPDATE_POINTER(0);
553 _ANV_MULTIALLOC_UPDATE_POINTER(1);
554 _ANV_MULTIALLOC_UPDATE_POINTER(2);
555 _ANV_MULTIALLOC_UPDATE_POINTER(3);
556 _ANV_MULTIALLOC_UPDATE_POINTER(4);
557 _ANV_MULTIALLOC_UPDATE_POINTER(5);
558 _ANV_MULTIALLOC_UPDATE_POINTER(6);
559 _ANV_MULTIALLOC_UPDATE_POINTER(7);
560 #undef _ANV_MULTIALLOC_UPDATE_POINTER
561
562 return ptr;
563 }
564
565 __attribute__((always_inline))
566 static inline void *
567 anv_multialloc_alloc2(struct anv_multialloc *ma,
568 const VkAllocationCallbacks *parent_alloc,
569 const VkAllocationCallbacks *alloc,
570 VkSystemAllocationScope scope)
571 {
572 return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
573 }
574
575 /* Extra ANV-defined BO flags which won't be passed to the kernel */
576 #define ANV_BO_EXTERNAL (1ull << 31)
577 #define ANV_BO_FLAG_MASK (1ull << 31)
578
579 struct anv_bo {
580 uint32_t gem_handle;
581
582 /* Index into the current validation list. This is used by the
583 * validation list building alrogithm to track which buffers are already
584 * in the validation list so that we can ensure uniqueness.
585 */
586 uint32_t index;
587
588 /* Last known offset. This value is provided by the kernel when we
589 * execbuf and is used as the presumed offset for the next bunch of
590 * relocations.
591 */
592 uint64_t offset;
593
594 uint64_t size;
595 void *map;
596
597 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
598 uint32_t flags;
599 };
600
601 static inline void
602 anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
603 {
604 bo->gem_handle = gem_handle;
605 bo->index = 0;
606 bo->offset = -1;
607 bo->size = size;
608 bo->map = NULL;
609 bo->flags = 0;
610 }
611
612 /* Represents a lock-free linked list of "free" things. This is used by
613 * both the block pool and the state pools. Unfortunately, in order to
614 * solve the ABA problem, we can't use a single uint32_t head.
615 */
616 union anv_free_list {
617 struct {
618 uint32_t offset;
619
620 /* A simple count that is incremented every time the head changes. */
621 uint32_t count;
622 };
623 uint64_t u64;
624 };
625
626 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { UINT32_MAX, 0 } })
627
628 struct anv_block_state {
629 union {
630 struct {
631 uint32_t next;
632 uint32_t end;
633 };
634 uint64_t u64;
635 };
636 };
637
638 #define anv_block_pool_foreach_bo(bo, pool) \
639 for (bo = (pool)->bos; bo != &(pool)->bos[(pool)->nbos]; bo++)
640
641 #define ANV_MAX_BLOCK_POOL_BOS 20
642
643 struct anv_block_pool {
644 struct anv_device *device;
645
646 uint64_t bo_flags;
647
648 struct anv_bo bos[ANV_MAX_BLOCK_POOL_BOS];
649 struct anv_bo *bo;
650 uint32_t nbos;
651
652 uint64_t size;
653
654 /* The address where the start of the pool is pinned. The various bos that
655 * are created as the pool grows will have addresses in the range
656 * [start_address, start_address + BLOCK_POOL_MEMFD_SIZE).
657 */
658 uint64_t start_address;
659
660 /* The offset from the start of the bo to the "center" of the block
661 * pool. Pointers to allocated blocks are given by
662 * bo.map + center_bo_offset + offsets.
663 */
664 uint32_t center_bo_offset;
665
666 /* Current memory map of the block pool. This pointer may or may not
667 * point to the actual beginning of the block pool memory. If
668 * anv_block_pool_alloc_back has ever been called, then this pointer
669 * will point to the "center" position of the buffer and all offsets
670 * (negative or positive) given out by the block pool alloc functions
671 * will be valid relative to this pointer.
672 *
673 * In particular, map == bo.map + center_offset
674 *
675 * DO NOT access this pointer directly. Use anv_block_pool_map() instead,
676 * since it will handle the softpin case as well, where this points to NULL.
677 */
678 void *map;
679 int fd;
680
681 /**
682 * Array of mmaps and gem handles owned by the block pool, reclaimed when
683 * the block pool is destroyed.
684 */
685 struct u_vector mmap_cleanups;
686
687 struct anv_block_state state;
688
689 struct anv_block_state back_state;
690 };
691
692 /* Block pools are backed by a fixed-size 1GB memfd */
693 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
694
695 /* The center of the block pool is also the middle of the memfd. This may
696 * change in the future if we decide differently for some reason.
697 */
698 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
699
700 static inline uint32_t
701 anv_block_pool_size(struct anv_block_pool *pool)
702 {
703 return pool->state.end + pool->back_state.end;
704 }
705
706 struct anv_state {
707 int32_t offset;
708 uint32_t alloc_size;
709 void *map;
710 uint32_t idx;
711 };
712
713 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
714
715 struct anv_fixed_size_state_pool {
716 union anv_free_list free_list;
717 struct anv_block_state block;
718 };
719
720 #define ANV_MIN_STATE_SIZE_LOG2 6
721 #define ANV_MAX_STATE_SIZE_LOG2 20
722
723 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
724
725 struct anv_free_entry {
726 uint32_t next;
727 struct anv_state state;
728 };
729
730 struct anv_state_table {
731 struct anv_device *device;
732 int fd;
733 struct anv_free_entry *map;
734 uint32_t size;
735 struct anv_block_state state;
736 struct u_vector mmap_cleanups;
737 };
738
739 struct anv_state_pool {
740 struct anv_block_pool block_pool;
741
742 struct anv_state_table table;
743
744 /* The size of blocks which will be allocated from the block pool */
745 uint32_t block_size;
746
747 /** Free list for "back" allocations */
748 union anv_free_list back_alloc_free_list;
749
750 struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
751 };
752
753 struct anv_state_stream_block;
754
755 struct anv_state_stream {
756 struct anv_state_pool *state_pool;
757
758 /* The size of blocks to allocate from the state pool */
759 uint32_t block_size;
760
761 /* Current block we're allocating from */
762 struct anv_state block;
763
764 /* Offset into the current block at which to allocate the next state */
765 uint32_t next;
766
767 /* List of all blocks allocated from this pool */
768 struct anv_state_stream_block *block_list;
769 };
770
771 /* The block_pool functions exported for testing only. The block pool should
772 * only be used via a state pool (see below).
773 */
774 VkResult anv_block_pool_init(struct anv_block_pool *pool,
775 struct anv_device *device,
776 uint64_t start_address,
777 uint32_t initial_size,
778 uint64_t bo_flags);
779 void anv_block_pool_finish(struct anv_block_pool *pool);
780 int32_t anv_block_pool_alloc(struct anv_block_pool *pool,
781 uint32_t block_size, uint32_t *padding);
782 int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool,
783 uint32_t block_size);
784 void* anv_block_pool_map(struct anv_block_pool *pool, int32_t offset);
785
786 VkResult anv_state_pool_init(struct anv_state_pool *pool,
787 struct anv_device *device,
788 uint64_t start_address,
789 uint32_t block_size,
790 uint64_t bo_flags);
791 void anv_state_pool_finish(struct anv_state_pool *pool);
792 struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool,
793 uint32_t state_size, uint32_t alignment);
794 struct anv_state anv_state_pool_alloc_back(struct anv_state_pool *pool);
795 void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state);
796 void anv_state_stream_init(struct anv_state_stream *stream,
797 struct anv_state_pool *state_pool,
798 uint32_t block_size);
799 void anv_state_stream_finish(struct anv_state_stream *stream);
800 struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
801 uint32_t size, uint32_t alignment);
802
803 VkResult anv_state_table_init(struct anv_state_table *table,
804 struct anv_device *device,
805 uint32_t initial_entries);
806 void anv_state_table_finish(struct anv_state_table *table);
807 VkResult anv_state_table_add(struct anv_state_table *table, uint32_t *idx,
808 uint32_t count);
809 void anv_free_list_push(union anv_free_list *list,
810 struct anv_state_table *table,
811 uint32_t idx, uint32_t count);
812 struct anv_state* anv_free_list_pop(union anv_free_list *list,
813 struct anv_state_table *table);
814
815
816 static inline struct anv_state *
817 anv_state_table_get(struct anv_state_table *table, uint32_t idx)
818 {
819 return &table->map[idx].state;
820 }
821 /**
822 * Implements a pool of re-usable BOs. The interface is identical to that
823 * of block_pool except that each block is its own BO.
824 */
825 struct anv_bo_pool {
826 struct anv_device *device;
827
828 uint64_t bo_flags;
829
830 void *free_list[16];
831 };
832
833 void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device,
834 uint64_t bo_flags);
835 void anv_bo_pool_finish(struct anv_bo_pool *pool);
836 VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo,
837 uint32_t size);
838 void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
839
840 struct anv_scratch_bo {
841 bool exists;
842 struct anv_bo bo;
843 };
844
845 struct anv_scratch_pool {
846 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
847 struct anv_scratch_bo bos[16][MESA_SHADER_STAGES];
848 };
849
850 void anv_scratch_pool_init(struct anv_device *device,
851 struct anv_scratch_pool *pool);
852 void anv_scratch_pool_finish(struct anv_device *device,
853 struct anv_scratch_pool *pool);
854 struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
855 struct anv_scratch_pool *pool,
856 gl_shader_stage stage,
857 unsigned per_thread_scratch);
858
859 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
860 struct anv_bo_cache {
861 struct hash_table *bo_map;
862 pthread_mutex_t mutex;
863 };
864
865 VkResult anv_bo_cache_init(struct anv_bo_cache *cache);
866 void anv_bo_cache_finish(struct anv_bo_cache *cache);
867 VkResult anv_bo_cache_alloc(struct anv_device *device,
868 struct anv_bo_cache *cache,
869 uint64_t size, uint64_t bo_flags,
870 struct anv_bo **bo);
871 VkResult anv_bo_cache_import(struct anv_device *device,
872 struct anv_bo_cache *cache,
873 int fd, uint64_t bo_flags,
874 struct anv_bo **bo);
875 VkResult anv_bo_cache_export(struct anv_device *device,
876 struct anv_bo_cache *cache,
877 struct anv_bo *bo_in, int *fd_out);
878 void anv_bo_cache_release(struct anv_device *device,
879 struct anv_bo_cache *cache,
880 struct anv_bo *bo);
881
882 struct anv_memory_type {
883 /* Standard bits passed on to the client */
884 VkMemoryPropertyFlags propertyFlags;
885 uint32_t heapIndex;
886
887 /* Driver-internal book-keeping */
888 VkBufferUsageFlags valid_buffer_usage;
889 };
890
891 struct anv_memory_heap {
892 /* Standard bits passed on to the client */
893 VkDeviceSize size;
894 VkMemoryHeapFlags flags;
895
896 /* Driver-internal book-keeping */
897 bool supports_48bit_addresses;
898 };
899
900 struct anv_physical_device {
901 VK_LOADER_DATA _loader_data;
902
903 struct anv_instance * instance;
904 uint32_t chipset_id;
905 bool no_hw;
906 char path[20];
907 const char * name;
908 struct {
909 uint16_t domain;
910 uint8_t bus;
911 uint8_t device;
912 uint8_t function;
913 } pci_info;
914 struct gen_device_info info;
915 /** Amount of "GPU memory" we want to advertise
916 *
917 * Clearly, this value is bogus since Intel is a UMA architecture. On
918 * gen7 platforms, we are limited by GTT size unless we want to implement
919 * fine-grained tracking and GTT splitting. On Broadwell and above we are
920 * practically unlimited. However, we will never report more than 3/4 of
921 * the total system ram to try and avoid running out of RAM.
922 */
923 bool supports_48bit_addresses;
924 struct brw_compiler * compiler;
925 struct isl_device isl_dev;
926 int cmd_parser_version;
927 bool has_exec_async;
928 bool has_exec_capture;
929 bool has_exec_fence;
930 bool has_syncobj;
931 bool has_syncobj_wait;
932 bool has_context_priority;
933 bool use_softpin;
934 bool has_context_isolation;
935
936 struct anv_device_extension_table supported_extensions;
937
938 uint32_t eu_total;
939 uint32_t subslice_total;
940
941 struct {
942 uint32_t type_count;
943 struct anv_memory_type types[VK_MAX_MEMORY_TYPES];
944 uint32_t heap_count;
945 struct anv_memory_heap heaps[VK_MAX_MEMORY_HEAPS];
946 } memory;
947
948 uint8_t driver_build_sha1[20];
949 uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
950 uint8_t driver_uuid[VK_UUID_SIZE];
951 uint8_t device_uuid[VK_UUID_SIZE];
952
953 struct disk_cache * disk_cache;
954
955 struct wsi_device wsi_device;
956 int local_fd;
957 int master_fd;
958 };
959
960 struct anv_app_info {
961 const char* app_name;
962 uint32_t app_version;
963 const char* engine_name;
964 uint32_t engine_version;
965 uint32_t api_version;
966 };
967
968 struct anv_instance {
969 VK_LOADER_DATA _loader_data;
970
971 VkAllocationCallbacks alloc;
972
973 struct anv_app_info app_info;
974
975 struct anv_instance_extension_table enabled_extensions;
976 struct anv_instance_dispatch_table dispatch;
977 struct anv_device_dispatch_table device_dispatch;
978
979 int physicalDeviceCount;
980 struct anv_physical_device physicalDevice;
981
982 bool pipeline_cache_enabled;
983
984 struct vk_debug_report_instance debug_report_callbacks;
985 };
986
987 VkResult anv_init_wsi(struct anv_physical_device *physical_device);
988 void anv_finish_wsi(struct anv_physical_device *physical_device);
989
990 uint32_t anv_physical_device_api_version(struct anv_physical_device *dev);
991 bool anv_physical_device_extension_supported(struct anv_physical_device *dev,
992 const char *name);
993
994 struct anv_queue {
995 VK_LOADER_DATA _loader_data;
996
997 struct anv_device * device;
998
999 VkDeviceQueueCreateFlags flags;
1000 };
1001
1002 struct anv_pipeline_cache {
1003 struct anv_device * device;
1004 pthread_mutex_t mutex;
1005
1006 struct hash_table * nir_cache;
1007
1008 struct hash_table * cache;
1009 };
1010
1011 struct nir_xfb_info;
1012 struct anv_pipeline_bind_map;
1013
1014 void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
1015 struct anv_device *device,
1016 bool cache_enabled);
1017 void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
1018
1019 struct anv_shader_bin *
1020 anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
1021 const void *key, uint32_t key_size);
1022 struct anv_shader_bin *
1023 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
1024 const void *key_data, uint32_t key_size,
1025 const void *kernel_data, uint32_t kernel_size,
1026 const void *constant_data,
1027 uint32_t constant_data_size,
1028 const struct brw_stage_prog_data *prog_data,
1029 uint32_t prog_data_size,
1030 const struct nir_xfb_info *xfb_info,
1031 const struct anv_pipeline_bind_map *bind_map);
1032
1033 struct anv_shader_bin *
1034 anv_device_search_for_kernel(struct anv_device *device,
1035 struct anv_pipeline_cache *cache,
1036 const void *key_data, uint32_t key_size);
1037
1038 struct anv_shader_bin *
1039 anv_device_upload_kernel(struct anv_device *device,
1040 struct anv_pipeline_cache *cache,
1041 const void *key_data, uint32_t key_size,
1042 const void *kernel_data, uint32_t kernel_size,
1043 const void *constant_data,
1044 uint32_t constant_data_size,
1045 const struct brw_stage_prog_data *prog_data,
1046 uint32_t prog_data_size,
1047 const struct nir_xfb_info *xfb_info,
1048 const struct anv_pipeline_bind_map *bind_map);
1049
1050 struct nir_shader;
1051 struct nir_shader_compiler_options;
1052
1053 struct nir_shader *
1054 anv_device_search_for_nir(struct anv_device *device,
1055 struct anv_pipeline_cache *cache,
1056 const struct nir_shader_compiler_options *nir_options,
1057 unsigned char sha1_key[20],
1058 void *mem_ctx);
1059
1060 void
1061 anv_device_upload_nir(struct anv_device *device,
1062 struct anv_pipeline_cache *cache,
1063 const struct nir_shader *nir,
1064 unsigned char sha1_key[20]);
1065
1066 struct anv_device {
1067 VK_LOADER_DATA _loader_data;
1068
1069 VkAllocationCallbacks alloc;
1070
1071 struct anv_instance * instance;
1072 uint32_t chipset_id;
1073 bool no_hw;
1074 struct gen_device_info info;
1075 struct isl_device isl_dev;
1076 int context_id;
1077 int fd;
1078 bool can_chain_batches;
1079 bool robust_buffer_access;
1080 struct anv_device_extension_table enabled_extensions;
1081 struct anv_device_dispatch_table dispatch;
1082
1083 pthread_mutex_t vma_mutex;
1084 struct util_vma_heap vma_lo;
1085 struct util_vma_heap vma_hi;
1086 uint64_t vma_lo_available;
1087 uint64_t vma_hi_available;
1088
1089 struct anv_bo_pool batch_bo_pool;
1090
1091 struct anv_bo_cache bo_cache;
1092
1093 struct anv_state_pool dynamic_state_pool;
1094 struct anv_state_pool instruction_state_pool;
1095 struct anv_state_pool binding_table_pool;
1096 struct anv_state_pool surface_state_pool;
1097
1098 struct anv_bo workaround_bo;
1099 struct anv_bo trivial_batch_bo;
1100 struct anv_bo hiz_clear_bo;
1101
1102 /* Set of pointers to anv_buffer objects for all pinned buffers. Pinned
1103 * buffers are always resident because they could be used at any time via
1104 * VK_EXT_buffer_device_address.
1105 */
1106 struct set * pinned_buffers;
1107
1108 struct anv_pipeline_cache default_pipeline_cache;
1109 struct blorp_context blorp;
1110
1111 struct anv_state border_colors;
1112
1113 struct anv_queue queue;
1114
1115 struct anv_scratch_pool scratch_pool;
1116
1117 uint32_t default_mocs;
1118 uint32_t external_mocs;
1119
1120 pthread_mutex_t mutex;
1121 pthread_cond_t queue_submit;
1122 bool _lost;
1123 };
1124
1125 static inline struct anv_state_pool *
1126 anv_binding_table_pool(struct anv_device *device)
1127 {
1128 if (device->instance->physicalDevice.use_softpin)
1129 return &device->binding_table_pool;
1130 else
1131 return &device->surface_state_pool;
1132 }
1133
1134 static inline struct anv_state
1135 anv_binding_table_pool_alloc(struct anv_device *device) {
1136 if (device->instance->physicalDevice.use_softpin)
1137 return anv_state_pool_alloc(&device->binding_table_pool,
1138 device->binding_table_pool.block_size, 0);
1139 else
1140 return anv_state_pool_alloc_back(&device->surface_state_pool);
1141 }
1142
1143 static inline void
1144 anv_binding_table_pool_free(struct anv_device *device, struct anv_state state) {
1145 anv_state_pool_free(anv_binding_table_pool(device), state);
1146 }
1147
1148 static inline uint32_t
1149 anv_mocs_for_bo(const struct anv_device *device, const struct anv_bo *bo)
1150 {
1151 if (bo->flags & ANV_BO_EXTERNAL)
1152 return device->external_mocs;
1153 else
1154 return device->default_mocs;
1155 }
1156
1157 void anv_device_init_blorp(struct anv_device *device);
1158 void anv_device_finish_blorp(struct anv_device *device);
1159
1160 VkResult _anv_device_set_lost(struct anv_device *device,
1161 const char *file, int line,
1162 const char *msg, ...);
1163 #define anv_device_set_lost(dev, ...) \
1164 _anv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)
1165
1166 static inline bool
1167 anv_device_is_lost(struct anv_device *device)
1168 {
1169 return unlikely(device->_lost);
1170 }
1171
1172 VkResult anv_device_execbuf(struct anv_device *device,
1173 struct drm_i915_gem_execbuffer2 *execbuf,
1174 struct anv_bo **execbuf_bos);
1175 VkResult anv_device_query_status(struct anv_device *device);
1176 VkResult anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo);
1177 VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo,
1178 int64_t timeout);
1179
1180 void* anv_gem_mmap(struct anv_device *device,
1181 uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags);
1182 void anv_gem_munmap(void *p, uint64_t size);
1183 uint32_t anv_gem_create(struct anv_device *device, uint64_t size);
1184 void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
1185 uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
1186 int anv_gem_busy(struct anv_device *device, uint32_t gem_handle);
1187 int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns);
1188 int anv_gem_execbuffer(struct anv_device *device,
1189 struct drm_i915_gem_execbuffer2 *execbuf);
1190 int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
1191 uint32_t stride, uint32_t tiling);
1192 int anv_gem_create_context(struct anv_device *device);
1193 bool anv_gem_has_context_priority(int fd);
1194 int anv_gem_destroy_context(struct anv_device *device, int context);
1195 int anv_gem_set_context_param(int fd, int context, uint32_t param,
1196 uint64_t value);
1197 int anv_gem_get_context_param(int fd, int context, uint32_t param,
1198 uint64_t *value);
1199 int anv_gem_get_param(int fd, uint32_t param);
1200 int anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle);
1201 bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
1202 int anv_gem_get_aperture(int fd, uint64_t *size);
1203 int anv_gem_gpu_get_reset_stats(struct anv_device *device,
1204 uint32_t *active, uint32_t *pending);
1205 int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
1206 int anv_gem_reg_read(struct anv_device *device,
1207 uint32_t offset, uint64_t *result);
1208 uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
1209 int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
1210 int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
1211 uint32_t read_domains, uint32_t write_domain);
1212 int anv_gem_sync_file_merge(struct anv_device *device, int fd1, int fd2);
1213 uint32_t anv_gem_syncobj_create(struct anv_device *device, uint32_t flags);
1214 void anv_gem_syncobj_destroy(struct anv_device *device, uint32_t handle);
1215 int anv_gem_syncobj_handle_to_fd(struct anv_device *device, uint32_t handle);
1216 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device *device, int fd);
1217 int anv_gem_syncobj_export_sync_file(struct anv_device *device,
1218 uint32_t handle);
1219 int anv_gem_syncobj_import_sync_file(struct anv_device *device,
1220 uint32_t handle, int fd);
1221 void anv_gem_syncobj_reset(struct anv_device *device, uint32_t handle);
1222 bool anv_gem_supports_syncobj_wait(int fd);
1223 int anv_gem_syncobj_wait(struct anv_device *device,
1224 uint32_t *handles, uint32_t num_handles,
1225 int64_t abs_timeout_ns, bool wait_all);
1226
1227 bool anv_vma_alloc(struct anv_device *device, struct anv_bo *bo);
1228 void anv_vma_free(struct anv_device *device, struct anv_bo *bo);
1229
1230 VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size);
1231
1232 struct anv_reloc_list {
1233 uint32_t num_relocs;
1234 uint32_t array_length;
1235 struct drm_i915_gem_relocation_entry * relocs;
1236 struct anv_bo ** reloc_bos;
1237 struct set * deps;
1238 };
1239
1240 VkResult anv_reloc_list_init(struct anv_reloc_list *list,
1241 const VkAllocationCallbacks *alloc);
1242 void anv_reloc_list_finish(struct anv_reloc_list *list,
1243 const VkAllocationCallbacks *alloc);
1244
1245 VkResult anv_reloc_list_add(struct anv_reloc_list *list,
1246 const VkAllocationCallbacks *alloc,
1247 uint32_t offset, struct anv_bo *target_bo,
1248 uint32_t delta);
1249
1250 struct anv_batch_bo {
1251 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1252 struct list_head link;
1253
1254 struct anv_bo bo;
1255
1256 /* Bytes actually consumed in this batch BO */
1257 uint32_t length;
1258
1259 struct anv_reloc_list relocs;
1260 };
1261
1262 struct anv_batch {
1263 const VkAllocationCallbacks * alloc;
1264
1265 void * start;
1266 void * end;
1267 void * next;
1268
1269 struct anv_reloc_list * relocs;
1270
1271 /* This callback is called (with the associated user data) in the event
1272 * that the batch runs out of space.
1273 */
1274 VkResult (*extend_cb)(struct anv_batch *, void *);
1275 void * user_data;
1276
1277 /**
1278 * Current error status of the command buffer. Used to track inconsistent
1279 * or incomplete command buffer states that are the consequence of run-time
1280 * errors such as out of memory scenarios. We want to track this in the
1281 * batch because the command buffer object is not visible to some parts
1282 * of the driver.
1283 */
1284 VkResult status;
1285 };
1286
1287 void *anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords);
1288 void anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other);
1289 uint64_t anv_batch_emit_reloc(struct anv_batch *batch,
1290 void *location, struct anv_bo *bo, uint32_t offset);
1291 VkResult anv_device_submit_simple_batch(struct anv_device *device,
1292 struct anv_batch *batch);
1293
1294 static inline VkResult
1295 anv_batch_set_error(struct anv_batch *batch, VkResult error)
1296 {
1297 assert(error != VK_SUCCESS);
1298 if (batch->status == VK_SUCCESS)
1299 batch->status = error;
1300 return batch->status;
1301 }
1302
1303 static inline bool
1304 anv_batch_has_error(struct anv_batch *batch)
1305 {
1306 return batch->status != VK_SUCCESS;
1307 }
1308
1309 struct anv_address {
1310 struct anv_bo *bo;
1311 uint32_t offset;
1312 };
1313
1314 #define ANV_NULL_ADDRESS ((struct anv_address) { NULL, 0 })
1315
1316 static inline bool
1317 anv_address_is_null(struct anv_address addr)
1318 {
1319 return addr.bo == NULL && addr.offset == 0;
1320 }
1321
1322 static inline uint64_t
1323 anv_address_physical(struct anv_address addr)
1324 {
1325 if (addr.bo && (addr.bo->flags & EXEC_OBJECT_PINNED))
1326 return gen_canonical_address(addr.bo->offset + addr.offset);
1327 else
1328 return gen_canonical_address(addr.offset);
1329 }
1330
1331 static inline struct anv_address
1332 anv_address_add(struct anv_address addr, uint64_t offset)
1333 {
1334 addr.offset += offset;
1335 return addr;
1336 }
1337
1338 static inline void
1339 write_reloc(const struct anv_device *device, void *p, uint64_t v, bool flush)
1340 {
1341 unsigned reloc_size = 0;
1342 if (device->info.gen >= 8) {
1343 reloc_size = sizeof(uint64_t);
1344 *(uint64_t *)p = gen_canonical_address(v);
1345 } else {
1346 reloc_size = sizeof(uint32_t);
1347 *(uint32_t *)p = v;
1348 }
1349
1350 if (flush && !device->info.has_llc)
1351 gen_flush_range(p, reloc_size);
1352 }
1353
1354 static inline uint64_t
1355 _anv_combine_address(struct anv_batch *batch, void *location,
1356 const struct anv_address address, uint32_t delta)
1357 {
1358 if (address.bo == NULL) {
1359 return address.offset + delta;
1360 } else {
1361 assert(batch->start <= location && location < batch->end);
1362
1363 return anv_batch_emit_reloc(batch, location, address.bo, address.offset + delta);
1364 }
1365 }
1366
1367 #define __gen_address_type struct anv_address
1368 #define __gen_user_data struct anv_batch
1369 #define __gen_combine_address _anv_combine_address
1370
1371 /* Wrapper macros needed to work around preprocessor argument issues. In
1372 * particular, arguments don't get pre-evaluated if they are concatenated.
1373 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1374 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1375 * We can work around this easily enough with these helpers.
1376 */
1377 #define __anv_cmd_length(cmd) cmd ## _length
1378 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1379 #define __anv_cmd_header(cmd) cmd ## _header
1380 #define __anv_cmd_pack(cmd) cmd ## _pack
1381 #define __anv_reg_num(reg) reg ## _num
1382
1383 #define anv_pack_struct(dst, struc, ...) do { \
1384 struct struc __template = { \
1385 __VA_ARGS__ \
1386 }; \
1387 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1388 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1389 } while (0)
1390
1391 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1392 void *__dst = anv_batch_emit_dwords(batch, n); \
1393 if (__dst) { \
1394 struct cmd __template = { \
1395 __anv_cmd_header(cmd), \
1396 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1397 __VA_ARGS__ \
1398 }; \
1399 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1400 } \
1401 __dst; \
1402 })
1403
1404 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1405 do { \
1406 uint32_t *dw; \
1407 \
1408 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1409 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1410 if (!dw) \
1411 break; \
1412 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1413 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1414 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1415 } while (0)
1416
1417 #define anv_batch_emit(batch, cmd, name) \
1418 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1419 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1420 __builtin_expect(_dst != NULL, 1); \
1421 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1422 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1423 _dst = NULL; \
1424 }))
1425
1426 /* MEMORY_OBJECT_CONTROL_STATE:
1427 * .GraphicsDataTypeGFDT = 0,
1428 * .LLCCacheabilityControlLLCCC = 0,
1429 * .L3CacheabilityControlL3CC = 1,
1430 */
1431 #define GEN7_MOCS 1
1432
1433 /* MEMORY_OBJECT_CONTROL_STATE:
1434 * .LLCeLLCCacheabilityControlLLCCC = 0,
1435 * .L3CacheabilityControlL3CC = 1,
1436 */
1437 #define GEN75_MOCS 1
1438
1439 /* MEMORY_OBJECT_CONTROL_STATE:
1440 * .MemoryTypeLLCeLLCCacheabilityControl = WB,
1441 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1442 * .AgeforQUADLRU = 0
1443 */
1444 #define GEN8_MOCS 0x78
1445
1446 /* MEMORY_OBJECT_CONTROL_STATE:
1447 * .MemoryTypeLLCeLLCCacheabilityControl = UCwithFenceifcoherentcycle,
1448 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1449 * .AgeforQUADLRU = 0
1450 */
1451 #define GEN8_EXTERNAL_MOCS 0x18
1452
1453 /* Skylake: MOCS is now an index into an array of 62 different caching
1454 * configurations programmed by the kernel.
1455 */
1456
1457 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1458 #define GEN9_MOCS 2
1459
1460 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1461 #define GEN9_EXTERNAL_MOCS 1
1462
1463 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1464 #define GEN10_MOCS GEN9_MOCS
1465 #define GEN10_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1466
1467 /* Ice Lake MOCS defines are duplicates of Skylake MOCS defines. */
1468 #define GEN11_MOCS GEN9_MOCS
1469 #define GEN11_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1470
1471 struct anv_device_memory {
1472 struct anv_bo * bo;
1473 struct anv_memory_type * type;
1474 VkDeviceSize map_size;
1475 void * map;
1476
1477 /* If set, we are holding reference to AHardwareBuffer
1478 * which we must release when memory is freed.
1479 */
1480 struct AHardwareBuffer * ahw;
1481 };
1482
1483 /**
1484 * Header for Vertex URB Entry (VUE)
1485 */
1486 struct anv_vue_header {
1487 uint32_t Reserved;
1488 uint32_t RTAIndex; /* RenderTargetArrayIndex */
1489 uint32_t ViewportIndex;
1490 float PointWidth;
1491 };
1492
1493 struct anv_descriptor_set_binding_layout {
1494 #ifndef NDEBUG
1495 /* The type of the descriptors in this binding */
1496 VkDescriptorType type;
1497 #endif
1498
1499 /* Number of array elements in this binding */
1500 uint16_t array_size;
1501
1502 /* Index into the flattend descriptor set */
1503 uint16_t descriptor_index;
1504
1505 /* Index into the dynamic state array for a dynamic buffer */
1506 int16_t dynamic_offset_index;
1507
1508 /* Index into the descriptor set buffer views */
1509 int16_t buffer_index;
1510
1511 struct {
1512 /* Index into the binding table for the associated surface */
1513 int16_t surface_index;
1514
1515 /* Index into the sampler table for the associated sampler */
1516 int16_t sampler_index;
1517
1518 /* Index into the image table for the associated image */
1519 int16_t image_index;
1520 } stage[MESA_SHADER_STAGES];
1521
1522 /* Immutable samplers (or NULL if no immutable samplers) */
1523 struct anv_sampler **immutable_samplers;
1524 };
1525
1526 struct anv_descriptor_set_layout {
1527 /* Descriptor set layouts can be destroyed at almost any time */
1528 uint32_t ref_cnt;
1529
1530 /* Number of bindings in this descriptor set */
1531 uint16_t binding_count;
1532
1533 /* Total size of the descriptor set with room for all array entries */
1534 uint16_t size;
1535
1536 /* Shader stages affected by this descriptor set */
1537 uint16_t shader_stages;
1538
1539 /* Number of buffers in this descriptor set */
1540 uint16_t buffer_count;
1541
1542 /* Number of dynamic offsets used by this descriptor set */
1543 uint16_t dynamic_offset_count;
1544
1545 /* Bindings in this descriptor set */
1546 struct anv_descriptor_set_binding_layout binding[0];
1547 };
1548
1549 static inline void
1550 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout *layout)
1551 {
1552 assert(layout && layout->ref_cnt >= 1);
1553 p_atomic_inc(&layout->ref_cnt);
1554 }
1555
1556 static inline void
1557 anv_descriptor_set_layout_unref(struct anv_device *device,
1558 struct anv_descriptor_set_layout *layout)
1559 {
1560 assert(layout && layout->ref_cnt >= 1);
1561 if (p_atomic_dec_zero(&layout->ref_cnt))
1562 vk_free(&device->alloc, layout);
1563 }
1564
1565 struct anv_descriptor {
1566 VkDescriptorType type;
1567
1568 union {
1569 struct {
1570 VkImageLayout layout;
1571 struct anv_image_view *image_view;
1572 struct anv_sampler *sampler;
1573 };
1574
1575 struct {
1576 struct anv_buffer *buffer;
1577 uint64_t offset;
1578 uint64_t range;
1579 };
1580
1581 struct anv_buffer_view *buffer_view;
1582 };
1583 };
1584
1585 struct anv_descriptor_set {
1586 struct anv_descriptor_set_layout *layout;
1587 uint32_t size;
1588 uint32_t buffer_count;
1589 struct anv_buffer_view *buffer_views;
1590 struct anv_descriptor descriptors[0];
1591 };
1592
1593 struct anv_buffer_view {
1594 enum isl_format format; /**< VkBufferViewCreateInfo::format */
1595 uint64_t range; /**< VkBufferViewCreateInfo::range */
1596
1597 struct anv_address address;
1598
1599 struct anv_state surface_state;
1600 struct anv_state storage_surface_state;
1601 struct anv_state writeonly_storage_surface_state;
1602
1603 struct brw_image_param storage_image_param;
1604 };
1605
1606 struct anv_push_descriptor_set {
1607 struct anv_descriptor_set set;
1608
1609 /* Put this field right behind anv_descriptor_set so it fills up the
1610 * descriptors[0] field. */
1611 struct anv_descriptor descriptors[MAX_PUSH_DESCRIPTORS];
1612 struct anv_buffer_view buffer_views[MAX_PUSH_DESCRIPTORS];
1613 };
1614
1615 struct anv_descriptor_pool {
1616 uint32_t size;
1617 uint32_t next;
1618 uint32_t free_list;
1619
1620 struct anv_state_stream surface_state_stream;
1621 void *surface_state_free_list;
1622
1623 char data[0];
1624 };
1625
1626 enum anv_descriptor_template_entry_type {
1627 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
1628 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
1629 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1630 };
1631
1632 struct anv_descriptor_template_entry {
1633 /* The type of descriptor in this entry */
1634 VkDescriptorType type;
1635
1636 /* Binding in the descriptor set */
1637 uint32_t binding;
1638
1639 /* Offset at which to write into the descriptor set binding */
1640 uint32_t array_element;
1641
1642 /* Number of elements to write into the descriptor set binding */
1643 uint32_t array_count;
1644
1645 /* Offset into the user provided data */
1646 size_t offset;
1647
1648 /* Stride between elements into the user provided data */
1649 size_t stride;
1650 };
1651
1652 struct anv_descriptor_update_template {
1653 VkPipelineBindPoint bind_point;
1654
1655 /* The descriptor set this template corresponds to. This value is only
1656 * valid if the template was created with the templateType
1657 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET.
1658 */
1659 uint8_t set;
1660
1661 /* Number of entries in this template */
1662 uint32_t entry_count;
1663
1664 /* Entries of the template */
1665 struct anv_descriptor_template_entry entries[0];
1666 };
1667
1668 size_t
1669 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
1670
1671 void
1672 anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
1673 const struct gen_device_info * const devinfo,
1674 const VkDescriptorImageInfo * const info,
1675 VkDescriptorType type,
1676 uint32_t binding,
1677 uint32_t element);
1678
1679 void
1680 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set *set,
1681 VkDescriptorType type,
1682 struct anv_buffer_view *buffer_view,
1683 uint32_t binding,
1684 uint32_t element);
1685
1686 void
1687 anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
1688 struct anv_device *device,
1689 struct anv_state_stream *alloc_stream,
1690 VkDescriptorType type,
1691 struct anv_buffer *buffer,
1692 uint32_t binding,
1693 uint32_t element,
1694 VkDeviceSize offset,
1695 VkDeviceSize range);
1696
1697 void
1698 anv_descriptor_set_write_template(struct anv_descriptor_set *set,
1699 struct anv_device *device,
1700 struct anv_state_stream *alloc_stream,
1701 const struct anv_descriptor_update_template *template,
1702 const void *data);
1703
1704 VkResult
1705 anv_descriptor_set_create(struct anv_device *device,
1706 struct anv_descriptor_pool *pool,
1707 struct anv_descriptor_set_layout *layout,
1708 struct anv_descriptor_set **out_set);
1709
1710 void
1711 anv_descriptor_set_destroy(struct anv_device *device,
1712 struct anv_descriptor_pool *pool,
1713 struct anv_descriptor_set *set);
1714
1715 #define ANV_DESCRIPTOR_SET_SHADER_CONSTANTS (UINT8_MAX - 1)
1716 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1717
1718 struct anv_pipeline_binding {
1719 /* The descriptor set this surface corresponds to. The special value of
1720 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1721 * to a color attachment and not a regular descriptor.
1722 */
1723 uint8_t set;
1724
1725 /* Binding in the descriptor set */
1726 uint32_t binding;
1727
1728 /* Index in the binding */
1729 uint32_t index;
1730
1731 /* Plane in the binding index */
1732 uint8_t plane;
1733
1734 /* Input attachment index (relative to the subpass) */
1735 uint8_t input_attachment_index;
1736
1737 /* For a storage image, whether it is write-only */
1738 bool write_only;
1739 };
1740
1741 struct anv_pipeline_layout {
1742 struct {
1743 struct anv_descriptor_set_layout *layout;
1744 uint32_t dynamic_offset_start;
1745 } set[MAX_SETS];
1746
1747 uint32_t num_sets;
1748
1749 struct {
1750 bool has_dynamic_offsets;
1751 } stage[MESA_SHADER_STAGES];
1752
1753 unsigned char sha1[20];
1754 };
1755
1756 struct anv_buffer {
1757 struct anv_device * device;
1758 VkDeviceSize size;
1759
1760 VkBufferUsageFlags usage;
1761
1762 /* Set when bound */
1763 struct anv_address address;
1764 };
1765
1766 static inline uint64_t
1767 anv_buffer_get_range(struct anv_buffer *buffer, uint64_t offset, uint64_t range)
1768 {
1769 assert(offset <= buffer->size);
1770 if (range == VK_WHOLE_SIZE) {
1771 return buffer->size - offset;
1772 } else {
1773 assert(range + offset >= range);
1774 assert(range + offset <= buffer->size);
1775 return range;
1776 }
1777 }
1778
1779 enum anv_cmd_dirty_bits {
1780 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1781 ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1782 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1783 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1784 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1785 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1786 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1787 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1788 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1789 ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
1790 ANV_CMD_DIRTY_PIPELINE = 1 << 9,
1791 ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
1792 ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
1793 ANV_CMD_DIRTY_XFB_ENABLE = 1 << 12,
1794 };
1795 typedef uint32_t anv_cmd_dirty_mask_t;
1796
1797 enum anv_pipe_bits {
1798 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
1799 ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
1800 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
1801 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
1802 ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
1803 ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
1804 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
1805 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
1806 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
1807 ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
1808 ANV_PIPE_CS_STALL_BIT = (1 << 20),
1809
1810 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1811 * a flush has happened but not a CS stall. The next time we do any sort
1812 * of invalidation we need to insert a CS stall at that time. Otherwise,
1813 * we would have to CS stall on every flush which could be bad.
1814 */
1815 ANV_PIPE_NEEDS_CS_STALL_BIT = (1 << 21),
1816
1817 /* This bit does not exist directly in PIPE_CONTROL. It means that render
1818 * target operations related to transfer commands with VkBuffer as
1819 * destination are ongoing. Some operations like copies on the command
1820 * streamer might need to be aware of this to trigger the appropriate stall
1821 * before they can proceed with the copy.
1822 */
1823 ANV_PIPE_RENDER_TARGET_BUFFER_WRITES = (1 << 22),
1824 };
1825
1826 #define ANV_PIPE_FLUSH_BITS ( \
1827 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1828 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1829 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1830
1831 #define ANV_PIPE_STALL_BITS ( \
1832 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1833 ANV_PIPE_DEPTH_STALL_BIT | \
1834 ANV_PIPE_CS_STALL_BIT)
1835
1836 #define ANV_PIPE_INVALIDATE_BITS ( \
1837 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1838 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1839 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1840 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1841 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1842 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1843
1844 static inline enum anv_pipe_bits
1845 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags)
1846 {
1847 enum anv_pipe_bits pipe_bits = 0;
1848
1849 unsigned b;
1850 for_each_bit(b, flags) {
1851 switch ((VkAccessFlagBits)(1 << b)) {
1852 case VK_ACCESS_SHADER_WRITE_BIT:
1853 /* We're transitioning a buffer that was previously used as write
1854 * destination through the data port. To make its content available
1855 * to future operations, flush the data cache.
1856 */
1857 pipe_bits |= ANV_PIPE_DATA_CACHE_FLUSH_BIT;
1858 break;
1859 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT:
1860 /* We're transitioning a buffer that was previously used as render
1861 * target. To make its content available to future operations, flush
1862 * the render target cache.
1863 */
1864 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
1865 break;
1866 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT:
1867 /* We're transitioning a buffer that was previously used as depth
1868 * buffer. To make its content available to future operations, flush
1869 * the depth cache.
1870 */
1871 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
1872 break;
1873 case VK_ACCESS_TRANSFER_WRITE_BIT:
1874 /* We're transitioning a buffer that was previously used as a
1875 * transfer write destination. Generic write operations include color
1876 * & depth operations as well as buffer operations like :
1877 * - vkCmdClearColorImage()
1878 * - vkCmdClearDepthStencilImage()
1879 * - vkCmdBlitImage()
1880 * - vkCmdCopy*(), vkCmdUpdate*(), vkCmdFill*()
1881 *
1882 * Most of these operations are implemented using Blorp which writes
1883 * through the render target, so flush that cache to make it visible
1884 * to future operations. And for depth related operations we also
1885 * need to flush the depth cache.
1886 */
1887 pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
1888 pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
1889 break;
1890 case VK_ACCESS_MEMORY_WRITE_BIT:
1891 /* We're transitioning a buffer for generic write operations. Flush
1892 * all the caches.
1893 */
1894 pipe_bits |= ANV_PIPE_FLUSH_BITS;
1895 break;
1896 default:
1897 break; /* Nothing to do */
1898 }
1899 }
1900
1901 return pipe_bits;
1902 }
1903
1904 static inline enum anv_pipe_bits
1905 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags)
1906 {
1907 enum anv_pipe_bits pipe_bits = 0;
1908
1909 unsigned b;
1910 for_each_bit(b, flags) {
1911 switch ((VkAccessFlagBits)(1 << b)) {
1912 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT:
1913 /* Indirect draw commands take a buffer as input that we're going to
1914 * read from the command streamer to load some of the HW registers
1915 * (see genX_cmd_buffer.c:load_indirect_parameters). This requires a
1916 * command streamer stall so that all the cache flushes have
1917 * completed before the command streamer loads from memory.
1918 */
1919 pipe_bits |= ANV_PIPE_CS_STALL_BIT;
1920 /* Indirect draw commands also set gl_BaseVertex & gl_BaseIndex
1921 * through a vertex buffer, so invalidate that cache.
1922 */
1923 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
1924 /* For CmdDipatchIndirect, we also load gl_NumWorkGroups through a
1925 * UBO from the buffer, so we need to invalidate constant cache.
1926 */
1927 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
1928 break;
1929 case VK_ACCESS_INDEX_READ_BIT:
1930 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT:
1931 /* We transitioning a buffer to be used for as input for vkCmdDraw*
1932 * commands, so we invalidate the VF cache to make sure there is no
1933 * stale data when we start rendering.
1934 */
1935 pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
1936 break;
1937 case VK_ACCESS_UNIFORM_READ_BIT:
1938 /* We transitioning a buffer to be used as uniform data. Because
1939 * uniform is accessed through the data port & sampler, we need to
1940 * invalidate the texture cache (sampler) & constant cache (data
1941 * port) to avoid stale data.
1942 */
1943 pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
1944 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
1945 break;
1946 case VK_ACCESS_SHADER_READ_BIT:
1947 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT:
1948 case VK_ACCESS_TRANSFER_READ_BIT:
1949 /* Transitioning a buffer to be read through the sampler, so
1950 * invalidate the texture cache, we don't want any stale data.
1951 */
1952 pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
1953 break;
1954 case VK_ACCESS_MEMORY_READ_BIT:
1955 /* Transitioning a buffer for generic read, invalidate all the
1956 * caches.
1957 */
1958 pipe_bits |= ANV_PIPE_INVALIDATE_BITS;
1959 break;
1960 case VK_ACCESS_MEMORY_WRITE_BIT:
1961 /* Generic write, make sure all previously written things land in
1962 * memory.
1963 */
1964 pipe_bits |= ANV_PIPE_FLUSH_BITS;
1965 break;
1966 case VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT:
1967 /* Transitioning a buffer for conditional rendering. We'll load the
1968 * content of this buffer into HW registers using the command
1969 * streamer, so we need to stall the command streamer to make sure
1970 * any in-flight flush operations have completed.
1971 */
1972 pipe_bits |= ANV_PIPE_CS_STALL_BIT;
1973 break;
1974 default:
1975 break; /* Nothing to do */
1976 }
1977 }
1978
1979 return pipe_bits;
1980 }
1981
1982 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
1983 VK_IMAGE_ASPECT_COLOR_BIT | \
1984 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1985 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1986 VK_IMAGE_ASPECT_PLANE_2_BIT)
1987 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
1988 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1989 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1990 VK_IMAGE_ASPECT_PLANE_2_BIT)
1991
1992 struct anv_vertex_binding {
1993 struct anv_buffer * buffer;
1994 VkDeviceSize offset;
1995 };
1996
1997 struct anv_xfb_binding {
1998 struct anv_buffer * buffer;
1999 VkDeviceSize offset;
2000 VkDeviceSize size;
2001 };
2002
2003 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
2004 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
2005
2006 struct anv_push_constants {
2007 /* Current allocated size of this push constants data structure.
2008 * Because a decent chunk of it may not be used (images on SKL, for
2009 * instance), we won't actually allocate the entire structure up-front.
2010 */
2011 uint32_t size;
2012
2013 /* Push constant data provided by the client through vkPushConstants */
2014 uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
2015
2016 /* Used for vkCmdDispatchBase */
2017 uint32_t base_work_group_id[3];
2018
2019 /* Image data for image_load_store on pre-SKL */
2020 struct brw_image_param images[MAX_GEN8_IMAGES];
2021 };
2022
2023 struct anv_dynamic_state {
2024 struct {
2025 uint32_t count;
2026 VkViewport viewports[MAX_VIEWPORTS];
2027 } viewport;
2028
2029 struct {
2030 uint32_t count;
2031 VkRect2D scissors[MAX_SCISSORS];
2032 } scissor;
2033
2034 float line_width;
2035
2036 struct {
2037 float bias;
2038 float clamp;
2039 float slope;
2040 } depth_bias;
2041
2042 float blend_constants[4];
2043
2044 struct {
2045 float min;
2046 float max;
2047 } depth_bounds;
2048
2049 struct {
2050 uint32_t front;
2051 uint32_t back;
2052 } stencil_compare_mask;
2053
2054 struct {
2055 uint32_t front;
2056 uint32_t back;
2057 } stencil_write_mask;
2058
2059 struct {
2060 uint32_t front;
2061 uint32_t back;
2062 } stencil_reference;
2063 };
2064
2065 extern const struct anv_dynamic_state default_dynamic_state;
2066
2067 void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
2068 const struct anv_dynamic_state *src,
2069 uint32_t copy_mask);
2070
2071 struct anv_surface_state {
2072 struct anv_state state;
2073 /** Address of the surface referred to by this state
2074 *
2075 * This address is relative to the start of the BO.
2076 */
2077 struct anv_address address;
2078 /* Address of the aux surface, if any
2079 *
2080 * This field is ANV_NULL_ADDRESS if and only if no aux surface exists.
2081 *
2082 * With the exception of gen8, the bottom 12 bits of this address' offset
2083 * include extra aux information.
2084 */
2085 struct anv_address aux_address;
2086 /* Address of the clear color, if any
2087 *
2088 * This address is relative to the start of the BO.
2089 */
2090 struct anv_address clear_address;
2091 };
2092
2093 /**
2094 * Attachment state when recording a renderpass instance.
2095 *
2096 * The clear value is valid only if there exists a pending clear.
2097 */
2098 struct anv_attachment_state {
2099 enum isl_aux_usage aux_usage;
2100 enum isl_aux_usage input_aux_usage;
2101 struct anv_surface_state color;
2102 struct anv_surface_state input;
2103
2104 VkImageLayout current_layout;
2105 VkImageAspectFlags pending_clear_aspects;
2106 VkImageAspectFlags pending_load_aspects;
2107 bool fast_clear;
2108 VkClearValue clear_value;
2109 bool clear_color_is_zero_one;
2110 bool clear_color_is_zero;
2111
2112 /* When multiview is active, attachments with a renderpass clear
2113 * operation have their respective layers cleared on the first
2114 * subpass that uses them, and only in that subpass. We keep track
2115 * of this using a bitfield to indicate which layers of an attachment
2116 * have not been cleared yet when multiview is active.
2117 */
2118 uint32_t pending_clear_views;
2119 };
2120
2121 /** State tracking for particular pipeline bind point
2122 *
2123 * This struct is the base struct for anv_cmd_graphics_state and
2124 * anv_cmd_compute_state. These are used to track state which is bound to a
2125 * particular type of pipeline. Generic state that applies per-stage such as
2126 * binding table offsets and push constants is tracked generically with a
2127 * per-stage array in anv_cmd_state.
2128 */
2129 struct anv_cmd_pipeline_state {
2130 struct anv_pipeline *pipeline;
2131 struct anv_pipeline_layout *layout;
2132
2133 struct anv_descriptor_set *descriptors[MAX_SETS];
2134 uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS];
2135
2136 struct anv_push_descriptor_set *push_descriptors[MAX_SETS];
2137 };
2138
2139 /** State tracking for graphics pipeline
2140 *
2141 * This has anv_cmd_pipeline_state as a base struct to track things which get
2142 * bound to a graphics pipeline. Along with general pipeline bind point state
2143 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2144 * state which is graphics-specific.
2145 */
2146 struct anv_cmd_graphics_state {
2147 struct anv_cmd_pipeline_state base;
2148
2149 anv_cmd_dirty_mask_t dirty;
2150 uint32_t vb_dirty;
2151
2152 struct anv_dynamic_state dynamic;
2153
2154 struct {
2155 struct anv_buffer *index_buffer;
2156 uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
2157 uint32_t index_offset;
2158 } gen7;
2159 };
2160
2161 /** State tracking for compute pipeline
2162 *
2163 * This has anv_cmd_pipeline_state as a base struct to track things which get
2164 * bound to a compute pipeline. Along with general pipeline bind point state
2165 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2166 * state which is compute-specific.
2167 */
2168 struct anv_cmd_compute_state {
2169 struct anv_cmd_pipeline_state base;
2170
2171 bool pipeline_dirty;
2172
2173 struct anv_address num_workgroups;
2174 };
2175
2176 /** State required while building cmd buffer */
2177 struct anv_cmd_state {
2178 /* PIPELINE_SELECT.PipelineSelection */
2179 uint32_t current_pipeline;
2180 const struct gen_l3_config * current_l3_config;
2181
2182 struct anv_cmd_graphics_state gfx;
2183 struct anv_cmd_compute_state compute;
2184
2185 enum anv_pipe_bits pending_pipe_bits;
2186 VkShaderStageFlags descriptors_dirty;
2187 VkShaderStageFlags push_constants_dirty;
2188
2189 struct anv_framebuffer * framebuffer;
2190 struct anv_render_pass * pass;
2191 struct anv_subpass * subpass;
2192 VkRect2D render_area;
2193 uint32_t restart_index;
2194 struct anv_vertex_binding vertex_bindings[MAX_VBS];
2195 bool xfb_enabled;
2196 struct anv_xfb_binding xfb_bindings[MAX_XFB_BUFFERS];
2197 VkShaderStageFlags push_constant_stages;
2198 struct anv_push_constants * push_constants[MESA_SHADER_STAGES];
2199 struct anv_state binding_tables[MESA_SHADER_STAGES];
2200 struct anv_state samplers[MESA_SHADER_STAGES];
2201
2202 /**
2203 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
2204 * of any command buffer it is disabled by disabling it in EndCommandBuffer
2205 * and before invoking the secondary in ExecuteCommands.
2206 */
2207 bool pma_fix_enabled;
2208
2209 /**
2210 * Whether or not we know for certain that HiZ is enabled for the current
2211 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
2212 * enabled or not, this will be false.
2213 */
2214 bool hiz_enabled;
2215
2216 bool conditional_render_enabled;
2217
2218 /**
2219 * Array length is anv_cmd_state::pass::attachment_count. Array content is
2220 * valid only when recording a render pass instance.
2221 */
2222 struct anv_attachment_state * attachments;
2223
2224 /**
2225 * Surface states for color render targets. These are stored in a single
2226 * flat array. For depth-stencil attachments, the surface state is simply
2227 * left blank.
2228 */
2229 struct anv_state render_pass_states;
2230
2231 /**
2232 * A null surface state of the right size to match the framebuffer. This
2233 * is one of the states in render_pass_states.
2234 */
2235 struct anv_state null_surface_state;
2236 };
2237
2238 struct anv_cmd_pool {
2239 VkAllocationCallbacks alloc;
2240 struct list_head cmd_buffers;
2241 };
2242
2243 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
2244
2245 enum anv_cmd_buffer_exec_mode {
2246 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
2247 ANV_CMD_BUFFER_EXEC_MODE_EMIT,
2248 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
2249 ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
2250 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
2251 };
2252
2253 struct anv_cmd_buffer {
2254 VK_LOADER_DATA _loader_data;
2255
2256 struct anv_device * device;
2257
2258 struct anv_cmd_pool * pool;
2259 struct list_head pool_link;
2260
2261 struct anv_batch batch;
2262
2263 /* Fields required for the actual chain of anv_batch_bo's.
2264 *
2265 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
2266 */
2267 struct list_head batch_bos;
2268 enum anv_cmd_buffer_exec_mode exec_mode;
2269
2270 /* A vector of anv_batch_bo pointers for every batch or surface buffer
2271 * referenced by this command buffer
2272 *
2273 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2274 */
2275 struct u_vector seen_bbos;
2276
2277 /* A vector of int32_t's for every block of binding tables.
2278 *
2279 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2280 */
2281 struct u_vector bt_block_states;
2282 uint32_t bt_next;
2283
2284 struct anv_reloc_list surface_relocs;
2285 /** Last seen surface state block pool center bo offset */
2286 uint32_t last_ss_pool_center;
2287
2288 /* Serial for tracking buffer completion */
2289 uint32_t serial;
2290
2291 /* Stream objects for storing temporary data */
2292 struct anv_state_stream surface_state_stream;
2293 struct anv_state_stream dynamic_state_stream;
2294
2295 VkCommandBufferUsageFlags usage_flags;
2296 VkCommandBufferLevel level;
2297
2298 struct anv_cmd_state state;
2299 };
2300
2301 VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2302 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2303 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
2304 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
2305 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
2306 struct anv_cmd_buffer *secondary);
2307 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
2308 VkResult anv_cmd_buffer_execbuf(struct anv_device *device,
2309 struct anv_cmd_buffer *cmd_buffer,
2310 const VkSemaphore *in_semaphores,
2311 uint32_t num_in_semaphores,
2312 const VkSemaphore *out_semaphores,
2313 uint32_t num_out_semaphores,
2314 VkFence fence);
2315
2316 VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
2317
2318 VkResult
2319 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
2320 gl_shader_stage stage, uint32_t size);
2321 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
2322 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
2323 (offsetof(struct anv_push_constants, field) + \
2324 sizeof(cmd_buffer->state.push_constants[0]->field)))
2325
2326 struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
2327 const void *data, uint32_t size, uint32_t alignment);
2328 struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
2329 uint32_t *a, uint32_t *b,
2330 uint32_t dwords, uint32_t alignment);
2331
2332 struct anv_address
2333 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
2334 struct anv_state
2335 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
2336 uint32_t entries, uint32_t *state_offset);
2337 struct anv_state
2338 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
2339 struct anv_state
2340 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
2341 uint32_t size, uint32_t alignment);
2342
2343 VkResult
2344 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
2345
2346 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
2347 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
2348 bool depth_clamp_enable);
2349 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
2350
2351 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
2352 struct anv_render_pass *pass,
2353 struct anv_framebuffer *framebuffer,
2354 const VkClearValue *clear_values);
2355
2356 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
2357
2358 struct anv_state
2359 anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
2360 gl_shader_stage stage);
2361 struct anv_state
2362 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
2363
2364 const struct anv_image_view *
2365 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
2366
2367 VkResult
2368 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
2369 uint32_t num_entries,
2370 uint32_t *state_offset,
2371 struct anv_state *bt_state);
2372
2373 void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
2374
2375 void anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer *cmd_buffer);
2376
2377 enum anv_fence_type {
2378 ANV_FENCE_TYPE_NONE = 0,
2379 ANV_FENCE_TYPE_BO,
2380 ANV_FENCE_TYPE_SYNCOBJ,
2381 ANV_FENCE_TYPE_WSI,
2382 };
2383
2384 enum anv_bo_fence_state {
2385 /** Indicates that this is a new (or newly reset fence) */
2386 ANV_BO_FENCE_STATE_RESET,
2387
2388 /** Indicates that this fence has been submitted to the GPU but is still
2389 * (as far as we know) in use by the GPU.
2390 */
2391 ANV_BO_FENCE_STATE_SUBMITTED,
2392
2393 ANV_BO_FENCE_STATE_SIGNALED,
2394 };
2395
2396 struct anv_fence_impl {
2397 enum anv_fence_type type;
2398
2399 union {
2400 /** Fence implementation for BO fences
2401 *
2402 * These fences use a BO and a set of CPU-tracked state flags. The BO
2403 * is added to the object list of the last execbuf call in a QueueSubmit
2404 * and is marked EXEC_WRITE. The state flags track when the BO has been
2405 * submitted to the kernel. We need to do this because Vulkan lets you
2406 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2407 * will say it's idle in this case.
2408 */
2409 struct {
2410 struct anv_bo bo;
2411 enum anv_bo_fence_state state;
2412 } bo;
2413
2414 /** DRM syncobj handle for syncobj-based fences */
2415 uint32_t syncobj;
2416
2417 /** WSI fence */
2418 struct wsi_fence *fence_wsi;
2419 };
2420 };
2421
2422 struct anv_fence {
2423 /* Permanent fence state. Every fence has some form of permanent state
2424 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2425 * cross-process fences) or it could just be a dummy for use internally.
2426 */
2427 struct anv_fence_impl permanent;
2428
2429 /* Temporary fence state. A fence *may* have temporary state. That state
2430 * is added to the fence by an import operation and is reset back to
2431 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2432 * state cannot be signaled because the fence must already be signaled
2433 * before the temporary state can be exported from the fence in the other
2434 * process and imported here.
2435 */
2436 struct anv_fence_impl temporary;
2437 };
2438
2439 struct anv_event {
2440 uint64_t semaphore;
2441 struct anv_state state;
2442 };
2443
2444 enum anv_semaphore_type {
2445 ANV_SEMAPHORE_TYPE_NONE = 0,
2446 ANV_SEMAPHORE_TYPE_DUMMY,
2447 ANV_SEMAPHORE_TYPE_BO,
2448 ANV_SEMAPHORE_TYPE_SYNC_FILE,
2449 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ,
2450 };
2451
2452 struct anv_semaphore_impl {
2453 enum anv_semaphore_type type;
2454
2455 union {
2456 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
2457 * This BO will be added to the object list on any execbuf2 calls for
2458 * which this semaphore is used as a wait or signal fence. When used as
2459 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
2460 */
2461 struct anv_bo *bo;
2462
2463 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
2464 * If the semaphore is in the unsignaled state due to either just being
2465 * created or because it has been used for a wait, fd will be -1.
2466 */
2467 int fd;
2468
2469 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
2470 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
2471 * import so we don't need to bother with a userspace cache.
2472 */
2473 uint32_t syncobj;
2474 };
2475 };
2476
2477 struct anv_semaphore {
2478 /* Permanent semaphore state. Every semaphore has some form of permanent
2479 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
2480 * (for cross-process semaphores0 or it could just be a dummy for use
2481 * internally.
2482 */
2483 struct anv_semaphore_impl permanent;
2484
2485 /* Temporary semaphore state. A semaphore *may* have temporary state.
2486 * That state is added to the semaphore by an import operation and is reset
2487 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
2488 * semaphore with temporary state cannot be signaled because the semaphore
2489 * must already be signaled before the temporary state can be exported from
2490 * the semaphore in the other process and imported here.
2491 */
2492 struct anv_semaphore_impl temporary;
2493 };
2494
2495 void anv_semaphore_reset_temporary(struct anv_device *device,
2496 struct anv_semaphore *semaphore);
2497
2498 struct anv_shader_module {
2499 unsigned char sha1[20];
2500 uint32_t size;
2501 char data[0];
2502 };
2503
2504 static inline gl_shader_stage
2505 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
2506 {
2507 assert(__builtin_popcount(vk_stage) == 1);
2508 return ffs(vk_stage) - 1;
2509 }
2510
2511 static inline VkShaderStageFlagBits
2512 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
2513 {
2514 return (1 << mesa_stage);
2515 }
2516
2517 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2518
2519 #define anv_foreach_stage(stage, stage_bits) \
2520 for (gl_shader_stage stage, \
2521 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2522 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2523 __tmp &= ~(1 << (stage)))
2524
2525 struct anv_pipeline_bind_map {
2526 uint32_t surface_count;
2527 uint32_t sampler_count;
2528 uint32_t image_count;
2529
2530 struct anv_pipeline_binding * surface_to_descriptor;
2531 struct anv_pipeline_binding * sampler_to_descriptor;
2532 };
2533
2534 struct anv_shader_bin_key {
2535 uint32_t size;
2536 uint8_t data[0];
2537 };
2538
2539 struct anv_shader_bin {
2540 uint32_t ref_cnt;
2541
2542 const struct anv_shader_bin_key *key;
2543
2544 struct anv_state kernel;
2545 uint32_t kernel_size;
2546
2547 struct anv_state constant_data;
2548 uint32_t constant_data_size;
2549
2550 const struct brw_stage_prog_data *prog_data;
2551 uint32_t prog_data_size;
2552
2553 struct nir_xfb_info *xfb_info;
2554
2555 struct anv_pipeline_bind_map bind_map;
2556 };
2557
2558 struct anv_shader_bin *
2559 anv_shader_bin_create(struct anv_device *device,
2560 const void *key, uint32_t key_size,
2561 const void *kernel, uint32_t kernel_size,
2562 const void *constant_data, uint32_t constant_data_size,
2563 const struct brw_stage_prog_data *prog_data,
2564 uint32_t prog_data_size, const void *prog_data_param,
2565 const struct nir_xfb_info *xfb_info,
2566 const struct anv_pipeline_bind_map *bind_map);
2567
2568 void
2569 anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
2570
2571 static inline void
2572 anv_shader_bin_ref(struct anv_shader_bin *shader)
2573 {
2574 assert(shader && shader->ref_cnt >= 1);
2575 p_atomic_inc(&shader->ref_cnt);
2576 }
2577
2578 static inline void
2579 anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
2580 {
2581 assert(shader && shader->ref_cnt >= 1);
2582 if (p_atomic_dec_zero(&shader->ref_cnt))
2583 anv_shader_bin_destroy(device, shader);
2584 }
2585
2586 struct anv_pipeline {
2587 struct anv_device * device;
2588 struct anv_batch batch;
2589 uint32_t batch_data[512];
2590 struct anv_reloc_list batch_relocs;
2591 uint32_t dynamic_state_mask;
2592 struct anv_dynamic_state dynamic_state;
2593
2594 struct anv_subpass * subpass;
2595
2596 bool needs_data_cache;
2597
2598 struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
2599
2600 struct {
2601 const struct gen_l3_config * l3_config;
2602 uint32_t total_size;
2603 } urb;
2604
2605 VkShaderStageFlags active_stages;
2606 struct anv_state blend_state;
2607
2608 uint32_t vb_used;
2609 struct anv_pipeline_vertex_binding {
2610 uint32_t stride;
2611 bool instanced;
2612 uint32_t instance_divisor;
2613 } vb[MAX_VBS];
2614
2615 uint8_t xfb_used;
2616
2617 bool primitive_restart;
2618 uint32_t topology;
2619
2620 uint32_t cs_right_mask;
2621
2622 bool writes_depth;
2623 bool depth_test_enable;
2624 bool writes_stencil;
2625 bool stencil_test_enable;
2626 bool depth_clamp_enable;
2627 bool sample_shading_enable;
2628 bool kill_pixel;
2629
2630 struct {
2631 uint32_t sf[7];
2632 uint32_t depth_stencil_state[3];
2633 } gen7;
2634
2635 struct {
2636 uint32_t sf[4];
2637 uint32_t raster[5];
2638 uint32_t wm_depth_stencil[3];
2639 } gen8;
2640
2641 struct {
2642 uint32_t wm_depth_stencil[4];
2643 } gen9;
2644
2645 uint32_t interface_descriptor_data[8];
2646 };
2647
2648 static inline bool
2649 anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
2650 gl_shader_stage stage)
2651 {
2652 return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
2653 }
2654
2655 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2656 static inline const struct brw_##prefix##_prog_data * \
2657 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2658 { \
2659 if (anv_pipeline_has_stage(pipeline, stage)) { \
2660 return (const struct brw_##prefix##_prog_data *) \
2661 pipeline->shaders[stage]->prog_data; \
2662 } else { \
2663 return NULL; \
2664 } \
2665 }
2666
2667 ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
2668 ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
2669 ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
2670 ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
2671 ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
2672 ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
2673
2674 static inline const struct brw_vue_prog_data *
2675 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
2676 {
2677 if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
2678 return &get_gs_prog_data(pipeline)->base;
2679 else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
2680 return &get_tes_prog_data(pipeline)->base;
2681 else
2682 return &get_vs_prog_data(pipeline)->base;
2683 }
2684
2685 VkResult
2686 anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
2687 struct anv_pipeline_cache *cache,
2688 const VkGraphicsPipelineCreateInfo *pCreateInfo,
2689 const VkAllocationCallbacks *alloc);
2690
2691 VkResult
2692 anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
2693 struct anv_pipeline_cache *cache,
2694 const VkComputePipelineCreateInfo *info,
2695 const struct anv_shader_module *module,
2696 const char *entrypoint,
2697 const VkSpecializationInfo *spec_info);
2698
2699 struct anv_format_plane {
2700 enum isl_format isl_format:16;
2701 struct isl_swizzle swizzle;
2702
2703 /* Whether this plane contains chroma channels */
2704 bool has_chroma;
2705
2706 /* For downscaling of YUV planes */
2707 uint8_t denominator_scales[2];
2708
2709 /* How to map sampled ycbcr planes to a single 4 component element. */
2710 struct isl_swizzle ycbcr_swizzle;
2711
2712 /* What aspect is associated to this plane */
2713 VkImageAspectFlags aspect;
2714 };
2715
2716
2717 struct anv_format {
2718 struct anv_format_plane planes[3];
2719 VkFormat vk_format;
2720 uint8_t n_planes;
2721 bool can_ycbcr;
2722 };
2723
2724 static inline uint32_t
2725 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects,
2726 VkImageAspectFlags aspect_mask)
2727 {
2728 switch (aspect_mask) {
2729 case VK_IMAGE_ASPECT_COLOR_BIT:
2730 case VK_IMAGE_ASPECT_DEPTH_BIT:
2731 case VK_IMAGE_ASPECT_PLANE_0_BIT:
2732 return 0;
2733 case VK_IMAGE_ASPECT_STENCIL_BIT:
2734 if ((image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) == 0)
2735 return 0;
2736 /* Fall-through */
2737 case VK_IMAGE_ASPECT_PLANE_1_BIT:
2738 return 1;
2739 case VK_IMAGE_ASPECT_PLANE_2_BIT:
2740 return 2;
2741 default:
2742 /* Purposefully assert with depth/stencil aspects. */
2743 unreachable("invalid image aspect");
2744 }
2745 }
2746
2747 static inline VkImageAspectFlags
2748 anv_plane_to_aspect(VkImageAspectFlags image_aspects,
2749 uint32_t plane)
2750 {
2751 if (image_aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) {
2752 if (util_bitcount(image_aspects) > 1)
2753 return VK_IMAGE_ASPECT_PLANE_0_BIT << plane;
2754 return VK_IMAGE_ASPECT_COLOR_BIT;
2755 }
2756 if (image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT)
2757 return VK_IMAGE_ASPECT_DEPTH_BIT << plane;
2758 assert(image_aspects == VK_IMAGE_ASPECT_STENCIL_BIT);
2759 return VK_IMAGE_ASPECT_STENCIL_BIT;
2760 }
2761
2762 #define anv_foreach_image_aspect_bit(b, image, aspects) \
2763 for_each_bit(b, anv_image_expand_aspects(image, aspects))
2764
2765 const struct anv_format *
2766 anv_get_format(VkFormat format);
2767
2768 static inline uint32_t
2769 anv_get_format_planes(VkFormat vk_format)
2770 {
2771 const struct anv_format *format = anv_get_format(vk_format);
2772
2773 return format != NULL ? format->n_planes : 0;
2774 }
2775
2776 struct anv_format_plane
2777 anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
2778 VkImageAspectFlagBits aspect, VkImageTiling tiling);
2779
2780 static inline enum isl_format
2781 anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
2782 VkImageAspectFlags aspect, VkImageTiling tiling)
2783 {
2784 return anv_get_format_plane(devinfo, vk_format, aspect, tiling).isl_format;
2785 }
2786
2787 static inline struct isl_swizzle
2788 anv_swizzle_for_render(struct isl_swizzle swizzle)
2789 {
2790 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2791 * RGB as RGBA for texturing
2792 */
2793 assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
2794 swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
2795
2796 /* But it doesn't matter what we render to that channel */
2797 swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
2798
2799 return swizzle;
2800 }
2801
2802 void
2803 anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
2804
2805 /**
2806 * Subsurface of an anv_image.
2807 */
2808 struct anv_surface {
2809 /** Valid only if isl_surf::size_B > 0. */
2810 struct isl_surf isl;
2811
2812 /**
2813 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2814 */
2815 uint32_t offset;
2816 };
2817
2818 struct anv_image {
2819 VkImageType type;
2820 /* The original VkFormat provided by the client. This may not match any
2821 * of the actual surface formats.
2822 */
2823 VkFormat vk_format;
2824 const struct anv_format *format;
2825
2826 VkImageAspectFlags aspects;
2827 VkExtent3D extent;
2828 uint32_t levels;
2829 uint32_t array_size;
2830 uint32_t samples; /**< VkImageCreateInfo::samples */
2831 uint32_t n_planes;
2832 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
2833 VkImageCreateFlags create_flags; /* Flags used when creating image. */
2834 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
2835
2836 /** True if this is needs to be bound to an appropriately tiled BO.
2837 *
2838 * When not using modifiers, consumers such as X11, Wayland, and KMS need
2839 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
2840 * we require a dedicated allocation so that we can know to allocate a
2841 * tiled buffer.
2842 */
2843 bool needs_set_tiling;
2844
2845 /**
2846 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
2847 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
2848 */
2849 uint64_t drm_format_mod;
2850
2851 VkDeviceSize size;
2852 uint32_t alignment;
2853
2854 /* Whether the image is made of several underlying buffer objects rather a
2855 * single one with different offsets.
2856 */
2857 bool disjoint;
2858
2859 /* All the formats that can be used when creating views of this image
2860 * are CCS_E compatible.
2861 */
2862 bool ccs_e_compatible;
2863
2864 /* Image was created with external format. */
2865 bool external_format;
2866
2867 /**
2868 * Image subsurfaces
2869 *
2870 * For each foo, anv_image::planes[x].surface is valid if and only if
2871 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
2872 * to figure the number associated with a given aspect.
2873 *
2874 * The hardware requires that the depth buffer and stencil buffer be
2875 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2876 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2877 * allocate the depth and stencil buffers as separate surfaces in the same
2878 * bo.
2879 *
2880 * Memory layout :
2881 *
2882 * -----------------------
2883 * | surface0 | /|\
2884 * ----------------------- |
2885 * | shadow surface0 | |
2886 * ----------------------- | Plane 0
2887 * | aux surface0 | |
2888 * ----------------------- |
2889 * | fast clear colors0 | \|/
2890 * -----------------------
2891 * | surface1 | /|\
2892 * ----------------------- |
2893 * | shadow surface1 | |
2894 * ----------------------- | Plane 1
2895 * | aux surface1 | |
2896 * ----------------------- |
2897 * | fast clear colors1 | \|/
2898 * -----------------------
2899 * | ... |
2900 * | |
2901 * -----------------------
2902 */
2903 struct {
2904 /**
2905 * Offset of the entire plane (whenever the image is disjoint this is
2906 * set to 0).
2907 */
2908 uint32_t offset;
2909
2910 VkDeviceSize size;
2911 uint32_t alignment;
2912
2913 struct anv_surface surface;
2914
2915 /**
2916 * A surface which shadows the main surface and may have different
2917 * tiling. This is used for sampling using a tiling that isn't supported
2918 * for other operations.
2919 */
2920 struct anv_surface shadow_surface;
2921
2922 /**
2923 * For color images, this is the aux usage for this image when not used
2924 * as a color attachment.
2925 *
2926 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
2927 * image has a HiZ buffer.
2928 */
2929 enum isl_aux_usage aux_usage;
2930
2931 struct anv_surface aux_surface;
2932
2933 /**
2934 * Offset of the fast clear state (used to compute the
2935 * fast_clear_state_offset of the following planes).
2936 */
2937 uint32_t fast_clear_state_offset;
2938
2939 /**
2940 * BO associated with this plane, set when bound.
2941 */
2942 struct anv_address address;
2943
2944 /**
2945 * When destroying the image, also free the bo.
2946 * */
2947 bool bo_is_owned;
2948 } planes[3];
2949 };
2950
2951 /* The ordering of this enum is important */
2952 enum anv_fast_clear_type {
2953 /** Image does not have/support any fast-clear blocks */
2954 ANV_FAST_CLEAR_NONE = 0,
2955 /** Image has/supports fast-clear but only to the default value */
2956 ANV_FAST_CLEAR_DEFAULT_VALUE = 1,
2957 /** Image has/supports fast-clear with an arbitrary fast-clear value */
2958 ANV_FAST_CLEAR_ANY = 2,
2959 };
2960
2961 /* Returns the number of auxiliary buffer levels attached to an image. */
2962 static inline uint8_t
2963 anv_image_aux_levels(const struct anv_image * const image,
2964 VkImageAspectFlagBits aspect)
2965 {
2966 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
2967 return image->planes[plane].aux_surface.isl.size_B > 0 ?
2968 image->planes[plane].aux_surface.isl.levels : 0;
2969 }
2970
2971 /* Returns the number of auxiliary buffer layers attached to an image. */
2972 static inline uint32_t
2973 anv_image_aux_layers(const struct anv_image * const image,
2974 VkImageAspectFlagBits aspect,
2975 const uint8_t miplevel)
2976 {
2977 assert(image);
2978
2979 /* The miplevel must exist in the main buffer. */
2980 assert(miplevel < image->levels);
2981
2982 if (miplevel >= anv_image_aux_levels(image, aspect)) {
2983 /* There are no layers with auxiliary data because the miplevel has no
2984 * auxiliary data.
2985 */
2986 return 0;
2987 } else {
2988 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
2989 return MAX2(image->planes[plane].aux_surface.isl.logical_level0_px.array_len,
2990 image->planes[plane].aux_surface.isl.logical_level0_px.depth >> miplevel);
2991 }
2992 }
2993
2994 static inline struct anv_address
2995 anv_image_get_clear_color_addr(const struct anv_device *device,
2996 const struct anv_image *image,
2997 VkImageAspectFlagBits aspect)
2998 {
2999 assert(image->aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV);
3000
3001 uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3002 return anv_address_add(image->planes[plane].address,
3003 image->planes[plane].fast_clear_state_offset);
3004 }
3005
3006 static inline struct anv_address
3007 anv_image_get_fast_clear_type_addr(const struct anv_device *device,
3008 const struct anv_image *image,
3009 VkImageAspectFlagBits aspect)
3010 {
3011 struct anv_address addr =
3012 anv_image_get_clear_color_addr(device, image, aspect);
3013
3014 const unsigned clear_color_state_size = device->info.gen >= 10 ?
3015 device->isl_dev.ss.clear_color_state_size :
3016 device->isl_dev.ss.clear_value_size;
3017 return anv_address_add(addr, clear_color_state_size);
3018 }
3019
3020 static inline struct anv_address
3021 anv_image_get_compression_state_addr(const struct anv_device *device,
3022 const struct anv_image *image,
3023 VkImageAspectFlagBits aspect,
3024 uint32_t level, uint32_t array_layer)
3025 {
3026 assert(level < anv_image_aux_levels(image, aspect));
3027 assert(array_layer < anv_image_aux_layers(image, aspect, level));
3028 UNUSED uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
3029 assert(image->planes[plane].aux_usage == ISL_AUX_USAGE_CCS_E);
3030
3031 struct anv_address addr =
3032 anv_image_get_fast_clear_type_addr(device, image, aspect);
3033 addr.offset += 4; /* Go past the fast clear type */
3034
3035 if (image->type == VK_IMAGE_TYPE_3D) {
3036 for (uint32_t l = 0; l < level; l++)
3037 addr.offset += anv_minify(image->extent.depth, l) * 4;
3038 } else {
3039 addr.offset += level * image->array_size * 4;
3040 }
3041 addr.offset += array_layer * 4;
3042
3043 return addr;
3044 }
3045
3046 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
3047 static inline bool
3048 anv_can_sample_with_hiz(const struct gen_device_info * const devinfo,
3049 const struct anv_image *image)
3050 {
3051 if (!(image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT))
3052 return false;
3053
3054 if (devinfo->gen < 8)
3055 return false;
3056
3057 return image->samples == 1;
3058 }
3059
3060 void
3061 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer *cmd_buffer,
3062 const struct anv_image *image,
3063 VkImageAspectFlagBits aspect,
3064 enum isl_aux_usage aux_usage,
3065 uint32_t level,
3066 uint32_t base_layer,
3067 uint32_t layer_count);
3068
3069 void
3070 anv_image_clear_color(struct anv_cmd_buffer *cmd_buffer,
3071 const struct anv_image *image,
3072 VkImageAspectFlagBits aspect,
3073 enum isl_aux_usage aux_usage,
3074 enum isl_format format, struct isl_swizzle swizzle,
3075 uint32_t level, uint32_t base_layer, uint32_t layer_count,
3076 VkRect2D area, union isl_color_value clear_color);
3077 void
3078 anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
3079 const struct anv_image *image,
3080 VkImageAspectFlags aspects,
3081 enum isl_aux_usage depth_aux_usage,
3082 uint32_t level,
3083 uint32_t base_layer, uint32_t layer_count,
3084 VkRect2D area,
3085 float depth_value, uint8_t stencil_value);
3086 void
3087 anv_image_msaa_resolve(struct anv_cmd_buffer *cmd_buffer,
3088 const struct anv_image *src_image,
3089 enum isl_aux_usage src_aux_usage,
3090 uint32_t src_level, uint32_t src_base_layer,
3091 const struct anv_image *dst_image,
3092 enum isl_aux_usage dst_aux_usage,
3093 uint32_t dst_level, uint32_t dst_base_layer,
3094 VkImageAspectFlagBits aspect,
3095 uint32_t src_x, uint32_t src_y,
3096 uint32_t dst_x, uint32_t dst_y,
3097 uint32_t width, uint32_t height,
3098 uint32_t layer_count,
3099 enum blorp_filter filter);
3100 void
3101 anv_image_hiz_op(struct anv_cmd_buffer *cmd_buffer,
3102 const struct anv_image *image,
3103 VkImageAspectFlagBits aspect, uint32_t level,
3104 uint32_t base_layer, uint32_t layer_count,
3105 enum isl_aux_op hiz_op);
3106 void
3107 anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
3108 const struct anv_image *image,
3109 VkImageAspectFlags aspects,
3110 uint32_t level,
3111 uint32_t base_layer, uint32_t layer_count,
3112 VkRect2D area, uint8_t stencil_value);
3113 void
3114 anv_image_mcs_op(struct anv_cmd_buffer *cmd_buffer,
3115 const struct anv_image *image,
3116 enum isl_format format,
3117 VkImageAspectFlagBits aspect,
3118 uint32_t base_layer, uint32_t layer_count,
3119 enum isl_aux_op mcs_op, union isl_color_value *clear_value,
3120 bool predicate);
3121 void
3122 anv_image_ccs_op(struct anv_cmd_buffer *cmd_buffer,
3123 const struct anv_image *image,
3124 enum isl_format format,
3125 VkImageAspectFlagBits aspect, uint32_t level,
3126 uint32_t base_layer, uint32_t layer_count,
3127 enum isl_aux_op ccs_op, union isl_color_value *clear_value,
3128 bool predicate);
3129
3130 void
3131 anv_image_copy_to_shadow(struct anv_cmd_buffer *cmd_buffer,
3132 const struct anv_image *image,
3133 uint32_t base_level, uint32_t level_count,
3134 uint32_t base_layer, uint32_t layer_count);
3135
3136 enum isl_aux_usage
3137 anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
3138 const struct anv_image *image,
3139 const VkImageAspectFlagBits aspect,
3140 const VkImageLayout layout);
3141
3142 enum anv_fast_clear_type
3143 anv_layout_to_fast_clear_type(const struct gen_device_info * const devinfo,
3144 const struct anv_image * const image,
3145 const VkImageAspectFlagBits aspect,
3146 const VkImageLayout layout);
3147
3148 /* This is defined as a macro so that it works for both
3149 * VkImageSubresourceRange and VkImageSubresourceLayers
3150 */
3151 #define anv_get_layerCount(_image, _range) \
3152 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
3153 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
3154
3155 static inline uint32_t
3156 anv_get_levelCount(const struct anv_image *image,
3157 const VkImageSubresourceRange *range)
3158 {
3159 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
3160 image->levels - range->baseMipLevel : range->levelCount;
3161 }
3162
3163 static inline VkImageAspectFlags
3164 anv_image_expand_aspects(const struct anv_image *image,
3165 VkImageAspectFlags aspects)
3166 {
3167 /* If the underlying image has color plane aspects and
3168 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
3169 * the underlying image. */
3170 if ((image->aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) != 0 &&
3171 aspects == VK_IMAGE_ASPECT_COLOR_BIT)
3172 return image->aspects;
3173
3174 return aspects;
3175 }
3176
3177 static inline bool
3178 anv_image_aspects_compatible(VkImageAspectFlags aspects1,
3179 VkImageAspectFlags aspects2)
3180 {
3181 if (aspects1 == aspects2)
3182 return true;
3183
3184 /* Only 1 color aspects are compatibles. */
3185 if ((aspects1 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
3186 (aspects2 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
3187 util_bitcount(aspects1) == util_bitcount(aspects2))
3188 return true;
3189
3190 return false;
3191 }
3192
3193 struct anv_image_view {
3194 const struct anv_image *image; /**< VkImageViewCreateInfo::image */
3195
3196 VkImageAspectFlags aspect_mask;
3197 VkFormat vk_format;
3198 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
3199
3200 unsigned n_planes;
3201 struct {
3202 uint32_t image_plane;
3203
3204 struct isl_view isl;
3205
3206 /**
3207 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3208 * image layout of SHADER_READ_ONLY_OPTIMAL or
3209 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
3210 */
3211 struct anv_surface_state optimal_sampler_surface_state;
3212
3213 /**
3214 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3215 * image layout of GENERAL.
3216 */
3217 struct anv_surface_state general_sampler_surface_state;
3218
3219 /**
3220 * RENDER_SURFACE_STATE when using image as a storage image. Separate
3221 * states for write-only and readable, using the real format for
3222 * write-only and the lowered format for readable.
3223 */
3224 struct anv_surface_state storage_surface_state;
3225 struct anv_surface_state writeonly_storage_surface_state;
3226
3227 struct brw_image_param storage_image_param;
3228 } planes[3];
3229 };
3230
3231 enum anv_image_view_state_flags {
3232 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY = (1 << 0),
3233 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL = (1 << 1),
3234 };
3235
3236 void anv_image_fill_surface_state(struct anv_device *device,
3237 const struct anv_image *image,
3238 VkImageAspectFlagBits aspect,
3239 const struct isl_view *view,
3240 isl_surf_usage_flags_t view_usage,
3241 enum isl_aux_usage aux_usage,
3242 const union isl_color_value *clear_color,
3243 enum anv_image_view_state_flags flags,
3244 struct anv_surface_state *state_inout,
3245 struct brw_image_param *image_param_out);
3246
3247 struct anv_image_create_info {
3248 const VkImageCreateInfo *vk_info;
3249
3250 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
3251 isl_tiling_flags_t isl_tiling_flags;
3252
3253 /** These flags will be added to any derived from VkImageCreateInfo. */
3254 isl_surf_usage_flags_t isl_extra_usage_flags;
3255
3256 uint32_t stride;
3257 bool external_format;
3258 };
3259
3260 VkResult anv_image_create(VkDevice _device,
3261 const struct anv_image_create_info *info,
3262 const VkAllocationCallbacks* alloc,
3263 VkImage *pImage);
3264
3265 const struct anv_surface *
3266 anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
3267 VkImageAspectFlags aspect_mask);
3268
3269 enum isl_format
3270 anv_isl_format_for_descriptor_type(VkDescriptorType type);
3271
3272 static inline struct VkExtent3D
3273 anv_sanitize_image_extent(const VkImageType imageType,
3274 const struct VkExtent3D imageExtent)
3275 {
3276 switch (imageType) {
3277 case VK_IMAGE_TYPE_1D:
3278 return (VkExtent3D) { imageExtent.width, 1, 1 };
3279 case VK_IMAGE_TYPE_2D:
3280 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
3281 case VK_IMAGE_TYPE_3D:
3282 return imageExtent;
3283 default:
3284 unreachable("invalid image type");
3285 }
3286 }
3287
3288 static inline struct VkOffset3D
3289 anv_sanitize_image_offset(const VkImageType imageType,
3290 const struct VkOffset3D imageOffset)
3291 {
3292 switch (imageType) {
3293 case VK_IMAGE_TYPE_1D:
3294 return (VkOffset3D) { imageOffset.x, 0, 0 };
3295 case VK_IMAGE_TYPE_2D:
3296 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
3297 case VK_IMAGE_TYPE_3D:
3298 return imageOffset;
3299 default:
3300 unreachable("invalid image type");
3301 }
3302 }
3303
3304 VkFormatFeatureFlags
3305 anv_get_image_format_features(const struct gen_device_info *devinfo,
3306 VkFormat vk_format,
3307 const struct anv_format *anv_format,
3308 VkImageTiling vk_tiling);
3309
3310 void anv_fill_buffer_surface_state(struct anv_device *device,
3311 struct anv_state state,
3312 enum isl_format format,
3313 struct anv_address address,
3314 uint32_t range, uint32_t stride);
3315
3316 static inline void
3317 anv_clear_color_from_att_state(union isl_color_value *clear_color,
3318 const struct anv_attachment_state *att_state,
3319 const struct anv_image_view *iview)
3320 {
3321 const struct isl_format_layout *view_fmtl =
3322 isl_format_get_layout(iview->planes[0].isl.format);
3323
3324 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
3325 if (view_fmtl->channels.c.bits) \
3326 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
3327
3328 COPY_CLEAR_COLOR_CHANNEL(r, 0);
3329 COPY_CLEAR_COLOR_CHANNEL(g, 1);
3330 COPY_CLEAR_COLOR_CHANNEL(b, 2);
3331 COPY_CLEAR_COLOR_CHANNEL(a, 3);
3332
3333 #undef COPY_CLEAR_COLOR_CHANNEL
3334 }
3335
3336
3337 struct anv_ycbcr_conversion {
3338 const struct anv_format * format;
3339 VkSamplerYcbcrModelConversion ycbcr_model;
3340 VkSamplerYcbcrRange ycbcr_range;
3341 VkComponentSwizzle mapping[4];
3342 VkChromaLocation chroma_offsets[2];
3343 VkFilter chroma_filter;
3344 bool chroma_reconstruction;
3345 };
3346
3347 struct anv_sampler {
3348 uint32_t state[3][4];
3349 uint32_t n_planes;
3350 struct anv_ycbcr_conversion *conversion;
3351 };
3352
3353 struct anv_framebuffer {
3354 uint32_t width;
3355 uint32_t height;
3356 uint32_t layers;
3357
3358 uint32_t attachment_count;
3359 struct anv_image_view * attachments[0];
3360 };
3361
3362 struct anv_subpass_attachment {
3363 VkImageUsageFlagBits usage;
3364 uint32_t attachment;
3365 VkImageLayout layout;
3366 };
3367
3368 struct anv_subpass {
3369 uint32_t attachment_count;
3370
3371 /**
3372 * A pointer to all attachment references used in this subpass.
3373 * Only valid if ::attachment_count > 0.
3374 */
3375 struct anv_subpass_attachment * attachments;
3376 uint32_t input_count;
3377 struct anv_subpass_attachment * input_attachments;
3378 uint32_t color_count;
3379 struct anv_subpass_attachment * color_attachments;
3380 struct anv_subpass_attachment * resolve_attachments;
3381
3382 struct anv_subpass_attachment * depth_stencil_attachment;
3383 struct anv_subpass_attachment * ds_resolve_attachment;
3384 VkResolveModeFlagBitsKHR depth_resolve_mode;
3385 VkResolveModeFlagBitsKHR stencil_resolve_mode;
3386
3387 uint32_t view_mask;
3388
3389 /** Subpass has a depth/stencil self-dependency */
3390 bool has_ds_self_dep;
3391
3392 /** Subpass has at least one color resolve attachment */
3393 bool has_color_resolve;
3394 };
3395
3396 static inline unsigned
3397 anv_subpass_view_count(const struct anv_subpass *subpass)
3398 {
3399 return MAX2(1, util_bitcount(subpass->view_mask));
3400 }
3401
3402 struct anv_render_pass_attachment {
3403 /* TODO: Consider using VkAttachmentDescription instead of storing each of
3404 * its members individually.
3405 */
3406 VkFormat format;
3407 uint32_t samples;
3408 VkImageUsageFlags usage;
3409 VkAttachmentLoadOp load_op;
3410 VkAttachmentStoreOp store_op;
3411 VkAttachmentLoadOp stencil_load_op;
3412 VkImageLayout initial_layout;
3413 VkImageLayout final_layout;
3414 VkImageLayout first_subpass_layout;
3415
3416 /* The subpass id in which the attachment will be used last. */
3417 uint32_t last_subpass_idx;
3418 };
3419
3420 struct anv_render_pass {
3421 uint32_t attachment_count;
3422 uint32_t subpass_count;
3423 /* An array of subpass_count+1 flushes, one per subpass boundary */
3424 enum anv_pipe_bits * subpass_flushes;
3425 struct anv_render_pass_attachment * attachments;
3426 struct anv_subpass subpasses[0];
3427 };
3428
3429 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
3430
3431 struct anv_query_pool {
3432 VkQueryType type;
3433 VkQueryPipelineStatisticFlags pipeline_statistics;
3434 /** Stride between slots, in bytes */
3435 uint32_t stride;
3436 /** Number of slots in this query pool */
3437 uint32_t slots;
3438 struct anv_bo bo;
3439 };
3440
3441 int anv_get_instance_entrypoint_index(const char *name);
3442 int anv_get_device_entrypoint_index(const char *name);
3443
3444 bool
3445 anv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
3446 const struct anv_instance_extension_table *instance);
3447
3448 bool
3449 anv_device_entrypoint_is_enabled(int index, uint32_t core_version,
3450 const struct anv_instance_extension_table *instance,
3451 const struct anv_device_extension_table *device);
3452
3453 void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
3454 const char *name);
3455
3456 void anv_dump_image_to_ppm(struct anv_device *device,
3457 struct anv_image *image, unsigned miplevel,
3458 unsigned array_layer, VkImageAspectFlagBits aspect,
3459 const char *filename);
3460
3461 enum anv_dump_action {
3462 ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
3463 };
3464
3465 void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
3466 void anv_dump_finish(void);
3467
3468 void anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
3469 struct anv_framebuffer *fb);
3470
3471 static inline uint32_t
3472 anv_get_subpass_id(const struct anv_cmd_state * const cmd_state)
3473 {
3474 /* This function must be called from within a subpass. */
3475 assert(cmd_state->pass && cmd_state->subpass);
3476
3477 const uint32_t subpass_id = cmd_state->subpass - cmd_state->pass->subpasses;
3478
3479 /* The id of this subpass shouldn't exceed the number of subpasses in this
3480 * render pass minus 1.
3481 */
3482 assert(subpass_id < cmd_state->pass->subpass_count);
3483 return subpass_id;
3484 }
3485
3486 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
3487 \
3488 static inline struct __anv_type * \
3489 __anv_type ## _from_handle(__VkType _handle) \
3490 { \
3491 return (struct __anv_type *) _handle; \
3492 } \
3493 \
3494 static inline __VkType \
3495 __anv_type ## _to_handle(struct __anv_type *_obj) \
3496 { \
3497 return (__VkType) _obj; \
3498 }
3499
3500 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
3501 \
3502 static inline struct __anv_type * \
3503 __anv_type ## _from_handle(__VkType _handle) \
3504 { \
3505 return (struct __anv_type *)(uintptr_t) _handle; \
3506 } \
3507 \
3508 static inline __VkType \
3509 __anv_type ## _to_handle(struct __anv_type *_obj) \
3510 { \
3511 return (__VkType)(uintptr_t) _obj; \
3512 }
3513
3514 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
3515 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
3516
3517 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
3518 ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
3519 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
3520 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
3521 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
3522
3523 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
3524 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
3525 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
3526 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
3527 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
3528 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
3529 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplate)
3530 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
3531 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
3532 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
3533 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
3534 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
3535 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
3536 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
3537 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
3538 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
3539 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
3540 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
3541 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
3542 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore, VkSemaphore)
3543 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
3544 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback, VkDebugReportCallbackEXT)
3545 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion, VkSamplerYcbcrConversion)
3546
3547 /* Gen-specific function declarations */
3548 #ifdef genX
3549 # include "anv_genX.h"
3550 #else
3551 # define genX(x) gen7_##x
3552 # include "anv_genX.h"
3553 # undef genX
3554 # define genX(x) gen75_##x
3555 # include "anv_genX.h"
3556 # undef genX
3557 # define genX(x) gen8_##x
3558 # include "anv_genX.h"
3559 # undef genX
3560 # define genX(x) gen9_##x
3561 # include "anv_genX.h"
3562 # undef genX
3563 # define genX(x) gen10_##x
3564 # include "anv_genX.h"
3565 # undef genX
3566 # define genX(x) gen11_##x
3567 # include "anv_genX.h"
3568 # undef genX
3569 #endif
3570
3571 #endif /* ANV_PRIVATE_H */