4 * this is public domain without any warranties of any kind
7 /* XXX: KEEP AN EYE ON ABBREVIATIONS */
9 * XXX: we are fixing vulkan ABI which made the huge mistake to use
10 * enums as function parameters or function return values.
13 #include <xcb.h> /* we use the xcb wsi */
14 #include "app_core_types.h"
16 /*----------------------------------------------------------------------------*/
19 #define vk_whole_sz 0xffffffffffffffff
20 #define vk_q_fam_ignored 0xffffffff
21 /*----------------------------------------------------------------------------*/
22 #define VK_VERSION_MAJOR(x) (x >> 22)
23 #define VK_VERSION_MINOR(x) ((x >> 12) & 0x3ff)
24 #define VK_VERSION_PATCH(x) (x & 0xfff)
26 /******************************************************************************/
29 * 64 bits platforms: enums do default to 32 bits, but can go up to 64 bits
30 * based on the range of values they hold. this is important for
31 * vulkan ABI which we will fix.
32 * _individually_, each value is defaulted to 32bits, if possible, and signed
34 * XXX: All vulkan enums use 32 bits storage
37 vk_err_out_of_host_mem
= -1,
38 /*--------------------------------------------------------------------*/
41 vk_r_enum_max
= 0x7fffffff
45 vk_struct_type_instance_create_info
= 1,
46 vk_struct_type_dev_q_create_info
= 2,
47 vk_struct_type_dev_create_info
= 3,
48 vk_struct_type_submit_info
= 4,
49 vk_struct_type_mem_alloc_info
= 5,
50 vk_struct_type_fence_create_info
= 8,
51 vk_struct_type_sem_create_info
= 9,
52 vk_struct_type_img_create_info
= 14,
53 vk_struct_type_cmdpool_create_info
= 39,
54 vk_struct_type_cmdbuf_alloc_info
= 40,
55 vk_struct_type_cmdbuf_begin_info
= 42,
56 vk_struct_type_img_mem_barrier
= 45,
57 /* extension number 2 or index 1, offset 0 */
58 vk_struct_type_swpchn_create_info
= 1000000000 + 1000 + 0,
59 /* extension number 2 or index 1, offset 1 */
60 vk_struct_type_present_info
= 1000000000 + 1000 + 1,
61 /* extension number 6 or index 5, offset 0 */
62 vk_struct_type_xcb_surf_create_info
= 1000000000 + 5000 + 0,
63 /* extension number 60 or index 59, offset 1 */
64 vk_struct_type_phydev_props
= 1000000000 + 59000 + 1,
65 /* extension number 60 or index 59, offset 5 */
66 vk_struct_type_q_fam_props
= 1000000000 + 59000 + 5,
67 /* extension number 60 or index 59, offset 6 */
68 vk_struct_type_phydev_mem_props
= 1000000000 + 59000 + 6,
69 /* extension number 60 or index 59, offset 10 */
70 vk_struct_type_acquire_next_img_info
= 1000000000 + 59000 + 10,
71 /* extension number 91 or index 90, offset 0 */
72 vk_struct_type_surf_caps
= 1000000000 + 90000 + 0,
73 /* extension number 120 or index 119, offset 0 */
74 vk_struct_type_phydev_surf_info
= 1000000000 + 119000 + 0,
75 /* extension number 120 or index 119, offset 2 */
76 vk_struct_type_surf_texel_mem_blk_conf
= 1000000000 + 119000 + 2,
77 /* extension number 147 or index 146, offset 1 */
78 vk_struct_type_img_mem_rqmts_info
= 1000000000 + 146000 + 1,
79 /* extension number 147 or index 146, offset 3 */
80 vk_struct_type_mem_rqmts
= 1000000000 + 146000 + 3,
81 /* extension number 158 or index 157, offset 1 */
82 vk_struct_type_bind_img_mem_info
= 1000000000 + 157000 + 1,
83 vk_struct_type_enum_max
= 0x7fffffff
86 struct vk_instance_create_info_t
{
90 void *app_info
; /* allow easy hidden driver optimizations: no! */
92 u8
**enabled_layer_names
;
94 u8
**enabled_ext_names
;
97 #define VK_MAX_EXT_NAME_SZ 256
98 struct vk_ext_props_t
{
99 u8 name
[VK_MAX_EXT_NAME_SZ
];
103 #define VK_MAX_DESC_SZ 256
104 struct vk_layer_props_t
{
105 u8 name
[VK_MAX_EXT_NAME_SZ
];
107 u32 implementation_version
;
108 u8 desc
[VK_MAX_DESC_SZ
];
112 vk_phydev_type_other
= 0,
113 vk_phydev_type_integrated_gpu
= 1,
114 vk_phydev_type_discrete_gpu
= 2,
115 vk_phydev_type_virtual_gpu
= 3,
116 vk_phydev_type_cpu
= 4,
117 vk_phydev_type_enum_max
= 0x7fffffff
120 struct vk_phydev_limits_t
{
124 float not_used_03
[2];
126 float not_used_05
[2];
131 float not_used_10
[2];
135 float not_used_14
[6];
140 struct vk_phydev_sparse_props_t
{
144 /*----------------------------------------------------------------------------*/
145 #define VK_MAX_PHYDEV_NAME_SZ 256
146 #define VK_UUID_SZ 16
147 struct vk_phydev_props_core_t
{
153 u8 name
[VK_MAX_PHYDEV_NAME_SZ
];
154 u8 pipeline_cache_uuid
[VK_UUID_SZ
];
155 struct vk_phydev_limits_t limits
;
156 struct vk_phydev_sparse_props_t sparse_props
;
158 /* the vulkan 1.1 version */
159 struct vk_phydev_props_t
{
162 struct vk_phydev_props_core_t core
;
164 /*----------------------------------------------------------------------------*/
166 vk_q_gfx_bit
= 0x00000001,
167 vk_q_compute_bit
= 0x00000002,
168 vk_q_transfer_bit
= 0x00000004,
169 vk_q_sparse_binding_bit
= 0x00000008,
170 vk_q_protected_bit
= 0x00000010,
171 vk_q_flag_bits_enum_max
= 0x7fffffff
174 struct vk_extent_3d_t
{
179 /*----------------------------------------------------------------------------*/
180 struct vk_q_fam_props_core_t
{
183 u32 timestamp_valid_bits
;
184 struct vk_extent_3d_t min_img_transfer_granularity
;
187 struct vk_q_fam_props_t
{
190 struct vk_q_fam_props_core_t core
;
192 /*----------------------------------------------------------------------------*/
193 struct vk_phydev_features_t
{
197 struct vk_dev_q_create_info_t
{
206 struct vk_dev_create_info_t
{
210 u32 q_create_infos_n
;
211 struct vk_dev_q_create_info_t
*q_create_infos
;
215 u8
**enabled_ext_names
;
220 vk_cmdpool_create_transient_bit
= 0x00000001,
221 vk_cmdpool_create_reset_cmdbuf_bit
= 0x00000002,
222 vk_cmdpool_create_flag_bits_enum_max
= 0x7fffffff
225 struct vk_cmdpool_create_info_t
{
232 struct vk_xcb_surf_create_info_t
{
240 struct vk_phydev_surf_info_t
{
247 vk_texel_mem_blk_fmt_undefined
= 0,
248 vk_texel_mem_blk_fmt_b8g8r8a8_unorm
= 44,
249 vk_texel_mem_blk_fmt_b8g8r8a8_srgb
= 50,
250 vk_texel_mem_blk_fmt_enum_max
= 0x7fffffff
254 vk_color_space_srgb_nonlinear
= 0,
255 vk_color_space_enum_max
= 0x7fffffff
258 struct vk_surf_texel_mem_blk_conf_core_t
{
263 struct vk_surf_texel_mem_blk_conf_t
{
266 struct vk_surf_texel_mem_blk_conf_core_t core
;
268 /*----------------------------------------------------------------------------*/
270 vk_mem_prop_dev_local_bit
= 0x00000001,
271 vk_mem_prop_host_visible_bit
= 0x00000002,
272 vk_mem_prop_host_cached_bit
= 0x00000008,
273 vk_mem_prop_flag_bits_enum_max
= 0x7fffffff
276 struct vk_mem_type_t
{
280 /*----------------------------------------------------------------------------*/
282 vk_mem_heap_dev_local_bit
= 0x00000001,
283 vk_mem_heap_multi_instance_bit
= 0x00000002,
284 vk_mem_heap_flag_bits_enum_max
= 0x7FFFFFFF
287 struct vk_mem_heap_t
{
291 /*----------------------------------------------------------------------------*/
292 #define VK_MEM_TYPES_N_MAX 32
293 #define VK_MEM_HEAPS_N_MAX 16
294 struct vk_phydev_mem_props_core_t
{
296 struct vk_mem_type_t mem_types
[VK_MEM_TYPES_N_MAX
];
298 struct vk_mem_heap_t mem_heaps
[VK_MEM_HEAPS_N_MAX
];
301 struct vk_phydev_mem_props_t
{
304 struct vk_phydev_mem_props_core_t core
;
306 /*----------------------------------------------------------------------------*/
307 struct vk_extent_2d_t
{
313 vk_surf_transform_identity_bit
= 0x00000001,
314 vk_surf_transform_flag_bits_enum_max
= 0x7fffffff
318 vk_composite_alpha_opaque_bit
= 0x00000001,
319 vk_composite_alpha_flag_bits_enum_max
= 0x7fffffff
323 vk_img_usage_transfer_src_bit
= 0x00000001,
324 vk_img_usage_transfer_dst_bit
= 0x00000002,
325 vk_img_usage_color_attachment_bit
= 0x00000010,
326 vk_img_usage_flag_bits_enum_max
= 0x7fffffff
329 struct vk_surf_caps_core_t
{
332 struct vk_extent_2d_t current_extent
;
333 struct vk_extent_2d_t img_extent_min
;
334 struct vk_extent_2d_t img_extent_max
;
335 u32 img_array_layers_n_max
;
336 u32 supported_transforms
;
337 u32 current_transform
;
338 u32 supported_composite_alpha
;
339 u32 supported_img_usage_flags
;
342 struct vk_surf_caps_t
{
345 struct vk_surf_caps_core_t core
;
351 /*----------------------------------------------------------------------------*/
353 vk_sharing_mode_exclusive
= 0,
354 vk_sharing_mode_enum_max
= 0x7fffffff
358 vk_present_mode_immediate
= 0,
359 vk_present_mode_mailbox
= 1,
360 vk_present_mode_fifo
= 2,
361 vk_present_mode_fifo_relaxed
= 3,
362 vk_present_mode_enum_max
= 0x7fffffff
365 struct vk_swpchn_create_info_t
{
371 u32 img_texel_mem_blk_fmt
;
373 struct vk_extent_2d_t img_extent
;
376 u32 img_sharing_mode
;
388 vk_img_type_enum_max
= 0x7fffffff
392 vk_samples_n_1_bit
= 0x00000001,
393 vk_samples_n_enum_max
= 0x7fffffff
397 vk_img_tiling_optimal
= 0,
398 vk_img_tiling_linear
= 1,
399 vk_img_tiling_enum_max
= 0x7fffffff
403 vk_img_create_flag_2d_array_compatible_bit
= 0x00000002,
404 vk_img_create_flag_enum_max
= 0x7fffffff
408 vk_img_layout_undefined
= 0,
409 vk_img_layout_general
= 1,
410 /* extension number 2 or index 1, offset 2 */
411 vk_img_layout_present
= 1000000000 + 1000 + 2,
412 vk_img_layout_enum_n_max
= 0x7fffffff
415 struct vk_img_create_info_t
{
420 u32 texel_mem_blk_fmt
;
421 struct vk_extent_3d_t extent
;
424 u32 samples_n
; /* flags */
433 struct vk_img_mem_rqmts_info_t
{
439 struct vk_mem_rqmts_core_t
{
442 /*idxs of bits are idxs in mem types of vk_phydev_mem_props_core_t */
446 struct vk_mem_rqmts_t
{
449 struct vk_mem_rqmts_core_t core
;
452 struct vk_mem_alloc_info_t
{
456 u32 mem_type_idx
; /* in the physical device array of memory types */
459 struct vk_bind_img_mem_info_t
{
468 vk_pipeline_stage_top_of_pipe_bit
= (1 << 0),
469 vk_pipeline_stage_bottom_of_pipe_bit
= (1 << 13),
470 vk_pipeline_stage_enum_max
= 0x7fffffff
474 vk_img_aspect_color_bit
= 1,
475 vk_img_aspect_enum_max
= 0x7fffffff
478 struct vk_img_subrsrc_range_t
{
482 u32 base_array_layer
;
486 struct vk_img_mem_barrier_t
{
496 struct vk_img_subrsrc_range_t subrsrc_range
;
500 vk_cmdbuf_lvl_primary
= 0,
501 vk_cmdbuf_lvl_enum_max
= 0x7fffffff
504 struct vk_cmdbuf_alloc_info_t
{
513 vk_cmdbuf_usage_one_time_submit_bit
= 0x00000001,
514 vk_cmdbuf_usage_enum_max
= 0x7fffffff
517 struct vk_cmdbuf_begin_info_t
{
524 struct vk_submit_info_t
{
529 u32
* wait_dst_stages
;
536 struct vk_img_subrsrc_t
{
542 struct vk_subrsrc_layout_t
{
550 struct vk_acquire_next_img_info_t
{
560 struct vk_fence_create_info_t
{
566 struct vk_img_subrsrc_layers_t
{
569 u32 base_array_layer
;
573 struct vk_offset_3d_t
{
579 struct vk_img_blit_t
{
580 struct vk_img_subrsrc_layers_t src_subrsrc
;
581 struct vk_offset_3d_t src_offsets
[2];
582 struct vk_img_subrsrc_layers_t dst_subrsrc
;
583 struct vk_offset_3d_t dst_offsets
[2];
586 struct vk_present_info_t
{
597 struct vk_sem_create_info_t
{
602 /******************************************************************************/
603 /* dev function pointers prototypes with some namespace/local keywords */
604 #define vk_get_dev_q(...) \
605 app_surf.dev.dl_vk_get_dev_q(app_surf.dev.vk,##__VA_ARGS__)
607 #define vk_create_cmdpool(...) \
608 app_surf.dev.dl_vk_create_cmdpool(app_surf.dev.vk,##__VA_ARGS__)
610 #define vk_create_swpchn(...) \
611 app_surf.dev.dl_vk_create_swpchn(app_surf.dev.vk,##__VA_ARGS__)
613 #define vk_get_swpchn_imgs(...) \
614 app_surf.dev.dl_vk_get_swpchn_imgs(app_surf.dev.vk,##__VA_ARGS__)
616 #define vk_create_img(...) \
617 app_surf.dev.dl_vk_create_img(app_surf.dev.vk,##__VA_ARGS__)
619 #define vk_get_img_mem_rqmts(...) \
620 app_surf.dev.dl_vk_get_img_mem_rqmts(app_surf.dev.vk,##__VA_ARGS__)
622 #define vk_alloc_mem(...) \
623 app_surf.dev.dl_vk_alloc_mem(app_surf.dev.vk,##__VA_ARGS__)
625 #define vk_bind_img_mem(...) \
626 app_surf.dev.dl_vk_bind_img_mem(app_surf.dev.vk,##__VA_ARGS__)
628 #define vk_map_mem(...) \
629 app_surf.dev.dl_vk_map_mem(app_surf.dev.vk,##__VA_ARGS__)
631 #define vk_alloc_cmdbufs(...) \
632 app_surf.dev.dl_vk_alloc_cmdbufs(app_surf.dev.vk,##__VA_ARGS__)
634 #define vk_free_cmdbufs(...) \
635 app_surf.dev.dl_vk_free_cmdbufs(app_surf.dev.vk,##__VA_ARGS__)
637 #define vk_begin_cmdbuf(...) \
638 app_surf.dev.dl_vk_begin_cmdbuf(__VA_ARGS__)
640 #define vk_end_cmdbuf(...) \
641 app_surf.dev.dl_vk_end_cmdbuf(__VA_ARGS__)
643 #define vk_cmd_pipeline_barrier(...) \
644 app_surf.dev.dl_vk_cmd_pipeline_barrier(__VA_ARGS__)
646 #define vk_q_submit(...) \
647 app_surf.dev.dl_vk_q_submit(__VA_ARGS__)
649 #define vk_q_wait_idle(...) \
650 app_surf.dev.dl_vk_q_wait_idle(__VA_ARGS__)
652 #define vk_get_img_subrsrc_layout(...) \
653 app_surf.dev.dl_vk_get_img_subrsrc_layout(app_surf.dev.vk,##__VA_ARGS__)
655 #define vk_acquire_next_img(...) \
656 app_surf.dev.dl_vk_acquire_next_img(app_surf.dev.vk,##__VA_ARGS__)
658 #define vk_create_fence(...) \
659 app_surf.dev.dl_create_fence(app_surf.dev.vk,##__VA_ARGS__)
661 #define vk_reset_cmdbuf(...) \
662 app_surf.dev.dl_vk_reset_cmdbuf(__VA_ARGS__)
664 #define vk_cmd_blit_img(...) \
665 app_surf.dev.dl_vk_cmd_blit_img(__VA_ARGS__)
667 #define vk_wait_for_fences(...) \
668 app_surf.dev.dl_vk_wait_for_fences(app_surf.dev.vk,##__VA_ARGS__)
670 #define vk_reset_fences(...) \
671 app_surf.dev.dl_vk_reset_fences(app_surf.dev.vk,##__VA_ARGS__)
673 #define vk_q_present(...) \
674 app_surf.dev.dl_vk_q_present(__VA_ARGS__)
676 #define vk_create_sem(...) \
677 app_surf.dev.dl_vk_create_sem(app_surf.dev.vk,##__VA_ARGS__)
678 /*----------------------------------------------------------------------------*/
679 #define VK_DEV_SYMS \
680 void (*dl_vk_get_dev_q)(void *dev, u32 fam, u32 q_idx, void **q); \
681 s32 (*dl_vk_create_cmdpool)( \
683 struct vk_cmdpool_create_info_t *create_info, \
685 void **vk_cmdpool); \
686 s32 (*dl_vk_create_swpchn)( \
688 struct vk_swpchn_create_info_t *info, \
691 s32 (*dl_vk_get_swpchn_imgs)( \
696 s32 (*dl_vk_create_img)( \
698 struct vk_img_create_info_t *info, \
701 s32 (*dl_vk_get_img_mem_rqmts)( \
703 struct vk_img_mem_rqmts_info_t *info, \
704 struct vk_mem_rqmts_t *mem_rqmts); \
705 s32 (*dl_vk_alloc_mem)( \
707 struct vk_mem_alloc_info_t *info, \
710 s32 (*dl_vk_bind_img_mem)( \
713 struct vk_bind_img_mem_info_t *infos); \
714 s32 (*dl_vk_map_mem)( \
721 s32 (*dl_vk_alloc_cmdbufs)( \
723 struct vk_cmdbuf_alloc_info_t *info, \
725 void (*dl_vk_free_cmdbufs)( \
730 s32 (*dl_vk_begin_cmdbuf)( \
732 struct vk_cmdbuf_begin_info_t *info); \
733 s32 (*dl_vk_end_cmdbuf)(void *cmdbuf); \
734 void (*dl_vk_cmd_pipeline_barrier)( \
738 u32 dependency_flags, \
739 u32 mem_barriers_n, \
740 void *mem_barriers, \
741 u32 buf_mem_barriers_n, \
742 void *buf_mem_barriers, \
743 u32 img_mem_barriers_n, \
744 struct vk_img_mem_barrier_t *img_mem_barriers); \
745 s32 (*dl_vk_q_submit)( \
748 struct vk_submit_info_t *submits, \
750 s32 (*dl_vk_q_wait_idle)(void *q); \
751 void (*dl_vk_get_img_subrsrc_layout)( \
754 struct vk_img_subrsrc_t *subrsrc, \
755 struct vk_subrsrc_layout_t *layout); \
756 s32 (*dl_vk_acquire_next_img)( \
758 struct vk_acquire_next_img_info_t *info, \
760 s32 (*dl_vk_create_fence)( \
762 struct vk_fence_create_info_t *info, \
765 s32 (*dl_vk_reset_cmdbuf)( \
768 void (*dl_vk_cmd_blit_img)( \
771 u32 src_img_layout, \
773 u32 dst_img_layout, \
775 struct vk_img_blit_t *regions, \
777 s32 (*dl_vk_wait_for_fences)( \
783 s32 (*dl_vk_reset_fences)( \
787 s32 (*dl_vk_q_present)( \
789 struct vk_present_info_t *info); \
790 s32 (*dl_vk_create_sem)( \
792 struct vk_sem_create_info_t *info, \