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
37 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
42 #include "brw_device_info.h"
43 #include "util/macros.h"
44 #include "util/list.h"
47 #include <vulkan/vulkan.h>
48 #include <vulkan/vulkan_intel.h>
49 #include <vulkan/vk_ext_khr_swapchain.h>
50 #include <vulkan/vk_ext_khr_device_swapchain.h>
52 #include "anv_entrypoints.h"
53 #include "anv_gen_macros.h"
54 #include "brw_context.h"
61 #define ICD_LOADER_MAGIC 0x01CDC0DE
63 typedef union _VK_LOADER_DATA
{
64 uintptr_t loaderMagic
;
68 #define anv_noreturn __attribute__((__noreturn__))
69 #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
71 #define MIN(a, b) ((a) < (b) ? (a) : (b))
72 #define MAX(a, b) ((a) > (b) ? (a) : (b))
74 static inline uint32_t
75 align_u32(uint32_t v
, uint32_t a
)
77 return (v
+ a
- 1) & ~(a
- 1);
81 align_i32(int32_t v
, int32_t a
)
83 return (v
+ a
- 1) & ~(a
- 1);
86 /** Alignment must be a power of 2. */
88 anv_is_aligned(uintmax_t n
, uintmax_t a
)
90 assert(a
== (a
& -a
));
91 return (n
& (a
- 1)) == 0;
94 static inline uint32_t
95 anv_minify(uint32_t n
, uint32_t levels
)
100 return MAX(n
>> levels
, 1);
104 anv_clamp_f(float f
, float min
, float max
)
117 anv_clear_mask(uint32_t *inout_mask
, uint32_t clear_mask
)
119 if (*inout_mask
& clear_mask
) {
120 *inout_mask
&= ~clear_mask
;
127 #define for_each_bit(b, dword) \
128 for (uint32_t __dword = (dword); \
129 (b) = __builtin_ffs(__dword) - 1, __dword; \
130 __dword &= ~(1 << (b)))
132 #define typed_memcpy(dest, src, count) ({ \
133 static_assert(sizeof(*src) == sizeof(*dest), ""); \
134 memcpy((dest), (src), (count) * sizeof(*(src))); \
137 /* Define no kernel as 1, since that's an illegal offset for a kernel */
141 VkStructureType sType
;
145 /* Whenever we generate an error, pass it through this function. Useful for
146 * debugging, where we can break on it. Only call at error site, not when
147 * propagating errors. Might be useful to plug in a stack trace here.
150 VkResult
__vk_errorf(VkResult error
, const char *file
, int line
, const char *format
, ...);
153 #define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
154 #define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
156 #define vk_error(error) error
157 #define vk_errorf(error, format, ...) error
160 void __anv_finishme(const char *file
, int line
, const char *format
, ...)
161 anv_printflike(3, 4);
162 void anv_loge(const char *format
, ...) anv_printflike(1, 2);
163 void anv_loge_v(const char *format
, va_list va
);
166 * Print a FINISHME message, including its source location.
168 #define anv_finishme(format, ...) \
169 __anv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__);
171 /* A non-fatal assert. Useful for debugging. */
173 #define anv_assert(x) ({ \
174 if (unlikely(!(x))) \
175 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
178 #define anv_assert(x)
182 * If a block of code is annotated with anv_validate, then the block runs only
186 #define anv_validate if (1)
188 #define anv_validate if (0)
191 void anv_abortf(const char *format
, ...) anv_noreturn
anv_printflike(1, 2);
192 void anv_abortfv(const char *format
, va_list va
) anv_noreturn
;
194 #define stub_return(v) \
196 anv_finishme("stub %s", __func__); \
202 anv_finishme("stub %s", __func__); \
207 * A dynamically growable, circular buffer. Elements are added at head and
208 * removed from tail. head and tail are free-running uint32_t indices and we
209 * only compute the modulo with size when accessing the array. This way,
210 * number of bytes in the queue is always head - tail, even in case of
217 uint32_t element_size
;
222 int anv_vector_init(struct anv_vector
*queue
, uint32_t element_size
, uint32_t size
);
223 void *anv_vector_add(struct anv_vector
*queue
);
224 void *anv_vector_remove(struct anv_vector
*queue
);
227 anv_vector_length(struct anv_vector
*queue
)
229 return (queue
->head
- queue
->tail
) / queue
->element_size
;
233 anv_vector_head(struct anv_vector
*vector
)
235 assert(vector
->tail
< vector
->head
);
236 return (void *)((char *)vector
->data
+
237 ((vector
->head
- vector
->element_size
) &
238 (vector
->size
- 1)));
242 anv_vector_tail(struct anv_vector
*vector
)
244 return (void *)((char *)vector
->data
+ (vector
->tail
& (vector
->size
- 1)));
248 anv_vector_finish(struct anv_vector
*queue
)
253 #define anv_vector_foreach(elem, queue) \
254 static_assert(__builtin_types_compatible_p(__typeof__(queue), struct anv_vector *), ""); \
255 for (uint32_t __anv_vector_offset = (queue)->tail; \
256 elem = (queue)->data + (__anv_vector_offset & ((queue)->size - 1)), __anv_vector_offset < (queue)->head; \
257 __anv_vector_offset += (queue)->element_size)
262 /* Index into the current validation list. This is used by the
263 * validation list building alrogithm to track which buffers are already
264 * in the validation list so that we can ensure uniqueness.
268 /* Last known offset. This value is provided by the kernel when we
269 * execbuf and is used as the presumed offset for the next bunch of
278 /* Represents a lock-free linked list of "free" things. This is used by
279 * both the block pool and the state pools. Unfortunately, in order to
280 * solve the ABA problem, we can't use a single uint32_t head.
282 union anv_free_list
{
286 /* A simple count that is incremented every time the head changes. */
292 #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
294 struct anv_block_state
{
304 struct anv_block_pool
{
305 struct anv_device
*device
;
309 /* The offset from the start of the bo to the "center" of the block
310 * pool. Pointers to allocated blocks are given by
311 * bo.map + center_bo_offset + offsets.
313 uint32_t center_bo_offset
;
315 /* Current memory map of the block pool. This pointer may or may not
316 * point to the actual beginning of the block pool memory. If
317 * anv_block_pool_alloc_back has ever been called, then this pointer
318 * will point to the "center" position of the buffer and all offsets
319 * (negative or positive) given out by the block pool alloc functions
320 * will be valid relative to this pointer.
322 * In particular, map == bo.map + center_offset
328 * Array of mmaps and gem handles owned by the block pool, reclaimed when
329 * the block pool is destroyed.
331 struct anv_vector mmap_cleanups
;
335 union anv_free_list free_list
;
336 struct anv_block_state state
;
338 union anv_free_list back_free_list
;
339 struct anv_block_state back_state
;
342 /* Block pools are backed by a fixed-size 2GB memfd */
343 #define BLOCK_POOL_MEMFD_SIZE (1ull << 32)
345 /* The center of the block pool is also the middle of the memfd. This may
346 * change in the future if we decide differently for some reason.
348 #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
350 static inline uint32_t
351 anv_block_pool_size(struct anv_block_pool
*pool
)
353 return pool
->state
.end
+ pool
->back_state
.end
;
362 struct anv_fixed_size_state_pool
{
364 union anv_free_list free_list
;
365 struct anv_block_state block
;
368 #define ANV_MIN_STATE_SIZE_LOG2 6
369 #define ANV_MAX_STATE_SIZE_LOG2 10
371 #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2)
373 struct anv_state_pool
{
374 struct anv_block_pool
*block_pool
;
375 struct anv_fixed_size_state_pool buckets
[ANV_STATE_BUCKETS
];
378 struct anv_state_stream
{
379 struct anv_block_pool
*block_pool
;
381 uint32_t current_block
;
385 void anv_block_pool_init(struct anv_block_pool
*pool
,
386 struct anv_device
*device
, uint32_t block_size
);
387 void anv_block_pool_finish(struct anv_block_pool
*pool
);
388 int32_t anv_block_pool_alloc(struct anv_block_pool
*pool
);
389 int32_t anv_block_pool_alloc_back(struct anv_block_pool
*pool
);
390 void anv_block_pool_free(struct anv_block_pool
*pool
, int32_t offset
);
391 void anv_state_pool_init(struct anv_state_pool
*pool
,
392 struct anv_block_pool
*block_pool
);
393 void anv_state_pool_finish(struct anv_state_pool
*pool
);
394 struct anv_state
anv_state_pool_alloc(struct anv_state_pool
*pool
,
395 size_t state_size
, size_t alignment
);
396 void anv_state_pool_free(struct anv_state_pool
*pool
, struct anv_state state
);
397 void anv_state_stream_init(struct anv_state_stream
*stream
,
398 struct anv_block_pool
*block_pool
);
399 void anv_state_stream_finish(struct anv_state_stream
*stream
);
400 struct anv_state
anv_state_stream_alloc(struct anv_state_stream
*stream
,
401 uint32_t size
, uint32_t alignment
);
404 * Implements a pool of re-usable BOs. The interface is identical to that
405 * of block_pool except that each block is its own BO.
408 struct anv_device
*device
;
415 void anv_bo_pool_init(struct anv_bo_pool
*pool
,
416 struct anv_device
*device
, uint32_t block_size
);
417 void anv_bo_pool_finish(struct anv_bo_pool
*pool
);
418 VkResult
anv_bo_pool_alloc(struct anv_bo_pool
*pool
, struct anv_bo
*bo
);
419 void anv_bo_pool_free(struct anv_bo_pool
*pool
, const struct anv_bo
*bo
);
422 void *anv_resolve_entrypoint(uint32_t index
);
424 extern struct anv_dispatch_table dtable
;
426 #define ANV_CALL(func) ({ \
427 if (dtable.func == NULL) { \
428 size_t idx = offsetof(struct anv_dispatch_table, func) / sizeof(void *); \
429 dtable.entrypoints[idx] = anv_resolve_entrypoint(idx); \
435 anv_alloc(const VkAllocationCallbacks
*alloc
,
436 size_t size
, size_t align
,
437 VkSystemAllocationScope scope
)
439 return alloc
->pfnAllocation(alloc
->pUserData
, size
, align
, scope
);
443 anv_realloc(const VkAllocationCallbacks
*alloc
,
444 void *ptr
, size_t size
, size_t align
,
445 VkSystemAllocationScope scope
)
447 return alloc
->pfnReallocation(alloc
->pUserData
, ptr
, size
, align
, scope
);
451 anv_free(const VkAllocationCallbacks
*alloc
, void *data
)
453 alloc
->pfnFree(alloc
->pUserData
, data
);
457 anv_alloc2(const VkAllocationCallbacks
*parent_alloc
,
458 const VkAllocationCallbacks
*alloc
,
459 size_t size
, size_t align
,
460 VkSystemAllocationScope scope
)
463 return anv_alloc(alloc
, size
, align
, scope
);
465 return anv_alloc(parent_alloc
, size
, align
, scope
);
469 anv_free2(const VkAllocationCallbacks
*parent_alloc
,
470 const VkAllocationCallbacks
*alloc
,
474 anv_free(alloc
, data
);
476 anv_free(parent_alloc
, data
);
479 struct anv_physical_device
{
480 VK_LOADER_DATA _loader_data
;
482 struct anv_instance
* instance
;
486 const struct brw_device_info
* info
;
487 uint64_t aperture_size
;
488 struct brw_compiler
* compiler
;
489 struct isl_device isl_dev
;
492 bool anv_is_scalar_shader_stage(const struct brw_compiler
*compiler
,
493 VkShaderStage stage
);
495 struct anv_instance
{
496 VK_LOADER_DATA _loader_data
;
498 VkAllocationCallbacks alloc
;
501 int physicalDeviceCount
;
502 struct anv_physical_device physicalDevice
;
504 struct anv_wsi_implementation
* wsi_impl
[VK_PLATFORM_NUM_KHR
];
507 VkResult
anv_init_wsi(struct anv_instance
*instance
);
508 void anv_finish_wsi(struct anv_instance
*instance
);
510 struct anv_meta_state
{
512 struct anv_pipeline
*color_pipeline
;
513 struct anv_pipeline
*depth_only_pipeline
;
514 struct anv_pipeline
*stencil_only_pipeline
;
515 struct anv_pipeline
*depthstencil_pipeline
;
519 VkRenderPass render_pass
;
521 /** Pipeline that blits from a 2D image. */
522 VkPipeline pipeline_2d_src
;
524 /** Pipeline that blits from a 3D image. */
525 VkPipeline pipeline_3d_src
;
527 VkPipelineLayout pipeline_layout
;
528 VkDescriptorSetLayout ds_layout
;
533 VK_LOADER_DATA _loader_data
;
535 struct anv_device
* device
;
537 struct anv_state_pool
* pool
;
541 VK_LOADER_DATA _loader_data
;
543 VkAllocationCallbacks alloc
;
545 struct anv_instance
* instance
;
547 struct brw_device_info info
;
548 struct isl_device isl_dev
;
552 struct anv_bo_pool batch_bo_pool
;
554 struct anv_block_pool dynamic_state_block_pool
;
555 struct anv_state_pool dynamic_state_pool
;
557 struct anv_block_pool instruction_block_pool
;
558 struct anv_block_pool surface_state_block_pool
;
559 struct anv_state_pool surface_state_pool
;
561 struct anv_bo workaround_bo
;
563 struct anv_meta_state meta_state
;
565 struct anv_state border_colors
;
567 struct anv_queue queue
;
569 struct anv_block_pool scratch_block_pool
;
571 pthread_mutex_t mutex
;
574 void* anv_gem_mmap(struct anv_device
*device
,
575 uint32_t gem_handle
, uint64_t offset
, uint64_t size
);
576 void anv_gem_munmap(void *p
, uint64_t size
);
577 uint32_t anv_gem_create(struct anv_device
*device
, size_t size
);
578 void anv_gem_close(struct anv_device
*device
, int gem_handle
);
579 int anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
580 int anv_gem_wait(struct anv_device
*device
, int gem_handle
, int64_t *timeout_ns
);
581 int anv_gem_execbuffer(struct anv_device
*device
,
582 struct drm_i915_gem_execbuffer2
*execbuf
);
583 int anv_gem_set_tiling(struct anv_device
*device
, int gem_handle
,
584 uint32_t stride
, uint32_t tiling
);
585 int anv_gem_create_context(struct anv_device
*device
);
586 int anv_gem_destroy_context(struct anv_device
*device
, int context
);
587 int anv_gem_get_param(int fd
, uint32_t param
);
588 int anv_gem_get_aperture(int fd
, uint64_t *size
);
589 int anv_gem_handle_to_fd(struct anv_device
*device
, int gem_handle
);
590 int anv_gem_fd_to_handle(struct anv_device
*device
, int fd
);
591 int anv_gem_userptr(struct anv_device
*device
, void *mem
, size_t size
);
593 VkResult
anv_bo_init_new(struct anv_bo
*bo
, struct anv_device
*device
, uint64_t size
);
595 struct anv_reloc_list
{
598 struct drm_i915_gem_relocation_entry
* relocs
;
599 struct anv_bo
** reloc_bos
;
602 VkResult
anv_reloc_list_init(struct anv_reloc_list
*list
,
603 const VkAllocationCallbacks
*alloc
);
604 void anv_reloc_list_finish(struct anv_reloc_list
*list
,
605 const VkAllocationCallbacks
*alloc
);
607 uint64_t anv_reloc_list_add(struct anv_reloc_list
*list
,
608 const VkAllocationCallbacks
*alloc
,
609 uint32_t offset
, struct anv_bo
*target_bo
,
612 struct anv_batch_bo
{
613 /* Link in the anv_cmd_buffer.owned_batch_bos list */
614 struct list_head link
;
618 /* Bytes actually consumed in this batch BO */
621 /* Last seen surface state block pool bo offset */
622 uint32_t last_ss_pool_bo_offset
;
624 struct anv_reloc_list relocs
;
628 const VkAllocationCallbacks
* alloc
;
634 struct anv_reloc_list
* relocs
;
636 /* This callback is called (with the associated user data) in the event
637 * that the batch runs out of space.
639 VkResult (*extend_cb
)(struct anv_batch
*, void *);
643 void *anv_batch_emit_dwords(struct anv_batch
*batch
, int num_dwords
);
644 void anv_batch_emit_batch(struct anv_batch
*batch
, struct anv_batch
*other
);
645 uint64_t anv_batch_emit_reloc(struct anv_batch
*batch
,
646 void *location
, struct anv_bo
*bo
, uint32_t offset
);
653 #define __gen_address_type struct anv_address
654 #define __gen_user_data struct anv_batch
656 static inline uint64_t
657 __gen_combine_address(struct anv_batch
*batch
, void *location
,
658 const struct anv_address address
, uint32_t delta
)
660 if (address
.bo
== NULL
) {
661 return address
.offset
+ delta
;
663 assert(batch
->start
<= location
&& location
< batch
->end
);
665 return anv_batch_emit_reloc(batch
, location
, address
.bo
, address
.offset
+ delta
);
669 /* Wrapper macros needed to work around preprocessor argument issues. In
670 * particular, arguments don't get pre-evaluated if they are concatenated.
671 * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
672 * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
673 * We can work around this easily enough with these helpers.
675 #define __anv_cmd_length(cmd) cmd ## _length
676 #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
677 #define __anv_cmd_header(cmd) cmd ## _header
678 #define __anv_cmd_pack(cmd) cmd ## _pack
680 #define anv_batch_emit(batch, cmd, ...) do { \
681 void *__dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
682 struct cmd __template = { \
683 __anv_cmd_header(cmd), \
686 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
687 VG(VALGRIND_CHECK_MEM_IS_DEFINED(__dst, __anv_cmd_length(cmd) * 4)); \
690 #define anv_batch_emitn(batch, n, cmd, ...) ({ \
691 void *__dst = anv_batch_emit_dwords(batch, n); \
692 struct cmd __template = { \
693 __anv_cmd_header(cmd), \
694 .DwordLength = n - __anv_cmd_length_bias(cmd), \
697 __anv_cmd_pack(cmd)(batch, __dst, &__template); \
701 #define anv_batch_emit_merge(batch, dwords0, dwords1) \
705 static_assert(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1), "mismatch merge"); \
706 dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
707 for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
708 dw[i] = (dwords0)[i] | (dwords1)[i]; \
709 VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
712 #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
713 .GraphicsDataTypeGFDT = 0, \
714 .LLCCacheabilityControlLLCCC = 0, \
715 .L3CacheabilityControlL3CC = 1, \
718 #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
719 .LLCeLLCCacheabilityControlLLCCC = 0, \
720 .L3CacheabilityControlL3CC = 1, \
723 #define GEN8_MOCS { \
724 .MemoryTypeLLCeLLCCacheabilityControl = WB, \
725 .TargetCache = L3DefertoPATforLLCeLLCselection, \
729 /* Skylake: MOCS is now an index into an array of 62 different caching
730 * configurations programmed by the kernel.
733 #define GEN9_MOCS { \
734 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
735 .IndextoMOCSTables = 2 \
738 #define GEN9_MOCS_PTE { \
739 /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
740 .IndextoMOCSTables = 1 \
743 struct anv_device_memory
{
745 VkDeviceSize map_size
;
750 * Header for Vertex URB Entry (VUE)
752 struct anv_vue_header
{
754 uint32_t RTAIndex
; /* RenderTargetArrayIndex */
755 uint32_t ViewportIndex
;
759 struct anv_descriptor_set_binding_layout
{
760 /* Number of array elements in this binding */
763 /* Index into the flattend descriptor set */
764 uint16_t descriptor_index
;
766 /* Index into the dynamic state array for a dynamic buffer */
767 int16_t dynamic_offset_index
;
770 /* Index into the binding table for the associated surface */
771 int16_t surface_index
;
773 /* Index into the sampler table for the associated sampler */
774 int16_t sampler_index
;
775 } stage
[VK_SHADER_STAGE_NUM
];
777 /* Immutable samplers (or NULL if no immutable samplers) */
778 struct anv_sampler
**immutable_samplers
;
781 struct anv_descriptor_set_layout
{
782 /* Number of bindings in this descriptor set */
783 uint16_t binding_count
;
785 /* Total size of the descriptor set with room for all array entries */
788 /* Shader stages affected by this descriptor set */
789 uint16_t shader_stages
;
791 /* Number of dynamic offsets used by this descriptor set */
792 uint16_t dynamic_offset_count
;
794 /* Bindings in this descriptor set */
795 struct anv_descriptor_set_binding_layout binding
[0];
798 struct anv_descriptor
{
799 VkDescriptorType type
;
804 struct anv_image_view
*image_view
;
806 struct anv_sampler
*sampler
;
810 struct anv_buffer
*buffer
;
817 struct anv_descriptor_set
{
818 const struct anv_descriptor_set_layout
*layout
;
819 struct anv_descriptor descriptors
[0];
823 anv_descriptor_set_create(struct anv_device
*device
,
824 const struct anv_descriptor_set_layout
*layout
,
825 struct anv_descriptor_set
**out_set
);
828 anv_descriptor_set_destroy(struct anv_device
*device
,
829 struct anv_descriptor_set
*set
);
834 #define MAX_VIEWPORTS 16
835 #define MAX_SCISSORS 16
836 #define MAX_PUSH_CONSTANTS_SIZE 128
837 #define MAX_DYNAMIC_BUFFERS 16
840 struct anv_pipeline_binding
{
841 /* The descriptor set this surface corresponds to */
844 /* Offset into the descriptor set */
848 struct anv_pipeline_layout
{
850 struct anv_descriptor_set_layout
*layout
;
851 uint32_t dynamic_offset_start
;
853 uint32_t surface_start
;
854 uint32_t sampler_start
;
855 } stage
[VK_SHADER_STAGE_NUM
];
861 bool has_dynamic_offsets
;
862 uint32_t surface_count
;
863 struct anv_pipeline_binding
*surface_to_descriptor
;
864 uint32_t sampler_count
;
865 struct anv_pipeline_binding
*sampler_to_descriptor
;
866 } stage
[VK_SHADER_STAGE_NUM
];
868 struct anv_pipeline_binding entries
[0];
872 struct anv_device
* device
;
880 enum anv_cmd_dirty_bits
{
881 ANV_CMD_DIRTY_DYNAMIC_VIEWPORT
= 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
882 ANV_CMD_DIRTY_DYNAMIC_SCISSOR
= 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
883 ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH
= 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
884 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS
= 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
885 ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS
= 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
886 ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS
= 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
887 ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK
= 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
888 ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK
= 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
889 ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE
= 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
890 ANV_CMD_DIRTY_DYNAMIC_ALL
= (1 << 9) - 1,
891 ANV_CMD_DIRTY_PIPELINE
= 1 << 9,
892 ANV_CMD_DIRTY_INDEX_BUFFER
= 1 << 10,
893 ANV_CMD_DIRTY_RENDER_TARGETS
= 1 << 11,
895 typedef uint32_t anv_cmd_dirty_mask_t
;
897 struct anv_vertex_binding
{
898 struct anv_buffer
* buffer
;
902 struct anv_push_constants
{
903 /* Current allocated size of this push constants data structure.
904 * Because a decent chunk of it may not be used (images on SKL, for
905 * instance), we won't actually allocate the entire structure up-front.
909 /* Push constant data provided by the client through vkPushConstants */
910 uint8_t client_data
[MAX_PUSH_CONSTANTS_SIZE
];
912 /* Our hardware only provides zero-based vertex and instance id so, in
913 * order to satisfy the vulkan requirements, we may have to push one or
914 * both of these into the shader.
916 uint32_t base_vertex
;
917 uint32_t base_instance
;
919 /* Offsets and ranges for dynamically bound buffers */
923 } dynamic
[MAX_DYNAMIC_BUFFERS
];
925 /* Image data for image_load_store on pre-SKL */
926 struct brw_image_param images
[MAX_IMAGES
];
929 struct anv_dynamic_state
{
932 VkViewport viewports
[MAX_VIEWPORTS
];
937 VkRect2D scissors
[MAX_SCISSORS
];
948 float blend_constants
[4];
958 } stencil_compare_mask
;
963 } stencil_write_mask
;
971 extern const struct anv_dynamic_state default_dynamic_state
;
973 void anv_dynamic_state_copy(struct anv_dynamic_state
*dest
,
974 const struct anv_dynamic_state
*src
,
977 /** State required while building cmd buffer */
978 struct anv_cmd_state
{
979 uint32_t current_pipeline
;
981 anv_cmd_dirty_mask_t dirty
;
982 anv_cmd_dirty_mask_t compute_dirty
;
983 VkShaderStageFlags descriptors_dirty
;
984 VkShaderStageFlags push_constants_dirty
;
985 uint32_t scratch_size
;
986 struct anv_pipeline
* pipeline
;
987 struct anv_pipeline
* compute_pipeline
;
988 struct anv_framebuffer
* framebuffer
;
989 struct anv_render_pass
* pass
;
990 struct anv_subpass
* subpass
;
991 uint32_t restart_index
;
992 struct anv_vertex_binding vertex_bindings
[MAX_VBS
];
993 struct anv_descriptor_set
* descriptors
[MAX_SETS
];
994 struct anv_push_constants
* push_constants
[VK_SHADER_STAGE_NUM
];
995 struct anv_dynamic_state dynamic
;
998 struct anv_buffer
* index_buffer
;
999 uint32_t index_type
; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
1000 uint32_t index_offset
;
1004 struct anv_cmd_pool
{
1005 VkAllocationCallbacks alloc
;
1006 struct list_head cmd_buffers
;
1009 #define ANV_CMD_BUFFER_BATCH_SIZE 8192
1011 enum anv_cmd_buffer_exec_mode
{
1012 ANV_CMD_BUFFER_EXEC_MODE_PRIMARY
,
1013 ANV_CMD_BUFFER_EXEC_MODE_EMIT
,
1014 ANV_CMD_BUFFER_EXEC_MODE_CHAIN
,
1015 ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN
,
1018 struct anv_cmd_buffer
{
1019 VK_LOADER_DATA _loader_data
;
1021 struct anv_device
* device
;
1023 struct anv_cmd_pool
* pool
;
1024 struct list_head pool_link
;
1026 struct anv_batch batch
;
1028 /* Fields required for the actual chain of anv_batch_bo's.
1030 * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
1032 struct list_head batch_bos
;
1033 enum anv_cmd_buffer_exec_mode exec_mode
;
1035 /* A vector of anv_batch_bo pointers for every batch or surface buffer
1036 * referenced by this command buffer
1038 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1040 struct anv_vector seen_bbos
;
1042 /* A vector of int32_t's for every block of binding tables.
1044 * initialized by anv_cmd_buffer_init_batch_bo_chain()
1046 struct anv_vector bt_blocks
;
1048 struct anv_reloc_list surface_relocs
;
1050 /* Information needed for execbuf
1052 * These fields are generated by anv_cmd_buffer_prepare_execbuf().
1055 struct drm_i915_gem_execbuffer2 execbuf
;
1057 struct drm_i915_gem_exec_object2
* objects
;
1059 struct anv_bo
** bos
;
1061 /* Allocated length of the 'objects' and 'bos' arrays */
1062 uint32_t array_length
;
1067 /* Serial for tracking buffer completion */
1070 /* Stream objects for storing temporary data */
1071 struct anv_state_stream surface_state_stream
;
1072 struct anv_state_stream dynamic_state_stream
;
1074 VkCommandBufferUsageFlags usage_flags
;
1075 VkCommandBufferLevel level
;
1077 struct anv_cmd_state state
;
1080 VkResult
anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1081 void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1082 void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer
*cmd_buffer
);
1083 void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer
*cmd_buffer
);
1084 void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer
*primary
,
1085 struct anv_cmd_buffer
*secondary
);
1086 void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer
*cmd_buffer
);
1088 VkResult
anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1089 unsigned stage
, struct anv_state
*bt_state
);
1090 VkResult
anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer
*cmd_buffer
,
1091 unsigned stage
, struct anv_state
*state
);
1092 void gen7_cmd_buffer_flush_descriptor_sets(struct anv_cmd_buffer
*cmd_buffer
);
1094 struct anv_state
anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1095 uint32_t *a
, uint32_t dwords
,
1096 uint32_t alignment
);
1097 struct anv_state
anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer
*cmd_buffer
,
1098 uint32_t *a
, uint32_t *b
,
1099 uint32_t dwords
, uint32_t alignment
);
1100 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1101 struct anv_subpass
*subpass
);
1104 anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1106 anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1107 uint32_t entries
, uint32_t *state_offset
);
1109 anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer
*cmd_buffer
);
1111 anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer
*cmd_buffer
,
1112 uint32_t size
, uint32_t alignment
);
1115 anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer
*cmd_buffer
);
1117 void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer
*cmd_buffer
);
1118 void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer
*cmd_buffer
);
1120 void gen7_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1121 void gen75_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1122 void gen8_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1123 void gen9_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1125 void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer
*cmd_buffer
);
1127 void gen7_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1128 struct anv_subpass
*subpass
);
1130 void gen8_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1131 struct anv_subpass
*subpass
);
1132 void gen9_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1133 struct anv_subpass
*subpass
);
1135 void anv_cmd_buffer_begin_subpass(struct anv_cmd_buffer
*cmd_buffer
,
1136 struct anv_subpass
*subpass
);
1139 anv_cmd_buffer_push_constants(struct anv_cmd_buffer
*cmd_buffer
,
1140 VkShaderStage stage
);
1142 void anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
1143 struct anv_render_pass
*pass
,
1144 const VkClearValue
*clear_values
);
1145 const struct anv_image_view
*
1146 anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer
*cmd_buffer
);
1148 void anv_cmd_buffer_dump(struct anv_cmd_buffer
*cmd_buffer
);
1152 struct drm_i915_gem_execbuffer2 execbuf
;
1153 struct drm_i915_gem_exec_object2 exec2_objects
[1];
1159 struct anv_shader_module
{
1160 struct nir_shader
* nir
;
1167 struct anv_shader_module
* module
;
1171 struct anv_pipeline
{
1172 struct anv_device
* device
;
1173 struct anv_batch batch
;
1174 uint32_t batch_data
[512];
1175 struct anv_reloc_list batch_relocs
;
1176 uint32_t dynamic_state_mask
;
1177 struct anv_dynamic_state dynamic_state
;
1179 struct anv_pipeline_layout
* layout
;
1182 struct brw_vs_prog_data vs_prog_data
;
1183 struct brw_wm_prog_data wm_prog_data
;
1184 struct brw_gs_prog_data gs_prog_data
;
1185 struct brw_cs_prog_data cs_prog_data
;
1186 bool writes_point_size
;
1187 struct brw_stage_prog_data
* prog_data
[VK_SHADER_STAGE_NUM
];
1188 uint32_t scratch_start
[VK_SHADER_STAGE_NUM
];
1189 uint32_t total_scratch
;
1193 uint32_t nr_vs_entries
;
1196 uint32_t nr_gs_entries
;
1199 VkShaderStageFlags active_stages
;
1200 struct anv_state_stream program_stream
;
1201 struct anv_state blend_state
;
1208 uint32_t ps_grf_start0
;
1209 uint32_t ps_grf_start2
;
1211 uint32_t gs_vertex_count
;
1215 uint32_t binding_stride
[MAX_VBS
];
1216 bool instancing_enable
[MAX_VBS
];
1217 bool primitive_restart
;
1220 uint32_t cs_thread_width_max
;
1221 uint32_t cs_right_mask
;
1225 uint32_t depth_stencil_state
[3];
1231 uint32_t wm_depth_stencil
[3];
1235 uint32_t wm_depth_stencil
[4];
1239 struct anv_graphics_pipeline_create_info
{
1241 bool disable_viewport
;
1242 bool disable_scissor
;
1248 anv_pipeline_init(struct anv_pipeline
*pipeline
, struct anv_device
*device
,
1249 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1250 const struct anv_graphics_pipeline_create_info
*extra
,
1251 const VkAllocationCallbacks
*alloc
);
1254 anv_pipeline_compile_cs(struct anv_pipeline
*pipeline
,
1255 const VkComputePipelineCreateInfo
*info
,
1256 struct anv_shader
*shader
);
1259 anv_graphics_pipeline_create(VkDevice device
,
1260 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1261 const struct anv_graphics_pipeline_create_info
*extra
,
1262 const VkAllocationCallbacks
*alloc
,
1263 VkPipeline
*pPipeline
);
1266 gen7_graphics_pipeline_create(VkDevice _device
,
1267 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1268 const struct anv_graphics_pipeline_create_info
*extra
,
1269 const VkAllocationCallbacks
*alloc
,
1270 VkPipeline
*pPipeline
);
1273 gen75_graphics_pipeline_create(VkDevice _device
,
1274 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1275 const struct anv_graphics_pipeline_create_info
*extra
,
1276 const VkAllocationCallbacks
*alloc
,
1277 VkPipeline
*pPipeline
);
1280 gen8_graphics_pipeline_create(VkDevice _device
,
1281 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1282 const struct anv_graphics_pipeline_create_info
*extra
,
1283 const VkAllocationCallbacks
*alloc
,
1284 VkPipeline
*pPipeline
);
1286 gen9_graphics_pipeline_create(VkDevice _device
,
1287 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
1288 const struct anv_graphics_pipeline_create_info
*extra
,
1289 const VkAllocationCallbacks
*alloc
,
1290 VkPipeline
*pPipeline
);
1292 gen7_compute_pipeline_create(VkDevice _device
,
1293 const VkComputePipelineCreateInfo
*pCreateInfo
,
1294 const VkAllocationCallbacks
*alloc
,
1295 VkPipeline
*pPipeline
);
1297 gen75_compute_pipeline_create(VkDevice _device
,
1298 const VkComputePipelineCreateInfo
*pCreateInfo
,
1299 const VkAllocationCallbacks
*alloc
,
1300 VkPipeline
*pPipeline
);
1303 gen8_compute_pipeline_create(VkDevice _device
,
1304 const VkComputePipelineCreateInfo
*pCreateInfo
,
1305 const VkAllocationCallbacks
*alloc
,
1306 VkPipeline
*pPipeline
);
1308 gen9_compute_pipeline_create(VkDevice _device
,
1309 const VkComputePipelineCreateInfo
*pCreateInfo
,
1310 const VkAllocationCallbacks
*alloc
,
1311 VkPipeline
*pPipeline
);
1314 const VkFormat vk_format
;
1316 enum isl_format surface_format
; /**< RENDER_SURFACE_STATE.SurfaceFormat */
1317 const struct isl_format_layout
*isl_layout
;
1318 uint8_t num_channels
;
1319 uint16_t depth_format
; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
1324 * Stencil formats are often a special case. To reduce the number of lookups
1325 * into the VkFormat-to-anv_format translation table when working with
1326 * stencil, here is the handle to the table's entry for VK_FORMAT_S8_UINT.
1328 extern const struct anv_format
*const anv_format_s8_uint
;
1330 const struct anv_format
*
1331 anv_format_for_vk_format(VkFormat format
);
1334 anv_format_is_color(const struct anv_format
*format
)
1336 return !format
->depth_format
&& !format
->has_stencil
;
1340 anv_format_is_depth_or_stencil(const struct anv_format
*format
)
1342 return format
->depth_format
|| format
->has_stencil
;
1345 struct anv_image_view_info
{
1346 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
1347 bool is_array
:1; /**< RENDER_SURFACE_STATE.SurfaceArray */
1348 bool is_cube
:1; /**< RENDER_SURFACE_STATE.CubeFaceEnable* */
1351 struct anv_image_view_info
1352 anv_image_view_info_for_vk_image_view_type(VkImageViewType type
);
1355 * A proxy for the color surfaces, depth surfaces, and stencil surfaces.
1357 struct anv_surface
{
1359 * Offset from VkImage's base address, as bound by vkBindImageMemory().
1363 uint32_t stride
; /**< RENDER_SURFACE_STATE.SurfacePitch */
1364 uint16_t qpitch
; /**< RENDER_SURFACE_STATE.QPitch */
1367 * \name Alignment of miptree images, in units of pixels.
1369 * These fields contain the real alignment values, not the values to be
1370 * given to the GPU. For example, if h_align is 4, then program the GPU
1374 uint8_t h_align
; /**< RENDER_SURFACE_STATE.SurfaceHorizontalAlignment */
1375 uint8_t v_align
; /**< RENDER_SURFACE_STATE.SurfaceVerticalAlignment */
1378 enum isl_tiling tiling
;
1383 const struct anv_format
*format
;
1386 uint32_t array_size
;
1387 VkImageUsageFlags usage
; /**< Superset of VkImageCreateInfo::usage. */
1392 /* Set when bound */
1394 VkDeviceSize offset
;
1396 uint8_t surface_type
; /**< RENDER_SURFACE_STATE.SurfaceType */
1398 bool needs_nonrt_surface_state
:1;
1399 bool needs_color_rt_surface_state
:1;
1404 * For each foo, anv_image::foo_surface is valid if and only if
1405 * anv_image::format has a foo aspect.
1407 * The hardware requires that the depth buffer and stencil buffer be
1408 * separate surfaces. From Vulkan's perspective, though, depth and stencil
1409 * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
1410 * allocate the depth and stencil buffers as separate surfaces in the same
1414 struct anv_surface color_surface
;
1417 struct anv_surface depth_surface
;
1418 struct anv_surface stencil_surface
;
1423 struct anv_image_view
{
1424 const struct anv_image
*image
; /**< VkImageViewCreateInfo::image */
1425 const struct anv_format
*format
; /**< VkImageViewCreateInfo::format */
1427 uint32_t offset
; /**< Offset into bo. */
1428 VkExtent3D extent
; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1430 /** RENDER_SURFACE_STATE when using image as a color render target. */
1431 struct anv_state color_rt_surface_state
;
1433 /** RENDER_SURFACE_STATE when using image as a non render target. */
1434 struct anv_state nonrt_surface_state
;
1437 struct anv_image_create_info
{
1438 const VkImageCreateInfo
*vk_info
;
1440 enum isl_tiling tiling
;
1444 VkResult
anv_image_create(VkDevice _device
,
1445 const struct anv_image_create_info
*info
,
1446 const VkAllocationCallbacks
* alloc
,
1449 struct anv_surface
*
1450 anv_image_get_surface_for_aspect_mask(struct anv_image
*image
,
1451 VkImageAspectFlags aspect_mask
);
1453 void anv_image_view_init(struct anv_image_view
*view
,
1454 struct anv_device
*device
,
1455 const VkImageViewCreateInfo
* pCreateInfo
,
1456 struct anv_cmd_buffer
*cmd_buffer
);
1459 gen7_image_view_init(struct anv_image_view
*iview
,
1460 struct anv_device
*device
,
1461 const VkImageViewCreateInfo
* pCreateInfo
,
1462 struct anv_cmd_buffer
*cmd_buffer
);
1465 gen75_image_view_init(struct anv_image_view
*iview
,
1466 struct anv_device
*device
,
1467 const VkImageViewCreateInfo
* pCreateInfo
,
1468 struct anv_cmd_buffer
*cmd_buffer
);
1471 gen8_image_view_init(struct anv_image_view
*iview
,
1472 struct anv_device
*device
,
1473 const VkImageViewCreateInfo
* pCreateInfo
,
1474 struct anv_cmd_buffer
*cmd_buffer
);
1477 gen9_image_view_init(struct anv_image_view
*iview
,
1478 struct anv_device
*device
,
1479 const VkImageViewCreateInfo
* pCreateInfo
,
1480 struct anv_cmd_buffer
*cmd_buffer
);
1482 void anv_fill_buffer_surface_state(struct anv_device
*device
, void *state
,
1483 const struct anv_format
*format
,
1484 uint32_t offset
, uint32_t range
,
1487 void gen7_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1488 uint32_t offset
, uint32_t range
,
1490 void gen75_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1491 uint32_t offset
, uint32_t range
,
1493 void gen8_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1494 uint32_t offset
, uint32_t range
,
1496 void gen9_fill_buffer_surface_state(void *state
, const struct anv_format
*format
,
1497 uint32_t offset
, uint32_t range
,
1500 struct anv_sampler
{
1504 struct anv_framebuffer
{
1509 uint32_t attachment_count
;
1510 const struct anv_image_view
* attachments
[0];
1513 struct anv_subpass
{
1514 uint32_t input_count
;
1515 uint32_t * input_attachments
;
1516 uint32_t color_count
;
1517 uint32_t * color_attachments
;
1518 uint32_t * resolve_attachments
;
1519 uint32_t depth_stencil_attachment
;
1522 struct anv_render_pass_attachment
{
1523 const struct anv_format
*format
;
1525 VkAttachmentLoadOp load_op
;
1526 VkAttachmentLoadOp stencil_load_op
;
1529 struct anv_render_pass
{
1530 uint32_t attachment_count
;
1531 uint32_t subpass_count
;
1532 struct anv_render_pass_attachment
* attachments
;
1533 struct anv_subpass subpasses
[0];
1536 extern struct anv_render_pass anv_meta_dummy_renderpass
;
1538 struct anv_query_pool_slot
{
1544 struct anv_query_pool
{
1550 void anv_device_init_meta(struct anv_device
*device
);
1551 void anv_device_finish_meta(struct anv_device
*device
);
1553 void *anv_lookup_entrypoint(const char *name
);
1555 void anv_dump_image_to_ppm(struct anv_device
*device
,
1556 struct anv_image
*image
, unsigned miplevel
,
1557 unsigned array_layer
, const char *filename
);
1559 #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
1561 static inline struct __anv_type * \
1562 __anv_type ## _from_handle(__VkType _handle) \
1564 return (struct __anv_type *) _handle; \
1567 static inline __VkType \
1568 __anv_type ## _to_handle(struct __anv_type *_obj) \
1570 return (__VkType) _obj; \
1573 #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
1575 static inline struct __anv_type * \
1576 __anv_type ## _from_handle(__VkType _handle) \
1578 return (struct __anv_type *)(uintptr_t) _handle; \
1581 static inline __VkType \
1582 __anv_type ## _to_handle(struct __anv_type *_obj) \
1584 return (__VkType)(uintptr_t) _obj; \
1587 #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
1588 struct __anv_type *__name = __anv_type ## _from_handle(__handle)
1590 ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer
, VkCommandBuffer
)
1591 ANV_DEFINE_HANDLE_CASTS(anv_device
, VkDevice
)
1592 ANV_DEFINE_HANDLE_CASTS(anv_instance
, VkInstance
)
1593 ANV_DEFINE_HANDLE_CASTS(anv_physical_device
, VkPhysicalDevice
)
1594 ANV_DEFINE_HANDLE_CASTS(anv_queue
, VkQueue
)
1596 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool
, VkCommandPool
)
1597 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer
, VkBuffer
)
1598 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set
, VkDescriptorSet
)
1599 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout
, VkDescriptorSetLayout
)
1600 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory
, VkDeviceMemory
)
1601 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence
, VkFence
)
1602 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer
, VkFramebuffer
)
1603 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image
, VkImage
)
1604 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view
, VkImageView
);
1605 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline
, VkPipeline
)
1606 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout
, VkPipelineLayout
)
1607 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool
, VkQueryPool
)
1608 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass
, VkRenderPass
)
1609 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler
, VkSampler
)
1610 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader
, VkShader
)
1611 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module
, VkShaderModule
)
1613 #define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
1615 static inline const __VkType * \
1616 __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
1618 return (const __VkType *) __anv_obj; \
1621 #define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
1622 const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
1624 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkMemoryBarrier
)
1625 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkBufferMemoryBarrier
)
1626 ANV_DEFINE_STRUCT_CASTS(anv_common
, VkImageMemoryBarrier
)