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