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"
78 #define MAX_VIEWPORTS 16
79 #define MAX_SCISSORS 16
80 #define MAX_PUSH_CONSTANTS_SIZE 128
81 #define MAX_DYNAMIC_BUFFERS 16
83 #define MAX_SAMPLES_LOG2 4 /* SKL supports 16 samples */
85 #define anv_noreturn __attribute__((__noreturn__))
86 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
88 static inline uint32_t
89 align_down_npot_u32(uint32_t v
, uint32_t a
)
94 static inline uint32_t
95 align_u32(uint32_t v
, uint32_t a
)
97 assert(a
!= 0 && a
== (a
& -a
));
98 return (v
+ a
- 1) & ~(a
- 1);
101 static inline uint64_t
102 align_u64(uint64_t v
, uint64_t a
)
104 assert(a
!= 0 && a
== (a
& -a
));
105 return (v
+ a
- 1) & ~(a
- 1);
108 static inline int32_t
109 align_i32(int32_t v
, int32_t a
)
111 assert(a
!= 0 && a
== (a
& -a
));
112 return (v
+ a
- 1) & ~(a
- 1);
115 /** Alignment must be a power of 2. */
117 anv_is_aligned(uintmax_t n
, uintmax_t a
)
119 assert(a
== (a
& -a
));
120 return (n
& (a
- 1)) == 0;
123 static inline uint32_t
124 anv_minify(uint32_t n
, uint32_t levels
)
126 if (unlikely(n
== 0))
129 return MAX2(n
>> levels
, 1);
133 anv_clamp_f(float f
, float min
, float max
)
146 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
148 if (*inout_mask
& clear_mask
) {
149 *inout_mask
&= ~clear_mask
;
156 #define for_each_bit(b, dword) \
157 for (uint32_t __dword = (dword); \
158 (b) = __builtin_ffs(__dword) - 1, __dword; \
159 __dword &= ~(1 << (b)))
161 #define typed_memcpy(dest, src, count) ({ \
162 static_assert(sizeof(*src) == sizeof(*dest), ""); \
163 memcpy((dest), (src), (count) * sizeof(*(src))); \
166 /* Define no kernel as 1, since that's an illegal offset for a kernel */
170 VkStructureType sType
;
174 /* Whenever we generate an error, pass it through this function. Useful for
175 * debugging, where we can break on it. Only call at error site, not when
176 * propagating errors. Might be useful to plug in a stack trace here.
179 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
182 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
183 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
185 #define vk_error(error) error
186 #define vk_errorf(error, format, ...) error
189 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
190 anv_printflike(3, 4);
191 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
192 void anv_loge_v(const char *format
, va_list va
);
195 * Print a FINISHME message, including its source location.
197 #define anv_finishme(format, ...) ({ \
198 static bool reported = false; \
200 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
205 /* A non-fatal assert. Useful for debugging. */
207 #define anv_assert(x) ({ \
208 if (unlikely(!(x))) \
209 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
212 #define anv_assert(x)
216 * If a block of code is annotated with anv_validate, then the block runs only
220 #define anv_validate if (1)
222 #define anv_validate if (0)
225 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
226 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
228 #define stub_return(v) \
230 anv_finishme("stub %s", __func__); \
236 anv_finishme("stub %s", __func__); \
241 * A dynamically growable, circular buffer. Elements are added at head and
242 * removed from tail. head and tail are free-running uint32_t indices and we
243 * only compute the modulo with size when accessing the array. This way,
244 * number of bytes in the queue is always head - tail, even in case of
251 /* Index into the current validation list. This is used by the
252 * validation list building alrogithm to track which buffers are already
253 * in the validation list so that we can ensure uniqueness.
257 /* Last known offset. This value is provided by the kernel when we
258 * execbuf and is used as the presumed offset for the next bunch of
266 /* We need to set the WRITE flag on winsys bos so GEM will know we're
267 * writing to them and synchronize uses on other rings (eg if the display
268 * server uses the blitter ring).
274 anv_bo_init(struct anv_bo
*bo
, uint32_t gem_handle
, uint64_t size
)
276 bo
->gem_handle
= gem_handle
;
281 bo
->is_winsys_bo
= false;
284 /* Represents a lock-free linked list of "free" things. This is used by
285 * both the block pool and the state pools. Unfortunately, in order to
286 * solve the ABA problem, we can't use a single uint32_t head.
288 union anv_free_list
{
292 /* A simple count that is incremented every time the head changes. */
298 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
300 struct anv_block_state
{
310 struct anv_block_pool
{
311 struct anv_device
*device
;
315 /* The offset from the start of the bo to the "center" of the block
316 * pool. Pointers to allocated blocks are given by
317 * bo.map + center_bo_offset + offsets.
319 uint32_t center_bo_offset
;
321 /* Current memory map of the block pool. This pointer may or may not
322 * point to the actual beginning of the block pool memory. If
323 * anv_block_pool_alloc_back has ever been called, then this pointer
324 * will point to the "center" position of the buffer and all offsets
325 * (negative or positive) given out by the block pool alloc functions
326 * will be valid relative to this pointer.
328 * In particular, map == bo.map + center_offset
334 * Array of mmaps and gem handles owned by the block pool, reclaimed when
335 * the block pool is destroyed.
337 struct u_vector mmap_cleanups
;
341 union anv_free_list free_list
;
342 struct anv_block_state state
;
344 union anv_free_list back_free_list
;
345 struct anv_block_state back_state
;
348 /* Block pools are backed by a fixed-size 2GB memfd */
349 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
351 /* The center of the block pool is also the middle of the memfd. This may
352 * change in the future if we decide differently for some reason.
354 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
356 static inline uint32_t
357 anv_block_pool_size(struct anv_block_pool
*pool
)
359 return pool
->state
.end
+ pool
->back_state
.end
;
368 struct anv_fixed_size_state_pool
{
370 union anv_free_list free_list
;
371 struct anv_block_state block
;
374 #define ANV_MIN_STATE_SIZE_LOG2 6
375 #define ANV_MAX_STATE_SIZE_LOG2 17
377 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
379 struct anv_state_pool
{
380 struct anv_block_pool
*block_pool
;
381 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
384 struct anv_state_stream_block
;
386 struct anv_state_stream
{
387 struct anv_block_pool
*block_pool
;
389 /* The current working block */
390 struct anv_state_stream_block
*block
;
392 /* Offset at which the current block starts */
394 /* Offset at which to allocate the next state */
396 /* Offset at which the current block ends */
400 #define CACHELINE_SIZE 64
401 #define CACHELINE_MASK 63
404 anv_clflush_range(void *start
, size_t size
)
406 void *p
= (void *) (((uintptr_t) start
) & ~CACHELINE_MASK
);
407 void *end
= start
+ size
;
409 __builtin_ia32_mfence();
411 __builtin_ia32_clflush(p
);
417 anv_state_clflush(struct anv_state state
)
419 anv_clflush_range(state
.map
, state
.alloc_size
);
422 void anv_block_pool_init(struct anv_block_pool
*pool
,
423 struct anv_device
*device
, uint32_t block_size
);
424 void anv_block_pool_finish(struct anv_block_pool
*pool
);
425 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
426 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
427 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
428 void anv_state_pool_init(struct anv_state_pool
*pool
,
429 struct anv_block_pool
*block_pool
);
430 void anv_state_pool_finish(struct anv_state_pool
*pool
);
431 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
432 size_t state_size
, size_t alignment
);
433 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
434 void anv_state_stream_init(struct anv_state_stream
*stream
,
435 struct anv_block_pool
*block_pool
);
436 void anv_state_stream_finish(struct anv_state_stream
*stream
);
437 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
438 uint32_t size
, uint32_t alignment
);
441 * Implements a pool of re-usable BOs. The interface is identical to that
442 * of block_pool except that each block is its own BO.
445 struct anv_device
*device
;
450 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
);
451 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
452 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
454 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
456 struct anv_scratch_bo
{
461 struct anv_scratch_pool
{
462 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
463 struct anv_scratch_bo bos
[16][MESA_SHADER_STAGES
];
466 void anv_scratch_pool_init(struct anv_device
*device
,
467 struct anv_scratch_pool
*pool
);
468 void anv_scratch_pool_finish(struct anv_device
*device
,
469 struct anv_scratch_pool
*pool
);
470 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
471 struct anv_scratch_pool
*pool
,
472 gl_shader_stage stage
,
473 unsigned per_thread_scratch
);
475 extern struct anv_dispatch_table dtable
;
477 #define VK_ICD_WSI_PLATFORM_MAX 5
479 struct anv_physical_device
{
480 VK_LOADER_DATA _loader_data
;
482 struct anv_instance
* instance
;
486 struct gen_device_info info
;
487 uint64_t aperture_size
;
488 struct brw_compiler
* compiler
;
489 struct isl_device isl_dev
;
490 int cmd_parser_version
;
493 uint32_t subslice_total
;
495 struct wsi_device wsi_device
;
498 struct anv_instance
{
499 VK_LOADER_DATA _loader_data
;
501 VkAllocationCallbacks alloc
;
504 int physicalDeviceCount
;
505 struct anv_physical_device physicalDevice
;
508 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
509 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
512 VK_LOADER_DATA _loader_data
;
514 struct anv_device
* device
;
516 struct anv_state_pool
* pool
;
519 struct anv_pipeline_cache
{
520 struct anv_device
* device
;
521 pthread_mutex_t mutex
;
523 struct hash_table
* cache
;
526 struct anv_pipeline_bind_map
;
528 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
529 struct anv_device
*device
,
531 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
533 struct anv_shader_bin
*
534 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
535 const void *key
, uint32_t key_size
);
536 struct anv_shader_bin
*
537 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
538 const void *key_data
, uint32_t key_size
,
539 const void *kernel_data
, uint32_t kernel_size
,
540 const struct brw_stage_prog_data
*prog_data
,
541 uint32_t prog_data_size
,
542 const struct anv_pipeline_bind_map
*bind_map
);
545 VK_LOADER_DATA _loader_data
;
547 VkAllocationCallbacks alloc
;
549 struct anv_instance
* instance
;
551 struct gen_device_info info
;
552 struct isl_device isl_dev
;
555 bool can_chain_batches
;
556 bool robust_buffer_access
;
558 struct anv_bo_pool batch_bo_pool
;
560 struct anv_block_pool dynamic_state_block_pool
;
561 struct anv_state_pool dynamic_state_pool
;
563 struct anv_block_pool instruction_block_pool
;
564 struct anv_state_pool instruction_state_pool
;
566 struct anv_block_pool surface_state_block_pool
;
567 struct anv_state_pool surface_state_pool
;
569 struct anv_bo workaround_bo
;
571 struct anv_pipeline_cache blorp_shader_cache
;
572 struct blorp_context blorp
;
574 struct anv_state border_colors
;
576 struct anv_queue queue
;
578 struct anv_scratch_pool scratch_pool
;
580 uint32_t default_mocs
;
582 pthread_mutex_t mutex
;
585 void anv_device_get_cache_uuid(void *uuid
);
587 void anv_device_init_blorp(struct anv_device
*device
);
588 void anv_device_finish_blorp(struct anv_device
*device
);
590 VkResult
anv_device_execbuf(struct anv_device
*device
,
591 struct drm_i915_gem_execbuffer2
*execbuf
,
592 struct anv_bo
**execbuf_bos
);
594 void* anv_gem_mmap(struct anv_device
*device
,
595 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
596 void anv_gem_munmap(void *p
, uint64_t size
);
597 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
598 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
599 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
600 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
601 int anv_gem_execbuffer(struct anv_device
*device
,
602 struct drm_i915_gem_execbuffer2
*execbuf
);
603 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
604 uint32_t stride
, uint32_t tiling
);
605 int anv_gem_create_context(struct anv_device
*device
);
606 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
607 int anv_gem_get_param(int fd
, uint32_t param
);
608 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
609 int anv_gem_get_aperture(int fd
, uint64_t *size
);
610 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
611 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
612 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
613 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
614 uint32_t read_domains
, uint32_t write_domain
);
616 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
618 struct anv_reloc_list
{
621 struct drm_i915_gem_relocation_entry
* relocs
;
622 struct anv_bo
** reloc_bos
;
625 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
626 const VkAllocationCallbacks
*alloc
);
627 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
628 const VkAllocationCallbacks
*alloc
);
630 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
631 const VkAllocationCallbacks
*alloc
,
632 uint32_t offset
, struct anv_bo
*target_bo
,
635 struct anv_batch_bo
{
636 /* Link in the anv_cmd_buffer.owned_batch_bos list */
637 struct list_head link
;
641 /* Bytes actually consumed in this batch BO */
644 /* Last seen surface state block pool bo offset */
645 uint32_t last_ss_pool_bo_offset
;
647 struct anv_reloc_list relocs
;
651 const VkAllocationCallbacks
* alloc
;
657 struct anv_reloc_list
* relocs
;
659 /* This callback is called (with the associated user data) in the event
660 * that the batch runs out of space.
662 VkResult (*extend_cb
)(struct anv_batch
*, void *);
666 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
667 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
668 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
669 void *location
, struct anv_bo
*bo
, uint32_t offset
);
670 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
671 struct anv_batch
*batch
);
678 static inline uint64_t
679 _anv_combine_address(struct anv_batch
*batch
, void *location
,
680 const struct anv_address address
, uint32_t delta
)
682 if (address
.bo
== NULL
) {
683 return address
.offset
+ delta
;
685 assert(batch
->start
<= location
&& location
< batch
->end
);
687 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
691 #define __gen_address_type struct anv_address
692 #define __gen_user_data struct anv_batch
693 #define __gen_combine_address _anv_combine_address
695 /* Wrapper macros needed to work around preprocessor argument issues. In
696 * particular, arguments don't get pre-evaluated if they are concatenated.
697 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
698 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
699 * We can work around this easily enough with these helpers.
701 #define __anv_cmd_length(cmd) cmd ## _length
702 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
703 #define __anv_cmd_header(cmd) cmd ## _header
704 #define __anv_cmd_pack(cmd) cmd ## _pack
705 #define __anv_reg_num(reg) reg ## _num
707 #define anv_pack_struct(dst, struc, ...) do { \
708 struct struc __template = { \
711 __anv_cmd_pack(struc)(NULL, dst, &__template); \
712 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
715 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
716 void *__dst = anv_batch_emit_dwords(batch, n); \
717 struct cmd __template = { \
718 __anv_cmd_header(cmd), \
719 .DWordLength = n - __anv_cmd_length_bias(cmd), \
722 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
726 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
730 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
731 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
732 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
733 dw[i] = (dwords0)[i] | (dwords1)[i]; \
734 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
737 #define anv_batch_emit(batch, cmd, name) \
738 for (struct cmd name = { __anv_cmd_header(cmd) }, \
739 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
740 __builtin_expect(_dst != NULL, 1); \
741 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
742 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
746 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
747 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
748 struct anv_state __state = \
749 anv_state_pool_alloc((pool), __size, align); \
750 struct cmd __template = { \
753 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
754 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
755 if (!(pool)->block_pool->device->info.has_llc) \
756 anv_state_clflush(__state); \
760 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
761 .GraphicsDataTypeGFDT = 0, \
762 .LLCCacheabilityControlLLCCC = 0, \
763 .L3CacheabilityControlL3CC = 1, \
766 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
767 .LLCeLLCCacheabilityControlLLCCC = 0, \
768 .L3CacheabilityControlL3CC = 1, \
771 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
772 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
773 .TargetCache = L3DefertoPATforLLCeLLCselection, \
777 /* Skylake: MOCS is now an index into an array of 62 different caching
778 * configurations programmed by the kernel.
781 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
782 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
783 .IndextoMOCSTables = 2 \
786 #define GEN9_MOCS_PTE { \
787 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
788 .IndextoMOCSTables = 1 \
791 struct anv_device_memory
{
794 VkDeviceSize map_size
;
799 * Header for Vertex URB Entry (VUE)
801 struct anv_vue_header
{
803 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
804 uint32_t ViewportIndex
;
808 struct anv_descriptor_set_binding_layout
{
810 /* The type of the descriptors in this binding */
811 VkDescriptorType type
;
814 /* Number of array elements in this binding */
817 /* Index into the flattend descriptor set */
818 uint16_t descriptor_index
;
820 /* Index into the dynamic state array for a dynamic buffer */
821 int16_t dynamic_offset_index
;
823 /* Index into the descriptor set buffer views */
824 int16_t buffer_index
;
827 /* Index into the binding table for the associated surface */
828 int16_t surface_index
;
830 /* Index into the sampler table for the associated sampler */
831 int16_t sampler_index
;
833 /* Index into the image table for the associated image */
835 } stage
[MESA_SHADER_STAGES
];
837 /* Immutable samplers (or NULL if no immutable samplers) */
838 struct anv_sampler
**immutable_samplers
;
841 struct anv_descriptor_set_layout
{
842 /* Number of bindings in this descriptor set */
843 uint16_t binding_count
;
845 /* Total size of the descriptor set with room for all array entries */
848 /* Shader stages affected by this descriptor set */
849 uint16_t shader_stages
;
851 /* Number of buffers in this descriptor set */
852 uint16_t buffer_count
;
854 /* Number of dynamic offsets used by this descriptor set */
855 uint16_t dynamic_offset_count
;
857 /* Bindings in this descriptor set */
858 struct anv_descriptor_set_binding_layout binding
[0];
861 struct anv_descriptor
{
862 VkDescriptorType type
;
866 struct anv_image_view
*image_view
;
867 struct anv_sampler
*sampler
;
870 struct anv_buffer_view
*buffer_view
;
874 struct anv_descriptor_set
{
875 const struct anv_descriptor_set_layout
*layout
;
877 uint32_t buffer_count
;
878 struct anv_buffer_view
*buffer_views
;
879 struct anv_descriptor descriptors
[0];
882 struct anv_descriptor_pool
{
887 struct anv_state_stream surface_state_stream
;
888 void *surface_state_free_list
;
894 anv_descriptor_set_create(struct anv_device
*device
,
895 struct anv_descriptor_pool
*pool
,
896 const struct anv_descriptor_set_layout
*layout
,
897 struct anv_descriptor_set
**out_set
);
900 anv_descriptor_set_destroy(struct anv_device
*device
,
901 struct anv_descriptor_pool
*pool
,
902 struct anv_descriptor_set
*set
);
904 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
906 struct anv_pipeline_binding
{
907 /* The descriptor set this surface corresponds to. The special value of
908 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
909 * to a color attachment and not a regular descriptor.
913 /* Binding in the descriptor set */
916 /* Index in the binding */
920 struct anv_pipeline_layout
{
922 struct anv_descriptor_set_layout
*layout
;
923 uint32_t dynamic_offset_start
;
929 bool has_dynamic_offsets
;
930 } stage
[MESA_SHADER_STAGES
];
932 unsigned char sha1
[20];
936 struct anv_device
* device
;
939 VkBufferUsageFlags usage
;
946 enum anv_cmd_dirty_bits
{
947 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
948 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
949 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
950 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
951 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
952 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
953 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
954 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
955 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
956 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
957 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
958 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
959 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
961 typedef uint32_t anv_cmd_dirty_mask_t
;
964 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
965 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
966 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
967 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
968 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
969 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
970 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
971 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
972 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
973 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
974 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
976 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
977 * a flush has happened but not a CS stall. The next time we do any sort
978 * of invalidation we need to insert a CS stall at that time. Otherwise,
979 * we would have to CS stall on every flush which could be bad.
981 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
984 #define ANV_PIPE_FLUSH_BITS ( \
985 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
986 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
987 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
989 #define ANV_PIPE_STALL_BITS ( \
990 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
991 ANV_PIPE_DEPTH_STALL_BIT | \
992 ANV_PIPE_CS_STALL_BIT)
994 #define ANV_PIPE_INVALIDATE_BITS ( \
995 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
996 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
997 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
998 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
999 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
1000 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
1002 struct anv_vertex_binding
{
1003 struct anv_buffer
* buffer
;
1004 VkDeviceSize offset
;
1007 struct anv_push_constants
{
1008 /* Current allocated size of this push constants data structure.
1009 * Because a decent chunk of it may not be used (images on SKL, for
1010 * instance), we won't actually allocate the entire structure up-front.
1014 /* Push constant data provided by the client through vkPushConstants */
1015 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1017 /* Our hardware only provides zero-based vertex and instance id so, in
1018 * order to satisfy the vulkan requirements, we may have to push one or
1019 * both of these into the shader.
1021 uint32_t base_vertex
;
1022 uint32_t base_instance
;
1024 /* Offsets and ranges for dynamically bound buffers */
1028 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1030 /* Image data for image_load_store on pre-SKL */
1031 struct brw_image_param images
[MAX_IMAGES
];
1034 struct anv_dynamic_state
{
1037 VkViewport viewports
[MAX_VIEWPORTS
];
1042 VkRect2D scissors
[MAX_SCISSORS
];
1053 float blend_constants
[4];
1063 } stencil_compare_mask
;
1068 } stencil_write_mask
;
1073 } stencil_reference
;
1076 extern const struct anv_dynamic_state default_dynamic_state
;
1078 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1079 const struct anv_dynamic_state
*src
,
1080 uint32_t copy_mask
);
1083 * Attachment state when recording a renderpass instance.
1085 * The clear value is valid only if there exists a pending clear.
1087 struct anv_attachment_state
{
1088 VkImageAspectFlags pending_clear_aspects
;
1089 VkClearValue clear_value
;
1092 /** State required while building cmd buffer */
1093 struct anv_cmd_state
{
1094 /* PIPELINE_SELECT.PipelineSelection */
1095 uint32_t current_pipeline
;
1096 const struct gen_l3_config
* current_l3_config
;
1098 anv_cmd_dirty_mask_t dirty
;
1099 anv_cmd_dirty_mask_t compute_dirty
;
1100 enum anv_pipe_bits pending_pipe_bits
;
1101 uint32_t num_workgroups_offset
;
1102 struct anv_bo
*num_workgroups_bo
;
1103 VkShaderStageFlags descriptors_dirty
;
1104 VkShaderStageFlags push_constants_dirty
;
1105 uint32_t scratch_size
;
1106 struct anv_pipeline
* pipeline
;
1107 struct anv_pipeline
* compute_pipeline
;
1108 struct anv_framebuffer
* framebuffer
;
1109 struct anv_render_pass
* pass
;
1110 struct anv_subpass
* subpass
;
1111 VkRect2D render_area
;
1112 uint32_t restart_index
;
1113 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1114 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1115 VkShaderStageFlags push_constant_stages
;
1116 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1117 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1118 struct anv_state samplers
[MESA_SHADER_STAGES
];
1119 struct anv_dynamic_state dynamic
;
1123 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1124 * valid only when recording a render pass instance.
1126 struct anv_attachment_state
* attachments
;
1129 struct anv_buffer
* index_buffer
;
1130 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1131 uint32_t index_offset
;
1135 struct anv_cmd_pool
{
1136 VkAllocationCallbacks alloc
;
1137 struct list_head cmd_buffers
;
1140 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1142 enum anv_cmd_buffer_exec_mode
{
1143 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1144 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1145 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1146 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1147 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1150 struct anv_cmd_buffer
{
1151 VK_LOADER_DATA _loader_data
;
1153 struct anv_device
* device
;
1155 struct anv_cmd_pool
* pool
;
1156 struct list_head pool_link
;
1158 struct anv_batch batch
;
1160 /* Fields required for the actual chain of anv_batch_bo's.
1162 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1164 struct list_head batch_bos
;
1165 enum anv_cmd_buffer_exec_mode exec_mode
;
1167 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1168 * referenced by this command buffer
1170 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1172 struct u_vector seen_bbos
;
1174 /* A vector of int32_t's for every block of binding tables.
1176 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1178 struct u_vector bt_blocks
;
1180 struct anv_reloc_list surface_relocs
;
1182 /* Information needed for execbuf
1184 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1187 struct drm_i915_gem_execbuffer2 execbuf
;
1189 struct drm_i915_gem_exec_object2
* objects
;
1191 struct anv_bo
** bos
;
1193 /* Allocated length of the 'objects' and 'bos' arrays */
1194 uint32_t array_length
;
1197 /* Serial for tracking buffer completion */
1200 /* Stream objects for storing temporary data */
1201 struct anv_state_stream surface_state_stream
;
1202 struct anv_state_stream dynamic_state_stream
;
1204 VkCommandBufferUsageFlags usage_flags
;
1205 VkCommandBufferLevel level
;
1207 struct anv_cmd_state state
;
1210 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1211 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1212 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1213 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1214 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1215 struct anv_cmd_buffer
*secondary
);
1216 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1217 VkResult
anv_cmd_buffer_execbuf(struct anv_device
*device
,
1218 struct anv_cmd_buffer
*cmd_buffer
);
1220 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1223 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1224 gl_shader_stage stage
, uint32_t size
);
1225 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1226 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1227 (offsetof(struct anv_push_constants, field) + \
1228 sizeof(cmd_buffer->state.push_constants[0]->field)))
1230 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1231 const void *data
, uint32_t size
, uint32_t alignment
);
1232 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1233 uint32_t *a
, uint32_t *b
,
1234 uint32_t dwords
, uint32_t alignment
);
1237 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1239 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1240 uint32_t entries
, uint32_t *state_offset
);
1242 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1244 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1245 uint32_t size
, uint32_t alignment
);
1248 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1250 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1251 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1252 bool depth_clamp_enable
);
1253 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1255 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1256 const VkRenderPassBeginInfo
*info
);
1259 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1260 gl_shader_stage stage
);
1262 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1264 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1265 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1267 const struct anv_image_view
*
1268 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1270 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1274 struct drm_i915_gem_execbuffer2 execbuf
;
1275 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1281 struct anv_state state
;
1284 struct anv_shader_module
{
1285 unsigned char sha1
[20];
1290 void anv_hash_shader(unsigned char *hash
, const void *key
, size_t key_size
,
1291 struct anv_shader_module
*module
,
1292 const char *entrypoint
,
1293 const struct anv_pipeline_layout
*pipeline_layout
,
1294 const VkSpecializationInfo
*spec_info
);
1296 static inline gl_shader_stage
1297 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1299 assert(__builtin_popcount(vk_stage
) == 1);
1300 return ffs(vk_stage
) - 1;
1303 static inline VkShaderStageFlagBits
1304 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1306 return (1 << mesa_stage
);
1309 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1311 #define anv_foreach_stage(stage, stage_bits) \
1312 for (gl_shader_stage stage, \
1313 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1314 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1315 __tmp &= ~(1 << (stage)))
1317 struct anv_pipeline_bind_map
{
1318 uint32_t surface_count
;
1319 uint32_t sampler_count
;
1320 uint32_t image_count
;
1322 struct anv_pipeline_binding
* surface_to_descriptor
;
1323 struct anv_pipeline_binding
* sampler_to_descriptor
;
1326 struct anv_shader_bin_key
{
1331 struct anv_shader_bin
{
1334 const struct anv_shader_bin_key
*key
;
1336 struct anv_state kernel
;
1337 uint32_t kernel_size
;
1339 const struct brw_stage_prog_data
*prog_data
;
1340 uint32_t prog_data_size
;
1342 struct anv_pipeline_bind_map bind_map
;
1344 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1347 struct anv_shader_bin
*
1348 anv_shader_bin_create(struct anv_device
*device
,
1349 const void *key
, uint32_t key_size
,
1350 const void *kernel
, uint32_t kernel_size
,
1351 const struct brw_stage_prog_data
*prog_data
,
1352 uint32_t prog_data_size
, const void *prog_data_param
,
1353 const struct anv_pipeline_bind_map
*bind_map
);
1356 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
1359 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
1361 assert(shader
->ref_cnt
>= 1);
1362 __sync_fetch_and_add(&shader
->ref_cnt
, 1);
1366 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
1368 assert(shader
->ref_cnt
>= 1);
1369 if (__sync_fetch_and_add(&shader
->ref_cnt
, -1) == 1)
1370 anv_shader_bin_destroy(device
, shader
);
1373 struct anv_pipeline
{
1374 struct anv_device
* device
;
1375 struct anv_batch batch
;
1376 uint32_t batch_data
[512];
1377 struct anv_reloc_list batch_relocs
;
1378 uint32_t dynamic_state_mask
;
1379 struct anv_dynamic_state dynamic_state
;
1381 struct anv_pipeline_layout
* layout
;
1383 bool needs_data_cache
;
1385 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
1388 const struct gen_l3_config
* l3_config
;
1389 uint32_t total_size
;
1392 VkShaderStageFlags active_stages
;
1393 struct anv_state blend_state
;
1401 uint32_t binding_stride
[MAX_VBS
];
1402 bool instancing_enable
[MAX_VBS
];
1403 bool primitive_restart
;
1406 uint32_t cs_right_mask
;
1408 bool depth_clamp_enable
;
1412 uint32_t depth_stencil_state
[3];
1418 uint32_t wm_depth_stencil
[3];
1422 uint32_t wm_depth_stencil
[4];
1427 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
1428 gl_shader_stage stage
)
1430 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
1433 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1434 static inline const struct brw_##prefix##_prog_data * \
1435 get_##prefix##_prog_data(struct anv_pipeline *pipeline) \
1437 if (anv_pipeline_has_stage(pipeline, stage)) { \
1438 return (const struct brw_##prefix##_prog_data *) \
1439 pipeline->shaders[stage]->prog_data; \
1445 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
1446 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
1447 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
1448 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
1451 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1452 struct anv_pipeline_cache
*cache
,
1453 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1454 const VkAllocationCallbacks
*alloc
);
1457 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1458 struct anv_pipeline_cache
*cache
,
1459 const VkComputePipelineCreateInfo
*info
,
1460 struct anv_shader_module
*module
,
1461 const char *entrypoint
,
1462 const VkSpecializationInfo
*spec_info
);
1465 enum isl_format isl_format
:16;
1466 struct isl_swizzle swizzle
;
1470 anv_get_format(const struct gen_device_info
*devinfo
, VkFormat format
,
1471 VkImageAspectFlags aspect
, VkImageTiling tiling
);
1473 static inline enum isl_format
1474 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
1475 VkImageAspectFlags aspect
, VkImageTiling tiling
)
1477 return anv_get_format(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
1481 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
1484 * Subsurface of an anv_image.
1486 struct anv_surface
{
1487 /** Valid only if isl_surf::size > 0. */
1488 struct isl_surf isl
;
1491 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1498 /* The original VkFormat provided by the client. This may not match any
1499 * of the actual surface formats.
1502 VkImageAspectFlags aspects
;
1505 uint32_t array_size
;
1506 uint32_t samples
; /**< VkImageCreateInfo::samples */
1507 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1508 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1513 /* Set when bound */
1515 VkDeviceSize offset
;
1520 * For each foo, anv_image::foo_surface is valid if and only if
1521 * anv_image::aspects has a foo aspect.
1523 * The hardware requires that the depth buffer and stencil buffer be
1524 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1525 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1526 * allocate the depth and stencil buffers as separate surfaces in the same
1530 struct anv_surface color_surface
;
1533 struct anv_surface depth_surface
;
1534 struct anv_surface hiz_surface
;
1535 struct anv_surface stencil_surface
;
1540 static inline uint32_t
1541 anv_get_layerCount(const struct anv_image
*image
,
1542 const VkImageSubresourceRange
*range
)
1544 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
?
1545 image
->array_size
- range
->baseArrayLayer
: range
->layerCount
;
1548 static inline uint32_t
1549 anv_get_levelCount(const struct anv_image
*image
,
1550 const VkImageSubresourceRange
*range
)
1552 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
1553 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
1557 struct anv_image_view
{
1558 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1560 uint32_t offset
; /**< Offset into bo. */
1562 struct isl_view isl
;
1564 VkImageAspectFlags aspect_mask
;
1566 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1568 /** RENDER_SURFACE_STATE when using image as a color render target. */
1569 struct anv_state color_rt_surface_state
;
1571 /** RENDER_SURFACE_STATE when using image as a sampler surface. */
1572 struct anv_state sampler_surface_state
;
1574 /** RENDER_SURFACE_STATE when using image as a storage image. */
1575 struct anv_state storage_surface_state
;
1577 struct brw_image_param storage_image_param
;
1580 struct anv_image_create_info
{
1581 const VkImageCreateInfo
*vk_info
;
1583 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
1584 isl_tiling_flags_t isl_tiling_flags
;
1589 VkResult
anv_image_create(VkDevice _device
,
1590 const struct anv_image_create_info
*info
,
1591 const VkAllocationCallbacks
* alloc
,
1594 const struct anv_surface
*
1595 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
1596 VkImageAspectFlags aspect_mask
);
1599 anv_image_has_hiz(const struct anv_image
*image
)
1601 /* We must check the aspect because anv_image::hiz_surface belongs to
1604 return (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) &&
1605 image
->hiz_surface
.isl
.size
> 0;
1608 struct anv_buffer_view
{
1609 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1611 uint32_t offset
; /**< Offset into bo. */
1612 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1614 struct anv_state surface_state
;
1615 struct anv_state storage_surface_state
;
1617 struct brw_image_param storage_image_param
;
1621 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
1623 static inline struct VkExtent3D
1624 anv_sanitize_image_extent(const VkImageType imageType
,
1625 const struct VkExtent3D imageExtent
)
1627 switch (imageType
) {
1628 case VK_IMAGE_TYPE_1D
:
1629 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1630 case VK_IMAGE_TYPE_2D
:
1631 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1632 case VK_IMAGE_TYPE_3D
:
1635 unreachable("invalid image type");
1639 static inline struct VkOffset3D
1640 anv_sanitize_image_offset(const VkImageType imageType
,
1641 const struct VkOffset3D imageOffset
)
1643 switch (imageType
) {
1644 case VK_IMAGE_TYPE_1D
:
1645 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1646 case VK_IMAGE_TYPE_2D
:
1647 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1648 case VK_IMAGE_TYPE_3D
:
1651 unreachable("invalid image type");
1656 void anv_fill_buffer_surface_state(struct anv_device
*device
,
1657 struct anv_state state
,
1658 enum isl_format format
,
1659 uint32_t offset
, uint32_t range
,
1662 void anv_image_view_fill_image_param(struct anv_device
*device
,
1663 struct anv_image_view
*view
,
1664 struct brw_image_param
*param
);
1665 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1666 struct anv_buffer_view
*view
,
1667 struct brw_image_param
*param
);
1669 struct anv_sampler
{
1673 struct anv_framebuffer
{
1678 uint32_t attachment_count
;
1679 struct anv_image_view
* attachments
[0];
1682 struct anv_subpass
{
1683 uint32_t input_count
;
1684 uint32_t * input_attachments
;
1685 uint32_t color_count
;
1686 uint32_t * color_attachments
;
1687 uint32_t * resolve_attachments
;
1688 uint32_t depth_stencil_attachment
;
1690 /** Subpass has at least one resolve attachment */
1694 struct anv_render_pass_attachment
{
1697 VkAttachmentLoadOp load_op
;
1698 VkAttachmentStoreOp store_op
;
1699 VkAttachmentLoadOp stencil_load_op
;
1702 struct anv_render_pass
{
1703 uint32_t attachment_count
;
1704 uint32_t subpass_count
;
1705 uint32_t * subpass_attachments
;
1706 struct anv_render_pass_attachment
* attachments
;
1707 struct anv_subpass subpasses
[0];
1710 struct anv_query_pool_slot
{
1716 struct anv_query_pool
{
1722 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
1725 void anv_dump_image_to_ppm(struct anv_device
*device
,
1726 struct anv_image
*image
, unsigned miplevel
,
1727 unsigned array_layer
, VkImageAspectFlagBits aspect
,
1728 const char *filename
);
1730 enum anv_dump_action
{
1731 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
1734 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
1735 void anv_dump_finish(void);
1737 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
1738 struct anv_framebuffer
*fb
);
1740 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1742 static inline struct __anv_type * \
1743 __anv_type ## _from_handle(__VkType _handle) \
1745 return (struct __anv_type *) _handle; \
1748 static inline __VkType \
1749 __anv_type ## _to_handle(struct __anv_type *_obj) \
1751 return (__VkType) _obj; \
1754 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1756 static inline struct __anv_type * \
1757 __anv_type ## _from_handle(__VkType _handle) \
1759 return (struct __anv_type *)(uintptr_t) _handle; \
1762 static inline __VkType \
1763 __anv_type ## _to_handle(struct __anv_type *_obj) \
1765 return (__VkType)(uintptr_t) _obj; \
1768 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1769 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1771 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1772 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1773 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1774 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1775 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1777 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1778 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1779 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1780 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
1781 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1782 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1783 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1784 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1785 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1786 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1787 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1788 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1789 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1790 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1791 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1792 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1793 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1794 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1795 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1797 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1799 static inline const __VkType * \
1800 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1802 return (const __VkType *) __anv_obj; \
1805 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1806 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1808 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1809 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1810 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)
1812 /* Gen-specific function declarations */
1814 # include "anv_genX.h"
1816 # define genX(x) gen7_##x
1817 # include "anv_genX.h"
1819 # define genX(x) gen75_##x
1820 # include "anv_genX.h"
1822 # define genX(x) gen8_##x
1823 # include "anv_genX.h"
1825 # define genX(x) gen9_##x
1826 # include "anv_genX.h"
1834 #endif /* ANV_PRIVATE_H */