2 * Copyright © 2015 Intel Corporation
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:
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
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
33 #include "drm-uapi/i915_drm.h"
40 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
43 #define VG(x) ((void)0)
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"
56 #include "util/u_atomic.h"
57 #include "util/u_vector.h"
58 #include "util/u_math.h"
60 #include "util/xmlconfig.h"
62 #include "vk_debug_report.h"
64 /* Pre-declarations needed for WSI entrypoints */
67 typedef struct xcb_connection_t xcb_connection_t
;
68 typedef uint32_t xcb_visualid_t
;
69 typedef uint32_t xcb_window_t
;
72 struct anv_buffer_view
;
73 struct anv_image_view
;
76 struct gen_aux_map_context
;
78 struct gen_perf_config
;
80 #include <vulkan/vulkan.h>
81 #include <vulkan/vulkan_intel.h>
82 #include <vulkan/vk_icd.h>
84 #include "anv_android.h"
85 #include "anv_entrypoints.h"
86 #include "anv_extensions.h"
89 #include "dev/gen_debug.h"
90 #include "common/intel_log.h"
91 #include "wsi_common.h"
93 /* anv Virtual Memory Layout
94 * =========================
96 * When the anv driver is determining the virtual graphics addresses of memory
97 * objects itself using the softpin mechanism, the following memory ranges
100 * Three special considerations to notice:
102 * (1) the dynamic state pool is located within the same 4 GiB as the low
103 * heap. This is to work around a VF cache issue described in a comment in
104 * anv_physical_device_init_heaps.
106 * (2) the binding table pool is located at lower addresses than the surface
107 * state pool, within a 4 GiB range. This allows surface state base addresses
108 * to cover both binding tables (16 bit offsets) and surface states (32 bit
111 * (3) the last 4 GiB of the address space is withheld from the high
112 * heap. Various hardware units will read past the end of an object for
113 * various reasons. This healthy margin prevents reads from wrapping around
116 #define LOW_HEAP_MIN_ADDRESS 0x000000001000ULL /* 4 KiB */
117 #define LOW_HEAP_MAX_ADDRESS 0x0000bfffffffULL
118 #define DYNAMIC_STATE_POOL_MIN_ADDRESS 0x0000c0000000ULL /* 3 GiB */
119 #define DYNAMIC_STATE_POOL_MAX_ADDRESS 0x0000ffffffffULL
120 #define BINDING_TABLE_POOL_MIN_ADDRESS 0x000100000000ULL /* 4 GiB */
121 #define BINDING_TABLE_POOL_MAX_ADDRESS 0x00013fffffffULL
122 #define SURFACE_STATE_POOL_MIN_ADDRESS 0x000140000000ULL /* 5 GiB */
123 #define SURFACE_STATE_POOL_MAX_ADDRESS 0x00017fffffffULL
124 #define INSTRUCTION_STATE_POOL_MIN_ADDRESS 0x000180000000ULL /* 6 GiB */
125 #define INSTRUCTION_STATE_POOL_MAX_ADDRESS 0x0001bfffffffULL
126 #define HIGH_HEAP_MIN_ADDRESS 0x0001c0000000ULL /* 7 GiB */
128 #define LOW_HEAP_SIZE \
129 (LOW_HEAP_MAX_ADDRESS - LOW_HEAP_MIN_ADDRESS + 1)
130 #define DYNAMIC_STATE_POOL_SIZE \
131 (DYNAMIC_STATE_POOL_MAX_ADDRESS - DYNAMIC_STATE_POOL_MIN_ADDRESS + 1)
132 #define BINDING_TABLE_POOL_SIZE \
133 (BINDING_TABLE_POOL_MAX_ADDRESS - BINDING_TABLE_POOL_MIN_ADDRESS + 1)
134 #define SURFACE_STATE_POOL_SIZE \
135 (SURFACE_STATE_POOL_MAX_ADDRESS - SURFACE_STATE_POOL_MIN_ADDRESS + 1)
136 #define INSTRUCTION_STATE_POOL_SIZE \
137 (INSTRUCTION_STATE_POOL_MAX_ADDRESS - INSTRUCTION_STATE_POOL_MIN_ADDRESS + 1)
139 /* Allowing different clear colors requires us to perform a depth resolve at
140 * the end of certain render passes. This is because while slow clears store
141 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
142 * See the PRMs for examples describing when additional resolves would be
143 * necessary. To enable fast clears without requiring extra resolves, we set
144 * the clear value to a globally-defined one. We could allow different values
145 * if the user doesn't expect coherent data during or after a render passes
146 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
147 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
148 * 1.0f seems to be the only value used. The only application that doesn't set
149 * this value does so through the usage of an seemingly uninitialized clear
152 #define ANV_HZ_FC_VAL 1.0f
155 #define MAX_XFB_BUFFERS 4
156 #define MAX_XFB_STREAMS 4
159 #define MAX_VIEWPORTS 16
160 #define MAX_SCISSORS 16
161 #define MAX_PUSH_CONSTANTS_SIZE 128
162 #define MAX_DYNAMIC_BUFFERS 16
163 #define MAX_IMAGES 64
164 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
165 #define MAX_INLINE_UNIFORM_BLOCK_SIZE 4096
166 #define MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS 32
168 /* From the Skylake PRM Vol. 7 "Binding Table Surface State Model":
170 * "The surface state model is used when a Binding Table Index (specified
171 * in the message descriptor) of less than 240 is specified. In this model,
172 * the Binding Table Index is used to index into the binding table, and the
173 * binding table entry contains a pointer to the SURFACE_STATE."
175 * Binding table values above 240 are used for various things in the hardware
176 * such as stateless, stateless with incoherent cache, SLM, and bindless.
178 #define MAX_BINDING_TABLE_SIZE 240
180 /* The kernel relocation API has a limitation of a 32-bit delta value
181 * applied to the address before it is written which, in spite of it being
182 * unsigned, is treated as signed . Because of the way that this maps to
183 * the Vulkan API, we cannot handle an offset into a buffer that does not
184 * fit into a signed 32 bits. The only mechanism we have for dealing with
185 * this at the moment is to limit all VkDeviceMemory objects to a maximum
186 * of 2GB each. The Vulkan spec allows us to do this:
188 * "Some platforms may have a limit on the maximum size of a single
189 * allocation. For example, certain systems may fail to create
190 * allocations with a size greater than or equal to 4GB. Such a limit is
191 * implementation-dependent, and if such a failure occurs then the error
192 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
194 * We don't use vk_error here because it's not an error so much as an
195 * indication to the application that the allocation is too large.
197 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
199 #define ANV_SVGS_VB_INDEX MAX_VBS
200 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
202 /* We reserve this MI ALU register for the purpose of handling predication.
203 * Other code which uses the MI ALU should leave it alone.
205 #define ANV_PREDICATE_RESULT_REG 0x2678 /* MI_ALU_REG15 */
207 /* For gen12 we set the streamout buffers using 4 separate commands
208 * (3DSTATE_SO_BUFFER_INDEX_*) instead of 3DSTATE_SO_BUFFER. However the layout
209 * of the 3DSTATE_SO_BUFFER_INDEX_* commands is identical to that of
210 * 3DSTATE_SO_BUFFER apart from the SOBufferIndex field, so for now we use the
211 * 3DSTATE_SO_BUFFER command, but change the 3DCommandSubOpcode.
212 * SO_BUFFER_INDEX_0_CMD is actually the 3DCommandSubOpcode for
213 * 3DSTATE_SO_BUFFER_INDEX_0.
215 #define SO_BUFFER_INDEX_0_CMD 0x60
216 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
218 static inline uint32_t
219 align_down_npot_u32(uint32_t v
, uint32_t a
)
224 static inline uint32_t
225 align_u32(uint32_t v
, uint32_t a
)
227 assert(a
!= 0 && a
== (a
& -a
));
228 return (v
+ a
- 1) & ~(a
- 1);
231 static inline uint64_t
232 align_u64(uint64_t v
, uint64_t a
)
234 assert(a
!= 0 && a
== (a
& -a
));
235 return (v
+ a
- 1) & ~(a
- 1);
238 static inline int32_t
239 align_i32(int32_t v
, int32_t a
)
241 assert(a
!= 0 && a
== (a
& -a
));
242 return (v
+ a
- 1) & ~(a
- 1);
245 /** Alignment must be a power of 2. */
247 anv_is_aligned(uintmax_t n
, uintmax_t a
)
249 assert(a
== (a
& -a
));
250 return (n
& (a
- 1)) == 0;
253 static inline uint32_t
254 anv_minify(uint32_t n
, uint32_t levels
)
256 if (unlikely(n
== 0))
259 return MAX2(n
>> levels
, 1);
263 anv_clamp_f(float f
, float min
, float max
)
276 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
278 if (*inout_mask
& clear_mask
) {
279 *inout_mask
&= ~clear_mask
;
286 static inline union isl_color_value
287 vk_to_isl_color(VkClearColorValue color
)
289 return (union isl_color_value
) {
299 #define for_each_bit(b, dword) \
300 for (uint32_t __dword = (dword); \
301 (b) = __builtin_ffs(__dword) - 1, __dword; \
302 __dword &= ~(1 << (b)))
304 #define typed_memcpy(dest, src, count) ({ \
305 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
306 memcpy((dest), (src), (count) * sizeof(*(src))); \
309 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
310 * to be added here in order to utilize mapping in debug/error/perf macros.
312 #define REPORT_OBJECT_TYPE(o) \
313 __builtin_choose_expr ( \
314 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
315 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
316 __builtin_choose_expr ( \
317 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
318 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
319 __builtin_choose_expr ( \
320 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
321 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
322 __builtin_choose_expr ( \
323 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
324 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
325 __builtin_choose_expr ( \
326 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
327 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
328 __builtin_choose_expr ( \
329 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
330 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
331 __builtin_choose_expr ( \
332 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
333 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
334 __builtin_choose_expr ( \
335 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
336 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
337 __builtin_choose_expr ( \
338 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
339 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
340 __builtin_choose_expr ( \
341 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
342 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
343 __builtin_choose_expr ( \
344 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
345 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
346 __builtin_choose_expr ( \
347 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
348 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
349 __builtin_choose_expr ( \
350 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
351 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
352 __builtin_choose_expr ( \
353 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
354 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
355 __builtin_choose_expr ( \
356 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
357 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
358 __builtin_choose_expr ( \
359 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
360 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
361 __builtin_choose_expr ( \
362 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
363 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
364 __builtin_choose_expr ( \
365 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
366 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
367 __builtin_choose_expr ( \
368 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
369 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
370 __builtin_choose_expr ( \
371 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
372 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
373 __builtin_choose_expr ( \
374 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
375 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
376 __builtin_choose_expr ( \
377 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
378 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
379 __builtin_choose_expr ( \
380 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
381 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
382 __builtin_choose_expr ( \
383 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
384 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
385 __builtin_choose_expr ( \
386 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
387 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
388 __builtin_choose_expr ( \
389 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
390 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
391 __builtin_choose_expr ( \
392 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
393 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
394 __builtin_choose_expr ( \
395 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
396 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
397 __builtin_choose_expr ( \
398 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
399 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
400 __builtin_choose_expr ( \
401 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
402 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
403 __builtin_choose_expr ( \
404 __builtin_types_compatible_p (__typeof (o), void*), \
405 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
406 /* The void expression results in a compile-time error \
407 when assigning the result to something. */ \
408 (void)0)))))))))))))))))))))))))))))))
410 /* Whenever we generate an error, pass it through this function. Useful for
411 * debugging, where we can break on it. Only call at error site, not when
412 * propagating errors. Might be useful to plug in a stack trace here.
415 VkResult
__vk_errorv(struct anv_instance
*instance
, const void *object
,
416 VkDebugReportObjectTypeEXT type
, VkResult error
,
417 const char *file
, int line
, const char *format
,
420 VkResult
__vk_errorf(struct anv_instance
*instance
, const void *object
,
421 VkDebugReportObjectTypeEXT type
, VkResult error
,
422 const char *file
, int line
, const char *format
, ...)
423 anv_printflike(7, 8);
426 #define vk_error(error) __vk_errorf(NULL, NULL,\
427 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
428 error, __FILE__, __LINE__, NULL)
429 #define vk_errorv(instance, obj, error, format, args)\
430 __vk_errorv(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
431 __FILE__, __LINE__, format, args)
432 #define vk_errorf(instance, obj, error, format, ...)\
433 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
434 __FILE__, __LINE__, format, ## __VA_ARGS__)
436 #define vk_error(error) error
437 #define vk_errorf(instance, obj, error, format, ...) error
441 * Warn on ignored extension structs.
443 * The Vulkan spec requires us to ignore unsupported or unknown structs in
444 * a pNext chain. In debug mode, emitting warnings for ignored structs may
445 * help us discover structs that we should not have ignored.
448 * From the Vulkan 1.0.38 spec:
450 * Any component of the implementation (the loader, any enabled layers,
451 * and drivers) must skip over, without processing (other than reading the
452 * sType and pNext members) any chained structures with sType values not
453 * defined by extensions supported by that component.
455 #define anv_debug_ignored_stype(sType) \
456 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
458 void __anv_perf_warn(struct anv_instance
*instance
, const void *object
,
459 VkDebugReportObjectTypeEXT type
, const char *file
,
460 int line
, const char *format
, ...)
461 anv_printflike(6, 7);
462 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
463 void anv_loge_v(const char *format
, va_list va
);
466 * Print a FINISHME message, including its source location.
468 #define anv_finishme(format, ...) \
470 static bool reported = false; \
472 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
479 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
481 #define anv_perf_warn(instance, obj, format, ...) \
483 static bool reported = false; \
484 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
485 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
486 format, ##__VA_ARGS__); \
491 /* A non-fatal assert. Useful for debugging. */
493 #define anv_assert(x) ({ \
494 if (unlikely(!(x))) \
495 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
498 #define anv_assert(x)
501 /* A multi-pointer allocator
503 * When copying data structures from the user (such as a render pass), it's
504 * common to need to allocate data for a bunch of different things. Instead
505 * of doing several allocations and having to handle all of the error checking
506 * that entails, it can be easier to do a single allocation. This struct
507 * helps facilitate that. The intended usage looks like this:
510 * anv_multialloc_add(&ma, &main_ptr, 1);
511 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
512 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
514 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
515 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
517 struct anv_multialloc
{
525 #define ANV_MULTIALLOC_INIT \
526 ((struct anv_multialloc) { 0, })
528 #define ANV_MULTIALLOC(_name) \
529 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
531 __attribute__((always_inline
))
533 _anv_multialloc_add(struct anv_multialloc
*ma
,
534 void **ptr
, size_t size
, size_t align
)
536 size_t offset
= align_u64(ma
->size
, align
);
537 ma
->size
= offset
+ size
;
538 ma
->align
= MAX2(ma
->align
, align
);
540 /* Store the offset in the pointer. */
541 *ptr
= (void *)(uintptr_t)offset
;
543 assert(ma
->ptr_count
< ARRAY_SIZE(ma
->ptrs
));
544 ma
->ptrs
[ma
->ptr_count
++] = ptr
;
547 #define anv_multialloc_add_size(_ma, _ptr, _size) \
548 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
550 #define anv_multialloc_add(_ma, _ptr, _count) \
551 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
553 __attribute__((always_inline
))
555 anv_multialloc_alloc(struct anv_multialloc
*ma
,
556 const VkAllocationCallbacks
*alloc
,
557 VkSystemAllocationScope scope
)
559 void *ptr
= vk_alloc(alloc
, ma
->size
, ma
->align
, scope
);
563 /* Fill out each of the pointers with their final value.
565 * for (uint32_t i = 0; i < ma->ptr_count; i++)
566 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
568 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
569 * constant, GCC is incapable of figuring this out and unrolling the loop
570 * so we have to give it a little help.
572 STATIC_ASSERT(ARRAY_SIZE(ma
->ptrs
) == 8);
573 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
574 if ((_i) < ma->ptr_count) \
575 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
576 _ANV_MULTIALLOC_UPDATE_POINTER(0);
577 _ANV_MULTIALLOC_UPDATE_POINTER(1);
578 _ANV_MULTIALLOC_UPDATE_POINTER(2);
579 _ANV_MULTIALLOC_UPDATE_POINTER(3);
580 _ANV_MULTIALLOC_UPDATE_POINTER(4);
581 _ANV_MULTIALLOC_UPDATE_POINTER(5);
582 _ANV_MULTIALLOC_UPDATE_POINTER(6);
583 _ANV_MULTIALLOC_UPDATE_POINTER(7);
584 #undef _ANV_MULTIALLOC_UPDATE_POINTER
589 __attribute__((always_inline
))
591 anv_multialloc_alloc2(struct anv_multialloc
*ma
,
592 const VkAllocationCallbacks
*parent_alloc
,
593 const VkAllocationCallbacks
*alloc
,
594 VkSystemAllocationScope scope
)
596 return anv_multialloc_alloc(ma
, alloc
? alloc
: parent_alloc
, scope
);
599 /* Extra ANV-defined BO flags which won't be passed to the kernel */
600 #define ANV_BO_EXTERNAL (1ull << 31)
601 #define ANV_BO_FLAG_MASK (1ull << 31)
608 /* Index into the current validation list. This is used by the
609 * validation list building alrogithm to track which buffers are already
610 * in the validation list so that we can ensure uniqueness.
614 /* Last known offset. This value is provided by the kernel when we
615 * execbuf and is used as the presumed offset for the next bunch of
623 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
628 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
630 bo
->gem_handle
= gem_handle
;
639 /* Represents a lock-free linked list of "free" things. This is used by
640 * both the block pool and the state pools. Unfortunately, in order to
641 * solve the ABA problem, we can't use a single uint32_t head.
643 union anv_free_list
{
647 /* A simple count that is incremented every time the head changes. */
650 /* Make sure it's aligned to 64 bits. This will make atomic operations
651 * faster on 32 bit platforms.
653 uint64_t u64
__attribute__ ((aligned (8)));
656 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { UINT32_MAX, 0 } })
658 struct anv_block_state
{
664 /* Make sure it's aligned to 64 bits. This will make atomic operations
665 * faster on 32 bit platforms.
667 uint64_t u64
__attribute__ ((aligned (8)));
671 #define anv_block_pool_foreach_bo(bo, pool) \
672 for (bo = (pool)->bos; bo != &(pool)->bos[(pool)->nbos]; bo++)
674 #define ANV_MAX_BLOCK_POOL_BOS 20
676 struct anv_block_pool
{
677 struct anv_device
*device
;
681 struct anv_bo bos
[ANV_MAX_BLOCK_POOL_BOS
];
687 /* The address where the start of the pool is pinned. The various bos that
688 * are created as the pool grows will have addresses in the range
689 * [start_address, start_address + BLOCK_POOL_MEMFD_SIZE).
691 uint64_t start_address
;
693 /* The offset from the start of the bo to the "center" of the block
694 * pool. Pointers to allocated blocks are given by
695 * bo.map + center_bo_offset + offsets.
697 uint32_t center_bo_offset
;
699 /* Current memory map of the block pool. This pointer may or may not
700 * point to the actual beginning of the block pool memory. If
701 * anv_block_pool_alloc_back has ever been called, then this pointer
702 * will point to the "center" position of the buffer and all offsets
703 * (negative or positive) given out by the block pool alloc functions
704 * will be valid relative to this pointer.
706 * In particular, map == bo.map + center_offset
708 * DO NOT access this pointer directly. Use anv_block_pool_map() instead,
709 * since it will handle the softpin case as well, where this points to NULL.
715 * Array of mmaps and gem handles owned by the block pool, reclaimed when
716 * the block pool is destroyed.
718 struct u_vector mmap_cleanups
;
720 struct anv_block_state state
;
722 struct anv_block_state back_state
;
725 /* Block pools are backed by a fixed-size 1GB memfd */
726 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
728 /* The center of the block pool is also the middle of the memfd. This may
729 * change in the future if we decide differently for some reason.
731 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
733 static inline uint32_t
734 anv_block_pool_size(struct anv_block_pool
*pool
)
736 return pool
->state
.end
+ pool
->back_state
.end
;
746 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
748 struct anv_fixed_size_state_pool
{
749 union anv_free_list free_list
;
750 struct anv_block_state block
;
753 #define ANV_MIN_STATE_SIZE_LOG2 6
754 #define ANV_MAX_STATE_SIZE_LOG2 21
756 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
758 struct anv_free_entry
{
760 struct anv_state state
;
763 struct anv_state_table
{
764 struct anv_device
*device
;
766 struct anv_free_entry
*map
;
768 struct anv_block_state state
;
769 struct u_vector cleanups
;
772 struct anv_state_pool
{
773 struct anv_block_pool block_pool
;
775 struct anv_state_table table
;
777 /* The size of blocks which will be allocated from the block pool */
780 /** Free list for "back" allocations */
781 union anv_free_list back_alloc_free_list
;
783 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
786 struct anv_state_stream_block
;
788 struct anv_state_stream
{
789 struct anv_state_pool
*state_pool
;
791 /* The size of blocks to allocate from the state pool */
794 /* Current block we're allocating from */
795 struct anv_state block
;
797 /* Offset into the current block at which to allocate the next state */
800 /* List of all blocks allocated from this pool */
801 struct anv_state_stream_block
*block_list
;
804 /* The block_pool functions exported for testing only. The block pool should
805 * only be used via a state pool (see below).
807 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
808 struct anv_device
*device
,
809 uint64_t start_address
,
810 uint32_t initial_size
,
812 void anv_block_pool_finish(struct anv_block_pool
*pool
);
813 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
,
814 uint32_t block_size
, uint32_t *padding
);
815 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
,
816 uint32_t block_size
);
817 void* anv_block_pool_map(struct anv_block_pool
*pool
, int32_t offset
);
819 VkResult
anv_state_pool_init(struct anv_state_pool
*pool
,
820 struct anv_device
*device
,
821 uint64_t start_address
,
824 void anv_state_pool_finish(struct anv_state_pool
*pool
);
825 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
826 uint32_t state_size
, uint32_t alignment
);
827 struct anv_state
anv_state_pool_alloc_back(struct anv_state_pool
*pool
);
828 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
829 void anv_state_stream_init(struct anv_state_stream
*stream
,
830 struct anv_state_pool
*state_pool
,
831 uint32_t block_size
);
832 void anv_state_stream_finish(struct anv_state_stream
*stream
);
833 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
834 uint32_t size
, uint32_t alignment
);
836 VkResult
anv_state_table_init(struct anv_state_table
*table
,
837 struct anv_device
*device
,
838 uint32_t initial_entries
);
839 void anv_state_table_finish(struct anv_state_table
*table
);
840 VkResult
anv_state_table_add(struct anv_state_table
*table
, uint32_t *idx
,
842 void anv_free_list_push(union anv_free_list
*list
,
843 struct anv_state_table
*table
,
844 uint32_t idx
, uint32_t count
);
845 struct anv_state
* anv_free_list_pop(union anv_free_list
*list
,
846 struct anv_state_table
*table
);
849 static inline struct anv_state
*
850 anv_state_table_get(struct anv_state_table
*table
, uint32_t idx
)
852 return &table
->map
[idx
].state
;
855 * Implements a pool of re-usable BOs. The interface is identical to that
856 * of block_pool except that each block is its own BO.
859 struct anv_device
*device
;
866 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
,
868 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
869 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
871 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
873 struct anv_scratch_bo
{
878 struct anv_scratch_pool
{
879 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
880 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
883 void anv_scratch_pool_init(struct anv_device
*device
,
884 struct anv_scratch_pool
*pool
);
885 void anv_scratch_pool_finish(struct anv_device
*device
,
886 struct anv_scratch_pool
*pool
);
887 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
888 struct anv_scratch_pool
*pool
,
889 gl_shader_stage stage
,
890 unsigned per_thread_scratch
);
892 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
893 struct anv_bo_cache
{
894 struct hash_table
*bo_map
;
895 pthread_mutex_t mutex
;
898 VkResult
anv_bo_cache_init(struct anv_bo_cache
*cache
);
899 void anv_bo_cache_finish(struct anv_bo_cache
*cache
);
900 VkResult
anv_bo_cache_alloc(struct anv_device
*device
,
901 struct anv_bo_cache
*cache
,
902 uint64_t size
, uint64_t bo_flags
,
904 VkResult
anv_bo_cache_import_host_ptr(struct anv_device
*device
,
905 struct anv_bo_cache
*cache
,
906 void *host_ptr
, uint32_t size
,
907 uint64_t bo_flags
, struct anv_bo
**bo_out
);
908 VkResult
anv_bo_cache_import(struct anv_device
*device
,
909 struct anv_bo_cache
*cache
,
910 int fd
, uint64_t bo_flags
,
912 VkResult
anv_bo_cache_export(struct anv_device
*device
,
913 struct anv_bo_cache
*cache
,
914 struct anv_bo
*bo_in
, int *fd_out
);
915 void anv_bo_cache_release(struct anv_device
*device
,
916 struct anv_bo_cache
*cache
,
919 struct anv_memory_type
{
920 /* Standard bits passed on to the client */
921 VkMemoryPropertyFlags propertyFlags
;
924 /* Driver-internal book-keeping */
925 VkBufferUsageFlags valid_buffer_usage
;
928 struct anv_memory_heap
{
929 /* Standard bits passed on to the client */
931 VkMemoryHeapFlags flags
;
933 /* Driver-internal book-keeping */
936 bool supports_48bit_addresses
;
940 struct anv_physical_device
{
941 VK_LOADER_DATA _loader_data
;
943 struct anv_instance
* instance
;
954 struct gen_device_info info
;
955 /** Amount of "GPU memory" we want to advertise
957 * Clearly, this value is bogus since Intel is a UMA architecture. On
958 * gen7 platforms, we are limited by GTT size unless we want to implement
959 * fine-grained tracking and GTT splitting. On Broadwell and above we are
960 * practically unlimited. However, we will never report more than 3/4 of
961 * the total system ram to try and avoid running out of RAM.
963 bool supports_48bit_addresses
;
964 struct brw_compiler
* compiler
;
965 struct isl_device isl_dev
;
966 struct gen_perf_config
* perf
;
967 int cmd_parser_version
;
969 bool has_exec_capture
;
972 bool has_syncobj_wait
;
973 bool has_context_priority
;
975 bool has_context_isolation
;
976 bool has_mem_available
;
977 bool always_use_bindless
;
979 /** True if we can access buffers using A64 messages */
980 bool has_a64_buffer_access
;
981 /** True if we can use bindless access for images */
982 bool has_bindless_images
;
983 /** True if we can use bindless access for samplers */
984 bool has_bindless_samplers
;
986 struct anv_device_extension_table supported_extensions
;
987 struct anv_physical_device_dispatch_table dispatch
;
990 uint32_t subslice_total
;
994 struct anv_memory_type types
[VK_MAX_MEMORY_TYPES
];
996 struct anv_memory_heap heaps
[VK_MAX_MEMORY_HEAPS
];
999 uint8_t driver_build_sha1
[20];
1000 uint8_t pipeline_cache_uuid
[VK_UUID_SIZE
];
1001 uint8_t driver_uuid
[VK_UUID_SIZE
];
1002 uint8_t device_uuid
[VK_UUID_SIZE
];
1004 struct disk_cache
* disk_cache
;
1006 struct wsi_device wsi_device
;
1011 struct anv_app_info
{
1012 const char* app_name
;
1013 uint32_t app_version
;
1014 const char* engine_name
;
1015 uint32_t engine_version
;
1016 uint32_t api_version
;
1019 struct anv_instance
{
1020 VK_LOADER_DATA _loader_data
;
1022 VkAllocationCallbacks alloc
;
1024 struct anv_app_info app_info
;
1026 struct anv_instance_extension_table enabled_extensions
;
1027 struct anv_instance_dispatch_table dispatch
;
1028 struct anv_device_dispatch_table device_dispatch
;
1030 int physicalDeviceCount
;
1031 struct anv_physical_device physicalDevice
;
1033 bool pipeline_cache_enabled
;
1035 struct vk_debug_report_instance debug_report_callbacks
;
1037 struct driOptionCache dri_options
;
1038 struct driOptionCache available_dri_options
;
1041 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
1042 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
1044 uint32_t anv_physical_device_api_version(struct anv_physical_device
*dev
);
1045 bool anv_physical_device_extension_supported(struct anv_physical_device
*dev
,
1049 VK_LOADER_DATA _loader_data
;
1051 struct anv_device
* device
;
1053 VkDeviceQueueCreateFlags flags
;
1056 struct anv_pipeline_cache
{
1057 struct anv_device
* device
;
1058 pthread_mutex_t mutex
;
1060 struct hash_table
* nir_cache
;
1062 struct hash_table
* cache
;
1065 struct nir_xfb_info
;
1066 struct anv_pipeline_bind_map
;
1068 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
1069 struct anv_device
*device
,
1070 bool cache_enabled
);
1071 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
1073 struct anv_shader_bin
*
1074 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
1075 const void *key
, uint32_t key_size
);
1076 struct anv_shader_bin
*
1077 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
1078 const void *key_data
, uint32_t key_size
,
1079 const void *kernel_data
, uint32_t kernel_size
,
1080 const void *constant_data
,
1081 uint32_t constant_data_size
,
1082 const struct brw_stage_prog_data
*prog_data
,
1083 uint32_t prog_data_size
,
1084 const struct brw_compile_stats
*stats
,
1086 const struct nir_xfb_info
*xfb_info
,
1087 const struct anv_pipeline_bind_map
*bind_map
);
1089 struct anv_shader_bin
*
1090 anv_device_search_for_kernel(struct anv_device
*device
,
1091 struct anv_pipeline_cache
*cache
,
1092 const void *key_data
, uint32_t key_size
,
1093 bool *user_cache_bit
);
1095 struct anv_shader_bin
*
1096 anv_device_upload_kernel(struct anv_device
*device
,
1097 struct anv_pipeline_cache
*cache
,
1098 const void *key_data
, uint32_t key_size
,
1099 const void *kernel_data
, uint32_t kernel_size
,
1100 const void *constant_data
,
1101 uint32_t constant_data_size
,
1102 const struct brw_stage_prog_data
*prog_data
,
1103 uint32_t prog_data_size
,
1104 const struct brw_compile_stats
*stats
,
1106 const struct nir_xfb_info
*xfb_info
,
1107 const struct anv_pipeline_bind_map
*bind_map
);
1110 struct nir_shader_compiler_options
;
1113 anv_device_search_for_nir(struct anv_device
*device
,
1114 struct anv_pipeline_cache
*cache
,
1115 const struct nir_shader_compiler_options
*nir_options
,
1116 unsigned char sha1_key
[20],
1120 anv_device_upload_nir(struct anv_device
*device
,
1121 struct anv_pipeline_cache
*cache
,
1122 const struct nir_shader
*nir
,
1123 unsigned char sha1_key
[20]);
1126 VK_LOADER_DATA _loader_data
;
1128 VkAllocationCallbacks alloc
;
1130 struct anv_instance
* instance
;
1131 uint32_t chipset_id
;
1133 struct gen_device_info info
;
1134 struct isl_device isl_dev
;
1137 bool can_chain_batches
;
1138 bool robust_buffer_access
;
1139 struct anv_device_extension_table enabled_extensions
;
1140 struct anv_device_dispatch_table dispatch
;
1142 pthread_mutex_t vma_mutex
;
1143 struct util_vma_heap vma_lo
;
1144 struct util_vma_heap vma_hi
;
1145 uint64_t vma_lo_available
;
1146 uint64_t vma_hi_available
;
1148 /** List of all anv_device_memory objects */
1149 struct list_head memory_objects
;
1151 struct anv_bo_pool batch_bo_pool
;
1153 struct anv_bo_cache bo_cache
;
1155 struct anv_state_pool dynamic_state_pool
;
1156 struct anv_state_pool instruction_state_pool
;
1157 struct anv_state_pool binding_table_pool
;
1158 struct anv_state_pool surface_state_pool
;
1160 struct anv_bo workaround_bo
;
1161 struct anv_bo trivial_batch_bo
;
1162 struct anv_bo hiz_clear_bo
;
1164 struct anv_pipeline_cache default_pipeline_cache
;
1165 struct blorp_context blorp
;
1167 struct anv_state border_colors
;
1169 struct anv_state slice_hash
;
1171 struct anv_queue queue
;
1173 struct anv_scratch_pool scratch_pool
;
1175 uint32_t default_mocs
;
1176 uint32_t external_mocs
;
1178 pthread_mutex_t mutex
;
1179 pthread_cond_t queue_submit
;
1182 struct gen_batch_decode_ctx decoder_ctx
;
1184 * When decoding a anv_cmd_buffer, we might need to search for BOs through
1185 * the cmd_buffer's list.
1187 struct anv_cmd_buffer
*cmd_buffer_being_decoded
;
1189 int perf_fd
; /* -1 if no opened */
1190 uint64_t perf_metric
; /* 0 if unset */
1192 struct gen_aux_map_context
*aux_map_ctx
;
1195 static inline struct anv_state_pool
*
1196 anv_binding_table_pool(struct anv_device
*device
)
1198 if (device
->instance
->physicalDevice
.use_softpin
)
1199 return &device
->binding_table_pool
;
1201 return &device
->surface_state_pool
;
1204 static inline struct anv_state
1205 anv_binding_table_pool_alloc(struct anv_device
*device
) {
1206 if (device
->instance
->physicalDevice
.use_softpin
)
1207 return anv_state_pool_alloc(&device
->binding_table_pool
,
1208 device
->binding_table_pool
.block_size
, 0);
1210 return anv_state_pool_alloc_back(&device
->surface_state_pool
);
1214 anv_binding_table_pool_free(struct anv_device
*device
, struct anv_state state
) {
1215 anv_state_pool_free(anv_binding_table_pool(device
), state
);
1218 static inline uint32_t
1219 anv_mocs_for_bo(const struct anv_device
*device
, const struct anv_bo
*bo
)
1221 if (bo
->flags
& ANV_BO_EXTERNAL
)
1222 return device
->external_mocs
;
1224 return device
->default_mocs
;
1227 void anv_device_init_blorp(struct anv_device
*device
);
1228 void anv_device_finish_blorp(struct anv_device
*device
);
1230 VkResult
_anv_device_set_lost(struct anv_device
*device
,
1231 const char *file
, int line
,
1232 const char *msg
, ...)
1233 anv_printflike(4, 5);
1234 #define anv_device_set_lost(dev, ...) \
1235 _anv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)
1238 anv_device_is_lost(struct anv_device
*device
)
1240 return unlikely(device
->_lost
);
1243 VkResult
anv_device_execbuf(struct anv_device
*device
,
1244 struct drm_i915_gem_execbuffer2
*execbuf
,
1245 struct anv_bo
**execbuf_bos
);
1246 VkResult
anv_device_query_status(struct anv_device
*device
);
1247 VkResult
anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
);
1248 VkResult
anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1251 void* anv_gem_mmap(struct anv_device
*device
,
1252 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
1253 void anv_gem_munmap(void *p
, uint64_t size
);
1254 uint32_t anv_gem_create(struct anv_device
*device
, uint64_t size
);
1255 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
1256 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
1257 int anv_gem_busy(struct anv_device
*device
, uint32_t gem_handle
);
1258 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
1259 int anv_gem_execbuffer(struct anv_device
*device
,
1260 struct drm_i915_gem_execbuffer2
*execbuf
);
1261 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
1262 uint32_t stride
, uint32_t tiling
);
1263 int anv_gem_create_context(struct anv_device
*device
);
1264 bool anv_gem_has_context_priority(int fd
);
1265 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
1266 int anv_gem_set_context_param(int fd
, int context
, uint32_t param
,
1268 int anv_gem_get_context_param(int fd
, int context
, uint32_t param
,
1270 int anv_gem_get_param(int fd
, uint32_t param
);
1271 int anv_gem_get_tiling(struct anv_device
*device
, uint32_t gem_handle
);
1272 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
1273 int anv_gem_get_aperture(int fd
, uint64_t *size
);
1274 int anv_gem_gpu_get_reset_stats(struct anv_device
*device
,
1275 uint32_t *active
, uint32_t *pending
);
1276 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
1277 int anv_gem_reg_read(struct anv_device
*device
,
1278 uint32_t offset
, uint64_t *result
);
1279 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
1280 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
1281 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
1282 uint32_t read_domains
, uint32_t write_domain
);
1283 int anv_gem_sync_file_merge(struct anv_device
*device
, int fd1
, int fd2
);
1284 uint32_t anv_gem_syncobj_create(struct anv_device
*device
, uint32_t flags
);
1285 void anv_gem_syncobj_destroy(struct anv_device
*device
, uint32_t handle
);
1286 int anv_gem_syncobj_handle_to_fd(struct anv_device
*device
, uint32_t handle
);
1287 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device
*device
, int fd
);
1288 int anv_gem_syncobj_export_sync_file(struct anv_device
*device
,
1290 int anv_gem_syncobj_import_sync_file(struct anv_device
*device
,
1291 uint32_t handle
, int fd
);
1292 void anv_gem_syncobj_reset(struct anv_device
*device
, uint32_t handle
);
1293 bool anv_gem_supports_syncobj_wait(int fd
);
1294 int anv_gem_syncobj_wait(struct anv_device
*device
,
1295 uint32_t *handles
, uint32_t num_handles
,
1296 int64_t abs_timeout_ns
, bool wait_all
);
1298 bool anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
);
1299 void anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
);
1301 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
1303 struct anv_reloc_list
{
1304 uint32_t num_relocs
;
1305 uint32_t array_length
;
1306 struct drm_i915_gem_relocation_entry
* relocs
;
1307 struct anv_bo
** reloc_bos
;
1311 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
1312 const VkAllocationCallbacks
*alloc
);
1313 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
1314 const VkAllocationCallbacks
*alloc
);
1316 VkResult
anv_reloc_list_add(struct anv_reloc_list
*list
,
1317 const VkAllocationCallbacks
*alloc
,
1318 uint32_t offset
, struct anv_bo
*target_bo
,
1321 struct anv_batch_bo
{
1322 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1323 struct list_head link
;
1327 /* Bytes actually consumed in this batch BO */
1330 struct anv_reloc_list relocs
;
1334 const VkAllocationCallbacks
* alloc
;
1340 struct anv_reloc_list
* relocs
;
1342 /* This callback is called (with the associated user data) in the event
1343 * that the batch runs out of space.
1345 VkResult (*extend_cb
)(struct anv_batch
*, void *);
1349 * Current error status of the command buffer. Used to track inconsistent
1350 * or incomplete command buffer states that are the consequence of run-time
1351 * errors such as out of memory scenarios. We want to track this in the
1352 * batch because the command buffer object is not visible to some parts
1358 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
1359 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
1360 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
1361 void *location
, struct anv_bo
*bo
, uint32_t offset
);
1362 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
1363 struct anv_batch
*batch
);
1365 static inline VkResult
1366 anv_batch_set_error(struct anv_batch
*batch
, VkResult error
)
1368 assert(error
!= VK_SUCCESS
);
1369 if (batch
->status
== VK_SUCCESS
)
1370 batch
->status
= error
;
1371 return batch
->status
;
1375 anv_batch_has_error(struct anv_batch
*batch
)
1377 return batch
->status
!= VK_SUCCESS
;
1380 struct anv_address
{
1385 #define ANV_NULL_ADDRESS ((struct anv_address) { NULL, 0 })
1388 anv_address_is_null(struct anv_address addr
)
1390 return addr
.bo
== NULL
&& addr
.offset
== 0;
1393 static inline uint64_t
1394 anv_address_physical(struct anv_address addr
)
1396 if (addr
.bo
&& (addr
.bo
->flags
& EXEC_OBJECT_PINNED
))
1397 return gen_canonical_address(addr
.bo
->offset
+ addr
.offset
);
1399 return gen_canonical_address(addr
.offset
);
1402 static inline struct anv_address
1403 anv_address_add(struct anv_address addr
, uint64_t offset
)
1405 addr
.offset
+= offset
;
1410 write_reloc(const struct anv_device
*device
, void *p
, uint64_t v
, bool flush
)
1412 unsigned reloc_size
= 0;
1413 if (device
->info
.gen
>= 8) {
1414 reloc_size
= sizeof(uint64_t);
1415 *(uint64_t *)p
= gen_canonical_address(v
);
1417 reloc_size
= sizeof(uint32_t);
1421 if (flush
&& !device
->info
.has_llc
)
1422 gen_flush_range(p
, reloc_size
);
1425 static inline uint64_t
1426 _anv_combine_address(struct anv_batch
*batch
, void *location
,
1427 const struct anv_address address
, uint32_t delta
)
1429 if (address
.bo
== NULL
) {
1430 return address
.offset
+ delta
;
1432 assert(batch
->start
<= location
&& location
< batch
->end
);
1434 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
1438 #define __gen_address_type struct anv_address
1439 #define __gen_user_data struct anv_batch
1440 #define __gen_combine_address _anv_combine_address
1442 /* Wrapper macros needed to work around preprocessor argument issues. In
1443 * particular, arguments don't get pre-evaluated if they are concatenated.
1444 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1445 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1446 * We can work around this easily enough with these helpers.
1448 #define __anv_cmd_length(cmd) cmd ## _length
1449 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1450 #define __anv_cmd_header(cmd) cmd ## _header
1451 #define __anv_cmd_pack(cmd) cmd ## _pack
1452 #define __anv_reg_num(reg) reg ## _num
1454 #define anv_pack_struct(dst, struc, ...) do { \
1455 struct struc __template = { \
1458 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1459 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1462 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1463 void *__dst = anv_batch_emit_dwords(batch, n); \
1465 struct cmd __template = { \
1466 __anv_cmd_header(cmd), \
1467 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1470 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1475 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1479 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1480 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1483 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1484 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1485 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1488 #define anv_batch_emit(batch, cmd, name) \
1489 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1490 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1491 __builtin_expect(_dst != NULL, 1); \
1492 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1493 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1497 /* MEMORY_OBJECT_CONTROL_STATE:
1498 * .GraphicsDataTypeGFDT = 0,
1499 * .LLCCacheabilityControlLLCCC = 0,
1500 * .L3CacheabilityControlL3CC = 1,
1504 /* MEMORY_OBJECT_CONTROL_STATE:
1505 * .LLCeLLCCacheabilityControlLLCCC = 0,
1506 * .L3CacheabilityControlL3CC = 1,
1508 #define GEN75_MOCS 1
1510 /* MEMORY_OBJECT_CONTROL_STATE:
1511 * .MemoryTypeLLCeLLCCacheabilityControl = WB,
1512 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1513 * .AgeforQUADLRU = 0
1515 #define GEN8_MOCS 0x78
1517 /* MEMORY_OBJECT_CONTROL_STATE:
1518 * .MemoryTypeLLCeLLCCacheabilityControl = UCwithFenceifcoherentcycle,
1519 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1520 * .AgeforQUADLRU = 0
1522 #define GEN8_EXTERNAL_MOCS 0x18
1524 /* Skylake: MOCS is now an index into an array of 62 different caching
1525 * configurations programmed by the kernel.
1528 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1529 #define GEN9_MOCS (2 << 1)
1531 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1532 #define GEN9_EXTERNAL_MOCS (1 << 1)
1534 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1535 #define GEN10_MOCS GEN9_MOCS
1536 #define GEN10_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1538 /* Ice Lake MOCS defines are duplicates of Skylake MOCS defines. */
1539 #define GEN11_MOCS GEN9_MOCS
1540 #define GEN11_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1542 /* TigerLake MOCS */
1543 #define GEN12_MOCS GEN9_MOCS
1544 /* TC=1/LLC Only, LeCC=1/Uncacheable, LRUM=0, L3CC=1/Uncacheable */
1545 #define GEN12_EXTERNAL_MOCS (3 << 1)
1547 struct anv_device_memory
{
1548 struct list_head link
;
1551 struct anv_memory_type
* type
;
1552 VkDeviceSize map_size
;
1555 /* If set, we are holding reference to AHardwareBuffer
1556 * which we must release when memory is freed.
1558 struct AHardwareBuffer
* ahw
;
1560 /* If set, this memory comes from a host pointer. */
1565 * Header for Vertex URB Entry (VUE)
1567 struct anv_vue_header
{
1569 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
1570 uint32_t ViewportIndex
;
1574 /** Struct representing a sampled image descriptor
1576 * This descriptor layout is used for sampled images, bare sampler, and
1577 * combined image/sampler descriptors.
1579 struct anv_sampled_image_descriptor
{
1580 /** Bindless image handle
1582 * This is expected to already be shifted such that the 20-bit
1583 * SURFACE_STATE table index is in the top 20 bits.
1587 /** Bindless sampler handle
1589 * This is assumed to be a 32B-aligned SAMPLER_STATE pointer relative
1590 * to the dynamic state base address.
1595 struct anv_texture_swizzle_descriptor
{
1598 * See also nir_intrinsic_channel_select_intel
1602 /** Unused padding to ensure the struct is a multiple of 64 bits */
1606 /** Struct representing a storage image descriptor */
1607 struct anv_storage_image_descriptor
{
1608 /** Bindless image handles
1610 * These are expected to already be shifted such that the 20-bit
1611 * SURFACE_STATE table index is in the top 20 bits.
1613 uint32_t read_write
;
1614 uint32_t write_only
;
1617 /** Struct representing a address/range descriptor
1619 * The fields of this struct correspond directly to the data layout of
1620 * nir_address_format_64bit_bounded_global addresses. The last field is the
1621 * offset in the NIR address so it must be zero so that when you load the
1622 * descriptor you get a pointer to the start of the range.
1624 struct anv_address_range_descriptor
{
1630 enum anv_descriptor_data
{
1631 /** The descriptor contains a BTI reference to a surface state */
1632 ANV_DESCRIPTOR_SURFACE_STATE
= (1 << 0),
1633 /** The descriptor contains a BTI reference to a sampler state */
1634 ANV_DESCRIPTOR_SAMPLER_STATE
= (1 << 1),
1635 /** The descriptor contains an actual buffer view */
1636 ANV_DESCRIPTOR_BUFFER_VIEW
= (1 << 2),
1637 /** The descriptor contains auxiliary image layout data */
1638 ANV_DESCRIPTOR_IMAGE_PARAM
= (1 << 3),
1639 /** The descriptor contains auxiliary image layout data */
1640 ANV_DESCRIPTOR_INLINE_UNIFORM
= (1 << 4),
1641 /** anv_address_range_descriptor with a buffer address and range */
1642 ANV_DESCRIPTOR_ADDRESS_RANGE
= (1 << 5),
1643 /** Bindless surface handle */
1644 ANV_DESCRIPTOR_SAMPLED_IMAGE
= (1 << 6),
1645 /** Storage image handles */
1646 ANV_DESCRIPTOR_STORAGE_IMAGE
= (1 << 7),
1647 /** Storage image handles */
1648 ANV_DESCRIPTOR_TEXTURE_SWIZZLE
= (1 << 8),
1651 struct anv_descriptor_set_binding_layout
{
1653 /* The type of the descriptors in this binding */
1654 VkDescriptorType type
;
1657 /* Flags provided when this binding was created */
1658 VkDescriptorBindingFlagsEXT flags
;
1660 /* Bitfield representing the type of data this descriptor contains */
1661 enum anv_descriptor_data data
;
1663 /* Maximum number of YCbCr texture/sampler planes */
1664 uint8_t max_plane_count
;
1666 /* Number of array elements in this binding (or size in bytes for inline
1669 uint16_t array_size
;
1671 /* Index into the flattend descriptor set */
1672 uint16_t descriptor_index
;
1674 /* Index into the dynamic state array for a dynamic buffer */
1675 int16_t dynamic_offset_index
;
1677 /* Index into the descriptor set buffer views */
1678 int16_t buffer_view_index
;
1680 /* Offset into the descriptor buffer where this descriptor lives */
1681 uint32_t descriptor_offset
;
1683 /* Immutable samplers (or NULL if no immutable samplers) */
1684 struct anv_sampler
**immutable_samplers
;
1687 unsigned anv_descriptor_size(const struct anv_descriptor_set_binding_layout
*layout
);
1689 unsigned anv_descriptor_type_size(const struct anv_physical_device
*pdevice
,
1690 VkDescriptorType type
);
1692 bool anv_descriptor_supports_bindless(const struct anv_physical_device
*pdevice
,
1693 const struct anv_descriptor_set_binding_layout
*binding
,
1696 bool anv_descriptor_requires_bindless(const struct anv_physical_device
*pdevice
,
1697 const struct anv_descriptor_set_binding_layout
*binding
,
1700 struct anv_descriptor_set_layout
{
1701 /* Descriptor set layouts can be destroyed at almost any time */
1704 /* Number of bindings in this descriptor set */
1705 uint16_t binding_count
;
1707 /* Total size of the descriptor set with room for all array entries */
1710 /* Shader stages affected by this descriptor set */
1711 uint16_t shader_stages
;
1713 /* Number of buffer views in this descriptor set */
1714 uint16_t buffer_view_count
;
1716 /* Number of dynamic offsets used by this descriptor set */
1717 uint16_t dynamic_offset_count
;
1719 /* Size of the descriptor buffer for this descriptor set */
1720 uint32_t descriptor_buffer_size
;
1722 /* Bindings in this descriptor set */
1723 struct anv_descriptor_set_binding_layout binding
[0];
1727 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout
*layout
)
1729 assert(layout
&& layout
->ref_cnt
>= 1);
1730 p_atomic_inc(&layout
->ref_cnt
);
1734 anv_descriptor_set_layout_unref(struct anv_device
*device
,
1735 struct anv_descriptor_set_layout
*layout
)
1737 assert(layout
&& layout
->ref_cnt
>= 1);
1738 if (p_atomic_dec_zero(&layout
->ref_cnt
))
1739 vk_free(&device
->alloc
, layout
);
1742 struct anv_descriptor
{
1743 VkDescriptorType type
;
1747 VkImageLayout layout
;
1748 struct anv_image_view
*image_view
;
1749 struct anv_sampler
*sampler
;
1753 struct anv_buffer
*buffer
;
1758 struct anv_buffer_view
*buffer_view
;
1762 struct anv_descriptor_set
{
1763 struct anv_descriptor_pool
*pool
;
1764 struct anv_descriptor_set_layout
*layout
;
1767 /* State relative to anv_descriptor_pool::bo */
1768 struct anv_state desc_mem
;
1769 /* Surface state for the descriptor buffer */
1770 struct anv_state desc_surface_state
;
1772 uint32_t buffer_view_count
;
1773 struct anv_buffer_view
*buffer_views
;
1775 /* Link to descriptor pool's desc_sets list . */
1776 struct list_head pool_link
;
1778 struct anv_descriptor descriptors
[0];
1781 struct anv_buffer_view
{
1782 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1783 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1785 struct anv_address address
;
1787 struct anv_state surface_state
;
1788 struct anv_state storage_surface_state
;
1789 struct anv_state writeonly_storage_surface_state
;
1791 struct brw_image_param storage_image_param
;
1794 struct anv_push_descriptor_set
{
1795 struct anv_descriptor_set set
;
1797 /* Put this field right behind anv_descriptor_set so it fills up the
1798 * descriptors[0] field. */
1799 struct anv_descriptor descriptors
[MAX_PUSH_DESCRIPTORS
];
1801 /** True if the descriptor set buffer has been referenced by a draw or
1804 bool set_used_on_gpu
;
1806 struct anv_buffer_view buffer_views
[MAX_PUSH_DESCRIPTORS
];
1809 struct anv_descriptor_pool
{
1815 struct util_vma_heap bo_heap
;
1817 struct anv_state_stream surface_state_stream
;
1818 void *surface_state_free_list
;
1820 struct list_head desc_sets
;
1825 enum anv_descriptor_template_entry_type
{
1826 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE
,
1827 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER
,
1828 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1831 struct anv_descriptor_template_entry
{
1832 /* The type of descriptor in this entry */
1833 VkDescriptorType type
;
1835 /* Binding in the descriptor set */
1838 /* Offset at which to write into the descriptor set binding */
1839 uint32_t array_element
;
1841 /* Number of elements to write into the descriptor set binding */
1842 uint32_t array_count
;
1844 /* Offset into the user provided data */
1847 /* Stride between elements into the user provided data */
1851 struct anv_descriptor_update_template
{
1852 VkPipelineBindPoint bind_point
;
1854 /* The descriptor set this template corresponds to. This value is only
1855 * valid if the template was created with the templateType
1856 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET.
1860 /* Number of entries in this template */
1861 uint32_t entry_count
;
1863 /* Entries of the template */
1864 struct anv_descriptor_template_entry entries
[0];
1868 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
);
1871 anv_descriptor_set_write_image_view(struct anv_device
*device
,
1872 struct anv_descriptor_set
*set
,
1873 const VkDescriptorImageInfo
* const info
,
1874 VkDescriptorType type
,
1879 anv_descriptor_set_write_buffer_view(struct anv_device
*device
,
1880 struct anv_descriptor_set
*set
,
1881 VkDescriptorType type
,
1882 struct anv_buffer_view
*buffer_view
,
1887 anv_descriptor_set_write_buffer(struct anv_device
*device
,
1888 struct anv_descriptor_set
*set
,
1889 struct anv_state_stream
*alloc_stream
,
1890 VkDescriptorType type
,
1891 struct anv_buffer
*buffer
,
1894 VkDeviceSize offset
,
1895 VkDeviceSize range
);
1897 anv_descriptor_set_write_inline_uniform_data(struct anv_device
*device
,
1898 struct anv_descriptor_set
*set
,
1905 anv_descriptor_set_write_template(struct anv_device
*device
,
1906 struct anv_descriptor_set
*set
,
1907 struct anv_state_stream
*alloc_stream
,
1908 const struct anv_descriptor_update_template
*template,
1912 anv_descriptor_set_create(struct anv_device
*device
,
1913 struct anv_descriptor_pool
*pool
,
1914 struct anv_descriptor_set_layout
*layout
,
1915 struct anv_descriptor_set
**out_set
);
1918 anv_descriptor_set_destroy(struct anv_device
*device
,
1919 struct anv_descriptor_pool
*pool
,
1920 struct anv_descriptor_set
*set
);
1922 #define ANV_DESCRIPTOR_SET_DESCRIPTORS (UINT8_MAX - 3)
1923 #define ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS (UINT8_MAX - 2)
1924 #define ANV_DESCRIPTOR_SET_SHADER_CONSTANTS (UINT8_MAX - 1)
1925 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1927 struct anv_pipeline_binding
{
1928 /* The descriptor set this surface corresponds to. The special value of
1929 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1930 * to a color attachment and not a regular descriptor.
1934 /* Binding in the descriptor set */
1937 /* Index in the binding */
1940 /* Plane in the binding index */
1943 /* Input attachment index (relative to the subpass) */
1944 uint8_t input_attachment_index
;
1946 /* For a storage image, whether it is write-only */
1950 struct anv_pipeline_layout
{
1952 struct anv_descriptor_set_layout
*layout
;
1953 uint32_t dynamic_offset_start
;
1958 unsigned char sha1
[20];
1962 struct anv_device
* device
;
1965 VkBufferUsageFlags usage
;
1967 /* Set when bound */
1968 struct anv_address address
;
1971 static inline uint64_t
1972 anv_buffer_get_range(struct anv_buffer
*buffer
, uint64_t offset
, uint64_t range
)
1974 assert(offset
<= buffer
->size
);
1975 if (range
== VK_WHOLE_SIZE
) {
1976 return buffer
->size
- offset
;
1978 assert(range
+ offset
>= range
);
1979 assert(range
+ offset
<= buffer
->size
);
1984 enum anv_cmd_dirty_bits
{
1985 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1986 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1987 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1988 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1989 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1990 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1991 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1992 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1993 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1994 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1995 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1996 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1997 ANV_CMD_DIRTY_XFB_ENABLE
= 1 << 12,
1998 ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE
= 1 << 13, /* VK_DYNAMIC_STATE_LINE_STIPPLE_EXT */
2000 typedef uint32_t anv_cmd_dirty_mask_t
;
2002 #define ANV_CMD_DIRTY_DYNAMIC_ALL \
2003 (ANV_CMD_DIRTY_DYNAMIC_VIEWPORT | \
2004 ANV_CMD_DIRTY_DYNAMIC_SCISSOR | \
2005 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH | \
2006 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS | \
2007 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS | \
2008 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS | \
2009 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK | \
2010 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK | \
2011 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE | \
2012 ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE)
2014 static inline enum anv_cmd_dirty_bits
2015 anv_cmd_dirty_bit_for_vk_dynamic_state(VkDynamicState vk_state
)
2018 case VK_DYNAMIC_STATE_VIEWPORT
:
2019 return ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
;
2020 case VK_DYNAMIC_STATE_SCISSOR
:
2021 return ANV_CMD_DIRTY_DYNAMIC_SCISSOR
;
2022 case VK_DYNAMIC_STATE_LINE_WIDTH
:
2023 return ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
;
2024 case VK_DYNAMIC_STATE_DEPTH_BIAS
:
2025 return ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
;
2026 case VK_DYNAMIC_STATE_BLEND_CONSTANTS
:
2027 return ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
;
2028 case VK_DYNAMIC_STATE_DEPTH_BOUNDS
:
2029 return ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
;
2030 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
:
2031 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
;
2032 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
:
2033 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
;
2034 case VK_DYNAMIC_STATE_STENCIL_REFERENCE
:
2035 return ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
;
2036 case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT
:
2037 return ANV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE
;
2039 assert(!"Unsupported dynamic state");
2045 enum anv_pipe_bits
{
2046 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
2047 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
2048 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
2049 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
2050 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
2051 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
2052 ANV_PIPE_TILE_CACHE_FLUSH_BIT
= (1 << 6),
2053 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
2054 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
2055 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
2056 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
2057 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
2059 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
2060 * a flush has happened but not a CS stall. The next time we do any sort
2061 * of invalidation we need to insert a CS stall at that time. Otherwise,
2062 * we would have to CS stall on every flush which could be bad.
2064 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
2066 /* This bit does not exist directly in PIPE_CONTROL. It means that render
2067 * target operations related to transfer commands with VkBuffer as
2068 * destination are ongoing. Some operations like copies on the command
2069 * streamer might need to be aware of this to trigger the appropriate stall
2070 * before they can proceed with the copy.
2072 ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
= (1 << 22),
2075 #define ANV_PIPE_FLUSH_BITS ( \
2076 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
2077 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
2078 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT | \
2079 ANV_PIPE_TILE_CACHE_FLUSH_BIT)
2081 #define ANV_PIPE_STALL_BITS ( \
2082 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
2083 ANV_PIPE_DEPTH_STALL_BIT | \
2084 ANV_PIPE_CS_STALL_BIT)
2086 #define ANV_PIPE_INVALIDATE_BITS ( \
2087 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
2088 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
2089 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
2090 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
2091 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
2092 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
2094 static inline enum anv_pipe_bits
2095 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags
)
2097 enum anv_pipe_bits pipe_bits
= 0;
2100 for_each_bit(b
, flags
) {
2101 switch ((VkAccessFlagBits
)(1 << b
)) {
2102 case VK_ACCESS_SHADER_WRITE_BIT
:
2103 /* We're transitioning a buffer that was previously used as write
2104 * destination through the data port. To make its content available
2105 * to future operations, flush the data cache.
2107 pipe_bits
|= ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
2109 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
2110 /* We're transitioning a buffer that was previously used as render
2111 * target. To make its content available to future operations, flush
2112 * the render target cache.
2114 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
2116 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
2117 /* We're transitioning a buffer that was previously used as depth
2118 * buffer. To make its content available to future operations, flush
2121 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
2123 case VK_ACCESS_TRANSFER_WRITE_BIT
:
2124 /* We're transitioning a buffer that was previously used as a
2125 * transfer write destination. Generic write operations include color
2126 * & depth operations as well as buffer operations like :
2127 * - vkCmdClearColorImage()
2128 * - vkCmdClearDepthStencilImage()
2129 * - vkCmdBlitImage()
2130 * - vkCmdCopy*(), vkCmdUpdate*(), vkCmdFill*()
2132 * Most of these operations are implemented using Blorp which writes
2133 * through the render target, so flush that cache to make it visible
2134 * to future operations. And for depth related operations we also
2135 * need to flush the depth cache.
2137 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
2138 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
2140 case VK_ACCESS_MEMORY_WRITE_BIT
:
2141 /* We're transitioning a buffer for generic write operations. Flush
2144 pipe_bits
|= ANV_PIPE_FLUSH_BITS
;
2147 break; /* Nothing to do */
2154 static inline enum anv_pipe_bits
2155 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags
)
2157 enum anv_pipe_bits pipe_bits
= 0;
2160 for_each_bit(b
, flags
) {
2161 switch ((VkAccessFlagBits
)(1 << b
)) {
2162 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
2163 /* Indirect draw commands take a buffer as input that we're going to
2164 * read from the command streamer to load some of the HW registers
2165 * (see genX_cmd_buffer.c:load_indirect_parameters). This requires a
2166 * command streamer stall so that all the cache flushes have
2167 * completed before the command streamer loads from memory.
2169 pipe_bits
|= ANV_PIPE_CS_STALL_BIT
;
2170 /* Indirect draw commands also set gl_BaseVertex & gl_BaseIndex
2171 * through a vertex buffer, so invalidate that cache.
2173 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
2174 /* For CmdDipatchIndirect, we also load gl_NumWorkGroups through a
2175 * UBO from the buffer, so we need to invalidate constant cache.
2177 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
2179 case VK_ACCESS_INDEX_READ_BIT
:
2180 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
2181 /* We transitioning a buffer to be used for as input for vkCmdDraw*
2182 * commands, so we invalidate the VF cache to make sure there is no
2183 * stale data when we start rendering.
2185 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
2187 case VK_ACCESS_UNIFORM_READ_BIT
:
2188 /* We transitioning a buffer to be used as uniform data. Because
2189 * uniform is accessed through the data port & sampler, we need to
2190 * invalidate the texture cache (sampler) & constant cache (data
2191 * port) to avoid stale data.
2193 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
2194 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
2196 case VK_ACCESS_SHADER_READ_BIT
:
2197 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
:
2198 case VK_ACCESS_TRANSFER_READ_BIT
:
2199 /* Transitioning a buffer to be read through the sampler, so
2200 * invalidate the texture cache, we don't want any stale data.
2202 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
2204 case VK_ACCESS_MEMORY_READ_BIT
:
2205 /* Transitioning a buffer for generic read, invalidate all the
2208 pipe_bits
|= ANV_PIPE_INVALIDATE_BITS
;
2210 case VK_ACCESS_MEMORY_WRITE_BIT
:
2211 /* Generic write, make sure all previously written things land in
2214 pipe_bits
|= ANV_PIPE_FLUSH_BITS
;
2216 case VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT
:
2217 /* Transitioning a buffer for conditional rendering. We'll load the
2218 * content of this buffer into HW registers using the command
2219 * streamer, so we need to stall the command streamer to make sure
2220 * any in-flight flush operations have completed.
2222 pipe_bits
|= ANV_PIPE_CS_STALL_BIT
;
2225 break; /* Nothing to do */
2232 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
2233 VK_IMAGE_ASPECT_COLOR_BIT | \
2234 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2235 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2236 VK_IMAGE_ASPECT_PLANE_2_BIT)
2237 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
2238 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2239 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2240 VK_IMAGE_ASPECT_PLANE_2_BIT)
2242 struct anv_vertex_binding
{
2243 struct anv_buffer
* buffer
;
2244 VkDeviceSize offset
;
2247 struct anv_xfb_binding
{
2248 struct anv_buffer
* buffer
;
2249 VkDeviceSize offset
;
2253 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
2254 #define ANV_PARAM_IS_PUSH(param) ((uint32_t)(param) >> 16 == 1)
2255 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
2257 #define ANV_PARAM_DYN_OFFSET(offset) ((2 << 16) | (uint32_t)(offset))
2258 #define ANV_PARAM_IS_DYN_OFFSET(param) ((uint32_t)(param) >> 16 == 2)
2259 #define ANV_PARAM_DYN_OFFSET_IDX(param) ((param) & 0xffff)
2261 struct anv_push_constants
{
2262 /* Push constant data provided by the client through vkPushConstants */
2263 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
2265 /* Used for vkCmdDispatchBase */
2266 uint32_t base_work_group_id
[3];
2269 struct anv_dynamic_state
{
2272 VkViewport viewports
[MAX_VIEWPORTS
];
2277 VkRect2D scissors
[MAX_SCISSORS
];
2288 float blend_constants
[4];
2298 } stencil_compare_mask
;
2303 } stencil_write_mask
;
2308 } stencil_reference
;
2316 extern const struct anv_dynamic_state default_dynamic_state
;
2318 uint32_t anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
2319 const struct anv_dynamic_state
*src
,
2320 uint32_t copy_mask
);
2322 struct anv_surface_state
{
2323 struct anv_state state
;
2324 /** Address of the surface referred to by this state
2326 * This address is relative to the start of the BO.
2328 struct anv_address address
;
2329 /* Address of the aux surface, if any
2331 * This field is ANV_NULL_ADDRESS if and only if no aux surface exists.
2333 * With the exception of gen8, the bottom 12 bits of this address' offset
2334 * include extra aux information.
2336 struct anv_address aux_address
;
2337 /* Address of the clear color, if any
2339 * This address is relative to the start of the BO.
2341 struct anv_address clear_address
;
2345 * Attachment state when recording a renderpass instance.
2347 * The clear value is valid only if there exists a pending clear.
2349 struct anv_attachment_state
{
2350 enum isl_aux_usage aux_usage
;
2351 enum isl_aux_usage input_aux_usage
;
2352 struct anv_surface_state color
;
2353 struct anv_surface_state input
;
2355 VkImageLayout current_layout
;
2356 VkImageAspectFlags pending_clear_aspects
;
2357 VkImageAspectFlags pending_load_aspects
;
2359 VkClearValue clear_value
;
2360 bool clear_color_is_zero_one
;
2361 bool clear_color_is_zero
;
2363 /* When multiview is active, attachments with a renderpass clear
2364 * operation have their respective layers cleared on the first
2365 * subpass that uses them, and only in that subpass. We keep track
2366 * of this using a bitfield to indicate which layers of an attachment
2367 * have not been cleared yet when multiview is active.
2369 uint32_t pending_clear_views
;
2370 struct anv_image_view
* image_view
;
2373 /** State tracking for particular pipeline bind point
2375 * This struct is the base struct for anv_cmd_graphics_state and
2376 * anv_cmd_compute_state. These are used to track state which is bound to a
2377 * particular type of pipeline. Generic state that applies per-stage such as
2378 * binding table offsets and push constants is tracked generically with a
2379 * per-stage array in anv_cmd_state.
2381 struct anv_cmd_pipeline_state
{
2382 struct anv_pipeline
*pipeline
;
2383 struct anv_pipeline_layout
*layout
;
2385 struct anv_descriptor_set
*descriptors
[MAX_SETS
];
2386 uint32_t dynamic_offsets
[MAX_DYNAMIC_BUFFERS
];
2388 struct anv_push_descriptor_set
*push_descriptors
[MAX_SETS
];
2391 /** State tracking for graphics pipeline
2393 * This has anv_cmd_pipeline_state as a base struct to track things which get
2394 * bound to a graphics pipeline. Along with general pipeline bind point state
2395 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2396 * state which is graphics-specific.
2398 struct anv_cmd_graphics_state
{
2399 struct anv_cmd_pipeline_state base
;
2401 anv_cmd_dirty_mask_t dirty
;
2404 struct anv_dynamic_state dynamic
;
2407 struct anv_buffer
*index_buffer
;
2408 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
2409 uint32_t index_offset
;
2413 /** State tracking for compute pipeline
2415 * This has anv_cmd_pipeline_state as a base struct to track things which get
2416 * bound to a compute pipeline. Along with general pipeline bind point state
2417 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2418 * state which is compute-specific.
2420 struct anv_cmd_compute_state
{
2421 struct anv_cmd_pipeline_state base
;
2423 bool pipeline_dirty
;
2425 struct anv_address num_workgroups
;
2428 /** State required while building cmd buffer */
2429 struct anv_cmd_state
{
2430 /* PIPELINE_SELECT.PipelineSelection */
2431 uint32_t current_pipeline
;
2432 const struct gen_l3_config
* current_l3_config
;
2433 uint32_t last_aux_map_state
;
2435 struct anv_cmd_graphics_state gfx
;
2436 struct anv_cmd_compute_state compute
;
2438 enum anv_pipe_bits pending_pipe_bits
;
2439 VkShaderStageFlags descriptors_dirty
;
2440 VkShaderStageFlags push_constants_dirty
;
2442 struct anv_framebuffer
* framebuffer
;
2443 struct anv_render_pass
* pass
;
2444 struct anv_subpass
* subpass
;
2445 VkRect2D render_area
;
2446 uint32_t restart_index
;
2447 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
2449 struct anv_xfb_binding xfb_bindings
[MAX_XFB_BUFFERS
];
2450 VkShaderStageFlags push_constant_stages
;
2451 struct anv_push_constants push_constants
[MESA_SHADER_STAGES
];
2452 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
2453 struct anv_state samplers
[MESA_SHADER_STAGES
];
2456 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
2457 * of any command buffer it is disabled by disabling it in EndCommandBuffer
2458 * and before invoking the secondary in ExecuteCommands.
2460 bool pma_fix_enabled
;
2463 * Whether or not we know for certain that HiZ is enabled for the current
2464 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
2465 * enabled or not, this will be false.
2469 bool conditional_render_enabled
;
2472 * Last rendering scale argument provided to
2473 * genX(cmd_buffer_emit_hashing_mode)().
2475 unsigned current_hash_scale
;
2478 * Array length is anv_cmd_state::pass::attachment_count. Array content is
2479 * valid only when recording a render pass instance.
2481 struct anv_attachment_state
* attachments
;
2484 * Surface states for color render targets. These are stored in a single
2485 * flat array. For depth-stencil attachments, the surface state is simply
2488 struct anv_state render_pass_states
;
2491 * A null surface state of the right size to match the framebuffer. This
2492 * is one of the states in render_pass_states.
2494 struct anv_state null_surface_state
;
2497 struct anv_cmd_pool
{
2498 VkAllocationCallbacks alloc
;
2499 struct list_head cmd_buffers
;
2502 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
2504 enum anv_cmd_buffer_exec_mode
{
2505 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
2506 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
2507 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
2508 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
2509 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
2512 struct anv_cmd_buffer
{
2513 VK_LOADER_DATA _loader_data
;
2515 struct anv_device
* device
;
2517 struct anv_cmd_pool
* pool
;
2518 struct list_head pool_link
;
2520 struct anv_batch batch
;
2522 /* Fields required for the actual chain of anv_batch_bo's.
2524 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
2526 struct list_head batch_bos
;
2527 enum anv_cmd_buffer_exec_mode exec_mode
;
2529 /* A vector of anv_batch_bo pointers for every batch or surface buffer
2530 * referenced by this command buffer
2532 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2534 struct u_vector seen_bbos
;
2536 /* A vector of int32_t's for every block of binding tables.
2538 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2540 struct u_vector bt_block_states
;
2543 struct anv_reloc_list surface_relocs
;
2544 /** Last seen surface state block pool center bo offset */
2545 uint32_t last_ss_pool_center
;
2547 /* Serial for tracking buffer completion */
2550 /* Stream objects for storing temporary data */
2551 struct anv_state_stream surface_state_stream
;
2552 struct anv_state_stream dynamic_state_stream
;
2554 VkCommandBufferUsageFlags usage_flags
;
2555 VkCommandBufferLevel level
;
2557 struct anv_cmd_state state
;
2559 /* Set by SetPerformanceMarkerINTEL, written into queries by CmdBeginQuery */
2560 uint64_t intel_perf_marker
;
2563 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2564 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2565 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2566 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
2567 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
2568 struct anv_cmd_buffer
*secondary
);
2569 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
2570 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
2571 struct anv_cmd_buffer
*cmd_buffer
,
2572 const VkSemaphore
*in_semaphores
,
2573 uint32_t num_in_semaphores
,
2574 const VkSemaphore
*out_semaphores
,
2575 uint32_t num_out_semaphores
,
2578 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
2580 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
2581 const void *data
, uint32_t size
, uint32_t alignment
);
2582 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
2583 uint32_t *a
, uint32_t *b
,
2584 uint32_t dwords
, uint32_t alignment
);
2587 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
2589 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2590 uint32_t entries
, uint32_t *state_offset
);
2592 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
2594 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
2595 uint32_t size
, uint32_t alignment
);
2598 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
2600 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
2601 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
2602 bool depth_clamp_enable
);
2603 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
2605 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
2606 struct anv_render_pass
*pass
,
2607 struct anv_framebuffer
*framebuffer
,
2608 const VkClearValue
*clear_values
);
2610 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
2613 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
2614 gl_shader_stage stage
);
2616 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
2618 const struct anv_image_view
*
2619 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
2622 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2623 uint32_t num_entries
,
2624 uint32_t *state_offset
,
2625 struct anv_state
*bt_state
);
2627 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
2629 void anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer
*cmd_buffer
);
2631 enum anv_fence_type
{
2632 ANV_FENCE_TYPE_NONE
= 0,
2634 ANV_FENCE_TYPE_SYNCOBJ
,
2638 enum anv_bo_fence_state
{
2639 /** Indicates that this is a new (or newly reset fence) */
2640 ANV_BO_FENCE_STATE_RESET
,
2642 /** Indicates that this fence has been submitted to the GPU but is still
2643 * (as far as we know) in use by the GPU.
2645 ANV_BO_FENCE_STATE_SUBMITTED
,
2647 ANV_BO_FENCE_STATE_SIGNALED
,
2650 struct anv_fence_impl
{
2651 enum anv_fence_type type
;
2654 /** Fence implementation for BO fences
2656 * These fences use a BO and a set of CPU-tracked state flags. The BO
2657 * is added to the object list of the last execbuf call in a QueueSubmit
2658 * and is marked EXEC_WRITE. The state flags track when the BO has been
2659 * submitted to the kernel. We need to do this because Vulkan lets you
2660 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2661 * will say it's idle in this case.
2665 enum anv_bo_fence_state state
;
2668 /** DRM syncobj handle for syncobj-based fences */
2672 struct wsi_fence
*fence_wsi
;
2677 /* Permanent fence state. Every fence has some form of permanent state
2678 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2679 * cross-process fences) or it could just be a dummy for use internally.
2681 struct anv_fence_impl permanent
;
2683 /* Temporary fence state. A fence *may* have temporary state. That state
2684 * is added to the fence by an import operation and is reset back to
2685 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2686 * state cannot be signaled because the fence must already be signaled
2687 * before the temporary state can be exported from the fence in the other
2688 * process and imported here.
2690 struct anv_fence_impl temporary
;
2695 struct anv_state state
;
2698 enum anv_semaphore_type
{
2699 ANV_SEMAPHORE_TYPE_NONE
= 0,
2700 ANV_SEMAPHORE_TYPE_DUMMY
,
2701 ANV_SEMAPHORE_TYPE_BO
,
2702 ANV_SEMAPHORE_TYPE_SYNC_FILE
,
2703 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ
,
2706 struct anv_semaphore_impl
{
2707 enum anv_semaphore_type type
;
2710 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
2711 * This BO will be added to the object list on any execbuf2 calls for
2712 * which this semaphore is used as a wait or signal fence. When used as
2713 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
2717 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
2718 * If the semaphore is in the unsignaled state due to either just being
2719 * created or because it has been used for a wait, fd will be -1.
2723 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
2724 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
2725 * import so we don't need to bother with a userspace cache.
2731 struct anv_semaphore
{
2732 /* Permanent semaphore state. Every semaphore has some form of permanent
2733 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
2734 * (for cross-process semaphores0 or it could just be a dummy for use
2737 struct anv_semaphore_impl permanent
;
2739 /* Temporary semaphore state. A semaphore *may* have temporary state.
2740 * That state is added to the semaphore by an import operation and is reset
2741 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
2742 * semaphore with temporary state cannot be signaled because the semaphore
2743 * must already be signaled before the temporary state can be exported from
2744 * the semaphore in the other process and imported here.
2746 struct anv_semaphore_impl temporary
;
2749 void anv_semaphore_reset_temporary(struct anv_device
*device
,
2750 struct anv_semaphore
*semaphore
);
2752 struct anv_shader_module
{
2753 unsigned char sha1
[20];
2758 static inline gl_shader_stage
2759 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
2761 assert(__builtin_popcount(vk_stage
) == 1);
2762 return ffs(vk_stage
) - 1;
2765 static inline VkShaderStageFlagBits
2766 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
2768 return (1 << mesa_stage
);
2771 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2773 #define anv_foreach_stage(stage, stage_bits) \
2774 for (gl_shader_stage stage, \
2775 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2776 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2777 __tmp &= ~(1 << (stage)))
2779 struct anv_pipeline_bind_map
{
2780 uint32_t surface_count
;
2781 uint32_t sampler_count
;
2783 struct anv_pipeline_binding
* surface_to_descriptor
;
2784 struct anv_pipeline_binding
* sampler_to_descriptor
;
2787 struct anv_shader_bin_key
{
2792 struct anv_shader_bin
{
2795 const struct anv_shader_bin_key
*key
;
2797 struct anv_state kernel
;
2798 uint32_t kernel_size
;
2800 struct anv_state constant_data
;
2801 uint32_t constant_data_size
;
2803 const struct brw_stage_prog_data
*prog_data
;
2804 uint32_t prog_data_size
;
2806 struct brw_compile_stats stats
[3];
2809 struct nir_xfb_info
*xfb_info
;
2811 struct anv_pipeline_bind_map bind_map
;
2814 struct anv_shader_bin
*
2815 anv_shader_bin_create(struct anv_device
*device
,
2816 const void *key
, uint32_t key_size
,
2817 const void *kernel
, uint32_t kernel_size
,
2818 const void *constant_data
, uint32_t constant_data_size
,
2819 const struct brw_stage_prog_data
*prog_data
,
2820 uint32_t prog_data_size
, const void *prog_data_param
,
2821 const struct brw_compile_stats
*stats
, uint32_t num_stats
,
2822 const struct nir_xfb_info
*xfb_info
,
2823 const struct anv_pipeline_bind_map
*bind_map
);
2826 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
2829 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
2831 assert(shader
&& shader
->ref_cnt
>= 1);
2832 p_atomic_inc(&shader
->ref_cnt
);
2836 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
2838 assert(shader
&& shader
->ref_cnt
>= 1);
2839 if (p_atomic_dec_zero(&shader
->ref_cnt
))
2840 anv_shader_bin_destroy(device
, shader
);
2843 /* 5 possible simultaneous shader stages and FS may have up to 3 binaries */
2844 #define MAX_PIPELINE_EXECUTABLES 7
2846 struct anv_pipeline_executable
{
2847 gl_shader_stage stage
;
2849 struct brw_compile_stats stats
;
2855 struct anv_pipeline
{
2856 struct anv_device
* device
;
2857 struct anv_batch batch
;
2858 uint32_t batch_data
[512];
2859 struct anv_reloc_list batch_relocs
;
2860 anv_cmd_dirty_mask_t dynamic_state_mask
;
2861 struct anv_dynamic_state dynamic_state
;
2865 VkPipelineCreateFlags flags
;
2866 struct anv_subpass
* subpass
;
2868 bool needs_data_cache
;
2870 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
2872 uint32_t num_executables
;
2873 struct anv_pipeline_executable executables
[MAX_PIPELINE_EXECUTABLES
];
2876 const struct gen_l3_config
* l3_config
;
2877 uint32_t total_size
;
2880 VkShaderStageFlags active_stages
;
2881 struct anv_state blend_state
;
2884 struct anv_pipeline_vertex_binding
{
2887 uint32_t instance_divisor
;
2892 bool primitive_restart
;
2895 uint32_t cs_right_mask
;
2898 bool depth_test_enable
;
2899 bool writes_stencil
;
2900 bool stencil_test_enable
;
2901 bool depth_clamp_enable
;
2902 bool depth_clip_enable
;
2903 bool sample_shading_enable
;
2905 bool depth_bounds_test_enable
;
2909 uint32_t depth_stencil_state
[3];
2915 uint32_t wm_depth_stencil
[3];
2919 uint32_t wm_depth_stencil
[4];
2922 uint32_t interface_descriptor_data
[8];
2926 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
2927 gl_shader_stage stage
)
2929 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
2932 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2933 static inline const struct brw_##prefix##_prog_data * \
2934 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2936 if (anv_pipeline_has_stage(pipeline, stage)) { \
2937 return (const struct brw_##prefix##_prog_data *) \
2938 pipeline->shaders[stage]->prog_data; \
2944 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
2945 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
2946 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
2947 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
2948 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
2949 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
2951 static inline const struct brw_vue_prog_data
*
2952 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
2954 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
2955 return &get_gs_prog_data(pipeline
)->base
;
2956 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
2957 return &get_tes_prog_data(pipeline
)->base
;
2959 return &get_vs_prog_data(pipeline
)->base
;
2963 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
2964 struct anv_pipeline_cache
*cache
,
2965 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2966 const VkAllocationCallbacks
*alloc
);
2969 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
2970 struct anv_pipeline_cache
*cache
,
2971 const VkComputePipelineCreateInfo
*info
,
2972 const struct anv_shader_module
*module
,
2973 const char *entrypoint
,
2974 const VkSpecializationInfo
*spec_info
);
2976 struct anv_format_plane
{
2977 enum isl_format isl_format
:16;
2978 struct isl_swizzle swizzle
;
2980 /* Whether this plane contains chroma channels */
2983 /* For downscaling of YUV planes */
2984 uint8_t denominator_scales
[2];
2986 /* How to map sampled ycbcr planes to a single 4 component element. */
2987 struct isl_swizzle ycbcr_swizzle
;
2989 /* What aspect is associated to this plane */
2990 VkImageAspectFlags aspect
;
2995 struct anv_format_plane planes
[3];
3001 static inline uint32_t
3002 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects
,
3003 VkImageAspectFlags aspect_mask
)
3005 switch (aspect_mask
) {
3006 case VK_IMAGE_ASPECT_COLOR_BIT
:
3007 case VK_IMAGE_ASPECT_DEPTH_BIT
:
3008 case VK_IMAGE_ASPECT_PLANE_0_BIT
:
3010 case VK_IMAGE_ASPECT_STENCIL_BIT
:
3011 if ((image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) == 0)
3014 case VK_IMAGE_ASPECT_PLANE_1_BIT
:
3016 case VK_IMAGE_ASPECT_PLANE_2_BIT
:
3019 /* Purposefully assert with depth/stencil aspects. */
3020 unreachable("invalid image aspect");
3024 static inline VkImageAspectFlags
3025 anv_plane_to_aspect(VkImageAspectFlags image_aspects
,
3028 if (image_aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
3029 if (util_bitcount(image_aspects
) > 1)
3030 return VK_IMAGE_ASPECT_PLANE_0_BIT
<< plane
;
3031 return VK_IMAGE_ASPECT_COLOR_BIT
;
3033 if (image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)
3034 return VK_IMAGE_ASPECT_DEPTH_BIT
<< plane
;
3035 assert(image_aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
3036 return VK_IMAGE_ASPECT_STENCIL_BIT
;
3039 #define anv_foreach_image_aspect_bit(b, image, aspects) \
3040 for_each_bit(b, anv_image_expand_aspects(image, aspects))
3042 const struct anv_format
*
3043 anv_get_format(VkFormat format
);
3045 static inline uint32_t
3046 anv_get_format_planes(VkFormat vk_format
)
3048 const struct anv_format
*format
= anv_get_format(vk_format
);
3050 return format
!= NULL
? format
->n_planes
: 0;
3053 struct anv_format_plane
3054 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
3055 VkImageAspectFlagBits aspect
, VkImageTiling tiling
);
3057 static inline enum isl_format
3058 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
3059 VkImageAspectFlags aspect
, VkImageTiling tiling
)
3061 return anv_get_format_plane(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
3064 static inline struct isl_swizzle
3065 anv_swizzle_for_render(struct isl_swizzle swizzle
)
3067 /* Sometimes the swizzle will have alpha map to one. We do this to fake
3068 * RGB as RGBA for texturing
3070 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
3071 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
3073 /* But it doesn't matter what we render to that channel */
3074 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
3080 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
3083 * Subsurface of an anv_image.
3085 struct anv_surface
{
3086 /** Valid only if isl_surf::size_B > 0. */
3087 struct isl_surf isl
;
3090 * Offset from VkImage's base address, as bound by vkBindImageMemory().
3096 VkImageType type
; /**< VkImageCreateInfo::imageType */
3097 /* The original VkFormat provided by the client. This may not match any
3098 * of the actual surface formats.
3101 const struct anv_format
*format
;
3103 VkImageAspectFlags aspects
;
3106 uint32_t array_size
;
3107 uint32_t samples
; /**< VkImageCreateInfo::samples */
3109 VkImageUsageFlags usage
; /**< VkImageCreateInfo::usage. */
3110 VkImageUsageFlags stencil_usage
;
3111 VkImageCreateFlags create_flags
; /* Flags used when creating image. */
3112 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
3114 /** True if this is needs to be bound to an appropriately tiled BO.
3116 * When not using modifiers, consumers such as X11, Wayland, and KMS need
3117 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
3118 * we require a dedicated allocation so that we can know to allocate a
3121 bool needs_set_tiling
;
3124 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
3125 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
3127 uint64_t drm_format_mod
;
3132 /* Whether the image is made of several underlying buffer objects rather a
3133 * single one with different offsets.
3137 /* All the formats that can be used when creating views of this image
3138 * are CCS_E compatible.
3140 bool ccs_e_compatible
;
3142 /* Image was created with external format. */
3143 bool external_format
;
3148 * For each foo, anv_image::planes[x].surface is valid if and only if
3149 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
3150 * to figure the number associated with a given aspect.
3152 * The hardware requires that the depth buffer and stencil buffer be
3153 * separate surfaces. From Vulkan's perspective, though, depth and stencil
3154 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
3155 * allocate the depth and stencil buffers as separate surfaces in the same
3160 * -----------------------
3162 * ----------------------- |
3163 * | shadow surface0 | |
3164 * ----------------------- | Plane 0
3165 * | aux surface0 | |
3166 * ----------------------- |
3167 * | fast clear colors0 | \|/
3168 * -----------------------
3170 * ----------------------- |
3171 * | shadow surface1 | |
3172 * ----------------------- | Plane 1
3173 * | aux surface1 | |
3174 * ----------------------- |
3175 * | fast clear colors1 | \|/
3176 * -----------------------
3179 * -----------------------
3183 * Offset of the entire plane (whenever the image is disjoint this is
3191 struct anv_surface surface
;
3194 * A surface which shadows the main surface and may have different
3195 * tiling. This is used for sampling using a tiling that isn't supported
3196 * for other operations.
3198 struct anv_surface shadow_surface
;
3201 * For color images, this is the aux usage for this image when not used
3202 * as a color attachment.
3204 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
3205 * image has a HiZ buffer.
3207 enum isl_aux_usage aux_usage
;
3209 struct anv_surface aux_surface
;
3212 * Offset of the fast clear state (used to compute the
3213 * fast_clear_state_offset of the following planes).
3215 uint32_t fast_clear_state_offset
;
3218 * BO associated with this plane, set when bound.
3220 struct anv_address address
;
3223 * Address of the main surface used to fill the aux map table. This is
3224 * used at destruction of the image since the Vulkan spec does not
3225 * guarantee that the address.bo field we still be valid at destruction.
3227 uint64_t aux_map_surface_address
;
3230 * When destroying the image, also free the bo.
3236 /* The ordering of this enum is important */
3237 enum anv_fast_clear_type
{
3238 /** Image does not have/support any fast-clear blocks */
3239 ANV_FAST_CLEAR_NONE
= 0,
3240 /** Image has/supports fast-clear but only to the default value */
3241 ANV_FAST_CLEAR_DEFAULT_VALUE
= 1,
3242 /** Image has/supports fast-clear with an arbitrary fast-clear value */
3243 ANV_FAST_CLEAR_ANY
= 2,
3246 /* Returns the number of auxiliary buffer levels attached to an image. */
3247 static inline uint8_t
3248 anv_image_aux_levels(const struct anv_image
* const image
,
3249 VkImageAspectFlagBits aspect
)
3251 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3253 /* The Gen12 CCS aux surface is represented with only one level. */
3254 const uint8_t aux_logical_levels
=
3255 image
->planes
[plane
].aux_surface
.isl
.tiling
== ISL_TILING_GEN12_CCS
?
3256 image
->planes
[plane
].surface
.isl
.levels
:
3257 image
->planes
[plane
].aux_surface
.isl
.levels
;
3259 return image
->planes
[plane
].aux_surface
.isl
.size_B
> 0 ?
3260 aux_logical_levels
: 0;
3263 /* Returns the number of auxiliary buffer layers attached to an image. */
3264 static inline uint32_t
3265 anv_image_aux_layers(const struct anv_image
* const image
,
3266 VkImageAspectFlagBits aspect
,
3267 const uint8_t miplevel
)
3271 /* The miplevel must exist in the main buffer. */
3272 assert(miplevel
< image
->levels
);
3274 if (miplevel
>= anv_image_aux_levels(image
, aspect
)) {
3275 /* There are no layers with auxiliary data because the miplevel has no
3280 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3282 /* The Gen12 CCS aux surface is represented with only one layer. */
3283 const struct isl_extent4d
*aux_logical_level0_px
=
3284 image
->planes
[plane
].aux_surface
.isl
.tiling
== ISL_TILING_GEN12_CCS
?
3285 &image
->planes
[plane
].surface
.isl
.logical_level0_px
:
3286 &image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
;
3288 return MAX2(aux_logical_level0_px
->array_len
,
3289 aux_logical_level0_px
->depth
>> miplevel
);
3293 static inline struct anv_address
3294 anv_image_get_clear_color_addr(const struct anv_device
*device
,
3295 const struct anv_image
*image
,
3296 VkImageAspectFlagBits aspect
)
3298 assert(image
->aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
3300 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3301 return anv_address_add(image
->planes
[plane
].address
,
3302 image
->planes
[plane
].fast_clear_state_offset
);
3305 static inline struct anv_address
3306 anv_image_get_fast_clear_type_addr(const struct anv_device
*device
,
3307 const struct anv_image
*image
,
3308 VkImageAspectFlagBits aspect
)
3310 struct anv_address addr
=
3311 anv_image_get_clear_color_addr(device
, image
, aspect
);
3313 const unsigned clear_color_state_size
= device
->info
.gen
>= 10 ?
3314 device
->isl_dev
.ss
.clear_color_state_size
:
3315 device
->isl_dev
.ss
.clear_value_size
;
3316 return anv_address_add(addr
, clear_color_state_size
);
3319 static inline struct anv_address
3320 anv_image_get_compression_state_addr(const struct anv_device
*device
,
3321 const struct anv_image
*image
,
3322 VkImageAspectFlagBits aspect
,
3323 uint32_t level
, uint32_t array_layer
)
3325 assert(level
< anv_image_aux_levels(image
, aspect
));
3326 assert(array_layer
< anv_image_aux_layers(image
, aspect
, level
));
3327 UNUSED
uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3328 assert(image
->planes
[plane
].aux_usage
== ISL_AUX_USAGE_CCS_E
);
3330 struct anv_address addr
=
3331 anv_image_get_fast_clear_type_addr(device
, image
, aspect
);
3332 addr
.offset
+= 4; /* Go past the fast clear type */
3334 if (image
->type
== VK_IMAGE_TYPE_3D
) {
3335 for (uint32_t l
= 0; l
< level
; l
++)
3336 addr
.offset
+= anv_minify(image
->extent
.depth
, l
) * 4;
3338 addr
.offset
+= level
* image
->array_size
* 4;
3340 addr
.offset
+= array_layer
* 4;
3342 assert(addr
.offset
<
3343 image
->planes
[plane
].address
.offset
+ image
->planes
[plane
].size
);
3347 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
3349 anv_can_sample_with_hiz(const struct gen_device_info
* const devinfo
,
3350 const struct anv_image
*image
)
3352 if (!(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
))
3355 /* Allow this feature on BDW even though it is disabled in the BDW devinfo
3356 * struct. There's documentation which suggests that this feature actually
3357 * reduces performance on BDW, but it has only been observed to help so
3358 * far. Sampling fast-cleared blocks on BDW must also be handled with care
3359 * (see depth_stencil_attachment_compute_aux_usage() for more info).
3361 if (devinfo
->gen
!= 8 && !devinfo
->has_sample_with_hiz
)
3364 return image
->samples
== 1;
3368 anv_image_plane_uses_aux_map(const struct anv_device
*device
,
3369 const struct anv_image
*image
,
3372 return device
->info
.has_aux_map
&&
3373 isl_aux_usage_has_ccs(image
->planes
[plane
].aux_usage
);
3377 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer
*cmd_buffer
,
3378 const struct anv_image
*image
,
3379 VkImageAspectFlagBits aspect
,
3380 enum isl_aux_usage aux_usage
,
3382 uint32_t base_layer
,
3383 uint32_t layer_count
);
3386 anv_image_clear_color(struct anv_cmd_buffer
*cmd_buffer
,
3387 const struct anv_image
*image
,
3388 VkImageAspectFlagBits aspect
,
3389 enum isl_aux_usage aux_usage
,
3390 enum isl_format format
, struct isl_swizzle swizzle
,
3391 uint32_t level
, uint32_t base_layer
, uint32_t layer_count
,
3392 VkRect2D area
, union isl_color_value clear_color
);
3394 anv_image_clear_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
3395 const struct anv_image
*image
,
3396 VkImageAspectFlags aspects
,
3397 enum isl_aux_usage depth_aux_usage
,
3399 uint32_t base_layer
, uint32_t layer_count
,
3401 float depth_value
, uint8_t stencil_value
);
3403 anv_image_msaa_resolve(struct anv_cmd_buffer
*cmd_buffer
,
3404 const struct anv_image
*src_image
,
3405 enum isl_aux_usage src_aux_usage
,
3406 uint32_t src_level
, uint32_t src_base_layer
,
3407 const struct anv_image
*dst_image
,
3408 enum isl_aux_usage dst_aux_usage
,
3409 uint32_t dst_level
, uint32_t dst_base_layer
,
3410 VkImageAspectFlagBits aspect
,
3411 uint32_t src_x
, uint32_t src_y
,
3412 uint32_t dst_x
, uint32_t dst_y
,
3413 uint32_t width
, uint32_t height
,
3414 uint32_t layer_count
,
3415 enum blorp_filter filter
);
3417 anv_image_hiz_op(struct anv_cmd_buffer
*cmd_buffer
,
3418 const struct anv_image
*image
,
3419 VkImageAspectFlagBits aspect
, uint32_t level
,
3420 uint32_t base_layer
, uint32_t layer_count
,
3421 enum isl_aux_op hiz_op
);
3423 anv_image_hiz_clear(struct anv_cmd_buffer
*cmd_buffer
,
3424 const struct anv_image
*image
,
3425 VkImageAspectFlags aspects
,
3427 uint32_t base_layer
, uint32_t layer_count
,
3428 VkRect2D area
, uint8_t stencil_value
);
3430 anv_image_mcs_op(struct anv_cmd_buffer
*cmd_buffer
,
3431 const struct anv_image
*image
,
3432 enum isl_format format
,
3433 VkImageAspectFlagBits aspect
,
3434 uint32_t base_layer
, uint32_t layer_count
,
3435 enum isl_aux_op mcs_op
, union isl_color_value
*clear_value
,
3438 anv_image_ccs_op(struct anv_cmd_buffer
*cmd_buffer
,
3439 const struct anv_image
*image
,
3440 enum isl_format format
,
3441 VkImageAspectFlagBits aspect
, uint32_t level
,
3442 uint32_t base_layer
, uint32_t layer_count
,
3443 enum isl_aux_op ccs_op
, union isl_color_value
*clear_value
,
3447 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
3448 const struct anv_image
*image
,
3449 VkImageAspectFlagBits aspect
,
3450 uint32_t base_level
, uint32_t level_count
,
3451 uint32_t base_layer
, uint32_t layer_count
);
3454 anv_layout_to_aux_usage(const struct gen_device_info
* const devinfo
,
3455 const struct anv_image
*image
,
3456 const VkImageAspectFlagBits aspect
,
3457 const VkImageLayout layout
);
3459 enum anv_fast_clear_type
3460 anv_layout_to_fast_clear_type(const struct gen_device_info
* const devinfo
,
3461 const struct anv_image
* const image
,
3462 const VkImageAspectFlagBits aspect
,
3463 const VkImageLayout layout
);
3465 /* This is defined as a macro so that it works for both
3466 * VkImageSubresourceRange and VkImageSubresourceLayers
3468 #define anv_get_layerCount(_image, _range) \
3469 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
3470 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
3472 static inline uint32_t
3473 anv_get_levelCount(const struct anv_image
*image
,
3474 const VkImageSubresourceRange
*range
)
3476 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
3477 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
3480 static inline VkImageAspectFlags
3481 anv_image_expand_aspects(const struct anv_image
*image
,
3482 VkImageAspectFlags aspects
)
3484 /* If the underlying image has color plane aspects and
3485 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
3486 * the underlying image. */
3487 if ((image
->aspects
& VK_IMAGE_ASPECT_PLANES_BITS_ANV
) != 0 &&
3488 aspects
== VK_IMAGE_ASPECT_COLOR_BIT
)
3489 return image
->aspects
;
3495 anv_image_aspects_compatible(VkImageAspectFlags aspects1
,
3496 VkImageAspectFlags aspects2
)
3498 if (aspects1
== aspects2
)
3501 /* Only 1 color aspects are compatibles. */
3502 if ((aspects1
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
3503 (aspects2
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
3504 util_bitcount(aspects1
) == util_bitcount(aspects2
))
3510 struct anv_image_view
{
3511 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
3513 VkImageAspectFlags aspect_mask
;
3515 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
3519 uint32_t image_plane
;
3521 struct isl_view isl
;
3524 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3525 * image layout of SHADER_READ_ONLY_OPTIMAL or
3526 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
3528 struct anv_surface_state optimal_sampler_surface_state
;
3531 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3532 * image layout of GENERAL.
3534 struct anv_surface_state general_sampler_surface_state
;
3537 * RENDER_SURFACE_STATE when using image as a storage image. Separate
3538 * states for write-only and readable, using the real format for
3539 * write-only and the lowered format for readable.
3541 struct anv_surface_state storage_surface_state
;
3542 struct anv_surface_state writeonly_storage_surface_state
;
3544 struct brw_image_param storage_image_param
;
3548 enum anv_image_view_state_flags
{
3549 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY
= (1 << 0),
3550 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL
= (1 << 1),
3553 void anv_image_fill_surface_state(struct anv_device
*device
,
3554 const struct anv_image
*image
,
3555 VkImageAspectFlagBits aspect
,
3556 const struct isl_view
*view
,
3557 isl_surf_usage_flags_t view_usage
,
3558 enum isl_aux_usage aux_usage
,
3559 const union isl_color_value
*clear_color
,
3560 enum anv_image_view_state_flags flags
,
3561 struct anv_surface_state
*state_inout
,
3562 struct brw_image_param
*image_param_out
);
3564 struct anv_image_create_info
{
3565 const VkImageCreateInfo
*vk_info
;
3567 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
3568 isl_tiling_flags_t isl_tiling_flags
;
3570 /** These flags will be added to any derived from VkImageCreateInfo. */
3571 isl_surf_usage_flags_t isl_extra_usage_flags
;
3574 bool external_format
;
3577 VkResult
anv_image_create(VkDevice _device
,
3578 const struct anv_image_create_info
*info
,
3579 const VkAllocationCallbacks
* alloc
,
3582 const struct anv_surface
*
3583 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
3584 VkImageAspectFlags aspect_mask
);
3587 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
3589 static inline struct VkExtent3D
3590 anv_sanitize_image_extent(const VkImageType imageType
,
3591 const struct VkExtent3D imageExtent
)
3593 switch (imageType
) {
3594 case VK_IMAGE_TYPE_1D
:
3595 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
3596 case VK_IMAGE_TYPE_2D
:
3597 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
3598 case VK_IMAGE_TYPE_3D
:
3601 unreachable("invalid image type");
3605 static inline struct VkOffset3D
3606 anv_sanitize_image_offset(const VkImageType imageType
,
3607 const struct VkOffset3D imageOffset
)
3609 switch (imageType
) {
3610 case VK_IMAGE_TYPE_1D
:
3611 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
3612 case VK_IMAGE_TYPE_2D
:
3613 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
3614 case VK_IMAGE_TYPE_3D
:
3617 unreachable("invalid image type");
3621 VkFormatFeatureFlags
3622 anv_get_image_format_features(const struct gen_device_info
*devinfo
,
3624 const struct anv_format
*anv_format
,
3625 VkImageTiling vk_tiling
);
3627 void anv_fill_buffer_surface_state(struct anv_device
*device
,
3628 struct anv_state state
,
3629 enum isl_format format
,
3630 struct anv_address address
,
3631 uint32_t range
, uint32_t stride
);
3634 anv_clear_color_from_att_state(union isl_color_value
*clear_color
,
3635 const struct anv_attachment_state
*att_state
,
3636 const struct anv_image_view
*iview
)
3638 const struct isl_format_layout
*view_fmtl
=
3639 isl_format_get_layout(iview
->planes
[0].isl
.format
);
3641 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
3642 if (view_fmtl->channels.c.bits) \
3643 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
3645 COPY_CLEAR_COLOR_CHANNEL(r
, 0);
3646 COPY_CLEAR_COLOR_CHANNEL(g
, 1);
3647 COPY_CLEAR_COLOR_CHANNEL(b
, 2);
3648 COPY_CLEAR_COLOR_CHANNEL(a
, 3);
3650 #undef COPY_CLEAR_COLOR_CHANNEL
3654 struct anv_ycbcr_conversion
{
3655 const struct anv_format
* format
;
3656 VkSamplerYcbcrModelConversion ycbcr_model
;
3657 VkSamplerYcbcrRange ycbcr_range
;
3658 VkComponentSwizzle mapping
[4];
3659 VkChromaLocation chroma_offsets
[2];
3660 VkFilter chroma_filter
;
3661 bool chroma_reconstruction
;
3664 struct anv_sampler
{
3665 uint32_t state
[3][4];
3667 struct anv_ycbcr_conversion
*conversion
;
3669 /* Blob of sampler state data which is guaranteed to be 32-byte aligned
3670 * and with a 32-byte stride for use as bindless samplers.
3672 struct anv_state bindless_state
;
3675 struct anv_framebuffer
{
3680 uint32_t attachment_count
;
3681 struct anv_image_view
* attachments
[0];
3684 struct anv_subpass_attachment
{
3685 VkImageUsageFlagBits usage
;
3686 uint32_t attachment
;
3687 VkImageLayout layout
;
3690 struct anv_subpass
{
3691 uint32_t attachment_count
;
3694 * A pointer to all attachment references used in this subpass.
3695 * Only valid if ::attachment_count > 0.
3697 struct anv_subpass_attachment
* attachments
;
3698 uint32_t input_count
;
3699 struct anv_subpass_attachment
* input_attachments
;
3700 uint32_t color_count
;
3701 struct anv_subpass_attachment
* color_attachments
;
3702 struct anv_subpass_attachment
* resolve_attachments
;
3704 struct anv_subpass_attachment
* depth_stencil_attachment
;
3705 struct anv_subpass_attachment
* ds_resolve_attachment
;
3706 VkResolveModeFlagBitsKHR depth_resolve_mode
;
3707 VkResolveModeFlagBitsKHR stencil_resolve_mode
;
3711 /** Subpass has a depth/stencil self-dependency */
3712 bool has_ds_self_dep
;
3714 /** Subpass has at least one color resolve attachment */
3715 bool has_color_resolve
;
3718 static inline unsigned
3719 anv_subpass_view_count(const struct anv_subpass
*subpass
)
3721 return MAX2(1, util_bitcount(subpass
->view_mask
));
3724 struct anv_render_pass_attachment
{
3725 /* TODO: Consider using VkAttachmentDescription instead of storing each of
3726 * its members individually.
3730 VkImageUsageFlags usage
;
3731 VkAttachmentLoadOp load_op
;
3732 VkAttachmentStoreOp store_op
;
3733 VkAttachmentLoadOp stencil_load_op
;
3734 VkImageLayout initial_layout
;
3735 VkImageLayout final_layout
;
3736 VkImageLayout first_subpass_layout
;
3738 /* The subpass id in which the attachment will be used last. */
3739 uint32_t last_subpass_idx
;
3742 struct anv_render_pass
{
3743 uint32_t attachment_count
;
3744 uint32_t subpass_count
;
3745 /* An array of subpass_count+1 flushes, one per subpass boundary */
3746 enum anv_pipe_bits
* subpass_flushes
;
3747 struct anv_render_pass_attachment
* attachments
;
3748 struct anv_subpass subpasses
[0];
3751 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
3753 struct anv_query_pool
{
3755 VkQueryPipelineStatisticFlags pipeline_statistics
;
3756 /** Stride between slots, in bytes */
3758 /** Number of slots in this query pool */
3763 int anv_get_instance_entrypoint_index(const char *name
);
3764 int anv_get_device_entrypoint_index(const char *name
);
3765 int anv_get_physical_device_entrypoint_index(const char *name
);
3767 const char *anv_get_instance_entry_name(int index
);
3768 const char *anv_get_physical_device_entry_name(int index
);
3769 const char *anv_get_device_entry_name(int index
);
3772 anv_instance_entrypoint_is_enabled(int index
, uint32_t core_version
,
3773 const struct anv_instance_extension_table
*instance
);
3775 anv_physical_device_entrypoint_is_enabled(int index
, uint32_t core_version
,
3776 const struct anv_instance_extension_table
*instance
);
3778 anv_device_entrypoint_is_enabled(int index
, uint32_t core_version
,
3779 const struct anv_instance_extension_table
*instance
,
3780 const struct anv_device_extension_table
*device
);
3782 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
3785 void anv_dump_image_to_ppm(struct anv_device
*device
,
3786 struct anv_image
*image
, unsigned miplevel
,
3787 unsigned array_layer
, VkImageAspectFlagBits aspect
,
3788 const char *filename
);
3790 enum anv_dump_action
{
3791 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
3794 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
3795 void anv_dump_finish(void);
3797 void anv_dump_add_attachments(struct anv_cmd_buffer
*cmd_buffer
);
3799 static inline uint32_t
3800 anv_get_subpass_id(const struct anv_cmd_state
* const cmd_state
)
3802 /* This function must be called from within a subpass. */
3803 assert(cmd_state
->pass
&& cmd_state
->subpass
);
3805 const uint32_t subpass_id
= cmd_state
->subpass
- cmd_state
->pass
->subpasses
;
3807 /* The id of this subpass shouldn't exceed the number of subpasses in this
3808 * render pass minus 1.
3810 assert(subpass_id
< cmd_state
->pass
->subpass_count
);
3814 struct gen_perf_config
*anv_get_perf(const struct gen_device_info
*devinfo
, int fd
);
3815 void anv_device_perf_init(struct anv_device
*device
);
3817 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
3819 static inline struct __anv_type * \
3820 __anv_type ## _from_handle(__VkType _handle) \
3822 return (struct __anv_type *) _handle; \
3825 static inline __VkType \
3826 __anv_type ## _to_handle(struct __anv_type *_obj) \
3828 return (__VkType) _obj; \
3831 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
3833 static inline struct __anv_type * \
3834 __anv_type ## _from_handle(__VkType _handle) \
3836 return (struct __anv_type *)(uintptr_t) _handle; \
3839 static inline __VkType \
3840 __anv_type ## _to_handle(struct __anv_type *_obj) \
3842 return (__VkType)(uintptr_t) _obj; \
3845 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
3846 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
3848 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
3849 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
3850 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
3851 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
3852 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
3854 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
3855 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
3856 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
3857 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
3858 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
3859 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
3860 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template
, VkDescriptorUpdateTemplate
)
3861 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
3862 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
3863 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
3864 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
3865 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
3866 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
3867 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
3868 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
3869 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
3870 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
3871 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
3872 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
3873 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore
, VkSemaphore
)
3874 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
3875 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback
, VkDebugReportCallbackEXT
)
3876 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion
, VkSamplerYcbcrConversion
)
3878 /* Gen-specific function declarations */
3880 # include "anv_genX.h"
3882 # define genX(x) gen7_##x
3883 # include "anv_genX.h"
3885 # define genX(x) gen75_##x
3886 # include "anv_genX.h"
3888 # define genX(x) gen8_##x
3889 # include "anv_genX.h"
3891 # define genX(x) gen9_##x
3892 # include "anv_genX.h"
3894 # define genX(x) gen10_##x
3895 # include "anv_genX.h"
3897 # define genX(x) gen11_##x
3898 # include "anv_genX.h"
3900 # define genX(x) gen12_##x
3901 # include "anv_genX.h"
3905 #endif /* ANV_PRIVATE_H */