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).
273 /* Represents a lock-free linked list of "free" things. This is used by
274 * both the block pool and the state pools. Unfortunately, in order to
275 * solve the ABA problem, we can't use a single uint32_t head.
277 union anv_free_list
{
281 /* A simple count that is incremented every time the head changes. */
287 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
289 struct anv_block_state
{
299 struct anv_block_pool
{
300 struct anv_device
*device
;
304 /* The offset from the start of the bo to the "center" of the block
305 * pool. Pointers to allocated blocks are given by
306 * bo.map + center_bo_offset + offsets.
308 uint32_t center_bo_offset
;
310 /* Current memory map of the block pool. This pointer may or may not
311 * point to the actual beginning of the block pool memory. If
312 * anv_block_pool_alloc_back has ever been called, then this pointer
313 * will point to the "center" position of the buffer and all offsets
314 * (negative or positive) given out by the block pool alloc functions
315 * will be valid relative to this pointer.
317 * In particular, map == bo.map + center_offset
323 * Array of mmaps and gem handles owned by the block pool, reclaimed when
324 * the block pool is destroyed.
326 struct u_vector mmap_cleanups
;
330 union anv_free_list free_list
;
331 struct anv_block_state state
;
333 union anv_free_list back_free_list
;
334 struct anv_block_state back_state
;
337 /* Block pools are backed by a fixed-size 2GB memfd */
338 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
340 /* The center of the block pool is also the middle of the memfd. This may
341 * change in the future if we decide differently for some reason.
343 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
345 static inline uint32_t
346 anv_block_pool_size(struct anv_block_pool
*pool
)
348 return pool
->state
.end
+ pool
->back_state
.end
;
357 struct anv_fixed_size_state_pool
{
359 union anv_free_list free_list
;
360 struct anv_block_state block
;
363 #define ANV_MIN_STATE_SIZE_LOG2 6
364 #define ANV_MAX_STATE_SIZE_LOG2 17
366 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
368 struct anv_state_pool
{
369 struct anv_block_pool
*block_pool
;
370 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
373 struct anv_state_stream_block
;
375 struct anv_state_stream
{
376 struct anv_block_pool
*block_pool
;
378 /* The current working block */
379 struct anv_state_stream_block
*block
;
381 /* Offset at which the current block starts */
383 /* Offset at which to allocate the next state */
385 /* Offset at which the current block ends */
389 #define CACHELINE_SIZE 64
390 #define CACHELINE_MASK 63
393 anv_clflush_range(void *start
, size_t size
)
395 void *p
= (void *) (((uintptr_t) start
) & ~CACHELINE_MASK
);
396 void *end
= start
+ size
;
398 __builtin_ia32_mfence();
400 __builtin_ia32_clflush(p
);
406 anv_state_clflush(struct anv_state state
)
408 anv_clflush_range(state
.map
, state
.alloc_size
);
411 void anv_block_pool_init(struct anv_block_pool
*pool
,
412 struct anv_device
*device
, uint32_t block_size
);
413 void anv_block_pool_finish(struct anv_block_pool
*pool
);
414 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
415 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
416 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
417 void anv_state_pool_init(struct anv_state_pool
*pool
,
418 struct anv_block_pool
*block_pool
);
419 void anv_state_pool_finish(struct anv_state_pool
*pool
);
420 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
421 size_t state_size
, size_t alignment
);
422 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
423 void anv_state_stream_init(struct anv_state_stream
*stream
,
424 struct anv_block_pool
*block_pool
);
425 void anv_state_stream_finish(struct anv_state_stream
*stream
);
426 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
427 uint32_t size
, uint32_t alignment
);
430 * Implements a pool of re-usable BOs. The interface is identical to that
431 * of block_pool except that each block is its own BO.
434 struct anv_device
*device
;
439 void anv_bo_pool_init(struct anv_bo_pool
*pool
, struct anv_device
*device
);
440 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
441 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
,
443 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
445 struct anv_scratch_pool
{
446 /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
447 struct anv_bo bos
[16][MESA_SHADER_STAGES
];
450 void anv_scratch_pool_init(struct anv_device
*device
,
451 struct anv_scratch_pool
*pool
);
452 void anv_scratch_pool_finish(struct anv_device
*device
,
453 struct anv_scratch_pool
*pool
);
454 struct anv_bo
*anv_scratch_pool_alloc(struct anv_device
*device
,
455 struct anv_scratch_pool
*pool
,
456 gl_shader_stage stage
,
457 unsigned per_thread_scratch
);
459 extern struct anv_dispatch_table dtable
;
461 #define VK_ICD_WSI_PLATFORM_MAX 5
463 struct anv_physical_device
{
464 VK_LOADER_DATA _loader_data
;
466 struct anv_instance
* instance
;
470 struct gen_device_info info
;
471 uint64_t aperture_size
;
472 struct brw_compiler
* compiler
;
473 struct isl_device isl_dev
;
474 int cmd_parser_version
;
477 uint32_t subslice_total
;
479 struct wsi_device wsi_device
;
482 struct anv_instance
{
483 VK_LOADER_DATA _loader_data
;
485 VkAllocationCallbacks alloc
;
488 int physicalDeviceCount
;
489 struct anv_physical_device physicalDevice
;
492 VkResult
anv_init_wsi(struct anv_physical_device
*physical_device
);
493 void anv_finish_wsi(struct anv_physical_device
*physical_device
);
496 VK_LOADER_DATA _loader_data
;
498 struct anv_device
* device
;
500 struct anv_state_pool
* pool
;
503 struct anv_pipeline_cache
{
504 struct anv_device
* device
;
505 pthread_mutex_t mutex
;
507 struct hash_table
* cache
;
510 struct anv_pipeline_bind_map
;
512 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
513 struct anv_device
*device
,
515 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
517 struct anv_shader_bin
*
518 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
519 const void *key
, uint32_t key_size
);
520 struct anv_shader_bin
*
521 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
522 const void *key_data
, uint32_t key_size
,
523 const void *kernel_data
, uint32_t kernel_size
,
524 const struct brw_stage_prog_data
*prog_data
,
525 uint32_t prog_data_size
,
526 const struct anv_pipeline_bind_map
*bind_map
);
529 VK_LOADER_DATA _loader_data
;
531 VkAllocationCallbacks alloc
;
533 struct anv_instance
* instance
;
535 struct gen_device_info info
;
536 struct isl_device isl_dev
;
539 bool can_chain_batches
;
540 bool robust_buffer_access
;
542 struct anv_bo_pool batch_bo_pool
;
544 struct anv_block_pool dynamic_state_block_pool
;
545 struct anv_state_pool dynamic_state_pool
;
547 struct anv_block_pool instruction_block_pool
;
548 struct anv_state_pool instruction_state_pool
;
550 struct anv_block_pool surface_state_block_pool
;
551 struct anv_state_pool surface_state_pool
;
553 struct anv_bo workaround_bo
;
555 struct anv_pipeline_cache blorp_shader_cache
;
556 struct blorp_context blorp
;
558 struct anv_state border_colors
;
560 struct anv_queue queue
;
562 struct anv_scratch_pool scratch_pool
;
564 uint32_t default_mocs
;
566 pthread_mutex_t mutex
;
569 void anv_device_get_cache_uuid(void *uuid
);
571 void anv_device_init_blorp(struct anv_device
*device
);
572 void anv_device_finish_blorp(struct anv_device
*device
);
574 void* anv_gem_mmap(struct anv_device
*device
,
575 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
576 void anv_gem_munmap(void *p
, uint64_t size
);
577 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
578 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
579 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
580 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
581 int anv_gem_execbuffer(struct anv_device
*device
,
582 struct drm_i915_gem_execbuffer2
*execbuf
);
583 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
584 uint32_t stride
, uint32_t tiling
);
585 int anv_gem_create_context(struct anv_device
*device
);
586 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
587 int anv_gem_get_param(int fd
, uint32_t param
);
588 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
589 int anv_gem_get_aperture(int fd
, uint64_t *size
);
590 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
591 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
592 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
593 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
594 uint32_t read_domains
, uint32_t write_domain
);
596 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
598 struct anv_reloc_list
{
601 struct drm_i915_gem_relocation_entry
* relocs
;
602 struct anv_bo
** reloc_bos
;
605 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
606 const VkAllocationCallbacks
*alloc
);
607 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
608 const VkAllocationCallbacks
*alloc
);
610 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
611 const VkAllocationCallbacks
*alloc
,
612 uint32_t offset
, struct anv_bo
*target_bo
,
615 struct anv_batch_bo
{
616 /* Link in the anv_cmd_buffer.owned_batch_bos list */
617 struct list_head link
;
621 /* Bytes actually consumed in this batch BO */
624 /* Last seen surface state block pool bo offset */
625 uint32_t last_ss_pool_bo_offset
;
627 struct anv_reloc_list relocs
;
631 const VkAllocationCallbacks
* alloc
;
637 struct anv_reloc_list
* relocs
;
639 /* This callback is called (with the associated user data) in the event
640 * that the batch runs out of space.
642 VkResult (*extend_cb
)(struct anv_batch
*, void *);
646 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
647 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
648 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
649 void *location
, struct anv_bo
*bo
, uint32_t offset
);
650 VkResult
anv_device_submit_simple_batch(struct anv_device
*device
,
651 struct anv_batch
*batch
);
658 static inline uint64_t
659 _anv_combine_address(struct anv_batch
*batch
, void *location
,
660 const struct anv_address address
, uint32_t delta
)
662 if (address
.bo
== NULL
) {
663 return address
.offset
+ delta
;
665 assert(batch
->start
<= location
&& location
< batch
->end
);
667 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
671 #define __gen_address_type struct anv_address
672 #define __gen_user_data struct anv_batch
673 #define __gen_combine_address _anv_combine_address
675 /* Wrapper macros needed to work around preprocessor argument issues. In
676 * particular, arguments don't get pre-evaluated if they are concatenated.
677 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
678 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
679 * We can work around this easily enough with these helpers.
681 #define __anv_cmd_length(cmd) cmd ## _length
682 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
683 #define __anv_cmd_header(cmd) cmd ## _header
684 #define __anv_cmd_pack(cmd) cmd ## _pack
685 #define __anv_reg_num(reg) reg ## _num
687 #define anv_pack_struct(dst, struc, ...) do { \
688 struct struc __template = { \
691 __anv_cmd_pack(struc)(NULL, dst, &__template); \
692 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
695 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
696 void *__dst = anv_batch_emit_dwords(batch, n); \
697 struct cmd __template = { \
698 __anv_cmd_header(cmd), \
699 .DWordLength = n - __anv_cmd_length_bias(cmd), \
702 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
706 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
710 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
711 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
712 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
713 dw[i] = (dwords0)[i] | (dwords1)[i]; \
714 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
717 #define anv_batch_emit(batch, cmd, name) \
718 for (struct cmd name = { __anv_cmd_header(cmd) }, \
719 *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
720 __builtin_expect(_dst != NULL, 1); \
721 ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
722 VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
726 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
727 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
728 struct anv_state __state = \
729 anv_state_pool_alloc((pool), __size, align); \
730 struct cmd __template = { \
733 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
734 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
735 if (!(pool)->block_pool->device->info.has_llc) \
736 anv_state_clflush(__state); \
740 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
741 .GraphicsDataTypeGFDT = 0, \
742 .LLCCacheabilityControlLLCCC = 0, \
743 .L3CacheabilityControlL3CC = 1, \
746 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
747 .LLCeLLCCacheabilityControlLLCCC = 0, \
748 .L3CacheabilityControlL3CC = 1, \
751 #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
752 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
753 .TargetCache = L3DefertoPATforLLCeLLCselection, \
757 /* Skylake: MOCS is now an index into an array of 62 different caching
758 * configurations programmed by the kernel.
761 #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
762 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
763 .IndextoMOCSTables = 2 \
766 #define GEN9_MOCS_PTE { \
767 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
768 .IndextoMOCSTables = 1 \
771 struct anv_device_memory
{
774 VkDeviceSize map_size
;
779 * Header for Vertex URB Entry (VUE)
781 struct anv_vue_header
{
783 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
784 uint32_t ViewportIndex
;
788 struct anv_descriptor_set_binding_layout
{
790 /* The type of the descriptors in this binding */
791 VkDescriptorType type
;
794 /* Number of array elements in this binding */
797 /* Index into the flattend descriptor set */
798 uint16_t descriptor_index
;
800 /* Index into the dynamic state array for a dynamic buffer */
801 int16_t dynamic_offset_index
;
803 /* Index into the descriptor set buffer views */
804 int16_t buffer_index
;
807 /* Index into the binding table for the associated surface */
808 int16_t surface_index
;
810 /* Index into the sampler table for the associated sampler */
811 int16_t sampler_index
;
813 /* Index into the image table for the associated image */
815 } stage
[MESA_SHADER_STAGES
];
817 /* Immutable samplers (or NULL if no immutable samplers) */
818 struct anv_sampler
**immutable_samplers
;
821 struct anv_descriptor_set_layout
{
822 /* Number of bindings in this descriptor set */
823 uint16_t binding_count
;
825 /* Total size of the descriptor set with room for all array entries */
828 /* Shader stages affected by this descriptor set */
829 uint16_t shader_stages
;
831 /* Number of buffers in this descriptor set */
832 uint16_t buffer_count
;
834 /* Number of dynamic offsets used by this descriptor set */
835 uint16_t dynamic_offset_count
;
837 /* Bindings in this descriptor set */
838 struct anv_descriptor_set_binding_layout binding
[0];
841 struct anv_descriptor
{
842 VkDescriptorType type
;
846 struct anv_image_view
*image_view
;
847 struct anv_sampler
*sampler
;
850 struct anv_buffer_view
*buffer_view
;
854 struct anv_descriptor_set
{
855 const struct anv_descriptor_set_layout
*layout
;
857 uint32_t buffer_count
;
858 struct anv_buffer_view
*buffer_views
;
859 struct anv_descriptor descriptors
[0];
862 struct anv_descriptor_pool
{
867 struct anv_state_stream surface_state_stream
;
868 void *surface_state_free_list
;
874 anv_descriptor_set_create(struct anv_device
*device
,
875 struct anv_descriptor_pool
*pool
,
876 const struct anv_descriptor_set_layout
*layout
,
877 struct anv_descriptor_set
**out_set
);
880 anv_descriptor_set_destroy(struct anv_device
*device
,
881 struct anv_descriptor_pool
*pool
,
882 struct anv_descriptor_set
*set
);
884 #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
886 struct anv_pipeline_binding
{
887 /* The descriptor set this surface corresponds to. The special value of
888 * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
889 * to a color attachment and not a regular descriptor.
893 /* Binding in the descriptor set */
896 /* Index in the binding */
900 struct anv_pipeline_layout
{
902 struct anv_descriptor_set_layout
*layout
;
903 uint32_t dynamic_offset_start
;
909 bool has_dynamic_offsets
;
910 } stage
[MESA_SHADER_STAGES
];
912 unsigned char sha1
[20];
916 struct anv_device
* device
;
919 VkBufferUsageFlags usage
;
926 enum anv_cmd_dirty_bits
{
927 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
928 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
929 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
930 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
931 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
932 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
933 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
934 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
935 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
936 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
937 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
938 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
939 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
941 typedef uint32_t anv_cmd_dirty_mask_t
;
944 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
= (1 << 0),
945 ANV_PIPE_STALL_AT_SCOREBOARD_BIT
= (1 << 1),
946 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT
= (1 << 2),
947 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT
= (1 << 3),
948 ANV_PIPE_VF_CACHE_INVALIDATE_BIT
= (1 << 4),
949 ANV_PIPE_DATA_CACHE_FLUSH_BIT
= (1 << 5),
950 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
= (1 << 10),
951 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT
= (1 << 11),
952 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
= (1 << 12),
953 ANV_PIPE_DEPTH_STALL_BIT
= (1 << 13),
954 ANV_PIPE_CS_STALL_BIT
= (1 << 20),
956 /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
957 * a flush has happened but not a CS stall. The next time we do any sort
958 * of invalidation we need to insert a CS stall at that time. Otherwise,
959 * we would have to CS stall on every flush which could be bad.
961 ANV_PIPE_NEEDS_CS_STALL_BIT
= (1 << 21),
964 #define ANV_PIPE_FLUSH_BITS ( \
965 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
966 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
967 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
969 #define ANV_PIPE_STALL_BITS ( \
970 ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
971 ANV_PIPE_DEPTH_STALL_BIT | \
972 ANV_PIPE_CS_STALL_BIT)
974 #define ANV_PIPE_INVALIDATE_BITS ( \
975 ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
976 ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
977 ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
978 ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
979 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
980 ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
982 struct anv_vertex_binding
{
983 struct anv_buffer
* buffer
;
987 struct anv_push_constants
{
988 /* Current allocated size of this push constants data structure.
989 * Because a decent chunk of it may not be used (images on SKL, for
990 * instance), we won't actually allocate the entire structure up-front.
994 /* Push constant data provided by the client through vkPushConstants */
995 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
997 /* Our hardware only provides zero-based vertex and instance id so, in
998 * order to satisfy the vulkan requirements, we may have to push one or
999 * both of these into the shader.
1001 uint32_t base_vertex
;
1002 uint32_t base_instance
;
1004 /* Offsets and ranges for dynamically bound buffers */
1008 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1010 /* Image data for image_load_store on pre-SKL */
1011 struct brw_image_param images
[MAX_IMAGES
];
1014 struct anv_dynamic_state
{
1017 VkViewport viewports
[MAX_VIEWPORTS
];
1022 VkRect2D scissors
[MAX_SCISSORS
];
1033 float blend_constants
[4];
1043 } stencil_compare_mask
;
1048 } stencil_write_mask
;
1053 } stencil_reference
;
1056 extern const struct anv_dynamic_state default_dynamic_state
;
1058 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1059 const struct anv_dynamic_state
*src
,
1060 uint32_t copy_mask
);
1063 * Attachment state when recording a renderpass instance.
1065 * The clear value is valid only if there exists a pending clear.
1067 struct anv_attachment_state
{
1068 VkImageAspectFlags pending_clear_aspects
;
1069 VkClearValue clear_value
;
1072 /** State required while building cmd buffer */
1073 struct anv_cmd_state
{
1074 /* PIPELINE_SELECT.PipelineSelection */
1075 uint32_t current_pipeline
;
1076 const struct gen_l3_config
* current_l3_config
;
1078 anv_cmd_dirty_mask_t dirty
;
1079 anv_cmd_dirty_mask_t compute_dirty
;
1080 enum anv_pipe_bits pending_pipe_bits
;
1081 uint32_t num_workgroups_offset
;
1082 struct anv_bo
*num_workgroups_bo
;
1083 VkShaderStageFlags descriptors_dirty
;
1084 VkShaderStageFlags push_constants_dirty
;
1085 uint32_t scratch_size
;
1086 struct anv_pipeline
* pipeline
;
1087 struct anv_pipeline
* compute_pipeline
;
1088 struct anv_framebuffer
* framebuffer
;
1089 struct anv_render_pass
* pass
;
1090 struct anv_subpass
* subpass
;
1091 VkRect2D render_area
;
1092 uint32_t restart_index
;
1093 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1094 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1095 VkShaderStageFlags push_constant_stages
;
1096 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1097 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1098 struct anv_state samplers
[MESA_SHADER_STAGES
];
1099 struct anv_dynamic_state dynamic
;
1103 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1104 * valid only when recording a render pass instance.
1106 struct anv_attachment_state
* attachments
;
1109 struct anv_buffer
* index_buffer
;
1110 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1111 uint32_t index_offset
;
1115 struct anv_cmd_pool
{
1116 VkAllocationCallbacks alloc
;
1117 struct list_head cmd_buffers
;
1120 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1122 enum anv_cmd_buffer_exec_mode
{
1123 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1124 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1125 ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT
,
1126 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1127 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1130 struct anv_cmd_buffer
{
1131 VK_LOADER_DATA _loader_data
;
1133 struct anv_device
* device
;
1135 struct anv_cmd_pool
* pool
;
1136 struct list_head pool_link
;
1138 struct anv_batch batch
;
1140 /* Fields required for the actual chain of anv_batch_bo's.
1142 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1144 struct list_head batch_bos
;
1145 enum anv_cmd_buffer_exec_mode exec_mode
;
1147 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1148 * referenced by this command buffer
1150 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1152 struct u_vector seen_bbos
;
1154 /* A vector of int32_t's for every block of binding tables.
1156 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1158 struct u_vector bt_blocks
;
1160 struct anv_reloc_list surface_relocs
;
1162 /* Information needed for execbuf
1164 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1167 struct drm_i915_gem_execbuffer2 execbuf
;
1169 struct drm_i915_gem_exec_object2
* objects
;
1171 struct anv_bo
** bos
;
1173 /* Allocated length of the 'objects' and 'bos' arrays */
1174 uint32_t array_length
;
1179 /* Serial for tracking buffer completion */
1182 /* Stream objects for storing temporary data */
1183 struct anv_state_stream surface_state_stream
;
1184 struct anv_state_stream dynamic_state_stream
;
1186 VkCommandBufferUsageFlags usage_flags
;
1187 VkCommandBufferLevel level
;
1189 struct anv_cmd_state state
;
1192 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1193 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1194 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1195 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1196 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1197 struct anv_cmd_buffer
*secondary
);
1198 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1200 VkResult
anv_cmd_buffer_reset(struct anv_cmd_buffer
*cmd_buffer
);
1203 anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer
*cmd_buffer
,
1204 gl_shader_stage stage
, uint32_t size
);
1205 #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
1206 anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
1207 (offsetof(struct anv_push_constants, field) + \
1208 sizeof(cmd_buffer->state.push_constants[0]->field)))
1210 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1211 const void *data
, uint32_t size
, uint32_t alignment
);
1212 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1213 uint32_t *a
, uint32_t *b
,
1214 uint32_t dwords
, uint32_t alignment
);
1217 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1219 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1220 uint32_t entries
, uint32_t *state_offset
);
1222 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1224 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1225 uint32_t size
, uint32_t alignment
);
1228 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1230 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1231 void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer
*cmd_buffer
,
1232 bool depth_clamp_enable
);
1233 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1235 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1236 const VkRenderPassBeginInfo
*info
);
1239 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1240 gl_shader_stage stage
);
1242 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1244 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1245 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1247 const struct anv_image_view
*
1248 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1250 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1254 struct drm_i915_gem_execbuffer2 execbuf
;
1255 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1261 struct anv_state state
;
1264 struct anv_shader_module
{
1265 unsigned char sha1
[20];
1270 void anv_hash_shader(unsigned char *hash
, const void *key
, size_t key_size
,
1271 struct anv_shader_module
*module
,
1272 const char *entrypoint
,
1273 const struct anv_pipeline_layout
*pipeline_layout
,
1274 const VkSpecializationInfo
*spec_info
);
1276 static inline gl_shader_stage
1277 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1279 assert(__builtin_popcount(vk_stage
) == 1);
1280 return ffs(vk_stage
) - 1;
1283 static inline VkShaderStageFlagBits
1284 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1286 return (1 << mesa_stage
);
1289 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1291 #define anv_foreach_stage(stage, stage_bits) \
1292 for (gl_shader_stage stage, \
1293 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1294 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1295 __tmp &= ~(1 << (stage)))
1297 struct anv_pipeline_bind_map
{
1298 uint32_t surface_count
;
1299 uint32_t sampler_count
;
1300 uint32_t image_count
;
1302 struct anv_pipeline_binding
* surface_to_descriptor
;
1303 struct anv_pipeline_binding
* sampler_to_descriptor
;
1306 struct anv_shader_bin_key
{
1311 struct anv_shader_bin
{
1314 const struct anv_shader_bin_key
*key
;
1316 struct anv_state kernel
;
1317 uint32_t kernel_size
;
1319 const struct brw_stage_prog_data
*prog_data
;
1320 uint32_t prog_data_size
;
1322 struct anv_pipeline_bind_map bind_map
;
1324 /* Prog data follows, then params, then the key, all aligned to 8-bytes */
1327 struct anv_shader_bin
*
1328 anv_shader_bin_create(struct anv_device
*device
,
1329 const void *key
, uint32_t key_size
,
1330 const void *kernel
, uint32_t kernel_size
,
1331 const struct brw_stage_prog_data
*prog_data
,
1332 uint32_t prog_data_size
, const void *prog_data_param
,
1333 const struct anv_pipeline_bind_map
*bind_map
);
1336 anv_shader_bin_destroy(struct anv_device
*device
, struct anv_shader_bin
*shader
);
1339 anv_shader_bin_ref(struct anv_shader_bin
*shader
)
1341 assert(shader
->ref_cnt
>= 1);
1342 __sync_fetch_and_add(&shader
->ref_cnt
, 1);
1346 anv_shader_bin_unref(struct anv_device
*device
, struct anv_shader_bin
*shader
)
1348 assert(shader
->ref_cnt
>= 1);
1349 if (__sync_fetch_and_add(&shader
->ref_cnt
, -1) == 1)
1350 anv_shader_bin_destroy(device
, shader
);
1353 struct anv_pipeline
{
1354 struct anv_device
* device
;
1355 struct anv_batch batch
;
1356 uint32_t batch_data
[512];
1357 struct anv_reloc_list batch_relocs
;
1358 uint32_t dynamic_state_mask
;
1359 struct anv_dynamic_state dynamic_state
;
1361 struct anv_pipeline_layout
* layout
;
1363 bool needs_data_cache
;
1365 struct anv_shader_bin
* shaders
[MESA_SHADER_STAGES
];
1368 const struct gen_l3_config
* l3_config
;
1369 uint32_t total_size
;
1372 VkShaderStageFlags active_stages
;
1373 struct anv_state blend_state
;
1381 uint32_t binding_stride
[MAX_VBS
];
1382 bool instancing_enable
[MAX_VBS
];
1383 bool primitive_restart
;
1386 uint32_t cs_right_mask
;
1388 bool depth_clamp_enable
;
1392 uint32_t depth_stencil_state
[3];
1398 uint32_t wm_depth_stencil
[3];
1402 uint32_t wm_depth_stencil
[4];
1407 anv_pipeline_has_stage(const struct anv_pipeline
*pipeline
,
1408 gl_shader_stage stage
)
1410 return (pipeline
->active_stages
& mesa_to_vk_shader_stage(stage
)) != 0;
1413 #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
1414 static inline const struct brw_##prefix##_prog_data * \
1415 get_##prefix##_prog_data(struct anv_pipeline *pipeline) \
1417 if (anv_pipeline_has_stage(pipeline, stage)) { \
1418 return (const struct brw_##prefix##_prog_data *) \
1419 pipeline->shaders[stage]->prog_data; \
1425 ANV_DECL_GET_PROG_DATA_FUNC(vs
, MESA_SHADER_VERTEX
)
1426 ANV_DECL_GET_PROG_DATA_FUNC(gs
, MESA_SHADER_GEOMETRY
)
1427 ANV_DECL_GET_PROG_DATA_FUNC(wm
, MESA_SHADER_FRAGMENT
)
1428 ANV_DECL_GET_PROG_DATA_FUNC(cs
, MESA_SHADER_COMPUTE
)
1431 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1432 struct anv_pipeline_cache
*cache
,
1433 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1434 const VkAllocationCallbacks
*alloc
);
1437 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1438 struct anv_pipeline_cache
*cache
,
1439 const VkComputePipelineCreateInfo
*info
,
1440 struct anv_shader_module
*module
,
1441 const char *entrypoint
,
1442 const VkSpecializationInfo
*spec_info
);
1445 enum isl_format isl_format
:16;
1446 struct isl_swizzle swizzle
;
1450 anv_get_format(const struct gen_device_info
*devinfo
, VkFormat format
,
1451 VkImageAspectFlags aspect
, VkImageTiling tiling
);
1453 static inline enum isl_format
1454 anv_get_isl_format(const struct gen_device_info
*devinfo
, VkFormat vk_format
,
1455 VkImageAspectFlags aspect
, VkImageTiling tiling
)
1457 return anv_get_format(devinfo
, vk_format
, aspect
, tiling
).isl_format
;
1461 anv_pipeline_setup_l3_config(struct anv_pipeline
*pipeline
, bool needs_slm
);
1464 * Subsurface of an anv_image.
1466 struct anv_surface
{
1467 /** Valid only if isl_surf::size > 0. */
1468 struct isl_surf isl
;
1471 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1478 /* The original VkFormat provided by the client. This may not match any
1479 * of the actual surface formats.
1482 VkImageAspectFlags aspects
;
1485 uint32_t array_size
;
1486 uint32_t samples
; /**< VkImageCreateInfo::samples */
1487 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1488 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1493 /* Set when bound */
1495 VkDeviceSize offset
;
1500 * For each foo, anv_image::foo_surface is valid if and only if
1501 * anv_image::aspects has a foo aspect.
1503 * The hardware requires that the depth buffer and stencil buffer be
1504 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1505 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1506 * allocate the depth and stencil buffers as separate surfaces in the same
1510 struct anv_surface color_surface
;
1513 struct anv_surface depth_surface
;
1514 struct anv_surface hiz_surface
;
1515 struct anv_surface stencil_surface
;
1520 static inline uint32_t
1521 anv_get_layerCount(const struct anv_image
*image
,
1522 const VkImageSubresourceRange
*range
)
1524 return range
->layerCount
== VK_REMAINING_ARRAY_LAYERS
?
1525 image
->array_size
- range
->baseArrayLayer
: range
->layerCount
;
1528 static inline uint32_t
1529 anv_get_levelCount(const struct anv_image
*image
,
1530 const VkImageSubresourceRange
*range
)
1532 return range
->levelCount
== VK_REMAINING_MIP_LEVELS
?
1533 image
->levels
- range
->baseMipLevel
: range
->levelCount
;
1537 struct anv_image_view
{
1538 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1540 uint32_t offset
; /**< Offset into bo. */
1542 struct isl_view isl
;
1544 VkImageAspectFlags aspect_mask
;
1546 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1548 /** RENDER_SURFACE_STATE when using image as a color render target. */
1549 struct anv_state color_rt_surface_state
;
1551 /** RENDER_SURFACE_STATE when using image as a sampler surface. */
1552 struct anv_state sampler_surface_state
;
1554 /** RENDER_SURFACE_STATE when using image as a storage image. */
1555 struct anv_state storage_surface_state
;
1557 struct brw_image_param storage_image_param
;
1560 struct anv_image_create_info
{
1561 const VkImageCreateInfo
*vk_info
;
1563 /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
1564 isl_tiling_flags_t isl_tiling_flags
;
1569 VkResult
anv_image_create(VkDevice _device
,
1570 const struct anv_image_create_info
*info
,
1571 const VkAllocationCallbacks
* alloc
,
1574 const struct anv_surface
*
1575 anv_image_get_surface_for_aspect_mask(const struct anv_image
*image
,
1576 VkImageAspectFlags aspect_mask
);
1579 anv_image_has_hiz(const struct anv_image
*image
)
1581 /* We must check the aspect because anv_image::hiz_surface belongs to
1584 return (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) &&
1585 image
->hiz_surface
.isl
.size
> 0;
1588 struct anv_buffer_view
{
1589 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1591 uint32_t offset
; /**< Offset into bo. */
1592 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1594 struct anv_state surface_state
;
1595 struct anv_state storage_surface_state
;
1597 struct brw_image_param storage_image_param
;
1601 anv_isl_format_for_descriptor_type(VkDescriptorType type
);
1603 static inline struct VkExtent3D
1604 anv_sanitize_image_extent(const VkImageType imageType
,
1605 const struct VkExtent3D imageExtent
)
1607 switch (imageType
) {
1608 case VK_IMAGE_TYPE_1D
:
1609 return (VkExtent3D
) { imageExtent
.width
, 1, 1 };
1610 case VK_IMAGE_TYPE_2D
:
1611 return (VkExtent3D
) { imageExtent
.width
, imageExtent
.height
, 1 };
1612 case VK_IMAGE_TYPE_3D
:
1615 unreachable("invalid image type");
1619 static inline struct VkOffset3D
1620 anv_sanitize_image_offset(const VkImageType imageType
,
1621 const struct VkOffset3D imageOffset
)
1623 switch (imageType
) {
1624 case VK_IMAGE_TYPE_1D
:
1625 return (VkOffset3D
) { imageOffset
.x
, 0, 0 };
1626 case VK_IMAGE_TYPE_2D
:
1627 return (VkOffset3D
) { imageOffset
.x
, imageOffset
.y
, 0 };
1628 case VK_IMAGE_TYPE_3D
:
1631 unreachable("invalid image type");
1636 void anv_fill_buffer_surface_state(struct anv_device
*device
,
1637 struct anv_state state
,
1638 enum isl_format format
,
1639 uint32_t offset
, uint32_t range
,
1642 void anv_image_view_fill_image_param(struct anv_device
*device
,
1643 struct anv_image_view
*view
,
1644 struct brw_image_param
*param
);
1645 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1646 struct anv_buffer_view
*view
,
1647 struct brw_image_param
*param
);
1649 struct anv_sampler
{
1653 struct anv_framebuffer
{
1658 uint32_t attachment_count
;
1659 struct anv_image_view
* attachments
[0];
1662 struct anv_subpass
{
1663 uint32_t input_count
;
1664 uint32_t * input_attachments
;
1665 uint32_t color_count
;
1666 uint32_t * color_attachments
;
1667 uint32_t * resolve_attachments
;
1668 uint32_t depth_stencil_attachment
;
1670 /** Subpass has at least one resolve attachment */
1674 struct anv_render_pass_attachment
{
1677 VkAttachmentLoadOp load_op
;
1678 VkAttachmentStoreOp store_op
;
1679 VkAttachmentLoadOp stencil_load_op
;
1682 struct anv_render_pass
{
1683 uint32_t attachment_count
;
1684 uint32_t subpass_count
;
1685 uint32_t * subpass_attachments
;
1686 struct anv_render_pass_attachment
* attachments
;
1687 struct anv_subpass subpasses
[0];
1690 struct anv_query_pool_slot
{
1696 struct anv_query_pool
{
1702 void *anv_lookup_entrypoint(const struct gen_device_info
*devinfo
,
1705 void anv_dump_image_to_ppm(struct anv_device
*device
,
1706 struct anv_image
*image
, unsigned miplevel
,
1707 unsigned array_layer
, VkImageAspectFlagBits aspect
,
1708 const char *filename
);
1710 enum anv_dump_action
{
1711 ANV_DUMP_FRAMEBUFFERS_BIT
= 0x1,
1714 void anv_dump_start(struct anv_device
*device
, enum anv_dump_action actions
);
1715 void anv_dump_finish(void);
1717 void anv_dump_add_framebuffer(struct anv_cmd_buffer
*cmd_buffer
,
1718 struct anv_framebuffer
*fb
);
1720 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1722 static inline struct __anv_type * \
1723 __anv_type ## _from_handle(__VkType _handle) \
1725 return (struct __anv_type *) _handle; \
1728 static inline __VkType \
1729 __anv_type ## _to_handle(struct __anv_type *_obj) \
1731 return (__VkType) _obj; \
1734 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1736 static inline struct __anv_type * \
1737 __anv_type ## _from_handle(__VkType _handle) \
1739 return (struct __anv_type *)(uintptr_t) _handle; \
1742 static inline __VkType \
1743 __anv_type ## _to_handle(struct __anv_type *_obj) \
1745 return (__VkType)(uintptr_t) _obj; \
1748 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1749 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1751 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1752 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1753 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1754 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1755 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1757 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1758 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1759 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1760 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool
, VkDescriptorPool
)
1761 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1762 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1763 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1764 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1765 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1766 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1767 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1768 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1769 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1770 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1771 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1772 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1773 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1774 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1775 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1777 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1779 static inline const __VkType * \
1780 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1782 return (const __VkType *) __anv_obj; \
1785 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1786 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1788 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1789 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1790 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)
1792 /* Gen-specific function declarations */
1794 # include "anv_genX.h"
1796 # define genX(x) gen7_##x
1797 # include "anv_genX.h"
1799 # define genX(x) gen75_##x
1800 # include "anv_genX.h"
1802 # define genX(x) gen8_##x
1803 # include "anv_genX.h"
1805 # define genX(x) gen9_##x
1806 # include "anv_genX.h"
1814 #endif /* ANV_PRIVATE_H */