2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
39 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
44 #include "common/gen_clflush.h"
45 #include "common/gen_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 #define ANV_SVGS_VB_INDEX MAX_VBS
108 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
110 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
112 static inline uint32_t
113 align_down_npot_u32(uint32_t v
, uint32_t a
)
118 static inline uint32_t
119 align_u32(uint32_t v
, uint32_t a
)
121 assert(a
!= 0 && a
== (a
& -a
));
122 return (v
+ a
- 1) & ~(a
- 1);
125 static inline uint64_t
126 align_u64(uint64_t v
, uint64_t a
)
128 assert(a
!= 0 && a
== (a
& -a
));
129 return (v
+ a
- 1) & ~(a
- 1);
132 static inline int32_t
133 align_i32(int32_t v
, int32_t a
)
135 assert(a
!= 0 && a
== (a
& -a
));
136 return (v
+ a
- 1) & ~(a
- 1);
139 /** Alignment must be a power of 2. */
141 anv_is_aligned(uintmax_t n
, uintmax_t a
)
143 assert(a
== (a
& -a
));
144 return (n
& (a
- 1)) == 0;
147 static inline uint32_t
148 anv_minify(uint32_t n
, uint32_t levels
)
150 if (unlikely(n
== 0))
153 return MAX2(n
>> levels
, 1);
157 anv_clamp_f(float f
, float min
, float max
)
170 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
172 if (*inout_mask
& clear_mask
) {
173 *inout_mask
&= ~clear_mask
;
180 static inline union isl_color_value
181 vk_to_isl_color(VkClearColorValue color
)
183 return (union isl_color_value
) {
193 #define for_each_bit(b, dword) \
194 for (uint32_t __dword = (dword); \
195 (b) = __builtin_ffs(__dword) - 1, __dword; \
196 __dword &= ~(1 << (b)))
198 #define typed_memcpy(dest, src, count) ({ \
199 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
200 memcpy((dest), (src), (count) * sizeof(*(src))); \
203 /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
204 * to be added here in order to utilize mapping in debug/error/perf macros.
206 #define REPORT_OBJECT_TYPE(o) \
207 __builtin_choose_expr ( \
208 __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
209 VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
210 __builtin_choose_expr ( \
211 __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
212 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
213 __builtin_choose_expr ( \
214 __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
215 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
216 __builtin_choose_expr ( \
217 __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
218 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
219 __builtin_choose_expr ( \
220 __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
221 VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
222 __builtin_choose_expr ( \
223 __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
224 VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
225 __builtin_choose_expr ( \
226 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
227 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
228 __builtin_choose_expr ( \
229 __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
230 VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
231 __builtin_choose_expr ( \
232 __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
233 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
234 __builtin_choose_expr ( \
235 __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
236 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
237 __builtin_choose_expr ( \
238 __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
239 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
240 __builtin_choose_expr ( \
241 __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
242 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
243 __builtin_choose_expr ( \
244 __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
245 VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
246 __builtin_choose_expr ( \
247 __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
248 VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
249 __builtin_choose_expr ( \
250 __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
251 VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
252 __builtin_choose_expr ( \
253 __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
254 VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
255 __builtin_choose_expr ( \
256 __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
257 VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
258 __builtin_choose_expr ( \
259 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
260 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
261 __builtin_choose_expr ( \
262 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
263 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
264 __builtin_choose_expr ( \
265 __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
266 VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
267 __builtin_choose_expr ( \
268 __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
269 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
270 __builtin_choose_expr ( \
271 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
272 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
273 __builtin_choose_expr ( \
274 __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
275 VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
276 __builtin_choose_expr ( \
277 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
278 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
279 __builtin_choose_expr ( \
280 __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
281 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
282 __builtin_choose_expr ( \
283 __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
284 VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
285 __builtin_choose_expr ( \
286 __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
287 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
288 __builtin_choose_expr ( \
289 __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
290 VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
291 __builtin_choose_expr ( \
292 __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
293 VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
294 __builtin_choose_expr ( \
295 __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
296 VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
297 __builtin_choose_expr ( \
298 __builtin_types_compatible_p (__typeof (o), void*), \
299 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
300 /* The void expression results in a compile-time error \
301 when assigning the result to something. */ \
302 (void)0)))))))))))))))))))))))))))))))
304 /* Whenever we generate an error, pass it through this function. Useful for
305 * debugging, where we can break on it. Only call at error site, not when
306 * propagating errors. Might be useful to plug in a stack trace here.
309 VkResult
__vk_errorf(struct anv_instance
*instance
, const void *object
,
310 VkDebugReportObjectTypeEXT type
, VkResult error
,
311 const char *file
, int line
, const char *format
, ...);
314 #define vk_error(error) __vk_errorf(NULL, NULL,\
315 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
316 error, __FILE__, __LINE__, NULL);
317 #define vk_errorf(instance, obj, error, format, ...)\
318 __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
319 __FILE__, __LINE__, format, ## __VA_ARGS__);
321 #define vk_error(error) error
322 #define vk_errorf(instance, obj, error, format, ...) error
326 * Warn on ignored extension structs.
328 * The Vulkan spec requires us to ignore unsupported or unknown structs in
329 * a pNext chain. In debug mode, emitting warnings for ignored structs may
330 * help us discover structs that we should not have ignored.
333 * From the Vulkan 1.0.38 spec:
335 * Any component of the implementation (the loader, any enabled layers,
336 * and drivers) must skip over, without processing (other than reading the
337 * sType and pNext members) any chained structures with sType values not
338 * defined by extensions supported by that component.
340 #define anv_debug_ignored_stype(sType) \
341 intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
343 void __anv_perf_warn(struct anv_instance
*instance
, const void *object
,
344 VkDebugReportObjectTypeEXT type
, const char *file
,
345 int line
, const char *format
, ...)
346 anv_printflike(6, 7);
347 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
348 void anv_loge_v(const char *format
, va_list va
);
351 * Print a FINISHME message, including its source location.
353 #define anv_finishme(format, ...) \
355 static bool reported = false; \
357 intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
364 * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
366 #define anv_perf_warn(instance, obj, format, ...) \
368 static bool reported = false; \
369 if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
370 __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
371 format, ##__VA_ARGS__); \
376 /* A non-fatal assert. Useful for debugging. */
378 #define anv_assert(x) ({ \
379 if (unlikely(!(x))) \
380 intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
383 #define anv_assert(x)
386 /* A multi-pointer allocator
388 * When copying data structures from the user (such as a render pass), it's
389 * common to need to allocate data for a bunch of different things. Instead
390 * of doing several allocations and having to handle all of the error checking
391 * that entails, it can be easier to do a single allocation. This struct
392 * helps facilitate that. The intended usage looks like this:
395 * anv_multialloc_add(&ma, &main_ptr, 1);
396 * anv_multialloc_add(&ma, &substruct1, substruct1Count);
397 * anv_multialloc_add(&ma, &substruct2, substruct2Count);
399 * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
400 * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
402 struct anv_multialloc
{
410 #define ANV_MULTIALLOC_INIT \
411 ((struct anv_multialloc) { 0, })
413 #define ANV_MULTIALLOC(_name) \
414 struct anv_multialloc _name = ANV_MULTIALLOC_INIT
416 __attribute__((always_inline
))
418 _anv_multialloc_add(struct anv_multialloc
*ma
,
419 void **ptr
, size_t size
, size_t align
)
421 size_t offset
= align_u64(ma
->size
, align
);
422 ma
->size
= offset
+ size
;
423 ma
->align
= MAX2(ma
->align
, align
);
425 /* Store the offset in the pointer. */
426 *ptr
= (void *)(uintptr_t)offset
;
428 assert(ma
->ptr_count
< ARRAY_SIZE(ma
->ptrs
));
429 ma
->ptrs
[ma
->ptr_count
++] = ptr
;
432 #define anv_multialloc_add_size(_ma, _ptr, _size) \
433 _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
435 #define anv_multialloc_add(_ma, _ptr, _count) \
436 anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
438 __attribute__((always_inline
))
440 anv_multialloc_alloc(struct anv_multialloc
*ma
,
441 const VkAllocationCallbacks
*alloc
,
442 VkSystemAllocationScope scope
)
444 void *ptr
= vk_alloc(alloc
, ma
->size
, ma
->align
, scope
);
448 /* Fill out each of the pointers with their final value.
450 * for (uint32_t i = 0; i < ma->ptr_count; i++)
451 * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
453 * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
454 * constant, GCC is incapable of figuring this out and unrolling the loop
455 * so we have to give it a little help.
457 STATIC_ASSERT(ARRAY_SIZE(ma
->ptrs
) == 8);
458 #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
459 if ((_i) < ma->ptr_count) \
460 *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
461 _ANV_MULTIALLOC_UPDATE_POINTER(0);
462 _ANV_MULTIALLOC_UPDATE_POINTER(1);
463 _ANV_MULTIALLOC_UPDATE_POINTER(2);
464 _ANV_MULTIALLOC_UPDATE_POINTER(3);
465 _ANV_MULTIALLOC_UPDATE_POINTER(4);
466 _ANV_MULTIALLOC_UPDATE_POINTER(5);
467 _ANV_MULTIALLOC_UPDATE_POINTER(6);
468 _ANV_MULTIALLOC_UPDATE_POINTER(7);
469 #undef _ANV_MULTIALLOC_UPDATE_POINTER
474 __attribute__((always_inline
))
476 anv_multialloc_alloc2(struct anv_multialloc
*ma
,
477 const VkAllocationCallbacks
*parent_alloc
,
478 const VkAllocationCallbacks
*alloc
,
479 VkSystemAllocationScope scope
)
481 return anv_multialloc_alloc(ma
, alloc
? alloc
: parent_alloc
, scope
);
487 /* Index into the current validation list. This is used by the
488 * validation list building alrogithm to track which buffers are already
489 * in the validation list so that we can ensure uniqueness.
493 /* Last known offset. This value is provided by the kernel when we
494 * execbuf and is used as the presumed offset for the next bunch of
502 /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
507 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
509 bo
->gem_handle
= gem_handle
;
517 /* Represents a lock-free linked list of "free" things. This is used by
518 * both the block pool and the state pools. Unfortunately, in order to
519 * solve the ABA problem, we can't use a single uint32_t head.
521 union anv_free_list
{
525 /* A simple count that is incremented every time the head changes. */
531 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
533 struct anv_block_state
{
543 struct anv_block_pool
{
544 struct anv_device
*device
;
550 /* The offset from the start of the bo to the "center" of the block
551 * pool. Pointers to allocated blocks are given by
552 * bo.map + center_bo_offset + offsets.
554 uint32_t center_bo_offset
;
556 /* Current memory map of the block pool. This pointer may or may not
557 * point to the actual beginning of the block pool memory. If
558 * anv_block_pool_alloc_back has ever been called, then this pointer
559 * will point to the "center" position of the buffer and all offsets
560 * (negative or positive) given out by the block pool alloc functions
561 * will be valid relative to this pointer.
563 * In particular, map == bo.map + center_offset
569 * Array of mmaps and gem handles owned by the block pool, reclaimed when
570 * the block pool is destroyed.
572 struct u_vector mmap_cleanups
;
574 struct anv_block_state state
;
576 struct anv_block_state back_state
;
579 /* Block pools are backed by a fixed-size 1GB memfd */
580 #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
582 /* The center of the block pool is also the middle of the memfd. This may
583 * change in the future if we decide differently for some reason.
585 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
587 static inline uint32_t
588 anv_block_pool_size(struct anv_block_pool
*pool
)
590 return pool
->state
.end
+ pool
->back_state
.end
;
599 #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
601 struct anv_fixed_size_state_pool
{
602 union anv_free_list free_list
;
603 struct anv_block_state block
;
606 #define ANV_MIN_STATE_SIZE_LOG2 6
607 #define ANV_MAX_STATE_SIZE_LOG2 20
609 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
611 struct anv_state_pool
{
612 struct anv_block_pool block_pool
;
614 /* The size of blocks which will be allocated from the block pool */
617 /** Free list for "back" allocations */
618 union anv_free_list back_alloc_free_list
;
620 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
623 struct anv_state_stream_block
;
625 struct anv_state_stream
{
626 struct anv_state_pool
*state_pool
;
628 /* The size of blocks to allocate from the state pool */
631 /* Current block we're allocating from */
632 struct anv_state block
;
634 /* Offset into the current block at which to allocate the next state */
637 /* List of all blocks allocated from this pool */
638 struct anv_state_stream_block
*block_list
;
641 /* The block_pool functions exported for testing only. The block pool should
642 * only be used via a state pool (see below).
644 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
645 struct anv_device
*device
,
646 uint32_t initial_size
,
648 void anv_block_pool_finish(struct anv_block_pool
*pool
);
649 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
,
650 uint32_t block_size
);
651 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
,
652 uint32_t block_size
);
654 VkResult
anv_state_pool_init(struct anv_state_pool
*pool
,
655 struct anv_device
*device
,
658 void anv_state_pool_finish(struct anv_state_pool
*pool
);
659 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
660 uint32_t state_size
, uint32_t alignment
);
661 struct anv_state
anv_state_pool_alloc_back(struct anv_state_pool
*pool
);
662 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
663 void anv_state_stream_init(struct anv_state_stream
*stream
,
664 struct anv_state_pool
*state_pool
,
665 uint32_t block_size
);
666 void anv_state_stream_finish(struct anv_state_stream
*stream
);
667 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
668 uint32_t size
, uint32_t alignment
);
671 * Implements a pool of re-usable BOs. The interface is identical to that
672 * of block_pool except that each block is its own BO.
675 struct anv_device
*device
;
682 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
,
684 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
685 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
687 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
689 struct anv_scratch_bo
{
694 struct anv_scratch_pool
{
695 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
696 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
699 void anv_scratch_pool_init(struct anv_device
*device
,
700 struct anv_scratch_pool
*pool
);
701 void anv_scratch_pool_finish(struct anv_device
*device
,
702 struct anv_scratch_pool
*pool
);
703 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
704 struct anv_scratch_pool
*pool
,
705 gl_shader_stage stage
,
706 unsigned per_thread_scratch
);
708 /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
709 struct anv_bo_cache
{
710 struct hash_table
*bo_map
;
711 pthread_mutex_t mutex
;
714 VkResult
anv_bo_cache_init(struct anv_bo_cache
*cache
);
715 void anv_bo_cache_finish(struct anv_bo_cache
*cache
);
716 VkResult
anv_bo_cache_alloc(struct anv_device
*device
,
717 struct anv_bo_cache
*cache
,
718 uint64_t size
, struct anv_bo
**bo
);
719 VkResult
anv_bo_cache_import(struct anv_device
*device
,
720 struct anv_bo_cache
*cache
,
721 int fd
, struct anv_bo
**bo
);
722 VkResult
anv_bo_cache_export(struct anv_device
*device
,
723 struct anv_bo_cache
*cache
,
724 struct anv_bo
*bo_in
, int *fd_out
);
725 void anv_bo_cache_release(struct anv_device
*device
,
726 struct anv_bo_cache
*cache
,
729 struct anv_memory_type
{
730 /* Standard bits passed on to the client */
731 VkMemoryPropertyFlags propertyFlags
;
734 /* Driver-internal book-keeping */
735 VkBufferUsageFlags valid_buffer_usage
;
738 struct anv_memory_heap
{
739 /* Standard bits passed on to the client */
741 VkMemoryHeapFlags flags
;
743 /* Driver-internal book-keeping */
744 bool supports_48bit_addresses
;
747 struct anv_physical_device
{
748 VK_LOADER_DATA _loader_data
;
750 struct anv_instance
* instance
;
754 struct gen_device_info info
;
755 /** Amount of "GPU memory" we want to advertise
757 * Clearly, this value is bogus since Intel is a UMA architecture. On
758 * gen7 platforms, we are limited by GTT size unless we want to implement
759 * fine-grained tracking and GTT splitting. On Broadwell and above we are
760 * practically unlimited. However, we will never report more than 3/4 of
761 * the total system ram to try and avoid running out of RAM.
763 bool supports_48bit_addresses
;
764 struct brw_compiler
* compiler
;
765 struct isl_device isl_dev
;
766 int cmd_parser_version
;
768 bool has_exec_capture
;
771 bool has_syncobj_wait
;
774 uint32_t subslice_total
;
778 struct anv_memory_type types
[VK_MAX_MEMORY_TYPES
];
780 struct anv_memory_heap heaps
[VK_MAX_MEMORY_HEAPS
];
783 uint8_t pipeline_cache_uuid
[VK_UUID_SIZE
];
784 uint8_t driver_uuid
[VK_UUID_SIZE
];
785 uint8_t device_uuid
[VK_UUID_SIZE
];
787 struct wsi_device wsi_device
;
791 struct anv_instance
{
792 VK_LOADER_DATA _loader_data
;
794 VkAllocationCallbacks alloc
;
797 struct anv_instance_extension_table enabled_extensions
;
799 int physicalDeviceCount
;
800 struct anv_physical_device physicalDevice
;
802 struct vk_debug_report_instance debug_report_callbacks
;
805 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
806 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
808 uint32_t anv_physical_device_api_version(struct anv_physical_device
*dev
);
809 bool anv_physical_device_extension_supported(struct anv_physical_device
*dev
,
813 VK_LOADER_DATA _loader_data
;
815 struct anv_device
* device
;
817 struct anv_state_pool
* pool
;
820 struct anv_pipeline_cache
{
821 struct anv_device
* device
;
822 pthread_mutex_t mutex
;
824 struct hash_table
* cache
;
827 struct anv_pipeline_bind_map
;
829 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
830 struct anv_device
*device
,
832 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
834 struct anv_shader_bin
*
835 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
836 const void *key
, uint32_t key_size
);
837 struct anv_shader_bin
*
838 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
839 const void *key_data
, uint32_t key_size
,
840 const void *kernel_data
, uint32_t kernel_size
,
841 const struct brw_stage_prog_data
*prog_data
,
842 uint32_t prog_data_size
,
843 const struct anv_pipeline_bind_map
*bind_map
);
846 VK_LOADER_DATA _loader_data
;
848 VkAllocationCallbacks alloc
;
850 struct anv_instance
* instance
;
852 struct gen_device_info info
;
853 struct isl_device isl_dev
;
856 bool can_chain_batches
;
857 bool robust_buffer_access
;
859 struct anv_bo_pool batch_bo_pool
;
861 struct anv_bo_cache bo_cache
;
863 struct anv_state_pool dynamic_state_pool
;
864 struct anv_state_pool instruction_state_pool
;
865 struct anv_state_pool surface_state_pool
;
867 struct anv_bo workaround_bo
;
868 struct anv_bo trivial_batch_bo
;
870 struct anv_pipeline_cache blorp_shader_cache
;
871 struct blorp_context blorp
;
873 struct anv_state border_colors
;
875 struct anv_queue queue
;
877 struct anv_scratch_pool scratch_pool
;
879 uint32_t default_mocs
;
881 pthread_mutex_t mutex
;
882 pthread_cond_t queue_submit
;
887 anv_state_flush(struct anv_device
*device
, struct anv_state state
)
889 if (device
->info
.has_llc
)
892 gen_flush_range(state
.map
, state
.alloc_size
);
895 void anv_device_init_blorp(struct anv_device
*device
);
896 void anv_device_finish_blorp(struct anv_device
*device
);
898 VkResult
anv_device_execbuf(struct anv_device
*device
,
899 struct drm_i915_gem_execbuffer2
*execbuf
,
900 struct anv_bo
**execbuf_bos
);
901 VkResult
anv_device_query_status(struct anv_device
*device
);
902 VkResult
anv_device_bo_busy(struct anv_device
*device
, struct anv_bo
*bo
);
903 VkResult
anv_device_wait(struct anv_device
*device
, struct anv_bo
*bo
,
906 void* anv_gem_mmap(struct anv_device
*device
,
907 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
908 void anv_gem_munmap(void *p
, uint64_t size
);
909 uint32_t anv_gem_create(struct anv_device
*device
, uint64_t size
);
910 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
911 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
912 int anv_gem_busy(struct anv_device
*device
, uint32_t gem_handle
);
913 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
914 int anv_gem_execbuffer(struct anv_device
*device
,
915 struct drm_i915_gem_execbuffer2
*execbuf
);
916 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
917 uint32_t stride
, uint32_t tiling
);
918 int anv_gem_create_context(struct anv_device
*device
);
919 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
920 int anv_gem_get_context_param(int fd
, int context
, uint32_t param
,
922 int anv_gem_get_param(int fd
, uint32_t param
);
923 int anv_gem_get_tiling(struct anv_device
*device
, uint32_t gem_handle
);
924 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
925 int anv_gem_get_aperture(int fd
, uint64_t *size
);
926 bool anv_gem_supports_48b_addresses(int fd
);
927 int anv_gem_gpu_get_reset_stats(struct anv_device
*device
,
928 uint32_t *active
, uint32_t *pending
);
929 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
930 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
931 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
932 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
933 uint32_t read_domains
, uint32_t write_domain
);
934 int anv_gem_sync_file_merge(struct anv_device
*device
, int fd1
, int fd2
);
935 uint32_t anv_gem_syncobj_create(struct anv_device
*device
, uint32_t flags
);
936 void anv_gem_syncobj_destroy(struct anv_device
*device
, uint32_t handle
);
937 int anv_gem_syncobj_handle_to_fd(struct anv_device
*device
, uint32_t handle
);
938 uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device
*device
, int fd
);
939 int anv_gem_syncobj_export_sync_file(struct anv_device
*device
,
941 int anv_gem_syncobj_import_sync_file(struct anv_device
*device
,
942 uint32_t handle
, int fd
);
943 void anv_gem_syncobj_reset(struct anv_device
*device
, uint32_t handle
);
944 bool anv_gem_supports_syncobj_wait(int fd
);
945 int anv_gem_syncobj_wait(struct anv_device
*device
,
946 uint32_t *handles
, uint32_t num_handles
,
947 int64_t abs_timeout_ns
, bool wait_all
);
949 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
951 struct anv_reloc_list
{
953 uint32_t array_length
;
954 struct drm_i915_gem_relocation_entry
* relocs
;
955 struct anv_bo
** reloc_bos
;
958 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
959 const VkAllocationCallbacks
*alloc
);
960 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
961 const VkAllocationCallbacks
*alloc
);
963 VkResult
anv_reloc_list_add(struct anv_reloc_list
*list
,
964 const VkAllocationCallbacks
*alloc
,
965 uint32_t offset
, struct anv_bo
*target_bo
,
968 struct anv_batch_bo
{
969 /* Link in the anv_cmd_buffer.owned_batch_bos list */
970 struct list_head link
;
974 /* Bytes actually consumed in this batch BO */
977 struct anv_reloc_list relocs
;
981 const VkAllocationCallbacks
* alloc
;
987 struct anv_reloc_list
* relocs
;
989 /* This callback is called (with the associated user data) in the event
990 * that the batch runs out of space.
992 VkResult (*extend_cb
)(struct anv_batch
*, void *);
996 * Current error status of the command buffer. Used to track inconsistent
997 * or incomplete command buffer states that are the consequence of run-time
998 * errors such as out of memory scenarios. We want to track this in the
999 * batch because the command buffer object is not visible to some parts
1005 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
1006 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
1007 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
1008 void *location
, struct anv_bo
*bo
, uint32_t offset
);
1009 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
1010 struct anv_batch
*batch
);
1012 static inline VkResult
1013 anv_batch_set_error(struct anv_batch
*batch
, VkResult error
)
1015 assert(error
!= VK_SUCCESS
);
1016 if (batch
->status
== VK_SUCCESS
)
1017 batch
->status
= error
;
1018 return batch
->status
;
1022 anv_batch_has_error(struct anv_batch
*batch
)
1024 return batch
->status
!= VK_SUCCESS
;
1027 struct anv_address
{
1032 static inline uint64_t
1033 _anv_combine_address(struct anv_batch
*batch
, void *location
,
1034 const struct anv_address address
, uint32_t delta
)
1036 if (address
.bo
== NULL
) {
1037 return address
.offset
+ delta
;
1039 assert(batch
->start
<= location
&& location
< batch
->end
);
1041 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
1045 #define __gen_address_type struct anv_address
1046 #define __gen_user_data struct anv_batch
1047 #define __gen_combine_address _anv_combine_address
1049 /* Wrapper macros needed to work around preprocessor argument issues. In
1050 * particular, arguments don't get pre-evaluated if they are concatenated.
1051 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
1052 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
1053 * We can work around this easily enough with these helpers.
1055 #define __anv_cmd_length(cmd) cmd ## _length
1056 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
1057 #define __anv_cmd_header(cmd) cmd ## _header
1058 #define __anv_cmd_pack(cmd) cmd ## _pack
1059 #define __anv_reg_num(reg) reg ## _num
1061 #define anv_pack_struct(dst, struc, ...) do { \
1062 struct struc __template = { \
1065 __anv_cmd_pack(struc)(NULL, dst, &__template); \
1066 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
1069 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
1070 void *__dst = anv_batch_emit_dwords(batch, n); \
1072 struct cmd __template = { \
1073 __anv_cmd_header(cmd), \
1074 .DWordLength = n - __anv_cmd_length_bias(cmd), \
1077 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
1082 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
1086 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
1087 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
1090 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
1091 dw[i] = (dwords0)[i] | (dwords1)[i]; \
1092 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
1095 #define anv_batch_emit(batch, cmd, name) \
1096 for (struct cmd name = { __anv_cmd_header(cmd) }, \
1097 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
1098 __builtin_expect(_dst != NULL, 1); \
1099 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
1100 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
1104 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
1105 .GraphicsDataTypeGFDT = 0, \
1106 .LLCCacheabilityControlLLCCC = 0, \
1107 .L3CacheabilityControlL3CC = 1, \
1110 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
1111 .LLCeLLCCacheabilityControlLLCCC = 0, \
1112 .L3CacheabilityControlL3CC = 1, \
1115 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
1116 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
1117 .TargetCache = L3DefertoPATforLLCeLLCselection, \
1118 .AgeforQUADLRU = 0 \
1121 /* Skylake: MOCS is now an index into an array of 62 different caching
1122 * configurations programmed by the kernel.
1125 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
1126 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1127 .IndextoMOCSTables = 2 \
1130 #define GEN9_MOCS_PTE { \
1131 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1132 .IndextoMOCSTables = 1 \
1135 /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
1136 #define GEN10_MOCS (struct GEN10_MEMORY_OBJECT_CONTROL_STATE) { \
1137 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1138 .IndextoMOCSTables = 2 \
1141 #define GEN10_MOCS_PTE { \
1142 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
1143 .IndextoMOCSTables = 1 \
1146 struct anv_device_memory
{
1148 struct anv_memory_type
* type
;
1149 VkDeviceSize map_size
;
1154 * Header for Vertex URB Entry (VUE)
1156 struct anv_vue_header
{
1158 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
1159 uint32_t ViewportIndex
;
1163 struct anv_descriptor_set_binding_layout
{
1165 /* The type of the descriptors in this binding */
1166 VkDescriptorType type
;
1169 /* Number of array elements in this binding */
1170 uint16_t array_size
;
1172 /* Index into the flattend descriptor set */
1173 uint16_t descriptor_index
;
1175 /* Index into the dynamic state array for a dynamic buffer */
1176 int16_t dynamic_offset_index
;
1178 /* Index into the descriptor set buffer views */
1179 int16_t buffer_index
;
1182 /* Index into the binding table for the associated surface */
1183 int16_t surface_index
;
1185 /* Index into the sampler table for the associated sampler */
1186 int16_t sampler_index
;
1188 /* Index into the image table for the associated image */
1189 int16_t image_index
;
1190 } stage
[MESA_SHADER_STAGES
];
1192 /* Immutable samplers (or NULL if no immutable samplers) */
1193 struct anv_sampler
**immutable_samplers
;
1196 struct anv_descriptor_set_layout
{
1197 /* Number of bindings in this descriptor set */
1198 uint16_t binding_count
;
1200 /* Total size of the descriptor set with room for all array entries */
1203 /* Shader stages affected by this descriptor set */
1204 uint16_t shader_stages
;
1206 /* Number of buffers in this descriptor set */
1207 uint16_t buffer_count
;
1209 /* Number of dynamic offsets used by this descriptor set */
1210 uint16_t dynamic_offset_count
;
1212 /* Bindings in this descriptor set */
1213 struct anv_descriptor_set_binding_layout binding
[0];
1216 struct anv_descriptor
{
1217 VkDescriptorType type
;
1221 VkImageLayout layout
;
1222 struct anv_image_view
*image_view
;
1223 struct anv_sampler
*sampler
;
1227 struct anv_buffer
*buffer
;
1232 struct anv_buffer_view
*buffer_view
;
1236 struct anv_descriptor_set
{
1237 const struct anv_descriptor_set_layout
*layout
;
1239 uint32_t buffer_count
;
1240 struct anv_buffer_view
*buffer_views
;
1241 struct anv_descriptor descriptors
[0];
1244 struct anv_buffer_view
{
1245 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1247 uint32_t offset
; /**< Offset into bo. */
1248 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1250 struct anv_state surface_state
;
1251 struct anv_state storage_surface_state
;
1252 struct anv_state writeonly_storage_surface_state
;
1254 struct brw_image_param storage_image_param
;
1257 struct anv_push_descriptor_set
{
1258 struct anv_descriptor_set set
;
1260 /* Put this field right behind anv_descriptor_set so it fills up the
1261 * descriptors[0] field. */
1262 struct anv_descriptor descriptors
[MAX_PUSH_DESCRIPTORS
];
1263 struct anv_buffer_view buffer_views
[MAX_PUSH_DESCRIPTORS
];
1266 struct anv_descriptor_pool
{
1271 struct anv_state_stream surface_state_stream
;
1272 void *surface_state_free_list
;
1277 enum anv_descriptor_template_entry_type
{
1278 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE
,
1279 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER
,
1280 ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
1283 struct anv_descriptor_template_entry
{
1284 /* The type of descriptor in this entry */
1285 VkDescriptorType type
;
1287 /* Binding in the descriptor set */
1290 /* Offset at which to write into the descriptor set binding */
1291 uint32_t array_element
;
1293 /* Number of elements to write into the descriptor set binding */
1294 uint32_t array_count
;
1296 /* Offset into the user provided data */
1299 /* Stride between elements into the user provided data */
1303 struct anv_descriptor_update_template
{
1304 /* The descriptor set this template corresponds to. This value is only
1305 * valid if the template was created with the templateType
1306 * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
1310 /* Number of entries in this template */
1311 uint32_t entry_count
;
1313 /* Entries of the template */
1314 struct anv_descriptor_template_entry entries
[0];
1318 anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout
*binding
);
1321 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout
*layout
);
1324 anv_descriptor_set_write_image_view(struct anv_descriptor_set
*set
,
1325 const struct gen_device_info
* const devinfo
,
1326 const VkDescriptorImageInfo
* const info
,
1327 VkDescriptorType type
,
1332 anv_descriptor_set_write_buffer_view(struct anv_descriptor_set
*set
,
1333 VkDescriptorType type
,
1334 struct anv_buffer_view
*buffer_view
,
1339 anv_descriptor_set_write_buffer(struct anv_descriptor_set
*set
,
1340 struct anv_device
*device
,
1341 struct anv_state_stream
*alloc_stream
,
1342 VkDescriptorType type
,
1343 struct anv_buffer
*buffer
,
1346 VkDeviceSize offset
,
1347 VkDeviceSize range
);
1350 anv_descriptor_set_write_template(struct anv_descriptor_set
*set
,
1351 struct anv_device
*device
,
1352 struct anv_state_stream
*alloc_stream
,
1353 const struct anv_descriptor_update_template
*template,
1357 anv_descriptor_set_create(struct anv_device
*device
,
1358 struct anv_descriptor_pool
*pool
,
1359 const struct anv_descriptor_set_layout
*layout
,
1360 struct anv_descriptor_set
**out_set
);
1363 anv_descriptor_set_destroy(struct anv_device
*device
,
1364 struct anv_descriptor_pool
*pool
,
1365 struct anv_descriptor_set
*set
);
1367 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
1369 struct anv_pipeline_binding
{
1370 /* The descriptor set this surface corresponds to. The special value of
1371 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
1372 * to a color attachment and not a regular descriptor.
1376 /* Binding in the descriptor set */
1379 /* Index in the binding */
1382 /* Plane in the binding index */
1385 /* Input attachment index (relative to the subpass) */
1386 uint8_t input_attachment_index
;
1388 /* For a storage image, whether it is write-only */
1392 struct anv_pipeline_layout
{
1394 struct anv_descriptor_set_layout
*layout
;
1395 uint32_t dynamic_offset_start
;
1401 bool has_dynamic_offsets
;
1402 } stage
[MESA_SHADER_STAGES
];
1404 unsigned char sha1
[20];
1408 struct anv_device
* device
;
1411 VkBufferUsageFlags usage
;
1413 /* Set when bound */
1415 VkDeviceSize offset
;
1418 static inline uint64_t
1419 anv_buffer_get_range(struct anv_buffer
*buffer
, uint64_t offset
, uint64_t range
)
1421 assert(offset
<= buffer
->size
);
1422 if (range
== VK_WHOLE_SIZE
) {
1423 return buffer
->size
- offset
;
1425 assert(range
<= buffer
->size
);
1430 enum anv_cmd_dirty_bits
{
1431 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
1432 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
1433 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
1434 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
1435 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
1436 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
1437 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1438 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1439 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1440 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
1441 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1442 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1443 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1445 typedef uint32_t anv_cmd_dirty_mask_t
;
1447 enum anv_pipe_bits
{
1448 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
1449 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
1450 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
1451 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
1452 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
1453 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
1454 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
1455 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
1456 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
1457 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
1458 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
1460 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1461 * a flush has happened but not a CS stall. The next time we do any sort
1462 * of invalidation we need to insert a CS stall at that time. Otherwise,
1463 * we would have to CS stall on every flush which could be bad.
1465 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
1468 #define ANV_PIPE_FLUSH_BITS ( \
1469 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1470 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1471 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1473 #define ANV_PIPE_STALL_BITS ( \
1474 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1475 ANV_PIPE_DEPTH_STALL_BIT | \
1476 ANV_PIPE_CS_STALL_BIT)
1478 #define ANV_PIPE_INVALIDATE_BITS ( \
1479 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1480 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1481 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1482 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1483 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1484 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1486 static inline enum anv_pipe_bits
1487 anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags
)
1489 enum anv_pipe_bits pipe_bits
= 0;
1492 for_each_bit(b
, flags
) {
1493 switch ((VkAccessFlagBits
)(1 << b
)) {
1494 case VK_ACCESS_SHADER_WRITE_BIT
:
1495 pipe_bits
|= ANV_PIPE_DATA_CACHE_FLUSH_BIT
;
1497 case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
:
1498 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1500 case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
:
1501 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1503 case VK_ACCESS_TRANSFER_WRITE_BIT
:
1504 pipe_bits
|= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1505 pipe_bits
|= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
;
1508 break; /* Nothing to do */
1515 static inline enum anv_pipe_bits
1516 anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags
)
1518 enum anv_pipe_bits pipe_bits
= 0;
1521 for_each_bit(b
, flags
) {
1522 switch ((VkAccessFlagBits
)(1 << b
)) {
1523 case VK_ACCESS_INDIRECT_COMMAND_READ_BIT
:
1524 case VK_ACCESS_INDEX_READ_BIT
:
1525 case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
:
1526 pipe_bits
|= ANV_PIPE_VF_CACHE_INVALIDATE_BIT
;
1528 case VK_ACCESS_UNIFORM_READ_BIT
:
1529 pipe_bits
|= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
;
1530 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1532 case VK_ACCESS_SHADER_READ_BIT
:
1533 case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
:
1534 case VK_ACCESS_TRANSFER_READ_BIT
:
1535 pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1538 break; /* Nothing to do */
1545 #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
1546 VK_IMAGE_ASPECT_COLOR_BIT | \
1547 VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | \
1548 VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | \
1549 VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)
1550 #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
1551 VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | \
1552 VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | \
1553 VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)
1555 struct anv_vertex_binding
{
1556 struct anv_buffer
* buffer
;
1557 VkDeviceSize offset
;
1560 #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
1561 #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
1563 struct anv_push_constants
{
1564 /* Current allocated size of this push constants data structure.
1565 * Because a decent chunk of it may not be used (images on SKL, for
1566 * instance), we won't actually allocate the entire structure up-front.
1570 /* Push constant data provided by the client through vkPushConstants */
1571 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1573 /* Image data for image_load_store on pre-SKL */
1574 struct brw_image_param images
[MAX_IMAGES
];
1577 struct anv_dynamic_state
{
1580 VkViewport viewports
[MAX_VIEWPORTS
];
1585 VkRect2D scissors
[MAX_SCISSORS
];
1596 float blend_constants
[4];
1606 } stencil_compare_mask
;
1611 } stencil_write_mask
;
1616 } stencil_reference
;
1619 extern const struct anv_dynamic_state default_dynamic_state
;
1621 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1622 const struct anv_dynamic_state
*src
,
1623 uint32_t copy_mask
);
1625 struct anv_surface_state
{
1626 struct anv_state state
;
1627 /** Address of the surface referred to by this state
1629 * This address is relative to the start of the BO.
1632 /* Address of the aux surface, if any
1634 * This field is 0 if and only if no aux surface exists.
1636 * This address is relative to the start of the BO. On gen7, the bottom 12
1637 * bits of this address include extra aux information.
1639 uint64_t aux_address
;
1643 * Attachment state when recording a renderpass instance.
1645 * The clear value is valid only if there exists a pending clear.
1647 struct anv_attachment_state
{
1648 enum isl_aux_usage aux_usage
;
1649 enum isl_aux_usage input_aux_usage
;
1650 struct anv_surface_state color
;
1651 struct anv_surface_state input
;
1653 VkImageLayout current_layout
;
1654 VkImageAspectFlags pending_clear_aspects
;
1656 VkClearValue clear_value
;
1657 bool clear_color_is_zero_one
;
1658 bool clear_color_is_zero
;
1661 /** State required while building cmd buffer */
1662 struct anv_cmd_state
{
1663 /* PIPELINE_SELECT.PipelineSelection */
1664 uint32_t current_pipeline
;
1665 const struct gen_l3_config
* current_l3_config
;
1667 anv_cmd_dirty_mask_t dirty
;
1668 anv_cmd_dirty_mask_t compute_dirty
;
1669 enum anv_pipe_bits pending_pipe_bits
;
1670 uint32_t num_workgroups_offset
;
1671 struct anv_bo
*num_workgroups_bo
;
1672 VkShaderStageFlags descriptors_dirty
;
1673 VkShaderStageFlags push_constants_dirty
;
1674 uint32_t scratch_size
;
1675 struct anv_pipeline
* pipeline
;
1676 struct anv_pipeline
* compute_pipeline
;
1677 struct anv_framebuffer
* framebuffer
;
1678 struct anv_render_pass
* pass
;
1679 struct anv_subpass
* subpass
;
1680 VkRect2D render_area
;
1681 uint32_t restart_index
;
1682 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1683 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1684 uint32_t dynamic_offsets
[MAX_DYNAMIC_BUFFERS
];
1685 VkShaderStageFlags push_constant_stages
;
1686 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1687 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1688 struct anv_state samplers
[MESA_SHADER_STAGES
];
1689 struct anv_dynamic_state dynamic
;
1692 struct anv_push_descriptor_set
* push_descriptors
[MAX_SETS
];
1695 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1696 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1697 * and before invoking the secondary in ExecuteCommands.
1699 bool pma_fix_enabled
;
1702 * Whether or not we know for certain that HiZ is enabled for the current
1703 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1704 * enabled or not, this will be false.
1709 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1710 * valid only when recording a render pass instance.
1712 struct anv_attachment_state
* attachments
;
1715 * Surface states for color render targets. These are stored in a single
1716 * flat array. For depth-stencil attachments, the surface state is simply
1719 struct anv_state render_pass_states
;
1722 * A null surface state of the right size to match the framebuffer. This
1723 * is one of the states in render_pass_states.
1725 struct anv_state null_surface_state
;
1728 struct anv_buffer
* index_buffer
;
1729 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1730 uint32_t index_offset
;
1734 struct anv_cmd_pool
{
1735 VkAllocationCallbacks alloc
;
1736 struct list_head cmd_buffers
;
1739 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1741 enum anv_cmd_buffer_exec_mode
{
1742 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1743 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1744 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1745 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1746 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1749 struct anv_cmd_buffer
{
1750 VK_LOADER_DATA _loader_data
;
1752 struct anv_device
* device
;
1754 struct anv_cmd_pool
* pool
;
1755 struct list_head pool_link
;
1757 struct anv_batch batch
;
1759 /* Fields required for the actual chain of anv_batch_bo's.
1761 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1763 struct list_head batch_bos
;
1764 enum anv_cmd_buffer_exec_mode exec_mode
;
1766 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1767 * referenced by this command buffer
1769 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1771 struct u_vector seen_bbos
;
1773 /* A vector of int32_t's for every block of binding tables.
1775 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1777 struct u_vector bt_block_states
;
1780 struct anv_reloc_list surface_relocs
;
1781 /** Last seen surface state block pool center bo offset */
1782 uint32_t last_ss_pool_center
;
1784 /* Serial for tracking buffer completion */
1787 /* Stream objects for storing temporary data */
1788 struct anv_state_stream surface_state_stream
;
1789 struct anv_state_stream dynamic_state_stream
;
1791 VkCommandBufferUsageFlags usage_flags
;
1792 VkCommandBufferLevel level
;
1794 struct anv_cmd_state state
;
1797 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1798 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1799 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1800 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1801 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1802 struct anv_cmd_buffer
*secondary
);
1803 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1804 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
1805 struct anv_cmd_buffer
*cmd_buffer
,
1806 const VkSemaphore
*in_semaphores
,
1807 uint32_t num_in_semaphores
,
1808 const VkSemaphore
*out_semaphores
,
1809 uint32_t num_out_semaphores
,
1812 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1815 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1816 gl_shader_stage stage
, uint32_t size
);
1817 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1818 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1819 (offsetof(struct anv_push_constants, field) + \
1820 sizeof(cmd_buffer->state.push_constants[0]->field)))
1822 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1823 const void *data
, uint32_t size
, uint32_t alignment
);
1824 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1825 uint32_t *a
, uint32_t *b
,
1826 uint32_t dwords
, uint32_t alignment
);
1829 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1831 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1832 uint32_t entries
, uint32_t *state_offset
);
1834 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1836 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1837 uint32_t size
, uint32_t alignment
);
1840 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1842 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1843 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1844 bool depth_clamp_enable
);
1845 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1847 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1848 struct anv_render_pass
*pass
,
1849 struct anv_framebuffer
*framebuffer
,
1850 const VkClearValue
*clear_values
);
1852 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1855 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1856 gl_shader_stage stage
);
1858 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1860 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1861 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1863 const struct anv_image_view
*
1864 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1867 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1868 uint32_t num_entries
,
1869 uint32_t *state_offset
,
1870 struct anv_state
*bt_state
);
1872 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1874 enum anv_fence_type
{
1875 ANV_FENCE_TYPE_NONE
= 0,
1877 ANV_FENCE_TYPE_SYNCOBJ
,
1880 enum anv_bo_fence_state
{
1881 /** Indicates that this is a new (or newly reset fence) */
1882 ANV_BO_FENCE_STATE_RESET
,
1884 /** Indicates that this fence has been submitted to the GPU but is still
1885 * (as far as we know) in use by the GPU.
1887 ANV_BO_FENCE_STATE_SUBMITTED
,
1889 ANV_BO_FENCE_STATE_SIGNALED
,
1892 struct anv_fence_impl
{
1893 enum anv_fence_type type
;
1896 /** Fence implementation for BO fences
1898 * These fences use a BO and a set of CPU-tracked state flags. The BO
1899 * is added to the object list of the last execbuf call in a QueueSubmit
1900 * and is marked EXEC_WRITE. The state flags track when the BO has been
1901 * submitted to the kernel. We need to do this because Vulkan lets you
1902 * wait on a fence that has not yet been submitted and I915_GEM_BUSY
1903 * will say it's idle in this case.
1907 enum anv_bo_fence_state state
;
1910 /** DRM syncobj handle for syncobj-based fences */
1916 /* Permanent fence state. Every fence has some form of permanent state
1917 * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
1918 * cross-process fences) or it could just be a dummy for use internally.
1920 struct anv_fence_impl permanent
;
1922 /* Temporary fence state. A fence *may* have temporary state. That state
1923 * is added to the fence by an import operation and is reset back to
1924 * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
1925 * state cannot be signaled because the fence must already be signaled
1926 * before the temporary state can be exported from the fence in the other
1927 * process and imported here.
1929 struct anv_fence_impl temporary
;
1934 struct anv_state state
;
1937 enum anv_semaphore_type
{
1938 ANV_SEMAPHORE_TYPE_NONE
= 0,
1939 ANV_SEMAPHORE_TYPE_DUMMY
,
1940 ANV_SEMAPHORE_TYPE_BO
,
1941 ANV_SEMAPHORE_TYPE_SYNC_FILE
,
1942 ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ
,
1945 struct anv_semaphore_impl
{
1946 enum anv_semaphore_type type
;
1949 /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
1950 * This BO will be added to the object list on any execbuf2 calls for
1951 * which this semaphore is used as a wait or signal fence. When used as
1952 * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
1956 /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
1957 * If the semaphore is in the unsignaled state due to either just being
1958 * created or because it has been used for a wait, fd will be -1.
1962 /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
1963 * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
1964 * import so we don't need to bother with a userspace cache.
1970 struct anv_semaphore
{
1971 /* Permanent semaphore state. Every semaphore has some form of permanent
1972 * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
1973 * (for cross-process semaphores0 or it could just be a dummy for use
1976 struct anv_semaphore_impl permanent
;
1978 /* Temporary semaphore state. A semaphore *may* have temporary state.
1979 * That state is added to the semaphore by an import operation and is reset
1980 * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
1981 * semaphore with temporary state cannot be signaled because the semaphore
1982 * must already be signaled before the temporary state can be exported from
1983 * the semaphore in the other process and imported here.
1985 struct anv_semaphore_impl temporary
;
1988 void anv_semaphore_reset_temporary(struct anv_device
*device
,
1989 struct anv_semaphore
*semaphore
);
1991 struct anv_shader_module
{
1992 unsigned char sha1
[20];
1997 static inline gl_shader_stage
1998 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
2000 assert(__builtin_popcount(vk_stage
) == 1);
2001 return ffs(vk_stage
) - 1;
2004 static inline VkShaderStageFlagBits
2005 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
2007 return (1 << mesa_stage
);
2010 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
2012 #define anv_foreach_stage(stage, stage_bits) \
2013 for (gl_shader_stage stage, \
2014 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
2015 stage = __builtin_ffs(__tmp) - 1, __tmp; \
2016 __tmp &= ~(1 << (stage)))
2018 struct anv_pipeline_bind_map
{
2019 uint32_t surface_count
;
2020 uint32_t sampler_count
;
2021 uint32_t image_count
;
2023 struct anv_pipeline_binding
* surface_to_descriptor
;
2024 struct anv_pipeline_binding
* sampler_to_descriptor
;
2027 struct anv_shader_bin_key
{
2032 struct anv_shader_bin
{
2035 const struct anv_shader_bin_key
*key
;
2037 struct anv_state kernel
;
2038 uint32_t kernel_size
;
2040 const struct brw_stage_prog_data
*prog_data
;
2041 uint32_t prog_data_size
;
2043 struct anv_pipeline_bind_map bind_map
;
2046 struct anv_shader_bin
*
2047 anv_shader_bin_create(struct anv_device
*device
,
2048 const void *key
, uint32_t key_size
,
2049 const void *kernel
, uint32_t kernel_size
,
2050 const struct brw_stage_prog_data
*prog_data
,
2051 uint32_t prog_data_size
, const void *prog_data_param
,
2052 const struct anv_pipeline_bind_map
*bind_map
);
2055 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
2058 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
2060 assert(shader
&& shader
->ref_cnt
>= 1);
2061 p_atomic_inc(&shader
->ref_cnt
);
2065 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
2067 assert(shader
&& shader
->ref_cnt
>= 1);
2068 if (p_atomic_dec_zero(&shader
->ref_cnt
))
2069 anv_shader_bin_destroy(device
, shader
);
2072 struct anv_pipeline
{
2073 struct anv_device
* device
;
2074 struct anv_batch batch
;
2075 uint32_t batch_data
[512];
2076 struct anv_reloc_list batch_relocs
;
2077 uint32_t dynamic_state_mask
;
2078 struct anv_dynamic_state dynamic_state
;
2080 struct anv_subpass
* subpass
;
2081 struct anv_pipeline_layout
* layout
;
2083 bool needs_data_cache
;
2085 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
2088 const struct gen_l3_config
* l3_config
;
2089 uint32_t total_size
;
2092 VkShaderStageFlags active_stages
;
2093 struct anv_state blend_state
;
2096 uint32_t binding_stride
[MAX_VBS
];
2097 bool instancing_enable
[MAX_VBS
];
2098 bool primitive_restart
;
2101 uint32_t cs_right_mask
;
2104 bool depth_test_enable
;
2105 bool writes_stencil
;
2106 bool stencil_test_enable
;
2107 bool depth_clamp_enable
;
2108 bool sample_shading_enable
;
2113 uint32_t depth_stencil_state
[3];
2119 uint32_t wm_depth_stencil
[3];
2123 uint32_t wm_depth_stencil
[4];
2126 uint32_t interface_descriptor_data
[8];
2130 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
2131 gl_shader_stage stage
)
2133 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
2136 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
2137 static inline const struct brw_##prefix##_prog_data * \
2138 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
2140 if (anv_pipeline_has_stage(pipeline, stage)) { \
2141 return (const struct brw_##prefix##_prog_data *) \
2142 pipeline->shaders[stage]->prog_data; \
2148 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
2149 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
2150 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
2151 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
2152 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
2153 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
2155 static inline const struct brw_vue_prog_data
*
2156 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
2158 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
2159 return &get_gs_prog_data(pipeline
)->base
;
2160 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
2161 return &get_tes_prog_data(pipeline
)->base
;
2163 return &get_vs_prog_data(pipeline
)->base
;
2167 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
2168 struct anv_pipeline_cache
*cache
,
2169 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
2170 const VkAllocationCallbacks
*alloc
);
2173 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
2174 struct anv_pipeline_cache
*cache
,
2175 const VkComputePipelineCreateInfo
*info
,
2176 struct anv_shader_module
*module
,
2177 const char *entrypoint
,
2178 const VkSpecializationInfo
*spec_info
);
2180 struct anv_format_plane
{
2181 enum isl_format isl_format
:16;
2182 struct isl_swizzle swizzle
;
2184 /* Whether this plane contains chroma channels */
2187 /* For downscaling of YUV planes */
2188 uint8_t denominator_scales
[2];
2190 /* How to map sampled ycbcr planes to a single 4 component element. */
2191 struct isl_swizzle ycbcr_swizzle
;
2196 struct anv_format_plane planes
[3];
2201 static inline uint32_t
2202 anv_image_aspect_to_plane(VkImageAspectFlags image_aspects
,
2203 VkImageAspectFlags aspect_mask
)
2205 switch (aspect_mask
) {
2206 case VK_IMAGE_ASPECT_COLOR_BIT
:
2207 case VK_IMAGE_ASPECT_DEPTH_BIT
:
2208 case VK_IMAGE_ASPECT_PLANE_0_BIT_KHR
:
2210 case VK_IMAGE_ASPECT_STENCIL_BIT
:
2211 if ((image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) == 0)
2214 case VK_IMAGE_ASPECT_PLANE_1_BIT_KHR
:
2216 case VK_IMAGE_ASPECT_PLANE_2_BIT_KHR
:
2219 /* Purposefully assert with depth/stencil aspects. */
2220 unreachable("invalid image aspect");
2224 static inline uint32_t
2225 anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask
)
2227 uint32_t planes
= 0;
2229 if (aspect_mask
& (VK_IMAGE_ASPECT_COLOR_BIT
|
2230 VK_IMAGE_ASPECT_DEPTH_BIT
|
2231 VK_IMAGE_ASPECT_STENCIL_BIT
|
2232 VK_IMAGE_ASPECT_PLANE_0_BIT_KHR
))
2234 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_1_BIT_KHR
)
2236 if (aspect_mask
& VK_IMAGE_ASPECT_PLANE_2_BIT_KHR
)
2242 static inline VkImageAspectFlags
2243 anv_plane_to_aspect(VkImageAspectFlags image_aspects
,
2246 if (image_aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
2247 if (_mesa_bitcount(image_aspects
) > 1)
2248 return VK_IMAGE_ASPECT_PLANE_0_BIT_KHR
<< plane
;
2249 return VK_IMAGE_ASPECT_COLOR_BIT
;
2251 if (image_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)
2252 return VK_IMAGE_ASPECT_DEPTH_BIT
<< plane
;
2253 assert(image_aspects
== VK_IMAGE_ASPECT_STENCIL_BIT
);
2254 return VK_IMAGE_ASPECT_STENCIL_BIT
;
2257 #define anv_foreach_image_aspect_bit(b, image, aspects) \
2258 for_each_bit(b, anv_image_expand_aspects(image, aspects))
2260 const struct anv_format
*
2261 anv_get_format(VkFormat format
);
2263 static inline uint32_t
2264 anv_get_format_planes(VkFormat vk_format
)
2266 const struct anv_format
*format
= anv_get_format(vk_format
);
2268 return format
!= NULL
? format
->n_planes
: 0;
2271 struct anv_format_plane
2272 anv_get_format_plane(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2273 VkImageAspectFlagBits aspect
, VkImageTiling tiling
);
2275 static inline enum isl_format
2276 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
2277 VkImageAspectFlags aspect
, VkImageTiling tiling
)
2279 return anv_get_format_plane(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
2282 static inline struct isl_swizzle
2283 anv_swizzle_for_render(struct isl_swizzle swizzle
)
2285 /* Sometimes the swizzle will have alpha map to one. We do this to fake
2286 * RGB as RGBA for texturing
2288 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
2289 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
2291 /* But it doesn't matter what we render to that channel */
2292 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
2298 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
2301 * Subsurface of an anv_image.
2303 struct anv_surface
{
2304 /** Valid only if isl_surf::size > 0. */
2305 struct isl_surf isl
;
2308 * Offset from VkImage's base address, as bound by vkBindImageMemory().
2315 /* The original VkFormat provided by the client. This may not match any
2316 * of the actual surface formats.
2319 const struct anv_format
*format
;
2321 VkImageAspectFlags aspects
;
2324 uint32_t array_size
;
2325 uint32_t samples
; /**< VkImageCreateInfo::samples */
2327 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
2328 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
2331 * DRM format modifier for this image or DRM_FORMAT_MOD_INVALID.
2333 uint64_t drm_format_mod
;
2338 /* Whether the image is made of several underlying buffer objects rather a
2339 * single one with different offsets.
2346 * For each foo, anv_image::planes[x].surface is valid if and only if
2347 * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
2348 * to figure the number associated with a given aspect.
2350 * The hardware requires that the depth buffer and stencil buffer be
2351 * separate surfaces. From Vulkan's perspective, though, depth and stencil
2352 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
2353 * allocate the depth and stencil buffers as separate surfaces in the same
2358 * -----------------------
2360 * ----------------------- |
2361 * | shadow surface0 | |
2362 * ----------------------- | Plane 0
2363 * | aux surface0 | |
2364 * ----------------------- |
2365 * | fast clear colors0 | \|/
2366 * -----------------------
2368 * ----------------------- |
2369 * | shadow surface1 | |
2370 * ----------------------- | Plane 1
2371 * | aux surface1 | |
2372 * ----------------------- |
2373 * | fast clear colors1 | \|/
2374 * -----------------------
2377 * -----------------------
2381 * Offset of the entire plane (whenever the image is disjoint this is
2389 struct anv_surface surface
;
2392 * A surface which shadows the main surface and may have different
2393 * tiling. This is used for sampling using a tiling that isn't supported
2394 * for other operations.
2396 struct anv_surface shadow_surface
;
2399 * For color images, this is the aux usage for this image when not used
2400 * as a color attachment.
2402 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
2403 * image has a HiZ buffer.
2405 enum isl_aux_usage aux_usage
;
2407 struct anv_surface aux_surface
;
2410 * Offset of the fast clear state (used to compute the
2411 * fast_clear_state_offset of the following planes).
2413 uint32_t fast_clear_state_offset
;
2416 * BO associated with this plane, set when bound.
2419 VkDeviceSize bo_offset
;
2422 * When destroying the image, also free the bo.
2428 /* Returns the number of auxiliary buffer levels attached to an image. */
2429 static inline uint8_t
2430 anv_image_aux_levels(const struct anv_image
* const image
,
2431 VkImageAspectFlagBits aspect
)
2433 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2434 return image
->planes
[plane
].aux_surface
.isl
.size
> 0 ?
2435 image
->planes
[plane
].aux_surface
.isl
.levels
: 0;
2438 /* Returns the number of auxiliary buffer layers attached to an image. */
2439 static inline uint32_t
2440 anv_image_aux_layers(const struct anv_image
* const image
,
2441 VkImageAspectFlagBits aspect
,
2442 const uint8_t miplevel
)
2446 /* The miplevel must exist in the main buffer. */
2447 assert(miplevel
< image
->levels
);
2449 if (miplevel
>= anv_image_aux_levels(image
, aspect
)) {
2450 /* There are no layers with auxiliary data because the miplevel has no
2455 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2456 return MAX2(image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.array_len
,
2457 image
->planes
[plane
].aux_surface
.isl
.logical_level0_px
.depth
>> miplevel
);
2461 static inline unsigned
2462 anv_fast_clear_state_entry_size(const struct anv_device
*device
)
2466 * +--------------------------------------------+
2467 * | clear value dword(s) | needs resolve dword |
2468 * +--------------------------------------------+
2471 /* Ensure that the needs resolve dword is in fact dword-aligned to enable
2472 * GPU memcpy operations.
2474 assert(device
->isl_dev
.ss
.clear_value_size
% 4 == 0);
2475 return device
->isl_dev
.ss
.clear_value_size
+ 4;
2478 static inline struct anv_address
2479 anv_image_get_clear_color_addr(const struct anv_device
*device
,
2480 const struct anv_image
*image
,
2481 VkImageAspectFlagBits aspect
,
2484 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
2485 return (struct anv_address
) {
2486 .bo
= image
->planes
[plane
].bo
,
2487 .offset
= image
->planes
[plane
].bo_offset
+
2488 image
->planes
[plane
].fast_clear_state_offset
+
2489 anv_fast_clear_state_entry_size(device
) * level
,
2493 static inline struct anv_address
2494 anv_image_get_needs_resolve_addr(const struct anv_device
*device
,
2495 const struct anv_image
*image
,
2496 VkImageAspectFlagBits aspect
,
2499 struct anv_address addr
=
2500 anv_image_get_clear_color_addr(device
, image
, aspect
, level
);
2501 addr
.offset
+= device
->isl_dev
.ss
.clear_value_size
;
2505 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
2507 anv_can_sample_with_hiz(const struct gen_device_info
* const devinfo
,
2508 const struct anv_image
*image
)
2510 if (!(image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
))
2513 if (devinfo
->gen
< 8)
2516 return image
->samples
== 1;
2520 anv_gen8_hiz_op_resolve(struct anv_cmd_buffer
*cmd_buffer
,
2521 const struct anv_image
*image
,
2522 enum blorp_hiz_op op
);
2524 anv_ccs_resolve(struct anv_cmd_buffer
* const cmd_buffer
,
2525 const struct anv_image
* const image
,
2526 VkImageAspectFlagBits aspect
,
2527 const uint8_t level
,
2528 const uint32_t start_layer
, const uint32_t layer_count
,
2529 const enum blorp_fast_clear_op op
);
2532 anv_image_fast_clear(struct anv_cmd_buffer
*cmd_buffer
,
2533 const struct anv_image
*image
,
2534 VkImageAspectFlagBits aspect
,
2535 const uint32_t base_level
, const uint32_t level_count
,
2536 const uint32_t base_layer
, uint32_t layer_count
);
2539 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
2540 const struct anv_image
*image
,
2541 uint32_t base_level
, uint32_t level_count
,
2542 uint32_t base_layer
, uint32_t layer_count
);
2545 anv_layout_to_aux_usage(const struct gen_device_info
* const devinfo
,
2546 const struct anv_image
*image
,
2547 const VkImageAspectFlagBits aspect
,
2548 const VkImageLayout layout
);
2550 /* This is defined as a macro so that it works for both
2551 * VkImageSubresourceRange and VkImageSubresourceLayers
2553 #define anv_get_layerCount(_image, _range) \
2554 ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
2555 (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
2557 static inline uint32_t
2558 anv_get_levelCount(const struct anv_image
*image
,
2559 const VkImageSubresourceRange
*range
)
2561 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
2562 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
2565 static inline VkImageAspectFlags
2566 anv_image_expand_aspects(const struct anv_image
*image
,
2567 VkImageAspectFlags aspects
)
2569 /* If the underlying image has color plane aspects and
2570 * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
2571 * the underlying image. */
2572 if ((image
->aspects
& VK_IMAGE_ASPECT_PLANES_BITS_ANV
) != 0 &&
2573 aspects
== VK_IMAGE_ASPECT_COLOR_BIT
)
2574 return image
->aspects
;
2580 anv_image_aspects_compatible(VkImageAspectFlags aspects1
,
2581 VkImageAspectFlags aspects2
)
2583 if (aspects1
== aspects2
)
2586 /* Only 1 color aspects are compatibles. */
2587 if ((aspects1
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2588 (aspects2
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) != 0 &&
2589 _mesa_bitcount(aspects1
) == _mesa_bitcount(aspects2
))
2595 struct anv_image_view
{
2596 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
2598 VkImageAspectFlags aspect_mask
;
2600 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2604 uint32_t image_plane
;
2606 struct isl_view isl
;
2609 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2610 * image layout of SHADER_READ_ONLY_OPTIMAL or
2611 * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
2613 struct anv_surface_state optimal_sampler_surface_state
;
2616 * RENDER_SURFACE_STATE when using image as a sampler surface with an
2617 * image layout of GENERAL.
2619 struct anv_surface_state general_sampler_surface_state
;
2622 * RENDER_SURFACE_STATE when using image as a storage image. Separate
2623 * states for write-only and readable, using the real format for
2624 * write-only and the lowered format for readable.
2626 struct anv_surface_state storage_surface_state
;
2627 struct anv_surface_state writeonly_storage_surface_state
;
2629 struct brw_image_param storage_image_param
;
2633 enum anv_image_view_state_flags
{
2634 ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY
= (1 << 0),
2635 ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL
= (1 << 1),
2638 void anv_image_fill_surface_state(struct anv_device
*device
,
2639 const struct anv_image
*image
,
2640 VkImageAspectFlagBits aspect
,
2641 const struct isl_view
*view
,
2642 isl_surf_usage_flags_t view_usage
,
2643 enum isl_aux_usage aux_usage
,
2644 const union isl_color_value
*clear_color
,
2645 enum anv_image_view_state_flags flags
,
2646 struct anv_surface_state
*state_inout
,
2647 struct brw_image_param
*image_param_out
);
2649 struct anv_image_create_info
{
2650 const VkImageCreateInfo
*vk_info
;
2652 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
2653 isl_tiling_flags_t isl_tiling_flags
;
2655 /** These flags will be added to any derived from VkImageCreateInfo. */
2656 isl_surf_usage_flags_t isl_extra_usage_flags
;
2661 VkResult
anv_image_create(VkDevice _device
,
2662 const struct anv_image_create_info
*info
,
2663 const VkAllocationCallbacks
* alloc
,
2667 VkResult
anv_image_from_gralloc(VkDevice device_h
,
2668 const VkImageCreateInfo
*base_info
,
2669 const VkNativeBufferANDROID
*gralloc_info
,
2670 const VkAllocationCallbacks
*alloc
,
2674 const struct anv_surface
*
2675 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
2676 VkImageAspectFlags aspect_mask
);
2679 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
2681 static inline struct VkExtent3D
2682 anv_sanitize_image_extent(const VkImageType imageType
,
2683 const struct VkExtent3D imageExtent
)
2685 switch (imageType
) {
2686 case VK_IMAGE_TYPE_1D
:
2687 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
2688 case VK_IMAGE_TYPE_2D
:
2689 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
2690 case VK_IMAGE_TYPE_3D
:
2693 unreachable("invalid image type");
2697 static inline struct VkOffset3D
2698 anv_sanitize_image_offset(const VkImageType imageType
,
2699 const struct VkOffset3D imageOffset
)
2701 switch (imageType
) {
2702 case VK_IMAGE_TYPE_1D
:
2703 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
2704 case VK_IMAGE_TYPE_2D
:
2705 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
2706 case VK_IMAGE_TYPE_3D
:
2709 unreachable("invalid image type");
2714 void anv_fill_buffer_surface_state(struct anv_device
*device
,
2715 struct anv_state state
,
2716 enum isl_format format
,
2717 uint32_t offset
, uint32_t range
,
2721 struct anv_ycbcr_conversion
{
2722 const struct anv_format
* format
;
2723 VkSamplerYcbcrModelConversionKHR ycbcr_model
;
2724 VkSamplerYcbcrRangeKHR ycbcr_range
;
2725 VkComponentSwizzle mapping
[4];
2726 VkChromaLocationKHR chroma_offsets
[2];
2727 VkFilter chroma_filter
;
2728 bool chroma_reconstruction
;
2731 struct anv_sampler
{
2732 uint32_t state
[3][4];
2734 struct anv_ycbcr_conversion
*conversion
;
2737 struct anv_framebuffer
{
2742 uint32_t attachment_count
;
2743 struct anv_image_view
* attachments
[0];
2746 struct anv_subpass
{
2747 uint32_t attachment_count
;
2750 * A pointer to all attachment references used in this subpass.
2751 * Only valid if ::attachment_count > 0.
2753 VkAttachmentReference
* attachments
;
2754 uint32_t input_count
;
2755 VkAttachmentReference
* input_attachments
;
2756 uint32_t color_count
;
2757 VkAttachmentReference
* color_attachments
;
2758 VkAttachmentReference
* resolve_attachments
;
2760 VkAttachmentReference depth_stencil_attachment
;
2764 /** Subpass has a depth/stencil self-dependency */
2765 bool has_ds_self_dep
;
2767 /** Subpass has at least one resolve attachment */
2771 static inline unsigned
2772 anv_subpass_view_count(const struct anv_subpass
*subpass
)
2774 return MAX2(1, _mesa_bitcount(subpass
->view_mask
));
2777 struct anv_render_pass_attachment
{
2778 /* TODO: Consider using VkAttachmentDescription instead of storing each of
2779 * its members individually.
2783 VkImageUsageFlags usage
;
2784 VkAttachmentLoadOp load_op
;
2785 VkAttachmentStoreOp store_op
;
2786 VkAttachmentLoadOp stencil_load_op
;
2787 VkImageLayout initial_layout
;
2788 VkImageLayout final_layout
;
2789 VkImageLayout first_subpass_layout
;
2791 /* The subpass id in which the attachment will be used last. */
2792 uint32_t last_subpass_idx
;
2795 struct anv_render_pass
{
2796 uint32_t attachment_count
;
2797 uint32_t subpass_count
;
2798 /* An array of subpass_count+1 flushes, one per subpass boundary */
2799 enum anv_pipe_bits
* subpass_flushes
;
2800 struct anv_render_pass_attachment
* attachments
;
2801 struct anv_subpass subpasses
[0];
2804 #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
2806 struct anv_query_pool
{
2808 VkQueryPipelineStatisticFlags pipeline_statistics
;
2809 /** Stride between slots, in bytes */
2811 /** Number of slots in this query pool */
2816 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
2819 void anv_dump_image_to_ppm(struct anv_device
*device
,
2820 struct anv_image
*image
, unsigned miplevel
,
2821 unsigned array_layer
, VkImageAspectFlagBits aspect
,
2822 const char *filename
);
2824 enum anv_dump_action
{
2825 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
2828 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
2829 void anv_dump_finish(void);
2831 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
2832 struct anv_framebuffer
*fb
);
2834 static inline uint32_t
2835 anv_get_subpass_id(const struct anv_cmd_state
* const cmd_state
)
2837 /* This function must be called from within a subpass. */
2838 assert(cmd_state
->pass
&& cmd_state
->subpass
);
2840 const uint32_t subpass_id
= cmd_state
->subpass
- cmd_state
->pass
->subpasses
;
2842 /* The id of this subpass shouldn't exceed the number of subpasses in this
2843 * render pass minus 1.
2845 assert(subpass_id
< cmd_state
->pass
->subpass_count
);
2849 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
2851 static inline struct __anv_type * \
2852 __anv_type ## _from_handle(__VkType _handle) \
2854 return (struct __anv_type *) _handle; \
2857 static inline __VkType \
2858 __anv_type ## _to_handle(struct __anv_type *_obj) \
2860 return (__VkType) _obj; \
2863 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
2865 static inline struct __anv_type * \
2866 __anv_type ## _from_handle(__VkType _handle) \
2868 return (struct __anv_type *)(uintptr_t) _handle; \
2871 static inline __VkType \
2872 __anv_type ## _to_handle(struct __anv_type *_obj) \
2874 return (__VkType)(uintptr_t) _obj; \
2877 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
2878 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
2880 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
2881 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
2882 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
2883 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
2884 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
2886 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
2887 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
2888 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
2889 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
2890 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
2891 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
2892 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template
, VkDescriptorUpdateTemplateKHR
)
2893 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
2894 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
2895 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
2896 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
2897 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
2898 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
2899 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
2900 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
2901 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
2902 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
2903 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
2904 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
2905 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore
, VkSemaphore
)
2906 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
2907 ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback
, VkDebugReportCallbackEXT
)
2908 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion
, VkSamplerYcbcrConversionKHR
)
2910 /* Gen-specific function declarations */
2912 # include "anv_genX.h"
2914 # define genX(x) gen7_##x
2915 # include "anv_genX.h"
2917 # define genX(x) gen75_##x
2918 # include "anv_genX.h"
2920 # define genX(x) gen8_##x
2921 # include "anv_genX.h"
2923 # define genX(x) gen9_##x
2924 # include "anv_genX.h"
2926 # define genX(x) gen10_##x
2927 # include "anv_genX.h"
2931 #endif /* ANV_PRIVATE_H */