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
79 #define ICD_LOADER_MAGIC 0x01CDC0DE
81 typedef union _VK_LOADER_DATA
{
82 uintptr_t loaderMagic
;
86 #define anv_noreturn __attribute__((__noreturn__))
87 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
89 #define MIN(a, b) ((a) < (b) ? (a) : (b))
90 #define MAX(a, b) ((a) > (b) ? (a) : (b))
92 static inline uint32_t
93 align_u32(uint32_t v
, uint32_t a
)
95 assert(a
!= 0 && a
== (a
& -a
));
96 return (v
+ a
- 1) & ~(a
- 1);
99 static inline uint64_t
100 align_u64(uint64_t v
, uint64_t a
)
102 assert(a
!= 0 && a
== (a
& -a
));
103 return (v
+ a
- 1) & ~(a
- 1);
106 static inline int32_t
107 align_i32(int32_t v
, int32_t a
)
109 assert(a
!= 0 && a
== (a
& -a
));
110 return (v
+ a
- 1) & ~(a
- 1);
113 /** Alignment must be a power of 2. */
115 anv_is_aligned(uintmax_t n
, uintmax_t a
)
117 assert(a
== (a
& -a
));
118 return (n
& (a
- 1)) == 0;
121 static inline uint32_t
122 anv_minify(uint32_t n
, uint32_t levels
)
124 if (unlikely(n
== 0))
127 return MAX(n
>> levels
, 1);
131 anv_clamp_f(float f
, float min
, float max
)
144 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
146 if (*inout_mask
& clear_mask
) {
147 *inout_mask
&= ~clear_mask
;
154 #define for_each_bit(b, dword) \
155 for (uint32_t __dword = (dword); \
156 (b) = __builtin_ffs(__dword) - 1, __dword; \
157 __dword &= ~(1 << (b)))
159 #define typed_memcpy(dest, src, count) ({ \
160 static_assert(sizeof(*src) == sizeof(*dest), ""); \
161 memcpy((dest), (src), (count) * sizeof(*(src))); \
164 #define zero(x) (memset(&(x), 0, sizeof(x)))
166 /* Define no kernel as 1, since that's an illegal offset for a kernel */
170 VkStructureType sType
;
174 /* Whenever we generate an error, pass it through this function. Useful for
175 * debugging, where we can break on it. Only call at error site, not when
176 * propagating errors. Might be useful to plug in a stack trace here.
179 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
182 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
183 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
185 #define vk_error(error) error
186 #define vk_errorf(error, format, ...) error
189 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
190 anv_printflike(3, 4);
191 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
192 void anv_loge_v(const char *format
, va_list va
);
195 * Print a FINISHME message, including its source location.
197 #define anv_finishme(format, ...) \
198 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
200 /* A non-fatal assert. Useful for debugging. */
202 #define anv_assert(x) ({ \
203 if (unlikely(!(x))) \
204 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
207 #define anv_assert(x)
211 * If a block of code is annotated with anv_validate, then the block runs only
215 #define anv_validate if (1)
217 #define anv_validate if (0)
220 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
221 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
223 #define stub_return(v) \
225 anv_finishme("stub %s", __func__); \
231 anv_finishme("stub %s", __func__); \
236 * A dynamically growable, circular buffer. Elements are added at head and
237 * removed from tail. head and tail are free-running uint32_t indices and we
238 * only compute the modulo with size when accessing the array. This way,
239 * number of bytes in the queue is always head - tail, even in case of
246 uint32_t element_size
;
251 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
252 void *anv_vector_add(struct anv_vector
*queue
);
253 void *anv_vector_remove(struct anv_vector
*queue
);
256 anv_vector_length(struct anv_vector
*queue
)
258 return (queue
->head
- queue
->tail
) / queue
->element_size
;
262 anv_vector_head(struct anv_vector
*vector
)
264 assert(vector
->tail
< vector
->head
);
265 return (void *)((char *)vector
->data
+
266 ((vector
->head
- vector
->element_size
) &
267 (vector
->size
- 1)));
271 anv_vector_tail(struct anv_vector
*vector
)
273 return (void *)((char *)vector
->data
+ (vector
->tail
& (vector
->size
- 1)));
277 anv_vector_finish(struct anv_vector
*queue
)
282 #define anv_vector_foreach(elem, queue) \
283 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
284 for (uint32_t __anv_vector_offset = (queue)->tail; \
285 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
286 __anv_vector_offset += (queue)->element_size)
291 /* Index into the current validation list. This is used by the
292 * validation list building alrogithm to track which buffers are already
293 * in the validation list so that we can ensure uniqueness.
297 /* Last known offset. This value is provided by the kernel when we
298 * execbuf and is used as the presumed offset for the next bunch of
307 /* Represents a lock-free linked list of "free" things. This is used by
308 * both the block pool and the state pools. Unfortunately, in order to
309 * solve the ABA problem, we can't use a single uint32_t head.
311 union anv_free_list
{
315 /* A simple count that is incremented every time the head changes. */
321 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
323 struct anv_block_state
{
333 struct anv_block_pool
{
334 struct anv_device
*device
;
338 /* The offset from the start of the bo to the "center" of the block
339 * pool. Pointers to allocated blocks are given by
340 * bo.map + center_bo_offset + offsets.
342 uint32_t center_bo_offset
;
344 /* Current memory map of the block pool. This pointer may or may not
345 * point to the actual beginning of the block pool memory. If
346 * anv_block_pool_alloc_back has ever been called, then this pointer
347 * will point to the "center" position of the buffer and all offsets
348 * (negative or positive) given out by the block pool alloc functions
349 * will be valid relative to this pointer.
351 * In particular, map == bo.map + center_offset
357 * Array of mmaps and gem handles owned by the block pool, reclaimed when
358 * the block pool is destroyed.
360 struct anv_vector mmap_cleanups
;
364 union anv_free_list free_list
;
365 struct anv_block_state state
;
367 union anv_free_list back_free_list
;
368 struct anv_block_state back_state
;
371 /* Block pools are backed by a fixed-size 2GB memfd */
372 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
374 /* The center of the block pool is also the middle of the memfd. This may
375 * change in the future if we decide differently for some reason.
377 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
379 static inline uint32_t
380 anv_block_pool_size(struct anv_block_pool
*pool
)
382 return pool
->state
.end
+ pool
->back_state
.end
;
391 struct anv_fixed_size_state_pool
{
393 union anv_free_list free_list
;
394 struct anv_block_state block
;
397 #define ANV_MIN_STATE_SIZE_LOG2 6
398 #define ANV_MAX_STATE_SIZE_LOG2 10
400 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
402 struct anv_state_pool
{
403 struct anv_block_pool
*block_pool
;
404 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
407 struct anv_state_stream_block
;
409 struct anv_state_stream
{
410 struct anv_block_pool
*block_pool
;
412 /* The current working block */
413 struct anv_state_stream_block
*block
;
415 /* Offset at which the current block starts */
417 /* Offset at which to allocate the next state */
419 /* Offset at which the current block ends */
423 #define CACHELINE_SIZE 64
424 #define CACHELINE_MASK 63
427 anv_state_clflush(struct anv_state state
)
429 /* state.map may not be cacheline aligned, so round down the start pointer
430 * to a cacheline boundary so we flush all pages that contain the state.
432 void *end
= state
.map
+ state
.alloc_size
;
433 void *p
= (void *) (((uintptr_t) state
.map
) & ~CACHELINE_MASK
);
435 __builtin_ia32_sfence();
437 __builtin_ia32_clflush(p
);
442 void anv_block_pool_init(struct anv_block_pool
*pool
,
443 struct anv_device
*device
, uint32_t block_size
);
444 void anv_block_pool_finish(struct anv_block_pool
*pool
);
445 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
446 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
447 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
448 void anv_state_pool_init(struct anv_state_pool
*pool
,
449 struct anv_block_pool
*block_pool
);
450 void anv_state_pool_finish(struct anv_state_pool
*pool
);
451 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
452 size_t state_size
, size_t alignment
);
453 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
454 void anv_state_stream_init(struct anv_state_stream
*stream
,
455 struct anv_block_pool
*block_pool
);
456 void anv_state_stream_finish(struct anv_state_stream
*stream
);
457 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
458 uint32_t size
, uint32_t alignment
);
461 * Implements a pool of re-usable BOs. The interface is identical to that
462 * of block_pool except that each block is its own BO.
465 struct anv_device
*device
;
472 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
473 struct anv_device
*device
, uint32_t block_size
);
474 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
475 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
476 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
479 void *anv_resolve_entrypoint(uint32_t index
);
481 extern struct anv_dispatch_table dtable
;
483 #define ANV_CALL(func) ({ \
484 if (dtable.func == NULL) { \
485 size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
486 dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
492 anv_alloc(const VkAllocationCallbacks
*alloc
,
493 size_t size
, size_t align
,
494 VkSystemAllocationScope scope
)
496 return alloc
->pfnAllocation(alloc
->pUserData
, size
, align
, scope
);
500 anv_realloc(const VkAllocationCallbacks
*alloc
,
501 void *ptr
, size_t size
, size_t align
,
502 VkSystemAllocationScope scope
)
504 return alloc
->pfnReallocation(alloc
->pUserData
, ptr
, size
, align
, scope
);
508 anv_free(const VkAllocationCallbacks
*alloc
, void *data
)
510 alloc
->pfnFree(alloc
->pUserData
, data
);
514 anv_alloc2(const VkAllocationCallbacks
*parent_alloc
,
515 const VkAllocationCallbacks
*alloc
,
516 size_t size
, size_t align
,
517 VkSystemAllocationScope scope
)
520 return anv_alloc(alloc
, size
, align
, scope
);
522 return anv_alloc(parent_alloc
, size
, align
, scope
);
526 anv_free2(const VkAllocationCallbacks
*parent_alloc
,
527 const VkAllocationCallbacks
*alloc
,
531 anv_free(alloc
, data
);
533 anv_free(parent_alloc
, data
);
536 struct anv_physical_device
{
537 VK_LOADER_DATA _loader_data
;
539 struct anv_instance
* instance
;
543 const struct brw_device_info
* info
;
544 uint64_t aperture_size
;
545 struct brw_compiler
* compiler
;
546 struct isl_device isl_dev
;
549 struct anv_instance
{
550 VK_LOADER_DATA _loader_data
;
552 VkAllocationCallbacks alloc
;
555 int physicalDeviceCount
;
556 struct anv_physical_device physicalDevice
;
561 VkResult
anv_init_wsi(struct anv_instance
*instance
);
562 void anv_finish_wsi(struct anv_instance
*instance
);
564 struct anv_meta_state
{
565 VkAllocationCallbacks alloc
;
569 * Pipeline N is used to clear color attachment N of the current
572 * HACK: We use one pipeline per color attachment to work around the
573 * compiler's inability to dynamically set the render target index of
574 * the render target write message.
576 struct anv_pipeline
*color_pipelines
[MAX_RTS
];
578 struct anv_pipeline
*depth_only_pipeline
;
579 struct anv_pipeline
*stencil_only_pipeline
;
580 struct anv_pipeline
*depthstencil_pipeline
;
584 VkRenderPass render_pass
;
586 /** Pipeline that blits from a 1D image. */
587 VkPipeline pipeline_1d_src
;
589 /** Pipeline that blits from a 2D image. */
590 VkPipeline pipeline_2d_src
;
592 /** Pipeline that blits from a 3D image. */
593 VkPipeline pipeline_3d_src
;
595 VkPipelineLayout pipeline_layout
;
596 VkDescriptorSetLayout ds_layout
;
601 VK_LOADER_DATA _loader_data
;
603 struct anv_device
* device
;
605 struct anv_state_pool
* pool
;
608 struct anv_pipeline_cache
{
609 struct anv_device
* device
;
610 struct anv_state_stream program_stream
;
611 pthread_mutex_t mutex
;
614 void anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
615 struct anv_device
*device
);
616 void anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
);
619 VK_LOADER_DATA _loader_data
;
621 VkAllocationCallbacks alloc
;
623 struct anv_instance
* instance
;
625 struct brw_device_info info
;
626 struct isl_device isl_dev
;
630 struct anv_bo_pool batch_bo_pool
;
632 struct anv_block_pool dynamic_state_block_pool
;
633 struct anv_state_pool dynamic_state_pool
;
635 struct anv_block_pool instruction_block_pool
;
636 struct anv_pipeline_cache default_pipeline_cache
;
638 struct anv_block_pool surface_state_block_pool
;
639 struct anv_state_pool surface_state_pool
;
641 struct anv_bo workaround_bo
;
643 struct anv_meta_state meta_state
;
645 struct anv_state border_colors
;
647 struct anv_queue queue
;
649 struct anv_block_pool scratch_block_pool
;
651 pthread_mutex_t mutex
;
654 void* anv_gem_mmap(struct anv_device
*device
,
655 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
656 void anv_gem_munmap(void *p
, uint64_t size
);
657 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
658 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
659 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
660 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
661 int anv_gem_execbuffer(struct anv_device
*device
,
662 struct drm_i915_gem_execbuffer2
*execbuf
);
663 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
664 uint32_t stride
, uint32_t tiling
);
665 int anv_gem_create_context(struct anv_device
*device
);
666 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
667 int anv_gem_get_param(int fd
, uint32_t param
);
668 bool anv_gem_get_bit6_swizzle(int fd
, uint32_t tiling
);
669 int anv_gem_get_aperture(int fd
, uint64_t *size
);
670 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
671 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
672 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
673 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
674 uint32_t read_domains
, uint32_t write_domain
);
676 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
678 struct anv_reloc_list
{
681 struct drm_i915_gem_relocation_entry
* relocs
;
682 struct anv_bo
** reloc_bos
;
685 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
686 const VkAllocationCallbacks
*alloc
);
687 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
688 const VkAllocationCallbacks
*alloc
);
690 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
691 const VkAllocationCallbacks
*alloc
,
692 uint32_t offset
, struct anv_bo
*target_bo
,
695 struct anv_batch_bo
{
696 /* Link in the anv_cmd_buffer.owned_batch_bos list */
697 struct list_head link
;
701 /* Bytes actually consumed in this batch BO */
704 /* Last seen surface state block pool bo offset */
705 uint32_t last_ss_pool_bo_offset
;
707 struct anv_reloc_list relocs
;
711 const VkAllocationCallbacks
* alloc
;
717 struct anv_reloc_list
* relocs
;
719 /* This callback is called (with the associated user data) in the event
720 * that the batch runs out of space.
722 VkResult (*extend_cb
)(struct anv_batch
*, void *);
726 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
727 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
728 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
729 void *location
, struct anv_bo
*bo
, uint32_t offset
);
736 #define __gen_address_type struct anv_address
737 #define __gen_user_data struct anv_batch
739 static inline uint64_t
740 __gen_combine_address(struct anv_batch
*batch
, void *location
,
741 const struct anv_address address
, uint32_t delta
)
743 if (address
.bo
== NULL
) {
744 return address
.offset
+ delta
;
746 assert(batch
->start
<= location
&& location
< batch
->end
);
748 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
752 /* Wrapper macros needed to work around preprocessor argument issues. In
753 * particular, arguments don't get pre-evaluated if they are concatenated.
754 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
755 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
756 * We can work around this easily enough with these helpers.
758 #define __anv_cmd_length(cmd) cmd ## _length
759 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
760 #define __anv_cmd_header(cmd) cmd ## _header
761 #define __anv_cmd_pack(cmd) cmd ## _pack
763 #define anv_batch_emit(batch, cmd, ...) do { \
764 void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
765 struct cmd __template = { \
766 __anv_cmd_header(cmd), \
769 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
770 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, __anv_cmd_length(cmd) * 4)); \
773 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
774 void *__dst = anv_batch_emit_dwords(batch, n); \
775 struct cmd __template = { \
776 __anv_cmd_header(cmd), \
777 .DwordLength = n - __anv_cmd_length_bias(cmd), \
780 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
784 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
788 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
789 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
790 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
791 dw[i] = (dwords0)[i] | (dwords1)[i]; \
792 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
795 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
796 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
797 struct anv_state __state = \
798 anv_state_pool_alloc((pool), __size, align); \
799 struct cmd __template = { \
802 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
803 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
804 if (!(pool)->block_pool->device->info.has_llc) \
805 anv_state_clflush(__state); \
809 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
810 .GraphicsDataTypeGFDT = 0, \
811 .LLCCacheabilityControlLLCCC = 0, \
812 .L3CacheabilityControlL3CC = 1, \
815 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
816 .LLCeLLCCacheabilityControlLLCCC = 0, \
817 .L3CacheabilityControlL3CC = 1, \
820 #define GEN8_MOCS { \
821 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
822 .TargetCache = L3DefertoPATforLLCeLLCselection, \
826 /* Skylake: MOCS is now an index into an array of 62 different caching
827 * configurations programmed by the kernel.
830 #define GEN9_MOCS { \
831 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
832 .IndextoMOCSTables = 2 \
835 #define GEN9_MOCS_PTE { \
836 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
837 .IndextoMOCSTables = 1 \
840 struct anv_device_memory
{
843 VkDeviceSize map_size
;
848 * Header for Vertex URB Entry (VUE)
850 struct anv_vue_header
{
852 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
853 uint32_t ViewportIndex
;
857 struct anv_descriptor_set_binding_layout
{
858 /* Number of array elements in this binding */
861 /* Index into the flattend descriptor set */
862 uint16_t descriptor_index
;
864 /* Index into the dynamic state array for a dynamic buffer */
865 int16_t dynamic_offset_index
;
867 /* Index into the descriptor set buffer views */
868 int16_t buffer_index
;
871 /* Index into the binding table for the associated surface */
872 int16_t surface_index
;
874 /* Index into the sampler table for the associated sampler */
875 int16_t sampler_index
;
877 /* Index into the image table for the associated image */
879 } stage
[MESA_SHADER_STAGES
];
881 /* Immutable samplers (or NULL if no immutable samplers) */
882 struct anv_sampler
**immutable_samplers
;
885 struct anv_descriptor_set_layout
{
886 /* Number of bindings in this descriptor set */
887 uint16_t binding_count
;
889 /* Total size of the descriptor set with room for all array entries */
892 /* Shader stages affected by this descriptor set */
893 uint16_t shader_stages
;
895 /* Number of buffers in this descriptor set */
896 uint16_t buffer_count
;
898 /* Number of dynamic offsets used by this descriptor set */
899 uint16_t dynamic_offset_count
;
901 /* Bindings in this descriptor set */
902 struct anv_descriptor_set_binding_layout binding
[0];
905 struct anv_descriptor
{
906 VkDescriptorType type
;
911 struct anv_image_view
*image_view
;
913 struct anv_sampler
*sampler
;
916 struct anv_buffer_view
*buffer_view
;
920 struct anv_descriptor_set
{
921 const struct anv_descriptor_set_layout
*layout
;
922 struct anv_buffer_view
*buffer_views
;
923 struct anv_descriptor descriptors
[0];
927 anv_descriptor_set_create(struct anv_device
*device
,
928 const struct anv_descriptor_set_layout
*layout
,
929 struct anv_descriptor_set
**out_set
);
932 anv_descriptor_set_destroy(struct anv_device
*device
,
933 struct anv_descriptor_set
*set
);
935 struct anv_pipeline_binding
{
936 /* The descriptor set this surface corresponds to */
939 /* Offset into the descriptor set */
943 struct anv_pipeline_layout
{
945 struct anv_descriptor_set_layout
*layout
;
946 uint32_t dynamic_offset_start
;
948 uint32_t surface_start
;
949 uint32_t sampler_start
;
950 uint32_t image_start
;
951 } stage
[MESA_SHADER_STAGES
];
957 bool has_dynamic_offsets
;
958 uint32_t surface_count
;
959 struct anv_pipeline_binding
*surface_to_descriptor
;
960 uint32_t sampler_count
;
961 struct anv_pipeline_binding
*sampler_to_descriptor
;
962 uint32_t image_count
;
963 } stage
[MESA_SHADER_STAGES
];
965 struct anv_pipeline_binding entries
[0];
969 struct anv_device
* device
;
972 VkBufferUsageFlags usage
;
979 enum anv_cmd_dirty_bits
{
980 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
981 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
982 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
983 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
984 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
985 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
986 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
987 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
988 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
989 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
990 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
991 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
992 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
994 typedef uint32_t anv_cmd_dirty_mask_t
;
996 struct anv_vertex_binding
{
997 struct anv_buffer
* buffer
;
1001 struct anv_push_constants
{
1002 /* Current allocated size of this push constants data structure.
1003 * Because a decent chunk of it may not be used (images on SKL, for
1004 * instance), we won't actually allocate the entire structure up-front.
1008 /* Push constant data provided by the client through vkPushConstants */
1009 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
1011 /* Our hardware only provides zero-based vertex and instance id so, in
1012 * order to satisfy the vulkan requirements, we may have to push one or
1013 * both of these into the shader.
1015 uint32_t base_vertex
;
1016 uint32_t base_instance
;
1018 /* Offsets and ranges for dynamically bound buffers */
1022 } dynamic
[MAX_DYNAMIC_BUFFERS
];
1024 /* Image data for image_load_store on pre-SKL */
1025 struct brw_image_param images
[MAX_IMAGES
];
1028 struct anv_dynamic_state
{
1031 VkViewport viewports
[MAX_VIEWPORTS
];
1036 VkRect2D scissors
[MAX_SCISSORS
];
1047 float blend_constants
[4];
1057 } stencil_compare_mask
;
1062 } stencil_write_mask
;
1067 } stencil_reference
;
1070 extern const struct anv_dynamic_state default_dynamic_state
;
1072 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1073 const struct anv_dynamic_state
*src
,
1074 uint32_t copy_mask
);
1077 * Attachment state when recording a renderpass instance.
1079 * The clear value is valid only if there exists a pending clear.
1081 struct anv_attachment_state
{
1082 VkImageAspectFlags pending_clear_aspects
;
1083 VkClearValue clear_value
;
1086 /** State required while building cmd buffer */
1087 struct anv_cmd_state
{
1088 /* PIPELINE_SELECT.PipelineSelection */
1089 uint32_t current_pipeline
;
1090 uint32_t current_l3_config
;
1092 anv_cmd_dirty_mask_t dirty
;
1093 anv_cmd_dirty_mask_t compute_dirty
;
1094 uint32_t num_workgroups_offset
;
1095 struct anv_bo
*num_workgroups_bo
;
1096 VkShaderStageFlags descriptors_dirty
;
1097 VkShaderStageFlags push_constants_dirty
;
1098 uint32_t scratch_size
;
1099 struct anv_pipeline
* pipeline
;
1100 struct anv_pipeline
* compute_pipeline
;
1101 struct anv_framebuffer
* framebuffer
;
1102 struct anv_render_pass
* pass
;
1103 struct anv_subpass
* subpass
;
1104 uint32_t restart_index
;
1105 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1106 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1107 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1108 struct anv_state binding_tables
[MESA_SHADER_STAGES
];
1109 struct anv_state samplers
[MESA_SHADER_STAGES
];
1110 struct anv_dynamic_state dynamic
;
1114 * Array length is anv_cmd_state::pass::attachment_count. Array content is
1115 * valid only when recording a render pass instance.
1117 struct anv_attachment_state
* attachments
;
1120 struct anv_buffer
* index_buffer
;
1121 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1122 uint32_t index_offset
;
1126 struct anv_cmd_pool
{
1127 VkAllocationCallbacks alloc
;
1128 struct list_head cmd_buffers
;
1131 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1133 enum anv_cmd_buffer_exec_mode
{
1134 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1135 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1136 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1137 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1140 struct anv_cmd_buffer
{
1141 VK_LOADER_DATA _loader_data
;
1143 struct anv_device
* device
;
1145 struct anv_cmd_pool
* pool
;
1146 struct list_head pool_link
;
1148 struct anv_batch batch
;
1150 /* Fields required for the actual chain of anv_batch_bo's.
1152 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1154 struct list_head batch_bos
;
1155 enum anv_cmd_buffer_exec_mode exec_mode
;
1157 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1158 * referenced by this command buffer
1160 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1162 struct anv_vector seen_bbos
;
1164 /* A vector of int32_t's for every block of binding tables.
1166 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1168 struct anv_vector bt_blocks
;
1170 struct anv_reloc_list surface_relocs
;
1172 /* Information needed for execbuf
1174 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1177 struct drm_i915_gem_execbuffer2 execbuf
;
1179 struct drm_i915_gem_exec_object2
* objects
;
1181 struct anv_bo
** bos
;
1183 /* Allocated length of the 'objects' and 'bos' arrays */
1184 uint32_t array_length
;
1189 /* Serial for tracking buffer completion */
1192 /* Stream objects for storing temporary data */
1193 struct anv_state_stream surface_state_stream
;
1194 struct anv_state_stream dynamic_state_stream
;
1196 VkCommandBufferUsageFlags usage_flags
;
1197 VkCommandBufferLevel level
;
1199 struct anv_cmd_state state
;
1202 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1203 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1204 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1205 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1206 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1207 struct anv_cmd_buffer
*secondary
);
1208 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1210 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1211 unsigned stage
, struct anv_state
*bt_state
);
1212 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1213 unsigned stage
, struct anv_state
*state
);
1214 uint32_t gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
1215 void gen7_cmd_buffer_emit_descriptor_pointers(struct anv_cmd_buffer
*cmd_buffer
,
1218 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1219 const void *data
, uint32_t size
, uint32_t alignment
);
1220 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1221 uint32_t *a
, uint32_t *b
,
1222 uint32_t dwords
, uint32_t alignment
);
1225 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1227 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1228 uint32_t entries
, uint32_t *state_offset
);
1230 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1232 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1233 uint32_t size
, uint32_t alignment
);
1236 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1238 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1239 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1241 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1242 void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1243 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1244 void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1246 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1248 void anv_cmd_state_setup_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1249 const VkRenderPassBeginInfo
*info
);
1251 void gen7_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1252 struct anv_subpass
*subpass
);
1253 void gen8_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1254 struct anv_subpass
*subpass
);
1255 void gen9_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1256 struct anv_subpass
*subpass
);
1257 void anv_cmd_buffer_set_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1258 struct anv_subpass
*subpass
);
1261 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1262 gl_shader_stage stage
);
1264 anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer
*cmd_buffer
);
1266 void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer
*cmd_buffer
);
1268 const struct anv_image_view
*
1269 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1271 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1275 struct drm_i915_gem_execbuffer2 execbuf
;
1276 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1282 struct anv_state state
;
1287 struct anv_shader_module
{
1288 struct nir_shader
* nir
;
1294 static inline gl_shader_stage
1295 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1297 assert(__builtin_popcount(vk_stage
) == 1);
1298 return ffs(vk_stage
) - 1;
1301 static inline VkShaderStageFlagBits
1302 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1304 return (1 << mesa_stage
);
1307 #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
1309 #define anv_foreach_stage(stage, stage_bits) \
1310 for (gl_shader_stage stage, \
1311 __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
1312 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1313 __tmp &= ~(1 << (stage)))
1315 struct anv_pipeline
{
1316 struct anv_device
* device
;
1317 struct anv_batch batch
;
1318 uint32_t batch_data
[512];
1319 struct anv_reloc_list batch_relocs
;
1320 uint32_t dynamic_state_mask
;
1321 struct anv_dynamic_state dynamic_state
;
1323 struct anv_pipeline_layout
* layout
;
1326 struct brw_vs_prog_data vs_prog_data
;
1327 struct brw_wm_prog_data wm_prog_data
;
1328 struct brw_gs_prog_data gs_prog_data
;
1329 struct brw_cs_prog_data cs_prog_data
;
1330 bool writes_point_size
;
1331 struct brw_stage_prog_data
* prog_data
[MESA_SHADER_STAGES
];
1332 uint32_t scratch_start
[MESA_SHADER_STAGES
];
1333 uint32_t total_scratch
;
1337 uint32_t nr_vs_entries
;
1340 uint32_t nr_gs_entries
;
1343 VkShaderStageFlags active_stages
;
1344 struct anv_state blend_state
;
1351 uint32_t ps_grf_start0
;
1352 uint32_t ps_grf_start2
;
1354 uint32_t gs_vertex_count
;
1358 uint32_t binding_stride
[MAX_VBS
];
1359 bool instancing_enable
[MAX_VBS
];
1360 bool primitive_restart
;
1363 uint32_t cs_thread_width_max
;
1364 uint32_t cs_right_mask
;
1368 uint32_t depth_stencil_state
[3];
1374 uint32_t wm_depth_stencil
[3];
1378 uint32_t wm_depth_stencil
[4];
1382 struct anv_graphics_pipeline_create_info
{
1384 * If non-negative, overrides the color attachment count of the pipeline's
1387 int8_t color_attachment_count
;
1390 bool disable_viewport
;
1391 bool disable_scissor
;
1397 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1398 struct anv_pipeline_cache
*cache
,
1399 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1400 const struct anv_graphics_pipeline_create_info
*extra
,
1401 const VkAllocationCallbacks
*alloc
);
1404 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1405 struct anv_pipeline_cache
*cache
,
1406 const VkComputePipelineCreateInfo
*info
,
1407 struct anv_shader_module
*module
,
1408 const char *entrypoint
,
1409 const VkSpecializationInfo
*spec_info
);
1412 anv_graphics_pipeline_create(VkDevice device
,
1413 VkPipelineCache cache
,
1414 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1415 const struct anv_graphics_pipeline_create_info
*extra
,
1416 const VkAllocationCallbacks
*alloc
,
1417 VkPipeline
*pPipeline
);
1420 gen7_graphics_pipeline_create(VkDevice _device
,
1421 struct anv_pipeline_cache
*cache
,
1422 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1423 const struct anv_graphics_pipeline_create_info
*extra
,
1424 const VkAllocationCallbacks
*alloc
,
1425 VkPipeline
*pPipeline
);
1428 gen75_graphics_pipeline_create(VkDevice _device
,
1429 struct anv_pipeline_cache
*cache
,
1430 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1431 const struct anv_graphics_pipeline_create_info
*extra
,
1432 const VkAllocationCallbacks
*alloc
,
1433 VkPipeline
*pPipeline
);
1436 gen8_graphics_pipeline_create(VkDevice _device
,
1437 struct anv_pipeline_cache
*cache
,
1438 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1439 const struct anv_graphics_pipeline_create_info
*extra
,
1440 const VkAllocationCallbacks
*alloc
,
1441 VkPipeline
*pPipeline
);
1443 gen9_graphics_pipeline_create(VkDevice _device
,
1444 struct anv_pipeline_cache
*cache
,
1445 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1446 const struct anv_graphics_pipeline_create_info
*extra
,
1447 const VkAllocationCallbacks
*alloc
,
1448 VkPipeline
*pPipeline
);
1450 gen7_compute_pipeline_create(VkDevice _device
,
1451 struct anv_pipeline_cache
*cache
,
1452 const VkComputePipelineCreateInfo
*pCreateInfo
,
1453 const VkAllocationCallbacks
*alloc
,
1454 VkPipeline
*pPipeline
);
1456 gen75_compute_pipeline_create(VkDevice _device
,
1457 struct anv_pipeline_cache
*cache
,
1458 const VkComputePipelineCreateInfo
*pCreateInfo
,
1459 const VkAllocationCallbacks
*alloc
,
1460 VkPipeline
*pPipeline
);
1463 gen8_compute_pipeline_create(VkDevice _device
,
1464 struct anv_pipeline_cache
*cache
,
1465 const VkComputePipelineCreateInfo
*pCreateInfo
,
1466 const VkAllocationCallbacks
*alloc
,
1467 VkPipeline
*pPipeline
);
1469 gen9_compute_pipeline_create(VkDevice _device
,
1470 struct anv_pipeline_cache
*cache
,
1471 const VkComputePipelineCreateInfo
*pCreateInfo
,
1472 const VkAllocationCallbacks
*alloc
,
1473 VkPipeline
*pPipeline
);
1475 struct anv_format_swizzle
{
1483 const VkFormat vk_format
;
1485 enum isl_format surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
1486 const struct isl_format_layout
*isl_layout
;
1487 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1488 struct anv_format_swizzle swizzle
;
1492 const struct anv_format
*
1493 anv_format_for_vk_format(VkFormat format
);
1496 anv_get_isl_format(VkFormat format
, VkImageAspectFlags aspect
,
1497 VkImageTiling tiling
, struct anv_format_swizzle
*swizzle
);
1500 anv_format_is_color(const struct anv_format
*format
)
1502 return !format
->depth_format
&& !format
->has_stencil
;
1506 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
1508 return format
->depth_format
|| format
->has_stencil
;
1512 * Subsurface of an anv_image.
1514 struct anv_surface
{
1515 struct isl_surf isl
;
1518 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1525 /* The original VkFormat provided by the client. This may not match any
1526 * of the actual surface formats.
1529 const struct anv_format
*format
;
1532 uint32_t array_size
;
1533 uint32_t samples
; /**< VkImageCreateInfo::samples */
1534 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1535 VkImageTiling tiling
; /** VkImageCreateInfo::tiling */
1540 /* Set when bound */
1542 VkDeviceSize offset
;
1544 bool needs_nonrt_surface_state
:1;
1545 bool needs_color_rt_surface_state
:1;
1546 bool needs_storage_surface_state
:1;
1551 * For each foo, anv_image::foo_surface is valid if and only if
1552 * anv_image::format has a foo aspect.
1554 * The hardware requires that the depth buffer and stencil buffer be
1555 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1556 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1557 * allocate the depth and stencil buffers as separate surfaces in the same
1561 struct anv_surface color_surface
;
1564 struct anv_surface depth_surface
;
1565 struct anv_surface stencil_surface
;
1570 struct anv_image_view
{
1571 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1573 uint32_t offset
; /**< Offset into bo. */
1575 VkImageAspectFlags aspect_mask
;
1577 VkComponentMapping swizzle
;
1578 enum isl_format format
;
1579 uint32_t base_layer
;
1581 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1583 /** RENDER_SURFACE_STATE when using image as a color render target. */
1584 struct anv_state color_rt_surface_state
;
1586 /** RENDER_SURFACE_STATE when using image as a non render target. */
1587 struct anv_state nonrt_surface_state
;
1589 /** RENDER_SURFACE_STATE when using image as a storage image. */
1590 struct anv_state storage_surface_state
;
1593 struct anv_image_create_info
{
1594 const VkImageCreateInfo
*vk_info
;
1595 isl_tiling_flags_t isl_tiling_flags
;
1599 VkResult
anv_image_create(VkDevice _device
,
1600 const struct anv_image_create_info
*info
,
1601 const VkAllocationCallbacks
* alloc
,
1604 struct anv_surface
*
1605 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
,
1606 VkImageAspectFlags aspect_mask
);
1608 void anv_image_view_init(struct anv_image_view
*view
,
1609 struct anv_device
*device
,
1610 const VkImageViewCreateInfo
* pCreateInfo
,
1611 struct anv_cmd_buffer
*cmd_buffer
);
1614 anv_fill_image_surface_state(struct anv_device
*device
, struct anv_state state
,
1615 struct anv_image_view
*iview
,
1616 const VkImageViewCreateInfo
*pCreateInfo
,
1617 VkImageUsageFlagBits usage
);
1619 gen7_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1620 struct anv_image_view
*iview
,
1621 const VkImageViewCreateInfo
*pCreateInfo
,
1622 VkImageUsageFlagBits usage
);
1624 gen75_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1625 struct anv_image_view
*iview
,
1626 const VkImageViewCreateInfo
*pCreateInfo
,
1627 VkImageUsageFlagBits usage
);
1629 gen8_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1630 struct anv_image_view
*iview
,
1631 const VkImageViewCreateInfo
*pCreateInfo
,
1632 VkImageUsageFlagBits usage
);
1634 gen9_fill_image_surface_state(struct anv_device
*device
, void *state_map
,
1635 struct anv_image_view
*iview
,
1636 const VkImageViewCreateInfo
*pCreateInfo
,
1637 VkImageUsageFlagBits usage
);
1639 struct anv_buffer_view
{
1640 enum isl_format format
; /**< VkBufferViewCreateInfo::format */
1642 uint32_t offset
; /**< Offset into bo. */
1643 uint64_t range
; /**< VkBufferViewCreateInfo::range */
1645 struct anv_state surface_state
;
1646 struct anv_state storage_surface_state
;
1649 const struct anv_format
*
1650 anv_format_for_descriptor_type(VkDescriptorType type
);
1652 void anv_fill_buffer_surface_state(struct anv_device
*device
,
1653 struct anv_state state
,
1654 enum isl_format format
,
1655 uint32_t offset
, uint32_t range
,
1658 void gen7_fill_buffer_surface_state(void *state
, enum isl_format format
,
1659 uint32_t offset
, uint32_t range
,
1661 void gen75_fill_buffer_surface_state(void *state
, enum isl_format format
,
1662 uint32_t offset
, uint32_t range
,
1664 void gen8_fill_buffer_surface_state(void *state
, enum isl_format format
,
1665 uint32_t offset
, uint32_t range
,
1667 void gen9_fill_buffer_surface_state(void *state
, enum isl_format format
,
1668 uint32_t offset
, uint32_t range
,
1671 void anv_image_view_fill_image_param(struct anv_device
*device
,
1672 struct anv_image_view
*view
,
1673 struct brw_image_param
*param
);
1674 void anv_buffer_view_fill_image_param(struct anv_device
*device
,
1675 struct anv_buffer_view
*view
,
1676 struct brw_image_param
*param
);
1678 struct anv_sampler
{
1682 struct anv_framebuffer
{
1687 uint32_t attachment_count
;
1688 const struct anv_image_view
* attachments
[0];
1691 struct anv_subpass
{
1692 uint32_t input_count
;
1693 uint32_t * input_attachments
;
1694 uint32_t color_count
;
1695 uint32_t * color_attachments
;
1696 uint32_t * resolve_attachments
;
1697 uint32_t depth_stencil_attachment
;
1700 struct anv_render_pass_attachment
{
1701 const struct anv_format
*format
;
1703 VkAttachmentLoadOp load_op
;
1704 VkAttachmentLoadOp stencil_load_op
;
1707 struct anv_render_pass
{
1708 uint32_t attachment_count
;
1709 uint32_t subpass_count
;
1710 uint32_t * subpass_attachments
;
1711 struct anv_render_pass_attachment
* attachments
;
1712 struct anv_subpass subpasses
[0];
1715 extern struct anv_render_pass anv_meta_dummy_renderpass
;
1717 struct anv_query_pool_slot
{
1723 struct anv_query_pool
{
1729 VkResult
anv_device_init_meta(struct anv_device
*device
);
1730 void anv_device_finish_meta(struct anv_device
*device
);
1732 void *anv_lookup_entrypoint(const char *name
);
1734 void anv_dump_image_to_ppm(struct anv_device
*device
,
1735 struct anv_image
*image
, unsigned miplevel
,
1736 unsigned array_layer
, const char *filename
);
1738 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1740 static inline struct __anv_type * \
1741 __anv_type ## _from_handle(__VkType _handle) \
1743 return (struct __anv_type *) _handle; \
1746 static inline __VkType \
1747 __anv_type ## _to_handle(struct __anv_type *_obj) \
1749 return (__VkType) _obj; \
1752 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1754 static inline struct __anv_type * \
1755 __anv_type ## _from_handle(__VkType _handle) \
1757 return (struct __anv_type *)(uintptr_t) _handle; \
1760 static inline __VkType \
1761 __anv_type ## _to_handle(struct __anv_type *_obj) \
1763 return (__VkType)(uintptr_t) _obj; \
1766 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1767 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1769 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1770 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1771 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1772 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1773 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1775 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1776 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1777 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view
, VkBufferView
)
1778 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1779 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1780 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1781 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1782 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event
, VkEvent
)
1783 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1784 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1785 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1786 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache
, VkPipelineCache
)
1787 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1788 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1789 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1790 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1791 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1792 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1794 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1796 static inline const __VkType * \
1797 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1799 return (const __VkType *) __anv_obj; \
1802 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1803 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1805 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1806 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1807 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)