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
38 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
43 #include "brw_device_info.h"
44 #include "util/macros.h"
45 #include "util/list.h"
47 /* Pre-declarations needed for WSI entrypoints */
50 typedef struct xcb_connection_t xcb_connection_t
;
51 typedef uint32_t xcb_visualid_t
;
52 typedef uint32_t xcb_window_t
;
54 #define VK_USE_PLATFORM_XCB_KHR
55 #define VK_USE_PLATFORM_WAYLAND_KHR
58 #include <vulkan/vulkan.h>
59 #include <vulkan/vulkan_intel.h>
61 #include "anv_entrypoints.h"
62 #include "anv_gen_macros.h"
63 #include "brw_context.h"
70 #define ICD_LOADER_MAGIC 0x01CDC0DE
72 typedef union _VK_LOADER_DATA
{
73 uintptr_t loaderMagic
;
77 #define anv_noreturn __attribute__((__noreturn__))
78 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
80 #define MIN(a, b) ((a) < (b) ? (a) : (b))
81 #define MAX(a, b) ((a) > (b) ? (a) : (b))
83 static inline uint32_t
84 align_u32(uint32_t v
, uint32_t a
)
86 assert(a
!= 0 && a
== (a
& -a
));
87 return (v
+ a
- 1) & ~(a
- 1);
90 static inline uint64_t
91 align_u64(uint64_t v
, uint64_t a
)
93 assert(a
!= 0 && a
== (a
& -a
));
94 return (v
+ a
- 1) & ~(a
- 1);
98 align_i32(int32_t v
, int32_t a
)
100 assert(a
!= 0 && a
== (a
& -a
));
101 return (v
+ a
- 1) & ~(a
- 1);
104 /** Alignment must be a power of 2. */
106 anv_is_aligned(uintmax_t n
, uintmax_t a
)
108 assert(a
== (a
& -a
));
109 return (n
& (a
- 1)) == 0;
112 static inline uint32_t
113 anv_minify(uint32_t n
, uint32_t levels
)
115 if (unlikely(n
== 0))
118 return MAX(n
>> levels
, 1);
122 anv_clamp_f(float f
, float min
, float max
)
135 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
137 if (*inout_mask
& clear_mask
) {
138 *inout_mask
&= ~clear_mask
;
145 #define for_each_bit(b, dword) \
146 for (uint32_t __dword = (dword); \
147 (b) = __builtin_ffs(__dword) - 1, __dword; \
148 __dword &= ~(1 << (b)))
150 #define typed_memcpy(dest, src, count) ({ \
151 static_assert(sizeof(*src) == sizeof(*dest), ""); \
152 memcpy((dest), (src), (count) * sizeof(*(src))); \
155 #define zero(x) (memset(&(x), 0, sizeof(x)))
157 /* Define no kernel as 1, since that's an illegal offset for a kernel */
161 VkStructureType sType
;
165 /* Whenever we generate an error, pass it through this function. Useful for
166 * debugging, where we can break on it. Only call at error site, not when
167 * propagating errors. Might be useful to plug in a stack trace here.
170 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
173 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
174 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
176 #define vk_error(error) error
177 #define vk_errorf(error, format, ...) error
180 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
181 anv_printflike(3, 4);
182 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
183 void anv_loge_v(const char *format
, va_list va
);
186 * Print a FINISHME message, including its source location.
188 #define anv_finishme(format, ...) \
189 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
191 /* A non-fatal assert. Useful for debugging. */
193 #define anv_assert(x) ({ \
194 if (unlikely(!(x))) \
195 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
198 #define anv_assert(x)
202 * If a block of code is annotated with anv_validate, then the block runs only
206 #define anv_validate if (1)
208 #define anv_validate if (0)
211 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
212 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
214 #define stub_return(v) \
216 anv_finishme("stub %s", __func__); \
222 anv_finishme("stub %s", __func__); \
227 * A dynamically growable, circular buffer. Elements are added at head and
228 * removed from tail. head and tail are free-running uint32_t indices and we
229 * only compute the modulo with size when accessing the array. This way,
230 * number of bytes in the queue is always head - tail, even in case of
237 uint32_t element_size
;
242 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
243 void *anv_vector_add(struct anv_vector
*queue
);
244 void *anv_vector_remove(struct anv_vector
*queue
);
247 anv_vector_length(struct anv_vector
*queue
)
249 return (queue
->head
- queue
->tail
) / queue
->element_size
;
253 anv_vector_head(struct anv_vector
*vector
)
255 assert(vector
->tail
< vector
->head
);
256 return (void *)((char *)vector
->data
+
257 ((vector
->head
- vector
->element_size
) &
258 (vector
->size
- 1)));
262 anv_vector_tail(struct anv_vector
*vector
)
264 return (void *)((char *)vector
->data
+ (vector
->tail
& (vector
->size
- 1)));
268 anv_vector_finish(struct anv_vector
*queue
)
273 #define anv_vector_foreach(elem, queue) \
274 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
275 for (uint32_t __anv_vector_offset = (queue)->tail; \
276 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
277 __anv_vector_offset += (queue)->element_size)
282 /* Index into the current validation list. This is used by the
283 * validation list building alrogithm to track which buffers are already
284 * in the validation list so that we can ensure uniqueness.
288 /* Last known offset. This value is provided by the kernel when we
289 * execbuf and is used as the presumed offset for the next bunch of
298 /* Represents a lock-free linked list of "free" things. This is used by
299 * both the block pool and the state pools. Unfortunately, in order to
300 * solve the ABA problem, we can't use a single uint32_t head.
302 union anv_free_list
{
306 /* A simple count that is incremented every time the head changes. */
312 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
314 struct anv_block_state
{
324 struct anv_block_pool
{
325 struct anv_device
*device
;
329 /* The offset from the start of the bo to the "center" of the block
330 * pool. Pointers to allocated blocks are given by
331 * bo.map + center_bo_offset + offsets.
333 uint32_t center_bo_offset
;
335 /* Current memory map of the block pool. This pointer may or may not
336 * point to the actual beginning of the block pool memory. If
337 * anv_block_pool_alloc_back has ever been called, then this pointer
338 * will point to the "center" position of the buffer and all offsets
339 * (negative or positive) given out by the block pool alloc functions
340 * will be valid relative to this pointer.
342 * In particular, map == bo.map + center_offset
348 * Array of mmaps and gem handles owned by the block pool, reclaimed when
349 * the block pool is destroyed.
351 struct anv_vector mmap_cleanups
;
355 union anv_free_list free_list
;
356 struct anv_block_state state
;
358 union anv_free_list back_free_list
;
359 struct anv_block_state back_state
;
362 /* Block pools are backed by a fixed-size 2GB memfd */
363 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
365 /* The center of the block pool is also the middle of the memfd. This may
366 * change in the future if we decide differently for some reason.
368 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
370 static inline uint32_t
371 anv_block_pool_size(struct anv_block_pool
*pool
)
373 return pool
->state
.end
+ pool
->back_state
.end
;
382 struct anv_fixed_size_state_pool
{
384 union anv_free_list free_list
;
385 struct anv_block_state block
;
388 #define ANV_MIN_STATE_SIZE_LOG2 6
389 #define ANV_MAX_STATE_SIZE_LOG2 10
391 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
393 struct anv_state_pool
{
394 struct anv_block_pool
*block_pool
;
395 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
398 struct anv_state_stream_block
;
400 struct anv_state_stream
{
401 struct anv_block_pool
*block_pool
;
403 /* The current working block */
404 struct anv_state_stream_block
*block
;
406 /* Offset at which the current block starts */
408 /* Offset at which to allocate the next state */
410 /* Offset at which the current block ends */
414 #define CACHELINE_SIZE 64
415 #define CACHELINE_MASK 63
418 anv_state_clflush(struct anv_state state
)
420 /* state.map may not be cacheline aligned, so round down the start pointer
421 * to a cacheline boundary so we flush all pages that contain the state.
423 void *end
= state
.map
+ state
.alloc_size
;
424 void *p
= (void *) (((uintptr_t) state
.map
) & ~CACHELINE_MASK
);
426 __builtin_ia32_sfence();
428 __builtin_ia32_clflush(p
);
433 void anv_block_pool_init(struct anv_block_pool
*pool
,
434 struct anv_device
*device
, uint32_t block_size
);
435 void anv_block_pool_finish(struct anv_block_pool
*pool
);
436 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
437 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
438 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
439 void anv_state_pool_init(struct anv_state_pool
*pool
,
440 struct anv_block_pool
*block_pool
);
441 void anv_state_pool_finish(struct anv_state_pool
*pool
);
442 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
443 size_t state_size
, size_t alignment
);
444 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
445 void anv_state_stream_init(struct anv_state_stream
*stream
,
446 struct anv_block_pool
*block_pool
);
447 void anv_state_stream_finish(struct anv_state_stream
*stream
);
448 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
449 uint32_t size
, uint32_t alignment
);
452 * Implements a pool of re-usable BOs. The interface is identical to that
453 * of block_pool except that each block is its own BO.
456 struct anv_device
*device
;
463 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
464 struct anv_device
*device
, uint32_t block_size
);
465 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
466 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
467 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
470 void *anv_resolve_entrypoint(uint32_t index
);
472 extern struct anv_dispatch_table dtable
;
474 #define ANV_CALL(func) ({ \
475 if (dtable.func == NULL) { \
476 size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
477 dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
483 anv_alloc(const VkAllocationCallbacks
*alloc
,
484 size_t size
, size_t align
,
485 VkSystemAllocationScope scope
)
487 return alloc
->pfnAllocation(alloc
->pUserData
, size
, align
, scope
);
491 anv_realloc(const VkAllocationCallbacks
*alloc
,
492 void *ptr
, size_t size
, size_t align
,
493 VkSystemAllocationScope scope
)
495 return alloc
->pfnReallocation(alloc
->pUserData
, ptr
, size
, align
, scope
);
499 anv_free(const VkAllocationCallbacks
*alloc
, void *data
)
501 alloc
->pfnFree(alloc
->pUserData
, data
);
505 anv_alloc2(const VkAllocationCallbacks
*parent_alloc
,
506 const VkAllocationCallbacks
*alloc
,
507 size_t size
, size_t align
,
508 VkSystemAllocationScope scope
)
511 return anv_alloc(alloc
, size
, align
, scope
);
513 return anv_alloc(parent_alloc
, size
, align
, scope
);
517 anv_free2(const VkAllocationCallbacks
*parent_alloc
,
518 const VkAllocationCallbacks
*alloc
,
522 anv_free(alloc
, data
);
524 anv_free(parent_alloc
, data
);
527 struct anv_physical_device
{
528 VK_LOADER_DATA _loader_data
;
530 struct anv_instance
* instance
;
534 const struct brw_device_info
* info
;
535 uint64_t aperture_size
;
536 struct brw_compiler
* compiler
;
537 struct isl_device isl_dev
;
540 struct anv_instance
{
541 VK_LOADER_DATA _loader_data
;
543 VkAllocationCallbacks alloc
;
546 int physicalDeviceCount
;
547 struct anv_physical_device physicalDevice
;
552 VkResult
anv_init_wsi(struct anv_instance
*instance
);
553 void anv_finish_wsi(struct anv_instance
*instance
);
555 struct anv_meta_state
{
557 struct anv_pipeline
*color_pipeline
;
558 struct anv_pipeline
*depth_only_pipeline
;
559 struct anv_pipeline
*stencil_only_pipeline
;
560 struct anv_pipeline
*depthstencil_pipeline
;
564 VkRenderPass render_pass
;
566 /** Pipeline that blits from a 1D image. */
567 VkPipeline pipeline_1d_src
;
569 /** Pipeline that blits from a 2D image. */
570 VkPipeline pipeline_2d_src
;
572 /** Pipeline that blits from a 3D image. */
573 VkPipeline pipeline_3d_src
;
575 VkPipelineLayout pipeline_layout
;
576 VkDescriptorSetLayout ds_layout
;
581 VK_LOADER_DATA _loader_data
;
583 struct anv_device
* device
;
585 struct anv_state_pool
* pool
;
588 struct anv_pipeline_cache
{
589 struct anv_device
* device
;
590 struct anv_state_stream program_stream
;
591 pthread_mutex_t mutex
;
594 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
595 struct anv_device
*device
);
596 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
599 VK_LOADER_DATA _loader_data
;
601 VkAllocationCallbacks alloc
;
603 struct anv_instance
* instance
;
605 struct brw_device_info info
;
606 struct isl_device isl_dev
;
610 struct anv_bo_pool batch_bo_pool
;
612 struct anv_block_pool dynamic_state_block_pool
;
613 struct anv_state_pool dynamic_state_pool
;
615 struct anv_block_pool instruction_block_pool
;
616 struct anv_pipeline_cache default_pipeline_cache
;
618 struct anv_block_pool surface_state_block_pool
;
619 struct anv_state_pool surface_state_pool
;
621 struct anv_bo workaround_bo
;
623 struct anv_meta_state meta_state
;
625 struct anv_state border_colors
;
627 struct anv_queue queue
;
629 struct anv_block_pool scratch_block_pool
;
631 pthread_mutex_t mutex
;
634 void* anv_gem_mmap(struct anv_device
*device
,
635 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
636 void anv_gem_munmap(void *p
, uint64_t size
);
637 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
638 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
639 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
640 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
641 int anv_gem_execbuffer(struct anv_device
*device
,
642 struct drm_i915_gem_execbuffer2
*execbuf
);
643 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
644 uint32_t stride
, uint32_t tiling
);
645 int anv_gem_create_context(struct anv_device
*device
);
646 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
647 int anv_gem_get_param(int fd
, uint32_t param
);
648 int anv_gem_get_aperture(int fd
, uint64_t *size
);
649 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
650 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
651 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
652 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
653 uint32_t read_domains
, uint32_t write_domain
);
655 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
657 struct anv_reloc_list
{
660 struct drm_i915_gem_relocation_entry
* relocs
;
661 struct anv_bo
** reloc_bos
;
664 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
665 const VkAllocationCallbacks
*alloc
);
666 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
667 const VkAllocationCallbacks
*alloc
);
669 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
670 const VkAllocationCallbacks
*alloc
,
671 uint32_t offset
, struct anv_bo
*target_bo
,
674 struct anv_batch_bo
{
675 /* Link in the anv_cmd_buffer.owned_batch_bos list */
676 struct list_head link
;
680 /* Bytes actually consumed in this batch BO */
683 /* Last seen surface state block pool bo offset */
684 uint32_t last_ss_pool_bo_offset
;
686 struct anv_reloc_list relocs
;
690 const VkAllocationCallbacks
* alloc
;
696 struct anv_reloc_list
* relocs
;
698 /* This callback is called (with the associated user data) in the event
699 * that the batch runs out of space.
701 VkResult (*extend_cb
)(struct anv_batch
*, void *);
705 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
706 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
707 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
708 void *location
, struct anv_bo
*bo
, uint32_t offset
);
715 #define __gen_address_type struct anv_address
716 #define __gen_user_data struct anv_batch
718 static inline uint64_t
719 __gen_combine_address(struct anv_batch
*batch
, void *location
,
720 const struct anv_address address
, uint32_t delta
)
722 if (address
.bo
== NULL
) {
723 return address
.offset
+ delta
;
725 assert(batch
->start
<= location
&& location
< batch
->end
);
727 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
731 /* Wrapper macros needed to work around preprocessor argument issues. In
732 * particular, arguments don't get pre-evaluated if they are concatenated.
733 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
734 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
735 * We can work around this easily enough with these helpers.
737 #define __anv_cmd_length(cmd) cmd ## _length
738 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
739 #define __anv_cmd_header(cmd) cmd ## _header
740 #define __anv_cmd_pack(cmd) cmd ## _pack
742 #define anv_batch_emit(batch, cmd, ...) do { \
743 void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
744 struct cmd __template = { \
745 __anv_cmd_header(cmd), \
748 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
749 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, __anv_cmd_length(cmd) * 4)); \
752 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
753 void *__dst = anv_batch_emit_dwords(batch, n); \
754 struct cmd __template = { \
755 __anv_cmd_header(cmd), \
756 .DwordLength = n - __anv_cmd_length_bias(cmd), \
759 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
763 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
767 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
768 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
769 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
770 dw[i] = (dwords0)[i] | (dwords1)[i]; \
771 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
774 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
775 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
776 struct anv_state __state = \
777 anv_state_pool_alloc((pool), __size, align); \
778 struct cmd __template = { \
781 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
782 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
783 if (!(pool)->block_pool->device->info.has_llc) \
784 anv_state_clflush(__state); \
788 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
789 .GraphicsDataTypeGFDT = 0, \
790 .LLCCacheabilityControlLLCCC = 0, \
791 .L3CacheabilityControlL3CC = 1, \
794 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
795 .LLCeLLCCacheabilityControlLLCCC = 0, \
796 .L3CacheabilityControlL3CC = 1, \
799 #define GEN8_MOCS { \
800 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
801 .TargetCache = L3DefertoPATforLLCeLLCselection, \
805 /* Skylake: MOCS is now an index into an array of 62 different caching
806 * configurations programmed by the kernel.
809 #define GEN9_MOCS { \
810 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
811 .IndextoMOCSTables = 2 \
814 #define GEN9_MOCS_PTE { \
815 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
816 .IndextoMOCSTables = 1 \
819 struct anv_device_memory
{
822 VkDeviceSize map_size
;
827 * Header for Vertex URB Entry (VUE)
829 struct anv_vue_header
{
831 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
832 uint32_t ViewportIndex
;
836 struct anv_descriptor_set_binding_layout
{
837 /* Number of array elements in this binding */
840 /* Index into the flattend descriptor set */
841 uint16_t descriptor_index
;
843 /* Index into the dynamic state array for a dynamic buffer */
844 int16_t dynamic_offset_index
;
846 /* Index into the descriptor set buffer views */
847 int16_t buffer_index
;
850 /* Index into the binding table for the associated surface */
851 int16_t surface_index
;
853 /* Index into the sampler table for the associated sampler */
854 int16_t sampler_index
;
856 /* Index into the image table for the associated image */
858 } stage
[MESA_SHADER_STAGES
];
860 /* Immutable samplers (or NULL if no immutable samplers) */
861 struct anv_sampler
**immutable_samplers
;
864 struct anv_descriptor_set_layout
{
865 /* Number of bindings in this descriptor set */
866 uint16_t binding_count
;
868 /* Total size of the descriptor set with room for all array entries */
871 /* Shader stages affected by this descriptor set */
872 uint16_t shader_stages
;
874 /* Number of buffers in this descriptor set */
875 uint16_t buffer_count
;
877 /* Number of dynamic offsets used by this descriptor set */
878 uint16_t dynamic_offset_count
;
880 /* Bindings in this descriptor set */
881 struct anv_descriptor_set_binding_layout binding
[0];
884 struct anv_descriptor
{
885 VkDescriptorType type
;
890 struct anv_image_view
*image_view
;
892 struct anv_sampler
*sampler
;
895 struct anv_buffer_view
*buffer_view
;
899 struct anv_descriptor_set
{
900 const struct anv_descriptor_set_layout
*layout
;
901 struct anv_buffer_view
*buffer_views
;
902 struct anv_descriptor descriptors
[0];
906 anv_descriptor_set_create(struct anv_device
*device
,
907 const struct anv_descriptor_set_layout
*layout
,
908 struct anv_descriptor_set
**out_set
);
911 anv_descriptor_set_destroy(struct anv_device
*device
,
912 struct anv_descriptor_set
*set
);
917 #define MAX_VIEWPORTS 16
918 #define MAX_SCISSORS 16
919 #define MAX_PUSH_CONSTANTS_SIZE 128
920 #define MAX_DYNAMIC_BUFFERS 16
923 struct anv_pipeline_binding
{
924 /* The descriptor set this surface corresponds to */
927 /* Offset into the descriptor set */
931 struct anv_pipeline_layout
{
933 struct anv_descriptor_set_layout
*layout
;
934 uint32_t dynamic_offset_start
;
936 uint32_t surface_start
;
937 uint32_t sampler_start
;
938 uint32_t image_start
;
939 } stage
[MESA_SHADER_STAGES
];
945 bool has_dynamic_offsets
;
946 uint32_t surface_count
;
947 struct anv_pipeline_binding
*surface_to_descriptor
;
948 uint32_t sampler_count
;
949 struct anv_pipeline_binding
*sampler_to_descriptor
;
950 uint32_t image_count
;
951 } stage
[MESA_SHADER_STAGES
];
953 struct anv_pipeline_binding entries
[0];
957 struct anv_device
* device
;
960 VkBufferUsageFlags usage
;
967 enum anv_cmd_dirty_bits
{
968 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
969 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
970 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
971 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
972 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
973 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
974 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
975 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
976 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
977 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
978 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
979 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
980 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
982 typedef uint32_t anv_cmd_dirty_mask_t
;
984 struct anv_vertex_binding
{
985 struct anv_buffer
* buffer
;
989 struct anv_push_constants
{
990 /* Current allocated size of this push constants data structure.
991 * Because a decent chunk of it may not be used (images on SKL, for
992 * instance), we won't actually allocate the entire structure up-front.
996 /* Push constant data provided by the client through vkPushConstants */
997 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
999 /* Our hardware only provides zero-based vertex and instance id so, in
1000 * order to satisfy the vulkan requirements, we may have to push one or
1001 * both of these into the shader.
1003 uint32_t base_vertex
;
1004 uint32_t base_instance
;
1006 /* Offsets and ranges for dynamically bound buffers */
1010 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1012 /* Image data for image_load_store on pre-SKL */
1013 struct brw_image_param images
[MAX_IMAGES
];
1016 struct anv_dynamic_state
{
1019 VkViewport viewports
[MAX_VIEWPORTS
];
1024 VkRect2D scissors
[MAX_SCISSORS
];
1035 float blend_constants
[4];
1045 } stencil_compare_mask
;
1050 } stencil_write_mask
;
1055 } stencil_reference
;
1058 extern const struct anv_dynamic_state default_dynamic_state
;
1060 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1061 const struct anv_dynamic_state
*src
,
1062 uint32_t copy_mask
);
1065 * Attachment state when recording a renderpass instance.
1067 * The clear value is valid only if there exists a pending clear.
1069 struct anv_attachment_state
{
1070 VkImageAspectFlags pending_clear_aspects
;
1071 VkClearValue clear_value
;
1074 /** State required while building cmd buffer */
1075 struct anv_cmd_state
{
1076 /* PIPELINE_SELECT.PipelineSelection */
1077 uint32_t current_pipeline
;
1079 anv_cmd_dirty_mask_t dirty
;
1080 anv_cmd_dirty_mask_t compute_dirty
;
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 uint32_t restart_index
;
1092 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1093 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1094 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1095 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1096 struct anv_state samplers
[MESA_SHADER_STAGES
];
1097 struct anv_dynamic_state dynamic
;
1101 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1102 * valid only when recording a render pass instance.
1104 struct anv_attachment_state
* attachments
;
1107 struct anv_buffer
* index_buffer
;
1108 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1109 uint32_t index_offset
;
1113 struct anv_cmd_pool
{
1114 VkAllocationCallbacks alloc
;
1115 struct list_head cmd_buffers
;
1118 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1120 enum anv_cmd_buffer_exec_mode
{
1121 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1122 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1123 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1124 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1127 struct anv_cmd_buffer
{
1128 VK_LOADER_DATA _loader_data
;
1130 struct anv_device
* device
;
1132 struct anv_cmd_pool
* pool
;
1133 struct list_head pool_link
;
1135 struct anv_batch batch
;
1137 /* Fields required for the actual chain of anv_batch_bo's.
1139 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1141 struct list_head batch_bos
;
1142 enum anv_cmd_buffer_exec_mode exec_mode
;
1144 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1145 * referenced by this command buffer
1147 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1149 struct anv_vector seen_bbos
;
1151 /* A vector of int32_t's for every block of binding tables.
1153 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1155 struct anv_vector bt_blocks
;
1157 struct anv_reloc_list surface_relocs
;
1159 /* Information needed for execbuf
1161 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1164 struct drm_i915_gem_execbuffer2 execbuf
;
1166 struct drm_i915_gem_exec_object2
* objects
;
1168 struct anv_bo
** bos
;
1170 /* Allocated length of the 'objects' and 'bos' arrays */
1171 uint32_t array_length
;
1176 /* Serial for tracking buffer completion */
1179 /* Stream objects for storing temporary data */
1180 struct anv_state_stream surface_state_stream
;
1181 struct anv_state_stream dynamic_state_stream
;
1183 VkCommandBufferUsageFlags usage_flags
;
1184 VkCommandBufferLevel level
;
1186 struct anv_cmd_state state
;
1189 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1190 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1191 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1192 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1193 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1194 struct anv_cmd_buffer
*secondary
);
1195 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1197 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1198 unsigned stage
, struct anv_state
*bt_state
);
1199 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1200 unsigned stage
, struct anv_state
*state
);
1201 uint32_t gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
1202 void gen7_cmd_buffer_emit_descriptor_pointers(struct anv_cmd_buffer
*cmd_buffer
,
1205 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1206 const void *data
, uint32_t size
, uint32_t alignment
);
1207 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1208 uint32_t *a
, uint32_t *b
,
1209 uint32_t dwords
, uint32_t alignment
);
1212 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1214 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1215 uint32_t entries
, uint32_t *state_offset
);
1217 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1219 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1220 uint32_t size
, uint32_t alignment
);
1223 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1225 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1226 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1228 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1229 void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1230 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1231 void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1233 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1235 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1236 const VkRenderPassBeginInfo
*info
);
1237 void gen7_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1238 struct anv_subpass
*subpass
);
1240 void gen8_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1241 struct anv_subpass
*subpass
);
1242 void gen9_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1243 struct anv_subpass
*subpass
);
1245 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1246 struct anv_subpass
*subpass
);
1249 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1250 gl_shader_stage stage
);
1252 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1254 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
);
1256 const struct anv_image_view
*
1257 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1259 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1263 struct drm_i915_gem_execbuffer2 execbuf
;
1264 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1270 struct anv_state state
;
1275 struct anv_shader_module
{
1276 struct nir_shader
* nir
;
1282 static inline gl_shader_stage
1283 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1285 assert(__builtin_popcount(vk_stage
) == 1);
1286 return ffs(vk_stage
) - 1;
1289 static inline VkShaderStageFlagBits
1290 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1292 return (1 << mesa_stage
);
1295 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1297 #define anv_foreach_stage(stage, stage_bits) \
1298 for (gl_shader_stage stage, \
1299 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1300 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1301 __tmp &= ~(1 << (stage)))
1303 struct anv_pipeline
{
1304 struct anv_device
* device
;
1305 struct anv_batch batch
;
1306 uint32_t batch_data
[512];
1307 struct anv_reloc_list batch_relocs
;
1308 uint32_t dynamic_state_mask
;
1309 struct anv_dynamic_state dynamic_state
;
1311 struct anv_pipeline_layout
* layout
;
1314 struct brw_vs_prog_data vs_prog_data
;
1315 struct brw_wm_prog_data wm_prog_data
;
1316 struct brw_gs_prog_data gs_prog_data
;
1317 struct brw_cs_prog_data cs_prog_data
;
1318 bool writes_point_size
;
1319 struct brw_stage_prog_data
* prog_data
[MESA_SHADER_STAGES
];
1320 uint32_t scratch_start
[MESA_SHADER_STAGES
];
1321 uint32_t total_scratch
;
1325 uint32_t nr_vs_entries
;
1328 uint32_t nr_gs_entries
;
1331 VkShaderStageFlags active_stages
;
1332 struct anv_state blend_state
;
1339 uint32_t ps_grf_start0
;
1340 uint32_t ps_grf_start2
;
1342 uint32_t gs_vertex_count
;
1346 uint32_t binding_stride
[MAX_VBS
];
1347 bool instancing_enable
[MAX_VBS
];
1348 bool primitive_restart
;
1351 uint32_t cs_thread_width_max
;
1352 uint32_t cs_right_mask
;
1356 uint32_t depth_stencil_state
[3];
1362 uint32_t wm_depth_stencil
[3];
1366 uint32_t wm_depth_stencil
[4];
1370 struct anv_graphics_pipeline_create_info
{
1372 bool disable_viewport
;
1373 bool disable_scissor
;
1379 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1380 struct anv_pipeline_cache
*cache
,
1381 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1382 const struct anv_graphics_pipeline_create_info
*extra
,
1383 const VkAllocationCallbacks
*alloc
);
1386 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1387 struct anv_pipeline_cache
*cache
,
1388 const VkComputePipelineCreateInfo
*info
,
1389 struct anv_shader_module
*module
,
1390 const char *entrypoint
,
1391 const VkSpecializationInfo
*spec_info
);
1394 anv_graphics_pipeline_create(VkDevice device
,
1395 VkPipelineCache cache
,
1396 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1397 const struct anv_graphics_pipeline_create_info
*extra
,
1398 const VkAllocationCallbacks
*alloc
,
1399 VkPipeline
*pPipeline
);
1402 gen7_graphics_pipeline_create(VkDevice _device
,
1403 struct anv_pipeline_cache
*cache
,
1404 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1405 const struct anv_graphics_pipeline_create_info
*extra
,
1406 const VkAllocationCallbacks
*alloc
,
1407 VkPipeline
*pPipeline
);
1410 gen75_graphics_pipeline_create(VkDevice _device
,
1411 struct anv_pipeline_cache
*cache
,
1412 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1413 const struct anv_graphics_pipeline_create_info
*extra
,
1414 const VkAllocationCallbacks
*alloc
,
1415 VkPipeline
*pPipeline
);
1418 gen8_graphics_pipeline_create(VkDevice _device
,
1419 struct anv_pipeline_cache
*cache
,
1420 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1421 const struct anv_graphics_pipeline_create_info
*extra
,
1422 const VkAllocationCallbacks
*alloc
,
1423 VkPipeline
*pPipeline
);
1425 gen9_graphics_pipeline_create(VkDevice _device
,
1426 struct anv_pipeline_cache
*cache
,
1427 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1428 const struct anv_graphics_pipeline_create_info
*extra
,
1429 const VkAllocationCallbacks
*alloc
,
1430 VkPipeline
*pPipeline
);
1432 gen7_compute_pipeline_create(VkDevice _device
,
1433 struct anv_pipeline_cache
*cache
,
1434 const VkComputePipelineCreateInfo
*pCreateInfo
,
1435 const VkAllocationCallbacks
*alloc
,
1436 VkPipeline
*pPipeline
);
1438 gen75_compute_pipeline_create(VkDevice _device
,
1439 struct anv_pipeline_cache
*cache
,
1440 const VkComputePipelineCreateInfo
*pCreateInfo
,
1441 const VkAllocationCallbacks
*alloc
,
1442 VkPipeline
*pPipeline
);
1445 gen8_compute_pipeline_create(VkDevice _device
,
1446 struct anv_pipeline_cache
*cache
,
1447 const VkComputePipelineCreateInfo
*pCreateInfo
,
1448 const VkAllocationCallbacks
*alloc
,
1449 VkPipeline
*pPipeline
);
1451 gen9_compute_pipeline_create(VkDevice _device
,
1452 struct anv_pipeline_cache
*cache
,
1453 const VkComputePipelineCreateInfo
*pCreateInfo
,
1454 const VkAllocationCallbacks
*alloc
,
1455 VkPipeline
*pPipeline
);
1458 const VkFormat vk_format
;
1460 enum isl_format surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
1461 const struct isl_format_layout
*isl_layout
;
1462 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1466 const struct anv_format
*
1467 anv_format_for_vk_format(VkFormat format
);
1470 anv_get_isl_format(VkFormat format
, VkImageAspectFlags aspect
,
1471 VkImageTiling tiling
);
1474 anv_format_is_color(const struct anv_format
*format
)
1476 return !format
->depth_format
&& !format
->has_stencil
;
1480 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
1482 return format
->depth_format
|| format
->has_stencil
;
1486 * Subsurface of an anv_image.
1488 struct anv_surface
{
1489 struct isl_surf isl
;
1492 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1499 /* The original VkFormat provided by the client. This may not match any
1500 * of the actual surface formats.
1503 const struct anv_format
*format
;
1506 uint32_t array_size
;
1507 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1508 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1513 /* Set when bound */
1515 VkDeviceSize offset
;
1517 bool needs_nonrt_surface_state
:1;
1518 bool needs_color_rt_surface_state
:1;
1519 bool needs_storage_surface_state
:1;
1524 * For each foo, anv_image::foo_surface is valid if and only if
1525 * anv_image::format has a foo aspect.
1527 * The hardware requires that the depth buffer and stencil buffer be
1528 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1529 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1530 * allocate the depth and stencil buffers as separate surfaces in the same
1534 struct anv_surface color_surface
;
1537 struct anv_surface depth_surface
;
1538 struct anv_surface stencil_surface
;
1543 struct anv_image_view
{
1544 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1546 uint32_t offset
; /**< Offset into bo. */
1548 VkImageAspectFlags aspect_mask
;
1550 enum isl_format format
;
1551 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1553 /** RENDER_SURFACE_STATE when using image as a color render target. */
1554 struct anv_state color_rt_surface_state
;
1556 /** RENDER_SURFACE_STATE when using image as a non render target. */
1557 struct anv_state nonrt_surface_state
;
1559 /** RENDER_SURFACE_STATE when using image as a storage image. */
1560 struct anv_state storage_surface_state
;
1563 struct anv_image_create_info
{
1564 const VkImageCreateInfo
*vk_info
;
1565 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 struct anv_surface
*
1575 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
,
1576 VkImageAspectFlags aspect_mask
);
1578 void anv_image_view_init(struct anv_image_view
*view
,
1579 struct anv_device
*device
,
1580 const VkImageViewCreateInfo
* pCreateInfo
,
1581 struct anv_cmd_buffer
*cmd_buffer
);
1584 gen7_image_view_init(struct anv_image_view
*iview
,
1585 struct anv_device
*device
,
1586 const VkImageViewCreateInfo
* pCreateInfo
,
1587 struct anv_cmd_buffer
*cmd_buffer
);
1590 gen75_image_view_init(struct anv_image_view
*iview
,
1591 struct anv_device
*device
,
1592 const VkImageViewCreateInfo
* pCreateInfo
,
1593 struct anv_cmd_buffer
*cmd_buffer
);
1596 gen8_image_view_init(struct anv_image_view
*iview
,
1597 struct anv_device
*device
,
1598 const VkImageViewCreateInfo
* pCreateInfo
,
1599 struct anv_cmd_buffer
*cmd_buffer
);
1602 gen9_image_view_init(struct anv_image_view
*iview
,
1603 struct anv_device
*device
,
1604 const VkImageViewCreateInfo
* pCreateInfo
,
1605 struct anv_cmd_buffer
*cmd_buffer
);
1607 struct anv_buffer_view
{
1608 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1610 uint32_t offset
; /**< Offset into bo. */
1611 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1613 struct anv_state surface_state
;
1614 struct anv_state storage_surface_state
;
1617 const struct anv_format
*
1618 anv_format_for_descriptor_type(VkDescriptorType type
);
1620 void anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1621 enum isl_format format
,
1622 uint32_t offset
, uint32_t range
,
1625 void gen7_fill_buffer_surface_state(void *state
, enum isl_format format
,
1626 uint32_t offset
, uint32_t range
,
1628 void gen75_fill_buffer_surface_state(void *state
, enum isl_format format
,
1629 uint32_t offset
, uint32_t range
,
1631 void gen8_fill_buffer_surface_state(void *state
, enum isl_format format
,
1632 uint32_t offset
, uint32_t range
,
1634 void gen9_fill_buffer_surface_state(void *state
, enum isl_format format
,
1635 uint32_t offset
, uint32_t range
,
1638 void anv_image_view_fill_image_param(struct anv_device
*device
,
1639 struct anv_image_view
*view
,
1640 struct brw_image_param
*param
);
1641 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1642 struct anv_buffer_view
*view
,
1643 struct brw_image_param
*param
);
1645 struct anv_sampler
{
1649 struct anv_framebuffer
{
1654 uint32_t attachment_count
;
1655 const struct anv_image_view
* attachments
[0];
1658 struct anv_subpass
{
1659 uint32_t input_count
;
1660 uint32_t * input_attachments
;
1661 uint32_t color_count
;
1662 uint32_t * color_attachments
;
1663 uint32_t * resolve_attachments
;
1664 uint32_t depth_stencil_attachment
;
1667 struct anv_render_pass_attachment
{
1668 const struct anv_format
*format
;
1670 VkAttachmentLoadOp load_op
;
1671 VkAttachmentLoadOp stencil_load_op
;
1674 struct anv_render_pass
{
1675 uint32_t attachment_count
;
1676 uint32_t subpass_count
;
1677 uint32_t * subpass_attachments
;
1678 struct anv_render_pass_attachment
* attachments
;
1679 struct anv_subpass subpasses
[0];
1682 extern struct anv_render_pass anv_meta_dummy_renderpass
;
1684 struct anv_query_pool_slot
{
1690 struct anv_query_pool
{
1696 VkResult
anv_device_init_meta(struct anv_device
*device
);
1697 void anv_device_finish_meta(struct anv_device
*device
);
1699 void *anv_lookup_entrypoint(const char *name
);
1701 void anv_dump_image_to_ppm(struct anv_device
*device
,
1702 struct anv_image
*image
, unsigned miplevel
,
1703 unsigned array_layer
, const char *filename
);
1705 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1707 static inline struct __anv_type * \
1708 __anv_type ## _from_handle(__VkType _handle) \
1710 return (struct __anv_type *) _handle; \
1713 static inline __VkType \
1714 __anv_type ## _to_handle(struct __anv_type *_obj) \
1716 return (__VkType) _obj; \
1719 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1721 static inline struct __anv_type * \
1722 __anv_type ## _from_handle(__VkType _handle) \
1724 return (struct __anv_type *)(uintptr_t) _handle; \
1727 static inline __VkType \
1728 __anv_type ## _to_handle(struct __anv_type *_obj) \
1730 return (__VkType)(uintptr_t) _obj; \
1733 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1734 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1736 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1737 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1738 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1739 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1740 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1742 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1743 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1744 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1745 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1746 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1747 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1748 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1749 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1750 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1751 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1752 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1753 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1754 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1755 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1756 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1757 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1758 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1759 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1761 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1763 static inline const __VkType * \
1764 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1766 return (const __VkType *) __anv_obj; \
1769 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1770 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1772 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1773 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1774 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)