2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
38 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
43 #include "brw_device_info.h"
44 #include "util/macros.h"
45 #include "util/list.h"
47 /* Pre-declarations needed for WSI entrypoints */
50 typedef struct xcb_connection_t xcb_connection_t
;
51 typedef uint32_t xcb_visualid_t
;
52 typedef uint32_t xcb_window_t
;
54 #define VK_USE_PLATFORM_XCB_KHR
55 #define VK_USE_PLATFORM_WAYLAND_KHR
58 #include <vulkan/vulkan.h>
59 #include <vulkan/vulkan_intel.h>
61 #include "anv_entrypoints.h"
62 #include "anv_gen_macros.h"
63 #include "brw_context.h"
70 #define ICD_LOADER_MAGIC 0x01CDC0DE
72 typedef union _VK_LOADER_DATA
{
73 uintptr_t loaderMagic
;
77 #define anv_noreturn __attribute__((__noreturn__))
78 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
80 #define MIN(a, b) ((a) < (b) ? (a) : (b))
81 #define MAX(a, b) ((a) > (b) ? (a) : (b))
83 static inline uint32_t
84 align_u32(uint32_t v
, uint32_t a
)
86 return (v
+ a
- 1) & ~(a
- 1);
90 align_i32(int32_t v
, int32_t a
)
92 return (v
+ a
- 1) & ~(a
- 1);
95 /** Alignment must be a power of 2. */
97 anv_is_aligned(uintmax_t n
, uintmax_t a
)
99 assert(a
== (a
& -a
));
100 return (n
& (a
- 1)) == 0;
103 static inline uint32_t
104 anv_minify(uint32_t n
, uint32_t levels
)
106 if (unlikely(n
== 0))
109 return MAX(n
>> levels
, 1);
113 anv_clamp_f(float f
, float min
, float max
)
126 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
128 if (*inout_mask
& clear_mask
) {
129 *inout_mask
&= ~clear_mask
;
136 #define for_each_bit(b, dword) \
137 for (uint32_t __dword = (dword); \
138 (b) = __builtin_ffs(__dword) - 1, __dword; \
139 __dword &= ~(1 << (b)))
141 #define typed_memcpy(dest, src, count) ({ \
142 static_assert(sizeof(*src) == sizeof(*dest), ""); \
143 memcpy((dest), (src), (count) * sizeof(*(src))); \
146 /* Define no kernel as 1, since that's an illegal offset for a kernel */
150 VkStructureType sType
;
154 /* Whenever we generate an error, pass it through this function. Useful for
155 * debugging, where we can break on it. Only call at error site, not when
156 * propagating errors. Might be useful to plug in a stack trace here.
159 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
162 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
163 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
165 #define vk_error(error) error
166 #define vk_errorf(error, format, ...) error
169 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
170 anv_printflike(3, 4);
171 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
172 void anv_loge_v(const char *format
, va_list va
);
175 * Print a FINISHME message, including its source location.
177 #define anv_finishme(format, ...) \
178 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
180 /* A non-fatal assert. Useful for debugging. */
182 #define anv_assert(x) ({ \
183 if (unlikely(!(x))) \
184 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
187 #define anv_assert(x)
191 * If a block of code is annotated with anv_validate, then the block runs only
195 #define anv_validate if (1)
197 #define anv_validate if (0)
200 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
201 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
203 #define stub_return(v) \
205 anv_finishme("stub %s", __func__); \
211 anv_finishme("stub %s", __func__); \
216 * A dynamically growable, circular buffer. Elements are added at head and
217 * removed from tail. head and tail are free-running uint32_t indices and we
218 * only compute the modulo with size when accessing the array. This way,
219 * number of bytes in the queue is always head - tail, even in case of
226 uint32_t element_size
;
231 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
232 void *anv_vector_add(struct anv_vector
*queue
);
233 void *anv_vector_remove(struct anv_vector
*queue
);
236 anv_vector_length(struct anv_vector
*queue
)
238 return (queue
->head
- queue
->tail
) / queue
->element_size
;
242 anv_vector_head(struct anv_vector
*vector
)
244 assert(vector
->tail
< vector
->head
);
245 return (void *)((char *)vector
->data
+
246 ((vector
->head
- vector
->element_size
) &
247 (vector
->size
- 1)));
251 anv_vector_tail(struct anv_vector
*vector
)
253 return (void *)((char *)vector
->data
+ (vector
->tail
& (vector
->size
- 1)));
257 anv_vector_finish(struct anv_vector
*queue
)
262 #define anv_vector_foreach(elem, queue) \
263 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
264 for (uint32_t __anv_vector_offset = (queue)->tail; \
265 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
266 __anv_vector_offset += (queue)->element_size)
271 /* Index into the current validation list. This is used by the
272 * validation list building alrogithm to track which buffers are already
273 * in the validation list so that we can ensure uniqueness.
277 /* Last known offset. This value is provided by the kernel when we
278 * execbuf and is used as the presumed offset for the next bunch of
287 /* Represents a lock-free linked list of "free" things. This is used by
288 * both the block pool and the state pools. Unfortunately, in order to
289 * solve the ABA problem, we can't use a single uint32_t head.
291 union anv_free_list
{
295 /* A simple count that is incremented every time the head changes. */
301 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
303 struct anv_block_state
{
313 struct anv_block_pool
{
314 struct anv_device
*device
;
318 /* The offset from the start of the bo to the "center" of the block
319 * pool. Pointers to allocated blocks are given by
320 * bo.map + center_bo_offset + offsets.
322 uint32_t center_bo_offset
;
324 /* Current memory map of the block pool. This pointer may or may not
325 * point to the actual beginning of the block pool memory. If
326 * anv_block_pool_alloc_back has ever been called, then this pointer
327 * will point to the "center" position of the buffer and all offsets
328 * (negative or positive) given out by the block pool alloc functions
329 * will be valid relative to this pointer.
331 * In particular, map == bo.map + center_offset
337 * Array of mmaps and gem handles owned by the block pool, reclaimed when
338 * the block pool is destroyed.
340 struct anv_vector mmap_cleanups
;
344 union anv_free_list free_list
;
345 struct anv_block_state state
;
347 union anv_free_list back_free_list
;
348 struct anv_block_state back_state
;
351 /* Block pools are backed by a fixed-size 2GB memfd */
352 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
354 /* The center of the block pool is also the middle of the memfd. This may
355 * change in the future if we decide differently for some reason.
357 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
359 static inline uint32_t
360 anv_block_pool_size(struct anv_block_pool
*pool
)
362 return pool
->state
.end
+ pool
->back_state
.end
;
371 struct anv_fixed_size_state_pool
{
373 union anv_free_list free_list
;
374 struct anv_block_state block
;
377 #define ANV_MIN_STATE_SIZE_LOG2 6
378 #define ANV_MAX_STATE_SIZE_LOG2 10
380 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
382 struct anv_state_pool
{
383 struct anv_block_pool
*block_pool
;
384 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
387 struct anv_state_stream
{
388 struct anv_block_pool
*block_pool
;
390 uint32_t current_block
;
394 #define CACHELINE_SIZE 64
395 #define CACHELINE_MASK 63
398 anv_state_clflush(struct anv_state state
)
400 /* state.map may not be cacheline aligned, so round down the start pointer
401 * to a cacheline boundary so we flush all pages that contain the state.
403 void *end
= state
.map
+ state
.alloc_size
;
404 void *p
= (void *) (((uintptr_t) state
.map
) & ~CACHELINE_MASK
);
406 __builtin_ia32_sfence();
408 __builtin_ia32_clflush(p
);
413 void anv_block_pool_init(struct anv_block_pool
*pool
,
414 struct anv_device
*device
, uint32_t block_size
);
415 void anv_block_pool_finish(struct anv_block_pool
*pool
);
416 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
417 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
418 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
419 void anv_state_pool_init(struct anv_state_pool
*pool
,
420 struct anv_block_pool
*block_pool
);
421 void anv_state_pool_finish(struct anv_state_pool
*pool
);
422 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
423 size_t state_size
, size_t alignment
);
424 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
425 void anv_state_stream_init(struct anv_state_stream
*stream
,
426 struct anv_block_pool
*block_pool
);
427 void anv_state_stream_finish(struct anv_state_stream
*stream
);
428 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
429 uint32_t size
, uint32_t alignment
);
432 * Implements a pool of re-usable BOs. The interface is identical to that
433 * of block_pool except that each block is its own BO.
436 struct anv_device
*device
;
443 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
444 struct anv_device
*device
, uint32_t block_size
);
445 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
446 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
447 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
450 void *anv_resolve_entrypoint(uint32_t index
);
452 extern struct anv_dispatch_table dtable
;
454 #define ANV_CALL(func) ({ \
455 if (dtable.func == NULL) { \
456 size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
457 dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
463 anv_alloc(const VkAllocationCallbacks
*alloc
,
464 size_t size
, size_t align
,
465 VkSystemAllocationScope scope
)
467 return alloc
->pfnAllocation(alloc
->pUserData
, size
, align
, scope
);
471 anv_realloc(const VkAllocationCallbacks
*alloc
,
472 void *ptr
, size_t size
, size_t align
,
473 VkSystemAllocationScope scope
)
475 return alloc
->pfnReallocation(alloc
->pUserData
, ptr
, size
, align
, scope
);
479 anv_free(const VkAllocationCallbacks
*alloc
, void *data
)
481 alloc
->pfnFree(alloc
->pUserData
, data
);
485 anv_alloc2(const VkAllocationCallbacks
*parent_alloc
,
486 const VkAllocationCallbacks
*alloc
,
487 size_t size
, size_t align
,
488 VkSystemAllocationScope scope
)
491 return anv_alloc(alloc
, size
, align
, scope
);
493 return anv_alloc(parent_alloc
, size
, align
, scope
);
497 anv_free2(const VkAllocationCallbacks
*parent_alloc
,
498 const VkAllocationCallbacks
*alloc
,
502 anv_free(alloc
, data
);
504 anv_free(parent_alloc
, data
);
507 struct anv_physical_device
{
508 VK_LOADER_DATA _loader_data
;
510 struct anv_instance
* instance
;
514 const struct brw_device_info
* info
;
515 uint64_t aperture_size
;
516 struct brw_compiler
* compiler
;
517 struct isl_device isl_dev
;
520 struct anv_instance
{
521 VK_LOADER_DATA _loader_data
;
523 VkAllocationCallbacks alloc
;
526 int physicalDeviceCount
;
527 struct anv_physical_device physicalDevice
;
532 VkResult
anv_init_wsi(struct anv_instance
*instance
);
533 void anv_finish_wsi(struct anv_instance
*instance
);
535 struct anv_meta_state
{
537 struct anv_pipeline
*color_pipeline
;
538 struct anv_pipeline
*depth_only_pipeline
;
539 struct anv_pipeline
*stencil_only_pipeline
;
540 struct anv_pipeline
*depthstencil_pipeline
;
544 VkRenderPass render_pass
;
546 /** Pipeline that blits from a 2D image. */
547 VkPipeline pipeline_2d_src
;
549 /** Pipeline that blits from a 3D image. */
550 VkPipeline pipeline_3d_src
;
552 VkPipelineLayout pipeline_layout
;
553 VkDescriptorSetLayout ds_layout
;
558 VK_LOADER_DATA _loader_data
;
560 struct anv_device
* device
;
562 struct anv_state_pool
* pool
;
566 VK_LOADER_DATA _loader_data
;
568 VkAllocationCallbacks alloc
;
570 struct anv_instance
* instance
;
572 struct brw_device_info info
;
573 struct isl_device isl_dev
;
577 struct anv_bo_pool batch_bo_pool
;
579 struct anv_block_pool dynamic_state_block_pool
;
580 struct anv_state_pool dynamic_state_pool
;
582 struct anv_block_pool instruction_block_pool
;
583 struct anv_block_pool surface_state_block_pool
;
584 struct anv_state_pool surface_state_pool
;
586 struct anv_bo workaround_bo
;
588 struct anv_meta_state meta_state
;
590 struct anv_state border_colors
;
592 struct anv_queue queue
;
594 struct anv_block_pool scratch_block_pool
;
596 pthread_mutex_t mutex
;
599 void* anv_gem_mmap(struct anv_device
*device
,
600 uint32_t gem_handle
, uint64_t offset
, uint64_t size
, uint32_t flags
);
601 void anv_gem_munmap(void *p
, uint64_t size
);
602 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
603 void anv_gem_close(struct anv_device
*device
, uint32_t gem_handle
);
604 uint32_t anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
605 int anv_gem_wait(struct anv_device
*device
, uint32_t gem_handle
, int64_t *timeout_ns
);
606 int anv_gem_execbuffer(struct anv_device
*device
,
607 struct drm_i915_gem_execbuffer2
*execbuf
);
608 int anv_gem_set_tiling(struct anv_device
*device
, uint32_t gem_handle
,
609 uint32_t stride
, uint32_t tiling
);
610 int anv_gem_create_context(struct anv_device
*device
);
611 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
612 int anv_gem_get_param(int fd
, uint32_t param
);
613 int anv_gem_get_aperture(int fd
, uint64_t *size
);
614 int anv_gem_handle_to_fd(struct anv_device
*device
, uint32_t gem_handle
);
615 uint32_t anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
616 int anv_gem_set_caching(struct anv_device
*device
, uint32_t gem_handle
, uint32_t caching
);
617 int anv_gem_set_domain(struct anv_device
*device
, uint32_t gem_handle
,
618 uint32_t read_domains
, uint32_t write_domain
);
620 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
622 struct anv_reloc_list
{
625 struct drm_i915_gem_relocation_entry
* relocs
;
626 struct anv_bo
** reloc_bos
;
629 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
630 const VkAllocationCallbacks
*alloc
);
631 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
632 const VkAllocationCallbacks
*alloc
);
634 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
635 const VkAllocationCallbacks
*alloc
,
636 uint32_t offset
, struct anv_bo
*target_bo
,
639 struct anv_batch_bo
{
640 /* Link in the anv_cmd_buffer.owned_batch_bos list */
641 struct list_head link
;
645 /* Bytes actually consumed in this batch BO */
648 /* Last seen surface state block pool bo offset */
649 uint32_t last_ss_pool_bo_offset
;
651 struct anv_reloc_list relocs
;
655 const VkAllocationCallbacks
* alloc
;
661 struct anv_reloc_list
* relocs
;
663 /* This callback is called (with the associated user data) in the event
664 * that the batch runs out of space.
666 VkResult (*extend_cb
)(struct anv_batch
*, void *);
670 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
671 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
672 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
673 void *location
, struct anv_bo
*bo
, uint32_t offset
);
680 #define __gen_address_type struct anv_address
681 #define __gen_user_data struct anv_batch
683 static inline uint64_t
684 __gen_combine_address(struct anv_batch
*batch
, void *location
,
685 const struct anv_address address
, uint32_t delta
)
687 if (address
.bo
== NULL
) {
688 return address
.offset
+ delta
;
690 assert(batch
->start
<= location
&& location
< batch
->end
);
692 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
696 /* Wrapper macros needed to work around preprocessor argument issues. In
697 * particular, arguments don't get pre-evaluated if they are concatenated.
698 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
699 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
700 * We can work around this easily enough with these helpers.
702 #define __anv_cmd_length(cmd) cmd ## _length
703 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
704 #define __anv_cmd_header(cmd) cmd ## _header
705 #define __anv_cmd_pack(cmd) cmd ## _pack
707 #define anv_batch_emit(batch, cmd, ...) do { \
708 void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
709 struct cmd __template = { \
710 __anv_cmd_header(cmd), \
713 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
714 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, __anv_cmd_length(cmd) * 4)); \
717 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
718 void *__dst = anv_batch_emit_dwords(batch, n); \
719 struct cmd __template = { \
720 __anv_cmd_header(cmd), \
721 .DwordLength = n - __anv_cmd_length_bias(cmd), \
724 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
728 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
732 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
733 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
734 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
735 dw[i] = (dwords0)[i] | (dwords1)[i]; \
736 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
739 #define anv_state_pool_emit(pool, cmd, align, ...) ({ \
740 const uint32_t __size = __anv_cmd_length(cmd) * 4; \
741 struct anv_state __state = \
742 anv_state_pool_alloc((pool), __size, align); \
743 struct cmd __template = { \
746 __anv_cmd_pack(cmd)(NULL, __state.map, &__template); \
747 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__state.map, __anv_cmd_length(cmd) * 4)); \
748 if (!(pool)->block_pool->device->info.has_llc) \
749 anv_state_clflush(__state); \
753 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
754 .GraphicsDataTypeGFDT = 0, \
755 .LLCCacheabilityControlLLCCC = 0, \
756 .L3CacheabilityControlL3CC = 1, \
759 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
760 .LLCeLLCCacheabilityControlLLCCC = 0, \
761 .L3CacheabilityControlL3CC = 1, \
764 #define GEN8_MOCS { \
765 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
766 .TargetCache = L3DefertoPATforLLCeLLCselection, \
770 /* Skylake: MOCS is now an index into an array of 62 different caching
771 * configurations programmed by the kernel.
774 #define GEN9_MOCS { \
775 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
776 .IndextoMOCSTables = 2 \
779 #define GEN9_MOCS_PTE { \
780 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
781 .IndextoMOCSTables = 1 \
784 struct anv_device_memory
{
787 VkDeviceSize map_size
;
792 * Header for Vertex URB Entry (VUE)
794 struct anv_vue_header
{
796 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
797 uint32_t ViewportIndex
;
801 struct anv_descriptor_set_binding_layout
{
802 /* Number of array elements in this binding */
805 /* Index into the flattend descriptor set */
806 uint16_t descriptor_index
;
808 /* Index into the dynamic state array for a dynamic buffer */
809 int16_t dynamic_offset_index
;
812 /* Index into the binding table for the associated surface */
813 int16_t surface_index
;
815 /* Index into the sampler table for the associated sampler */
816 int16_t sampler_index
;
818 /* Index into the image table for the associated image */
820 } stage
[MESA_SHADER_STAGES
];
822 /* Immutable samplers (or NULL if no immutable samplers) */
823 struct anv_sampler
**immutable_samplers
;
826 struct anv_descriptor_set_layout
{
827 /* Number of bindings in this descriptor set */
828 uint16_t binding_count
;
830 /* Total size of the descriptor set with room for all array entries */
833 /* Shader stages affected by this descriptor set */
834 uint16_t shader_stages
;
836 /* Number of dynamic offsets used by this descriptor set */
837 uint16_t dynamic_offset_count
;
839 /* Bindings in this descriptor set */
840 struct anv_descriptor_set_binding_layout binding
[0];
843 struct anv_descriptor
{
844 VkDescriptorType type
;
849 struct anv_image_view
*image_view
;
851 struct anv_sampler
*sampler
;
855 struct anv_buffer
*buffer
;
862 struct anv_descriptor_set
{
863 const struct anv_descriptor_set_layout
*layout
;
864 struct anv_descriptor descriptors
[0];
868 anv_descriptor_set_create(struct anv_device
*device
,
869 const struct anv_descriptor_set_layout
*layout
,
870 struct anv_descriptor_set
**out_set
);
873 anv_descriptor_set_destroy(struct anv_device
*device
,
874 struct anv_descriptor_set
*set
);
879 #define MAX_VIEWPORTS 16
880 #define MAX_SCISSORS 16
881 #define MAX_PUSH_CONSTANTS_SIZE 128
882 #define MAX_DYNAMIC_BUFFERS 16
885 struct anv_pipeline_binding
{
886 /* The descriptor set this surface corresponds to */
889 /* Offset into the descriptor set */
893 struct anv_pipeline_layout
{
895 struct anv_descriptor_set_layout
*layout
;
896 uint32_t dynamic_offset_start
;
898 uint32_t surface_start
;
899 uint32_t sampler_start
;
900 uint32_t image_start
;
901 } stage
[MESA_SHADER_STAGES
];
907 bool has_dynamic_offsets
;
908 uint32_t surface_count
;
909 struct anv_pipeline_binding
*surface_to_descriptor
;
910 uint32_t sampler_count
;
911 struct anv_pipeline_binding
*sampler_to_descriptor
;
912 uint32_t image_count
;
913 } stage
[MESA_SHADER_STAGES
];
915 struct anv_pipeline_binding entries
[0];
919 struct anv_device
* device
;
927 enum anv_cmd_dirty_bits
{
928 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
929 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
930 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
931 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
932 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
933 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
934 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
935 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
936 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
937 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
938 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
939 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
940 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
942 typedef uint32_t anv_cmd_dirty_mask_t
;
944 struct anv_vertex_binding
{
945 struct anv_buffer
* buffer
;
949 struct anv_push_constants
{
950 /* Current allocated size of this push constants data structure.
951 * Because a decent chunk of it may not be used (images on SKL, for
952 * instance), we won't actually allocate the entire structure up-front.
956 /* Push constant data provided by the client through vkPushConstants */
957 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
959 /* Our hardware only provides zero-based vertex and instance id so, in
960 * order to satisfy the vulkan requirements, we may have to push one or
961 * both of these into the shader.
963 uint32_t base_vertex
;
964 uint32_t base_instance
;
966 /* Offsets and ranges for dynamically bound buffers */
970 } dynamic
[MAX_DYNAMIC_BUFFERS
];
972 /* Image data for image_load_store on pre-SKL */
973 struct brw_image_param images
[MAX_IMAGES
];
976 struct anv_dynamic_state
{
979 VkViewport viewports
[MAX_VIEWPORTS
];
984 VkRect2D scissors
[MAX_SCISSORS
];
995 float blend_constants
[4];
1005 } stencil_compare_mask
;
1010 } stencil_write_mask
;
1015 } stencil_reference
;
1018 extern const struct anv_dynamic_state default_dynamic_state
;
1020 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
1021 const struct anv_dynamic_state
*src
,
1022 uint32_t copy_mask
);
1024 /** State required while building cmd buffer */
1025 struct anv_cmd_state
{
1026 uint32_t current_pipeline
;
1028 anv_cmd_dirty_mask_t dirty
;
1029 anv_cmd_dirty_mask_t compute_dirty
;
1030 VkShaderStageFlags descriptors_dirty
;
1031 VkShaderStageFlags push_constants_dirty
;
1032 uint32_t scratch_size
;
1033 struct anv_pipeline
* pipeline
;
1034 struct anv_pipeline
* compute_pipeline
;
1035 struct anv_framebuffer
* framebuffer
;
1036 struct anv_render_pass
* pass
;
1037 struct anv_subpass
* subpass
;
1038 uint32_t restart_index
;
1039 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
1040 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
1041 struct anv_push_constants
* push_constants
[MESA_SHADER_STAGES
];
1042 struct anv_dynamic_state dynamic
;
1045 struct anv_buffer
* index_buffer
;
1046 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1047 uint32_t index_offset
;
1051 struct anv_cmd_pool
{
1052 VkAllocationCallbacks alloc
;
1053 struct list_head cmd_buffers
;
1056 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1058 enum anv_cmd_buffer_exec_mode
{
1059 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1060 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1061 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1062 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1065 struct anv_cmd_buffer
{
1066 VK_LOADER_DATA _loader_data
;
1068 struct anv_device
* device
;
1070 struct anv_cmd_pool
* pool
;
1071 struct list_head pool_link
;
1073 struct anv_batch batch
;
1075 /* Fields required for the actual chain of anv_batch_bo's.
1077 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1079 struct list_head batch_bos
;
1080 enum anv_cmd_buffer_exec_mode exec_mode
;
1082 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1083 * referenced by this command buffer
1085 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1087 struct anv_vector seen_bbos
;
1089 /* A vector of int32_t's for every block of binding tables.
1091 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1093 struct anv_vector bt_blocks
;
1095 struct anv_reloc_list surface_relocs
;
1097 /* Information needed for execbuf
1099 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1102 struct drm_i915_gem_execbuffer2 execbuf
;
1104 struct drm_i915_gem_exec_object2
* objects
;
1106 struct anv_bo
** bos
;
1108 /* Allocated length of the 'objects' and 'bos' arrays */
1109 uint32_t array_length
;
1114 /* Serial for tracking buffer completion */
1117 /* Stream objects for storing temporary data */
1118 struct anv_state_stream surface_state_stream
;
1119 struct anv_state_stream dynamic_state_stream
;
1121 VkCommandBufferUsageFlags usage_flags
;
1122 VkCommandBufferLevel level
;
1124 struct anv_cmd_state state
;
1127 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1128 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1129 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1130 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1131 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1132 struct anv_cmd_buffer
*secondary
);
1133 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1135 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1136 unsigned stage
, struct anv_state
*bt_state
);
1137 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1138 unsigned stage
, struct anv_state
*state
);
1139 void gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
1141 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1142 const void *data
, uint32_t size
, uint32_t alignment
);
1143 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1144 uint32_t *a
, uint32_t *b
,
1145 uint32_t dwords
, uint32_t alignment
);
1146 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1147 struct anv_subpass
*subpass
);
1150 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1152 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1153 uint32_t entries
, uint32_t *state_offset
);
1155 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1157 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1158 uint32_t size
, uint32_t alignment
);
1161 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1163 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1164 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1166 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1167 void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1168 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1169 void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1171 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1173 void gen7_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1174 struct anv_subpass
*subpass
);
1176 void gen8_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1177 struct anv_subpass
*subpass
);
1178 void gen9_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1179 struct anv_subpass
*subpass
);
1181 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1182 struct anv_subpass
*subpass
);
1185 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1186 gl_shader_stage stage
);
1188 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1189 struct anv_render_pass
*pass
,
1190 const VkClearValue
*clear_values
);
1191 const struct anv_image_view
*
1192 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1194 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1198 struct drm_i915_gem_execbuffer2 execbuf
;
1199 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1205 struct anv_shader_module
{
1206 struct nir_shader
* nir
;
1212 static inline gl_shader_stage
1213 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage
)
1215 assert(__builtin_popcount(vk_stage
) == 1);
1216 return ffs(vk_stage
) - 1;
1219 static inline VkShaderStageFlagBits
1220 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage
)
1222 return (1 << mesa_stage
);
1225 #define anv_foreach_stage(stage, stage_bits) \
1226 for (gl_shader_stage stage, __tmp = (gl_shader_stage)(stage_bits);\
1227 stage = __builtin_ffs(__tmp) - 1, __tmp; \
1228 __tmp &= ~(1 << (stage)))
1230 struct anv_pipeline
{
1231 struct anv_device
* device
;
1232 struct anv_batch batch
;
1233 uint32_t batch_data
[512];
1234 struct anv_reloc_list batch_relocs
;
1235 uint32_t dynamic_state_mask
;
1236 struct anv_dynamic_state dynamic_state
;
1238 struct anv_pipeline_layout
* layout
;
1241 struct brw_vs_prog_data vs_prog_data
;
1242 struct brw_wm_prog_data wm_prog_data
;
1243 struct brw_gs_prog_data gs_prog_data
;
1244 struct brw_cs_prog_data cs_prog_data
;
1245 bool writes_point_size
;
1246 struct brw_stage_prog_data
* prog_data
[MESA_SHADER_STAGES
];
1247 uint32_t scratch_start
[MESA_SHADER_STAGES
];
1248 uint32_t total_scratch
;
1252 uint32_t nr_vs_entries
;
1255 uint32_t nr_gs_entries
;
1258 VkShaderStageFlags active_stages
;
1259 struct anv_state_stream program_stream
;
1260 struct anv_state blend_state
;
1267 uint32_t ps_grf_start0
;
1268 uint32_t ps_grf_start2
;
1270 uint32_t gs_vertex_count
;
1274 uint32_t binding_stride
[MAX_VBS
];
1275 bool instancing_enable
[MAX_VBS
];
1276 bool primitive_restart
;
1279 uint32_t cs_thread_width_max
;
1280 uint32_t cs_right_mask
;
1284 uint32_t depth_stencil_state
[3];
1290 uint32_t wm_depth_stencil
[3];
1294 uint32_t wm_depth_stencil
[4];
1298 struct anv_graphics_pipeline_create_info
{
1300 bool disable_viewport
;
1301 bool disable_scissor
;
1307 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1308 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1309 const struct anv_graphics_pipeline_create_info
*extra
,
1310 const VkAllocationCallbacks
*alloc
);
1313 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1314 const VkComputePipelineCreateInfo
*info
,
1315 struct anv_shader_module
*module
,
1316 const char *entrypoint_name
);
1319 anv_graphics_pipeline_create(VkDevice device
,
1320 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1321 const struct anv_graphics_pipeline_create_info
*extra
,
1322 const VkAllocationCallbacks
*alloc
,
1323 VkPipeline
*pPipeline
);
1326 gen7_graphics_pipeline_create(VkDevice _device
,
1327 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1328 const struct anv_graphics_pipeline_create_info
*extra
,
1329 const VkAllocationCallbacks
*alloc
,
1330 VkPipeline
*pPipeline
);
1333 gen75_graphics_pipeline_create(VkDevice _device
,
1334 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1335 const struct anv_graphics_pipeline_create_info
*extra
,
1336 const VkAllocationCallbacks
*alloc
,
1337 VkPipeline
*pPipeline
);
1340 gen8_graphics_pipeline_create(VkDevice _device
,
1341 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1342 const struct anv_graphics_pipeline_create_info
*extra
,
1343 const VkAllocationCallbacks
*alloc
,
1344 VkPipeline
*pPipeline
);
1346 gen9_graphics_pipeline_create(VkDevice _device
,
1347 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1348 const struct anv_graphics_pipeline_create_info
*extra
,
1349 const VkAllocationCallbacks
*alloc
,
1350 VkPipeline
*pPipeline
);
1352 gen7_compute_pipeline_create(VkDevice _device
,
1353 const VkComputePipelineCreateInfo
*pCreateInfo
,
1354 const VkAllocationCallbacks
*alloc
,
1355 VkPipeline
*pPipeline
);
1357 gen75_compute_pipeline_create(VkDevice _device
,
1358 const VkComputePipelineCreateInfo
*pCreateInfo
,
1359 const VkAllocationCallbacks
*alloc
,
1360 VkPipeline
*pPipeline
);
1363 gen8_compute_pipeline_create(VkDevice _device
,
1364 const VkComputePipelineCreateInfo
*pCreateInfo
,
1365 const VkAllocationCallbacks
*alloc
,
1366 VkPipeline
*pPipeline
);
1368 gen9_compute_pipeline_create(VkDevice _device
,
1369 const VkComputePipelineCreateInfo
*pCreateInfo
,
1370 const VkAllocationCallbacks
*alloc
,
1371 VkPipeline
*pPipeline
);
1374 const VkFormat vk_format
;
1376 enum isl_format surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
1377 const struct isl_format_layout
*isl_layout
;
1378 uint8_t num_channels
;
1379 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1383 const struct anv_format
*
1384 anv_format_for_vk_format(VkFormat format
);
1387 anv_get_isl_format(VkFormat format
, VkImageAspectFlags aspect
);
1390 anv_format_is_color(const struct anv_format
*format
)
1392 return !format
->depth_format
&& !format
->has_stencil
;
1396 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
1398 return format
->depth_format
|| format
->has_stencil
;
1401 struct anv_image_view_info
{
1402 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
1403 bool is_array
:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
1404 bool is_cube
:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
1407 struct anv_image_view_info
1408 anv_image_view_info_for_vk_image_view_type(VkImageViewType type
);
1411 * Subsurface of an anv_image.
1413 struct anv_surface
{
1414 struct isl_surf isl
;
1417 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1424 const struct anv_format
*format
;
1427 uint32_t array_size
;
1428 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1433 /* Set when bound */
1435 VkDeviceSize offset
;
1437 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
1439 bool needs_nonrt_surface_state
:1;
1440 bool needs_color_rt_surface_state
:1;
1441 bool needs_storage_surface_state
:1;
1446 * For each foo, anv_image::foo_surface is valid if and only if
1447 * anv_image::format has a foo aspect.
1449 * The hardware requires that the depth buffer and stencil buffer be
1450 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1451 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1452 * allocate the depth and stencil buffers as separate surfaces in the same
1456 struct anv_surface color_surface
;
1459 struct anv_surface depth_surface
;
1460 struct anv_surface stencil_surface
;
1465 struct anv_image_view
{
1466 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1467 const struct anv_format
*format
; /**< VkImageViewCreateInfo::format */
1469 uint32_t offset
; /**< Offset into bo. */
1470 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1472 /** RENDER_SURFACE_STATE when using image as a color render target. */
1473 struct anv_state color_rt_surface_state
;
1475 /** RENDER_SURFACE_STATE when using image as a non render target. */
1476 struct anv_state nonrt_surface_state
;
1478 /** RENDER_SURFACE_STATE when using image as a storage image. */
1479 struct anv_state storage_surface_state
;
1482 struct anv_image_create_info
{
1483 const VkImageCreateInfo
*vk_info
;
1484 isl_tiling_flags_t isl_tiling_flags
;
1488 VkResult
anv_image_create(VkDevice _device
,
1489 const struct anv_image_create_info
*info
,
1490 const VkAllocationCallbacks
* alloc
,
1493 struct anv_surface
*
1494 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
,
1495 VkImageAspectFlags aspect_mask
);
1497 void anv_image_view_init(struct anv_image_view
*view
,
1498 struct anv_device
*device
,
1499 const VkImageViewCreateInfo
* pCreateInfo
,
1500 struct anv_cmd_buffer
*cmd_buffer
);
1503 gen7_image_view_init(struct anv_image_view
*iview
,
1504 struct anv_device
*device
,
1505 const VkImageViewCreateInfo
* pCreateInfo
,
1506 struct anv_cmd_buffer
*cmd_buffer
);
1509 gen75_image_view_init(struct anv_image_view
*iview
,
1510 struct anv_device
*device
,
1511 const VkImageViewCreateInfo
* pCreateInfo
,
1512 struct anv_cmd_buffer
*cmd_buffer
);
1515 gen8_image_view_init(struct anv_image_view
*iview
,
1516 struct anv_device
*device
,
1517 const VkImageViewCreateInfo
* pCreateInfo
,
1518 struct anv_cmd_buffer
*cmd_buffer
);
1521 gen9_image_view_init(struct anv_image_view
*iview
,
1522 struct anv_device
*device
,
1523 const VkImageViewCreateInfo
* pCreateInfo
,
1524 struct anv_cmd_buffer
*cmd_buffer
);
1526 void anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1527 const struct anv_format
*format
,
1528 uint32_t offset
, uint32_t range
,
1531 void gen7_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1532 uint32_t offset
, uint32_t range
,
1534 void gen75_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1535 uint32_t offset
, uint32_t range
,
1537 void gen8_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1538 uint32_t offset
, uint32_t range
,
1540 void gen9_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1541 uint32_t offset
, uint32_t range
,
1544 void anv_image_view_fill_image_param(struct anv_device
*device
,
1545 struct anv_image_view
*view
,
1546 struct brw_image_param
*param
);
1548 struct anv_sampler
{
1552 struct anv_framebuffer
{
1557 uint32_t attachment_count
;
1558 const struct anv_image_view
* attachments
[0];
1561 struct anv_subpass
{
1562 uint32_t input_count
;
1563 uint32_t * input_attachments
;
1564 uint32_t color_count
;
1565 uint32_t * color_attachments
;
1566 uint32_t * resolve_attachments
;
1567 uint32_t depth_stencil_attachment
;
1570 struct anv_render_pass_attachment
{
1571 const struct anv_format
*format
;
1573 VkAttachmentLoadOp load_op
;
1574 VkAttachmentLoadOp stencil_load_op
;
1577 struct anv_render_pass
{
1578 uint32_t attachment_count
;
1579 uint32_t subpass_count
;
1580 struct anv_render_pass_attachment
* attachments
;
1581 struct anv_subpass subpasses
[0];
1584 extern struct anv_render_pass anv_meta_dummy_renderpass
;
1586 struct anv_query_pool_slot
{
1592 struct anv_query_pool
{
1598 void anv_device_init_meta(struct anv_device
*device
);
1599 void anv_device_finish_meta(struct anv_device
*device
);
1601 void *anv_lookup_entrypoint(const char *name
);
1603 void anv_dump_image_to_ppm(struct anv_device
*device
,
1604 struct anv_image
*image
, unsigned miplevel
,
1605 unsigned array_layer
, const char *filename
);
1607 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1609 static inline struct __anv_type * \
1610 __anv_type ## _from_handle(__VkType _handle) \
1612 return (struct __anv_type *) _handle; \
1615 static inline __VkType \
1616 __anv_type ## _to_handle(struct __anv_type *_obj) \
1618 return (__VkType) _obj; \
1621 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1623 static inline struct __anv_type * \
1624 __anv_type ## _from_handle(__VkType _handle) \
1626 return (struct __anv_type *)(uintptr_t) _handle; \
1629 static inline __VkType \
1630 __anv_type ## _to_handle(struct __anv_type *_obj) \
1632 return (__VkType)(uintptr_t) _obj; \
1635 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1636 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1638 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1639 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1640 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1641 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1642 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1644 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1645 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1646 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1647 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1648 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1649 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1650 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1651 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1652 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1653 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1654 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1655 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1656 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1657 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1658 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1660 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1662 static inline const __VkType * \
1663 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1665 return (const __VkType *) __anv_obj; \
1668 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1669 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1671 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1672 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1673 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)