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_device_info.h"
45 #include "blorp/blorp.h"
46 #include "brw_compiler.h"
47 #include "util/macros.h"
48 #include "util/list.h"
49 #include "util/u_vector.h"
50 #include "util/vk_alloc.h"
52 /* Pre-declarations needed for WSI entrypoints */
55 typedef struct xcb_connection_t xcb_connection_t
;
56 typedef uint32_t xcb_visualid_t
;
57 typedef uint32_t xcb_window_t
;
61 #include <vulkan/vulkan.h>
62 #include <vulkan/vulkan_intel.h>
63 #include <vulkan/vk_icd.h>
65 #include "anv_entrypoints.h"
66 #include "brw_context.h"
69 #include "wsi_common.h"
75 /* Allowing different clear colors requires us to perform a depth resolve at
76 * the end of certain render passes. This is because while slow clears store
77 * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
78 * See the PRMs for examples describing when additional resolves would be
79 * necessary. To enable fast clears without requiring extra resolves, we set
80 * the clear value to a globally-defined one. We could allow different values
81 * if the user doesn't expect coherent data during or after a render passes
82 * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
83 * don't seem to exist yet. In almost all Vulkan applications tested thus far,
84 * 1.0f seems to be the only value used. The only application that doesn't set
85 * this value does so through the usage of an seemingly uninitialized clear
88 #define ANV_HZ_FC_VAL 1.0f
93 #define MAX_VIEWPORTS 16
94 #define MAX_SCISSORS 16
95 #define MAX_PUSH_CONSTANTS_SIZE 128
96 #define MAX_DYNAMIC_BUFFERS 16
99 #define ANV_SVGS_VB_INDEX MAX_VBS
100 #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
102 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
104 static inline uint32_t
105 align_down_npot_u32(uint32_t v
, uint32_t a
)
110 static inline uint32_t
111 align_u32(uint32_t v
, uint32_t a
)
113 assert(a
!= 0 && a
== (a
& -a
));
114 return (v
+ a
- 1) & ~(a
- 1);
117 static inline uint64_t
118 align_u64(uint64_t v
, uint64_t a
)
120 assert(a
!= 0 && a
== (a
& -a
));
121 return (v
+ a
- 1) & ~(a
- 1);
124 static inline int32_t
125 align_i32(int32_t v
, int32_t a
)
127 assert(a
!= 0 && a
== (a
& -a
));
128 return (v
+ a
- 1) & ~(a
- 1);
131 /** Alignment must be a power of 2. */
133 anv_is_aligned(uintmax_t n
, uintmax_t a
)
135 assert(a
== (a
& -a
));
136 return (n
& (a
- 1)) == 0;
139 static inline uint32_t
140 anv_minify(uint32_t n
, uint32_t levels
)
142 if (unlikely(n
== 0))
145 return MAX2(n
>> levels
, 1);
149 anv_clamp_f(float f
, float min
, float max
)
162 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
164 if (*inout_mask
& clear_mask
) {
165 *inout_mask
&= ~clear_mask
;
172 static inline union isl_color_value
173 vk_to_isl_color(VkClearColorValue color
)
175 return (union isl_color_value
) {
185 #define for_each_bit(b, dword) \
186 for (uint32_t __dword = (dword); \
187 (b) = __builtin_ffs(__dword) - 1, __dword; \
188 __dword &= ~(1 << (b)))
190 #define typed_memcpy(dest, src, count) ({ \
191 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
192 memcpy((dest), (src), (count) * sizeof(*(src))); \
195 /* Whenever we generate an error, pass it through this function. Useful for
196 * debugging, where we can break on it. Only call at error site, not when
197 * propagating errors. Might be useful to plug in a stack trace here.
200 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
203 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
204 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
205 #define anv_debug(format, ...) fprintf(stderr, "debug: " format, ##__VA_ARGS__)
207 #define vk_error(error) error
208 #define vk_errorf(error, format, ...) error
209 #define anv_debug(format, ...)
213 * Warn on ignored extension structs.
215 * The Vulkan spec requires us to ignore unsupported or unknown structs in
216 * a pNext chain. In debug mode, emitting warnings for ignored structs may
217 * help us discover structs that we should not have ignored.
220 * From the Vulkan 1.0.38 spec:
222 * Any component of the implementation (the loader, any enabled layers,
223 * and drivers) must skip over, without processing (other than reading the
224 * sType and pNext members) any chained structures with sType values not
225 * defined by extensions supported by that component.
227 #define anv_debug_ignored_stype(sType) \
228 anv_debug("debug: %s: ignored VkStructureType %u\n", __func__, (sType))
230 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
231 anv_printflike(3, 4);
232 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
233 void anv_loge_v(const char *format
, va_list va
);
236 * Print a FINISHME message, including its source location.
238 #define anv_finishme(format, ...) \
240 static bool reported = false; \
242 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
247 /* A non-fatal assert. Useful for debugging. */
249 #define anv_assert(x) ({ \
250 if (unlikely(!(x))) \
251 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
254 #define anv_assert(x)
258 * If a block of code is annotated with anv_validate, then the block runs only
262 #define anv_validate if (1)
264 #define anv_validate if (0)
267 #define stub_return(v) \
269 anv_finishme("stub %s", __func__); \
275 anv_finishme("stub %s", __func__); \
280 * A dynamically growable, circular buffer. Elements are added at head and
281 * removed from tail. head and tail are free-running uint32_t indices and we
282 * only compute the modulo with size when accessing the array. This way,
283 * number of bytes in the queue is always head - tail, even in case of
290 /* Index into the current validation list. This is used by the
291 * validation list building alrogithm to track which buffers are already
292 * in the validation list so that we can ensure uniqueness.
296 /* Last known offset. This value is provided by the kernel when we
297 * execbuf and is used as the presumed offset for the next bunch of
305 /* We need to set the WRITE flag on winsys bos so GEM will know we're
306 * writing to them and synchronize uses on other rings (eg if the display
307 * server uses the blitter ring).
313 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
315 bo
->gem_handle
= gem_handle
;
320 bo
->is_winsys_bo
= false;
323 /* Represents a lock-free linked list of "free" things. This is used by
324 * both the block pool and the state pools. Unfortunately, in order to
325 * solve the ABA problem, we can't use a single uint32_t head.
327 union anv_free_list
{
331 /* A simple count that is incremented every time the head changes. */
337 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
339 struct anv_block_state
{
349 struct anv_block_pool
{
350 struct anv_device
*device
;
354 /* The offset from the start of the bo to the "center" of the block
355 * pool. Pointers to allocated blocks are given by
356 * bo.map + center_bo_offset + offsets.
358 uint32_t center_bo_offset
;
360 /* Current memory map of the block pool. This pointer may or may not
361 * point to the actual beginning of the block pool memory. If
362 * anv_block_pool_alloc_back has ever been called, then this pointer
363 * will point to the "center" position of the buffer and all offsets
364 * (negative or positive) given out by the block pool alloc functions
365 * will be valid relative to this pointer.
367 * In particular, map == bo.map + center_offset
373 * Array of mmaps and gem handles owned by the block pool, reclaimed when
374 * the block pool is destroyed.
376 struct u_vector mmap_cleanups
;
380 union anv_free_list free_list
;
381 struct anv_block_state state
;
383 union anv_free_list back_free_list
;
384 struct anv_block_state back_state
;
387 /* Block pools are backed by a fixed-size 2GB memfd */
388 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
390 /* The center of the block pool is also the middle of the memfd. This may
391 * change in the future if we decide differently for some reason.
393 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
395 static inline uint32_t
396 anv_block_pool_size(struct anv_block_pool
*pool
)
398 return pool
->state
.end
+ pool
->back_state
.end
;
407 struct anv_fixed_size_state_pool
{
409 union anv_free_list free_list
;
410 struct anv_block_state block
;
413 #define ANV_MIN_STATE_SIZE_LOG2 6
414 #define ANV_MAX_STATE_SIZE_LOG2 20
416 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
418 struct anv_state_pool
{
419 struct anv_block_pool
*block_pool
;
420 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
423 struct anv_state_stream_block
;
425 struct anv_state_stream
{
426 struct anv_block_pool
*block_pool
;
428 /* The current working block */
429 struct anv_state_stream_block
*block
;
431 /* Offset at which the current block starts */
433 /* Offset at which to allocate the next state */
435 /* Offset at which the current block ends */
439 #define CACHELINE_SIZE 64
440 #define CACHELINE_MASK 63
443 anv_clflush_range(void *start
, size_t size
)
445 void *p
= (void *) (((uintptr_t) start
) & ~CACHELINE_MASK
);
446 void *end
= start
+ size
;
448 __builtin_ia32_mfence();
450 __builtin_ia32_clflush(p
);
456 anv_state_clflush(struct anv_state state
)
458 anv_clflush_range(state
.map
, state
.alloc_size
);
461 VkResult
anv_block_pool_init(struct anv_block_pool
*pool
,
462 struct anv_device
*device
, uint32_t block_size
);
463 void anv_block_pool_finish(struct anv_block_pool
*pool
);
464 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
465 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
466 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
467 void anv_state_pool_init(struct anv_state_pool
*pool
,
468 struct anv_block_pool
*block_pool
);
469 void anv_state_pool_finish(struct anv_state_pool
*pool
);
470 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
471 size_t state_size
, size_t alignment
);
472 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
473 void anv_state_stream_init(struct anv_state_stream
*stream
,
474 struct anv_block_pool
*block_pool
);
475 void anv_state_stream_finish(struct anv_state_stream
*stream
);
476 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
477 uint32_t size
, uint32_t alignment
);
480 * Implements a pool of re-usable BOs. The interface is identical to that
481 * of block_pool except that each block is its own BO.
484 struct anv_device
*device
;
489 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
);
490 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
491 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
493 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
495 struct anv_scratch_bo
{
500 struct anv_scratch_pool
{
501 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
502 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
505 void anv_scratch_pool_init(struct anv_device
*device
,
506 struct anv_scratch_pool
*pool
);
507 void anv_scratch_pool_finish(struct anv_device
*device
,
508 struct anv_scratch_pool
*pool
);
509 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
510 struct anv_scratch_pool
*pool
,
511 gl_shader_stage stage
,
512 unsigned per_thread_scratch
);
514 extern struct anv_dispatch_table dtable
;
516 struct anv_physical_device
{
517 VK_LOADER_DATA _loader_data
;
519 struct anv_instance
* instance
;
523 struct gen_device_info info
;
524 uint64_t aperture_size
;
525 struct brw_compiler
* compiler
;
526 struct isl_device isl_dev
;
527 int cmd_parser_version
;
530 uint32_t subslice_total
;
532 uint8_t uuid
[VK_UUID_SIZE
];
534 struct wsi_device wsi_device
;
538 struct anv_instance
{
539 VK_LOADER_DATA _loader_data
;
541 VkAllocationCallbacks alloc
;
544 int physicalDeviceCount
;
545 struct anv_physical_device physicalDevice
;
548 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
549 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
552 VK_LOADER_DATA _loader_data
;
554 struct anv_device
* device
;
556 struct anv_state_pool
* pool
;
559 struct anv_pipeline_cache
{
560 struct anv_device
* device
;
561 pthread_mutex_t mutex
;
563 struct hash_table
* cache
;
566 struct anv_pipeline_bind_map
;
568 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
569 struct anv_device
*device
,
571 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
573 struct anv_shader_bin
*
574 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
575 const void *key
, uint32_t key_size
);
576 struct anv_shader_bin
*
577 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
578 const void *key_data
, uint32_t key_size
,
579 const void *kernel_data
, uint32_t kernel_size
,
580 const struct brw_stage_prog_data
*prog_data
,
581 uint32_t prog_data_size
,
582 const struct anv_pipeline_bind_map
*bind_map
);
585 VK_LOADER_DATA _loader_data
;
587 VkAllocationCallbacks alloc
;
589 struct anv_instance
* instance
;
591 struct gen_device_info info
;
592 struct isl_device isl_dev
;
595 bool can_chain_batches
;
596 bool robust_buffer_access
;
598 struct anv_bo_pool batch_bo_pool
;
600 struct anv_block_pool dynamic_state_block_pool
;
601 struct anv_state_pool dynamic_state_pool
;
603 struct anv_block_pool instruction_block_pool
;
604 struct anv_state_pool instruction_state_pool
;
606 struct anv_block_pool surface_state_block_pool
;
607 struct anv_state_pool surface_state_pool
;
609 struct anv_bo workaround_bo
;
611 struct anv_pipeline_cache blorp_shader_cache
;
612 struct blorp_context blorp
;
614 struct anv_state border_colors
;
616 struct anv_queue queue
;
618 struct anv_scratch_pool scratch_pool
;
620 uint32_t default_mocs
;
622 pthread_mutex_t mutex
;
623 pthread_cond_t queue_submit
;
626 void anv_device_init_blorp(struct anv_device
*device
);
627 void anv_device_finish_blorp(struct anv_device
*device
);
629 VkResult
anv_device_execbuf(struct anv_device
*device
,
630 struct drm_i915_gem_execbuffer2
*execbuf
,
631 struct anv_bo
**execbuf_bos
);
633 void* anv_gem_mmap(struct anv_device
*device
,
634 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
635 void anv_gem_munmap(void *p
, uint64_t size
);
636 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
637 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
638 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
639 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
640 int anv_gem_execbuffer(struct anv_device
*device
,
641 struct drm_i915_gem_execbuffer2
*execbuf
);
642 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
643 uint32_t stride
, uint32_t tiling
);
644 int anv_gem_create_context(struct anv_device
*device
);
645 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
646 int anv_gem_get_param(int fd
, uint32_t param
);
647 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
648 int anv_gem_get_aperture(int fd
, uint64_t *size
);
649 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
650 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
651 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
652 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
653 uint32_t read_domains
, uint32_t write_domain
);
655 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
657 struct anv_reloc_list
{
660 struct drm_i915_gem_relocation_entry
* relocs
;
661 struct anv_bo
** reloc_bos
;
664 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
665 const VkAllocationCallbacks
*alloc
);
666 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
667 const VkAllocationCallbacks
*alloc
);
669 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
670 const VkAllocationCallbacks
*alloc
,
671 uint32_t offset
, struct anv_bo
*target_bo
,
674 struct anv_batch_bo
{
675 /* Link in the anv_cmd_buffer.owned_batch_bos list */
676 struct list_head link
;
680 /* Bytes actually consumed in this batch BO */
683 struct anv_reloc_list relocs
;
687 const VkAllocationCallbacks
* alloc
;
693 struct anv_reloc_list
* relocs
;
695 /* This callback is called (with the associated user data) in the event
696 * that the batch runs out of space.
698 VkResult (*extend_cb
)(struct anv_batch
*, void *);
702 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
703 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
704 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
705 void *location
, struct anv_bo
*bo
, uint32_t offset
);
706 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
707 struct anv_batch
*batch
);
714 static inline uint64_t
715 _anv_combine_address(struct anv_batch
*batch
, void *location
,
716 const struct anv_address address
, uint32_t delta
)
718 if (address
.bo
== NULL
) {
719 return address
.offset
+ delta
;
721 assert(batch
->start
<= location
&& location
< batch
->end
);
723 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
727 #define __gen_address_type struct anv_address
728 #define __gen_user_data struct anv_batch
729 #define __gen_combine_address _anv_combine_address
731 /* Wrapper macros needed to work around preprocessor argument issues. In
732 * particular, arguments don't get pre-evaluated if they are concatenated.
733 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
734 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
735 * We can work around this easily enough with these helpers.
737 #define __anv_cmd_length(cmd) cmd ## _length
738 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
739 #define __anv_cmd_header(cmd) cmd ## _header
740 #define __anv_cmd_pack(cmd) cmd ## _pack
741 #define __anv_reg_num(reg) reg ## _num
743 #define anv_pack_struct(dst, struc, ...) do { \
744 struct struc __template = { \
747 __anv_cmd_pack(struc)(NULL, dst, &__template); \
748 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
751 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
752 void *__dst = anv_batch_emit_dwords(batch, n); \
753 struct cmd __template = { \
754 __anv_cmd_header(cmd), \
755 .DWordLength = n - __anv_cmd_length_bias(cmd), \
758 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
762 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
766 STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
767 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
768 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
769 dw[i] = (dwords0)[i] | (dwords1)[i]; \
770 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
773 #define anv_batch_emit(batch, cmd, name) \
774 for (struct cmd name = { __anv_cmd_header(cmd) }, \
775 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
776 __builtin_expect(_dst != NULL, 1); \
777 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
778 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
782 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
783 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
784 struct anv_state __state = \
785 anv_state_pool_alloc((pool), __size, align); \
786 struct cmd __template = { \
789 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
790 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
791 if (!(pool)->block_pool->device->info.has_llc) \
792 anv_state_clflush(__state); \
796 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
797 .GraphicsDataTypeGFDT = 0, \
798 .LLCCacheabilityControlLLCCC = 0, \
799 .L3CacheabilityControlL3CC = 1, \
802 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
803 .LLCeLLCCacheabilityControlLLCCC = 0, \
804 .L3CacheabilityControlL3CC = 1, \
807 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
808 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
809 .TargetCache = L3DefertoPATforLLCeLLCselection, \
813 /* Skylake: MOCS is now an index into an array of 62 different caching
814 * configurations programmed by the kernel.
817 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
818 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
819 .IndextoMOCSTables = 2 \
822 #define GEN9_MOCS_PTE { \
823 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
824 .IndextoMOCSTables = 1 \
827 struct anv_device_memory
{
830 VkDeviceSize map_size
;
835 * Header for Vertex URB Entry (VUE)
837 struct anv_vue_header
{
839 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
840 uint32_t ViewportIndex
;
844 struct anv_descriptor_set_binding_layout
{
846 /* The type of the descriptors in this binding */
847 VkDescriptorType type
;
850 /* Number of array elements in this binding */
853 /* Index into the flattend descriptor set */
854 uint16_t descriptor_index
;
856 /* Index into the dynamic state array for a dynamic buffer */
857 int16_t dynamic_offset_index
;
859 /* Index into the descriptor set buffer views */
860 int16_t buffer_index
;
863 /* Index into the binding table for the associated surface */
864 int16_t surface_index
;
866 /* Index into the sampler table for the associated sampler */
867 int16_t sampler_index
;
869 /* Index into the image table for the associated image */
871 } stage
[MESA_SHADER_STAGES
];
873 /* Immutable samplers (or NULL if no immutable samplers) */
874 struct anv_sampler
**immutable_samplers
;
877 struct anv_descriptor_set_layout
{
878 /* Number of bindings in this descriptor set */
879 uint16_t binding_count
;
881 /* Total size of the descriptor set with room for all array entries */
884 /* Shader stages affected by this descriptor set */
885 uint16_t shader_stages
;
887 /* Number of buffers in this descriptor set */
888 uint16_t buffer_count
;
890 /* Number of dynamic offsets used by this descriptor set */
891 uint16_t dynamic_offset_count
;
893 /* Bindings in this descriptor set */
894 struct anv_descriptor_set_binding_layout binding
[0];
897 struct anv_descriptor
{
898 VkDescriptorType type
;
902 struct anv_image_view
*image_view
;
903 struct anv_sampler
*sampler
;
906 struct anv_buffer_view
*buffer_view
;
910 struct anv_descriptor_set
{
911 const struct anv_descriptor_set_layout
*layout
;
913 uint32_t buffer_count
;
914 struct anv_buffer_view
*buffer_views
;
915 struct anv_descriptor descriptors
[0];
918 struct anv_descriptor_pool
{
923 struct anv_state_stream surface_state_stream
;
924 void *surface_state_free_list
;
930 anv_descriptor_set_create(struct anv_device
*device
,
931 struct anv_descriptor_pool
*pool
,
932 const struct anv_descriptor_set_layout
*layout
,
933 struct anv_descriptor_set
**out_set
);
936 anv_descriptor_set_destroy(struct anv_device
*device
,
937 struct anv_descriptor_pool
*pool
,
938 struct anv_descriptor_set
*set
);
940 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
942 struct anv_pipeline_binding
{
943 /* The descriptor set this surface corresponds to. The special value of
944 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
945 * to a color attachment and not a regular descriptor.
949 /* Binding in the descriptor set */
952 /* Index in the binding */
955 /* Input attachment index (relative to the subpass) */
956 uint8_t input_attachment_index
;
958 /* For a storage image, whether it is write-only */
962 struct anv_pipeline_layout
{
964 struct anv_descriptor_set_layout
*layout
;
965 uint32_t dynamic_offset_start
;
971 bool has_dynamic_offsets
;
972 } stage
[MESA_SHADER_STAGES
];
974 unsigned char sha1
[20];
978 struct anv_device
* device
;
981 VkBufferUsageFlags usage
;
988 enum anv_cmd_dirty_bits
{
989 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
990 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
991 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
992 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
993 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
994 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
995 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
996 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
997 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
998 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
999 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1000 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1001 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1003 typedef uint32_t anv_cmd_dirty_mask_t
;
1005 enum anv_pipe_bits
{
1006 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
1007 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
1008 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
1009 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
1010 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
1011 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
1012 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
1013 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
1014 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
1015 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
1016 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
1018 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
1019 * a flush has happened but not a CS stall. The next time we do any sort
1020 * of invalidation we need to insert a CS stall at that time. Otherwise,
1021 * we would have to CS stall on every flush which could be bad.
1023 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
1026 #define ANV_PIPE_FLUSH_BITS ( \
1027 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
1028 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1029 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
1031 #define ANV_PIPE_STALL_BITS ( \
1032 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
1033 ANV_PIPE_DEPTH_STALL_BIT | \
1034 ANV_PIPE_CS_STALL_BIT)
1036 #define ANV_PIPE_INVALIDATE_BITS ( \
1037 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
1038 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
1039 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
1040 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
1041 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1042 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1044 struct anv_vertex_binding
{
1045 struct anv_buffer
* buffer
;
1046 VkDeviceSize offset
;
1049 struct anv_push_constants
{
1050 /* Current allocated size of this push constants data structure.
1051 * Because a decent chunk of it may not be used (images on SKL, for
1052 * instance), we won't actually allocate the entire structure up-front.
1056 /* Push constant data provided by the client through vkPushConstants */
1057 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1059 /* Our hardware only provides zero-based vertex and instance id so, in
1060 * order to satisfy the vulkan requirements, we may have to push one or
1061 * both of these into the shader.
1063 uint32_t base_vertex
;
1064 uint32_t base_instance
;
1066 /* Offsets and ranges for dynamically bound buffers */
1070 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1072 /* Image data for image_load_store on pre-SKL */
1073 struct brw_image_param images
[MAX_IMAGES
];
1076 struct anv_dynamic_state
{
1079 VkViewport viewports
[MAX_VIEWPORTS
];
1084 VkRect2D scissors
[MAX_SCISSORS
];
1095 float blend_constants
[4];
1105 } stencil_compare_mask
;
1110 } stencil_write_mask
;
1115 } stencil_reference
;
1118 extern const struct anv_dynamic_state default_dynamic_state
;
1120 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1121 const struct anv_dynamic_state
*src
,
1122 uint32_t copy_mask
);
1125 * Attachment state when recording a renderpass instance.
1127 * The clear value is valid only if there exists a pending clear.
1129 struct anv_attachment_state
{
1130 enum isl_aux_usage aux_usage
;
1131 enum isl_aux_usage input_aux_usage
;
1132 struct anv_state color_rt_state
;
1133 struct anv_state input_att_state
;
1135 VkImageLayout current_layout
;
1136 VkImageAspectFlags pending_clear_aspects
;
1138 VkClearValue clear_value
;
1139 bool clear_color_is_zero_one
;
1142 /** State required while building cmd buffer */
1143 struct anv_cmd_state
{
1144 /* PIPELINE_SELECT.PipelineSelection */
1145 uint32_t current_pipeline
;
1146 const struct gen_l3_config
* current_l3_config
;
1148 anv_cmd_dirty_mask_t dirty
;
1149 anv_cmd_dirty_mask_t compute_dirty
;
1150 enum anv_pipe_bits pending_pipe_bits
;
1151 uint32_t num_workgroups_offset
;
1152 struct anv_bo
*num_workgroups_bo
;
1153 VkShaderStageFlags descriptors_dirty
;
1154 VkShaderStageFlags push_constants_dirty
;
1155 uint32_t scratch_size
;
1156 struct anv_pipeline
* pipeline
;
1157 struct anv_pipeline
* compute_pipeline
;
1158 struct anv_framebuffer
* framebuffer
;
1159 struct anv_render_pass
* pass
;
1160 struct anv_subpass
* subpass
;
1161 VkRect2D render_area
;
1162 uint32_t restart_index
;
1163 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1164 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1165 VkShaderStageFlags push_constant_stages
;
1166 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1167 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1168 struct anv_state samplers
[MESA_SHADER_STAGES
];
1169 struct anv_dynamic_state dynamic
;
1173 * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
1174 * of any command buffer it is disabled by disabling it in EndCommandBuffer
1175 * and before invoking the secondary in ExecuteCommands.
1177 bool pma_fix_enabled
;
1180 * Whether or not we know for certain that HiZ is enabled for the current
1181 * subpass. If, for whatever reason, we are unsure as to whether HiZ is
1182 * enabled or not, this will be false.
1187 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1188 * valid only when recording a render pass instance.
1190 struct anv_attachment_state
* attachments
;
1193 * Surface states for color render targets. These are stored in a single
1194 * flat array. For depth-stencil attachments, the surface state is simply
1197 struct anv_state render_pass_states
;
1200 * A null surface state of the right size to match the framebuffer. This
1201 * is one of the states in render_pass_states.
1203 struct anv_state null_surface_state
;
1206 struct anv_buffer
* index_buffer
;
1207 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1208 uint32_t index_offset
;
1212 struct anv_cmd_pool
{
1213 VkAllocationCallbacks alloc
;
1214 struct list_head cmd_buffers
;
1217 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1219 enum anv_cmd_buffer_exec_mode
{
1220 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1221 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1222 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1223 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1224 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1227 struct anv_cmd_buffer
{
1228 VK_LOADER_DATA _loader_data
;
1230 struct anv_device
* device
;
1232 struct anv_cmd_pool
* pool
;
1233 struct list_head pool_link
;
1235 struct anv_batch batch
;
1237 /* Fields required for the actual chain of anv_batch_bo's.
1239 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1241 struct list_head batch_bos
;
1242 enum anv_cmd_buffer_exec_mode exec_mode
;
1244 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1245 * referenced by this command buffer
1247 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1249 struct u_vector seen_bbos
;
1251 /* A vector of int32_t's for every block of binding tables.
1253 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1255 struct u_vector bt_blocks
;
1258 struct anv_reloc_list surface_relocs
;
1259 /** Last seen surface state block pool center bo offset */
1260 uint32_t last_ss_pool_center
;
1262 /* Serial for tracking buffer completion */
1265 /* Stream objects for storing temporary data */
1266 struct anv_state_stream surface_state_stream
;
1267 struct anv_state_stream dynamic_state_stream
;
1269 VkCommandBufferUsageFlags usage_flags
;
1270 VkCommandBufferLevel level
;
1272 struct anv_cmd_state state
;
1275 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1276 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1277 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1278 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1279 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1280 struct anv_cmd_buffer
*secondary
);
1281 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1282 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
1283 struct anv_cmd_buffer
*cmd_buffer
);
1285 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1288 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1289 gl_shader_stage stage
, uint32_t size
);
1290 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1291 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1292 (offsetof(struct anv_push_constants, field) + \
1293 sizeof(cmd_buffer->state.push_constants[0]->field)))
1295 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1296 const void *data
, uint32_t size
, uint32_t alignment
);
1297 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1298 uint32_t *a
, uint32_t *b
,
1299 uint32_t dwords
, uint32_t alignment
);
1302 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1304 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1305 uint32_t entries
, uint32_t *state_offset
);
1307 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1309 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1310 uint32_t size
, uint32_t alignment
);
1313 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1315 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1316 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1317 bool depth_clamp_enable
);
1318 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1320 void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1321 struct anv_render_pass
*pass
,
1322 struct anv_framebuffer
*framebuffer
,
1323 const VkClearValue
*clear_values
);
1325 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1328 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1329 gl_shader_stage stage
);
1331 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1333 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1334 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1336 const struct anv_image_view
*
1337 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1340 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1341 uint32_t num_entries
,
1342 uint32_t *state_offset
);
1344 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1346 enum anv_fence_state
{
1347 /** Indicates that this is a new (or newly reset fence) */
1348 ANV_FENCE_STATE_RESET
,
1350 /** Indicates that this fence has been submitted to the GPU but is still
1351 * (as far as we know) in use by the GPU.
1353 ANV_FENCE_STATE_SUBMITTED
,
1355 ANV_FENCE_STATE_SIGNALED
,
1360 struct drm_i915_gem_execbuffer2 execbuf
;
1361 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1362 enum anv_fence_state state
;
1367 struct anv_state state
;
1370 struct anv_shader_module
{
1371 unsigned char sha1
[20];
1376 void anv_hash_shader(unsigned char *hash
, const void *key
, size_t key_size
,
1377 struct anv_shader_module
*module
,
1378 const char *entrypoint
,
1379 const struct anv_pipeline_layout
*pipeline_layout
,
1380 const VkSpecializationInfo
*spec_info
);
1382 static inline gl_shader_stage
1383 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1385 assert(__builtin_popcount(vk_stage
) == 1);
1386 return ffs(vk_stage
) - 1;
1389 static inline VkShaderStageFlagBits
1390 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1392 return (1 << mesa_stage
);
1395 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1397 #define anv_foreach_stage(stage, stage_bits) \
1398 for (gl_shader_stage stage, \
1399 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1400 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1401 __tmp &= ~(1 << (stage)))
1403 struct anv_pipeline_bind_map
{
1404 uint32_t surface_count
;
1405 uint32_t sampler_count
;
1406 uint32_t image_count
;
1408 struct anv_pipeline_binding
* surface_to_descriptor
;
1409 struct anv_pipeline_binding
* sampler_to_descriptor
;
1412 struct anv_shader_bin_key
{
1417 struct anv_shader_bin
{
1420 const struct anv_shader_bin_key
*key
;
1422 struct anv_state kernel
;
1423 uint32_t kernel_size
;
1425 const struct brw_stage_prog_data
*prog_data
;
1426 uint32_t prog_data_size
;
1428 struct anv_pipeline_bind_map bind_map
;
1430 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1433 struct anv_shader_bin
*
1434 anv_shader_bin_create(struct anv_device
*device
,
1435 const void *key
, uint32_t key_size
,
1436 const void *kernel
, uint32_t kernel_size
,
1437 const struct brw_stage_prog_data
*prog_data
,
1438 uint32_t prog_data_size
, const void *prog_data_param
,
1439 const struct anv_pipeline_bind_map
*bind_map
);
1442 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
1445 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
1447 assert(shader
->ref_cnt
>= 1);
1448 __sync_fetch_and_add(&shader
->ref_cnt
, 1);
1452 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
1454 assert(shader
->ref_cnt
>= 1);
1455 if (__sync_fetch_and_add(&shader
->ref_cnt
, -1) == 1)
1456 anv_shader_bin_destroy(device
, shader
);
1459 struct anv_pipeline
{
1460 struct anv_device
* device
;
1461 struct anv_batch batch
;
1462 uint32_t batch_data
[512];
1463 struct anv_reloc_list batch_relocs
;
1464 uint32_t dynamic_state_mask
;
1465 struct anv_dynamic_state dynamic_state
;
1467 struct anv_pipeline_layout
* layout
;
1469 bool needs_data_cache
;
1471 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
1474 const struct gen_l3_config
* l3_config
;
1475 uint32_t total_size
;
1478 VkShaderStageFlags active_stages
;
1479 struct anv_state blend_state
;
1482 uint32_t binding_stride
[MAX_VBS
];
1483 bool instancing_enable
[MAX_VBS
];
1484 bool primitive_restart
;
1487 uint32_t cs_right_mask
;
1490 bool depth_test_enable
;
1491 bool writes_stencil
;
1492 bool stencil_test_enable
;
1493 bool depth_clamp_enable
;
1498 uint32_t depth_stencil_state
[3];
1504 uint32_t wm_depth_stencil
[3];
1508 uint32_t wm_depth_stencil
[4];
1511 uint32_t interface_descriptor_data
[8];
1515 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
1516 gl_shader_stage stage
)
1518 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
1521 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1522 static inline const struct brw_##prefix##_prog_data * \
1523 get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
1525 if (anv_pipeline_has_stage(pipeline, stage)) { \
1526 return (const struct brw_##prefix##_prog_data *) \
1527 pipeline->shaders[stage]->prog_data; \
1533 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
1534 ANV_DECL_GET_PROG_DATA_FUNC(tcs
, MESA_SHADER_TESS_CTRL
)
1535 ANV_DECL_GET_PROG_DATA_FUNC(tes
, MESA_SHADER_TESS_EVAL
)
1536 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
1537 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
1538 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
1540 static inline const struct brw_vue_prog_data
*
1541 anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline
*pipeline
)
1543 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
1544 return &get_gs_prog_data(pipeline
)->base
;
1545 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
1546 return &get_tes_prog_data(pipeline
)->base
;
1548 return &get_vs_prog_data(pipeline
)->base
;
1552 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1553 struct anv_pipeline_cache
*cache
,
1554 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1555 const VkAllocationCallbacks
*alloc
);
1558 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1559 struct anv_pipeline_cache
*cache
,
1560 const VkComputePipelineCreateInfo
*info
,
1561 struct anv_shader_module
*module
,
1562 const char *entrypoint
,
1563 const VkSpecializationInfo
*spec_info
);
1566 enum isl_format isl_format
:16;
1567 struct isl_swizzle swizzle
;
1571 anv_get_format(const struct gen_device_info
*devinfo
, VkFormat format
,
1572 VkImageAspectFlags aspect
, VkImageTiling tiling
);
1574 static inline enum isl_format
1575 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
1576 VkImageAspectFlags aspect
, VkImageTiling tiling
)
1578 return anv_get_format(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
1581 static inline struct isl_swizzle
1582 anv_swizzle_for_render(struct isl_swizzle swizzle
)
1584 /* Sometimes the swizzle will have alpha map to one. We do this to fake
1585 * RGB as RGBA for texturing
1587 assert(swizzle
.a
== ISL_CHANNEL_SELECT_ONE
||
1588 swizzle
.a
== ISL_CHANNEL_SELECT_ALPHA
);
1590 /* But it doesn't matter what we render to that channel */
1591 swizzle
.a
= ISL_CHANNEL_SELECT_ALPHA
;
1597 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
1600 * Subsurface of an anv_image.
1602 struct anv_surface
{
1603 /** Valid only if isl_surf::size > 0. */
1604 struct isl_surf isl
;
1607 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1614 /* The original VkFormat provided by the client. This may not match any
1615 * of the actual surface formats.
1618 VkImageAspectFlags aspects
;
1621 uint32_t array_size
;
1622 uint32_t samples
; /**< VkImageCreateInfo::samples */
1623 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1624 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1629 /* Set when bound */
1631 VkDeviceSize offset
;
1636 * For each foo, anv_image::foo_surface is valid if and only if
1637 * anv_image::aspects has a foo aspect.
1639 * The hardware requires that the depth buffer and stencil buffer be
1640 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1641 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1642 * allocate the depth and stencil buffers as separate surfaces in the same
1646 struct anv_surface color_surface
;
1649 struct anv_surface depth_surface
;
1650 struct anv_surface stencil_surface
;
1655 * For color images, this is the aux usage for this image when not used as a
1658 * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the image
1661 enum isl_aux_usage aux_usage
;
1663 struct anv_surface aux_surface
;
1666 /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
1668 anv_can_sample_with_hiz(uint8_t gen
, uint32_t samples
)
1670 return gen
>= 8 && samples
== 1;
1674 anv_gen8_hiz_op_resolve(struct anv_cmd_buffer
*cmd_buffer
,
1675 const struct anv_image
*image
,
1676 enum blorp_hiz_op op
);
1678 static inline uint32_t
1679 anv_get_layerCount(const struct anv_image
*image
,
1680 const VkImageSubresourceRange
*range
)
1682 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
?
1683 image
->array_size
- range
->baseArrayLayer
: range
->layerCount
;
1686 static inline uint32_t
1687 anv_get_levelCount(const struct anv_image
*image
,
1688 const VkImageSubresourceRange
*range
)
1690 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
1691 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
1695 struct anv_image_view
{
1696 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1698 uint32_t offset
; /**< Offset into bo. */
1700 struct isl_view isl
;
1702 VkImageAspectFlags aspect_mask
;
1704 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1706 /** RENDER_SURFACE_STATE when using image as a sampler surface. */
1707 struct anv_state sampler_surface_state
;
1710 * RENDER_SURFACE_STATE when using image as a storage image. Separate states
1711 * for write-only and readable, using the real format for write-only and the
1712 * lowered format for readable.
1714 struct anv_state storage_surface_state
;
1715 struct anv_state writeonly_storage_surface_state
;
1717 struct brw_image_param storage_image_param
;
1720 struct anv_image_create_info
{
1721 const VkImageCreateInfo
*vk_info
;
1723 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
1724 isl_tiling_flags_t isl_tiling_flags
;
1729 VkResult
anv_image_create(VkDevice _device
,
1730 const struct anv_image_create_info
*info
,
1731 const VkAllocationCallbacks
* alloc
,
1734 const struct anv_surface
*
1735 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
1736 VkImageAspectFlags aspect_mask
);
1738 struct anv_buffer_view
{
1739 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1741 uint32_t offset
; /**< Offset into bo. */
1742 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1744 struct anv_state surface_state
;
1745 struct anv_state storage_surface_state
;
1746 struct anv_state writeonly_storage_surface_state
;
1748 struct brw_image_param storage_image_param
;
1752 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
1754 static inline struct VkExtent3D
1755 anv_sanitize_image_extent(const VkImageType imageType
,
1756 const struct VkExtent3D imageExtent
)
1758 switch (imageType
) {
1759 case VK_IMAGE_TYPE_1D
:
1760 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1761 case VK_IMAGE_TYPE_2D
:
1762 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1763 case VK_IMAGE_TYPE_3D
:
1766 unreachable("invalid image type");
1770 static inline struct VkOffset3D
1771 anv_sanitize_image_offset(const VkImageType imageType
,
1772 const struct VkOffset3D imageOffset
)
1774 switch (imageType
) {
1775 case VK_IMAGE_TYPE_1D
:
1776 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1777 case VK_IMAGE_TYPE_2D
:
1778 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1779 case VK_IMAGE_TYPE_3D
:
1782 unreachable("invalid image type");
1787 void anv_fill_buffer_surface_state(struct anv_device
*device
,
1788 struct anv_state state
,
1789 enum isl_format format
,
1790 uint32_t offset
, uint32_t range
,
1793 void anv_image_view_fill_image_param(struct anv_device
*device
,
1794 struct anv_image_view
*view
,
1795 struct brw_image_param
*param
);
1796 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1797 struct anv_buffer_view
*view
,
1798 struct brw_image_param
*param
);
1800 struct anv_sampler
{
1804 struct anv_framebuffer
{
1809 uint32_t attachment_count
;
1810 struct anv_image_view
* attachments
[0];
1813 struct anv_subpass
{
1814 uint32_t input_count
;
1815 uint32_t * input_attachments
;
1816 uint32_t color_count
;
1817 uint32_t * color_attachments
;
1818 uint32_t * resolve_attachments
;
1820 /* TODO: Consider storing the depth/stencil VkAttachmentReference
1821 * instead of its two structure members (below) individually.
1823 uint32_t depth_stencil_attachment
;
1824 VkImageLayout depth_stencil_layout
;
1826 /** Subpass has a depth/stencil self-dependency */
1827 bool has_ds_self_dep
;
1829 /** Subpass has at least one resolve attachment */
1833 enum anv_subpass_usage
{
1834 ANV_SUBPASS_USAGE_DRAW
= (1 << 0),
1835 ANV_SUBPASS_USAGE_INPUT
= (1 << 1),
1836 ANV_SUBPASS_USAGE_RESOLVE_SRC
= (1 << 2),
1837 ANV_SUBPASS_USAGE_RESOLVE_DST
= (1 << 3),
1840 struct anv_render_pass_attachment
{
1841 /* TODO: Consider using VkAttachmentDescription instead of storing each of
1842 * its members individually.
1846 VkImageUsageFlags usage
;
1847 VkAttachmentLoadOp load_op
;
1848 VkAttachmentStoreOp store_op
;
1849 VkAttachmentLoadOp stencil_load_op
;
1850 VkImageLayout initial_layout
;
1851 VkImageLayout final_layout
;
1853 /* An array, indexed by subpass id, of how the attachment will be used. */
1854 enum anv_subpass_usage
* subpass_usage
;
1856 /* The subpass id in which the attachment will be used last. */
1857 uint32_t last_subpass_idx
;
1860 struct anv_render_pass
{
1861 uint32_t attachment_count
;
1862 uint32_t subpass_count
;
1863 uint32_t * subpass_attachments
;
1864 enum anv_subpass_usage
* subpass_usages
;
1865 struct anv_render_pass_attachment
* attachments
;
1866 struct anv_subpass subpasses
[0];
1869 struct anv_query_pool_slot
{
1875 struct anv_query_pool
{
1881 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
1884 void anv_dump_image_to_ppm(struct anv_device
*device
,
1885 struct anv_image
*image
, unsigned miplevel
,
1886 unsigned array_layer
, VkImageAspectFlagBits aspect
,
1887 const char *filename
);
1889 enum anv_dump_action
{
1890 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
1893 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
1894 void anv_dump_finish(void);
1896 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
1897 struct anv_framebuffer
*fb
);
1899 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1901 static inline struct __anv_type * \
1902 __anv_type ## _from_handle(__VkType _handle) \
1904 return (struct __anv_type *) _handle; \
1907 static inline __VkType \
1908 __anv_type ## _to_handle(struct __anv_type *_obj) \
1910 return (__VkType) _obj; \
1913 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1915 static inline struct __anv_type * \
1916 __anv_type ## _from_handle(__VkType _handle) \
1918 return (struct __anv_type *)(uintptr_t) _handle; \
1921 static inline __VkType \
1922 __anv_type ## _to_handle(struct __anv_type *_obj) \
1924 return (__VkType)(uintptr_t) _obj; \
1927 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1928 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1930 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1931 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1932 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1933 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1934 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1936 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1937 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1938 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1939 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
1940 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1941 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1942 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1943 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1944 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1945 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1946 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1947 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1948 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1949 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1950 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1951 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1952 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1953 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1954 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1956 /* Gen-specific function declarations */
1958 # include "anv_genX.h"
1960 # define genX(x) gen7_##x
1961 # include "anv_genX.h"
1963 # define genX(x) gen75_##x
1964 # include "anv_genX.h"
1966 # define genX(x) gen8_##x
1967 # include "anv_genX.h"
1969 # define genX(x) gen9_##x
1970 # include "anv_genX.h"
1978 #endif /* ANV_PRIVATE_H */