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))
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"
61 #include "vk_debug_report.h"
63 /* Pre-declarations needed for WSI entrypoints */
66 typedef struct xcb_connection_t xcb_connection_t
;
67 typedef uint32_t xcb_visualid_t
;
68 typedef uint32_t xcb_window_t
;
71 struct anv_buffer_view
;
72 struct anv_image_view
;
77 #include <vulkan/vulkan.h>
78 #include <vulkan/vulkan_intel.h>
79 #include <vulkan/vk_icd.h>
81 #include "anv_android.h"
82 #include "anv_entrypoints.h"
83 #include "anv_extensions.h"
86 #include "dev/gen_debug.h"
87 #include "common/intel_log.h"
88 #include "wsi_common.h"
90 /* anv Virtual Memory Layout
91 * =========================
93 * When the anv driver is determining the virtual graphics addresses of memory
94 * objects itself using the softpin mechanism, the following memory ranges
97 * Three special considerations to notice:
99 * (1) the dynamic state pool is located within the same 4 GiB as the low
100 * heap. This is to work around a VF cache issue described in a comment in
101 * anv_physical_device_init_heaps.
103 * (2) the binding table pool is located at lower addresses than the surface
104 * state pool, within a 4 GiB range. This allows surface state base addresses
105 * to cover both binding tables (16 bit offsets) and surface states (32 bit
108 * (3) the last 4 GiB of the address space is withheld from the high
109 * heap. Various hardware units will read past the end of an object for
110 * various reasons. This healthy margin prevents reads from wrapping around
113 #define LOW_HEAP_MIN_ADDRESS 0x000000001000ULL /* 4 KiB */
114 #define LOW_HEAP_MAX_ADDRESS 0x0000bfffffffULL
115 #define DYNAMIC_STATE_POOL_MIN_ADDRESS 0x0000c0000000ULL /* 3 GiB */
116 #define DYNAMIC_STATE_POOL_MAX_ADDRESS 0x0000ffffffffULL
117 #define BINDING_TABLE_POOL_MIN_ADDRESS 0x000100000000ULL /* 4 GiB */
118 #define BINDING_TABLE_POOL_MAX_ADDRESS 0x00013fffffffULL
119 #define SURFACE_STATE_POOL_MIN_ADDRESS 0x000140000000ULL /* 5 GiB */
120 #define SURFACE_STATE_POOL_MAX_ADDRESS 0x00017fffffffULL
121 #define INSTRUCTION_STATE_POOL_MIN_ADDRESS 0x000180000000ULL /* 6 GiB */
122 #define INSTRUCTION_STATE_POOL_MAX_ADDRESS 0x0001bfffffffULL
123 #define HIGH_HEAP_MIN_ADDRESS 0x0001c0000000ULL /* 7 GiB */
125 #define LOW_HEAP_SIZE \
126 (LOW_HEAP_MAX_ADDRESS - LOW_HEAP_MIN_ADDRESS + 1)
127 #define DYNAMIC_STATE_POOL_SIZE \
128 (DYNAMIC_STATE_POOL_MAX_ADDRESS - DYNAMIC_STATE_POOL_MIN_ADDRESS + 1)
129 #define BINDING_TABLE_POOL_SIZE \
130 (BINDING_TABLE_POOL_MAX_ADDRESS - BINDING_TABLE_POOL_MIN_ADDRESS + 1)
131 #define SURFACE_STATE_POOL_SIZE \
132 (SURFACE_STATE_POOL_MAX_ADDRESS - SURFACE_STATE_POOL_MIN_ADDRESS + 1)
133 #define INSTRUCTION_STATE_POOL_SIZE \
134 (INSTRUCTION_STATE_POOL_MAX_ADDRESS - INSTRUCTION_STATE_POOL_MIN_ADDRESS + 1)
136 /* Allowing different clear colors requires us to perform a depth resolve at
137 * the end of certain render passes. This is because while slow clears store
138 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
139 * See the PRMs for examples describing when additional resolves would be
140 * necessary. To enable fast clears without requiring extra resolves, we set
141 * the clear value to a globally-defined one. We could allow different values
142 * if the user doesn't expect coherent data during or after a render passes
143 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
144 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
145 * 1.0f seems to be the only value used. The only application that doesn't set
146 * this value does so through the usage of an seemingly uninitialized clear
149 #define ANV_HZ_FC_VAL 1.0f
152 #define MAX_XFB_BUFFERS 4
153 #define MAX_XFB_STREAMS 4
156 #define MAX_VIEWPORTS 16
157 #define MAX_SCISSORS 16
158 #define MAX_PUSH_CONSTANTS_SIZE 128
159 #define MAX_DYNAMIC_BUFFERS 16
160 #define MAX_IMAGES 64
161 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
162 #define MAX_INLINE_UNIFORM_BLOCK_SIZE 4096
163 #define MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS 32
165 /* From the Skylake PRM Vol. 7 "Binding Table Surface State Model":
167 * "The surface state model is used when a Binding Table Index (specified
168 * in the message descriptor) of less than 240 is specified. In this model,
169 * the Binding Table Index is used to index into the binding table, and the
170 * binding table entry contains a pointer to the SURFACE_STATE."
172 * Binding table values above 240 are used for various things in the hardware
173 * such as stateless, stateless with incoherent cache, SLM, and bindless.
175 #define MAX_BINDING_TABLE_SIZE 240
177 /* The kernel relocation API has a limitation of a 32-bit delta value
178 * applied to the address before it is written which, in spite of it being
179 * unsigned, is treated as signed . Because of the way that this maps to
180 * the Vulkan API, we cannot handle an offset into a buffer that does not
181 * fit into a signed 32 bits. The only mechanism we have for dealing with
182 * this at the moment is to limit all VkDeviceMemory objects to a maximum
183 * of 2GB each. The Vulkan spec allows us to do this:
185 * "Some platforms may have a limit on the maximum size of a single
186 * allocation. For example, certain systems may fail to create
187 * allocations with a size greater than or equal to 4GB. Such a limit is
188 * implementation-dependent, and if such a failure occurs then the error
189 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
191 * We don't use vk_error here because it's not an error so much as an
192 * indication to the application that the allocation is too large.
194 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
196 #define ANV_SVGS_VB_INDEX MAX_VBS
197 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
199 /* We reserve this MI ALU register for the purpose of handling predication.
200 * Other code which uses the MI ALU should leave it alone.
202 #define ANV_PREDICATE_RESULT_REG 0x2678 /* MI_ALU_REG15 */
204 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
206 static inline uint32_t
207 align_down_npot_u32(uint32_t v
, uint32_t a
)
212 static inline uint32_t
213 align_u32(uint32_t v
, uint32_t a
)
215 assert(a
!= 0 && a
== (a
& -a
));
216 return (v
+ a
- 1) & ~(a
- 1);
219 static inline uint64_t
220 align_u64(uint64_t v
, uint64_t a
)
222 assert(a
!= 0 && a
== (a
& -a
));
223 return (v
+ a
- 1) & ~(a
- 1);
226 static inline int32_t
227 align_i32(int32_t v
, int32_t a
)
229 assert(a
!= 0 && a
== (a
& -a
));
230 return (v
+ a
- 1) & ~(a
- 1);
233 /** Alignment must be a power of 2. */
235 anv_is_aligned(uintmax_t n
, uintmax_t a
)
237 assert(a
== (a
& -a
));
238 return (n
& (a
- 1)) == 0;
241 static inline uint32_t
242 anv_minify(uint32_t n
, uint32_t levels
)
244 if (unlikely(n
== 0))
247 return MAX2(n
>> levels
, 1);
251 anv_clamp_f(float f
, float min
, float max
)
264 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
266 if (*inout_mask
& clear_mask
) {
267 *inout_mask
&= ~clear_mask
;
274 static inline union isl_color_value
275 vk_to_isl_color(VkClearColorValue color
)
277 return (union isl_color_value
) {
287 #define for_each_bit(b, dword) \
288 for (uint32_t __dword = (dword); \
289 (b) = __builtin_ffs(__dword) - 1, __dword; \
290 __dword &= ~(1 << (b)))
292 #define typed_memcpy(dest, src, count) ({ \
293 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
294 memcpy((dest), (src), (count) * sizeof(*(src))); \
297 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
298 * to be added here in order to utilize mapping in debug/error/perf macros.
300 #define REPORT_OBJECT_TYPE(o) \
301 __builtin_choose_expr ( \
302 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
303 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
304 __builtin_choose_expr ( \
305 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
306 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
307 __builtin_choose_expr ( \
308 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
309 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
310 __builtin_choose_expr ( \
311 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
312 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
313 __builtin_choose_expr ( \
314 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
315 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
316 __builtin_choose_expr ( \
317 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
318 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
319 __builtin_choose_expr ( \
320 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
321 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
322 __builtin_choose_expr ( \
323 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
324 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
325 __builtin_choose_expr ( \
326 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
327 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
328 __builtin_choose_expr ( \
329 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
330 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
331 __builtin_choose_expr ( \
332 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
333 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
334 __builtin_choose_expr ( \
335 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
336 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
337 __builtin_choose_expr ( \
338 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
339 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
340 __builtin_choose_expr ( \
341 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
342 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
343 __builtin_choose_expr ( \
344 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
345 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
346 __builtin_choose_expr ( \
347 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
348 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
349 __builtin_choose_expr ( \
350 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
351 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
352 __builtin_choose_expr ( \
353 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
354 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
355 __builtin_choose_expr ( \
356 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
357 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
358 __builtin_choose_expr ( \
359 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
360 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
361 __builtin_choose_expr ( \
362 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
363 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
364 __builtin_choose_expr ( \
365 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
366 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
367 __builtin_choose_expr ( \
368 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
369 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
370 __builtin_choose_expr ( \
371 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
372 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
373 __builtin_choose_expr ( \
374 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
375 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
376 __builtin_choose_expr ( \
377 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
378 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
379 __builtin_choose_expr ( \
380 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
381 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
382 __builtin_choose_expr ( \
383 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
384 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
385 __builtin_choose_expr ( \
386 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
387 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
388 __builtin_choose_expr ( \
389 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
390 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
391 __builtin_choose_expr ( \
392 __builtin_types_compatible_p (__typeof (o), void*), \
393 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
394 /* The void expression results in a compile-time error \
395 when assigning the result to something. */ \
396 (void)0)))))))))))))))))))))))))))))))
398 /* Whenever we generate an error, pass it through this function. Useful for
399 * debugging, where we can break on it. Only call at error site, not when
400 * propagating errors. Might be useful to plug in a stack trace here.
403 VkResult
__vk_errorv(struct anv_instance
*instance
, const void *object
,
404 VkDebugReportObjectTypeEXT type
, VkResult error
,
405 const char *file
, int line
, const char *format
,
408 VkResult
__vk_errorf(struct anv_instance
*instance
, const void *object
,
409 VkDebugReportObjectTypeEXT type
, VkResult error
,
410 const char *file
, int line
, const char *format
, ...);
413 #define vk_error(error) __vk_errorf(NULL, NULL,\
414 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
415 error, __FILE__, __LINE__, NULL)
416 #define vk_errorv(instance, obj, error, format, args)\
417 __vk_errorv(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
418 __FILE__, __LINE__, format, args)
419 #define vk_errorf(instance, obj, error, format, ...)\
420 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
421 __FILE__, __LINE__, format, ## __VA_ARGS__)
423 #define vk_error(error) error
424 #define vk_errorf(instance, obj, error, format, ...) error
428 * Warn on ignored extension structs.
430 * The Vulkan spec requires us to ignore unsupported or unknown structs in
431 * a pNext chain. In debug mode, emitting warnings for ignored structs may
432 * help us discover structs that we should not have ignored.
435 * From the Vulkan 1.0.38 spec:
437 * Any component of the implementation (the loader, any enabled layers,
438 * and drivers) must skip over, without processing (other than reading the
439 * sType and pNext members) any chained structures with sType values not
440 * defined by extensions supported by that component.
442 #define anv_debug_ignored_stype(sType) \
443 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
445 void __anv_perf_warn(struct anv_instance
*instance
, const void *object
,
446 VkDebugReportObjectTypeEXT type
, const char *file
,
447 int line
, const char *format
, ...)
448 anv_printflike(6, 7);
449 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
450 void anv_loge_v(const char *format
, va_list va
);
453 * Print a FINISHME message, including its source location.
455 #define anv_finishme(format, ...) \
457 static bool reported = false; \
459 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
466 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
468 #define anv_perf_warn(instance, obj, format, ...) \
470 static bool reported = false; \
471 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
472 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
473 format, ##__VA_ARGS__); \
478 /* A non-fatal assert. Useful for debugging. */
480 #define anv_assert(x) ({ \
481 if (unlikely(!(x))) \
482 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
485 #define anv_assert(x)
488 /* A multi-pointer allocator
490 * When copying data structures from the user (such as a render pass), it's
491 * common to need to allocate data for a bunch of different things. Instead
492 * of doing several allocations and having to handle all of the error checking
493 * that entails, it can be easier to do a single allocation. This struct
494 * helps facilitate that. The intended usage looks like this:
497 * anv_multialloc_add(&ma, &main_ptr, 1);
498 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
499 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
501 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
502 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
504 struct anv_multialloc
{
512 #define ANV_MULTIALLOC_INIT \
513 ((struct anv_multialloc) { 0, })
515 #define ANV_MULTIALLOC(_name) \
516 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
518 __attribute__((always_inline
))
520 _anv_multialloc_add(struct anv_multialloc
*ma
,
521 void **ptr
, size_t size
, size_t align
)
523 size_t offset
= align_u64(ma
->size
, align
);
524 ma
->size
= offset
+ size
;
525 ma
->align
= MAX2(ma
->align
, align
);
527 /* Store the offset in the pointer. */
528 *ptr
= (void *)(uintptr_t)offset
;
530 assert(ma
->ptr_count
< ARRAY_SIZE(ma
->ptrs
));
531 ma
->ptrs
[ma
->ptr_count
++] = ptr
;
534 #define anv_multialloc_add_size(_ma, _ptr, _size) \
535 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
537 #define anv_multialloc_add(_ma, _ptr, _count) \
538 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
540 __attribute__((always_inline
))
542 anv_multialloc_alloc(struct anv_multialloc
*ma
,
543 const VkAllocationCallbacks
*alloc
,
544 VkSystemAllocationScope scope
)
546 void *ptr
= vk_alloc(alloc
, ma
->size
, ma
->align
, scope
);
550 /* Fill out each of the pointers with their final value.
552 * for (uint32_t i = 0; i < ma->ptr_count; i++)
553 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
555 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
556 * constant, GCC is incapable of figuring this out and unrolling the loop
557 * so we have to give it a little help.
559 STATIC_ASSERT(ARRAY_SIZE(ma
->ptrs
) == 8);
560 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
561 if ((_i) < ma->ptr_count) \
562 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
563 _ANV_MULTIALLOC_UPDATE_POINTER(0);
564 _ANV_MULTIALLOC_UPDATE_POINTER(1);
565 _ANV_MULTIALLOC_UPDATE_POINTER(2);
566 _ANV_MULTIALLOC_UPDATE_POINTER(3);
567 _ANV_MULTIALLOC_UPDATE_POINTER(4);
568 _ANV_MULTIALLOC_UPDATE_POINTER(5);
569 _ANV_MULTIALLOC_UPDATE_POINTER(6);
570 _ANV_MULTIALLOC_UPDATE_POINTER(7);
571 #undef _ANV_MULTIALLOC_UPDATE_POINTER
576 __attribute__((always_inline
))
578 anv_multialloc_alloc2(struct anv_multialloc
*ma
,
579 const VkAllocationCallbacks
*parent_alloc
,
580 const VkAllocationCallbacks
*alloc
,
581 VkSystemAllocationScope scope
)
583 return anv_multialloc_alloc(ma
, alloc
? alloc
: parent_alloc
, scope
);
586 /* Extra ANV-defined BO flags which won't be passed to the kernel */
587 #define ANV_BO_EXTERNAL (1ull << 31)
588 #define ANV_BO_FLAG_MASK (1ull << 31)
593 /* Index into the current validation list. This is used by the
594 * validation list building alrogithm to track which buffers are already
595 * in the validation list so that we can ensure uniqueness.
599 /* Last known offset. This value is provided by the kernel when we
600 * execbuf and is used as the presumed offset for the next bunch of
608 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
613 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
615 bo
->gem_handle
= gem_handle
;
623 /* Represents a lock-free linked list of "free" things. This is used by
624 * both the block pool and the state pools. Unfortunately, in order to
625 * solve the ABA problem, we can't use a single uint32_t head.
627 union anv_free_list
{
631 /* A simple count that is incremented every time the head changes. */
637 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { UINT32_MAX, 0 } })
639 struct anv_block_state
{
649 #define anv_block_pool_foreach_bo(bo, pool) \
650 for (bo = (pool)->bos; bo != &(pool)->bos[(pool)->nbos]; bo++)
652 #define ANV_MAX_BLOCK_POOL_BOS 20
654 struct anv_block_pool
{
655 struct anv_device
*device
;
659 struct anv_bo bos
[ANV_MAX_BLOCK_POOL_BOS
];
665 /* The address where the start of the pool is pinned. The various bos that
666 * are created as the pool grows will have addresses in the range
667 * [start_address, start_address + BLOCK_POOL_MEMFD_SIZE).
669 uint64_t start_address
;
671 /* The offset from the start of the bo to the "center" of the block
672 * pool. Pointers to allocated blocks are given by
673 * bo.map + center_bo_offset + offsets.
675 uint32_t center_bo_offset
;
677 /* Current memory map of the block pool. This pointer may or may not
678 * point to the actual beginning of the block pool memory. If
679 * anv_block_pool_alloc_back has ever been called, then this pointer
680 * will point to the "center" position of the buffer and all offsets
681 * (negative or positive) given out by the block pool alloc functions
682 * will be valid relative to this pointer.
684 * In particular, map == bo.map + center_offset
686 * DO NOT access this pointer directly. Use anv_block_pool_map() instead,
687 * since it will handle the softpin case as well, where this points to NULL.
693 * Array of mmaps and gem handles owned by the block pool, reclaimed when
694 * the block pool is destroyed.
696 struct u_vector mmap_cleanups
;
698 struct anv_block_state state
;
700 struct anv_block_state back_state
;
703 /* Block pools are backed by a fixed-size 1GB memfd */
704 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
706 /* The center of the block pool is also the middle of the memfd. This may
707 * change in the future if we decide differently for some reason.
709 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
711 static inline uint32_t
712 anv_block_pool_size(struct anv_block_pool
*pool
)
714 return pool
->state
.end
+ pool
->back_state
.end
;
724 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
726 struct anv_fixed_size_state_pool
{
727 union anv_free_list free_list
;
728 struct anv_block_state block
;
731 #define ANV_MIN_STATE_SIZE_LOG2 6
732 #define ANV_MAX_STATE_SIZE_LOG2 20
734 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
736 struct anv_free_entry
{
738 struct anv_state state
;
741 struct anv_state_table
{
742 struct anv_device
*device
;
744 struct anv_free_entry
*map
;
746 struct anv_block_state state
;
747 struct u_vector mmap_cleanups
;
750 struct anv_state_pool
{
751 struct anv_block_pool block_pool
;
753 struct anv_state_table table
;
755 /* The size of blocks which will be allocated from the block pool */
758 /** Free list for "back" allocations */
759 union anv_free_list back_alloc_free_list
;
761 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
764 struct anv_state_stream_block
;
766 struct anv_state_stream
{
767 struct anv_state_pool
*state_pool
;
769 /* The size of blocks to allocate from the state pool */
772 /* Current block we're allocating from */
773 struct anv_state block
;
775 /* Offset into the current block at which to allocate the next state */
778 /* List of all blocks allocated from this pool */
779 struct anv_state_stream_block
*block_list
;
782 /* The block_pool functions exported for testing only. The block pool should
783 * only be used via a state pool (see below).
785 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
786 struct anv_device
*device
,
787 uint64_t start_address
,
788 uint32_t initial_size
,
790 void anv_block_pool_finish(struct anv_block_pool
*pool
);
791 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
,
792 uint32_t block_size
, uint32_t *padding
);
793 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
,
794 uint32_t block_size
);
795 void* anv_block_pool_map(struct anv_block_pool
*pool
, int32_t offset
);
797 VkResult
anv_state_pool_init(struct anv_state_pool
*pool
,
798 struct anv_device
*device
,
799 uint64_t start_address
,
802 void anv_state_pool_finish(struct anv_state_pool
*pool
);
803 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
804 uint32_t state_size
, uint32_t alignment
);
805 struct anv_state
anv_state_pool_alloc_back(struct anv_state_pool
*pool
);
806 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
807 void anv_state_stream_init(struct anv_state_stream
*stream
,
808 struct anv_state_pool
*state_pool
,
809 uint32_t block_size
);
810 void anv_state_stream_finish(struct anv_state_stream
*stream
);
811 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
812 uint32_t size
, uint32_t alignment
);
814 VkResult
anv_state_table_init(struct anv_state_table
*table
,
815 struct anv_device
*device
,
816 uint32_t initial_entries
);
817 void anv_state_table_finish(struct anv_state_table
*table
);
818 VkResult
anv_state_table_add(struct anv_state_table
*table
, uint32_t *idx
,
820 void anv_free_list_push(union anv_free_list
*list
,
821 struct anv_state_table
*table
,
822 uint32_t idx
, uint32_t count
);
823 struct anv_state
* anv_free_list_pop(union anv_free_list
*list
,
824 struct anv_state_table
*table
);
827 static inline struct anv_state
*
828 anv_state_table_get(struct anv_state_table
*table
, uint32_t idx
)
830 return &table
->map
[idx
].state
;
833 * Implements a pool of re-usable BOs. The interface is identical to that
834 * of block_pool except that each block is its own BO.
837 struct anv_device
*device
;
844 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
,
846 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
847 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
849 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
851 struct anv_scratch_bo
{
856 struct anv_scratch_pool
{
857 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
858 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
861 void anv_scratch_pool_init(struct anv_device
*device
,
862 struct anv_scratch_pool
*pool
);
863 void anv_scratch_pool_finish(struct anv_device
*device
,
864 struct anv_scratch_pool
*pool
);
865 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
866 struct anv_scratch_pool
*pool
,
867 gl_shader_stage stage
,
868 unsigned per_thread_scratch
);
870 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
871 struct anv_bo_cache
{
872 struct hash_table
*bo_map
;
873 pthread_mutex_t mutex
;
876 VkResult
anv_bo_cache_init(struct anv_bo_cache
*cache
);
877 void anv_bo_cache_finish(struct anv_bo_cache
*cache
);
878 VkResult
anv_bo_cache_alloc(struct anv_device
*device
,
879 struct anv_bo_cache
*cache
,
880 uint64_t size
, uint64_t bo_flags
,
882 VkResult
anv_bo_cache_import_host_ptr(struct anv_device
*device
,
883 struct anv_bo_cache
*cache
,
884 void *host_ptr
, uint32_t size
,
885 uint64_t bo_flags
, struct anv_bo
**bo_out
);
886 VkResult
anv_bo_cache_import(struct anv_device
*device
,
887 struct anv_bo_cache
*cache
,
888 int fd
, uint64_t bo_flags
,
890 VkResult
anv_bo_cache_export(struct anv_device
*device
,
891 struct anv_bo_cache
*cache
,
892 struct anv_bo
*bo_in
, int *fd_out
);
893 void anv_bo_cache_release(struct anv_device
*device
,
894 struct anv_bo_cache
*cache
,
897 struct anv_memory_type
{
898 /* Standard bits passed on to the client */
899 VkMemoryPropertyFlags propertyFlags
;
902 /* Driver-internal book-keeping */
903 VkBufferUsageFlags valid_buffer_usage
;
906 struct anv_memory_heap
{
907 /* Standard bits passed on to the client */
909 VkMemoryHeapFlags flags
;
911 /* Driver-internal book-keeping */
914 bool supports_48bit_addresses
;
917 struct anv_physical_device
{
918 VK_LOADER_DATA _loader_data
;
920 struct anv_instance
* instance
;
931 struct gen_device_info info
;
932 /** Amount of "GPU memory" we want to advertise
934 * Clearly, this value is bogus since Intel is a UMA architecture. On
935 * gen7 platforms, we are limited by GTT size unless we want to implement
936 * fine-grained tracking and GTT splitting. On Broadwell and above we are
937 * practically unlimited. However, we will never report more than 3/4 of
938 * the total system ram to try and avoid running out of RAM.
940 bool supports_48bit_addresses
;
941 struct brw_compiler
* compiler
;
942 struct isl_device isl_dev
;
943 int cmd_parser_version
;
945 bool has_exec_capture
;
948 bool has_syncobj_wait
;
949 bool has_context_priority
;
951 bool has_context_isolation
;
952 bool always_use_bindless
;
954 /** True if we can access buffers using A64 messages */
955 bool has_a64_buffer_access
;
957 struct anv_device_extension_table supported_extensions
;
960 uint32_t subslice_total
;
964 struct anv_memory_type types
[VK_MAX_MEMORY_TYPES
];
966 struct anv_memory_heap heaps
[VK_MAX_MEMORY_HEAPS
];
969 uint8_t driver_build_sha1
[20];
970 uint8_t pipeline_cache_uuid
[VK_UUID_SIZE
];
971 uint8_t driver_uuid
[VK_UUID_SIZE
];
972 uint8_t device_uuid
[VK_UUID_SIZE
];
974 struct disk_cache
* disk_cache
;
976 struct wsi_device wsi_device
;
981 struct anv_app_info
{
982 const char* app_name
;
983 uint32_t app_version
;
984 const char* engine_name
;
985 uint32_t engine_version
;
986 uint32_t api_version
;
989 struct anv_instance
{
990 VK_LOADER_DATA _loader_data
;
992 VkAllocationCallbacks alloc
;
994 struct anv_app_info app_info
;
996 struct anv_instance_extension_table enabled_extensions
;
997 struct anv_instance_dispatch_table dispatch
;
998 struct anv_device_dispatch_table device_dispatch
;
1000 int physicalDeviceCount
;
1001 struct anv_physical_device physicalDevice
;
1003 bool pipeline_cache_enabled
;
1005 struct vk_debug_report_instance debug_report_callbacks
;
1008 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
1009 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
1011 uint32_t anv_physical_device_api_version(struct anv_physical_device
*dev
);
1012 bool anv_physical_device_extension_supported(struct anv_physical_device
*dev
,
1016 VK_LOADER_DATA _loader_data
;
1018 struct anv_device
* device
;
1020 VkDeviceQueueCreateFlags flags
;
1023 struct anv_pipeline_cache
{
1024 struct anv_device
* device
;
1025 pthread_mutex_t mutex
;
1027 struct hash_table
* nir_cache
;
1029 struct hash_table
* cache
;
1032 struct nir_xfb_info
;
1033 struct anv_pipeline_bind_map
;
1035 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
1036 struct anv_device
*device
,
1037 bool cache_enabled
);
1038 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
1040 struct anv_shader_bin
*
1041 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
1042 const void *key
, uint32_t key_size
);
1043 struct anv_shader_bin
*
1044 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
1045 const void *key_data
, uint32_t key_size
,
1046 const void *kernel_data
, uint32_t kernel_size
,
1047 const void *constant_data
,
1048 uint32_t constant_data_size
,
1049 const struct brw_stage_prog_data
*prog_data
,
1050 uint32_t prog_data_size
,
1051 const struct nir_xfb_info
*xfb_info
,
1052 const struct anv_pipeline_bind_map
*bind_map
);
1054 struct anv_shader_bin
*
1055 anv_device_search_for_kernel(struct anv_device
*device
,
1056 struct anv_pipeline_cache
*cache
,
1057 const void *key_data
, uint32_t key_size
,
1058 bool *user_cache_bit
);
1060 struct anv_shader_bin
*
1061 anv_device_upload_kernel(struct anv_device
*device
,
1062 struct anv_pipeline_cache
*cache
,
1063 const void *key_data
, uint32_t key_size
,
1064 const void *kernel_data
, uint32_t kernel_size
,
1065 const void *constant_data
,
1066 uint32_t constant_data_size
,
1067 const struct brw_stage_prog_data
*prog_data
,
1068 uint32_t prog_data_size
,
1069 const struct nir_xfb_info
*xfb_info
,
1070 const struct anv_pipeline_bind_map
*bind_map
);
1073 struct nir_shader_compiler_options
;
1076 anv_device_search_for_nir(struct anv_device
*device
,
1077 struct anv_pipeline_cache
*cache
,
1078 const struct nir_shader_compiler_options
*nir_options
,
1079 unsigned char sha1_key
[20],
1083 anv_device_upload_nir(struct anv_device
*device
,
1084 struct anv_pipeline_cache
*cache
,
1085 const struct nir_shader
*nir
,
1086 unsigned char sha1_key
[20]);
1089 VK_LOADER_DATA _loader_data
;
1091 VkAllocationCallbacks alloc
;
1093 struct anv_instance
* instance
;
1094 uint32_t chipset_id
;
1096 struct gen_device_info info
;
1097 struct isl_device isl_dev
;
1100 bool can_chain_batches
;
1101 bool robust_buffer_access
;
1102 struct anv_device_extension_table enabled_extensions
;
1103 struct anv_device_dispatch_table dispatch
;
1105 pthread_mutex_t vma_mutex
;
1106 struct util_vma_heap vma_lo
;
1107 struct util_vma_heap vma_hi
;
1108 uint64_t vma_lo_available
;
1109 uint64_t vma_hi_available
;
1111 /** List of all anv_device_memory objects */
1112 struct list_head memory_objects
;
1114 struct anv_bo_pool batch_bo_pool
;
1116 struct anv_bo_cache bo_cache
;
1118 struct anv_state_pool dynamic_state_pool
;
1119 struct anv_state_pool instruction_state_pool
;
1120 struct anv_state_pool binding_table_pool
;
1121 struct anv_state_pool surface_state_pool
;
1123 struct anv_bo workaround_bo
;
1124 struct anv_bo trivial_batch_bo
;
1125 struct anv_bo hiz_clear_bo
;
1127 struct anv_pipeline_cache default_pipeline_cache
;
1128 struct blorp_context blorp
;
1130 struct anv_state border_colors
;
1132 struct anv_queue queue
;
1134 struct anv_scratch_pool scratch_pool
;
1136 uint32_t default_mocs
;
1137 uint32_t external_mocs
;
1139 pthread_mutex_t mutex
;
1140 pthread_cond_t queue_submit
;
1143 struct gen_batch_decode_ctx decoder_ctx
;
1145 * When decoding a anv_cmd_buffer, we might need to search for BOs through
1146 * the cmd_buffer's list.
1148 struct anv_cmd_buffer
*cmd_buffer_being_decoded
;
1151 static inline struct anv_state_pool
*
1152 anv_binding_table_pool(struct anv_device
*device
)
1154 if (device
->instance
->physicalDevice
.use_softpin
)
1155 return &device
->binding_table_pool
;
1157 return &device
->surface_state_pool
;
1160 static inline struct anv_state
1161 anv_binding_table_pool_alloc(struct anv_device
*device
) {
1162 if (device
->instance
->physicalDevice
.use_softpin
)
1163 return anv_state_pool_alloc(&device
->binding_table_pool
,
1164 device
->binding_table_pool
.block_size
, 0);
1166 return anv_state_pool_alloc_back(&device
->surface_state_pool
);
1170 anv_binding_table_pool_free(struct anv_device
*device
, struct anv_state state
) {
1171 anv_state_pool_free(anv_binding_table_pool(device
), state
);
1174 static inline uint32_t
1175 anv_mocs_for_bo(const struct anv_device
*device
, const struct anv_bo
*bo
)
1177 if (bo
->flags
& ANV_BO_EXTERNAL
)
1178 return device
->external_mocs
;
1180 return device
->default_mocs
;
1183 void anv_device_init_blorp(struct anv_device
*device
);
1184 void anv_device_finish_blorp(struct anv_device
*device
);
1186 VkResult
_anv_device_set_lost(struct anv_device
*device
,
1187 const char *file
, int line
,
1188 const char *msg
, ...);
1189 #define anv_device_set_lost(dev, ...) \
1190 _anv_device_set_lost(dev, __FILE__, __LINE__, __VA_ARGS__)
1193 anv_device_is_lost(struct anv_device
*device
)
1195 return unlikely(device
->_lost
);
1198 VkResult
anv_device_execbuf(struct anv_device
*device
,
1199 struct drm_i915_gem_execbuffer2
*execbuf
,
1200 struct anv_bo
**execbuf_bos
);
1201 VkResult
anv_device_query_status(struct anv_device
*device
);
1202 VkResult
anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
);
1203 VkResult
anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
1206 void* anv_gem_mmap(struct anv_device
*device
,
1207 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
1208 void anv_gem_munmap(void *p
, uint64_t size
);
1209 uint32_t anv_gem_create(struct anv_device
*device
, uint64_t size
);
1210 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
1211 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
1212 int anv_gem_busy(struct anv_device
*device
, uint32_t gem_handle
);
1213 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
1214 int anv_gem_execbuffer(struct anv_device
*device
,
1215 struct drm_i915_gem_execbuffer2
*execbuf
);
1216 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
1217 uint32_t stride
, uint32_t tiling
);
1218 int anv_gem_create_context(struct anv_device
*device
);
1219 bool anv_gem_has_context_priority(int fd
);
1220 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
1221 int anv_gem_set_context_param(int fd
, int context
, uint32_t param
,
1223 int anv_gem_get_context_param(int fd
, int context
, uint32_t param
,
1225 int anv_gem_get_param(int fd
, uint32_t param
);
1226 int anv_gem_get_tiling(struct anv_device
*device
, uint32_t gem_handle
);
1227 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
1228 int anv_gem_get_aperture(int fd
, uint64_t *size
);
1229 int anv_gem_gpu_get_reset_stats(struct anv_device
*device
,
1230 uint32_t *active
, uint32_t *pending
);
1231 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
1232 int anv_gem_reg_read(struct anv_device
*device
,
1233 uint32_t offset
, uint64_t *result
);
1234 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
1235 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
1236 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
1237 uint32_t read_domains
, uint32_t write_domain
);
1238 int anv_gem_sync_file_merge(struct anv_device
*device
, int fd1
, int fd2
);
1239 uint32_t anv_gem_syncobj_create(struct anv_device
*device
, uint32_t flags
);
1240 void anv_gem_syncobj_destroy(struct anv_device
*device
, uint32_t handle
);
1241 int anv_gem_syncobj_handle_to_fd(struct anv_device
*device
, uint32_t handle
);
1242 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device
*device
, int fd
);
1243 int anv_gem_syncobj_export_sync_file(struct anv_device
*device
,
1245 int anv_gem_syncobj_import_sync_file(struct anv_device
*device
,
1246 uint32_t handle
, int fd
);
1247 void anv_gem_syncobj_reset(struct anv_device
*device
, uint32_t handle
);
1248 bool anv_gem_supports_syncobj_wait(int fd
);
1249 int anv_gem_syncobj_wait(struct anv_device
*device
,
1250 uint32_t *handles
, uint32_t num_handles
,
1251 int64_t abs_timeout_ns
, bool wait_all
);
1253 bool anv_vma_alloc(struct anv_device
*device
, struct anv_bo
*bo
);
1254 void anv_vma_free(struct anv_device
*device
, struct anv_bo
*bo
);
1256 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
1258 struct anv_reloc_list
{
1259 uint32_t num_relocs
;
1260 uint32_t array_length
;
1261 struct drm_i915_gem_relocation_entry
* relocs
;
1262 struct anv_bo
** reloc_bos
;
1266 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
1267 const VkAllocationCallbacks
*alloc
);
1268 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
1269 const VkAllocationCallbacks
*alloc
);
1271 VkResult
anv_reloc_list_add(struct anv_reloc_list
*list
,
1272 const VkAllocationCallbacks
*alloc
,
1273 uint32_t offset
, struct anv_bo
*target_bo
,
1276 struct anv_batch_bo
{
1277 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1278 struct list_head link
;
1282 /* Bytes actually consumed in this batch BO */
1285 struct anv_reloc_list relocs
;
1289 const VkAllocationCallbacks
* alloc
;
1295 struct anv_reloc_list
* relocs
;
1297 /* This callback is called (with the associated user data) in the event
1298 * that the batch runs out of space.
1300 VkResult (*extend_cb
)(struct anv_batch
*, void *);
1304 * Current error status of the command buffer. Used to track inconsistent
1305 * or incomplete command buffer states that are the consequence of run-time
1306 * errors such as out of memory scenarios. We want to track this in the
1307 * batch because the command buffer object is not visible to some parts
1313 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
1314 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
1315 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
1316 void *location
, struct anv_bo
*bo
, uint32_t offset
);
1317 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
1318 struct anv_batch
*batch
);
1320 static inline VkResult
1321 anv_batch_set_error(struct anv_batch
*batch
, VkResult error
)
1323 assert(error
!= VK_SUCCESS
);
1324 if (batch
->status
== VK_SUCCESS
)
1325 batch
->status
= error
;
1326 return batch
->status
;
1330 anv_batch_has_error(struct anv_batch
*batch
)
1332 return batch
->status
!= VK_SUCCESS
;
1335 struct anv_address
{
1340 #define ANV_NULL_ADDRESS ((struct anv_address) { NULL, 0 })
1343 anv_address_is_null(struct anv_address addr
)
1345 return addr
.bo
== NULL
&& addr
.offset
== 0;
1348 static inline uint64_t
1349 anv_address_physical(struct anv_address addr
)
1351 if (addr
.bo
&& (addr
.bo
->flags
& EXEC_OBJECT_PINNED
))
1352 return gen_canonical_address(addr
.bo
->offset
+ addr
.offset
);
1354 return gen_canonical_address(addr
.offset
);
1357 static inline struct anv_address
1358 anv_address_add(struct anv_address addr
, uint64_t offset
)
1360 addr
.offset
+= offset
;
1365 write_reloc(const struct anv_device
*device
, void *p
, uint64_t v
, bool flush
)
1367 unsigned reloc_size
= 0;
1368 if (device
->info
.gen
>= 8) {
1369 reloc_size
= sizeof(uint64_t);
1370 *(uint64_t *)p
= gen_canonical_address(v
);
1372 reloc_size
= sizeof(uint32_t);
1376 if (flush
&& !device
->info
.has_llc
)
1377 gen_flush_range(p
, reloc_size
);
1380 static inline uint64_t
1381 _anv_combine_address(struct anv_batch
*batch
, void *location
,
1382 const struct anv_address address
, uint32_t delta
)
1384 if (address
.bo
== NULL
) {
1385 return address
.offset
+ delta
;
1387 assert(batch
->start
<= location
&& location
< batch
->end
);
1389 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
1393 #define __gen_address_type struct anv_address
1394 #define __gen_user_data struct anv_batch
1395 #define __gen_combine_address _anv_combine_address
1397 /* Wrapper macros needed to work around preprocessor argument issues. In
1398 * particular, arguments don't get pre-evaluated if they are concatenated.
1399 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1400 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1401 * We can work around this easily enough with these helpers.
1403 #define __anv_cmd_length(cmd) cmd ## _length
1404 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1405 #define __anv_cmd_header(cmd) cmd ## _header
1406 #define __anv_cmd_pack(cmd) cmd ## _pack
1407 #define __anv_reg_num(reg) reg ## _num
1409 #define anv_pack_struct(dst, struc, ...) do { \
1410 struct struc __template = { \
1413 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1414 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1417 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1418 void *__dst = anv_batch_emit_dwords(batch, n); \
1420 struct cmd __template = { \
1421 __anv_cmd_header(cmd), \
1422 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1425 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1430 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1434 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1435 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1438 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1439 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1440 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1443 #define anv_batch_emit(batch, cmd, name) \
1444 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1445 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1446 __builtin_expect(_dst != NULL, 1); \
1447 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1448 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1452 /* MEMORY_OBJECT_CONTROL_STATE:
1453 * .GraphicsDataTypeGFDT = 0,
1454 * .LLCCacheabilityControlLLCCC = 0,
1455 * .L3CacheabilityControlL3CC = 1,
1459 /* MEMORY_OBJECT_CONTROL_STATE:
1460 * .LLCeLLCCacheabilityControlLLCCC = 0,
1461 * .L3CacheabilityControlL3CC = 1,
1463 #define GEN75_MOCS 1
1465 /* MEMORY_OBJECT_CONTROL_STATE:
1466 * .MemoryTypeLLCeLLCCacheabilityControl = WB,
1467 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1468 * .AgeforQUADLRU = 0
1470 #define GEN8_MOCS 0x78
1472 /* MEMORY_OBJECT_CONTROL_STATE:
1473 * .MemoryTypeLLCeLLCCacheabilityControl = UCwithFenceifcoherentcycle,
1474 * .TargetCache = L3DefertoPATforLLCeLLCselection,
1475 * .AgeforQUADLRU = 0
1477 #define GEN8_EXTERNAL_MOCS 0x18
1479 /* Skylake: MOCS is now an index into an array of 62 different caching
1480 * configurations programmed by the kernel.
1483 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1484 #define GEN9_MOCS (2 << 1)
1486 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */
1487 #define GEN9_EXTERNAL_MOCS (1 << 1)
1489 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1490 #define GEN10_MOCS GEN9_MOCS
1491 #define GEN10_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1493 /* Ice Lake MOCS defines are duplicates of Skylake MOCS defines. */
1494 #define GEN11_MOCS GEN9_MOCS
1495 #define GEN11_EXTERNAL_MOCS GEN9_EXTERNAL_MOCS
1497 struct anv_device_memory
{
1498 struct list_head link
;
1501 struct anv_memory_type
* type
;
1502 VkDeviceSize map_size
;
1505 /* If set, we are holding reference to AHardwareBuffer
1506 * which we must release when memory is freed.
1508 struct AHardwareBuffer
* ahw
;
1510 /* If set, this memory comes from a host pointer. */
1515 * Header for Vertex URB Entry (VUE)
1517 struct anv_vue_header
{
1519 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
1520 uint32_t ViewportIndex
;
1524 /** Struct representing a address/range descriptor
1526 * The fields of this struct correspond directly to the data layout of
1527 * nir_address_format_64bit_bounded_global addresses. The last field is the
1528 * offset in the NIR address so it must be zero so that when you load the
1529 * descriptor you get a pointer to the start of the range.
1531 struct anv_address_range_descriptor
{
1537 enum anv_descriptor_data
{
1538 /** The descriptor contains a BTI reference to a surface state */
1539 ANV_DESCRIPTOR_SURFACE_STATE
= (1 << 0),
1540 /** The descriptor contains a BTI reference to a sampler state */
1541 ANV_DESCRIPTOR_SAMPLER_STATE
= (1 << 1),
1542 /** The descriptor contains an actual buffer view */
1543 ANV_DESCRIPTOR_BUFFER_VIEW
= (1 << 2),
1544 /** The descriptor contains auxiliary image layout data */
1545 ANV_DESCRIPTOR_IMAGE_PARAM
= (1 << 3),
1546 /** The descriptor contains auxiliary image layout data */
1547 ANV_DESCRIPTOR_INLINE_UNIFORM
= (1 << 4),
1548 /** anv_address_range_descriptor with a buffer address and range */
1549 ANV_DESCRIPTOR_ADDRESS_RANGE
= (1 << 5),
1552 struct anv_descriptor_set_binding_layout
{
1554 /* The type of the descriptors in this binding */
1555 VkDescriptorType type
;
1558 /* Bitfield representing the type of data this descriptor contains */
1559 enum anv_descriptor_data data
;
1561 /* Maximum number of YCbCr texture/sampler planes */
1562 uint8_t max_plane_count
;
1564 /* Number of array elements in this binding (or size in bytes for inline
1567 uint16_t array_size
;
1569 /* Index into the flattend descriptor set */
1570 uint16_t descriptor_index
;
1572 /* Index into the dynamic state array for a dynamic buffer */
1573 int16_t dynamic_offset_index
;
1575 /* Index into the descriptor set buffer views */
1576 int16_t buffer_view_index
;
1578 /* Offset into the descriptor buffer where this descriptor lives */
1579 uint32_t descriptor_offset
;
1581 /* Immutable samplers (or NULL if no immutable samplers) */
1582 struct anv_sampler
**immutable_samplers
;
1585 unsigned anv_descriptor_size(const struct anv_descriptor_set_binding_layout
*layout
);
1587 unsigned anv_descriptor_type_size(const struct anv_physical_device
*pdevice
,
1588 VkDescriptorType type
);
1590 bool anv_descriptor_supports_bindless(const struct anv_physical_device
*pdevice
,
1591 const struct anv_descriptor_set_binding_layout
*binding
,
1594 bool anv_descriptor_requires_bindless(const struct anv_physical_device
*pdevice
,
1595 const struct anv_descriptor_set_binding_layout
*binding
,
1598 struct anv_descriptor_set_layout
{
1599 /* Descriptor set layouts can be destroyed at almost any time */
1602 /* Number of bindings in this descriptor set */
1603 uint16_t binding_count
;
1605 /* Total size of the descriptor set with room for all array entries */
1608 /* Shader stages affected by this descriptor set */
1609 uint16_t shader_stages
;
1611 /* Number of buffer views in this descriptor set */
1612 uint16_t buffer_view_count
;
1614 /* Number of dynamic offsets used by this descriptor set */
1615 uint16_t dynamic_offset_count
;
1617 /* Size of the descriptor buffer for this descriptor set */
1618 uint32_t descriptor_buffer_size
;
1620 /* Bindings in this descriptor set */
1621 struct anv_descriptor_set_binding_layout binding
[0];
1625 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout
*layout
)
1627 assert(layout
&& layout
->ref_cnt
>= 1);
1628 p_atomic_inc(&layout
->ref_cnt
);
1632 anv_descriptor_set_layout_unref(struct anv_device
*device
,
1633 struct anv_descriptor_set_layout
*layout
)
1635 assert(layout
&& layout
->ref_cnt
>= 1);
1636 if (p_atomic_dec_zero(&layout
->ref_cnt
))
1637 vk_free(&device
->alloc
, layout
);
1640 struct anv_descriptor
{
1641 VkDescriptorType type
;
1645 VkImageLayout layout
;
1646 struct anv_image_view
*image_view
;
1647 struct anv_sampler
*sampler
;
1651 struct anv_buffer
*buffer
;
1656 struct anv_buffer_view
*buffer_view
;
1660 struct anv_descriptor_set
{
1661 struct anv_descriptor_pool
*pool
;
1662 struct anv_descriptor_set_layout
*layout
;
1665 /* State relative to anv_descriptor_pool::bo */
1666 struct anv_state desc_mem
;
1667 /* Surface state for the descriptor buffer */
1668 struct anv_state desc_surface_state
;
1670 uint32_t buffer_view_count
;
1671 struct anv_buffer_view
*buffer_views
;
1673 /* Link to descriptor pool's desc_sets list . */
1674 struct list_head pool_link
;
1676 struct anv_descriptor descriptors
[0];
1679 struct anv_buffer_view
{
1680 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1681 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1683 struct anv_address address
;
1685 struct anv_state surface_state
;
1686 struct anv_state storage_surface_state
;
1687 struct anv_state writeonly_storage_surface_state
;
1689 struct brw_image_param storage_image_param
;
1692 struct anv_push_descriptor_set
{
1693 struct anv_descriptor_set set
;
1695 /* Put this field right behind anv_descriptor_set so it fills up the
1696 * descriptors[0] field. */
1697 struct anv_descriptor descriptors
[MAX_PUSH_DESCRIPTORS
];
1699 /** True if the descriptor set buffer has been referenced by a draw or
1702 bool set_used_on_gpu
;
1704 struct anv_buffer_view buffer_views
[MAX_PUSH_DESCRIPTORS
];
1707 struct anv_descriptor_pool
{
1713 struct util_vma_heap bo_heap
;
1715 struct anv_state_stream surface_state_stream
;
1716 void *surface_state_free_list
;
1718 struct list_head desc_sets
;
1723 enum anv_descriptor_template_entry_type
{
1724 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE
,
1725 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER
,
1726 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1729 struct anv_descriptor_template_entry
{
1730 /* The type of descriptor in this entry */
1731 VkDescriptorType type
;
1733 /* Binding in the descriptor set */
1736 /* Offset at which to write into the descriptor set binding */
1737 uint32_t array_element
;
1739 /* Number of elements to write into the descriptor set binding */
1740 uint32_t array_count
;
1742 /* Offset into the user provided data */
1745 /* Stride between elements into the user provided data */
1749 struct anv_descriptor_update_template
{
1750 VkPipelineBindPoint bind_point
;
1752 /* The descriptor set this template corresponds to. This value is only
1753 * valid if the template was created with the templateType
1754 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET.
1758 /* Number of entries in this template */
1759 uint32_t entry_count
;
1761 /* Entries of the template */
1762 struct anv_descriptor_template_entry entries
[0];
1766 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
);
1769 anv_descriptor_set_write_image_view(struct anv_device
*device
,
1770 struct anv_descriptor_set
*set
,
1771 const VkDescriptorImageInfo
* const info
,
1772 VkDescriptorType type
,
1777 anv_descriptor_set_write_buffer_view(struct anv_device
*device
,
1778 struct anv_descriptor_set
*set
,
1779 VkDescriptorType type
,
1780 struct anv_buffer_view
*buffer_view
,
1785 anv_descriptor_set_write_buffer(struct anv_device
*device
,
1786 struct anv_descriptor_set
*set
,
1787 struct anv_state_stream
*alloc_stream
,
1788 VkDescriptorType type
,
1789 struct anv_buffer
*buffer
,
1792 VkDeviceSize offset
,
1793 VkDeviceSize range
);
1795 anv_descriptor_set_write_inline_uniform_data(struct anv_device
*device
,
1796 struct anv_descriptor_set
*set
,
1803 anv_descriptor_set_write_template(struct anv_device
*device
,
1804 struct anv_descriptor_set
*set
,
1805 struct anv_state_stream
*alloc_stream
,
1806 const struct anv_descriptor_update_template
*template,
1810 anv_descriptor_set_create(struct anv_device
*device
,
1811 struct anv_descriptor_pool
*pool
,
1812 struct anv_descriptor_set_layout
*layout
,
1813 struct anv_descriptor_set
**out_set
);
1816 anv_descriptor_set_destroy(struct anv_device
*device
,
1817 struct anv_descriptor_pool
*pool
,
1818 struct anv_descriptor_set
*set
);
1820 #define ANV_DESCRIPTOR_SET_DESCRIPTORS (UINT8_MAX - 3)
1821 #define ANV_DESCRIPTOR_SET_NUM_WORK_GROUPS (UINT8_MAX - 2)
1822 #define ANV_DESCRIPTOR_SET_SHADER_CONSTANTS (UINT8_MAX - 1)
1823 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1825 struct anv_pipeline_binding
{
1826 /* The descriptor set this surface corresponds to. The special value of
1827 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1828 * to a color attachment and not a regular descriptor.
1832 /* Binding in the descriptor set */
1835 /* Index in the binding */
1838 /* Plane in the binding index */
1841 /* Input attachment index (relative to the subpass) */
1842 uint8_t input_attachment_index
;
1844 /* For a storage image, whether it is write-only */
1848 struct anv_pipeline_layout
{
1850 struct anv_descriptor_set_layout
*layout
;
1851 uint32_t dynamic_offset_start
;
1856 unsigned char sha1
[20];
1860 struct anv_device
* device
;
1863 VkBufferUsageFlags usage
;
1865 /* Set when bound */
1866 struct anv_address address
;
1869 static inline uint64_t
1870 anv_buffer_get_range(struct anv_buffer
*buffer
, uint64_t offset
, uint64_t range
)
1872 assert(offset
<= buffer
->size
);
1873 if (range
== VK_WHOLE_SIZE
) {
1874 return buffer
->size
- offset
;
1876 assert(range
+ offset
>= range
);
1877 assert(range
+ offset
<= buffer
->size
);
1882 enum anv_cmd_dirty_bits
{
1883 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1884 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1885 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1886 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1887 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1888 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1889 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1890 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1891 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1892 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
1893 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1894 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1895 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1896 ANV_CMD_DIRTY_XFB_ENABLE
= 1 << 12,
1898 typedef uint32_t anv_cmd_dirty_mask_t
;
1900 enum anv_pipe_bits
{
1901 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
1902 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
1903 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
1904 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
1905 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
1906 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
1907 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
1908 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
1909 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
1910 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
1911 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
1913 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1914 * a flush has happened but not a CS stall. The next time we do any sort
1915 * of invalidation we need to insert a CS stall at that time. Otherwise,
1916 * we would have to CS stall on every flush which could be bad.
1918 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
1920 /* This bit does not exist directly in PIPE_CONTROL. It means that render
1921 * target operations related to transfer commands with VkBuffer as
1922 * destination are ongoing. Some operations like copies on the command
1923 * streamer might need to be aware of this to trigger the appropriate stall
1924 * before they can proceed with the copy.
1926 ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
= (1 << 22),
1929 #define ANV_PIPE_FLUSH_BITS ( \
1930 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1931 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1932 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1934 #define ANV_PIPE_STALL_BITS ( \
1935 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1936 ANV_PIPE_DEPTH_STALL_BIT | \
1937 ANV_PIPE_CS_STALL_BIT)
1939 #define ANV_PIPE_INVALIDATE_BITS ( \
1940 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1941 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1942 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1943 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1944 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1945 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1947 static inline enum anv_pipe_bits
1948 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags
)
1950 enum anv_pipe_bits pipe_bits
= 0;
1953 for_each_bit(b
, flags
) {
1954 switch ((VkAccessFlagBits
)(1 << b
)) {
1955 case VK_ACCESS_SHADER_WRITE_BIT
:
1956 /* We're transitioning a buffer that was previously used as write
1957 * destination through the data port. To make its content available
1958 * to future operations, flush the data cache.
1960 pipe_bits
|= ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
1962 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
1963 /* We're transitioning a buffer that was previously used as render
1964 * target. To make its content available to future operations, flush
1965 * the render target cache.
1967 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1969 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
1970 /* We're transitioning a buffer that was previously used as depth
1971 * buffer. To make its content available to future operations, flush
1974 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1976 case VK_ACCESS_TRANSFER_WRITE_BIT
:
1977 /* We're transitioning a buffer that was previously used as a
1978 * transfer write destination. Generic write operations include color
1979 * & depth operations as well as buffer operations like :
1980 * - vkCmdClearColorImage()
1981 * - vkCmdClearDepthStencilImage()
1982 * - vkCmdBlitImage()
1983 * - vkCmdCopy*(), vkCmdUpdate*(), vkCmdFill*()
1985 * Most of these operations are implemented using Blorp which writes
1986 * through the render target, so flush that cache to make it visible
1987 * to future operations. And for depth related operations we also
1988 * need to flush the depth cache.
1990 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1991 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1993 case VK_ACCESS_MEMORY_WRITE_BIT
:
1994 /* We're transitioning a buffer for generic write operations. Flush
1997 pipe_bits
|= ANV_PIPE_FLUSH_BITS
;
2000 break; /* Nothing to do */
2007 static inline enum anv_pipe_bits
2008 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags
)
2010 enum anv_pipe_bits pipe_bits
= 0;
2013 for_each_bit(b
, flags
) {
2014 switch ((VkAccessFlagBits
)(1 << b
)) {
2015 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
2016 /* Indirect draw commands take a buffer as input that we're going to
2017 * read from the command streamer to load some of the HW registers
2018 * (see genX_cmd_buffer.c:load_indirect_parameters). This requires a
2019 * command streamer stall so that all the cache flushes have
2020 * completed before the command streamer loads from memory.
2022 pipe_bits
|= ANV_PIPE_CS_STALL_BIT
;
2023 /* Indirect draw commands also set gl_BaseVertex & gl_BaseIndex
2024 * through a vertex buffer, so invalidate that cache.
2026 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
2027 /* For CmdDipatchIndirect, we also load gl_NumWorkGroups through a
2028 * UBO from the buffer, so we need to invalidate constant cache.
2030 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
2032 case VK_ACCESS_INDEX_READ_BIT
:
2033 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
2034 /* We transitioning a buffer to be used for as input for vkCmdDraw*
2035 * commands, so we invalidate the VF cache to make sure there is no
2036 * stale data when we start rendering.
2038 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
2040 case VK_ACCESS_UNIFORM_READ_BIT
:
2041 /* We transitioning a buffer to be used as uniform data. Because
2042 * uniform is accessed through the data port & sampler, we need to
2043 * invalidate the texture cache (sampler) & constant cache (data
2044 * port) to avoid stale data.
2046 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
2047 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
2049 case VK_ACCESS_SHADER_READ_BIT
:
2050 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
:
2051 case VK_ACCESS_TRANSFER_READ_BIT
:
2052 /* Transitioning a buffer to be read through the sampler, so
2053 * invalidate the texture cache, we don't want any stale data.
2055 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
2057 case VK_ACCESS_MEMORY_READ_BIT
:
2058 /* Transitioning a buffer for generic read, invalidate all the
2061 pipe_bits
|= ANV_PIPE_INVALIDATE_BITS
;
2063 case VK_ACCESS_MEMORY_WRITE_BIT
:
2064 /* Generic write, make sure all previously written things land in
2067 pipe_bits
|= ANV_PIPE_FLUSH_BITS
;
2069 case VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT
:
2070 /* Transitioning a buffer for conditional rendering. We'll load the
2071 * content of this buffer into HW registers using the command
2072 * streamer, so we need to stall the command streamer to make sure
2073 * any in-flight flush operations have completed.
2075 pipe_bits
|= ANV_PIPE_CS_STALL_BIT
;
2078 break; /* Nothing to do */
2085 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
2086 VK_IMAGE_ASPECT_COLOR_BIT | \
2087 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2088 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2089 VK_IMAGE_ASPECT_PLANE_2_BIT)
2090 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
2091 VK_IMAGE_ASPECT_PLANE_0_BIT | \
2092 VK_IMAGE_ASPECT_PLANE_1_BIT | \
2093 VK_IMAGE_ASPECT_PLANE_2_BIT)
2095 struct anv_vertex_binding
{
2096 struct anv_buffer
* buffer
;
2097 VkDeviceSize offset
;
2100 struct anv_xfb_binding
{
2101 struct anv_buffer
* buffer
;
2102 VkDeviceSize offset
;
2106 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
2107 #define ANV_PARAM_IS_PUSH(param) ((uint32_t)(param) >> 16 == 1)
2108 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
2110 #define ANV_PARAM_DYN_OFFSET(offset) ((2 << 16) | (uint32_t)(offset))
2111 #define ANV_PARAM_IS_DYN_OFFSET(param) ((uint32_t)(param) >> 16 == 2)
2112 #define ANV_PARAM_DYN_OFFSET_IDX(param) ((param) & 0xffff)
2114 struct anv_push_constants
{
2115 /* Current allocated size of this push constants data structure.
2116 * Because a decent chunk of it may not be used (images on SKL, for
2117 * instance), we won't actually allocate the entire structure up-front.
2121 /* Push constant data provided by the client through vkPushConstants */
2122 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
2124 /* Used for vkCmdDispatchBase */
2125 uint32_t base_work_group_id
[3];
2128 struct anv_dynamic_state
{
2131 VkViewport viewports
[MAX_VIEWPORTS
];
2136 VkRect2D scissors
[MAX_SCISSORS
];
2147 float blend_constants
[4];
2157 } stencil_compare_mask
;
2162 } stencil_write_mask
;
2167 } stencil_reference
;
2170 extern const struct anv_dynamic_state default_dynamic_state
;
2172 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
2173 const struct anv_dynamic_state
*src
,
2174 uint32_t copy_mask
);
2176 struct anv_surface_state
{
2177 struct anv_state state
;
2178 /** Address of the surface referred to by this state
2180 * This address is relative to the start of the BO.
2182 struct anv_address address
;
2183 /* Address of the aux surface, if any
2185 * This field is ANV_NULL_ADDRESS if and only if no aux surface exists.
2187 * With the exception of gen8, the bottom 12 bits of this address' offset
2188 * include extra aux information.
2190 struct anv_address aux_address
;
2191 /* Address of the clear color, if any
2193 * This address is relative to the start of the BO.
2195 struct anv_address clear_address
;
2199 * Attachment state when recording a renderpass instance.
2201 * The clear value is valid only if there exists a pending clear.
2203 struct anv_attachment_state
{
2204 enum isl_aux_usage aux_usage
;
2205 enum isl_aux_usage input_aux_usage
;
2206 struct anv_surface_state color
;
2207 struct anv_surface_state input
;
2209 VkImageLayout current_layout
;
2210 VkImageAspectFlags pending_clear_aspects
;
2211 VkImageAspectFlags pending_load_aspects
;
2213 VkClearValue clear_value
;
2214 bool clear_color_is_zero_one
;
2215 bool clear_color_is_zero
;
2217 /* When multiview is active, attachments with a renderpass clear
2218 * operation have their respective layers cleared on the first
2219 * subpass that uses them, and only in that subpass. We keep track
2220 * of this using a bitfield to indicate which layers of an attachment
2221 * have not been cleared yet when multiview is active.
2223 uint32_t pending_clear_views
;
2226 /** State tracking for particular pipeline bind point
2228 * This struct is the base struct for anv_cmd_graphics_state and
2229 * anv_cmd_compute_state. These are used to track state which is bound to a
2230 * particular type of pipeline. Generic state that applies per-stage such as
2231 * binding table offsets and push constants is tracked generically with a
2232 * per-stage array in anv_cmd_state.
2234 struct anv_cmd_pipeline_state
{
2235 struct anv_pipeline
*pipeline
;
2236 struct anv_pipeline_layout
*layout
;
2238 struct anv_descriptor_set
*descriptors
[MAX_SETS
];
2239 uint32_t dynamic_offsets
[MAX_DYNAMIC_BUFFERS
];
2241 struct anv_push_descriptor_set
*push_descriptors
[MAX_SETS
];
2244 /** State tracking for graphics pipeline
2246 * This has anv_cmd_pipeline_state as a base struct to track things which get
2247 * bound to a graphics pipeline. Along with general pipeline bind point state
2248 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2249 * state which is graphics-specific.
2251 struct anv_cmd_graphics_state
{
2252 struct anv_cmd_pipeline_state base
;
2254 anv_cmd_dirty_mask_t dirty
;
2257 struct anv_dynamic_state dynamic
;
2260 struct anv_buffer
*index_buffer
;
2261 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
2262 uint32_t index_offset
;
2266 /** State tracking for compute pipeline
2268 * This has anv_cmd_pipeline_state as a base struct to track things which get
2269 * bound to a compute pipeline. Along with general pipeline bind point state
2270 * which is in the anv_cmd_pipeline_state base struct, it also contains other
2271 * state which is compute-specific.
2273 struct anv_cmd_compute_state
{
2274 struct anv_cmd_pipeline_state base
;
2276 bool pipeline_dirty
;
2278 struct anv_address num_workgroups
;
2281 /** State required while building cmd buffer */
2282 struct anv_cmd_state
{
2283 /* PIPELINE_SELECT.PipelineSelection */
2284 uint32_t current_pipeline
;
2285 const struct gen_l3_config
* current_l3_config
;
2287 struct anv_cmd_graphics_state gfx
;
2288 struct anv_cmd_compute_state compute
;
2290 enum anv_pipe_bits pending_pipe_bits
;
2291 VkShaderStageFlags descriptors_dirty
;
2292 VkShaderStageFlags push_constants_dirty
;
2294 struct anv_framebuffer
* framebuffer
;
2295 struct anv_render_pass
* pass
;
2296 struct anv_subpass
* subpass
;
2297 VkRect2D render_area
;
2298 uint32_t restart_index
;
2299 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
2301 struct anv_xfb_binding xfb_bindings
[MAX_XFB_BUFFERS
];
2302 VkShaderStageFlags push_constant_stages
;
2303 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
2304 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
2305 struct anv_state samplers
[MESA_SHADER_STAGES
];
2308 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
2309 * of any command buffer it is disabled by disabling it in EndCommandBuffer
2310 * and before invoking the secondary in ExecuteCommands.
2312 bool pma_fix_enabled
;
2315 * Whether or not we know for certain that HiZ is enabled for the current
2316 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
2317 * enabled or not, this will be false.
2321 bool conditional_render_enabled
;
2324 * Array length is anv_cmd_state::pass::attachment_count. Array content is
2325 * valid only when recording a render pass instance.
2327 struct anv_attachment_state
* attachments
;
2330 * Surface states for color render targets. These are stored in a single
2331 * flat array. For depth-stencil attachments, the surface state is simply
2334 struct anv_state render_pass_states
;
2337 * A null surface state of the right size to match the framebuffer. This
2338 * is one of the states in render_pass_states.
2340 struct anv_state null_surface_state
;
2343 struct anv_cmd_pool
{
2344 VkAllocationCallbacks alloc
;
2345 struct list_head cmd_buffers
;
2348 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
2350 enum anv_cmd_buffer_exec_mode
{
2351 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
2352 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
2353 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
2354 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
2355 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
2358 struct anv_cmd_buffer
{
2359 VK_LOADER_DATA _loader_data
;
2361 struct anv_device
* device
;
2363 struct anv_cmd_pool
* pool
;
2364 struct list_head pool_link
;
2366 struct anv_batch batch
;
2368 /* Fields required for the actual chain of anv_batch_bo's.
2370 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
2372 struct list_head batch_bos
;
2373 enum anv_cmd_buffer_exec_mode exec_mode
;
2375 /* A vector of anv_batch_bo pointers for every batch or surface buffer
2376 * referenced by this command buffer
2378 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2380 struct u_vector seen_bbos
;
2382 /* A vector of int32_t's for every block of binding tables.
2384 * initialized by anv_cmd_buffer_init_batch_bo_chain()
2386 struct u_vector bt_block_states
;
2389 struct anv_reloc_list surface_relocs
;
2390 /** Last seen surface state block pool center bo offset */
2391 uint32_t last_ss_pool_center
;
2393 /* Serial for tracking buffer completion */
2396 /* Stream objects for storing temporary data */
2397 struct anv_state_stream surface_state_stream
;
2398 struct anv_state_stream dynamic_state_stream
;
2400 VkCommandBufferUsageFlags usage_flags
;
2401 VkCommandBufferLevel level
;
2403 struct anv_cmd_state state
;
2406 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2407 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2408 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
2409 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
2410 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
2411 struct anv_cmd_buffer
*secondary
);
2412 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
2413 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
2414 struct anv_cmd_buffer
*cmd_buffer
,
2415 const VkSemaphore
*in_semaphores
,
2416 uint32_t num_in_semaphores
,
2417 const VkSemaphore
*out_semaphores
,
2418 uint32_t num_out_semaphores
,
2421 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
2424 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
2425 gl_shader_stage stage
, uint32_t size
);
2426 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
2427 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
2428 (offsetof(struct anv_push_constants, field) + \
2429 sizeof(cmd_buffer->state.push_constants[0]->field)))
2431 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
2432 const void *data
, uint32_t size
, uint32_t alignment
);
2433 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
2434 uint32_t *a
, uint32_t *b
,
2435 uint32_t dwords
, uint32_t alignment
);
2438 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
2440 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2441 uint32_t entries
, uint32_t *state_offset
);
2443 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
2445 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
2446 uint32_t size
, uint32_t alignment
);
2449 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
2451 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
2452 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
2453 bool depth_clamp_enable
);
2454 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
2456 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
2457 struct anv_render_pass
*pass
,
2458 struct anv_framebuffer
*framebuffer
,
2459 const VkClearValue
*clear_values
);
2461 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
2464 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
2465 gl_shader_stage stage
);
2467 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
2469 const struct anv_image_view
*
2470 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
2473 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
2474 uint32_t num_entries
,
2475 uint32_t *state_offset
,
2476 struct anv_state
*bt_state
);
2478 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
2480 void anv_cmd_emit_conditional_render_predicate(struct anv_cmd_buffer
*cmd_buffer
);
2482 enum anv_fence_type
{
2483 ANV_FENCE_TYPE_NONE
= 0,
2485 ANV_FENCE_TYPE_SYNCOBJ
,
2489 enum anv_bo_fence_state
{
2490 /** Indicates that this is a new (or newly reset fence) */
2491 ANV_BO_FENCE_STATE_RESET
,
2493 /** Indicates that this fence has been submitted to the GPU but is still
2494 * (as far as we know) in use by the GPU.
2496 ANV_BO_FENCE_STATE_SUBMITTED
,
2498 ANV_BO_FENCE_STATE_SIGNALED
,
2501 struct anv_fence_impl
{
2502 enum anv_fence_type type
;
2505 /** Fence implementation for BO fences
2507 * These fences use a BO and a set of CPU-tracked state flags. The BO
2508 * is added to the object list of the last execbuf call in a QueueSubmit
2509 * and is marked EXEC_WRITE. The state flags track when the BO has been
2510 * submitted to the kernel. We need to do this because Vulkan lets you
2511 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2512 * will say it's idle in this case.
2516 enum anv_bo_fence_state state
;
2519 /** DRM syncobj handle for syncobj-based fences */
2523 struct wsi_fence
*fence_wsi
;
2528 /* Permanent fence state. Every fence has some form of permanent state
2529 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2530 * cross-process fences) or it could just be a dummy for use internally.
2532 struct anv_fence_impl permanent
;
2534 /* Temporary fence state. A fence *may* have temporary state. That state
2535 * is added to the fence by an import operation and is reset back to
2536 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2537 * state cannot be signaled because the fence must already be signaled
2538 * before the temporary state can be exported from the fence in the other
2539 * process and imported here.
2541 struct anv_fence_impl temporary
;
2546 struct anv_state state
;
2549 enum anv_semaphore_type
{
2550 ANV_SEMAPHORE_TYPE_NONE
= 0,
2551 ANV_SEMAPHORE_TYPE_DUMMY
,
2552 ANV_SEMAPHORE_TYPE_BO
,
2553 ANV_SEMAPHORE_TYPE_SYNC_FILE
,
2554 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ
,
2557 struct anv_semaphore_impl
{
2558 enum anv_semaphore_type type
;
2561 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
2562 * This BO will be added to the object list on any execbuf2 calls for
2563 * which this semaphore is used as a wait or signal fence. When used as
2564 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
2568 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
2569 * If the semaphore is in the unsignaled state due to either just being
2570 * created or because it has been used for a wait, fd will be -1.
2574 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
2575 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
2576 * import so we don't need to bother with a userspace cache.
2582 struct anv_semaphore
{
2583 /* Permanent semaphore state. Every semaphore has some form of permanent
2584 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
2585 * (for cross-process semaphores0 or it could just be a dummy for use
2588 struct anv_semaphore_impl permanent
;
2590 /* Temporary semaphore state. A semaphore *may* have temporary state.
2591 * That state is added to the semaphore by an import operation and is reset
2592 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
2593 * semaphore with temporary state cannot be signaled because the semaphore
2594 * must already be signaled before the temporary state can be exported from
2595 * the semaphore in the other process and imported here.
2597 struct anv_semaphore_impl temporary
;
2600 void anv_semaphore_reset_temporary(struct anv_device
*device
,
2601 struct anv_semaphore
*semaphore
);
2603 struct anv_shader_module
{
2604 unsigned char sha1
[20];
2609 static inline gl_shader_stage
2610 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
2612 assert(__builtin_popcount(vk_stage
) == 1);
2613 return ffs(vk_stage
) - 1;
2616 static inline VkShaderStageFlagBits
2617 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
2619 return (1 << mesa_stage
);
2622 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2624 #define anv_foreach_stage(stage, stage_bits) \
2625 for (gl_shader_stage stage, \
2626 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2627 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2628 __tmp &= ~(1 << (stage)))
2630 struct anv_pipeline_bind_map
{
2631 uint32_t surface_count
;
2632 uint32_t sampler_count
;
2634 struct anv_pipeline_binding
* surface_to_descriptor
;
2635 struct anv_pipeline_binding
* sampler_to_descriptor
;
2638 struct anv_shader_bin_key
{
2643 struct anv_shader_bin
{
2646 const struct anv_shader_bin_key
*key
;
2648 struct anv_state kernel
;
2649 uint32_t kernel_size
;
2651 struct anv_state constant_data
;
2652 uint32_t constant_data_size
;
2654 const struct brw_stage_prog_data
*prog_data
;
2655 uint32_t prog_data_size
;
2657 struct nir_xfb_info
*xfb_info
;
2659 struct anv_pipeline_bind_map bind_map
;
2662 struct anv_shader_bin
*
2663 anv_shader_bin_create(struct anv_device
*device
,
2664 const void *key
, uint32_t key_size
,
2665 const void *kernel
, uint32_t kernel_size
,
2666 const void *constant_data
, uint32_t constant_data_size
,
2667 const struct brw_stage_prog_data
*prog_data
,
2668 uint32_t prog_data_size
, const void *prog_data_param
,
2669 const struct nir_xfb_info
*xfb_info
,
2670 const struct anv_pipeline_bind_map
*bind_map
);
2673 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
2676 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
2678 assert(shader
&& shader
->ref_cnt
>= 1);
2679 p_atomic_inc(&shader
->ref_cnt
);
2683 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
2685 assert(shader
&& shader
->ref_cnt
>= 1);
2686 if (p_atomic_dec_zero(&shader
->ref_cnt
))
2687 anv_shader_bin_destroy(device
, shader
);
2690 struct anv_pipeline
{
2691 struct anv_device
* device
;
2692 struct anv_batch batch
;
2693 uint32_t batch_data
[512];
2694 struct anv_reloc_list batch_relocs
;
2695 uint32_t dynamic_state_mask
;
2696 struct anv_dynamic_state dynamic_state
;
2698 struct anv_subpass
* subpass
;
2700 bool needs_data_cache
;
2702 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
2705 const struct gen_l3_config
* l3_config
;
2706 uint32_t total_size
;
2707 unsigned entry_size
[4];
2710 VkShaderStageFlags active_stages
;
2711 struct anv_state blend_state
;
2714 struct anv_pipeline_vertex_binding
{
2717 uint32_t instance_divisor
;
2722 bool primitive_restart
;
2725 uint32_t cs_right_mask
;
2728 bool depth_test_enable
;
2729 bool writes_stencil
;
2730 bool stencil_test_enable
;
2731 bool depth_clamp_enable
;
2732 bool depth_clip_enable
;
2733 bool sample_shading_enable
;
2738 uint32_t depth_stencil_state
[3];
2744 uint32_t wm_depth_stencil
[3];
2748 uint32_t wm_depth_stencil
[4];
2751 uint32_t interface_descriptor_data
[8];
2755 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
2756 gl_shader_stage stage
)
2758 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
2761 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2762 static inline const struct brw_##prefix##_prog_data * \
2763 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2765 if (anv_pipeline_has_stage(pipeline, stage)) { \
2766 return (const struct brw_##prefix##_prog_data *) \
2767 pipeline->shaders[stage]->prog_data; \
2773 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
2774 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
2775 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
2776 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
2777 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
2778 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
2780 static inline const struct brw_vue_prog_data
*
2781 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
2783 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
2784 return &get_gs_prog_data(pipeline
)->base
;
2785 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
2786 return &get_tes_prog_data(pipeline
)->base
;
2788 return &get_vs_prog_data(pipeline
)->base
;
2792 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
2793 struct anv_pipeline_cache
*cache
,
2794 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2795 const VkAllocationCallbacks
*alloc
);
2798 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
2799 struct anv_pipeline_cache
*cache
,
2800 const VkComputePipelineCreateInfo
*info
,
2801 const struct anv_shader_module
*module
,
2802 const char *entrypoint
,
2803 const VkSpecializationInfo
*spec_info
);
2805 struct anv_format_plane
{
2806 enum isl_format isl_format
:16;
2807 struct isl_swizzle swizzle
;
2809 /* Whether this plane contains chroma channels */
2812 /* For downscaling of YUV planes */
2813 uint8_t denominator_scales
[2];
2815 /* How to map sampled ycbcr planes to a single 4 component element. */
2816 struct isl_swizzle ycbcr_swizzle
;
2818 /* What aspect is associated to this plane */
2819 VkImageAspectFlags aspect
;
2824 struct anv_format_plane planes
[3];
2830 static inline uint32_t
2831 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects
,
2832 VkImageAspectFlags aspect_mask
)
2834 switch (aspect_mask
) {
2835 case VK_IMAGE_ASPECT_COLOR_BIT
:
2836 case VK_IMAGE_ASPECT_DEPTH_BIT
:
2837 case VK_IMAGE_ASPECT_PLANE_0_BIT
:
2839 case VK_IMAGE_ASPECT_STENCIL_BIT
:
2840 if ((image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) == 0)
2843 case VK_IMAGE_ASPECT_PLANE_1_BIT
:
2845 case VK_IMAGE_ASPECT_PLANE_2_BIT
:
2848 /* Purposefully assert with depth/stencil aspects. */
2849 unreachable("invalid image aspect");
2853 static inline VkImageAspectFlags
2854 anv_plane_to_aspect(VkImageAspectFlags image_aspects
,
2857 if (image_aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
2858 if (util_bitcount(image_aspects
) > 1)
2859 return VK_IMAGE_ASPECT_PLANE_0_BIT
<< plane
;
2860 return VK_IMAGE_ASPECT_COLOR_BIT
;
2862 if (image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)
2863 return VK_IMAGE_ASPECT_DEPTH_BIT
<< plane
;
2864 assert(image_aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
2865 return VK_IMAGE_ASPECT_STENCIL_BIT
;
2868 #define anv_foreach_image_aspect_bit(b, image, aspects) \
2869 for_each_bit(b, anv_image_expand_aspects(image, aspects))
2871 const struct anv_format
*
2872 anv_get_format(VkFormat format
);
2874 static inline uint32_t
2875 anv_get_format_planes(VkFormat vk_format
)
2877 const struct anv_format
*format
= anv_get_format(vk_format
);
2879 return format
!= NULL
? format
->n_planes
: 0;
2882 struct anv_format_plane
2883 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2884 VkImageAspectFlagBits aspect
, VkImageTiling tiling
);
2886 static inline enum isl_format
2887 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2888 VkImageAspectFlags aspect
, VkImageTiling tiling
)
2890 return anv_get_format_plane(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
2893 static inline struct isl_swizzle
2894 anv_swizzle_for_render(struct isl_swizzle swizzle
)
2896 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2897 * RGB as RGBA for texturing
2899 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
2900 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
2902 /* But it doesn't matter what we render to that channel */
2903 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
2909 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
2912 * Subsurface of an anv_image.
2914 struct anv_surface
{
2915 /** Valid only if isl_surf::size_B > 0. */
2916 struct isl_surf isl
;
2919 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2925 VkImageType type
; /**< VkImageCreateInfo::imageType */
2926 /* The original VkFormat provided by the client. This may not match any
2927 * of the actual surface formats.
2930 const struct anv_format
*format
;
2932 VkImageAspectFlags aspects
;
2935 uint32_t array_size
;
2936 uint32_t samples
; /**< VkImageCreateInfo::samples */
2938 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
2939 VkImageCreateFlags create_flags
; /* Flags used when creating image. */
2940 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
2942 /** True if this is needs to be bound to an appropriately tiled BO.
2944 * When not using modifiers, consumers such as X11, Wayland, and KMS need
2945 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
2946 * we require a dedicated allocation so that we can know to allocate a
2949 bool needs_set_tiling
;
2952 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
2953 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
2955 uint64_t drm_format_mod
;
2960 /* Whether the image is made of several underlying buffer objects rather a
2961 * single one with different offsets.
2965 /* All the formats that can be used when creating views of this image
2966 * are CCS_E compatible.
2968 bool ccs_e_compatible
;
2970 /* Image was created with external format. */
2971 bool external_format
;
2976 * For each foo, anv_image::planes[x].surface is valid if and only if
2977 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
2978 * to figure the number associated with a given aspect.
2980 * The hardware requires that the depth buffer and stencil buffer be
2981 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2982 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2983 * allocate the depth and stencil buffers as separate surfaces in the same
2988 * -----------------------
2990 * ----------------------- |
2991 * | shadow surface0 | |
2992 * ----------------------- | Plane 0
2993 * | aux surface0 | |
2994 * ----------------------- |
2995 * | fast clear colors0 | \|/
2996 * -----------------------
2998 * ----------------------- |
2999 * | shadow surface1 | |
3000 * ----------------------- | Plane 1
3001 * | aux surface1 | |
3002 * ----------------------- |
3003 * | fast clear colors1 | \|/
3004 * -----------------------
3007 * -----------------------
3011 * Offset of the entire plane (whenever the image is disjoint this is
3019 struct anv_surface surface
;
3022 * A surface which shadows the main surface and may have different
3023 * tiling. This is used for sampling using a tiling that isn't supported
3024 * for other operations.
3026 struct anv_surface shadow_surface
;
3029 * For color images, this is the aux usage for this image when not used
3030 * as a color attachment.
3032 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
3033 * image has a HiZ buffer.
3035 enum isl_aux_usage aux_usage
;
3037 struct anv_surface aux_surface
;
3040 * Offset of the fast clear state (used to compute the
3041 * fast_clear_state_offset of the following planes).
3043 uint32_t fast_clear_state_offset
;
3046 * BO associated with this plane, set when bound.
3048 struct anv_address address
;
3051 * When destroying the image, also free the bo.
3057 /* The ordering of this enum is important */
3058 enum anv_fast_clear_type
{
3059 /** Image does not have/support any fast-clear blocks */
3060 ANV_FAST_CLEAR_NONE
= 0,
3061 /** Image has/supports fast-clear but only to the default value */
3062 ANV_FAST_CLEAR_DEFAULT_VALUE
= 1,
3063 /** Image has/supports fast-clear with an arbitrary fast-clear value */
3064 ANV_FAST_CLEAR_ANY
= 2,
3067 /* Returns the number of auxiliary buffer levels attached to an image. */
3068 static inline uint8_t
3069 anv_image_aux_levels(const struct anv_image
* const image
,
3070 VkImageAspectFlagBits aspect
)
3072 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3073 return image
->planes
[plane
].aux_surface
.isl
.size_B
> 0 ?
3074 image
->planes
[plane
].aux_surface
.isl
.levels
: 0;
3077 /* Returns the number of auxiliary buffer layers attached to an image. */
3078 static inline uint32_t
3079 anv_image_aux_layers(const struct anv_image
* const image
,
3080 VkImageAspectFlagBits aspect
,
3081 const uint8_t miplevel
)
3085 /* The miplevel must exist in the main buffer. */
3086 assert(miplevel
< image
->levels
);
3088 if (miplevel
>= anv_image_aux_levels(image
, aspect
)) {
3089 /* There are no layers with auxiliary data because the miplevel has no
3094 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3095 return MAX2(image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.array_len
,
3096 image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.depth
>> miplevel
);
3100 static inline struct anv_address
3101 anv_image_get_clear_color_addr(const struct anv_device
*device
,
3102 const struct anv_image
*image
,
3103 VkImageAspectFlagBits aspect
)
3105 assert(image
->aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
3107 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3108 return anv_address_add(image
->planes
[plane
].address
,
3109 image
->planes
[plane
].fast_clear_state_offset
);
3112 static inline struct anv_address
3113 anv_image_get_fast_clear_type_addr(const struct anv_device
*device
,
3114 const struct anv_image
*image
,
3115 VkImageAspectFlagBits aspect
)
3117 struct anv_address addr
=
3118 anv_image_get_clear_color_addr(device
, image
, aspect
);
3120 const unsigned clear_color_state_size
= device
->info
.gen
>= 10 ?
3121 device
->isl_dev
.ss
.clear_color_state_size
:
3122 device
->isl_dev
.ss
.clear_value_size
;
3123 return anv_address_add(addr
, clear_color_state_size
);
3126 static inline struct anv_address
3127 anv_image_get_compression_state_addr(const struct anv_device
*device
,
3128 const struct anv_image
*image
,
3129 VkImageAspectFlagBits aspect
,
3130 uint32_t level
, uint32_t array_layer
)
3132 assert(level
< anv_image_aux_levels(image
, aspect
));
3133 assert(array_layer
< anv_image_aux_layers(image
, aspect
, level
));
3134 UNUSED
uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
3135 assert(image
->planes
[plane
].aux_usage
== ISL_AUX_USAGE_CCS_E
);
3137 struct anv_address addr
=
3138 anv_image_get_fast_clear_type_addr(device
, image
, aspect
);
3139 addr
.offset
+= 4; /* Go past the fast clear type */
3141 if (image
->type
== VK_IMAGE_TYPE_3D
) {
3142 for (uint32_t l
= 0; l
< level
; l
++)
3143 addr
.offset
+= anv_minify(image
->extent
.depth
, l
) * 4;
3145 addr
.offset
+= level
* image
->array_size
* 4;
3147 addr
.offset
+= array_layer
* 4;
3152 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
3154 anv_can_sample_with_hiz(const struct gen_device_info
* const devinfo
,
3155 const struct anv_image
*image
)
3157 if (!(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
))
3160 if (devinfo
->gen
< 8)
3163 return image
->samples
== 1;
3167 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer
*cmd_buffer
,
3168 const struct anv_image
*image
,
3169 VkImageAspectFlagBits aspect
,
3170 enum isl_aux_usage aux_usage
,
3172 uint32_t base_layer
,
3173 uint32_t layer_count
);
3176 anv_image_clear_color(struct anv_cmd_buffer
*cmd_buffer
,
3177 const struct anv_image
*image
,
3178 VkImageAspectFlagBits aspect
,
3179 enum isl_aux_usage aux_usage
,
3180 enum isl_format format
, struct isl_swizzle swizzle
,
3181 uint32_t level
, uint32_t base_layer
, uint32_t layer_count
,
3182 VkRect2D area
, union isl_color_value clear_color
);
3184 anv_image_clear_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
3185 const struct anv_image
*image
,
3186 VkImageAspectFlags aspects
,
3187 enum isl_aux_usage depth_aux_usage
,
3189 uint32_t base_layer
, uint32_t layer_count
,
3191 float depth_value
, uint8_t stencil_value
);
3193 anv_image_msaa_resolve(struct anv_cmd_buffer
*cmd_buffer
,
3194 const struct anv_image
*src_image
,
3195 enum isl_aux_usage src_aux_usage
,
3196 uint32_t src_level
, uint32_t src_base_layer
,
3197 const struct anv_image
*dst_image
,
3198 enum isl_aux_usage dst_aux_usage
,
3199 uint32_t dst_level
, uint32_t dst_base_layer
,
3200 VkImageAspectFlagBits aspect
,
3201 uint32_t src_x
, uint32_t src_y
,
3202 uint32_t dst_x
, uint32_t dst_y
,
3203 uint32_t width
, uint32_t height
,
3204 uint32_t layer_count
,
3205 enum blorp_filter filter
);
3207 anv_image_hiz_op(struct anv_cmd_buffer
*cmd_buffer
,
3208 const struct anv_image
*image
,
3209 VkImageAspectFlagBits aspect
, uint32_t level
,
3210 uint32_t base_layer
, uint32_t layer_count
,
3211 enum isl_aux_op hiz_op
);
3213 anv_image_hiz_clear(struct anv_cmd_buffer
*cmd_buffer
,
3214 const struct anv_image
*image
,
3215 VkImageAspectFlags aspects
,
3217 uint32_t base_layer
, uint32_t layer_count
,
3218 VkRect2D area
, uint8_t stencil_value
);
3220 anv_image_mcs_op(struct anv_cmd_buffer
*cmd_buffer
,
3221 const struct anv_image
*image
,
3222 enum isl_format format
,
3223 VkImageAspectFlagBits aspect
,
3224 uint32_t base_layer
, uint32_t layer_count
,
3225 enum isl_aux_op mcs_op
, union isl_color_value
*clear_value
,
3228 anv_image_ccs_op(struct anv_cmd_buffer
*cmd_buffer
,
3229 const struct anv_image
*image
,
3230 enum isl_format format
,
3231 VkImageAspectFlagBits aspect
, uint32_t level
,
3232 uint32_t base_layer
, uint32_t layer_count
,
3233 enum isl_aux_op ccs_op
, union isl_color_value
*clear_value
,
3237 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
3238 const struct anv_image
*image
,
3239 uint32_t base_level
, uint32_t level_count
,
3240 uint32_t base_layer
, uint32_t layer_count
);
3243 anv_layout_to_aux_usage(const struct gen_device_info
* const devinfo
,
3244 const struct anv_image
*image
,
3245 const VkImageAspectFlagBits aspect
,
3246 const VkImageLayout layout
);
3248 enum anv_fast_clear_type
3249 anv_layout_to_fast_clear_type(const struct gen_device_info
* const devinfo
,
3250 const struct anv_image
* const image
,
3251 const VkImageAspectFlagBits aspect
,
3252 const VkImageLayout layout
);
3254 /* This is defined as a macro so that it works for both
3255 * VkImageSubresourceRange and VkImageSubresourceLayers
3257 #define anv_get_layerCount(_image, _range) \
3258 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
3259 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
3261 static inline uint32_t
3262 anv_get_levelCount(const struct anv_image
*image
,
3263 const VkImageSubresourceRange
*range
)
3265 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
3266 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
3269 static inline VkImageAspectFlags
3270 anv_image_expand_aspects(const struct anv_image
*image
,
3271 VkImageAspectFlags aspects
)
3273 /* If the underlying image has color plane aspects and
3274 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
3275 * the underlying image. */
3276 if ((image
->aspects
& VK_IMAGE_ASPECT_PLANES_BITS_ANV
) != 0 &&
3277 aspects
== VK_IMAGE_ASPECT_COLOR_BIT
)
3278 return image
->aspects
;
3284 anv_image_aspects_compatible(VkImageAspectFlags aspects1
,
3285 VkImageAspectFlags aspects2
)
3287 if (aspects1
== aspects2
)
3290 /* Only 1 color aspects are compatibles. */
3291 if ((aspects1
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
3292 (aspects2
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
3293 util_bitcount(aspects1
) == util_bitcount(aspects2
))
3299 struct anv_image_view
{
3300 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
3302 VkImageAspectFlags aspect_mask
;
3304 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
3308 uint32_t image_plane
;
3310 struct isl_view isl
;
3313 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3314 * image layout of SHADER_READ_ONLY_OPTIMAL or
3315 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
3317 struct anv_surface_state optimal_sampler_surface_state
;
3320 * RENDER_SURFACE_STATE when using image as a sampler surface with an
3321 * image layout of GENERAL.
3323 struct anv_surface_state general_sampler_surface_state
;
3326 * RENDER_SURFACE_STATE when using image as a storage image. Separate
3327 * states for write-only and readable, using the real format for
3328 * write-only and the lowered format for readable.
3330 struct anv_surface_state storage_surface_state
;
3331 struct anv_surface_state writeonly_storage_surface_state
;
3333 struct brw_image_param storage_image_param
;
3337 enum anv_image_view_state_flags
{
3338 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY
= (1 << 0),
3339 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL
= (1 << 1),
3342 void anv_image_fill_surface_state(struct anv_device
*device
,
3343 const struct anv_image
*image
,
3344 VkImageAspectFlagBits aspect
,
3345 const struct isl_view
*view
,
3346 isl_surf_usage_flags_t view_usage
,
3347 enum isl_aux_usage aux_usage
,
3348 const union isl_color_value
*clear_color
,
3349 enum anv_image_view_state_flags flags
,
3350 struct anv_surface_state
*state_inout
,
3351 struct brw_image_param
*image_param_out
);
3353 struct anv_image_create_info
{
3354 const VkImageCreateInfo
*vk_info
;
3356 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
3357 isl_tiling_flags_t isl_tiling_flags
;
3359 /** These flags will be added to any derived from VkImageCreateInfo. */
3360 isl_surf_usage_flags_t isl_extra_usage_flags
;
3363 bool external_format
;
3366 VkResult
anv_image_create(VkDevice _device
,
3367 const struct anv_image_create_info
*info
,
3368 const VkAllocationCallbacks
* alloc
,
3371 const struct anv_surface
*
3372 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
3373 VkImageAspectFlags aspect_mask
);
3376 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
3378 static inline struct VkExtent3D
3379 anv_sanitize_image_extent(const VkImageType imageType
,
3380 const struct VkExtent3D imageExtent
)
3382 switch (imageType
) {
3383 case VK_IMAGE_TYPE_1D
:
3384 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
3385 case VK_IMAGE_TYPE_2D
:
3386 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
3387 case VK_IMAGE_TYPE_3D
:
3390 unreachable("invalid image type");
3394 static inline struct VkOffset3D
3395 anv_sanitize_image_offset(const VkImageType imageType
,
3396 const struct VkOffset3D imageOffset
)
3398 switch (imageType
) {
3399 case VK_IMAGE_TYPE_1D
:
3400 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
3401 case VK_IMAGE_TYPE_2D
:
3402 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
3403 case VK_IMAGE_TYPE_3D
:
3406 unreachable("invalid image type");
3410 VkFormatFeatureFlags
3411 anv_get_image_format_features(const struct gen_device_info
*devinfo
,
3413 const struct anv_format
*anv_format
,
3414 VkImageTiling vk_tiling
);
3416 void anv_fill_buffer_surface_state(struct anv_device
*device
,
3417 struct anv_state state
,
3418 enum isl_format format
,
3419 struct anv_address address
,
3420 uint32_t range
, uint32_t stride
);
3423 anv_clear_color_from_att_state(union isl_color_value
*clear_color
,
3424 const struct anv_attachment_state
*att_state
,
3425 const struct anv_image_view
*iview
)
3427 const struct isl_format_layout
*view_fmtl
=
3428 isl_format_get_layout(iview
->planes
[0].isl
.format
);
3430 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
3431 if (view_fmtl->channels.c.bits) \
3432 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
3434 COPY_CLEAR_COLOR_CHANNEL(r
, 0);
3435 COPY_CLEAR_COLOR_CHANNEL(g
, 1);
3436 COPY_CLEAR_COLOR_CHANNEL(b
, 2);
3437 COPY_CLEAR_COLOR_CHANNEL(a
, 3);
3439 #undef COPY_CLEAR_COLOR_CHANNEL
3443 struct anv_ycbcr_conversion
{
3444 const struct anv_format
* format
;
3445 VkSamplerYcbcrModelConversion ycbcr_model
;
3446 VkSamplerYcbcrRange ycbcr_range
;
3447 VkComponentSwizzle mapping
[4];
3448 VkChromaLocation chroma_offsets
[2];
3449 VkFilter chroma_filter
;
3450 bool chroma_reconstruction
;
3453 struct anv_sampler
{
3454 uint32_t state
[3][4];
3456 struct anv_ycbcr_conversion
*conversion
;
3459 struct anv_framebuffer
{
3464 uint32_t attachment_count
;
3465 struct anv_image_view
* attachments
[0];
3468 struct anv_subpass_attachment
{
3469 VkImageUsageFlagBits usage
;
3470 uint32_t attachment
;
3471 VkImageLayout layout
;
3474 struct anv_subpass
{
3475 uint32_t attachment_count
;
3478 * A pointer to all attachment references used in this subpass.
3479 * Only valid if ::attachment_count > 0.
3481 struct anv_subpass_attachment
* attachments
;
3482 uint32_t input_count
;
3483 struct anv_subpass_attachment
* input_attachments
;
3484 uint32_t color_count
;
3485 struct anv_subpass_attachment
* color_attachments
;
3486 struct anv_subpass_attachment
* resolve_attachments
;
3488 struct anv_subpass_attachment
* depth_stencil_attachment
;
3489 struct anv_subpass_attachment
* ds_resolve_attachment
;
3490 VkResolveModeFlagBitsKHR depth_resolve_mode
;
3491 VkResolveModeFlagBitsKHR stencil_resolve_mode
;
3495 /** Subpass has a depth/stencil self-dependency */
3496 bool has_ds_self_dep
;
3498 /** Subpass has at least one color resolve attachment */
3499 bool has_color_resolve
;
3502 static inline unsigned
3503 anv_subpass_view_count(const struct anv_subpass
*subpass
)
3505 return MAX2(1, util_bitcount(subpass
->view_mask
));
3508 struct anv_render_pass_attachment
{
3509 /* TODO: Consider using VkAttachmentDescription instead of storing each of
3510 * its members individually.
3514 VkImageUsageFlags usage
;
3515 VkAttachmentLoadOp load_op
;
3516 VkAttachmentStoreOp store_op
;
3517 VkAttachmentLoadOp stencil_load_op
;
3518 VkImageLayout initial_layout
;
3519 VkImageLayout final_layout
;
3520 VkImageLayout first_subpass_layout
;
3522 /* The subpass id in which the attachment will be used last. */
3523 uint32_t last_subpass_idx
;
3526 struct anv_render_pass
{
3527 uint32_t attachment_count
;
3528 uint32_t subpass_count
;
3529 /* An array of subpass_count+1 flushes, one per subpass boundary */
3530 enum anv_pipe_bits
* subpass_flushes
;
3531 struct anv_render_pass_attachment
* attachments
;
3532 struct anv_subpass subpasses
[0];
3535 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
3537 struct anv_query_pool
{
3539 VkQueryPipelineStatisticFlags pipeline_statistics
;
3540 /** Stride between slots, in bytes */
3542 /** Number of slots in this query pool */
3547 int anv_get_instance_entrypoint_index(const char *name
);
3548 int anv_get_device_entrypoint_index(const char *name
);
3551 anv_instance_entrypoint_is_enabled(int index
, uint32_t core_version
,
3552 const struct anv_instance_extension_table
*instance
);
3555 anv_device_entrypoint_is_enabled(int index
, uint32_t core_version
,
3556 const struct anv_instance_extension_table
*instance
,
3557 const struct anv_device_extension_table
*device
);
3559 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
3562 void anv_dump_image_to_ppm(struct anv_device
*device
,
3563 struct anv_image
*image
, unsigned miplevel
,
3564 unsigned array_layer
, VkImageAspectFlagBits aspect
,
3565 const char *filename
);
3567 enum anv_dump_action
{
3568 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
3571 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
3572 void anv_dump_finish(void);
3574 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
3575 struct anv_framebuffer
*fb
);
3577 static inline uint32_t
3578 anv_get_subpass_id(const struct anv_cmd_state
* const cmd_state
)
3580 /* This function must be called from within a subpass. */
3581 assert(cmd_state
->pass
&& cmd_state
->subpass
);
3583 const uint32_t subpass_id
= cmd_state
->subpass
- cmd_state
->pass
->subpasses
;
3585 /* The id of this subpass shouldn't exceed the number of subpasses in this
3586 * render pass minus 1.
3588 assert(subpass_id
< cmd_state
->pass
->subpass_count
);
3592 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
3594 static inline struct __anv_type * \
3595 __anv_type ## _from_handle(__VkType _handle) \
3597 return (struct __anv_type *) _handle; \
3600 static inline __VkType \
3601 __anv_type ## _to_handle(struct __anv_type *_obj) \
3603 return (__VkType) _obj; \
3606 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
3608 static inline struct __anv_type * \
3609 __anv_type ## _from_handle(__VkType _handle) \
3611 return (struct __anv_type *)(uintptr_t) _handle; \
3614 static inline __VkType \
3615 __anv_type ## _to_handle(struct __anv_type *_obj) \
3617 return (__VkType)(uintptr_t) _obj; \
3620 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
3621 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
3623 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
3624 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
3625 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
3626 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
3627 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
3629 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
3630 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
3631 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
3632 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
3633 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
3634 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
3635 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template
, VkDescriptorUpdateTemplate
)
3636 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
3637 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
3638 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
3639 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
3640 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
3641 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
3642 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
3643 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
3644 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
3645 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
3646 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
3647 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
3648 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore
, VkSemaphore
)
3649 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
3650 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback
, VkDebugReportCallbackEXT
)
3651 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion
, VkSamplerYcbcrConversion
)
3653 /* Gen-specific function declarations */
3655 # include "anv_genX.h"
3657 # define genX(x) gen7_##x
3658 # include "anv_genX.h"
3660 # define genX(x) gen75_##x
3661 # include "anv_genX.h"
3663 # define genX(x) gen8_##x
3664 # include "anv_genX.h"
3666 # define genX(x) gen9_##x
3667 # include "anv_genX.h"
3669 # define genX(x) gen10_##x
3670 # include "anv_genX.h"
3672 # define genX(x) gen11_##x
3673 # include "anv_genX.h"
3677 #endif /* ANV_PRIVATE_H */