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