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 "dev/gen_device_info.h"
46 #include "blorp/blorp.h"
47 #include "compiler/brw_compiler.h"
48 #include "util/macros.h"
49 #include "util/list.h"
50 #include "util/u_atomic.h"
51 #include "util/u_vector.h"
53 #include "vk_debug_report.h"
55 /* Pre-declarations needed for WSI entrypoints */
58 typedef struct xcb_connection_t xcb_connection_t
;
59 typedef uint32_t xcb_visualid_t
;
60 typedef uint32_t xcb_window_t
;
63 struct anv_buffer_view
;
64 struct anv_image_view
;
69 #include <vulkan/vulkan.h>
70 #include <vulkan/vulkan_intel.h>
71 #include <vulkan/vk_icd.h>
72 #include <vulkan/vk_android_native_buffer.h>
74 #include "anv_entrypoints.h"
75 #include "anv_extensions.h"
78 #include "common/gen_debug.h"
79 #include "common/intel_log.h"
80 #include "wsi_common.h"
82 /* Allowing different clear colors requires us to perform a depth resolve at
83 * the end of certain render passes. This is because while slow clears store
84 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
85 * See the PRMs for examples describing when additional resolves would be
86 * necessary. To enable fast clears without requiring extra resolves, we set
87 * the clear value to a globally-defined one. We could allow different values
88 * if the user doesn't expect coherent data during or after a render passes
89 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
90 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
91 * 1.0f seems to be the only value used. The only application that doesn't set
92 * this value does so through the usage of an seemingly uninitialized clear
95 #define ANV_HZ_FC_VAL 1.0f
100 #define MAX_VIEWPORTS 16
101 #define MAX_SCISSORS 16
102 #define MAX_PUSH_CONSTANTS_SIZE 128
103 #define MAX_DYNAMIC_BUFFERS 16
105 #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
107 /* The kernel relocation API has a limitation of a 32-bit delta value
108 * applied to the address before it is written which, in spite of it being
109 * unsigned, is treated as signed . Because of the way that this maps to
110 * the Vulkan API, we cannot handle an offset into a buffer that does not
111 * fit into a signed 32 bits. The only mechanism we have for dealing with
112 * this at the moment is to limit all VkDeviceMemory objects to a maximum
113 * of 2GB each. The Vulkan spec allows us to do this:
115 * "Some platforms may have a limit on the maximum size of a single
116 * allocation. For example, certain systems may fail to create
117 * allocations with a size greater than or equal to 4GB. Such a limit is
118 * implementation-dependent, and if such a failure occurs then the error
119 * VK_ERROR_OUT_OF_DEVICE_MEMORY should be returned."
121 * We don't use vk_error here because it's not an error so much as an
122 * indication to the application that the allocation is too large.
124 #define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
126 #define ANV_SVGS_VB_INDEX MAX_VBS
127 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
129 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
131 static inline uint32_t
132 align_down_npot_u32(uint32_t v
, uint32_t a
)
137 static inline uint32_t
138 align_u32(uint32_t v
, uint32_t a
)
140 assert(a
!= 0 && a
== (a
& -a
));
141 return (v
+ a
- 1) & ~(a
- 1);
144 static inline uint64_t
145 align_u64(uint64_t v
, uint64_t a
)
147 assert(a
!= 0 && a
== (a
& -a
));
148 return (v
+ a
- 1) & ~(a
- 1);
151 static inline int32_t
152 align_i32(int32_t v
, int32_t a
)
154 assert(a
!= 0 && a
== (a
& -a
));
155 return (v
+ a
- 1) & ~(a
- 1);
158 /** Alignment must be a power of 2. */
160 anv_is_aligned(uintmax_t n
, uintmax_t a
)
162 assert(a
== (a
& -a
));
163 return (n
& (a
- 1)) == 0;
166 static inline uint32_t
167 anv_minify(uint32_t n
, uint32_t levels
)
169 if (unlikely(n
== 0))
172 return MAX2(n
>> levels
, 1);
176 anv_clamp_f(float f
, float min
, float max
)
189 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
191 if (*inout_mask
& clear_mask
) {
192 *inout_mask
&= ~clear_mask
;
199 static inline union isl_color_value
200 vk_to_isl_color(VkClearColorValue color
)
202 return (union isl_color_value
) {
212 #define for_each_bit(b, dword) \
213 for (uint32_t __dword = (dword); \
214 (b) = __builtin_ffs(__dword) - 1, __dword; \
215 __dword &= ~(1 << (b)))
217 #define typed_memcpy(dest, src, count) ({ \
218 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
219 memcpy((dest), (src), (count) * sizeof(*(src))); \
222 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
223 * to be added here in order to utilize mapping in debug/error/perf macros.
225 #define REPORT_OBJECT_TYPE(o) \
226 __builtin_choose_expr ( \
227 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
228 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
229 __builtin_choose_expr ( \
230 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
231 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
232 __builtin_choose_expr ( \
233 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
234 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
235 __builtin_choose_expr ( \
236 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
237 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
238 __builtin_choose_expr ( \
239 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
240 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
241 __builtin_choose_expr ( \
242 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
243 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
244 __builtin_choose_expr ( \
245 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
246 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
247 __builtin_choose_expr ( \
248 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
249 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
250 __builtin_choose_expr ( \
251 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
252 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
253 __builtin_choose_expr ( \
254 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
255 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
256 __builtin_choose_expr ( \
257 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
258 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
259 __builtin_choose_expr ( \
260 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
261 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
262 __builtin_choose_expr ( \
263 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
264 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
265 __builtin_choose_expr ( \
266 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
267 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
268 __builtin_choose_expr ( \
269 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
270 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
271 __builtin_choose_expr ( \
272 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
273 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
274 __builtin_choose_expr ( \
275 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
276 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
277 __builtin_choose_expr ( \
278 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
279 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
280 __builtin_choose_expr ( \
281 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
282 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
283 __builtin_choose_expr ( \
284 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
285 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
286 __builtin_choose_expr ( \
287 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
288 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
289 __builtin_choose_expr ( \
290 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
291 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
292 __builtin_choose_expr ( \
293 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
294 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
295 __builtin_choose_expr ( \
296 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
297 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
298 __builtin_choose_expr ( \
299 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
300 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
301 __builtin_choose_expr ( \
302 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
303 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
304 __builtin_choose_expr ( \
305 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
306 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
307 __builtin_choose_expr ( \
308 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
309 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
310 __builtin_choose_expr ( \
311 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
312 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
313 __builtin_choose_expr ( \
314 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
315 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
316 __builtin_choose_expr ( \
317 __builtin_types_compatible_p (__typeof (o), void*), \
318 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
319 /* The void expression results in a compile-time error \
320 when assigning the result to something. */ \
321 (void)0)))))))))))))))))))))))))))))))
323 /* Whenever we generate an error, pass it through this function. Useful for
324 * debugging, where we can break on it. Only call at error site, not when
325 * propagating errors. Might be useful to plug in a stack trace here.
328 VkResult
__vk_errorf(struct anv_instance
*instance
, const void *object
,
329 VkDebugReportObjectTypeEXT type
, VkResult error
,
330 const char *file
, int line
, const char *format
, ...);
333 #define vk_error(error) __vk_errorf(NULL, NULL,\
334 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
335 error, __FILE__, __LINE__, NULL)
336 #define vk_errorf(instance, obj, error, format, ...)\
337 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
338 __FILE__, __LINE__, format, ## __VA_ARGS__)
340 #define vk_error(error) error
341 #define vk_errorf(instance, obj, error, format, ...) error
345 * Warn on ignored extension structs.
347 * The Vulkan spec requires us to ignore unsupported or unknown structs in
348 * a pNext chain. In debug mode, emitting warnings for ignored structs may
349 * help us discover structs that we should not have ignored.
352 * From the Vulkan 1.0.38 spec:
354 * Any component of the implementation (the loader, any enabled layers,
355 * and drivers) must skip over, without processing (other than reading the
356 * sType and pNext members) any chained structures with sType values not
357 * defined by extensions supported by that component.
359 #define anv_debug_ignored_stype(sType) \
360 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
362 void __anv_perf_warn(struct anv_instance
*instance
, const void *object
,
363 VkDebugReportObjectTypeEXT type
, const char *file
,
364 int line
, const char *format
, ...)
365 anv_printflike(6, 7);
366 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
367 void anv_loge_v(const char *format
, va_list va
);
370 * Print a FINISHME message, including its source location.
372 #define anv_finishme(format, ...) \
374 static bool reported = false; \
376 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
383 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
385 #define anv_perf_warn(instance, obj, format, ...) \
387 static bool reported = false; \
388 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
389 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
390 format, ##__VA_ARGS__); \
395 /* A non-fatal assert. Useful for debugging. */
397 #define anv_assert(x) ({ \
398 if (unlikely(!(x))) \
399 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
402 #define anv_assert(x)
405 /* A multi-pointer allocator
407 * When copying data structures from the user (such as a render pass), it's
408 * common to need to allocate data for a bunch of different things. Instead
409 * of doing several allocations and having to handle all of the error checking
410 * that entails, it can be easier to do a single allocation. This struct
411 * helps facilitate that. The intended usage looks like this:
414 * anv_multialloc_add(&ma, &main_ptr, 1);
415 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
416 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
418 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
419 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
421 struct anv_multialloc
{
429 #define ANV_MULTIALLOC_INIT \
430 ((struct anv_multialloc) { 0, })
432 #define ANV_MULTIALLOC(_name) \
433 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
435 __attribute__((always_inline
))
437 _anv_multialloc_add(struct anv_multialloc
*ma
,
438 void **ptr
, size_t size
, size_t align
)
440 size_t offset
= align_u64(ma
->size
, align
);
441 ma
->size
= offset
+ size
;
442 ma
->align
= MAX2(ma
->align
, align
);
444 /* Store the offset in the pointer. */
445 *ptr
= (void *)(uintptr_t)offset
;
447 assert(ma
->ptr_count
< ARRAY_SIZE(ma
->ptrs
));
448 ma
->ptrs
[ma
->ptr_count
++] = ptr
;
451 #define anv_multialloc_add_size(_ma, _ptr, _size) \
452 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
454 #define anv_multialloc_add(_ma, _ptr, _count) \
455 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
457 __attribute__((always_inline
))
459 anv_multialloc_alloc(struct anv_multialloc
*ma
,
460 const VkAllocationCallbacks
*alloc
,
461 VkSystemAllocationScope scope
)
463 void *ptr
= vk_alloc(alloc
, ma
->size
, ma
->align
, scope
);
467 /* Fill out each of the pointers with their final value.
469 * for (uint32_t i = 0; i < ma->ptr_count; i++)
470 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
472 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
473 * constant, GCC is incapable of figuring this out and unrolling the loop
474 * so we have to give it a little help.
476 STATIC_ASSERT(ARRAY_SIZE(ma
->ptrs
) == 8);
477 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
478 if ((_i) < ma->ptr_count) \
479 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
480 _ANV_MULTIALLOC_UPDATE_POINTER(0);
481 _ANV_MULTIALLOC_UPDATE_POINTER(1);
482 _ANV_MULTIALLOC_UPDATE_POINTER(2);
483 _ANV_MULTIALLOC_UPDATE_POINTER(3);
484 _ANV_MULTIALLOC_UPDATE_POINTER(4);
485 _ANV_MULTIALLOC_UPDATE_POINTER(5);
486 _ANV_MULTIALLOC_UPDATE_POINTER(6);
487 _ANV_MULTIALLOC_UPDATE_POINTER(7);
488 #undef _ANV_MULTIALLOC_UPDATE_POINTER
493 __attribute__((always_inline
))
495 anv_multialloc_alloc2(struct anv_multialloc
*ma
,
496 const VkAllocationCallbacks
*parent_alloc
,
497 const VkAllocationCallbacks
*alloc
,
498 VkSystemAllocationScope scope
)
500 return anv_multialloc_alloc(ma
, alloc
? alloc
: parent_alloc
, scope
);
506 /* Index into the current validation list. This is used by the
507 * validation list building alrogithm to track which buffers are already
508 * in the validation list so that we can ensure uniqueness.
512 /* Last known offset. This value is provided by the kernel when we
513 * execbuf and is used as the presumed offset for the next bunch of
521 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
526 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
528 bo
->gem_handle
= gem_handle
;
536 /* Represents a lock-free linked list of "free" things. This is used by
537 * both the block pool and the state pools. Unfortunately, in order to
538 * solve the ABA problem, we can't use a single uint32_t head.
540 union anv_free_list
{
544 /* A simple count that is incremented every time the head changes. */
550 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
552 struct anv_block_state
{
562 struct anv_block_pool
{
563 struct anv_device
*device
;
569 /* The offset from the start of the bo to the "center" of the block
570 * pool. Pointers to allocated blocks are given by
571 * bo.map + center_bo_offset + offsets.
573 uint32_t center_bo_offset
;
575 /* Current memory map of the block pool. This pointer may or may not
576 * point to the actual beginning of the block pool memory. If
577 * anv_block_pool_alloc_back has ever been called, then this pointer
578 * will point to the "center" position of the buffer and all offsets
579 * (negative or positive) given out by the block pool alloc functions
580 * will be valid relative to this pointer.
582 * In particular, map == bo.map + center_offset
588 * Array of mmaps and gem handles owned by the block pool, reclaimed when
589 * the block pool is destroyed.
591 struct u_vector mmap_cleanups
;
593 struct anv_block_state state
;
595 struct anv_block_state back_state
;
598 /* Block pools are backed by a fixed-size 1GB memfd */
599 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
601 /* The center of the block pool is also the middle of the memfd. This may
602 * change in the future if we decide differently for some reason.
604 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
606 static inline uint32_t
607 anv_block_pool_size(struct anv_block_pool
*pool
)
609 return pool
->state
.end
+ pool
->back_state
.end
;
618 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
620 struct anv_fixed_size_state_pool
{
621 union anv_free_list free_list
;
622 struct anv_block_state block
;
625 #define ANV_MIN_STATE_SIZE_LOG2 6
626 #define ANV_MAX_STATE_SIZE_LOG2 20
628 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
630 struct anv_state_pool
{
631 struct anv_block_pool block_pool
;
633 /* The size of blocks which will be allocated from the block pool */
636 /** Free list for "back" allocations */
637 union anv_free_list back_alloc_free_list
;
639 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
642 struct anv_state_stream_block
;
644 struct anv_state_stream
{
645 struct anv_state_pool
*state_pool
;
647 /* The size of blocks to allocate from the state pool */
650 /* Current block we're allocating from */
651 struct anv_state block
;
653 /* Offset into the current block at which to allocate the next state */
656 /* List of all blocks allocated from this pool */
657 struct anv_state_stream_block
*block_list
;
660 /* The block_pool functions exported for testing only. The block pool should
661 * only be used via a state pool (see below).
663 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
664 struct anv_device
*device
,
665 uint32_t initial_size
,
667 void anv_block_pool_finish(struct anv_block_pool
*pool
);
668 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
,
669 uint32_t block_size
);
670 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
,
671 uint32_t block_size
);
673 VkResult
anv_state_pool_init(struct anv_state_pool
*pool
,
674 struct anv_device
*device
,
677 void anv_state_pool_finish(struct anv_state_pool
*pool
);
678 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
679 uint32_t state_size
, uint32_t alignment
);
680 struct anv_state
anv_state_pool_alloc_back(struct anv_state_pool
*pool
);
681 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
682 void anv_state_stream_init(struct anv_state_stream
*stream
,
683 struct anv_state_pool
*state_pool
,
684 uint32_t block_size
);
685 void anv_state_stream_finish(struct anv_state_stream
*stream
);
686 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
687 uint32_t size
, uint32_t alignment
);
690 * Implements a pool of re-usable BOs. The interface is identical to that
691 * of block_pool except that each block is its own BO.
694 struct anv_device
*device
;
701 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
,
703 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
704 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
706 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
708 struct anv_scratch_bo
{
713 struct anv_scratch_pool
{
714 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
715 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
718 void anv_scratch_pool_init(struct anv_device
*device
,
719 struct anv_scratch_pool
*pool
);
720 void anv_scratch_pool_finish(struct anv_device
*device
,
721 struct anv_scratch_pool
*pool
);
722 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
723 struct anv_scratch_pool
*pool
,
724 gl_shader_stage stage
,
725 unsigned per_thread_scratch
);
727 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
728 struct anv_bo_cache
{
729 struct hash_table
*bo_map
;
730 pthread_mutex_t mutex
;
733 VkResult
anv_bo_cache_init(struct anv_bo_cache
*cache
);
734 void anv_bo_cache_finish(struct anv_bo_cache
*cache
);
735 VkResult
anv_bo_cache_alloc(struct anv_device
*device
,
736 struct anv_bo_cache
*cache
,
737 uint64_t size
, struct anv_bo
**bo
);
738 VkResult
anv_bo_cache_import(struct anv_device
*device
,
739 struct anv_bo_cache
*cache
,
740 int fd
, struct anv_bo
**bo
);
741 VkResult
anv_bo_cache_export(struct anv_device
*device
,
742 struct anv_bo_cache
*cache
,
743 struct anv_bo
*bo_in
, int *fd_out
);
744 void anv_bo_cache_release(struct anv_device
*device
,
745 struct anv_bo_cache
*cache
,
748 struct anv_memory_type
{
749 /* Standard bits passed on to the client */
750 VkMemoryPropertyFlags propertyFlags
;
753 /* Driver-internal book-keeping */
754 VkBufferUsageFlags valid_buffer_usage
;
757 struct anv_memory_heap
{
758 /* Standard bits passed on to the client */
760 VkMemoryHeapFlags flags
;
762 /* Driver-internal book-keeping */
763 bool supports_48bit_addresses
;
766 struct anv_physical_device
{
767 VK_LOADER_DATA _loader_data
;
769 struct anv_instance
* instance
;
774 struct gen_device_info info
;
775 /** Amount of "GPU memory" we want to advertise
777 * Clearly, this value is bogus since Intel is a UMA architecture. On
778 * gen7 platforms, we are limited by GTT size unless we want to implement
779 * fine-grained tracking and GTT splitting. On Broadwell and above we are
780 * practically unlimited. However, we will never report more than 3/4 of
781 * the total system ram to try and avoid running out of RAM.
783 bool supports_48bit_addresses
;
784 struct brw_compiler
* compiler
;
785 struct isl_device isl_dev
;
786 int cmd_parser_version
;
788 bool has_exec_capture
;
791 bool has_syncobj_wait
;
792 bool has_context_priority
;
794 struct anv_device_extension_table supported_extensions
;
797 uint32_t subslice_total
;
801 struct anv_memory_type types
[VK_MAX_MEMORY_TYPES
];
803 struct anv_memory_heap heaps
[VK_MAX_MEMORY_HEAPS
];
806 uint8_t pipeline_cache_uuid
[VK_UUID_SIZE
];
807 uint8_t driver_uuid
[VK_UUID_SIZE
];
808 uint8_t device_uuid
[VK_UUID_SIZE
];
810 struct wsi_device wsi_device
;
814 struct anv_instance
{
815 VK_LOADER_DATA _loader_data
;
817 VkAllocationCallbacks alloc
;
820 struct anv_instance_extension_table enabled_extensions
;
821 struct anv_dispatch_table dispatch
;
823 int physicalDeviceCount
;
824 struct anv_physical_device physicalDevice
;
826 struct vk_debug_report_instance debug_report_callbacks
;
829 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
830 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
832 uint32_t anv_physical_device_api_version(struct anv_physical_device
*dev
);
833 bool anv_physical_device_extension_supported(struct anv_physical_device
*dev
,
837 VK_LOADER_DATA _loader_data
;
839 struct anv_device
* device
;
841 struct anv_state_pool
* pool
;
843 VkDeviceQueueCreateFlags flags
;
846 struct anv_pipeline_cache
{
847 struct anv_device
* device
;
848 pthread_mutex_t mutex
;
850 struct hash_table
* cache
;
853 struct anv_pipeline_bind_map
;
855 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
856 struct anv_device
*device
,
858 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
860 struct anv_shader_bin
*
861 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
862 const void *key
, uint32_t key_size
);
863 struct anv_shader_bin
*
864 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
865 const void *key_data
, uint32_t key_size
,
866 const void *kernel_data
, uint32_t kernel_size
,
867 const struct brw_stage_prog_data
*prog_data
,
868 uint32_t prog_data_size
,
869 const struct anv_pipeline_bind_map
*bind_map
);
872 VK_LOADER_DATA _loader_data
;
874 VkAllocationCallbacks alloc
;
876 struct anv_instance
* instance
;
879 struct gen_device_info info
;
880 struct isl_device isl_dev
;
883 bool can_chain_batches
;
884 bool robust_buffer_access
;
885 struct anv_device_extension_table enabled_extensions
;
886 struct anv_dispatch_table dispatch
;
888 struct anv_bo_pool batch_bo_pool
;
890 struct anv_bo_cache bo_cache
;
892 struct anv_state_pool dynamic_state_pool
;
893 struct anv_state_pool instruction_state_pool
;
894 struct anv_state_pool surface_state_pool
;
896 struct anv_bo workaround_bo
;
897 struct anv_bo trivial_batch_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 bool anv_gem_supports_48b_addresses(int fd
);
959 int anv_gem_gpu_get_reset_stats(struct anv_device
*device
,
960 uint32_t *active
, uint32_t *pending
);
961 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
962 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
963 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
964 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
965 uint32_t read_domains
, uint32_t write_domain
);
966 int anv_gem_sync_file_merge(struct anv_device
*device
, int fd1
, int fd2
);
967 uint32_t anv_gem_syncobj_create(struct anv_device
*device
, uint32_t flags
);
968 void anv_gem_syncobj_destroy(struct anv_device
*device
, uint32_t handle
);
969 int anv_gem_syncobj_handle_to_fd(struct anv_device
*device
, uint32_t handle
);
970 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device
*device
, int fd
);
971 int anv_gem_syncobj_export_sync_file(struct anv_device
*device
,
973 int anv_gem_syncobj_import_sync_file(struct anv_device
*device
,
974 uint32_t handle
, int fd
);
975 void anv_gem_syncobj_reset(struct anv_device
*device
, uint32_t handle
);
976 bool anv_gem_supports_syncobj_wait(int fd
);
977 int anv_gem_syncobj_wait(struct anv_device
*device
,
978 uint32_t *handles
, uint32_t num_handles
,
979 int64_t abs_timeout_ns
, bool wait_all
);
981 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
983 struct anv_reloc_list
{
985 uint32_t array_length
;
986 struct drm_i915_gem_relocation_entry
* relocs
;
987 struct anv_bo
** reloc_bos
;
990 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
991 const VkAllocationCallbacks
*alloc
);
992 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
993 const VkAllocationCallbacks
*alloc
);
995 VkResult
anv_reloc_list_add(struct anv_reloc_list
*list
,
996 const VkAllocationCallbacks
*alloc
,
997 uint32_t offset
, struct anv_bo
*target_bo
,
1000 struct anv_batch_bo
{
1001 /* Link in the anv_cmd_buffer.owned_batch_bos list */
1002 struct list_head link
;
1006 /* Bytes actually consumed in this batch BO */
1009 struct anv_reloc_list relocs
;
1013 const VkAllocationCallbacks
* alloc
;
1019 struct anv_reloc_list
* relocs
;
1021 /* This callback is called (with the associated user data) in the event
1022 * that the batch runs out of space.
1024 VkResult (*extend_cb
)(struct anv_batch
*, void *);
1028 * Current error status of the command buffer. Used to track inconsistent
1029 * or incomplete command buffer states that are the consequence of run-time
1030 * errors such as out of memory scenarios. We want to track this in the
1031 * batch because the command buffer object is not visible to some parts
1037 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
1038 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
1039 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
1040 void *location
, struct anv_bo
*bo
, uint32_t offset
);
1041 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
1042 struct anv_batch
*batch
);
1044 static inline VkResult
1045 anv_batch_set_error(struct anv_batch
*batch
, VkResult error
)
1047 assert(error
!= VK_SUCCESS
);
1048 if (batch
->status
== VK_SUCCESS
)
1049 batch
->status
= error
;
1050 return batch
->status
;
1054 anv_batch_has_error(struct anv_batch
*batch
)
1056 return batch
->status
!= VK_SUCCESS
;
1059 struct anv_address
{
1064 static inline uint64_t
1065 _anv_combine_address(struct anv_batch
*batch
, void *location
,
1066 const struct anv_address address
, uint32_t delta
)
1068 if (address
.bo
== NULL
) {
1069 return address
.offset
+ delta
;
1071 assert(batch
->start
<= location
&& location
< batch
->end
);
1073 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
1077 #define __gen_address_type struct anv_address
1078 #define __gen_user_data struct anv_batch
1079 #define __gen_combine_address _anv_combine_address
1081 /* Wrapper macros needed to work around preprocessor argument issues. In
1082 * particular, arguments don't get pre-evaluated if they are concatenated.
1083 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1084 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1085 * We can work around this easily enough with these helpers.
1087 #define __anv_cmd_length(cmd) cmd ## _length
1088 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1089 #define __anv_cmd_header(cmd) cmd ## _header
1090 #define __anv_cmd_pack(cmd) cmd ## _pack
1091 #define __anv_reg_num(reg) reg ## _num
1093 #define anv_pack_struct(dst, struc, ...) do { \
1094 struct struc __template = { \
1097 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1098 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1101 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1102 void *__dst = anv_batch_emit_dwords(batch, n); \
1104 struct cmd __template = { \
1105 __anv_cmd_header(cmd), \
1106 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1109 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1114 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1118 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1119 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1122 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1123 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1124 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1127 #define anv_batch_emit(batch, cmd, name) \
1128 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1129 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1130 __builtin_expect(_dst != NULL, 1); \
1131 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1132 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1136 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
1137 .GraphicsDataTypeGFDT = 0, \
1138 .LLCCacheabilityControlLLCCC = 0, \
1139 .L3CacheabilityControlL3CC = 1, \
1142 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
1143 .LLCeLLCCacheabilityControlLLCCC = 0, \
1144 .L3CacheabilityControlL3CC = 1, \
1147 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
1148 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
1149 .TargetCache = L3DefertoPATforLLCeLLCselection, \
1150 .AgeforQUADLRU = 0 \
1153 /* Skylake: MOCS is now an index into an array of 62 different caching
1154 * configurations programmed by the kernel.
1157 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
1158 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1159 .IndextoMOCSTables = 2 \
1162 #define GEN9_MOCS_PTE { \
1163 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1164 .IndextoMOCSTables = 1 \
1167 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1168 #define GEN10_MOCS (struct GEN10_MEMORY_OBJECT_CONTROL_STATE) { \
1169 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1170 .IndextoMOCSTables = 2 \
1173 #define GEN10_MOCS_PTE { \
1174 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1175 .IndextoMOCSTables = 1 \
1178 /* Ice Lake MOCS defines are duplicates of Skylake MOCS defines. */
1179 #define GEN11_MOCS (struct GEN11_MEMORY_OBJECT_CONTROL_STATE) { \
1180 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1181 .IndextoMOCSTables = 2 \
1184 #define GEN11_MOCS_PTE { \
1185 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1186 .IndextoMOCSTables = 1 \
1189 struct anv_device_memory
{
1191 struct anv_memory_type
* type
;
1192 VkDeviceSize map_size
;
1197 * Header for Vertex URB Entry (VUE)
1199 struct anv_vue_header
{
1201 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
1202 uint32_t ViewportIndex
;
1206 struct anv_descriptor_set_binding_layout
{
1208 /* The type of the descriptors in this binding */
1209 VkDescriptorType type
;
1212 /* Number of array elements in this binding */
1213 uint16_t array_size
;
1215 /* Index into the flattend descriptor set */
1216 uint16_t descriptor_index
;
1218 /* Index into the dynamic state array for a dynamic buffer */
1219 int16_t dynamic_offset_index
;
1221 /* Index into the descriptor set buffer views */
1222 int16_t buffer_index
;
1225 /* Index into the binding table for the associated surface */
1226 int16_t surface_index
;
1228 /* Index into the sampler table for the associated sampler */
1229 int16_t sampler_index
;
1231 /* Index into the image table for the associated image */
1232 int16_t image_index
;
1233 } stage
[MESA_SHADER_STAGES
];
1235 /* Immutable samplers (or NULL if no immutable samplers) */
1236 struct anv_sampler
**immutable_samplers
;
1239 struct anv_descriptor_set_layout
{
1240 /* Descriptor set layouts can be destroyed at almost any time */
1243 /* Number of bindings in this descriptor set */
1244 uint16_t binding_count
;
1246 /* Total size of the descriptor set with room for all array entries */
1249 /* Shader stages affected by this descriptor set */
1250 uint16_t shader_stages
;
1252 /* Number of buffers in this descriptor set */
1253 uint16_t buffer_count
;
1255 /* Number of dynamic offsets used by this descriptor set */
1256 uint16_t dynamic_offset_count
;
1258 /* Bindings in this descriptor set */
1259 struct anv_descriptor_set_binding_layout binding
[0];
1263 anv_descriptor_set_layout_ref(struct anv_descriptor_set_layout
*layout
)
1265 assert(layout
&& layout
->ref_cnt
>= 1);
1266 p_atomic_inc(&layout
->ref_cnt
);
1270 anv_descriptor_set_layout_unref(struct anv_device
*device
,
1271 struct anv_descriptor_set_layout
*layout
)
1273 assert(layout
&& layout
->ref_cnt
>= 1);
1274 if (p_atomic_dec_zero(&layout
->ref_cnt
))
1275 vk_free(&device
->alloc
, layout
);
1278 struct anv_descriptor
{
1279 VkDescriptorType type
;
1283 VkImageLayout layout
;
1284 struct anv_image_view
*image_view
;
1285 struct anv_sampler
*sampler
;
1289 struct anv_buffer
*buffer
;
1294 struct anv_buffer_view
*buffer_view
;
1298 struct anv_descriptor_set
{
1299 struct anv_descriptor_set_layout
*layout
;
1301 uint32_t buffer_count
;
1302 struct anv_buffer_view
*buffer_views
;
1303 struct anv_descriptor descriptors
[0];
1306 struct anv_buffer_view
{
1307 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1309 uint32_t offset
; /**< Offset into bo. */
1310 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1312 struct anv_state surface_state
;
1313 struct anv_state storage_surface_state
;
1314 struct anv_state writeonly_storage_surface_state
;
1316 struct brw_image_param storage_image_param
;
1319 struct anv_push_descriptor_set
{
1320 struct anv_descriptor_set set
;
1322 /* Put this field right behind anv_descriptor_set so it fills up the
1323 * descriptors[0] field. */
1324 struct anv_descriptor descriptors
[MAX_PUSH_DESCRIPTORS
];
1325 struct anv_buffer_view buffer_views
[MAX_PUSH_DESCRIPTORS
];
1328 struct anv_descriptor_pool
{
1333 struct anv_state_stream surface_state_stream
;
1334 void *surface_state_free_list
;
1339 enum anv_descriptor_template_entry_type
{
1340 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE
,
1341 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER
,
1342 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1345 struct anv_descriptor_template_entry
{
1346 /* The type of descriptor in this entry */
1347 VkDescriptorType type
;
1349 /* Binding in the descriptor set */
1352 /* Offset at which to write into the descriptor set binding */
1353 uint32_t array_element
;
1355 /* Number of elements to write into the descriptor set binding */
1356 uint32_t array_count
;
1358 /* Offset into the user provided data */
1361 /* Stride between elements into the user provided data */
1365 struct anv_descriptor_update_template
{
1366 VkPipelineBindPoint bind_point
;
1368 /* The descriptor set this template corresponds to. This value is only
1369 * valid if the template was created with the templateType
1370 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
1374 /* Number of entries in this template */
1375 uint32_t entry_count
;
1377 /* Entries of the template */
1378 struct anv_descriptor_template_entry entries
[0];
1382 anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout
*binding
);
1385 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
);
1388 anv_descriptor_set_write_image_view(struct anv_descriptor_set
*set
,
1389 const struct gen_device_info
* const devinfo
,
1390 const VkDescriptorImageInfo
* const info
,
1391 VkDescriptorType type
,
1396 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set
*set
,
1397 VkDescriptorType type
,
1398 struct anv_buffer_view
*buffer_view
,
1403 anv_descriptor_set_write_buffer(struct anv_descriptor_set
*set
,
1404 struct anv_device
*device
,
1405 struct anv_state_stream
*alloc_stream
,
1406 VkDescriptorType type
,
1407 struct anv_buffer
*buffer
,
1410 VkDeviceSize offset
,
1411 VkDeviceSize range
);
1414 anv_descriptor_set_write_template(struct anv_descriptor_set
*set
,
1415 struct anv_device
*device
,
1416 struct anv_state_stream
*alloc_stream
,
1417 const struct anv_descriptor_update_template
*template,
1421 anv_descriptor_set_create(struct anv_device
*device
,
1422 struct anv_descriptor_pool
*pool
,
1423 struct anv_descriptor_set_layout
*layout
,
1424 struct anv_descriptor_set
**out_set
);
1427 anv_descriptor_set_destroy(struct anv_device
*device
,
1428 struct anv_descriptor_pool
*pool
,
1429 struct anv_descriptor_set
*set
);
1431 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1433 struct anv_pipeline_binding
{
1434 /* The descriptor set this surface corresponds to. The special value of
1435 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1436 * to a color attachment and not a regular descriptor.
1440 /* Binding in the descriptor set */
1443 /* Index in the binding */
1446 /* Plane in the binding index */
1449 /* Input attachment index (relative to the subpass) */
1450 uint8_t input_attachment_index
;
1452 /* For a storage image, whether it is write-only */
1456 struct anv_pipeline_layout
{
1458 struct anv_descriptor_set_layout
*layout
;
1459 uint32_t dynamic_offset_start
;
1465 bool has_dynamic_offsets
;
1466 } stage
[MESA_SHADER_STAGES
];
1468 unsigned char sha1
[20];
1472 struct anv_device
* device
;
1475 VkBufferUsageFlags usage
;
1477 /* Set when bound */
1479 VkDeviceSize offset
;
1482 static inline uint64_t
1483 anv_buffer_get_range(struct anv_buffer
*buffer
, uint64_t offset
, uint64_t range
)
1485 assert(offset
<= buffer
->size
);
1486 if (range
== VK_WHOLE_SIZE
) {
1487 return buffer
->size
- offset
;
1489 assert(range
<= buffer
->size
);
1494 enum anv_cmd_dirty_bits
{
1495 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1496 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1497 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1498 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1499 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1500 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1501 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1502 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1503 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1504 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
1505 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1506 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1507 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1509 typedef uint32_t anv_cmd_dirty_mask_t
;
1511 enum anv_pipe_bits
{
1512 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
1513 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
1514 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
1515 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
1516 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
1517 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
1518 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
1519 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
1520 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
1521 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
1522 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
1524 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1525 * a flush has happened but not a CS stall. The next time we do any sort
1526 * of invalidation we need to insert a CS stall at that time. Otherwise,
1527 * we would have to CS stall on every flush which could be bad.
1529 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
1532 #define ANV_PIPE_FLUSH_BITS ( \
1533 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1534 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1535 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1537 #define ANV_PIPE_STALL_BITS ( \
1538 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1539 ANV_PIPE_DEPTH_STALL_BIT | \
1540 ANV_PIPE_CS_STALL_BIT)
1542 #define ANV_PIPE_INVALIDATE_BITS ( \
1543 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1544 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1545 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1546 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1547 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1548 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1550 static inline enum anv_pipe_bits
1551 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags
)
1553 enum anv_pipe_bits pipe_bits
= 0;
1556 for_each_bit(b
, flags
) {
1557 switch ((VkAccessFlagBits
)(1 << b
)) {
1558 case VK_ACCESS_SHADER_WRITE_BIT
:
1559 pipe_bits
|= ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
1561 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
1562 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1564 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
1565 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1567 case VK_ACCESS_TRANSFER_WRITE_BIT
:
1568 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1569 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1572 break; /* Nothing to do */
1579 static inline enum anv_pipe_bits
1580 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags
)
1582 enum anv_pipe_bits pipe_bits
= 0;
1585 for_each_bit(b
, flags
) {
1586 switch ((VkAccessFlagBits
)(1 << b
)) {
1587 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
1588 case VK_ACCESS_INDEX_READ_BIT
:
1589 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
1590 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
1592 case VK_ACCESS_UNIFORM_READ_BIT
:
1593 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
1594 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1596 case VK_ACCESS_SHADER_READ_BIT
:
1597 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
:
1598 case VK_ACCESS_TRANSFER_READ_BIT
:
1599 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1602 break; /* Nothing to do */
1609 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
1610 VK_IMAGE_ASPECT_COLOR_BIT | \
1611 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1612 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1613 VK_IMAGE_ASPECT_PLANE_2_BIT)
1614 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
1615 VK_IMAGE_ASPECT_PLANE_0_BIT | \
1616 VK_IMAGE_ASPECT_PLANE_1_BIT | \
1617 VK_IMAGE_ASPECT_PLANE_2_BIT)
1619 struct anv_vertex_binding
{
1620 struct anv_buffer
* buffer
;
1621 VkDeviceSize offset
;
1624 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
1625 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
1627 struct anv_push_constants
{
1628 /* Current allocated size of this push constants data structure.
1629 * Because a decent chunk of it may not be used (images on SKL, for
1630 * instance), we won't actually allocate the entire structure up-front.
1634 /* Push constant data provided by the client through vkPushConstants */
1635 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1637 /* Used for vkCmdDispatchBase */
1638 uint32_t base_work_group_id
[3];
1640 /* Image data for image_load_store on pre-SKL */
1641 struct brw_image_param images
[MAX_IMAGES
];
1644 struct anv_dynamic_state
{
1647 VkViewport viewports
[MAX_VIEWPORTS
];
1652 VkRect2D scissors
[MAX_SCISSORS
];
1663 float blend_constants
[4];
1673 } stencil_compare_mask
;
1678 } stencil_write_mask
;
1683 } stencil_reference
;
1686 extern const struct anv_dynamic_state default_dynamic_state
;
1688 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1689 const struct anv_dynamic_state
*src
,
1690 uint32_t copy_mask
);
1692 struct anv_surface_state
{
1693 struct anv_state state
;
1694 /** Address of the surface referred to by this state
1696 * This address is relative to the start of the BO.
1699 /* Address of the aux surface, if any
1701 * This field is 0 if and only if no aux surface exists.
1703 * This address is relative to the start of the BO. With the exception of
1704 * gen8, the bottom 12 bits of this address include extra aux information.
1706 uint64_t aux_address
;
1710 * Attachment state when recording a renderpass instance.
1712 * The clear value is valid only if there exists a pending clear.
1714 struct anv_attachment_state
{
1715 enum isl_aux_usage aux_usage
;
1716 enum isl_aux_usage input_aux_usage
;
1717 struct anv_surface_state color
;
1718 struct anv_surface_state input
;
1720 VkImageLayout current_layout
;
1721 VkImageAspectFlags pending_clear_aspects
;
1722 VkImageAspectFlags pending_load_aspects
;
1724 VkClearValue clear_value
;
1725 bool clear_color_is_zero_one
;
1726 bool clear_color_is_zero
;
1728 /* When multiview is active, attachments with a renderpass clear
1729 * operation have their respective layers cleared on the first
1730 * subpass that uses them, and only in that subpass. We keep track
1731 * of this using a bitfield to indicate which layers of an attachment
1732 * have not been cleared yet when multiview is active.
1734 uint32_t pending_clear_views
;
1737 /** State tracking for particular pipeline bind point
1739 * This struct is the base struct for anv_cmd_graphics_state and
1740 * anv_cmd_compute_state. These are used to track state which is bound to a
1741 * particular type of pipeline. Generic state that applies per-stage such as
1742 * binding table offsets and push constants is tracked generically with a
1743 * per-stage array in anv_cmd_state.
1745 struct anv_cmd_pipeline_state
{
1746 struct anv_pipeline
*pipeline
;
1747 struct anv_pipeline_layout
*layout
;
1749 struct anv_descriptor_set
*descriptors
[MAX_SETS
];
1750 uint32_t dynamic_offsets
[MAX_DYNAMIC_BUFFERS
];
1752 struct anv_push_descriptor_set
*push_descriptors
[MAX_SETS
];
1755 /** State tracking for graphics pipeline
1757 * This has anv_cmd_pipeline_state as a base struct to track things which get
1758 * bound to a graphics pipeline. Along with general pipeline bind point state
1759 * which is in the anv_cmd_pipeline_state base struct, it also contains other
1760 * state which is graphics-specific.
1762 struct anv_cmd_graphics_state
{
1763 struct anv_cmd_pipeline_state base
;
1765 anv_cmd_dirty_mask_t dirty
;
1768 struct anv_dynamic_state dynamic
;
1771 struct anv_buffer
*index_buffer
;
1772 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1773 uint32_t index_offset
;
1777 /** State tracking for compute pipeline
1779 * This has anv_cmd_pipeline_state as a base struct to track things which get
1780 * bound to a compute pipeline. Along with general pipeline bind point state
1781 * which is in the anv_cmd_pipeline_state base struct, it also contains other
1782 * state which is compute-specific.
1784 struct anv_cmd_compute_state
{
1785 struct anv_cmd_pipeline_state base
;
1787 bool pipeline_dirty
;
1789 struct anv_address num_workgroups
;
1792 /** State required while building cmd buffer */
1793 struct anv_cmd_state
{
1794 /* PIPELINE_SELECT.PipelineSelection */
1795 uint32_t current_pipeline
;
1796 const struct gen_l3_config
* current_l3_config
;
1798 struct anv_cmd_graphics_state gfx
;
1799 struct anv_cmd_compute_state compute
;
1801 enum anv_pipe_bits pending_pipe_bits
;
1802 VkShaderStageFlags descriptors_dirty
;
1803 VkShaderStageFlags push_constants_dirty
;
1805 struct anv_framebuffer
* framebuffer
;
1806 struct anv_render_pass
* pass
;
1807 struct anv_subpass
* subpass
;
1808 VkRect2D render_area
;
1809 uint32_t restart_index
;
1810 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1811 VkShaderStageFlags push_constant_stages
;
1812 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1813 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1814 struct anv_state samplers
[MESA_SHADER_STAGES
];
1817 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1818 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1819 * and before invoking the secondary in ExecuteCommands.
1821 bool pma_fix_enabled
;
1824 * Whether or not we know for certain that HiZ is enabled for the current
1825 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1826 * enabled or not, this will be false.
1831 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1832 * valid only when recording a render pass instance.
1834 struct anv_attachment_state
* attachments
;
1837 * Surface states for color render targets. These are stored in a single
1838 * flat array. For depth-stencil attachments, the surface state is simply
1841 struct anv_state render_pass_states
;
1844 * A null surface state of the right size to match the framebuffer. This
1845 * is one of the states in render_pass_states.
1847 struct anv_state null_surface_state
;
1850 struct anv_cmd_pool
{
1851 VkAllocationCallbacks alloc
;
1852 struct list_head cmd_buffers
;
1855 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1857 enum anv_cmd_buffer_exec_mode
{
1858 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1859 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1860 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1861 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1862 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1865 struct anv_cmd_buffer
{
1866 VK_LOADER_DATA _loader_data
;
1868 struct anv_device
* device
;
1870 struct anv_cmd_pool
* pool
;
1871 struct list_head pool_link
;
1873 struct anv_batch batch
;
1875 /* Fields required for the actual chain of anv_batch_bo's.
1877 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1879 struct list_head batch_bos
;
1880 enum anv_cmd_buffer_exec_mode exec_mode
;
1882 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1883 * referenced by this command buffer
1885 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1887 struct u_vector seen_bbos
;
1889 /* A vector of int32_t's for every block of binding tables.
1891 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1893 struct u_vector bt_block_states
;
1896 struct anv_reloc_list surface_relocs
;
1897 /** Last seen surface state block pool center bo offset */
1898 uint32_t last_ss_pool_center
;
1900 /* Serial for tracking buffer completion */
1903 /* Stream objects for storing temporary data */
1904 struct anv_state_stream surface_state_stream
;
1905 struct anv_state_stream dynamic_state_stream
;
1907 VkCommandBufferUsageFlags usage_flags
;
1908 VkCommandBufferLevel level
;
1910 struct anv_cmd_state state
;
1913 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1914 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1915 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1916 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1917 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1918 struct anv_cmd_buffer
*secondary
);
1919 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1920 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
1921 struct anv_cmd_buffer
*cmd_buffer
,
1922 const VkSemaphore
*in_semaphores
,
1923 uint32_t num_in_semaphores
,
1924 const VkSemaphore
*out_semaphores
,
1925 uint32_t num_out_semaphores
,
1928 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1931 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1932 gl_shader_stage stage
, uint32_t size
);
1933 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1934 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1935 (offsetof(struct anv_push_constants, field) + \
1936 sizeof(cmd_buffer->state.push_constants[0]->field)))
1938 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1939 const void *data
, uint32_t size
, uint32_t alignment
);
1940 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1941 uint32_t *a
, uint32_t *b
,
1942 uint32_t dwords
, uint32_t alignment
);
1945 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1947 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1948 uint32_t entries
, uint32_t *state_offset
);
1950 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1952 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1953 uint32_t size
, uint32_t alignment
);
1956 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1958 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1959 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1960 bool depth_clamp_enable
);
1961 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1963 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1964 struct anv_render_pass
*pass
,
1965 struct anv_framebuffer
*framebuffer
,
1966 const VkClearValue
*clear_values
);
1968 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1971 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1972 gl_shader_stage stage
);
1974 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1976 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1978 const struct anv_image_view
*
1979 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1982 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1983 uint32_t num_entries
,
1984 uint32_t *state_offset
,
1985 struct anv_state
*bt_state
);
1987 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1989 enum anv_fence_type
{
1990 ANV_FENCE_TYPE_NONE
= 0,
1992 ANV_FENCE_TYPE_SYNCOBJ
,
1995 enum anv_bo_fence_state
{
1996 /** Indicates that this is a new (or newly reset fence) */
1997 ANV_BO_FENCE_STATE_RESET
,
1999 /** Indicates that this fence has been submitted to the GPU but is still
2000 * (as far as we know) in use by the GPU.
2002 ANV_BO_FENCE_STATE_SUBMITTED
,
2004 ANV_BO_FENCE_STATE_SIGNALED
,
2007 struct anv_fence_impl
{
2008 enum anv_fence_type type
;
2011 /** Fence implementation for BO fences
2013 * These fences use a BO and a set of CPU-tracked state flags. The BO
2014 * is added to the object list of the last execbuf call in a QueueSubmit
2015 * and is marked EXEC_WRITE. The state flags track when the BO has been
2016 * submitted to the kernel. We need to do this because Vulkan lets you
2017 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
2018 * will say it's idle in this case.
2022 enum anv_bo_fence_state state
;
2025 /** DRM syncobj handle for syncobj-based fences */
2031 /* Permanent fence state. Every fence has some form of permanent state
2032 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
2033 * cross-process fences) or it could just be a dummy for use internally.
2035 struct anv_fence_impl permanent
;
2037 /* Temporary fence state. A fence *may* have temporary state. That state
2038 * is added to the fence by an import operation and is reset back to
2039 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
2040 * state cannot be signaled because the fence must already be signaled
2041 * before the temporary state can be exported from the fence in the other
2042 * process and imported here.
2044 struct anv_fence_impl temporary
;
2049 struct anv_state state
;
2052 enum anv_semaphore_type
{
2053 ANV_SEMAPHORE_TYPE_NONE
= 0,
2054 ANV_SEMAPHORE_TYPE_DUMMY
,
2055 ANV_SEMAPHORE_TYPE_BO
,
2056 ANV_SEMAPHORE_TYPE_SYNC_FILE
,
2057 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ
,
2060 struct anv_semaphore_impl
{
2061 enum anv_semaphore_type type
;
2064 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
2065 * This BO will be added to the object list on any execbuf2 calls for
2066 * which this semaphore is used as a wait or signal fence. When used as
2067 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
2071 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
2072 * If the semaphore is in the unsignaled state due to either just being
2073 * created or because it has been used for a wait, fd will be -1.
2077 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
2078 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
2079 * import so we don't need to bother with a userspace cache.
2085 struct anv_semaphore
{
2086 /* Permanent semaphore state. Every semaphore has some form of permanent
2087 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
2088 * (for cross-process semaphores0 or it could just be a dummy for use
2091 struct anv_semaphore_impl permanent
;
2093 /* Temporary semaphore state. A semaphore *may* have temporary state.
2094 * That state is added to the semaphore by an import operation and is reset
2095 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
2096 * semaphore with temporary state cannot be signaled because the semaphore
2097 * must already be signaled before the temporary state can be exported from
2098 * the semaphore in the other process and imported here.
2100 struct anv_semaphore_impl temporary
;
2103 void anv_semaphore_reset_temporary(struct anv_device
*device
,
2104 struct anv_semaphore
*semaphore
);
2106 struct anv_shader_module
{
2107 unsigned char sha1
[20];
2112 static inline gl_shader_stage
2113 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
2115 assert(__builtin_popcount(vk_stage
) == 1);
2116 return ffs(vk_stage
) - 1;
2119 static inline VkShaderStageFlagBits
2120 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
2122 return (1 << mesa_stage
);
2125 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2127 #define anv_foreach_stage(stage, stage_bits) \
2128 for (gl_shader_stage stage, \
2129 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2130 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2131 __tmp &= ~(1 << (stage)))
2133 struct anv_pipeline_bind_map
{
2134 uint32_t surface_count
;
2135 uint32_t sampler_count
;
2136 uint32_t image_count
;
2138 struct anv_pipeline_binding
* surface_to_descriptor
;
2139 struct anv_pipeline_binding
* sampler_to_descriptor
;
2142 struct anv_shader_bin_key
{
2147 struct anv_shader_bin
{
2150 const struct anv_shader_bin_key
*key
;
2152 struct anv_state kernel
;
2153 uint32_t kernel_size
;
2155 const struct brw_stage_prog_data
*prog_data
;
2156 uint32_t prog_data_size
;
2158 struct anv_pipeline_bind_map bind_map
;
2161 struct anv_shader_bin
*
2162 anv_shader_bin_create(struct anv_device
*device
,
2163 const void *key
, uint32_t key_size
,
2164 const void *kernel
, uint32_t kernel_size
,
2165 const struct brw_stage_prog_data
*prog_data
,
2166 uint32_t prog_data_size
, const void *prog_data_param
,
2167 const struct anv_pipeline_bind_map
*bind_map
);
2170 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
2173 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
2175 assert(shader
&& shader
->ref_cnt
>= 1);
2176 p_atomic_inc(&shader
->ref_cnt
);
2180 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
2182 assert(shader
&& shader
->ref_cnt
>= 1);
2183 if (p_atomic_dec_zero(&shader
->ref_cnt
))
2184 anv_shader_bin_destroy(device
, shader
);
2187 struct anv_pipeline
{
2188 struct anv_device
* device
;
2189 struct anv_batch batch
;
2190 uint32_t batch_data
[512];
2191 struct anv_reloc_list batch_relocs
;
2192 uint32_t dynamic_state_mask
;
2193 struct anv_dynamic_state dynamic_state
;
2195 struct anv_subpass
* subpass
;
2197 bool needs_data_cache
;
2199 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
2202 const struct gen_l3_config
* l3_config
;
2203 uint32_t total_size
;
2206 VkShaderStageFlags active_stages
;
2207 struct anv_state blend_state
;
2210 uint32_t binding_stride
[MAX_VBS
];
2211 bool instancing_enable
[MAX_VBS
];
2212 bool primitive_restart
;
2215 uint32_t cs_right_mask
;
2218 bool depth_test_enable
;
2219 bool writes_stencil
;
2220 bool stencil_test_enable
;
2221 bool depth_clamp_enable
;
2222 bool sample_shading_enable
;
2227 uint32_t depth_stencil_state
[3];
2233 uint32_t wm_depth_stencil
[3];
2237 uint32_t wm_depth_stencil
[4];
2240 uint32_t interface_descriptor_data
[8];
2244 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
2245 gl_shader_stage stage
)
2247 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
2250 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2251 static inline const struct brw_##prefix##_prog_data * \
2252 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2254 if (anv_pipeline_has_stage(pipeline, stage)) { \
2255 return (const struct brw_##prefix##_prog_data *) \
2256 pipeline->shaders[stage]->prog_data; \
2262 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
2263 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
2264 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
2265 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
2266 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
2267 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
2269 static inline const struct brw_vue_prog_data
*
2270 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
2272 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
2273 return &get_gs_prog_data(pipeline
)->base
;
2274 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
2275 return &get_tes_prog_data(pipeline
)->base
;
2277 return &get_vs_prog_data(pipeline
)->base
;
2281 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
2282 struct anv_pipeline_cache
*cache
,
2283 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2284 const VkAllocationCallbacks
*alloc
);
2287 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
2288 struct anv_pipeline_cache
*cache
,
2289 const VkComputePipelineCreateInfo
*info
,
2290 struct anv_shader_module
*module
,
2291 const char *entrypoint
,
2292 const VkSpecializationInfo
*spec_info
);
2294 struct anv_format_plane
{
2295 enum isl_format isl_format
:16;
2296 struct isl_swizzle swizzle
;
2298 /* Whether this plane contains chroma channels */
2301 /* For downscaling of YUV planes */
2302 uint8_t denominator_scales
[2];
2304 /* How to map sampled ycbcr planes to a single 4 component element. */
2305 struct isl_swizzle ycbcr_swizzle
;
2310 struct anv_format_plane planes
[3];
2315 static inline uint32_t
2316 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects
,
2317 VkImageAspectFlags aspect_mask
)
2319 switch (aspect_mask
) {
2320 case VK_IMAGE_ASPECT_COLOR_BIT
:
2321 case VK_IMAGE_ASPECT_DEPTH_BIT
:
2322 case VK_IMAGE_ASPECT_PLANE_0_BIT
:
2324 case VK_IMAGE_ASPECT_STENCIL_BIT
:
2325 if ((image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) == 0)
2328 case VK_IMAGE_ASPECT_PLANE_1_BIT
:
2330 case VK_IMAGE_ASPECT_PLANE_2_BIT
:
2333 /* Purposefully assert with depth/stencil aspects. */
2334 unreachable("invalid image aspect");
2338 static inline uint32_t
2339 anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask
)
2341 uint32_t planes
= 0;
2343 if (aspect_mask
& (VK_IMAGE_ASPECT_COLOR_BIT
|
2344 VK_IMAGE_ASPECT_DEPTH_BIT
|
2345 VK_IMAGE_ASPECT_STENCIL_BIT
|
2346 VK_IMAGE_ASPECT_PLANE_0_BIT
))
2348 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_1_BIT
)
2350 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_2_BIT
)
2356 static inline VkImageAspectFlags
2357 anv_plane_to_aspect(VkImageAspectFlags image_aspects
,
2360 if (image_aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
2361 if (_mesa_bitcount(image_aspects
) > 1)
2362 return VK_IMAGE_ASPECT_PLANE_0_BIT
<< plane
;
2363 return VK_IMAGE_ASPECT_COLOR_BIT
;
2365 if (image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)
2366 return VK_IMAGE_ASPECT_DEPTH_BIT
<< plane
;
2367 assert(image_aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
2368 return VK_IMAGE_ASPECT_STENCIL_BIT
;
2371 #define anv_foreach_image_aspect_bit(b, image, aspects) \
2372 for_each_bit(b, anv_image_expand_aspects(image, aspects))
2374 const struct anv_format
*
2375 anv_get_format(VkFormat format
);
2377 static inline uint32_t
2378 anv_get_format_planes(VkFormat vk_format
)
2380 const struct anv_format
*format
= anv_get_format(vk_format
);
2382 return format
!= NULL
? format
->n_planes
: 0;
2385 struct anv_format_plane
2386 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2387 VkImageAspectFlagBits aspect
, VkImageTiling tiling
);
2389 static inline enum isl_format
2390 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2391 VkImageAspectFlags aspect
, VkImageTiling tiling
)
2393 return anv_get_format_plane(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
2396 static inline struct isl_swizzle
2397 anv_swizzle_for_render(struct isl_swizzle swizzle
)
2399 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2400 * RGB as RGBA for texturing
2402 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
2403 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
2405 /* But it doesn't matter what we render to that channel */
2406 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
2412 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
2415 * Subsurface of an anv_image.
2417 struct anv_surface
{
2418 /** Valid only if isl_surf::size > 0. */
2419 struct isl_surf isl
;
2422 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2429 /* The original VkFormat provided by the client. This may not match any
2430 * of the actual surface formats.
2433 const struct anv_format
*format
;
2435 VkImageAspectFlags aspects
;
2438 uint32_t array_size
;
2439 uint32_t samples
; /**< VkImageCreateInfo::samples */
2441 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
2442 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
2444 /** True if this is needs to be bound to an appropriately tiled BO.
2446 * When not using modifiers, consumers such as X11, Wayland, and KMS need
2447 * the tiling passed via I915_GEM_SET_TILING. When exporting these buffers
2448 * we require a dedicated allocation so that we can know to allocate a
2451 bool needs_set_tiling
;
2454 * Must be DRM_FORMAT_MOD_INVALID unless tiling is
2455 * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
2457 uint64_t drm_format_mod
;
2462 /* Whether the image is made of several underlying buffer objects rather a
2463 * single one with different offsets.
2470 * For each foo, anv_image::planes[x].surface is valid if and only if
2471 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
2472 * to figure the number associated with a given aspect.
2474 * The hardware requires that the depth buffer and stencil buffer be
2475 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2476 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2477 * allocate the depth and stencil buffers as separate surfaces in the same
2482 * -----------------------
2484 * ----------------------- |
2485 * | shadow surface0 | |
2486 * ----------------------- | Plane 0
2487 * | aux surface0 | |
2488 * ----------------------- |
2489 * | fast clear colors0 | \|/
2490 * -----------------------
2492 * ----------------------- |
2493 * | shadow surface1 | |
2494 * ----------------------- | Plane 1
2495 * | aux surface1 | |
2496 * ----------------------- |
2497 * | fast clear colors1 | \|/
2498 * -----------------------
2501 * -----------------------
2505 * Offset of the entire plane (whenever the image is disjoint this is
2513 struct anv_surface surface
;
2516 * A surface which shadows the main surface and may have different
2517 * tiling. This is used for sampling using a tiling that isn't supported
2518 * for other operations.
2520 struct anv_surface shadow_surface
;
2523 * For color images, this is the aux usage for this image when not used
2524 * as a color attachment.
2526 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
2527 * image has a HiZ buffer.
2529 enum isl_aux_usage aux_usage
;
2531 struct anv_surface aux_surface
;
2534 * Offset of the fast clear state (used to compute the
2535 * fast_clear_state_offset of the following planes).
2537 uint32_t fast_clear_state_offset
;
2540 * BO associated with this plane, set when bound.
2543 VkDeviceSize bo_offset
;
2546 * When destroying the image, also free the bo.
2552 /* The ordering of this enum is important */
2553 enum anv_fast_clear_type
{
2554 /** Image does not have/support any fast-clear blocks */
2555 ANV_FAST_CLEAR_NONE
= 0,
2556 /** Image has/supports fast-clear but only to the default value */
2557 ANV_FAST_CLEAR_DEFAULT_VALUE
= 1,
2558 /** Image has/supports fast-clear with an arbitrary fast-clear value */
2559 ANV_FAST_CLEAR_ANY
= 2,
2562 /* Returns the number of auxiliary buffer levels attached to an image. */
2563 static inline uint8_t
2564 anv_image_aux_levels(const struct anv_image
* const image
,
2565 VkImageAspectFlagBits aspect
)
2567 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2568 return image
->planes
[plane
].aux_surface
.isl
.size
> 0 ?
2569 image
->planes
[plane
].aux_surface
.isl
.levels
: 0;
2572 /* Returns the number of auxiliary buffer layers attached to an image. */
2573 static inline uint32_t
2574 anv_image_aux_layers(const struct anv_image
* const image
,
2575 VkImageAspectFlagBits aspect
,
2576 const uint8_t miplevel
)
2580 /* The miplevel must exist in the main buffer. */
2581 assert(miplevel
< image
->levels
);
2583 if (miplevel
>= anv_image_aux_levels(image
, aspect
)) {
2584 /* There are no layers with auxiliary data because the miplevel has no
2589 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2590 return MAX2(image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.array_len
,
2591 image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.depth
>> miplevel
);
2595 static inline struct anv_address
2596 anv_image_get_clear_color_addr(const struct anv_device
*device
,
2597 const struct anv_image
*image
,
2598 VkImageAspectFlagBits aspect
)
2600 assert(image
->aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
2602 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2603 return (struct anv_address
) {
2604 .bo
= image
->planes
[plane
].bo
,
2605 .offset
= image
->planes
[plane
].bo_offset
+
2606 image
->planes
[plane
].fast_clear_state_offset
,
2610 static inline struct anv_address
2611 anv_image_get_fast_clear_type_addr(const struct anv_device
*device
,
2612 const struct anv_image
*image
,
2613 VkImageAspectFlagBits aspect
)
2615 struct anv_address addr
=
2616 anv_image_get_clear_color_addr(device
, image
, aspect
);
2618 const unsigned clear_color_state_size
= device
->info
.gen
>= 10 ?
2619 device
->isl_dev
.ss
.clear_color_state_size
:
2620 device
->isl_dev
.ss
.clear_value_size
;
2621 addr
.offset
+= clear_color_state_size
;
2625 static inline struct anv_address
2626 anv_image_get_compression_state_addr(const struct anv_device
*device
,
2627 const struct anv_image
*image
,
2628 VkImageAspectFlagBits aspect
,
2629 uint32_t level
, uint32_t array_layer
)
2631 assert(level
< anv_image_aux_levels(image
, aspect
));
2632 assert(array_layer
< anv_image_aux_layers(image
, aspect
, level
));
2633 UNUSED
uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2634 assert(image
->planes
[plane
].aux_usage
== ISL_AUX_USAGE_CCS_E
);
2636 struct anv_address addr
=
2637 anv_image_get_fast_clear_type_addr(device
, image
, aspect
);
2638 addr
.offset
+= 4; /* Go past the fast clear type */
2640 if (image
->type
== VK_IMAGE_TYPE_3D
) {
2641 for (uint32_t l
= 0; l
< level
; l
++)
2642 addr
.offset
+= anv_minify(image
->extent
.depth
, l
) * 4;
2644 addr
.offset
+= level
* image
->array_size
* 4;
2646 addr
.offset
+= array_layer
* 4;
2651 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
2653 anv_can_sample_with_hiz(const struct gen_device_info
* const devinfo
,
2654 const struct anv_image
*image
)
2656 if (!(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
))
2659 if (devinfo
->gen
< 8)
2662 return image
->samples
== 1;
2666 anv_cmd_buffer_mark_image_written(struct anv_cmd_buffer
*cmd_buffer
,
2667 const struct anv_image
*image
,
2668 VkImageAspectFlagBits aspect
,
2669 enum isl_aux_usage aux_usage
,
2671 uint32_t base_layer
,
2672 uint32_t layer_count
);
2675 anv_image_clear_color(struct anv_cmd_buffer
*cmd_buffer
,
2676 const struct anv_image
*image
,
2677 VkImageAspectFlagBits aspect
,
2678 enum isl_aux_usage aux_usage
,
2679 enum isl_format format
, struct isl_swizzle swizzle
,
2680 uint32_t level
, uint32_t base_layer
, uint32_t layer_count
,
2681 VkRect2D area
, union isl_color_value clear_color
);
2683 anv_image_clear_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
2684 const struct anv_image
*image
,
2685 VkImageAspectFlags aspects
,
2686 enum isl_aux_usage depth_aux_usage
,
2688 uint32_t base_layer
, uint32_t layer_count
,
2690 float depth_value
, uint8_t stencil_value
);
2692 anv_image_hiz_op(struct anv_cmd_buffer
*cmd_buffer
,
2693 const struct anv_image
*image
,
2694 VkImageAspectFlagBits aspect
, uint32_t level
,
2695 uint32_t base_layer
, uint32_t layer_count
,
2696 enum isl_aux_op hiz_op
);
2698 anv_image_hiz_clear(struct anv_cmd_buffer
*cmd_buffer
,
2699 const struct anv_image
*image
,
2700 VkImageAspectFlags aspects
,
2702 uint32_t base_layer
, uint32_t layer_count
,
2703 VkRect2D area
, uint8_t stencil_value
);
2705 anv_image_mcs_op(struct anv_cmd_buffer
*cmd_buffer
,
2706 const struct anv_image
*image
,
2707 VkImageAspectFlagBits aspect
,
2708 uint32_t base_layer
, uint32_t layer_count
,
2709 enum isl_aux_op mcs_op
, bool predicate
);
2711 anv_image_ccs_op(struct anv_cmd_buffer
*cmd_buffer
,
2712 const struct anv_image
*image
,
2713 VkImageAspectFlagBits aspect
, uint32_t level
,
2714 uint32_t base_layer
, uint32_t layer_count
,
2715 enum isl_aux_op ccs_op
, bool predicate
);
2718 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
2719 const struct anv_image
*image
,
2720 uint32_t base_level
, uint32_t level_count
,
2721 uint32_t base_layer
, uint32_t layer_count
);
2724 anv_layout_to_aux_usage(const struct gen_device_info
* const devinfo
,
2725 const struct anv_image
*image
,
2726 const VkImageAspectFlagBits aspect
,
2727 const VkImageLayout layout
);
2729 enum anv_fast_clear_type
2730 anv_layout_to_fast_clear_type(const struct gen_device_info
* const devinfo
,
2731 const struct anv_image
* const image
,
2732 const VkImageAspectFlagBits aspect
,
2733 const VkImageLayout layout
);
2735 /* This is defined as a macro so that it works for both
2736 * VkImageSubresourceRange and VkImageSubresourceLayers
2738 #define anv_get_layerCount(_image, _range) \
2739 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
2740 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
2742 static inline uint32_t
2743 anv_get_levelCount(const struct anv_image
*image
,
2744 const VkImageSubresourceRange
*range
)
2746 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
2747 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
2750 static inline VkImageAspectFlags
2751 anv_image_expand_aspects(const struct anv_image
*image
,
2752 VkImageAspectFlags aspects
)
2754 /* If the underlying image has color plane aspects and
2755 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
2756 * the underlying image. */
2757 if ((image
->aspects
& VK_IMAGE_ASPECT_PLANES_BITS_ANV
) != 0 &&
2758 aspects
== VK_IMAGE_ASPECT_COLOR_BIT
)
2759 return image
->aspects
;
2765 anv_image_aspects_compatible(VkImageAspectFlags aspects1
,
2766 VkImageAspectFlags aspects2
)
2768 if (aspects1
== aspects2
)
2771 /* Only 1 color aspects are compatibles. */
2772 if ((aspects1
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2773 (aspects2
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2774 _mesa_bitcount(aspects1
) == _mesa_bitcount(aspects2
))
2780 struct anv_image_view
{
2781 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
2783 VkImageAspectFlags aspect_mask
;
2785 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2789 uint32_t image_plane
;
2791 struct isl_view isl
;
2794 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2795 * image layout of SHADER_READ_ONLY_OPTIMAL or
2796 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
2798 struct anv_surface_state optimal_sampler_surface_state
;
2801 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2802 * image layout of GENERAL.
2804 struct anv_surface_state general_sampler_surface_state
;
2807 * RENDER_SURFACE_STATE when using image as a storage image. Separate
2808 * states for write-only and readable, using the real format for
2809 * write-only and the lowered format for readable.
2811 struct anv_surface_state storage_surface_state
;
2812 struct anv_surface_state writeonly_storage_surface_state
;
2814 struct brw_image_param storage_image_param
;
2818 enum anv_image_view_state_flags
{
2819 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY
= (1 << 0),
2820 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL
= (1 << 1),
2823 void anv_image_fill_surface_state(struct anv_device
*device
,
2824 const struct anv_image
*image
,
2825 VkImageAspectFlagBits aspect
,
2826 const struct isl_view
*view
,
2827 isl_surf_usage_flags_t view_usage
,
2828 enum isl_aux_usage aux_usage
,
2829 const union isl_color_value
*clear_color
,
2830 enum anv_image_view_state_flags flags
,
2831 struct anv_surface_state
*state_inout
,
2832 struct brw_image_param
*image_param_out
);
2834 struct anv_image_create_info
{
2835 const VkImageCreateInfo
*vk_info
;
2837 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
2838 isl_tiling_flags_t isl_tiling_flags
;
2840 /** These flags will be added to any derived from VkImageCreateInfo. */
2841 isl_surf_usage_flags_t isl_extra_usage_flags
;
2846 VkResult
anv_image_create(VkDevice _device
,
2847 const struct anv_image_create_info
*info
,
2848 const VkAllocationCallbacks
* alloc
,
2852 VkResult
anv_image_from_gralloc(VkDevice device_h
,
2853 const VkImageCreateInfo
*base_info
,
2854 const VkNativeBufferANDROID
*gralloc_info
,
2855 const VkAllocationCallbacks
*alloc
,
2859 const struct anv_surface
*
2860 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
2861 VkImageAspectFlags aspect_mask
);
2864 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
2866 static inline struct VkExtent3D
2867 anv_sanitize_image_extent(const VkImageType imageType
,
2868 const struct VkExtent3D imageExtent
)
2870 switch (imageType
) {
2871 case VK_IMAGE_TYPE_1D
:
2872 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
2873 case VK_IMAGE_TYPE_2D
:
2874 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
2875 case VK_IMAGE_TYPE_3D
:
2878 unreachable("invalid image type");
2882 static inline struct VkOffset3D
2883 anv_sanitize_image_offset(const VkImageType imageType
,
2884 const struct VkOffset3D imageOffset
)
2886 switch (imageType
) {
2887 case VK_IMAGE_TYPE_1D
:
2888 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
2889 case VK_IMAGE_TYPE_2D
:
2890 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
2891 case VK_IMAGE_TYPE_3D
:
2894 unreachable("invalid image type");
2899 void anv_fill_buffer_surface_state(struct anv_device
*device
,
2900 struct anv_state state
,
2901 enum isl_format format
,
2902 uint32_t offset
, uint32_t range
,
2906 anv_clear_color_from_att_state(union isl_color_value
*clear_color
,
2907 const struct anv_attachment_state
*att_state
,
2908 const struct anv_image_view
*iview
)
2910 const struct isl_format_layout
*view_fmtl
=
2911 isl_format_get_layout(iview
->planes
[0].isl
.format
);
2913 #define COPY_CLEAR_COLOR_CHANNEL(c, i) \
2914 if (view_fmtl->channels.c.bits) \
2915 clear_color->u32[i] = att_state->clear_value.color.uint32[i]
2917 COPY_CLEAR_COLOR_CHANNEL(r
, 0);
2918 COPY_CLEAR_COLOR_CHANNEL(g
, 1);
2919 COPY_CLEAR_COLOR_CHANNEL(b
, 2);
2920 COPY_CLEAR_COLOR_CHANNEL(a
, 3);
2922 #undef COPY_CLEAR_COLOR_CHANNEL
2926 struct anv_ycbcr_conversion
{
2927 const struct anv_format
* format
;
2928 VkSamplerYcbcrModelConversion ycbcr_model
;
2929 VkSamplerYcbcrRange ycbcr_range
;
2930 VkComponentSwizzle mapping
[4];
2931 VkChromaLocation chroma_offsets
[2];
2932 VkFilter chroma_filter
;
2933 bool chroma_reconstruction
;
2936 struct anv_sampler
{
2937 uint32_t state
[3][4];
2939 struct anv_ycbcr_conversion
*conversion
;
2942 struct anv_framebuffer
{
2947 uint32_t attachment_count
;
2948 struct anv_image_view
* attachments
[0];
2951 struct anv_subpass_attachment
{
2952 VkImageUsageFlagBits usage
;
2953 uint32_t attachment
;
2954 VkImageLayout layout
;
2957 struct anv_subpass
{
2958 uint32_t attachment_count
;
2961 * A pointer to all attachment references used in this subpass.
2962 * Only valid if ::attachment_count > 0.
2964 struct anv_subpass_attachment
* attachments
;
2965 uint32_t input_count
;
2966 struct anv_subpass_attachment
* input_attachments
;
2967 uint32_t color_count
;
2968 struct anv_subpass_attachment
* color_attachments
;
2969 struct anv_subpass_attachment
* resolve_attachments
;
2971 struct anv_subpass_attachment depth_stencil_attachment
;
2975 /** Subpass has a depth/stencil self-dependency */
2976 bool has_ds_self_dep
;
2978 /** Subpass has at least one resolve attachment */
2982 static inline unsigned
2983 anv_subpass_view_count(const struct anv_subpass
*subpass
)
2985 return MAX2(1, _mesa_bitcount(subpass
->view_mask
));
2988 struct anv_render_pass_attachment
{
2989 /* TODO: Consider using VkAttachmentDescription instead of storing each of
2990 * its members individually.
2994 VkImageUsageFlags usage
;
2995 VkAttachmentLoadOp load_op
;
2996 VkAttachmentStoreOp store_op
;
2997 VkAttachmentLoadOp stencil_load_op
;
2998 VkImageLayout initial_layout
;
2999 VkImageLayout final_layout
;
3000 VkImageLayout first_subpass_layout
;
3002 /* The subpass id in which the attachment will be used last. */
3003 uint32_t last_subpass_idx
;
3006 struct anv_render_pass
{
3007 uint32_t attachment_count
;
3008 uint32_t subpass_count
;
3009 /* An array of subpass_count+1 flushes, one per subpass boundary */
3010 enum anv_pipe_bits
* subpass_flushes
;
3011 struct anv_render_pass_attachment
* attachments
;
3012 struct anv_subpass subpasses
[0];
3015 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
3017 struct anv_query_pool
{
3019 VkQueryPipelineStatisticFlags pipeline_statistics
;
3020 /** Stride between slots, in bytes */
3022 /** Number of slots in this query pool */
3027 int anv_get_entrypoint_index(const char *name
);
3030 anv_entrypoint_is_enabled(int index
, uint32_t core_version
,
3031 const struct anv_instance_extension_table
*instance
,
3032 const struct anv_device_extension_table
*device
);
3034 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
3037 void anv_dump_image_to_ppm(struct anv_device
*device
,
3038 struct anv_image
*image
, unsigned miplevel
,
3039 unsigned array_layer
, VkImageAspectFlagBits aspect
,
3040 const char *filename
);
3042 enum anv_dump_action
{
3043 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
3046 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
3047 void anv_dump_finish(void);
3049 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
3050 struct anv_framebuffer
*fb
);
3052 static inline uint32_t
3053 anv_get_subpass_id(const struct anv_cmd_state
* const cmd_state
)
3055 /* This function must be called from within a subpass. */
3056 assert(cmd_state
->pass
&& cmd_state
->subpass
);
3058 const uint32_t subpass_id
= cmd_state
->subpass
- cmd_state
->pass
->subpasses
;
3060 /* The id of this subpass shouldn't exceed the number of subpasses in this
3061 * render pass minus 1.
3063 assert(subpass_id
< cmd_state
->pass
->subpass_count
);
3067 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
3069 static inline struct __anv_type * \
3070 __anv_type ## _from_handle(__VkType _handle) \
3072 return (struct __anv_type *) _handle; \
3075 static inline __VkType \
3076 __anv_type ## _to_handle(struct __anv_type *_obj) \
3078 return (__VkType) _obj; \
3081 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
3083 static inline struct __anv_type * \
3084 __anv_type ## _from_handle(__VkType _handle) \
3086 return (struct __anv_type *)(uintptr_t) _handle; \
3089 static inline __VkType \
3090 __anv_type ## _to_handle(struct __anv_type *_obj) \
3092 return (__VkType)(uintptr_t) _obj; \
3095 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
3096 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
3098 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
3099 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
3100 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
3101 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
3102 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
3104 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
3105 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
3106 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
3107 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
3108 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
3109 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
3110 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template
, VkDescriptorUpdateTemplateKHR
)
3111 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
3112 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
3113 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
3114 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
3115 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
3116 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
3117 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
3118 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
3119 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
3120 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
3121 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
3122 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
3123 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore
, VkSemaphore
)
3124 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
3125 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback
, VkDebugReportCallbackEXT
)
3126 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion
, VkSamplerYcbcrConversion
)
3128 /* Gen-specific function declarations */
3130 # include "anv_genX.h"
3132 # define genX(x) gen7_##x
3133 # include "anv_genX.h"
3135 # define genX(x) gen75_##x
3136 # include "anv_genX.h"
3138 # define genX(x) gen8_##x
3139 # include "anv_genX.h"
3141 # define genX(x) gen9_##x
3142 # include "anv_genX.h"
3144 # define genX(x) gen10_##x
3145 # include "anv_genX.h"
3147 # define genX(x) gen11_##x
3148 # include "anv_genX.h"
3152 #endif /* ANV_PRIVATE_H */