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
39 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
44 #include "common/gen_clflush.h"
45 #include "common/gen_gem.h"
46 #include "dev/gen_device_info.h"
47 #include "blorp/blorp.h"
48 #include "compiler/brw_compiler.h"
49 #include "util/macros.h"
50 #include "util/list.h"
51 #include "util/u_atomic.h"
52 #include "util/u_vector.h"
54 #include "vk_debug_report.h"
56 /* Pre-declarations needed for WSI entrypoints */
59 typedef struct xcb_connection_t xcb_connection_t
;
60 typedef uint32_t xcb_visualid_t
;
61 typedef uint32_t xcb_window_t
;
64 struct anv_buffer_view
;
65 struct anv_image_view
;
70 #include <vulkan/vulkan.h>
71 #include <vulkan/vulkan_intel.h>
72 #include <vulkan/vk_icd.h>
73 #include <vulkan/vk_android_native_buffer.h>
75 #include "anv_entrypoints.h"
76 #include "anv_extensions.h"
79 #include "common/gen_debug.h"
80 #include "common/intel_log.h"
81 #include "wsi_common.h"
83 /* Allowing different clear colors requires us to perform a depth resolve at
84 * the end of certain render passes. This is because while slow clears store
85 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
86 * See the PRMs for examples describing when additional resolves would be
87 * necessary. To enable fast clears without requiring extra resolves, we set
88 * the clear value to a globally-defined one. We could allow different values
89 * if the user doesn't expect coherent data during or after a render passes
90 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
91 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
92 * 1.0f seems to be the only value used. The only application that doesn't set
93 * this value does so through the usage of an seemingly uninitialized clear
96 #define ANV_HZ_FC_VAL 1.0f
101 #define MAX_VIEWPORTS 16
102 #define MAX_SCISSORS 16
103 #define MAX_PUSH_CONSTANTS_SIZE 128
104 #define MAX_DYNAMIC_BUFFERS 16
106 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
108 /* The kernel relocation API has a limitation of a 32-bit delta value
109 * applied to the address before it is written which, in spite of it being
110 * unsigned, is treated as signed . Because of the way that this maps to
111 * the Vulkan API, we cannot handle an offset into a buffer that does not
112 * fit into a signed 32 bits. The only mechanism we have for dealing with
113 * this at the moment is to limit all VkDeviceMemory objects to a maximum
114 * of 2GB each. The Vulkan spec allows us to do this:
116 * "Some platforms may have a limit on the maximum size of a single
117 * allocation. For example, certain systems may fail to create
118 * allocations with a size greater than or equal to 4GB. Such a limit is
119 * implementation-dependent, and if such a failure occurs then the error
120 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
122 * We don't use vk_error here because it's not an error so much as an
123 * indication to the application that the allocation is too large.
125 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
127 #define ANV_SVGS_VB_INDEX MAX_VBS
128 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
130 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
132 static inline uint32_t
133 align_down_npot_u32(uint32_t v
, uint32_t a
)
138 static inline uint32_t
139 align_u32(uint32_t v
, uint32_t a
)
141 assert(a
!= 0 && a
== (a
& -a
));
142 return (v
+ a
- 1) & ~(a
- 1);
145 static inline uint64_t
146 align_u64(uint64_t v
, uint64_t a
)
148 assert(a
!= 0 && a
== (a
& -a
));
149 return (v
+ a
- 1) & ~(a
- 1);
152 static inline int32_t
153 align_i32(int32_t v
, int32_t a
)
155 assert(a
!= 0 && a
== (a
& -a
));
156 return (v
+ a
- 1) & ~(a
- 1);
159 /** Alignment must be a power of 2. */
161 anv_is_aligned(uintmax_t n
, uintmax_t a
)
163 assert(a
== (a
& -a
));
164 return (n
& (a
- 1)) == 0;
167 static inline uint32_t
168 anv_minify(uint32_t n
, uint32_t levels
)
170 if (unlikely(n
== 0))
173 return MAX2(n
>> levels
, 1);
177 anv_clamp_f(float f
, float min
, float max
)
190 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
192 if (*inout_mask
& clear_mask
) {
193 *inout_mask
&= ~clear_mask
;
200 static inline union isl_color_value
201 vk_to_isl_color(VkClearColorValue color
)
203 return (union isl_color_value
) {
213 #define for_each_bit(b, dword) \
214 for (uint32_t __dword = (dword); \
215 (b) = __builtin_ffs(__dword) - 1, __dword; \
216 __dword &= ~(1 << (b)))
218 #define typed_memcpy(dest, src, count) ({ \
219 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
220 memcpy((dest), (src), (count) * sizeof(*(src))); \
223 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
224 * to be added here in order to utilize mapping in debug/error/perf macros.
226 #define REPORT_OBJECT_TYPE(o) \
227 __builtin_choose_expr ( \
228 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
229 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
230 __builtin_choose_expr ( \
231 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
232 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
233 __builtin_choose_expr ( \
234 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
235 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
236 __builtin_choose_expr ( \
237 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
238 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
239 __builtin_choose_expr ( \
240 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
241 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
242 __builtin_choose_expr ( \
243 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
244 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
245 __builtin_choose_expr ( \
246 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
247 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
248 __builtin_choose_expr ( \
249 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
250 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
251 __builtin_choose_expr ( \
252 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
253 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
254 __builtin_choose_expr ( \
255 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
256 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
257 __builtin_choose_expr ( \
258 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
259 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
260 __builtin_choose_expr ( \
261 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
262 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
263 __builtin_choose_expr ( \
264 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
265 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
266 __builtin_choose_expr ( \
267 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
268 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
269 __builtin_choose_expr ( \
270 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
271 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
272 __builtin_choose_expr ( \
273 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
274 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
275 __builtin_choose_expr ( \
276 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
277 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
278 __builtin_choose_expr ( \
279 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
280 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
281 __builtin_choose_expr ( \
282 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
283 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
284 __builtin_choose_expr ( \
285 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
286 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
287 __builtin_choose_expr ( \
288 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
289 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
290 __builtin_choose_expr ( \
291 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
292 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
293 __builtin_choose_expr ( \
294 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
295 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
296 __builtin_choose_expr ( \
297 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
298 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
299 __builtin_choose_expr ( \
300 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
301 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
302 __builtin_choose_expr ( \
303 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
304 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
305 __builtin_choose_expr ( \
306 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
307 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
308 __builtin_choose_expr ( \
309 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
310 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
311 __builtin_choose_expr ( \
312 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
313 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
314 __builtin_choose_expr ( \
315 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
316 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
317 __builtin_choose_expr ( \
318 __builtin_types_compatible_p (__typeof (o), void*), \
319 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
320 /* The void expression results in a compile-time error \
321 when assigning the result to something. */ \
322 (void)0)))))))))))))))))))))))))))))))
324 /* Whenever we generate an error, pass it through this function. Useful for
325 * debugging, where we can break on it. Only call at error site, not when
326 * propagating errors. Might be useful to plug in a stack trace here.
329 VkResult
__vk_errorf(struct anv_instance
*instance
, const void *object
,
330 VkDebugReportObjectTypeEXT type
, VkResult error
,
331 const char *file
, int line
, const char *format
, ...);
334 #define vk_error(error) __vk_errorf(NULL, NULL,\
335 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
336 error, __FILE__, __LINE__, NULL)
337 #define vk_errorf(instance, obj, error, format, ...)\
338 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
339 __FILE__, __LINE__, format, ## __VA_ARGS__)
341 #define vk_error(error) error
342 #define vk_errorf(instance, obj, error, format, ...) error
346 * Warn on ignored extension structs.
348 * The Vulkan spec requires us to ignore unsupported or unknown structs in
349 * a pNext chain. In debug mode, emitting warnings for ignored structs may
350 * help us discover structs that we should not have ignored.
353 * From the Vulkan 1.0.38 spec:
355 * Any component of the implementation (the loader, any enabled layers,
356 * and drivers) must skip over, without processing (other than reading the
357 * sType and pNext members) any chained structures with sType values not
358 * defined by extensions supported by that component.
360 #define anv_debug_ignored_stype(sType) \
361 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
363 void __anv_perf_warn(struct anv_instance
*instance
, const void *object
,
364 VkDebugReportObjectTypeEXT type
, const char *file
,
365 int line
, const char *format
, ...)
366 anv_printflike(6, 7);
367 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
368 void anv_loge_v(const char *format
, va_list va
);
371 * Print a FINISHME message, including its source location.
373 #define anv_finishme(format, ...) \
375 static bool reported = false; \
377 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
384 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
386 #define anv_perf_warn(instance, obj, format, ...) \
388 static bool reported = false; \
389 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
390 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
391 format, ##__VA_ARGS__); \
396 /* A non-fatal assert. Useful for debugging. */
398 #define anv_assert(x) ({ \
399 if (unlikely(!(x))) \
400 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
403 #define anv_assert(x)
406 /* A multi-pointer allocator
408 * When copying data structures from the user (such as a render pass), it's
409 * common to need to allocate data for a bunch of different things. Instead
410 * of doing several allocations and having to handle all of the error checking
411 * that entails, it can be easier to do a single allocation. This struct
412 * helps facilitate that. The intended usage looks like this:
415 * anv_multialloc_add(&ma, &main_ptr, 1);
416 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
417 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
419 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
420 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
422 struct anv_multialloc
{
430 #define ANV_MULTIALLOC_INIT \
431 ((struct anv_multialloc) { 0, })
433 #define ANV_MULTIALLOC(_name) \
434 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
436 __attribute__((always_inline
))
438 _anv_multialloc_add(struct anv_multialloc
*ma
,
439 void **ptr
, size_t size
, size_t align
)
441 size_t offset
= align_u64(ma
->size
, align
);
442 ma
->size
= offset
+ size
;
443 ma
->align
= MAX2(ma
->align
, align
);
445 /* Store the offset in the pointer. */
446 *ptr
= (void *)(uintptr_t)offset
;
448 assert(ma
->ptr_count
< ARRAY_SIZE(ma
->ptrs
));
449 ma
->ptrs
[ma
->ptr_count
++] = ptr
;
452 #define anv_multialloc_add_size(_ma, _ptr, _size) \
453 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
455 #define anv_multialloc_add(_ma, _ptr, _count) \
456 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
458 __attribute__((always_inline
))
460 anv_multialloc_alloc(struct anv_multialloc
*ma
,
461 const VkAllocationCallbacks
*alloc
,
462 VkSystemAllocationScope scope
)
464 void *ptr
= vk_alloc(alloc
, ma
->size
, ma
->align
, scope
);
468 /* Fill out each of the pointers with their final value.
470 * for (uint32_t i = 0; i < ma->ptr_count; i++)
471 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
473 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
474 * constant, GCC is incapable of figuring this out and unrolling the loop
475 * so we have to give it a little help.
477 STATIC_ASSERT(ARRAY_SIZE(ma
->ptrs
) == 8);
478 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
479 if ((_i) < ma->ptr_count) \
480 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
481 _ANV_MULTIALLOC_UPDATE_POINTER(0);
482 _ANV_MULTIALLOC_UPDATE_POINTER(1);
483 _ANV_MULTIALLOC_UPDATE_POINTER(2);
484 _ANV_MULTIALLOC_UPDATE_POINTER(3);
485 _ANV_MULTIALLOC_UPDATE_POINTER(4);
486 _ANV_MULTIALLOC_UPDATE_POINTER(5);
487 _ANV_MULTIALLOC_UPDATE_POINTER(6);
488 _ANV_MULTIALLOC_UPDATE_POINTER(7);
489 #undef _ANV_MULTIALLOC_UPDATE_POINTER
494 __attribute__((always_inline
))
496 anv_multialloc_alloc2(struct anv_multialloc
*ma
,
497 const VkAllocationCallbacks
*parent_alloc
,
498 const VkAllocationCallbacks
*alloc
,
499 VkSystemAllocationScope scope
)
501 return anv_multialloc_alloc(ma
, alloc
? alloc
: parent_alloc
, scope
);
507 /* Index into the current validation list. This is used by the
508 * validation list building alrogithm to track which buffers are already
509 * in the validation list so that we can ensure uniqueness.
513 /* Last known offset. This value is provided by the kernel when we
514 * execbuf and is used as the presumed offset for the next bunch of
522 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
527 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
529 bo
->gem_handle
= gem_handle
;
537 /* Represents a lock-free linked list of "free" things. This is used by
538 * both the block pool and the state pools. Unfortunately, in order to
539 * solve the ABA problem, we can't use a single uint32_t head.
541 union anv_free_list
{
545 /* A simple count that is incremented every time the head changes. */
551 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
553 struct anv_block_state
{
563 struct anv_block_pool
{
564 struct anv_device
*device
;
570 /* The offset from the start of the bo to the "center" of the block
571 * pool. Pointers to allocated blocks are given by
572 * bo.map + center_bo_offset + offsets.
574 uint32_t center_bo_offset
;
576 /* Current memory map of the block pool. This pointer may or may not
577 * point to the actual beginning of the block pool memory. If
578 * anv_block_pool_alloc_back has ever been called, then this pointer
579 * will point to the "center" position of the buffer and all offsets
580 * (negative or positive) given out by the block pool alloc functions
581 * will be valid relative to this pointer.
583 * In particular, map == bo.map + center_offset
589 * Array of mmaps and gem handles owned by the block pool, reclaimed when
590 * the block pool is destroyed.
592 struct u_vector mmap_cleanups
;
594 struct anv_block_state state
;
596 struct anv_block_state back_state
;
599 /* Block pools are backed by a fixed-size 1GB memfd */
600 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
602 /* The center of the block pool is also the middle of the memfd. This may
603 * change in the future if we decide differently for some reason.
605 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
607 static inline uint32_t
608 anv_block_pool_size(struct anv_block_pool
*pool
)
610 return pool
->state
.end
+ pool
->back_state
.end
;
619 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
621 struct anv_fixed_size_state_pool
{
622 union anv_free_list free_list
;
623 struct anv_block_state block
;
626 #define ANV_MIN_STATE_SIZE_LOG2 6
627 #define ANV_MAX_STATE_SIZE_LOG2 20
629 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
631 struct anv_state_pool
{
632 struct anv_block_pool block_pool
;
634 /* The size of blocks which will be allocated from the block pool */
637 /** Free list for "back" allocations */
638 union anv_free_list back_alloc_free_list
;
640 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
643 struct anv_state_stream_block
;
645 struct anv_state_stream
{
646 struct anv_state_pool
*state_pool
;
648 /* The size of blocks to allocate from the state pool */
651 /* Current block we're allocating from */
652 struct anv_state block
;
654 /* Offset into the current block at which to allocate the next state */
657 /* List of all blocks allocated from this pool */
658 struct anv_state_stream_block
*block_list
;
661 /* The block_pool functions exported for testing only. The block pool should
662 * only be used via a state pool (see below).
664 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
665 struct anv_device
*device
,
666 uint32_t initial_size
,
668 void anv_block_pool_finish(struct anv_block_pool
*pool
);
669 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
,
670 uint32_t block_size
);
671 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
,
672 uint32_t block_size
);
674 VkResult
anv_state_pool_init(struct anv_state_pool
*pool
,
675 struct anv_device
*device
,
678 void anv_state_pool_finish(struct anv_state_pool
*pool
);
679 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
680 uint32_t state_size
, uint32_t alignment
);
681 struct anv_state
anv_state_pool_alloc_back(struct anv_state_pool
*pool
);
682 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
683 void anv_state_stream_init(struct anv_state_stream
*stream
,
684 struct anv_state_pool
*state_pool
,
685 uint32_t block_size
);
686 void anv_state_stream_finish(struct anv_state_stream
*stream
);
687 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
688 uint32_t size
, uint32_t alignment
);
691 * Implements a pool of re-usable BOs. The interface is identical to that
692 * of block_pool except that each block is its own BO.
695 struct anv_device
*device
;
702 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
,
704 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
705 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
707 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
709 struct anv_scratch_bo
{
714 struct anv_scratch_pool
{
715 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
716 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
719 void anv_scratch_pool_init(struct anv_device
*device
,
720 struct anv_scratch_pool
*pool
);
721 void anv_scratch_pool_finish(struct anv_device
*device
,
722 struct anv_scratch_pool
*pool
);
723 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
724 struct anv_scratch_pool
*pool
,
725 gl_shader_stage stage
,
726 unsigned per_thread_scratch
);
728 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
729 struct anv_bo_cache
{
730 struct hash_table
*bo_map
;
731 pthread_mutex_t mutex
;
734 VkResult
anv_bo_cache_init(struct anv_bo_cache
*cache
);
735 void anv_bo_cache_finish(struct anv_bo_cache
*cache
);
736 VkResult
anv_bo_cache_alloc(struct anv_device
*device
,
737 struct anv_bo_cache
*cache
,
738 uint64_t size
, struct anv_bo
**bo
);
739 VkResult
anv_bo_cache_import(struct anv_device
*device
,
740 struct anv_bo_cache
*cache
,
741 int fd
, struct anv_bo
**bo
);
742 VkResult
anv_bo_cache_export(struct anv_device
*device
,
743 struct anv_bo_cache
*cache
,
744 struct anv_bo
*bo_in
, int *fd_out
);
745 void anv_bo_cache_release(struct anv_device
*device
,
746 struct anv_bo_cache
*cache
,
749 struct anv_memory_type
{
750 /* Standard bits passed on to the client */
751 VkMemoryPropertyFlags propertyFlags
;
754 /* Driver-internal book-keeping */
755 VkBufferUsageFlags valid_buffer_usage
;
758 struct anv_memory_heap
{
759 /* Standard bits passed on to the client */
761 VkMemoryHeapFlags flags
;
763 /* Driver-internal book-keeping */
764 bool supports_48bit_addresses
;
767 struct anv_physical_device
{
768 VK_LOADER_DATA _loader_data
;
770 struct anv_instance
* instance
;
775 struct gen_device_info info
;
776 /** Amount of "GPU memory" we want to advertise
778 * Clearly, this value is bogus since Intel is a UMA architecture. On
779 * gen7 platforms, we are limited by GTT size unless we want to implement
780 * fine-grained tracking and GTT splitting. On Broadwell and above we are
781 * practically unlimited. However, we will never report more than 3/4 of
782 * the total system ram to try and avoid running out of RAM.
784 bool supports_48bit_addresses
;
785 struct brw_compiler
* compiler
;
786 struct isl_device isl_dev
;
787 int cmd_parser_version
;
789 bool has_exec_capture
;
792 bool has_syncobj_wait
;
793 bool has_context_priority
;
795 struct anv_device_extension_table supported_extensions
;
798 uint32_t subslice_total
;
802 struct anv_memory_type types
[VK_MAX_MEMORY_TYPES
];
804 struct anv_memory_heap heaps
[VK_MAX_MEMORY_HEAPS
];
807 uint8_t pipeline_cache_uuid
[VK_UUID_SIZE
];
808 uint8_t driver_uuid
[VK_UUID_SIZE
];
809 uint8_t device_uuid
[VK_UUID_SIZE
];
811 struct wsi_device wsi_device
;
815 struct anv_instance
{
816 VK_LOADER_DATA _loader_data
;
818 VkAllocationCallbacks alloc
;
821 struct anv_instance_extension_table enabled_extensions
;
822 struct anv_dispatch_table dispatch
;
824 int physicalDeviceCount
;
825 struct anv_physical_device physicalDevice
;
827 struct vk_debug_report_instance debug_report_callbacks
;
830 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
831 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
833 uint32_t anv_physical_device_api_version(struct anv_physical_device
*dev
);
834 bool anv_physical_device_extension_supported(struct anv_physical_device
*dev
,
838 VK_LOADER_DATA _loader_data
;
840 struct anv_device
* device
;
842 VkDeviceQueueCreateFlags flags
;
845 struct anv_pipeline_cache
{
846 struct anv_device
* device
;
847 pthread_mutex_t mutex
;
849 struct hash_table
* cache
;
852 struct anv_pipeline_bind_map
;
854 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
855 struct anv_device
*device
,
857 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
859 struct anv_shader_bin
*
860 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
861 const void *key
, uint32_t key_size
);
862 struct anv_shader_bin
*
863 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
864 const void *key_data
, uint32_t key_size
,
865 const void *kernel_data
, uint32_t kernel_size
,
866 const struct brw_stage_prog_data
*prog_data
,
867 uint32_t prog_data_size
,
868 const struct anv_pipeline_bind_map
*bind_map
);
871 VK_LOADER_DATA _loader_data
;
873 VkAllocationCallbacks alloc
;
875 struct anv_instance
* instance
;
878 struct gen_device_info info
;
879 struct isl_device isl_dev
;
882 bool can_chain_batches
;
883 bool robust_buffer_access
;
884 struct anv_device_extension_table enabled_extensions
;
885 struct anv_dispatch_table dispatch
;
887 struct anv_bo_pool batch_bo_pool
;
889 struct anv_bo_cache bo_cache
;
891 struct anv_state_pool dynamic_state_pool
;
892 struct anv_state_pool instruction_state_pool
;
893 struct anv_state_pool surface_state_pool
;
895 struct anv_bo workaround_bo
;
896 struct anv_bo trivial_batch_bo
;
897 struct anv_bo hiz_clear_bo
;
899 struct anv_pipeline_cache blorp_shader_cache
;
900 struct blorp_context blorp
;
902 struct anv_state border_colors
;
904 struct anv_queue queue
;
906 struct anv_scratch_pool scratch_pool
;
908 uint32_t default_mocs
;
910 pthread_mutex_t mutex
;
911 pthread_cond_t queue_submit
;
916 anv_state_flush(struct anv_device
*device
, struct anv_state state
)
918 if (device
->info
.has_llc
)
921 gen_flush_range(state
.map
, state
.alloc_size
);
924 void anv_device_init_blorp(struct anv_device
*device
);
925 void anv_device_finish_blorp(struct anv_device
*device
);
927 VkResult
anv_device_execbuf(struct anv_device
*device
,
928 struct drm_i915_gem_execbuffer2
*execbuf
,
929 struct anv_bo
**execbuf_bos
);
930 VkResult
anv_device_query_status(struct anv_device
*device
);
931 VkResult
anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
);
932 VkResult
anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
935 void* anv_gem_mmap(struct anv_device
*device
,
936 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
937 void anv_gem_munmap(void *p
, uint64_t size
);
938 uint32_t anv_gem_create(struct anv_device
*device
, uint64_t size
);
939 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
940 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
941 int anv_gem_busy(struct anv_device
*device
, uint32_t gem_handle
);
942 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
943 int anv_gem_execbuffer(struct anv_device
*device
,
944 struct drm_i915_gem_execbuffer2
*execbuf
);
945 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
946 uint32_t stride
, uint32_t tiling
);
947 int anv_gem_create_context(struct anv_device
*device
);
948 bool anv_gem_has_context_priority(int fd
);
949 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
950 int anv_gem_set_context_param(int fd
, int context
, uint32_t param
,
952 int anv_gem_get_context_param(int fd
, int context
, uint32_t param
,
954 int anv_gem_get_param(int fd
, uint32_t param
);
955 int anv_gem_get_tiling(struct anv_device
*device
, uint32_t gem_handle
);
956 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
957 int anv_gem_get_aperture(int fd
, uint64_t *size
);
958 int anv_gem_gpu_get_reset_stats(struct anv_device
*device
,
959 uint32_t *active
, uint32_t *pending
);
960 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
961 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
962 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
963 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
964 uint32_t read_domains
, uint32_t write_domain
);
965 int anv_gem_sync_file_merge(struct anv_device
*device
, int fd1
, int fd2
);
966 uint32_t anv_gem_syncobj_create(struct anv_device
*device
, uint32_t flags
);
967 void anv_gem_syncobj_destroy(struct anv_device
*device
, uint32_t handle
);
968 int anv_gem_syncobj_handle_to_fd(struct anv_device
*device
, uint32_t handle
);
969 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device
*device
, int fd
);
970 int anv_gem_syncobj_export_sync_file(struct anv_device
*device
,
972 int anv_gem_syncobj_import_sync_file(struct anv_device
*device
,
973 uint32_t handle
, int fd
);
974 void anv_gem_syncobj_reset(struct anv_device
*device
, uint32_t handle
);
975 bool anv_gem_supports_syncobj_wait(int fd
);
976 int anv_gem_syncobj_wait(struct anv_device
*device
,
977 uint32_t *handles
, uint32_t num_handles
,
978 int64_t abs_timeout_ns
, bool wait_all
);
980 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
982 struct anv_reloc_list
{
984 uint32_t array_length
;
985 struct drm_i915_gem_relocation_entry
* relocs
;
986 struct anv_bo
** reloc_bos
;
989 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
990 const VkAllocationCallbacks
*alloc
);
991 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
992 const VkAllocationCallbacks
*alloc
);
994 VkResult
anv_reloc_list_add(struct anv_reloc_list
*list
,
995 const VkAllocationCallbacks
*alloc
,
996 uint32_t offset
, struct anv_bo
*target_bo
,
999 struct anv_batch_bo
{
1000 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1001 struct list_head link
;
1005 /* Bytes actually consumed in this batch BO */
1008 struct anv_reloc_list relocs
;
1012 const VkAllocationCallbacks
* alloc
;
1018 struct anv_reloc_list
* relocs
;
1020 /* This callback is called (with the associated user data) in the event
1021 * that the batch runs out of space.
1023 VkResult (*extend_cb
)(struct anv_batch
*, void *);
1027 * Current error status of the command buffer. Used to track inconsistent
1028 * or incomplete command buffer states that are the consequence of run-time
1029 * errors such as out of memory scenarios. We want to track this in the
1030 * batch because the command buffer object is not visible to some parts
1036 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
1037 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
1038 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
1039 void *location
, struct anv_bo
*bo
, uint32_t offset
);
1040 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
1041 struct anv_batch
*batch
);
1043 static inline VkResult
1044 anv_batch_set_error(struct anv_batch
*batch
, VkResult error
)
1046 assert(error
!= VK_SUCCESS
);
1047 if (batch
->status
== VK_SUCCESS
)
1048 batch
->status
= error
;
1049 return batch
->status
;
1053 anv_batch_has_error(struct anv_batch
*batch
)
1055 return batch
->status
!= VK_SUCCESS
;
1058 struct anv_address
{
1063 static inline uint64_t
1064 _anv_combine_address(struct anv_batch
*batch
, void *location
,
1065 const struct anv_address address
, uint32_t delta
)
1067 if (address
.bo
== NULL
) {
1068 return address
.offset
+ delta
;
1070 assert(batch
->start
<= location
&& location
< batch
->end
);
1072 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
1076 #define __gen_address_type struct anv_address
1077 #define __gen_user_data struct anv_batch
1078 #define __gen_combine_address _anv_combine_address
1080 /* Wrapper macros needed to work around preprocessor argument issues. In
1081 * particular, arguments don't get pre-evaluated if they are concatenated.
1082 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1083 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1084 * We can work around this easily enough with these helpers.
1086 #define __anv_cmd_length(cmd) cmd ## _length
1087 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1088 #define __anv_cmd_header(cmd) cmd ## _header
1089 #define __anv_cmd_pack(cmd) cmd ## _pack
1090 #define __anv_reg_num(reg) reg ## _num
1092 #define anv_pack_struct(dst, struc, ...) do { \
1093 struct struc __template = { \
1096 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1097 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1100 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1101 void *__dst = anv_batch_emit_dwords(batch, n); \
1103 struct cmd __template = { \
1104 __anv_cmd_header(cmd), \
1105 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1108 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1113 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1117 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1118 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1121 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1122 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1123 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1126 #define anv_batch_emit(batch, cmd, name) \
1127 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1128 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1129 __builtin_expect(_dst != NULL, 1); \
1130 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1131 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1135 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
1136 .GraphicsDataTypeGFDT = 0, \
1137 .LLCCacheabilityControlLLCCC = 0, \
1138 .L3CacheabilityControlL3CC = 1, \
1141 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
1142 .LLCeLLCCacheabilityControlLLCCC = 0, \
1143 .L3CacheabilityControlL3CC = 1, \
1146 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
1147 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
1148 .TargetCache = L3DefertoPATforLLCeLLCselection, \
1149 .AgeforQUADLRU = 0 \
1152 /* Skylake: MOCS is now an index into an array of 62 different caching
1153 * configurations programmed by the kernel.
1156 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
1157 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1158 .IndextoMOCSTables = 2 \
1161 #define GEN9_MOCS_PTE { \
1162 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1163 .IndextoMOCSTables = 1 \
1166 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1167 #define GEN10_MOCS (struct GEN10_MEMORY_OBJECT_CONTROL_STATE) { \
1168 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1169 .IndextoMOCSTables = 2 \
1172 #define GEN10_MOCS_PTE { \
1173 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1174 .IndextoMOCSTables = 1 \
1177 /* Ice Lake MOCS defines are duplicates of Skylake MOCS defines. */
1178 #define GEN11_MOCS (struct GEN11_MEMORY_OBJECT_CONTROL_STATE) { \
1179 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1180 .IndextoMOCSTables = 2 \
1183 #define GEN11_MOCS_PTE { \
1184 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1185 .IndextoMOCSTables = 1 \
1188 struct anv_device_memory
{
1190 struct anv_memory_type
* type
;
1191 VkDeviceSize map_size
;
1196 * Header for Vertex URB Entry (VUE)
1198 struct anv_vue_header
{
1200 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
1201 uint32_t ViewportIndex
;
1205 struct anv_descriptor_set_binding_layout
{
1207 /* The type of the descriptors in this binding */
1208 VkDescriptorType type
;
1211 /* Number of array elements in this binding */
1212 uint16_t array_size
;
1214 /* Index into the flattend descriptor set */
1215 uint16_t descriptor_index
;
1217 /* Index into the dynamic state array for a dynamic buffer */
1218 int16_t dynamic_offset_index
;
1220 /* Index into the descriptor set buffer views */
1221 int16_t buffer_index
;
1224 /* Index into the binding table for the associated surface */
1225 int16_t surface_index
;
1227 /* Index into the sampler table for the associated sampler */
1228 int16_t sampler_index
;
1230 /* Index into the image table for the associated image */
1231 int16_t image_index
;
1232 } stage
[MESA_SHADER_STAGES
];
1234 /* Immutable samplers (or NULL if no immutable samplers) */
1235 struct anv_sampler
**immutable_samplers
;
1238 struct anv_descriptor_set_layout
{
1239 /* Descriptor set layouts can be destroyed at almost any time */
1242 /* Number of bindings in this descriptor set */
1243 uint16_t binding_count
;
1245 /* Total size of the descriptor set with room for all array entries */
1248 /* Shader stages affected by this descriptor set */
1249 uint16_t shader_stages
;
1251 /* Number of buffers in this descriptor set */
1252 uint16_t buffer_count
;
1254 /* Number of dynamic offsets used by this descriptor set */
1255 uint16_t dynamic_offset_count
;
1257 /* Bindings in this descriptor set */
1258 struct anv_descriptor_set_binding_layout binding
[0];
1262 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout
*layout
)
1264 assert(layout
&& layout
->ref_cnt
>= 1);
1265 p_atomic_inc(&layout
->ref_cnt
);
1269 anv_descriptor_set_layout_unref(struct anv_device
*device
,
1270 struct anv_descriptor_set_layout
*layout
)
1272 assert(layout
&& layout
->ref_cnt
>= 1);
1273 if (p_atomic_dec_zero(&layout
->ref_cnt
))
1274 vk_free(&device
->alloc
, layout
);
1277 struct anv_descriptor
{
1278 VkDescriptorType type
;
1282 VkImageLayout layout
;
1283 struct anv_image_view
*image_view
;
1284 struct anv_sampler
*sampler
;
1288 struct anv_buffer
*buffer
;
1293 struct anv_buffer_view
*buffer_view
;
1297 struct anv_descriptor_set
{
1298 struct anv_descriptor_set_layout
*layout
;
1300 uint32_t buffer_count
;
1301 struct anv_buffer_view
*buffer_views
;
1302 struct anv_descriptor descriptors
[0];
1305 struct anv_buffer_view
{
1306 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1308 uint32_t offset
; /**< Offset into bo. */
1309 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1311 struct anv_state surface_state
;
1312 struct anv_state storage_surface_state
;
1313 struct anv_state writeonly_storage_surface_state
;
1315 struct brw_image_param storage_image_param
;
1318 struct anv_push_descriptor_set
{
1319 struct anv_descriptor_set set
;
1321 /* Put this field right behind anv_descriptor_set so it fills up the
1322 * descriptors[0] field. */
1323 struct anv_descriptor descriptors
[MAX_PUSH_DESCRIPTORS
];
1324 struct anv_buffer_view buffer_views
[MAX_PUSH_DESCRIPTORS
];
1327 struct anv_descriptor_pool
{
1332 struct anv_state_stream surface_state_stream
;
1333 void *surface_state_free_list
;
1338 enum anv_descriptor_template_entry_type
{
1339 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE
,
1340 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER
,
1341 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1344 struct anv_descriptor_template_entry
{
1345 /* The type of descriptor in this entry */
1346 VkDescriptorType type
;
1348 /* Binding in the descriptor set */
1351 /* Offset at which to write into the descriptor set binding */
1352 uint32_t array_element
;
1354 /* Number of elements to write into the descriptor set binding */
1355 uint32_t array_count
;
1357 /* Offset into the user provided data */
1360 /* Stride between elements into the user provided data */
1364 struct anv_descriptor_update_template
{
1365 VkPipelineBindPoint bind_point
;
1367 /* The descriptor set this template corresponds to. This value is only
1368 * valid if the template was created with the templateType
1369 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
1373 /* Number of entries in this template */
1374 uint32_t entry_count
;
1376 /* Entries of the template */
1377 struct anv_descriptor_template_entry entries
[0];
1381 anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout
*binding
);
1384 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
);
1387 anv_descriptor_set_write_image_view(struct anv_descriptor_set
*set
,
1388 const struct gen_device_info
* const devinfo
,
1389 const VkDescriptorImageInfo
* const info
,
1390 VkDescriptorType type
,
1395 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set
*set
,
1396 VkDescriptorType type
,
1397 struct anv_buffer_view
*buffer_view
,
1402 anv_descriptor_set_write_buffer(struct anv_descriptor_set
*set
,
1403 struct anv_device
*device
,
1404 struct anv_state_stream
*alloc_stream
,
1405 VkDescriptorType type
,
1406 struct anv_buffer
*buffer
,
1409 VkDeviceSize offset
,
1410 VkDeviceSize range
);
1413 anv_descriptor_set_write_template(struct anv_descriptor_set
*set
,
1414 struct anv_device
*device
,
1415 struct anv_state_stream
*alloc_stream
,
1416 const struct anv_descriptor_update_template
*template,
1420 anv_descriptor_set_create(struct anv_device
*device
,
1421 struct anv_descriptor_pool
*pool
,
1422 struct anv_descriptor_set_layout
*layout
,
1423 struct anv_descriptor_set
**out_set
);
1426 anv_descriptor_set_destroy(struct anv_device
*device
,
1427 struct anv_descriptor_pool
*pool
,
1428 struct anv_descriptor_set
*set
);
1430 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1432 struct anv_pipeline_binding
{
1433 /* The descriptor set this surface corresponds to. The special value of
1434 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1435 * to a color attachment and not a regular descriptor.
1439 /* Binding in the descriptor set */
1442 /* Index in the binding */
1445 /* Plane in the binding index */
1448 /* Input attachment index (relative to the subpass) */
1449 uint8_t input_attachment_index
;
1451 /* For a storage image, whether it is write-only */
1455 struct anv_pipeline_layout
{
1457 struct anv_descriptor_set_layout
*layout
;
1458 uint32_t dynamic_offset_start
;
1464 bool has_dynamic_offsets
;
1465 } stage
[MESA_SHADER_STAGES
];
1467 unsigned char sha1
[20];
1471 struct anv_device
* device
;
1474 VkBufferUsageFlags usage
;
1476 /* Set when bound */
1478 VkDeviceSize offset
;
1481 static inline uint64_t
1482 anv_buffer_get_range(struct anv_buffer
*buffer
, uint64_t offset
, uint64_t range
)
1484 assert(offset
<= buffer
->size
);
1485 if (range
== VK_WHOLE_SIZE
) {
1486 return buffer
->size
- offset
;
1488 assert(range
<= buffer
->size
);
1493 enum anv_cmd_dirty_bits
{
1494 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1495 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1496 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1497 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1498 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1499 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1500 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1501 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1502 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1503 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
1504 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1505 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1506 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1508 typedef uint32_t anv_cmd_dirty_mask_t
;
1510 enum anv_pipe_bits
{
1511 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
1512 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
1513 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
1514 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
1515 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
1516 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
1517 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
1518 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
1519 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
1520 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
1521 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
1523 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1524 * a flush has happened but not a CS stall. The next time we do any sort
1525 * of invalidation we need to insert a CS stall at that time. Otherwise,
1526 * we would have to CS stall on every flush which could be bad.
1528 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
1531 #define ANV_PIPE_FLUSH_BITS ( \
1532 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1533 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1534 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1536 #define ANV_PIPE_STALL_BITS ( \
1537 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1538 ANV_PIPE_DEPTH_STALL_BIT | \
1539 ANV_PIPE_CS_STALL_BIT)
1541 #define ANV_PIPE_INVALIDATE_BITS ( \
1542 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1543 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1544 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1545 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1546 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1547 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1549 static inline enum anv_pipe_bits
1550 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags
)
1552 enum anv_pipe_bits pipe_bits
= 0;
1555 for_each_bit(b
, flags
) {
1556 switch ((VkAccessFlagBits
)(1 << b
)) {
1557 case VK_ACCESS_SHADER_WRITE_BIT
:
1558 pipe_bits
|= ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
1560 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
1561 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1563 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
1564 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1566 case VK_ACCESS_TRANSFER_WRITE_BIT
:
1567 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1568 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1571 break; /* Nothing to do */
1578 static inline enum anv_pipe_bits
1579 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags
)
1581 enum anv_pipe_bits pipe_bits
= 0;
1584 for_each_bit(b
, flags
) {
1585 switch ((VkAccessFlagBits
)(1 << b
)) {
1586 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
1587 case VK_ACCESS_INDEX_READ_BIT
:
1588 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
1589 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
1591 case VK_ACCESS_UNIFORM_READ_BIT
:
1592 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
1593 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1595 case VK_ACCESS_SHADER_READ_BIT
:
1596 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
:
1597 case VK_ACCESS_TRANSFER_READ_BIT
:
1598 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1601 break; /* Nothing to do */
1608 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
1609 VK_IMAGE_ASPECT_COLOR_BIT | \
1610 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1611 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1612 VK_IMAGE_ASPECT_PLANE_2_BIT)
1613 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
1614 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1615 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1616 VK_IMAGE_ASPECT_PLANE_2_BIT)
1618 struct anv_vertex_binding
{
1619 struct anv_buffer
* buffer
;
1620 VkDeviceSize offset
;
1623 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
1624 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
1626 struct anv_push_constants
{
1627 /* Current allocated size of this push constants data structure.
1628 * Because a decent chunk of it may not be used (images on SKL, for
1629 * instance), we won't actually allocate the entire structure up-front.
1633 /* Push constant data provided by the client through vkPushConstants */
1634 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1636 /* Used for vkCmdDispatchBase */
1637 uint32_t base_work_group_id
[3];
1639 /* Image data for image_load_store on pre-SKL */
1640 struct brw_image_param images
[MAX_IMAGES
];
1643 struct anv_dynamic_state
{
1646 VkViewport viewports
[MAX_VIEWPORTS
];
1651 VkRect2D scissors
[MAX_SCISSORS
];
1662 float blend_constants
[4];
1672 } stencil_compare_mask
;
1677 } stencil_write_mask
;
1682 } stencil_reference
;
1685 extern const struct anv_dynamic_state default_dynamic_state
;
1687 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1688 const struct anv_dynamic_state
*src
,
1689 uint32_t copy_mask
);
1691 struct anv_surface_state
{
1692 struct anv_state state
;
1693 /** Address of the surface referred to by this state
1695 * This address is relative to the start of the BO.
1698 /* Address of the aux surface, if any
1700 * This field is 0 if and only if no aux surface exists.
1702 * This address is relative to the start of the BO. With the exception of
1703 * gen8, the bottom 12 bits of this address include extra aux information.
1705 uint64_t aux_address
;
1706 /* Address of the clear color, if any
1708 * This address is relative to the start of the BO.
1710 uint64_t clear_address
;
1714 * Attachment state when recording a renderpass instance.
1716 * The clear value is valid only if there exists a pending clear.
1718 struct anv_attachment_state
{
1719 enum isl_aux_usage aux_usage
;
1720 enum isl_aux_usage input_aux_usage
;
1721 struct anv_surface_state color
;
1722 struct anv_surface_state input
;
1724 VkImageLayout current_layout
;
1725 VkImageAspectFlags pending_clear_aspects
;
1726 VkImageAspectFlags pending_load_aspects
;
1728 VkClearValue clear_value
;
1729 bool clear_color_is_zero_one
;
1730 bool clear_color_is_zero
;
1732 /* When multiview is active, attachments with a renderpass clear
1733 * operation have their respective layers cleared on the first
1734 * subpass that uses them, and only in that subpass. We keep track
1735 * of this using a bitfield to indicate which layers of an attachment
1736 * have not been cleared yet when multiview is active.
1738 uint32_t pending_clear_views
;
1741 /** State tracking for particular pipeline bind point
1743 * This struct is the base struct for anv_cmd_graphics_state and
1744 * anv_cmd_compute_state. These are used to track state which is bound to a
1745 * particular type of pipeline. Generic state that applies per-stage such as
1746 * binding table offsets and push constants is tracked generically with a
1747 * per-stage array in anv_cmd_state.
1749 struct anv_cmd_pipeline_state
{
1750 struct anv_pipeline
*pipeline
;
1751 struct anv_pipeline_layout
*layout
;
1753 struct anv_descriptor_set
*descriptors
[MAX_SETS
];
1754 uint32_t dynamic_offsets
[MAX_DYNAMIC_BUFFERS
];
1756 struct anv_push_descriptor_set
*push_descriptors
[MAX_SETS
];
1759 /** State tracking for graphics pipeline
1761 * This has anv_cmd_pipeline_state as a base struct to track things which get
1762 * bound to a graphics pipeline. Along with general pipeline bind point state
1763 * which is in the anv_cmd_pipeline_state base struct, it also contains other
1764 * state which is graphics-specific.
1766 struct anv_cmd_graphics_state
{
1767 struct anv_cmd_pipeline_state base
;
1769 anv_cmd_dirty_mask_t dirty
;
1772 struct anv_dynamic_state dynamic
;
1775 struct anv_buffer
*index_buffer
;
1776 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1777 uint32_t index_offset
;
1781 /** State tracking for compute pipeline
1783 * This has anv_cmd_pipeline_state as a base struct to track things which get
1784 * bound to a compute pipeline. Along with general pipeline bind point state
1785 * which is in the anv_cmd_pipeline_state base struct, it also contains other
1786 * state which is compute-specific.
1788 struct anv_cmd_compute_state
{
1789 struct anv_cmd_pipeline_state base
;
1791 bool pipeline_dirty
;
1793 struct anv_address num_workgroups
;
1796 /** State required while building cmd buffer */
1797 struct anv_cmd_state
{
1798 /* PIPELINE_SELECT.PipelineSelection */
1799 uint32_t current_pipeline
;
1800 const struct gen_l3_config
* current_l3_config
;
1802 struct anv_cmd_graphics_state gfx
;
1803 struct anv_cmd_compute_state compute
;
1805 enum anv_pipe_bits pending_pipe_bits
;
1806 VkShaderStageFlags descriptors_dirty
;
1807 VkShaderStageFlags push_constants_dirty
;
1809 struct anv_framebuffer
* framebuffer
;
1810 struct anv_render_pass
* pass
;
1811 struct anv_subpass
* subpass
;
1812 VkRect2D render_area
;
1813 uint32_t restart_index
;
1814 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1815 VkShaderStageFlags push_constant_stages
;
1816 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1817 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1818 struct anv_state samplers
[MESA_SHADER_STAGES
];
1821 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1822 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1823 * and before invoking the secondary in ExecuteCommands.
1825 bool pma_fix_enabled
;
1828 * Whether or not we know for certain that HiZ is enabled for the current
1829 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1830 * enabled or not, this will be false.
1835 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1836 * valid only when recording a render pass instance.
1838 struct anv_attachment_state
* attachments
;
1841 * Surface states for color render targets. These are stored in a single
1842 * flat array. For depth-stencil attachments, the surface state is simply
1845 struct anv_state render_pass_states
;
1848 * A null surface state of the right size to match the framebuffer. This
1849 * is one of the states in render_pass_states.
1851 struct anv_state null_surface_state
;
1854 struct anv_cmd_pool
{
1855 VkAllocationCallbacks alloc
;
1856 struct list_head cmd_buffers
;
1859 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1861 enum anv_cmd_buffer_exec_mode
{
1862 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1863 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1864 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1865 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1866 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1869 struct anv_cmd_buffer
{
1870 VK_LOADER_DATA _loader_data
;
1872 struct anv_device
* device
;
1874 struct anv_cmd_pool
* pool
;
1875 struct list_head pool_link
;
1877 struct anv_batch batch
;
1879 /* Fields required for the actual chain of anv_batch_bo's.
1881 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1883 struct list_head batch_bos
;
1884 enum anv_cmd_buffer_exec_mode exec_mode
;
1886 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1887 * referenced by this command buffer
1889 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1891 struct u_vector seen_bbos
;
1893 /* A vector of int32_t's for every block of binding tables.
1895 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1897 struct u_vector bt_block_states
;
1900 struct anv_reloc_list surface_relocs
;
1901 /** Last seen surface state block pool center bo offset */
1902 uint32_t last_ss_pool_center
;
1904 /* Serial for tracking buffer completion */
1907 /* Stream objects for storing temporary data */
1908 struct anv_state_stream surface_state_stream
;
1909 struct anv_state_stream dynamic_state_stream
;
1911 VkCommandBufferUsageFlags usage_flags
;
1912 VkCommandBufferLevel level
;
1914 struct anv_cmd_state state
;
1917 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1918 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1919 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1920 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1921 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1922 struct anv_cmd_buffer
*secondary
);
1923 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1924 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
1925 struct anv_cmd_buffer
*cmd_buffer
,
1926 const VkSemaphore
*in_semaphores
,
1927 uint32_t num_in_semaphores
,
1928 const VkSemaphore
*out_semaphores
,
1929 uint32_t num_out_semaphores
,
1932 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1935 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1936 gl_shader_stage stage
, uint32_t size
);
1937 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1938 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1939 (offsetof(struct anv_push_constants, field) + \
1940 sizeof(cmd_buffer->state.push_constants[0]->field)))
1942 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1943 const void *data
, uint32_t size
, uint32_t alignment
);
1944 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1945 uint32_t *a
, uint32_t *b
,
1946 uint32_t dwords
, uint32_t alignment
);
1949 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1951 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1952 uint32_t entries
, uint32_t *state_offset
);
1954 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1956 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1957 uint32_t size
, uint32_t alignment
);
1960 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1962 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1963 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1964 bool depth_clamp_enable
);
1965 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1967 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1968 struct anv_render_pass
*pass
,
1969 struct anv_framebuffer
*framebuffer
,
1970 const VkClearValue
*clear_values
);
1972 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1975 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1976 gl_shader_stage stage
);
1978 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1980 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1982 const struct anv_image_view
*
1983 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1986 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1987 uint32_t num_entries
,
1988 uint32_t *state_offset
,
1989 struct anv_state
*bt_state
);
1991 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1993 enum anv_fence_type
{
1994 ANV_FENCE_TYPE_NONE
= 0,
1996 ANV_FENCE_TYPE_SYNCOBJ
,
1999 enum anv_bo_fence_state
{
2000 /** Indicates that this is a new (or newly reset fence) */
2001 ANV_BO_FENCE_STATE_RESET
,
2003 /** Indicates that this fence has been submitted to the GPU but is still
2004 * (as far as we know) in use by the GPU.
2006 ANV_BO_FENCE_STATE_SUBMITTED
,
2008 ANV_BO_FENCE_STATE_SIGNALED
,
2011 struct anv_fence_impl
{
2012 enum anv_fence_type type
;
2015 /** Fence implementation for BO fences
2017 * These fences use a BO and a set of CPU-tracked state flags. The BO
2018 * is added to the object list of the last execbuf call in a QueueSubmit
2019 * and is marked EXEC_WRITE. The state flags track when the BO has been
2020 * submitted to the kernel. We need to do this because Vulkan lets you
2021 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2022 * will say it's idle in this case.
2026 enum anv_bo_fence_state state
;
2029 /** DRM syncobj handle for syncobj-based fences */
2035 /* Permanent fence state. Every fence has some form of permanent state
2036 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2037 * cross-process fences) or it could just be a dummy for use internally.
2039 struct anv_fence_impl permanent
;
2041 /* Temporary fence state. A fence *may* have temporary state. That state
2042 * is added to the fence by an import operation and is reset back to
2043 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2044 * state cannot be signaled because the fence must already be signaled
2045 * before the temporary state can be exported from the fence in the other
2046 * process and imported here.
2048 struct anv_fence_impl temporary
;
2053 struct anv_state state
;
2056 enum anv_semaphore_type
{
2057 ANV_SEMAPHORE_TYPE_NONE
= 0,
2058 ANV_SEMAPHORE_TYPE_DUMMY
,
2059 ANV_SEMAPHORE_TYPE_BO
,
2060 ANV_SEMAPHORE_TYPE_SYNC_FILE
,
2061 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ
,
2064 struct anv_semaphore_impl
{
2065 enum anv_semaphore_type type
;
2068 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
2069 * This BO will be added to the object list on any execbuf2 calls for
2070 * which this semaphore is used as a wait or signal fence. When used as
2071 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
2075 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
2076 * If the semaphore is in the unsignaled state due to either just being
2077 * created or because it has been used for a wait, fd will be -1.
2081 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
2082 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
2083 * import so we don't need to bother with a userspace cache.
2089 struct anv_semaphore
{
2090 /* Permanent semaphore state. Every semaphore has some form of permanent
2091 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
2092 * (for cross-process semaphores0 or it could just be a dummy for use
2095 struct anv_semaphore_impl permanent
;
2097 /* Temporary semaphore state. A semaphore *may* have temporary state.
2098 * That state is added to the semaphore by an import operation and is reset
2099 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
2100 * semaphore with temporary state cannot be signaled because the semaphore
2101 * must already be signaled before the temporary state can be exported from
2102 * the semaphore in the other process and imported here.
2104 struct anv_semaphore_impl temporary
;
2107 void anv_semaphore_reset_temporary(struct anv_device
*device
,
2108 struct anv_semaphore
*semaphore
);
2110 struct anv_shader_module
{
2111 unsigned char sha1
[20];
2116 static inline gl_shader_stage
2117 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
2119 assert(__builtin_popcount(vk_stage
) == 1);
2120 return ffs(vk_stage
) - 1;
2123 static inline VkShaderStageFlagBits
2124 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
2126 return (1 << mesa_stage
);
2129 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2131 #define anv_foreach_stage(stage, stage_bits) \
2132 for (gl_shader_stage stage, \
2133 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2134 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2135 __tmp &= ~(1 << (stage)))
2137 struct anv_pipeline_bind_map
{
2138 uint32_t surface_count
;
2139 uint32_t sampler_count
;
2140 uint32_t image_count
;
2142 struct anv_pipeline_binding
* surface_to_descriptor
;
2143 struct anv_pipeline_binding
* sampler_to_descriptor
;
2146 struct anv_shader_bin_key
{
2151 struct anv_shader_bin
{
2154 const struct anv_shader_bin_key
*key
;
2156 struct anv_state kernel
;
2157 uint32_t kernel_size
;
2159 const struct brw_stage_prog_data
*prog_data
;
2160 uint32_t prog_data_size
;
2162 struct anv_pipeline_bind_map bind_map
;
2165 struct anv_shader_bin
*
2166 anv_shader_bin_create(struct anv_device
*device
,
2167 const void *key
, uint32_t key_size
,
2168 const void *kernel
, uint32_t kernel_size
,
2169 const struct brw_stage_prog_data
*prog_data
,
2170 uint32_t prog_data_size
, const void *prog_data_param
,
2171 const struct anv_pipeline_bind_map
*bind_map
);
2174 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
2177 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
2179 assert(shader
&& shader
->ref_cnt
>= 1);
2180 p_atomic_inc(&shader
->ref_cnt
);
2184 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
2186 assert(shader
&& shader
->ref_cnt
>= 1);
2187 if (p_atomic_dec_zero(&shader
->ref_cnt
))
2188 anv_shader_bin_destroy(device
, shader
);
2191 struct anv_pipeline
{
2192 struct anv_device
* device
;
2193 struct anv_batch batch
;
2194 uint32_t batch_data
[512];
2195 struct anv_reloc_list batch_relocs
;
2196 uint32_t dynamic_state_mask
;
2197 struct anv_dynamic_state dynamic_state
;
2199 struct anv_subpass
* subpass
;
2201 bool needs_data_cache
;
2203 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
2206 const struct gen_l3_config
* l3_config
;
2207 uint32_t total_size
;
2210 VkShaderStageFlags active_stages
;
2211 struct anv_state blend_state
;
2214 uint32_t binding_stride
[MAX_VBS
];
2215 bool instancing_enable
[MAX_VBS
];
2216 bool primitive_restart
;
2219 uint32_t cs_right_mask
;
2222 bool depth_test_enable
;
2223 bool writes_stencil
;
2224 bool stencil_test_enable
;
2225 bool depth_clamp_enable
;
2226 bool sample_shading_enable
;
2231 uint32_t depth_stencil_state
[3];
2237 uint32_t wm_depth_stencil
[3];
2241 uint32_t wm_depth_stencil
[4];
2244 uint32_t interface_descriptor_data
[8];
2248 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
2249 gl_shader_stage stage
)
2251 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
2254 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2255 static inline const struct brw_##prefix##_prog_data * \
2256 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2258 if (anv_pipeline_has_stage(pipeline, stage)) { \
2259 return (const struct brw_##prefix##_prog_data *) \
2260 pipeline->shaders[stage]->prog_data; \
2266 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
2267 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
2268 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
2269 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
2270 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
2271 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
2273 static inline const struct brw_vue_prog_data
*
2274 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
2276 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
2277 return &get_gs_prog_data(pipeline
)->base
;
2278 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
2279 return &get_tes_prog_data(pipeline
)->base
;
2281 return &get_vs_prog_data(pipeline
)->base
;
2285 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
2286 struct anv_pipeline_cache
*cache
,
2287 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2288 const VkAllocationCallbacks
*alloc
);
2291 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
2292 struct anv_pipeline_cache
*cache
,
2293 const VkComputePipelineCreateInfo
*info
,
2294 struct anv_shader_module
*module
,
2295 const char *entrypoint
,
2296 const VkSpecializationInfo
*spec_info
);
2298 struct anv_format_plane
{
2299 enum isl_format isl_format
:16;
2300 struct isl_swizzle swizzle
;
2302 /* Whether this plane contains chroma channels */
2305 /* For downscaling of YUV planes */
2306 uint8_t denominator_scales
[2];
2308 /* How to map sampled ycbcr planes to a single 4 component element. */
2309 struct isl_swizzle ycbcr_swizzle
;
2314 struct anv_format_plane planes
[3];
2319 static inline uint32_t
2320 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects
,
2321 VkImageAspectFlags aspect_mask
)
2323 switch (aspect_mask
) {
2324 case VK_IMAGE_ASPECT_COLOR_BIT
:
2325 case VK_IMAGE_ASPECT_DEPTH_BIT
:
2326 case VK_IMAGE_ASPECT_PLANE_0_BIT
:
2328 case VK_IMAGE_ASPECT_STENCIL_BIT
:
2329 if ((image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) == 0)
2332 case VK_IMAGE_ASPECT_PLANE_1_BIT
:
2334 case VK_IMAGE_ASPECT_PLANE_2_BIT
:
2337 /* Purposefully assert with depth/stencil aspects. */
2338 unreachable("invalid image aspect");
2342 static inline uint32_t
2343 anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask
)
2345 uint32_t planes
= 0;
2347 if (aspect_mask
& (VK_IMAGE_ASPECT_COLOR_BIT
|
2348 VK_IMAGE_ASPECT_DEPTH_BIT
|
2349 VK_IMAGE_ASPECT_STENCIL_BIT
|
2350 VK_IMAGE_ASPECT_PLANE_0_BIT
))
2352 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_1_BIT
)
2354 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_2_BIT
)
2357 if ((aspect_mask
& VK_IMAGE_ASPECT_DEPTH_BIT
) != 0 &&
2358 (aspect_mask
& VK_IMAGE_ASPECT_STENCIL_BIT
) != 0)
2364 static inline VkImageAspectFlags
2365 anv_plane_to_aspect(VkImageAspectFlags image_aspects
,
2368 if (image_aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
2369 if (_mesa_bitcount(image_aspects
) > 1)
2370 return VK_IMAGE_ASPECT_PLANE_0_BIT
<< plane
;
2371 return VK_IMAGE_ASPECT_COLOR_BIT
;
2373 if (image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)
2374 return VK_IMAGE_ASPECT_DEPTH_BIT
<< plane
;
2375 assert(image_aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
2376 return VK_IMAGE_ASPECT_STENCIL_BIT
;
2379 #define anv_foreach_image_aspect_bit(b, image, aspects) \
2380 for_each_bit(b, anv_image_expand_aspects(image, aspects))
2382 const struct anv_format
*
2383 anv_get_format(VkFormat format
);
2385 static inline uint32_t
2386 anv_get_format_planes(VkFormat vk_format
)
2388 const struct anv_format
*format
= anv_get_format(vk_format
);
2390 return format
!= NULL
? format
->n_planes
: 0;
2393 struct anv_format_plane
2394 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2395 VkImageAspectFlagBits aspect
, VkImageTiling tiling
);
2397 static inline enum isl_format
2398 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2399 VkImageAspectFlags aspect
, VkImageTiling tiling
)
2401 return anv_get_format_plane(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
2404 static inline struct isl_swizzle
2405 anv_swizzle_for_render(struct isl_swizzle swizzle
)
2407 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2408 * RGB as RGBA for texturing
2410 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
2411 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
2413 /* But it doesn't matter what we render to that channel */
2414 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
2420 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
2423 * Subsurface of an anv_image.
2425 struct anv_surface
{
2426 /** Valid only if isl_surf::size > 0. */
2427 struct isl_surf isl
;
2430 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2437 /* The original VkFormat provided by the client. This may not match any
2438 * of the actual surface formats.
2441 const struct anv_format
*format
;
2443 VkImageAspectFlags aspects
;
2446 uint32_t array_size
;
2447 uint32_t samples
; /**< VkImageCreateInfo::samples */
2449 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
2450 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
2452 /** True if this is needs to be bound to an appropriately tiled BO.
2454 * When not using modifiers, consumers such as X11, Wayland, and KMS need
2455 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
2456 * we require a dedicated allocation so that we can know to allocate a
2459 bool needs_set_tiling
;
2462 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
2463 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
2465 uint64_t drm_format_mod
;
2470 /* Whether the image is made of several underlying buffer objects rather a
2471 * single one with different offsets.
2478 * For each foo, anv_image::planes[x].surface is valid if and only if
2479 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
2480 * to figure the number associated with a given aspect.
2482 * The hardware requires that the depth buffer and stencil buffer be
2483 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2484 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2485 * allocate the depth and stencil buffers as separate surfaces in the same
2490 * -----------------------
2492 * ----------------------- |
2493 * | shadow surface0 | |
2494 * ----------------------- | Plane 0
2495 * | aux surface0 | |
2496 * ----------------------- |
2497 * | fast clear colors0 | \|/
2498 * -----------------------
2500 * ----------------------- |
2501 * | shadow surface1 | |
2502 * ----------------------- | Plane 1
2503 * | aux surface1 | |
2504 * ----------------------- |
2505 * | fast clear colors1 | \|/
2506 * -----------------------
2509 * -----------------------
2513 * Offset of the entire plane (whenever the image is disjoint this is
2521 struct anv_surface surface
;
2524 * A surface which shadows the main surface and may have different
2525 * tiling. This is used for sampling using a tiling that isn't supported
2526 * for other operations.
2528 struct anv_surface shadow_surface
;
2531 * For color images, this is the aux usage for this image when not used
2532 * as a color attachment.
2534 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
2535 * image has a HiZ buffer.
2537 enum isl_aux_usage aux_usage
;
2539 struct anv_surface aux_surface
;
2542 * Offset of the fast clear state (used to compute the
2543 * fast_clear_state_offset of the following planes).
2545 uint32_t fast_clear_state_offset
;
2548 * BO associated with this plane, set when bound.
2551 VkDeviceSize bo_offset
;
2554 * When destroying the image, also free the bo.
2560 /* The ordering of this enum is important */
2561 enum anv_fast_clear_type
{
2562 /** Image does not have/support any fast-clear blocks */
2563 ANV_FAST_CLEAR_NONE
= 0,
2564 /** Image has/supports fast-clear but only to the default value */
2565 ANV_FAST_CLEAR_DEFAULT_VALUE
= 1,
2566 /** Image has/supports fast-clear with an arbitrary fast-clear value */
2567 ANV_FAST_CLEAR_ANY
= 2,
2570 /* Returns the number of auxiliary buffer levels attached to an image. */
2571 static inline uint8_t
2572 anv_image_aux_levels(const struct anv_image
* const image
,
2573 VkImageAspectFlagBits aspect
)
2575 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2576 return image
->planes
[plane
].aux_surface
.isl
.size
> 0 ?
2577 image
->planes
[plane
].aux_surface
.isl
.levels
: 0;
2580 /* Returns the number of auxiliary buffer layers attached to an image. */
2581 static inline uint32_t
2582 anv_image_aux_layers(const struct anv_image
* const image
,
2583 VkImageAspectFlagBits aspect
,
2584 const uint8_t miplevel
)
2588 /* The miplevel must exist in the main buffer. */
2589 assert(miplevel
< image
->levels
);
2591 if (miplevel
>= anv_image_aux_levels(image
, aspect
)) {
2592 /* There are no layers with auxiliary data because the miplevel has no
2597 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2598 return MAX2(image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.array_len
,
2599 image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.depth
>> miplevel
);
2603 static inline struct anv_address
2604 anv_image_get_clear_color_addr(const struct anv_device
*device
,
2605 const struct anv_image
*image
,
2606 VkImageAspectFlagBits aspect
)
2608 assert(image
->aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
2610 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2611 return (struct anv_address
) {
2612 .bo
= image
->planes
[plane
].bo
,
2613 .offset
= image
->planes
[plane
].bo_offset
+
2614 image
->planes
[plane
].fast_clear_state_offset
,
2618 static inline struct anv_address
2619 anv_image_get_fast_clear_type_addr(const struct anv_device
*device
,
2620 const struct anv_image
*image
,
2621 VkImageAspectFlagBits aspect
)
2623 struct anv_address addr
=
2624 anv_image_get_clear_color_addr(device
, image
, aspect
);
2626 const unsigned clear_color_state_size
= device
->info
.gen
>= 10 ?
2627 device
->isl_dev
.ss
.clear_color_state_size
:
2628 device
->isl_dev
.ss
.clear_value_size
;
2629 addr
.offset
+= clear_color_state_size
;
2633 static inline struct anv_address
2634 anv_image_get_compression_state_addr(const struct anv_device
*device
,
2635 const struct anv_image
*image
,
2636 VkImageAspectFlagBits aspect
,
2637 uint32_t level
, uint32_t array_layer
)
2639 assert(level
< anv_image_aux_levels(image
, aspect
));
2640 assert(array_layer
< anv_image_aux_layers(image
, aspect
, level
));
2641 UNUSED
uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2642 assert(image
->planes
[plane
].aux_usage
== ISL_AUX_USAGE_CCS_E
);
2644 struct anv_address addr
=
2645 anv_image_get_fast_clear_type_addr(device
, image
, aspect
);
2646 addr
.offset
+= 4; /* Go past the fast clear type */
2648 if (image
->type
== VK_IMAGE_TYPE_3D
) {
2649 for (uint32_t l
= 0; l
< level
; l
++)
2650 addr
.offset
+= anv_minify(image
->extent
.depth
, l
) * 4;
2652 addr
.offset
+= level
* image
->array_size
* 4;
2654 addr
.offset
+= array_layer
* 4;
2659 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
2661 anv_can_sample_with_hiz(const struct gen_device_info
* const devinfo
,
2662 const struct anv_image
*image
)
2664 if (!(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
))
2667 if (devinfo
->gen
< 8)
2670 return image
->samples
== 1;
2674 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer
*cmd_buffer
,
2675 const struct anv_image
*image
,
2676 VkImageAspectFlagBits aspect
,
2677 enum isl_aux_usage aux_usage
,
2679 uint32_t base_layer
,
2680 uint32_t layer_count
);
2683 anv_image_clear_color(struct anv_cmd_buffer
*cmd_buffer
,
2684 const struct anv_image
*image
,
2685 VkImageAspectFlagBits aspect
,
2686 enum isl_aux_usage aux_usage
,
2687 enum isl_format format
, struct isl_swizzle swizzle
,
2688 uint32_t level
, uint32_t base_layer
, uint32_t layer_count
,
2689 VkRect2D area
, union isl_color_value clear_color
);
2691 anv_image_clear_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
2692 const struct anv_image
*image
,
2693 VkImageAspectFlags aspects
,
2694 enum isl_aux_usage depth_aux_usage
,
2696 uint32_t base_layer
, uint32_t layer_count
,
2698 float depth_value
, uint8_t stencil_value
);
2700 anv_image_hiz_op(struct anv_cmd_buffer
*cmd_buffer
,
2701 const struct anv_image
*image
,
2702 VkImageAspectFlagBits aspect
, uint32_t level
,
2703 uint32_t base_layer
, uint32_t layer_count
,
2704 enum isl_aux_op hiz_op
);
2706 anv_image_hiz_clear(struct anv_cmd_buffer
*cmd_buffer
,
2707 const struct anv_image
*image
,
2708 VkImageAspectFlags aspects
,
2710 uint32_t base_layer
, uint32_t layer_count
,
2711 VkRect2D area
, uint8_t stencil_value
);
2713 anv_image_mcs_op(struct anv_cmd_buffer
*cmd_buffer
,
2714 const struct anv_image
*image
,
2715 VkImageAspectFlagBits aspect
,
2716 uint32_t base_layer
, uint32_t layer_count
,
2717 enum isl_aux_op mcs_op
, union isl_color_value
*clear_value
,
2720 anv_image_ccs_op(struct anv_cmd_buffer
*cmd_buffer
,
2721 const struct anv_image
*image
,
2722 VkImageAspectFlagBits aspect
, uint32_t level
,
2723 uint32_t base_layer
, uint32_t layer_count
,
2724 enum isl_aux_op ccs_op
, union isl_color_value
*clear_value
,
2728 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
2729 const struct anv_image
*image
,
2730 uint32_t base_level
, uint32_t level_count
,
2731 uint32_t base_layer
, uint32_t layer_count
);
2734 anv_layout_to_aux_usage(const struct gen_device_info
* const devinfo
,
2735 const struct anv_image
*image
,
2736 const VkImageAspectFlagBits aspect
,
2737 const VkImageLayout layout
);
2739 enum anv_fast_clear_type
2740 anv_layout_to_fast_clear_type(const struct gen_device_info
* const devinfo
,
2741 const struct anv_image
* const image
,
2742 const VkImageAspectFlagBits aspect
,
2743 const VkImageLayout layout
);
2745 /* This is defined as a macro so that it works for both
2746 * VkImageSubresourceRange and VkImageSubresourceLayers
2748 #define anv_get_layerCount(_image, _range) \
2749 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
2750 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
2752 static inline uint32_t
2753 anv_get_levelCount(const struct anv_image
*image
,
2754 const VkImageSubresourceRange
*range
)
2756 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
2757 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
2760 static inline VkImageAspectFlags
2761 anv_image_expand_aspects(const struct anv_image
*image
,
2762 VkImageAspectFlags aspects
)
2764 /* If the underlying image has color plane aspects and
2765 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
2766 * the underlying image. */
2767 if ((image
->aspects
& VK_IMAGE_ASPECT_PLANES_BITS_ANV
) != 0 &&
2768 aspects
== VK_IMAGE_ASPECT_COLOR_BIT
)
2769 return image
->aspects
;
2775 anv_image_aspects_compatible(VkImageAspectFlags aspects1
,
2776 VkImageAspectFlags aspects2
)
2778 if (aspects1
== aspects2
)
2781 /* Only 1 color aspects are compatibles. */
2782 if ((aspects1
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2783 (aspects2
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2784 _mesa_bitcount(aspects1
) == _mesa_bitcount(aspects2
))
2790 struct anv_image_view
{
2791 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
2793 VkImageAspectFlags aspect_mask
;
2795 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2799 uint32_t image_plane
;
2801 struct isl_view isl
;
2804 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2805 * image layout of SHADER_READ_ONLY_OPTIMAL or
2806 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
2808 struct anv_surface_state optimal_sampler_surface_state
;
2811 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2812 * image layout of GENERAL.
2814 struct anv_surface_state general_sampler_surface_state
;
2817 * RENDER_SURFACE_STATE when using image as a storage image. Separate
2818 * states for write-only and readable, using the real format for
2819 * write-only and the lowered format for readable.
2821 struct anv_surface_state storage_surface_state
;
2822 struct anv_surface_state writeonly_storage_surface_state
;
2824 struct brw_image_param storage_image_param
;
2828 enum anv_image_view_state_flags
{
2829 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY
= (1 << 0),
2830 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL
= (1 << 1),
2833 void anv_image_fill_surface_state(struct anv_device
*device
,
2834 const struct anv_image
*image
,
2835 VkImageAspectFlagBits aspect
,
2836 const struct isl_view
*view
,
2837 isl_surf_usage_flags_t view_usage
,
2838 enum isl_aux_usage aux_usage
,
2839 const union isl_color_value
*clear_color
,
2840 enum anv_image_view_state_flags flags
,
2841 struct anv_surface_state
*state_inout
,
2842 struct brw_image_param
*image_param_out
);
2844 struct anv_image_create_info
{
2845 const VkImageCreateInfo
*vk_info
;
2847 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
2848 isl_tiling_flags_t isl_tiling_flags
;
2850 /** These flags will be added to any derived from VkImageCreateInfo. */
2851 isl_surf_usage_flags_t isl_extra_usage_flags
;
2856 VkResult
anv_image_create(VkDevice _device
,
2857 const struct anv_image_create_info
*info
,
2858 const VkAllocationCallbacks
* alloc
,
2862 VkResult
anv_image_from_gralloc(VkDevice device_h
,
2863 const VkImageCreateInfo
*base_info
,
2864 const VkNativeBufferANDROID
*gralloc_info
,
2865 const VkAllocationCallbacks
*alloc
,
2869 const struct anv_surface
*
2870 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
2871 VkImageAspectFlags aspect_mask
);
2874 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
2876 static inline struct VkExtent3D
2877 anv_sanitize_image_extent(const VkImageType imageType
,
2878 const struct VkExtent3D imageExtent
)
2880 switch (imageType
) {
2881 case VK_IMAGE_TYPE_1D
:
2882 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
2883 case VK_IMAGE_TYPE_2D
:
2884 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
2885 case VK_IMAGE_TYPE_3D
:
2888 unreachable("invalid image type");
2892 static inline struct VkOffset3D
2893 anv_sanitize_image_offset(const VkImageType imageType
,
2894 const struct VkOffset3D imageOffset
)
2896 switch (imageType
) {
2897 case VK_IMAGE_TYPE_1D
:
2898 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
2899 case VK_IMAGE_TYPE_2D
:
2900 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
2901 case VK_IMAGE_TYPE_3D
:
2904 unreachable("invalid image type");
2909 void anv_fill_buffer_surface_state(struct anv_device
*device
,
2910 struct anv_state state
,
2911 enum isl_format format
,
2912 uint32_t offset
, uint32_t range
,
2916 anv_clear_color_from_att_state(union isl_color_value
*clear_color
,
2917 const struct anv_attachment_state
*att_state
,
2918 const struct anv_image_view
*iview
)
2920 const struct isl_format_layout
*view_fmtl
=
2921 isl_format_get_layout(iview
->planes
[0].isl
.format
);
2923 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
2924 if (view_fmtl->channels.c.bits) \
2925 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
2927 COPY_CLEAR_COLOR_CHANNEL(r
, 0);
2928 COPY_CLEAR_COLOR_CHANNEL(g
, 1);
2929 COPY_CLEAR_COLOR_CHANNEL(b
, 2);
2930 COPY_CLEAR_COLOR_CHANNEL(a
, 3);
2932 #undef COPY_CLEAR_COLOR_CHANNEL
2936 struct anv_ycbcr_conversion
{
2937 const struct anv_format
* format
;
2938 VkSamplerYcbcrModelConversion ycbcr_model
;
2939 VkSamplerYcbcrRange ycbcr_range
;
2940 VkComponentSwizzle mapping
[4];
2941 VkChromaLocation chroma_offsets
[2];
2942 VkFilter chroma_filter
;
2943 bool chroma_reconstruction
;
2946 struct anv_sampler
{
2947 uint32_t state
[3][4];
2949 struct anv_ycbcr_conversion
*conversion
;
2952 struct anv_framebuffer
{
2957 uint32_t attachment_count
;
2958 struct anv_image_view
* attachments
[0];
2961 struct anv_subpass_attachment
{
2962 VkImageUsageFlagBits usage
;
2963 uint32_t attachment
;
2964 VkImageLayout layout
;
2967 struct anv_subpass
{
2968 uint32_t attachment_count
;
2971 * A pointer to all attachment references used in this subpass.
2972 * Only valid if ::attachment_count > 0.
2974 struct anv_subpass_attachment
* attachments
;
2975 uint32_t input_count
;
2976 struct anv_subpass_attachment
* input_attachments
;
2977 uint32_t color_count
;
2978 struct anv_subpass_attachment
* color_attachments
;
2979 struct anv_subpass_attachment
* resolve_attachments
;
2981 struct anv_subpass_attachment depth_stencil_attachment
;
2985 /** Subpass has a depth/stencil self-dependency */
2986 bool has_ds_self_dep
;
2988 /** Subpass has at least one resolve attachment */
2992 static inline unsigned
2993 anv_subpass_view_count(const struct anv_subpass
*subpass
)
2995 return MAX2(1, _mesa_bitcount(subpass
->view_mask
));
2998 struct anv_render_pass_attachment
{
2999 /* TODO: Consider using VkAttachmentDescription instead of storing each of
3000 * its members individually.
3004 VkImageUsageFlags usage
;
3005 VkAttachmentLoadOp load_op
;
3006 VkAttachmentStoreOp store_op
;
3007 VkAttachmentLoadOp stencil_load_op
;
3008 VkImageLayout initial_layout
;
3009 VkImageLayout final_layout
;
3010 VkImageLayout first_subpass_layout
;
3012 /* The subpass id in which the attachment will be used last. */
3013 uint32_t last_subpass_idx
;
3016 struct anv_render_pass
{
3017 uint32_t attachment_count
;
3018 uint32_t subpass_count
;
3019 /* An array of subpass_count+1 flushes, one per subpass boundary */
3020 enum anv_pipe_bits
* subpass_flushes
;
3021 struct anv_render_pass_attachment
* attachments
;
3022 struct anv_subpass subpasses
[0];
3025 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
3027 struct anv_query_pool
{
3029 VkQueryPipelineStatisticFlags pipeline_statistics
;
3030 /** Stride between slots, in bytes */
3032 /** Number of slots in this query pool */
3037 int anv_get_entrypoint_index(const char *name
);
3040 anv_entrypoint_is_enabled(int index
, uint32_t core_version
,
3041 const struct anv_instance_extension_table
*instance
,
3042 const struct anv_device_extension_table
*device
);
3044 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
3047 void anv_dump_image_to_ppm(struct anv_device
*device
,
3048 struct anv_image
*image
, unsigned miplevel
,
3049 unsigned array_layer
, VkImageAspectFlagBits aspect
,
3050 const char *filename
);
3052 enum anv_dump_action
{
3053 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
3056 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
3057 void anv_dump_finish(void);
3059 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
3060 struct anv_framebuffer
*fb
);
3062 static inline uint32_t
3063 anv_get_subpass_id(const struct anv_cmd_state
* const cmd_state
)
3065 /* This function must be called from within a subpass. */
3066 assert(cmd_state
->pass
&& cmd_state
->subpass
);
3068 const uint32_t subpass_id
= cmd_state
->subpass
- cmd_state
->pass
->subpasses
;
3070 /* The id of this subpass shouldn't exceed the number of subpasses in this
3071 * render pass minus 1.
3073 assert(subpass_id
< cmd_state
->pass
->subpass_count
);
3077 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
3079 static inline struct __anv_type * \
3080 __anv_type ## _from_handle(__VkType _handle) \
3082 return (struct __anv_type *) _handle; \
3085 static inline __VkType \
3086 __anv_type ## _to_handle(struct __anv_type *_obj) \
3088 return (__VkType) _obj; \
3091 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
3093 static inline struct __anv_type * \
3094 __anv_type ## _from_handle(__VkType _handle) \
3096 return (struct __anv_type *)(uintptr_t) _handle; \
3099 static inline __VkType \
3100 __anv_type ## _to_handle(struct __anv_type *_obj) \
3102 return (__VkType)(uintptr_t) _obj; \
3105 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
3106 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
3108 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
3109 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
3110 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
3111 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
3112 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
3114 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
3115 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
3116 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
3117 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
3118 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
3119 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
3120 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template
, VkDescriptorUpdateTemplateKHR
)
3121 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
3122 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
3123 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
3124 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
3125 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
3126 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
3127 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
3128 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
3129 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
3130 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
3131 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
3132 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
3133 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore
, VkSemaphore
)
3134 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
3135 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback
, VkDebugReportCallbackEXT
)
3136 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion
, VkSamplerYcbcrConversion
)
3138 /* Gen-specific function declarations */
3140 # include "anv_genX.h"
3142 # define genX(x) gen7_##x
3143 # include "anv_genX.h"
3145 # define genX(x) gen75_##x
3146 # include "anv_genX.h"
3148 # define genX(x) gen8_##x
3149 # include "anv_genX.h"
3151 # define genX(x) gen9_##x
3152 # include "anv_genX.h"
3154 # define genX(x) gen10_##x
3155 # include "anv_genX.h"
3157 # define genX(x) gen11_##x
3158 # include "anv_genX.h"
3162 #endif /* ANV_PRIVATE_H */