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"
73 #define MAX_VIEWPORTS 16
74 #define MAX_SCISSORS 16
75 #define MAX_PUSH_CONSTANTS_SIZE 128
76 #define MAX_DYNAMIC_BUFFERS 16
78 #define MAX_SAMPLES_LOG2 4 /* SKL supports 16 samples */
80 #define ICD_LOADER_MAGIC 0x01CDC0DE
82 typedef union _VK_LOADER_DATA
{
83 uintptr_t loaderMagic
;
87 #define anv_noreturn __attribute__((__noreturn__))
88 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
90 #define MIN(a, b) ((a) < (b) ? (a) : (b))
91 #define MAX(a, b) ((a) > (b) ? (a) : (b))
93 static inline uint32_t
94 align_u32(uint32_t v
, uint32_t a
)
96 assert(a
!= 0 && a
== (a
& -a
));
97 return (v
+ a
- 1) & ~(a
- 1);
100 static inline uint64_t
101 align_u64(uint64_t v
, uint64_t a
)
103 assert(a
!= 0 && a
== (a
& -a
));
104 return (v
+ a
- 1) & ~(a
- 1);
107 static inline int32_t
108 align_i32(int32_t v
, int32_t a
)
110 assert(a
!= 0 && a
== (a
& -a
));
111 return (v
+ a
- 1) & ~(a
- 1);
114 /** Alignment must be a power of 2. */
116 anv_is_aligned(uintmax_t n
, uintmax_t a
)
118 assert(a
== (a
& -a
));
119 return (n
& (a
- 1)) == 0;
122 static inline uint32_t
123 anv_minify(uint32_t n
, uint32_t levels
)
125 if (unlikely(n
== 0))
128 return MAX(n
>> levels
, 1);
132 anv_clamp_f(float f
, float min
, float max
)
145 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
147 if (*inout_mask
& clear_mask
) {
148 *inout_mask
&= ~clear_mask
;
155 #define for_each_bit(b, dword) \
156 for (uint32_t __dword = (dword); \
157 (b) = __builtin_ffs(__dword) - 1, __dword; \
158 __dword &= ~(1 << (b)))
160 #define typed_memcpy(dest, src, count) ({ \
161 static_assert(sizeof(*src) == sizeof(*dest), ""); \
162 memcpy((dest), (src), (count) * sizeof(*(src))); \
165 #define zero(x) (memset(&(x), 0, sizeof(x)))
167 /* Define no kernel as 1, since that's an illegal offset for a kernel */
171 VkStructureType sType
;
175 /* Whenever we generate an error, pass it through this function. Useful for
176 * debugging, where we can break on it. Only call at error site, not when
177 * propagating errors. Might be useful to plug in a stack trace here.
180 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
183 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
184 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
186 #define vk_error(error) error
187 #define vk_errorf(error, format, ...) error
190 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
191 anv_printflike(3, 4);
192 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
193 void anv_loge_v(const char *format
, va_list va
);
196 * Print a FINISHME message, including its source location.
198 #define anv_finishme(format, ...) \
199 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
201 /* A non-fatal assert. Useful for debugging. */
203 #define anv_assert(x) ({ \
204 if (unlikely(!(x))) \
205 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
208 #define anv_assert(x)
212 * If a block of code is annotated with anv_validate, then the block runs only
216 #define anv_validate if (1)
218 #define anv_validate if (0)
221 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
222 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
224 #define stub_return(v) \
226 anv_finishme("stub %s", __func__); \
232 anv_finishme("stub %s", __func__); \
237 * A dynamically growable, circular buffer. Elements are added at head and
238 * removed from tail. head and tail are free-running uint32_t indices and we
239 * only compute the modulo with size when accessing the array. This way,
240 * number of bytes in the queue is always head - tail, even in case of
247 uint32_t element_size
;
252 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
253 void *anv_vector_add(struct anv_vector
*queue
);
254 void *anv_vector_remove(struct anv_vector
*queue
);
257 anv_vector_length(struct anv_vector
*queue
)
259 return (queue
->head
- queue
->tail
) / queue
->element_size
;
263 anv_vector_head(struct anv_vector
*vector
)
265 assert(vector
->tail
< vector
->head
);
266 return (void *)((char *)vector
->data
+
267 ((vector
->head
- vector
->element_size
) &
268 (vector
->size
- 1)));
272 anv_vector_tail(struct anv_vector
*vector
)
274 return (void *)((char *)vector
->data
+ (vector
->tail
& (vector
->size
- 1)));
278 anv_vector_finish(struct anv_vector
*queue
)
283 #define anv_vector_foreach(elem, queue) \
284 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
285 for (uint32_t __anv_vector_offset = (queue)->tail; \
286 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
287 __anv_vector_offset += (queue)->element_size)
292 /* Index into the current validation list. This is used by the
293 * validation list building alrogithm to track which buffers are already
294 * in the validation list so that we can ensure uniqueness.
298 /* Last known offset. This value is provided by the kernel when we
299 * execbuf and is used as the presumed offset for the next bunch of
308 /* Represents a lock-free linked list of "free" things. This is used by
309 * both the block pool and the state pools. Unfortunately, in order to
310 * solve the ABA problem, we can't use a single uint32_t head.
312 union anv_free_list
{
316 /* A simple count that is incremented every time the head changes. */
322 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
324 struct anv_block_state
{
334 struct anv_block_pool
{
335 struct anv_device
*device
;
339 /* The offset from the start of the bo to the "center" of the block
340 * pool. Pointers to allocated blocks are given by
341 * bo.map + center_bo_offset + offsets.
343 uint32_t center_bo_offset
;
345 /* Current memory map of the block pool. This pointer may or may not
346 * point to the actual beginning of the block pool memory. If
347 * anv_block_pool_alloc_back has ever been called, then this pointer
348 * will point to the "center" position of the buffer and all offsets
349 * (negative or positive) given out by the block pool alloc functions
350 * will be valid relative to this pointer.
352 * In particular, map == bo.map + center_offset
358 * Array of mmaps and gem handles owned by the block pool, reclaimed when
359 * the block pool is destroyed.
361 struct anv_vector mmap_cleanups
;
365 union anv_free_list free_list
;
366 struct anv_block_state state
;
368 union anv_free_list back_free_list
;
369 struct anv_block_state back_state
;
372 /* Block pools are backed by a fixed-size 2GB memfd */
373 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
375 /* The center of the block pool is also the middle of the memfd. This may
376 * change in the future if we decide differently for some reason.
378 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
380 static inline uint32_t
381 anv_block_pool_size(struct anv_block_pool
*pool
)
383 return pool
->state
.end
+ pool
->back_state
.end
;
392 struct anv_fixed_size_state_pool
{
394 union anv_free_list free_list
;
395 struct anv_block_state block
;
398 #define ANV_MIN_STATE_SIZE_LOG2 6
399 #define ANV_MAX_STATE_SIZE_LOG2 10
401 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
403 struct anv_state_pool
{
404 struct anv_block_pool
*block_pool
;
405 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
408 struct anv_state_stream_block
;
410 struct anv_state_stream
{
411 struct anv_block_pool
*block_pool
;
413 /* The current working block */
414 struct anv_state_stream_block
*block
;
416 /* Offset at which the current block starts */
418 /* Offset at which to allocate the next state */
420 /* Offset at which the current block ends */
424 #define CACHELINE_SIZE 64
425 #define CACHELINE_MASK 63
428 anv_state_clflush(struct anv_state state
)
430 /* state.map may not be cacheline aligned, so round down the start pointer
431 * to a cacheline boundary so we flush all pages that contain the state.
433 void *end
= state
.map
+ state
.alloc_size
;
434 void *p
= (void *) (((uintptr_t) state
.map
) & ~CACHELINE_MASK
);
436 __builtin_ia32_mfence();
438 __builtin_ia32_clflush(p
);
443 void anv_block_pool_init(struct anv_block_pool
*pool
,
444 struct anv_device
*device
, uint32_t block_size
);
445 void anv_block_pool_finish(struct anv_block_pool
*pool
);
446 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
447 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
448 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
449 void anv_state_pool_init(struct anv_state_pool
*pool
,
450 struct anv_block_pool
*block_pool
);
451 void anv_state_pool_finish(struct anv_state_pool
*pool
);
452 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
453 size_t state_size
, size_t alignment
);
454 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
455 void anv_state_stream_init(struct anv_state_stream
*stream
,
456 struct anv_block_pool
*block_pool
);
457 void anv_state_stream_finish(struct anv_state_stream
*stream
);
458 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
459 uint32_t size
, uint32_t alignment
);
462 * Implements a pool of re-usable BOs. The interface is identical to that
463 * of block_pool except that each block is its own BO.
466 struct anv_device
*device
;
473 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
474 struct anv_device
*device
, uint32_t block_size
);
475 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
476 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
477 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
480 void *anv_resolve_entrypoint(uint32_t index
);
482 extern struct anv_dispatch_table dtable
;
484 #define ANV_CALL(func) ({ \
485 if (dtable.func == NULL) { \
486 size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
487 dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
493 anv_alloc(const VkAllocationCallbacks
*alloc
,
494 size_t size
, size_t align
,
495 VkSystemAllocationScope scope
)
497 return alloc
->pfnAllocation(alloc
->pUserData
, size
, align
, scope
);
501 anv_realloc(const VkAllocationCallbacks
*alloc
,
502 void *ptr
, size_t size
, size_t align
,
503 VkSystemAllocationScope scope
)
505 return alloc
->pfnReallocation(alloc
->pUserData
, ptr
, size
, align
, scope
);
509 anv_free(const VkAllocationCallbacks
*alloc
, void *data
)
511 alloc
->pfnFree(alloc
->pUserData
, data
);
515 anv_alloc2(const VkAllocationCallbacks
*parent_alloc
,
516 const VkAllocationCallbacks
*alloc
,
517 size_t size
, size_t align
,
518 VkSystemAllocationScope scope
)
521 return anv_alloc(alloc
, size
, align
, scope
);
523 return anv_alloc(parent_alloc
, size
, align
, scope
);
527 anv_free2(const VkAllocationCallbacks
*parent_alloc
,
528 const VkAllocationCallbacks
*alloc
,
532 anv_free(alloc
, data
);
534 anv_free(parent_alloc
, data
);
537 struct anv_physical_device
{
538 VK_LOADER_DATA _loader_data
;
540 struct anv_instance
* instance
;
544 const struct brw_device_info
* info
;
545 uint64_t aperture_size
;
546 struct brw_compiler
* compiler
;
547 struct isl_device isl_dev
;
550 struct anv_instance
{
551 VK_LOADER_DATA _loader_data
;
553 VkAllocationCallbacks alloc
;
556 int physicalDeviceCount
;
557 struct anv_physical_device physicalDevice
;
562 VkResult
anv_init_wsi(struct anv_instance
*instance
);
563 void anv_finish_wsi(struct anv_instance
*instance
);
565 struct anv_meta_state
{
566 VkAllocationCallbacks alloc
;
569 * Use array element `i` for images with `2^i` samples.
573 * Pipeline N is used to clear color attachment N of the current
576 * HACK: We use one pipeline per color attachment to work around the
577 * compiler's inability to dynamically set the render target index of
578 * the render target write message.
580 struct anv_pipeline
*color_pipelines
[MAX_RTS
];
582 struct anv_pipeline
*depth_only_pipeline
;
583 struct anv_pipeline
*stencil_only_pipeline
;
584 struct anv_pipeline
*depthstencil_pipeline
;
585 } clear
[1 + MAX_SAMPLES_LOG2
];
588 VkRenderPass render_pass
;
590 /** Pipeline that blits from a 1D image. */
591 VkPipeline pipeline_1d_src
;
593 /** Pipeline that blits from a 2D image. */
594 VkPipeline pipeline_2d_src
;
596 /** Pipeline that blits from a 3D image. */
597 VkPipeline pipeline_3d_src
;
599 VkPipelineLayout pipeline_layout
;
600 VkDescriptorSetLayout ds_layout
;
604 /** Pipeline [i] resolves an image with 2^(i+1) samples. */
605 VkPipeline pipelines
[MAX_SAMPLES_LOG2
];
608 VkPipelineLayout pipeline_layout
;
609 VkDescriptorSetLayout ds_layout
;
614 VK_LOADER_DATA _loader_data
;
616 struct anv_device
* device
;
618 struct anv_state_pool
* pool
;
621 struct anv_pipeline_cache
{
622 struct anv_device
* device
;
623 struct anv_state_stream program_stream
;
624 pthread_mutex_t mutex
;
627 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
628 struct anv_device
*device
);
629 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
632 VK_LOADER_DATA _loader_data
;
634 VkAllocationCallbacks alloc
;
636 struct anv_instance
* instance
;
638 struct brw_device_info info
;
639 struct isl_device isl_dev
;
643 struct anv_bo_pool batch_bo_pool
;
645 struct anv_block_pool dynamic_state_block_pool
;
646 struct anv_state_pool dynamic_state_pool
;
648 struct anv_block_pool instruction_block_pool
;
649 struct anv_pipeline_cache default_pipeline_cache
;
651 struct anv_block_pool surface_state_block_pool
;
652 struct anv_state_pool surface_state_pool
;
654 struct anv_bo workaround_bo
;
656 struct anv_meta_state meta_state
;
658 struct anv_state border_colors
;
660 struct anv_queue queue
;
662 struct anv_block_pool scratch_block_pool
;
664 pthread_mutex_t mutex
;
667 void* anv_gem_mmap(struct anv_device
*device
,
668 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
669 void anv_gem_munmap(void *p
, uint64_t size
);
670 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
671 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
672 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
673 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
674 int anv_gem_execbuffer(struct anv_device
*device
,
675 struct drm_i915_gem_execbuffer2
*execbuf
);
676 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
677 uint32_t stride
, uint32_t tiling
);
678 int anv_gem_create_context(struct anv_device
*device
);
679 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
680 int anv_gem_get_param(int fd
, uint32_t param
);
681 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
682 int anv_gem_get_aperture(int fd
, uint64_t *size
);
683 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
684 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
685 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
686 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
687 uint32_t read_domains
, uint32_t write_domain
);
689 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
691 struct anv_reloc_list
{
694 struct drm_i915_gem_relocation_entry
* relocs
;
695 struct anv_bo
** reloc_bos
;
698 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
699 const VkAllocationCallbacks
*alloc
);
700 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
701 const VkAllocationCallbacks
*alloc
);
703 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
704 const VkAllocationCallbacks
*alloc
,
705 uint32_t offset
, struct anv_bo
*target_bo
,
708 struct anv_batch_bo
{
709 /* Link in the anv_cmd_buffer.owned_batch_bos list */
710 struct list_head link
;
714 /* Bytes actually consumed in this batch BO */
717 /* Last seen surface state block pool bo offset */
718 uint32_t last_ss_pool_bo_offset
;
720 struct anv_reloc_list relocs
;
724 const VkAllocationCallbacks
* alloc
;
730 struct anv_reloc_list
* relocs
;
732 /* This callback is called (with the associated user data) in the event
733 * that the batch runs out of space.
735 VkResult (*extend_cb
)(struct anv_batch
*, void *);
739 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
740 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
741 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
742 void *location
, struct anv_bo
*bo
, uint32_t offset
);
749 #define __gen_address_type struct anv_address
750 #define __gen_user_data struct anv_batch
752 static inline uint64_t
753 __gen_combine_address(struct anv_batch
*batch
, void *location
,
754 const struct anv_address address
, uint32_t delta
)
756 if (address
.bo
== NULL
) {
757 return address
.offset
+ delta
;
759 assert(batch
->start
<= location
&& location
< batch
->end
);
761 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
765 /* Wrapper macros needed to work around preprocessor argument issues. In
766 * particular, arguments don't get pre-evaluated if they are concatenated.
767 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
768 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
769 * We can work around this easily enough with these helpers.
771 #define __anv_cmd_length(cmd) cmd ## _length
772 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
773 #define __anv_cmd_header(cmd) cmd ## _header
774 #define __anv_cmd_pack(cmd) cmd ## _pack
776 #define anv_batch_emit(batch, cmd, ...) do { \
777 void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
778 struct cmd __template = { \
779 __anv_cmd_header(cmd), \
782 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
783 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, __anv_cmd_length(cmd) * 4)); \
786 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
787 void *__dst = anv_batch_emit_dwords(batch, n); \
788 struct cmd __template = { \
789 __anv_cmd_header(cmd), \
790 .DwordLength = n - __anv_cmd_length_bias(cmd), \
793 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
797 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
801 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
802 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
803 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
804 dw[i] = (dwords0)[i] | (dwords1)[i]; \
805 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
808 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
809 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
810 struct anv_state __state = \
811 anv_state_pool_alloc((pool), __size, align); \
812 struct cmd __template = { \
815 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
816 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
817 if (!(pool)->block_pool->device->info.has_llc) \
818 anv_state_clflush(__state); \
822 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
823 .GraphicsDataTypeGFDT = 0, \
824 .LLCCacheabilityControlLLCCC = 0, \
825 .L3CacheabilityControlL3CC = 1, \
828 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
829 .LLCeLLCCacheabilityControlLLCCC = 0, \
830 .L3CacheabilityControlL3CC = 1, \
833 #define GEN8_MOCS { \
834 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
835 .TargetCache = L3DefertoPATforLLCeLLCselection, \
839 /* Skylake: MOCS is now an index into an array of 62 different caching
840 * configurations programmed by the kernel.
843 #define GEN9_MOCS { \
844 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
845 .IndextoMOCSTables = 2 \
848 #define GEN9_MOCS_PTE { \
849 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
850 .IndextoMOCSTables = 1 \
853 struct anv_device_memory
{
856 VkDeviceSize map_size
;
861 * Header for Vertex URB Entry (VUE)
863 struct anv_vue_header
{
865 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
866 uint32_t ViewportIndex
;
870 struct anv_descriptor_set_binding_layout
{
871 /* Number of array elements in this binding */
874 /* Index into the flattend descriptor set */
875 uint16_t descriptor_index
;
877 /* Index into the dynamic state array for a dynamic buffer */
878 int16_t dynamic_offset_index
;
880 /* Index into the descriptor set buffer views */
881 int16_t buffer_index
;
884 /* Index into the binding table for the associated surface */
885 int16_t surface_index
;
887 /* Index into the sampler table for the associated sampler */
888 int16_t sampler_index
;
890 /* Index into the image table for the associated image */
892 } stage
[MESA_SHADER_STAGES
];
894 /* Immutable samplers (or NULL if no immutable samplers) */
895 struct anv_sampler
**immutable_samplers
;
898 struct anv_descriptor_set_layout
{
899 /* Number of bindings in this descriptor set */
900 uint16_t binding_count
;
902 /* Total size of the descriptor set with room for all array entries */
905 /* Shader stages affected by this descriptor set */
906 uint16_t shader_stages
;
908 /* Number of buffers in this descriptor set */
909 uint16_t buffer_count
;
911 /* Number of dynamic offsets used by this descriptor set */
912 uint16_t dynamic_offset_count
;
914 /* Bindings in this descriptor set */
915 struct anv_descriptor_set_binding_layout binding
[0];
918 struct anv_descriptor
{
919 VkDescriptorType type
;
924 struct anv_image_view
*image_view
;
926 struct anv_sampler
*sampler
;
929 struct anv_buffer_view
*buffer_view
;
933 struct anv_descriptor_set
{
934 const struct anv_descriptor_set_layout
*layout
;
935 struct anv_buffer_view
*buffer_views
;
936 struct anv_descriptor descriptors
[0];
940 anv_descriptor_set_create(struct anv_device
*device
,
941 const struct anv_descriptor_set_layout
*layout
,
942 struct anv_descriptor_set
**out_set
);
945 anv_descriptor_set_destroy(struct anv_device
*device
,
946 struct anv_descriptor_set
*set
);
948 struct anv_pipeline_binding
{
949 /* The descriptor set this surface corresponds to */
952 /* Offset into the descriptor set */
956 struct anv_pipeline_layout
{
958 struct anv_descriptor_set_layout
*layout
;
959 uint32_t dynamic_offset_start
;
961 uint32_t surface_start
;
962 uint32_t sampler_start
;
963 uint32_t image_start
;
964 } stage
[MESA_SHADER_STAGES
];
970 bool has_dynamic_offsets
;
971 uint32_t surface_count
;
972 struct anv_pipeline_binding
*surface_to_descriptor
;
973 uint32_t sampler_count
;
974 struct anv_pipeline_binding
*sampler_to_descriptor
;
975 uint32_t image_count
;
976 } stage
[MESA_SHADER_STAGES
];
978 struct anv_pipeline_binding entries
[0];
982 struct anv_device
* device
;
985 VkBufferUsageFlags usage
;
992 enum anv_cmd_dirty_bits
{
993 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
994 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
995 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
996 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
997 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
998 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
999 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
1000 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
1001 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
1002 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
1003 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
1004 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
1005 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
1007 typedef uint32_t anv_cmd_dirty_mask_t
;
1009 struct anv_vertex_binding
{
1010 struct anv_buffer
* buffer
;
1011 VkDeviceSize offset
;
1014 struct anv_push_constants
{
1015 /* Current allocated size of this push constants data structure.
1016 * Because a decent chunk of it may not be used (images on SKL, for
1017 * instance), we won't actually allocate the entire structure up-front.
1021 /* Push constant data provided by the client through vkPushConstants */
1022 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1024 /* Our hardware only provides zero-based vertex and instance id so, in
1025 * order to satisfy the vulkan requirements, we may have to push one or
1026 * both of these into the shader.
1028 uint32_t base_vertex
;
1029 uint32_t base_instance
;
1031 /* Offsets and ranges for dynamically bound buffers */
1035 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1037 /* Image data for image_load_store on pre-SKL */
1038 struct brw_image_param images
[MAX_IMAGES
];
1041 struct anv_dynamic_state
{
1044 VkViewport viewports
[MAX_VIEWPORTS
];
1049 VkRect2D scissors
[MAX_SCISSORS
];
1060 float blend_constants
[4];
1070 } stencil_compare_mask
;
1075 } stencil_write_mask
;
1080 } stencil_reference
;
1083 extern const struct anv_dynamic_state default_dynamic_state
;
1085 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1086 const struct anv_dynamic_state
*src
,
1087 uint32_t copy_mask
);
1090 * Attachment state when recording a renderpass instance.
1092 * The clear value is valid only if there exists a pending clear.
1094 struct anv_attachment_state
{
1095 VkImageAspectFlags pending_clear_aspects
;
1096 VkClearValue clear_value
;
1099 /** State required while building cmd buffer */
1100 struct anv_cmd_state
{
1101 /* PIPELINE_SELECT.PipelineSelection */
1102 uint32_t current_pipeline
;
1103 uint32_t current_l3_config
;
1105 anv_cmd_dirty_mask_t dirty
;
1106 anv_cmd_dirty_mask_t compute_dirty
;
1107 uint32_t num_workgroups_offset
;
1108 struct anv_bo
*num_workgroups_bo
;
1109 VkShaderStageFlags descriptors_dirty
;
1110 VkShaderStageFlags push_constants_dirty
;
1111 uint32_t scratch_size
;
1112 struct anv_pipeline
* pipeline
;
1113 struct anv_pipeline
* compute_pipeline
;
1114 struct anv_framebuffer
* framebuffer
;
1115 struct anv_render_pass
* pass
;
1116 struct anv_subpass
* subpass
;
1117 uint32_t restart_index
;
1118 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1119 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1120 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1121 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1122 struct anv_state samplers
[MESA_SHADER_STAGES
];
1123 struct anv_dynamic_state dynamic
;
1127 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1128 * valid only when recording a render pass instance.
1130 struct anv_attachment_state
* attachments
;
1133 struct anv_buffer
* index_buffer
;
1134 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1135 uint32_t index_offset
;
1139 struct anv_cmd_pool
{
1140 VkAllocationCallbacks alloc
;
1141 struct list_head cmd_buffers
;
1144 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1146 enum anv_cmd_buffer_exec_mode
{
1147 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1148 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1149 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1150 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1153 struct anv_cmd_buffer
{
1154 VK_LOADER_DATA _loader_data
;
1156 struct anv_device
* device
;
1158 struct anv_cmd_pool
* pool
;
1159 struct list_head pool_link
;
1161 struct anv_batch batch
;
1163 /* Fields required for the actual chain of anv_batch_bo's.
1165 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1167 struct list_head batch_bos
;
1168 enum anv_cmd_buffer_exec_mode exec_mode
;
1170 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1171 * referenced by this command buffer
1173 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1175 struct anv_vector seen_bbos
;
1177 /* A vector of int32_t's for every block of binding tables.
1179 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1181 struct anv_vector bt_blocks
;
1183 struct anv_reloc_list surface_relocs
;
1185 /* Information needed for execbuf
1187 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1190 struct drm_i915_gem_execbuffer2 execbuf
;
1192 struct drm_i915_gem_exec_object2
* objects
;
1194 struct anv_bo
** bos
;
1196 /* Allocated length of the 'objects' and 'bos' arrays */
1197 uint32_t array_length
;
1202 /* Serial for tracking buffer completion */
1205 /* Stream objects for storing temporary data */
1206 struct anv_state_stream surface_state_stream
;
1207 struct anv_state_stream dynamic_state_stream
;
1209 VkCommandBufferUsageFlags usage_flags
;
1210 VkCommandBufferLevel level
;
1212 struct anv_cmd_state state
;
1215 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1216 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1217 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1218 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1219 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1220 struct anv_cmd_buffer
*secondary
);
1221 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1223 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1224 unsigned stage
, struct anv_state
*bt_state
);
1225 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1226 unsigned stage
, struct anv_state
*state
);
1227 uint32_t gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
1228 void gen7_cmd_buffer_emit_descriptor_pointers(struct anv_cmd_buffer
*cmd_buffer
,
1231 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1232 const void *data
, uint32_t size
, uint32_t alignment
);
1233 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1234 uint32_t *a
, uint32_t *b
,
1235 uint32_t dwords
, uint32_t alignment
);
1238 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1240 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1241 uint32_t entries
, uint32_t *state_offset
);
1243 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1245 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1246 uint32_t size
, uint32_t alignment
);
1249 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1251 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1252 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1254 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1255 void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1256 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1257 void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1259 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1261 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1262 const VkRenderPassBeginInfo
*info
);
1264 void gen7_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1265 struct anv_subpass
*subpass
);
1266 void gen8_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1267 struct anv_subpass
*subpass
);
1268 void gen9_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1269 struct anv_subpass
*subpass
);
1270 void anv_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1271 struct anv_subpass
*subpass
);
1274 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1275 gl_shader_stage stage
);
1277 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1279 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1280 void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1282 const struct anv_image_view
*
1283 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1285 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1289 struct drm_i915_gem_execbuffer2 execbuf
;
1290 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1296 struct anv_state state
;
1301 struct anv_shader_module
{
1302 struct nir_shader
* nir
;
1308 static inline gl_shader_stage
1309 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1311 assert(__builtin_popcount(vk_stage
) == 1);
1312 return ffs(vk_stage
) - 1;
1315 static inline VkShaderStageFlagBits
1316 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1318 return (1 << mesa_stage
);
1321 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1323 #define anv_foreach_stage(stage, stage_bits) \
1324 for (gl_shader_stage stage, \
1325 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1326 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1327 __tmp &= ~(1 << (stage)))
1329 struct anv_pipeline
{
1330 struct anv_device
* device
;
1331 struct anv_batch batch
;
1332 uint32_t batch_data
[512];
1333 struct anv_reloc_list batch_relocs
;
1334 uint32_t dynamic_state_mask
;
1335 struct anv_dynamic_state dynamic_state
;
1337 struct anv_pipeline_layout
* layout
;
1340 struct brw_vs_prog_data vs_prog_data
;
1341 struct brw_wm_prog_data wm_prog_data
;
1342 struct brw_gs_prog_data gs_prog_data
;
1343 struct brw_cs_prog_data cs_prog_data
;
1344 bool writes_point_size
;
1345 struct brw_stage_prog_data
* prog_data
[MESA_SHADER_STAGES
];
1346 uint32_t scratch_start
[MESA_SHADER_STAGES
];
1347 uint32_t total_scratch
;
1351 uint32_t nr_vs_entries
;
1354 uint32_t nr_gs_entries
;
1357 VkShaderStageFlags active_stages
;
1358 struct anv_state blend_state
;
1365 uint32_t ps_grf_start0
;
1366 uint32_t ps_grf_start2
;
1368 uint32_t gs_vertex_count
;
1372 uint32_t binding_stride
[MAX_VBS
];
1373 bool instancing_enable
[MAX_VBS
];
1374 bool primitive_restart
;
1377 uint32_t cs_thread_width_max
;
1378 uint32_t cs_right_mask
;
1382 uint32_t depth_stencil_state
[3];
1388 uint32_t wm_depth_stencil
[3];
1392 uint32_t wm_depth_stencil
[4];
1396 struct anv_graphics_pipeline_create_info
{
1398 * If non-negative, overrides the color attachment count of the pipeline's
1401 int8_t color_attachment_count
;
1404 bool disable_viewport
;
1405 bool disable_scissor
;
1411 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1412 struct anv_pipeline_cache
*cache
,
1413 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1414 const struct anv_graphics_pipeline_create_info
*extra
,
1415 const VkAllocationCallbacks
*alloc
);
1418 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1419 struct anv_pipeline_cache
*cache
,
1420 const VkComputePipelineCreateInfo
*info
,
1421 struct anv_shader_module
*module
,
1422 const char *entrypoint
,
1423 const VkSpecializationInfo
*spec_info
);
1426 anv_graphics_pipeline_create(VkDevice device
,
1427 VkPipelineCache cache
,
1428 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1429 const struct anv_graphics_pipeline_create_info
*extra
,
1430 const VkAllocationCallbacks
*alloc
,
1431 VkPipeline
*pPipeline
);
1434 gen7_graphics_pipeline_create(VkDevice _device
,
1435 struct anv_pipeline_cache
*cache
,
1436 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1437 const struct anv_graphics_pipeline_create_info
*extra
,
1438 const VkAllocationCallbacks
*alloc
,
1439 VkPipeline
*pPipeline
);
1442 gen75_graphics_pipeline_create(VkDevice _device
,
1443 struct anv_pipeline_cache
*cache
,
1444 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1445 const struct anv_graphics_pipeline_create_info
*extra
,
1446 const VkAllocationCallbacks
*alloc
,
1447 VkPipeline
*pPipeline
);
1450 gen8_graphics_pipeline_create(VkDevice _device
,
1451 struct anv_pipeline_cache
*cache
,
1452 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1453 const struct anv_graphics_pipeline_create_info
*extra
,
1454 const VkAllocationCallbacks
*alloc
,
1455 VkPipeline
*pPipeline
);
1457 gen9_graphics_pipeline_create(VkDevice _device
,
1458 struct anv_pipeline_cache
*cache
,
1459 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1460 const struct anv_graphics_pipeline_create_info
*extra
,
1461 const VkAllocationCallbacks
*alloc
,
1462 VkPipeline
*pPipeline
);
1464 gen7_compute_pipeline_create(VkDevice _device
,
1465 struct anv_pipeline_cache
*cache
,
1466 const VkComputePipelineCreateInfo
*pCreateInfo
,
1467 const VkAllocationCallbacks
*alloc
,
1468 VkPipeline
*pPipeline
);
1470 gen75_compute_pipeline_create(VkDevice _device
,
1471 struct anv_pipeline_cache
*cache
,
1472 const VkComputePipelineCreateInfo
*pCreateInfo
,
1473 const VkAllocationCallbacks
*alloc
,
1474 VkPipeline
*pPipeline
);
1477 gen8_compute_pipeline_create(VkDevice _device
,
1478 struct anv_pipeline_cache
*cache
,
1479 const VkComputePipelineCreateInfo
*pCreateInfo
,
1480 const VkAllocationCallbacks
*alloc
,
1481 VkPipeline
*pPipeline
);
1483 gen9_compute_pipeline_create(VkDevice _device
,
1484 struct anv_pipeline_cache
*cache
,
1485 const VkComputePipelineCreateInfo
*pCreateInfo
,
1486 const VkAllocationCallbacks
*alloc
,
1487 VkPipeline
*pPipeline
);
1489 struct anv_format_swizzle
{
1497 const VkFormat vk_format
;
1499 enum isl_format surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
1500 const struct isl_format_layout
*isl_layout
;
1501 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1502 struct anv_format_swizzle swizzle
;
1506 const struct anv_format
*
1507 anv_format_for_vk_format(VkFormat format
);
1510 anv_get_isl_format(VkFormat format
, VkImageAspectFlags aspect
,
1511 VkImageTiling tiling
, struct anv_format_swizzle
*swizzle
);
1514 anv_format_is_color(const struct anv_format
*format
)
1516 return !format
->depth_format
&& !format
->has_stencil
;
1520 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
1522 return format
->depth_format
|| format
->has_stencil
;
1526 * Subsurface of an anv_image.
1528 struct anv_surface
{
1529 struct isl_surf isl
;
1532 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1539 /* The original VkFormat provided by the client. This may not match any
1540 * of the actual surface formats.
1543 const struct anv_format
*format
;
1546 uint32_t array_size
;
1547 uint32_t samples
; /**< VkImageCreateInfo::samples */
1548 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1549 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1554 /* Set when bound */
1556 VkDeviceSize offset
;
1558 bool needs_nonrt_surface_state
:1;
1559 bool needs_color_rt_surface_state
:1;
1560 bool needs_storage_surface_state
:1;
1565 * For each foo, anv_image::foo_surface is valid if and only if
1566 * anv_image::format has a foo aspect.
1568 * The hardware requires that the depth buffer and stencil buffer be
1569 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1570 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1571 * allocate the depth and stencil buffers as separate surfaces in the same
1575 struct anv_surface color_surface
;
1578 struct anv_surface depth_surface
;
1579 struct anv_surface stencil_surface
;
1584 struct anv_image_view
{
1585 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1587 uint32_t offset
; /**< Offset into bo. */
1589 VkImageAspectFlags aspect_mask
;
1591 VkComponentMapping swizzle
;
1592 enum isl_format format
;
1593 uint32_t base_layer
;
1595 VkExtent3D level_0_extent
; /**< Extent of ::image's level 0 adjusted for ::vk_format. */
1596 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1598 /** RENDER_SURFACE_STATE when using image as a color render target. */
1599 struct anv_state color_rt_surface_state
;
1601 /** RENDER_SURFACE_STATE when using image as a non render target. */
1602 struct anv_state nonrt_surface_state
;
1604 /** RENDER_SURFACE_STATE when using image as a storage image. */
1605 struct anv_state storage_surface_state
;
1608 struct anv_image_create_info
{
1609 const VkImageCreateInfo
*vk_info
;
1610 isl_tiling_flags_t isl_tiling_flags
;
1614 VkResult
anv_image_create(VkDevice _device
,
1615 const struct anv_image_create_info
*info
,
1616 const VkAllocationCallbacks
* alloc
,
1619 struct anv_surface
*
1620 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
,
1621 VkImageAspectFlags aspect_mask
);
1623 void anv_image_view_init(struct anv_image_view
*view
,
1624 struct anv_device
*device
,
1625 const VkImageViewCreateInfo
* pCreateInfo
,
1626 struct anv_cmd_buffer
*cmd_buffer
,
1630 anv_fill_image_surface_state(struct anv_device
*device
, struct anv_state state
,
1631 struct anv_image_view
*iview
,
1632 const VkImageViewCreateInfo
*pCreateInfo
,
1633 VkImageUsageFlagBits usage
);
1635 gen7_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1636 struct anv_image_view
*iview
,
1637 const VkImageViewCreateInfo
*pCreateInfo
,
1638 VkImageUsageFlagBits usage
);
1640 gen75_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1641 struct anv_image_view
*iview
,
1642 const VkImageViewCreateInfo
*pCreateInfo
,
1643 VkImageUsageFlagBits usage
);
1645 gen8_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1646 struct anv_image_view
*iview
,
1647 const VkImageViewCreateInfo
*pCreateInfo
,
1648 VkImageUsageFlagBits usage
);
1650 gen9_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1651 struct anv_image_view
*iview
,
1652 const VkImageViewCreateInfo
*pCreateInfo
,
1653 VkImageUsageFlagBits usage
);
1655 struct anv_buffer_view
{
1656 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1658 uint32_t offset
; /**< Offset into bo. */
1659 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1661 struct anv_state surface_state
;
1662 struct anv_state storage_surface_state
;
1665 const struct anv_format
*
1666 anv_format_for_descriptor_type(VkDescriptorType type
);
1668 void anv_fill_buffer_surface_state(struct anv_device
*device
,
1669 struct anv_state state
,
1670 enum isl_format format
,
1671 uint32_t offset
, uint32_t range
,
1674 void gen7_fill_buffer_surface_state(void *state
, enum isl_format format
,
1675 uint32_t offset
, uint32_t range
,
1677 void gen75_fill_buffer_surface_state(void *state
, enum isl_format format
,
1678 uint32_t offset
, uint32_t range
,
1680 void gen8_fill_buffer_surface_state(void *state
, enum isl_format format
,
1681 uint32_t offset
, uint32_t range
,
1683 void gen9_fill_buffer_surface_state(void *state
, enum isl_format format
,
1684 uint32_t offset
, uint32_t range
,
1687 void anv_image_view_fill_image_param(struct anv_device
*device
,
1688 struct anv_image_view
*view
,
1689 struct brw_image_param
*param
);
1690 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1691 struct anv_buffer_view
*view
,
1692 struct brw_image_param
*param
);
1694 struct anv_sampler
{
1698 struct anv_framebuffer
{
1703 uint32_t attachment_count
;
1704 struct anv_image_view
* attachments
[0];
1707 struct anv_subpass
{
1708 uint32_t input_count
;
1709 uint32_t * input_attachments
;
1710 uint32_t color_count
;
1711 uint32_t * color_attachments
;
1712 uint32_t * resolve_attachments
;
1713 uint32_t depth_stencil_attachment
;
1715 /** Subpass has at least one resolve attachment */
1719 struct anv_render_pass_attachment
{
1720 const struct anv_format
*format
;
1722 VkAttachmentLoadOp load_op
;
1723 VkAttachmentLoadOp stencil_load_op
;
1726 struct anv_render_pass
{
1727 uint32_t attachment_count
;
1728 uint32_t subpass_count
;
1729 uint32_t * subpass_attachments
;
1730 struct anv_render_pass_attachment
* attachments
;
1731 struct anv_subpass subpasses
[0];
1734 extern struct anv_render_pass anv_meta_dummy_renderpass
;
1736 struct anv_query_pool_slot
{
1742 struct anv_query_pool
{
1748 VkResult
anv_device_init_meta(struct anv_device
*device
);
1749 void anv_device_finish_meta(struct anv_device
*device
);
1751 void *anv_lookup_entrypoint(const char *name
);
1753 void anv_dump_image_to_ppm(struct anv_device
*device
,
1754 struct anv_image
*image
, unsigned miplevel
,
1755 unsigned array_layer
, const char *filename
);
1757 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1759 static inline struct __anv_type * \
1760 __anv_type ## _from_handle(__VkType _handle) \
1762 return (struct __anv_type *) _handle; \
1765 static inline __VkType \
1766 __anv_type ## _to_handle(struct __anv_type *_obj) \
1768 return (__VkType) _obj; \
1771 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1773 static inline struct __anv_type * \
1774 __anv_type ## _from_handle(__VkType _handle) \
1776 return (struct __anv_type *)(uintptr_t) _handle; \
1779 static inline __VkType \
1780 __anv_type ## _to_handle(struct __anv_type *_obj) \
1782 return (__VkType)(uintptr_t) _obj; \
1785 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1786 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1788 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1789 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1790 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1791 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1792 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1794 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1795 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1796 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1797 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1798 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1799 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1800 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1801 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1802 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1803 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1804 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1805 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1806 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1807 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1808 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1809 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1810 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1811 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1813 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1815 static inline const __VkType * \
1816 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1818 return (const __VkType *) __anv_obj; \
1821 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1822 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1824 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1825 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1826 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)