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