From cf73091d7461b2d872020e0ea3db3b8f75b27c80 Mon Sep 17 00:00:00 2001 From: Sylvain BERTRAND Date: Tue, 14 Jan 2020 17:16:45 +0000 Subject: [PATCH] simplification/taylorization and fix --- 2d/blit/ABBREVIATIONS | 14 + 2d/{kickstart => blit}/KEYBOARD | 0 2d/{kickstart => blit}/NAMESPACE | 0 2d/{kickstart => blit}/app.c | 514 ++++--------- 2d/{kickstart => blit}/app_core_types.h | 5 +- 2d/{kickstart => blit}/app_state.c | 9 +- 2d/{kickstart => blit}/app_state_types.h | 33 +- 2d/{kickstart => blit}/log.h | 2 +- 2d/{kickstart => blit}/namespace/app.c | 0 2d/{kickstart => blit}/namespace/app_state.c | 0 2d/{kickstart => blit}/namespace/app_state_types.h | 0 2d/{kickstart => blit}/namespace/vk_syms.c | 0 2d/blit/vk_app.h | 184 +++++ 2d/{kickstart => blit}/vk_syms.c | 123 +--- 2d/{kickstart => blit}/xcb.c | 5 +- 2d/{kickstart => blit}/xcb_syms.c | 4 +- 2d/kickstart/vk_gen.c | 219 ------ 2d/kickstart/vk_types.h | 795 --------------------- {2d/kickstart => nyanvk}/ABBREVIATIONS | 43 +- nyanvk/README | 4 + nyanvk/consts.h | 270 +++++++ nyanvk/syms_dev.h | 155 ++++ nyanvk/syms_global.h | 72 ++ nyanvk/types.h | 593 +++++++++++++++ 24 files changed, 1522 insertions(+), 1522 deletions(-) create mode 100644 2d/blit/ABBREVIATIONS rename 2d/{kickstart => blit}/KEYBOARD (100%) rename 2d/{kickstart => blit}/NAMESPACE (100%) rename 2d/{kickstart => blit}/app.c (78%) rename 2d/{kickstart => blit}/app_core_types.h (87%) rename 2d/{kickstart => blit}/app_state.c (78%) rename 2d/{kickstart => blit}/app_state_types.h (75%) rename 2d/{kickstart => blit}/log.h (81%) rename 2d/{kickstart => blit}/namespace/app.c (100%) rename 2d/{kickstart => blit}/namespace/app_state.c (100%) rename 2d/{kickstart => blit}/namespace/app_state_types.h (100%) rename 2d/{kickstart => blit}/namespace/vk_syms.c (100%) create mode 100644 2d/blit/vk_app.h rename 2d/{kickstart => blit}/vk_syms.c (59%) rename 2d/{kickstart => blit}/xcb.c (99%) rename 2d/{kickstart => blit}/xcb_syms.c (98%) delete mode 100644 2d/kickstart/vk_gen.c delete mode 100644 2d/kickstart/vk_types.h rename {2d/kickstart => nyanvk}/ABBREVIATIONS (61%) create mode 100644 nyanvk/README create mode 100644 nyanvk/consts.h create mode 100644 nyanvk/syms_dev.h create mode 100644 nyanvk/syms_global.h create mode 100644 nyanvk/types.h diff --git a/2d/blit/ABBREVIATIONS b/2d/blit/ABBREVIATIONS new file mode 100644 index 0000000..ea340d8 --- /dev/null +++ b/2d/blit/ABBREVIATIONS @@ -0,0 +1,14 @@ +LOCAL ABBREVIATIONS: + +_g : _global (naming noise for identifier keyword namespace growth) + +c : Connection (often) +disp :DISPlay +env : ENVironment +evt(s) :EVenT(S) +obj(s) : OBJect(S) +r : Result (often) +rec : RECord +resz : RESiZe +scr(s) : SCReen(S) +tmp : TeMPorary diff --git a/2d/kickstart/KEYBOARD b/2d/blit/KEYBOARD similarity index 100% rename from 2d/kickstart/KEYBOARD rename to 2d/blit/KEYBOARD diff --git a/2d/kickstart/NAMESPACE b/2d/blit/NAMESPACE similarity index 100% rename from 2d/kickstart/NAMESPACE rename to 2d/blit/NAMESPACE diff --git a/2d/kickstart/app.c b/2d/blit/app.c similarity index 78% rename from 2d/kickstart/app.c rename to 2d/blit/app.c index 470f7a9..57844c8 100644 --- a/2d/kickstart/app.c +++ b/2d/blit/app.c @@ -4,7 +4,7 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ /* * XXX vk abstraction is much more complex than real hardware, aka the cost of * most software generalisation/abstraction (and some hardware has lost its @@ -14,6 +14,11 @@ * fancy stuff above this "safe mode" must be validated by hardware vendors * then the user... or you literally walking on eggs. * + * The vulkan API is, here, simplified and taylored for the app using the C + * preprocessor. In other words, when there is no ambiguity in the context of + * this code, vulkan API function parameters get simplified out in C + * preprocessor macros. + * * XXX: this is a "One Compilation Unit" source code with preprocessor * namespace support. this allow the project to grow to very large and keep the * global identifier space in check (= tradeoff). Each source file, *.h *.c, @@ -27,12 +32,11 @@ * - a swpchn can become out-of-date. for instance the win system did resz * the parent surf of the swpchn... if you did allow it to happen * asynchronously. - * here we choose that any of those evts will be fatal for simplicity. - * for instance, if you choose to support the swpchn out-of-date state, - * if your rendering state was too much "pre-configured" in advanced, you would - * have to "re-pre-configure" everything... or you should drop - * "pre-configuring" and program everything *again* for each swpchn img you - * draw. + * here we choose that any of those evts will be fatal for simplicity. for + * instance, if you choose to support the swpchn out-of-date state, if your + * rendering state was too much "pre-configured", you would have to + * "re-pre-configure" everything... or you should drop "pre-configuring" and + * program everything *again* for each swpchn img you draw. * * display programing is demonstrated "officially" in khronos vk cube.c and * there is a tutorial slide "1-Vulkan-Tutorial.pdf" (just abstract away c++ @@ -40,7 +44,7 @@ * different: * - only 1 "main" synchronous loop * - only xcb wsi. xcb is a client library on top of the x11 protocol. - * (we know wayland should be added...) + * we know wayland ("x12") should be added. * - dynamic loading of xcb. * - no need of vk headers (using directly the ABI with custom headers). * @@ -56,33 +60,43 @@ * pay the cost of transfering from 1 q fam to another q fam: then think twice * on how you want to spread your work load on the q fams. * - * we did change the name of some vk objs to make some areas more explicit. - * * for proper keyboard support, joypad way or/and text input way, read the * included KEYBOARD file. here, since we use basic layout independent standard * keys, the x11 core keyboard protocol is fairly enough. * * TODO: use as less as possible device memory object, namely try to allocate - * one big chunk and manage alignment constraint ourself. + * one big chunk and manage alignment constraint ourself. vk api does provide + * a way to query for the memory alignment constraints. */ #include #include - +#include #include "app_core_types.h" -#include "vk_types.h" +#include "nyanvk/consts.h" +#include "nyanvk/types.h" +#include "vk_app.h" #include "app_state_types.h" #include "log.h" - #include "vk_syms.c" #include "app_state.c" #include "xcb.c" - /*---------------------------------------------------------------------------*/ #include "namespace/app.c" #include "namespace/vk_syms.c" #include "namespace/app_state_types.h" #include "namespace/app_state.c" +/*---------------------------------------------------------------------------*/ +#define VK_FATAL(fmt, ...) \ +if (r < 0) {\ + LOG(fmt, ##__VA_ARGS__);\ + exit(1);\ +} +#define FATAL(fmt, ...) \ +{\ + LOG(fmt, ##__VA_ARGS__);\ + exit(1);\ +} /* the phydev q fam selected */ static void dev_create(void) { @@ -112,12 +126,8 @@ static void dev_create(void) info.q_create_infos = &q_info; info.enabled_exts_n = ARRAY_N(exts); info.enabled_ext_names = exts; - - r = vk_create_dev(surf_g.dev.phydev.vk, &info, 0, &surf_g.dev.vk); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:unable to create a vulkan device\n", r, surf_g.dev.phydev.vk); - exit(1); - } + vk_create_dev(&info); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:unable to create a vulkan device\n", r, surf_g.dev.phydev.vk) LOG("0:MAIN:physical device:%p:vulkan device created with one proper queue:%p\n", surf_g.dev.phydev.vk, surf_g.dev.vk); } @@ -144,17 +154,12 @@ static void instance_create(void) LOG("0:MAIN:will use vulkan instance_g extension %s\n", exts[i]); ++i; } - memset(&info, 0, sizeof(info)); - info.type = vk_struct_type_instance_create_info; info.enabled_exts_n = ARRAY_N(exts); info.enabled_ext_names = exts; - r = vk_create_instance(&info, 0, &instance_g); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:unable to create a vulkan instance_g\n", r); - exit(1); - } + vk_create_instance(&info); + VK_FATAL("0:MAIN:FATAL:%d:unable to create a vulkan instance_g\n", r) LOG("0:MAIN:vulkan instance_g handle %p\n", instance_g); } @@ -167,25 +172,18 @@ static void instance_exts_dump(void) s32 r; memset(exts, 0, sizeof(exts)); - n = EXTS_N_MAX; - - r = vk_enumerate_instance_ext_props(0, &n, exts); - + vk_enumerate_instance_ext_props(&n, exts); if (r != vk_success && r != vk_incomplete) { LOG("0:MAIN:ERROR:%d:unable to enumerate instance_g extension(s)\n", r); return; } - if (r == vk_incomplete) { LOG("0:MAIN:ERROR:too many extensions (%u/%u), dumping disabled", n, EXTS_N_MAX); return; } - /* vk_success */ - LOG("0:MAIN:have %u instance_g extension(s)\n", n); - loop { if (n == 0) break; @@ -204,25 +202,18 @@ static void instance_layers_dump(void) s32 r; memset(layers, 0, sizeof(layers)); - n = LAYERS_N_MAX; - - r = vk_enumerate_instance_layer_props(&n, layers); - + vk_enumerate_instance_layer_props(&n, layers); if (r != vk_success && r != vk_incomplete) { LOG("0:MAIN:ERROR:%d:unable to enumerate instance_g layer(s)\n", r); return; } - if (r == vk_incomplete) { LOG("0:MAIN:ERROR:too many layers (%u/%u), dumping disabled", n, LAYERS_N_MAX); return; } - /* vk_success */ - LOG("0:MAIN:have %u instance_g layer(s)\n", n); - loop { if (n == 0) break; @@ -239,32 +230,18 @@ static void tmp_phydevs_get(void) s32 r; memset(phydevs, 0, sizeof(phydevs)); - n = tmp_phydevs_n_max; - - r = vk_enumerate_phydevs(instance_g, &n, phydevs); - - if (r != vk_success && r != vk_incomplete) { - LOG("0:MAIN:FATAL:%ld:unable to enumerate physical devices\n",r); - exit(1); - } - - if (r == vk_incomplete) { - LOG("0:MAIN:FATAL:too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max); - exit(1); - } - + vk_enumerate_phydevs(&n, phydevs); + if (r != vk_success && r != vk_incomplete) + FATAL("0:MAIN:FATAL:%ld:unable to enumerate physical devices\n",r) + if (r == vk_incomplete) + FATAL("0:MAIN:FATAL:too many vulkan physical devices %u/%u for our temporary storage\n", n, tmp_phydevs_n_max) /* vk_success */ - LOG("0:MAIN:detected %u physical devices\n", n); - if (n == 0) { - LOG("0:MAIN:no vulkan physical devices, exiting\n"); - exit(1); - } - + if (n == 0) + FATAL("0:MAIN:no vulkan physical devices, exiting\n") tmp_phydevs_n_g = n; memset(tmp_phydevs_g, 0, sizeof(tmp_phydevs_g)); - n = 0; loop { if (n == tmp_phydevs_n_g) @@ -282,25 +259,18 @@ static void phydev_exts_dump(void *phydev) s32 r; memset(exts, 0, sizeof(exts)); - n = EXTS_N_MAX; - - r = vk_enumerate_dev_ext_props(phydev, 0, &n, exts); - + vk_enumerate_dev_ext_props(phydev, &n, exts); if (r != vk_success && r != vk_incomplete) { LOG("0:MAIN:ERROR:physical device:%p:%d:unable to enumerate device extension(s)\n", phydev, r); return; } - if (r == vk_incomplete) { LOG("0:MAIN:ERROR:physical device:%p:too many extensions (%u/%u), dumping disabled", phydev, n, EXTS_N_MAX); return; } - /* vk_success */ - LOG("0:MAIN:physical device:%p:have %u device extension(s)\n", phydev, n); - loop { if (n == 0) break; @@ -353,7 +323,6 @@ static u8 *uuid_str(u8 *uuid) break; /* XXX: always write a terminating 0, truncated or not */ snprintf(uuid_str + i * 2, 3, "%02x", uuid[i]); - ++i; } return uuid_str; @@ -370,14 +339,10 @@ static void tmp_phydevs_props_dump(void) if (i == tmp_phydevs_n_g) break; - p = &tmp_phydevs_g[i]; - memset(&props, 0, sizeof(props)); props.type = vk_struct_type_phydev_props; - vk_get_phydev_props(p->vk, &props); - LOG("0:MAIN:physical device:%p:properties:api version=%#x=%u.%u.%u\n", p->vk, props.core.api_version, VK_VERSION_MAJOR(props.core.api_version), VK_VERSION_MINOR(props.core.api_version), VK_VERSION_PATCH(props.core.api_version)); LOG("0:MAIN:physical device:%p:properties:driver version=%#x=%u.%u.%u\n", p->vk, props.core.driver_version, VK_VERSION_MAJOR(props.core.driver_version), VK_VERSION_MINOR(props.core.driver_version), VK_VERSION_PATCH(props.core.driver_version)); LOG("0:MAIN:physical device:%p:properties:vendor id=%#x\n", p->vk, props.core.vendor_id); @@ -388,7 +353,7 @@ static void tmp_phydevs_props_dump(void) else p->is_discret_gpu = false; LOG("0:MAIN:physical device:%p:properties:name=%s\n", p->vk, props.core.name); - LOG("0:MAIN:physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pipeline_cache_uuid)); + LOG("0:MAIN:physical device:%p:properties:pipeline cache uuid=%s\n", p->vk, uuid_str(props.core.pl_cache_uuid)); /* display the limits and sparse props at log level 1, if needed */ ++i; } @@ -401,11 +366,8 @@ static void tmp_phydev_q_fams_get(struct tmp_phydev_t *p) n = 0; vk_get_phydev_q_fam_props(p->vk, &n, 0); - if (n > tmp_phydev_q_fams_n_max) { - LOG("0:MAIN:FATAL:physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max); - exit(1); - } - + if (n > tmp_phydev_q_fams_n_max) + FATAL("0:MAIN:FATAL:physical device:%p:too many queue families %u/%u\n", p->vk, n, tmp_phydev_q_fams_n_max) memset(p->q_fams, 0, sizeof(p->q_fams)); i = 0; loop { @@ -414,7 +376,6 @@ static void tmp_phydev_q_fams_get(struct tmp_phydev_t *p) p->q_fams[i].type = vk_struct_type_q_fam_props; ++i; } - vk_get_phydev_q_fam_props(p->vk, &n, p->q_fams); p->q_fams_n = n; LOG("0:MAIN:physical device:%p:have %u queue families\n", p->vk, p->q_fams_n); @@ -451,32 +412,25 @@ static void tmp_phydev_q_fams_dump(struct tmp_phydev_t *p) LOG("0:MAIN:physical device:%p:queue family:%u:flags:sparse binding\n", p->vk, i); if ((p->q_fams[i].core.flags & vk_q_protected_bit) != 0) LOG("0:MAIN:physical device:%p:queue family:%u:flags:protected\n", p->vk, i); - - LOG("0:MAIN:physical device:%p:queue family:%u:%u queues\n", p->vk, i, p->q_fams[i].core.qs_n); LOG("0:MAIN:physical device:%p:queue family:%u:%u bits timestamps\n", p->vk, i, p->q_fams[i].core.timestamp_valid_bits); - LOG("0:MAIN:physical device:%p:queue family:%u:(width=%u,height=%u,depth=%u) minimum image transfer granularity\n", p->vk, i, p->q_fams[i].core.min_img_transfer_granularity.width, p->q_fams[i].core.min_img_transfer_granularity.height, p->q_fams[i].core.min_img_transfer_granularity.depth); ++i; } } -static void cmdpools_create(void) +static void cp_create(void) { s32 r; - struct vk_cmdpool_create_info_t info; + struct vk_cp_create_info_t info; memset(&info, 0, sizeof(info)); - info.type = vk_struct_type_cmdpool_create_info; - info.flags = vk_cmdpool_create_reset_cmdbuf_bit; + info.type = vk_struct_type_cp_create_info; + info.flags = vk_cp_create_reset_cb_bit; info.q_fam = surf_g.dev.phydev.q_fam; - - r = vk_create_cmdpool(&info, 0, &surf_g.dev.cmdpool); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:unable create the commmand pool\n", r); - exit(1); - } - LOG("0:MAIN:device:%p:queue family:%u:created command pool %p\n", surf_g.dev.vk, surf_g.dev.phydev.q_fam, surf_g.dev.cmdpool); + vk_create_cp(&info); + VK_FATAL("0:MAIN:FATAL:%d:unable create the commmand pool\n", r) + LOG("0:MAIN:device:%p:queue family:%u:created command pool %p\n", surf_g.dev.vk, surf_g.dev.phydev.q_fam, surf_g.dev.cp); } static void tmp_phydevs_q_fams_dump(void) @@ -495,7 +449,7 @@ static void tmp_phydevs_q_fams_dump(void) static void q_get(void) { LOG("0:MAIN:device:%p:getting queue:family=%u queue=0\n", surf_g.dev.vk, surf_g.dev.phydev.q_fam); - vk_get_dev_q(surf_g.dev.phydev.q_fam, 0, &surf_g.dev.q); + vk_get_dev_q(); LOG("0:MAIN:device:%p:got queue:%p\n", surf_g.dev.vk, surf_g.dev.q); } @@ -504,17 +458,13 @@ static void check_vk_version(void) u32 api_version; s32 r; - r = vk_enumerate_instance_version(&api_version); - if (r != vk_success) { - LOG("0:MAIN:FATAL:%d:unable to enumerate instance_g version\n", r); - exit(1); - } + vk_enumerate_instance_version(&api_version); + if (r != vk_success) + FATAL("0:MAIN:FATAL:%d:unable to enumerate instance_g version\n", r) LOG("0:MAIN:vulkan instance_g version %#x = %u.%u.%u\n", api_version, VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), VK_VERSION_PATCH(api_version)); if (VK_VERSION_MAJOR(api_version) == 1 - && VK_VERSION_MINOR(api_version) == 0) { - LOG("0:MAIN:FATAL:vulkan instance_g version too old\n"); - exit(1); - } + && VK_VERSION_MINOR(api_version) == 0) + FATAL("0:MAIN:FATAL:vulkan instance_g version too old\n") } /* * the major obj to use in vk abstraction of gfx hardware is the q. In this @@ -534,9 +484,7 @@ static void tmp_phydevs_q_fams_surf_support_get(void) if (i == tmp_phydevs_n_g) break; - p = &tmp_phydevs_g[i]; - j = 0; loop { s32 r; @@ -544,15 +492,9 @@ static void tmp_phydevs_q_fams_surf_support_get(void) if (j == p->q_fams_n) break; - supported = vk_false; - r = vk_get_phydev_surf_support(p->vk, j, surf_g.vk, - &supported); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:queue family:%u:surface:%p:unable to query queue family wsi/(image presentation to our surface) support\n", r, p->vk, j, surf_g.vk); - exit(1); - } - + vk_get_phydev_surf_support(p->vk, j, &supported); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:queue family:%u:surface:%p:unable to query queue family wsi/(image presentation to our surface) support\n", r, p->vk, j, surf_g.vk) if (supported == vk_true) { LOG("0:MAIN:physical device:%p:queue family:%u:surface:%p:does support wsi/(image presentation to our surface) \n", p->vk, j, surf_g.vk); p->q_fams_surf_support[j] = true; @@ -571,7 +513,6 @@ static void tmp_selected_phydev_cherry_pick(u8 i) struct tmp_phydev_t *p; p = &tmp_phydevs_g[i]; - surf_g.dev.phydev.vk = p->vk; surf_g.dev.phydev.is_discret_gpu = p->is_discret_gpu; surf_g.dev.phydev.mem_types_n = p->mem_props.core.mem_types_n; @@ -596,9 +537,7 @@ static void tmp_phydev_and_q_fam_select(void) if (i == tmp_phydevs_n_g) break; - p = &tmp_phydevs_g[i]; - j = 0; loop { if (j == p->q_fams_n) @@ -633,17 +572,12 @@ static void surf_create(void) s32 r; memset(&surf_g, 0, sizeof(surf_g)); - memset(&xcb_info, 0, sizeof(xcb_info)); xcb_info.type = vk_struct_type_xcb_surf_create_info; xcb_info.c = app_xcb.c; xcb_info.win = app_xcb.win_id; - - r = vk_create_xcb_surf(instance_g, &xcb_info, 0, &surf_g.vk); - if (r < 0) {/* ok because this enum is forded to a signed 32 bits */ - LOG("0:MAIN:FATAL:%d:xcb:%s:screen:%d:root window id:%#x:window id:%#x:unable to create a vulkan surface from this x11 window\n", r, app_xcb.disp_env, app_xcb.scr_idx, app_xcb.scr->root, app_xcb.win_id); - exit(1); - } + vk_create_xcb_surf(&xcb_info); + VK_FATAL("0:MAIN:FATAL:%d:xcb:%s:screen:%d:root window id:%#x:window id:%#x:unable to create a vulkan surface from this x11 window\n", r, app_xcb.disp_env, app_xcb.scr_idx, app_xcb.scr->root, app_xcb.win_id) LOG("0:MAIN:xcb:'%s':screen:%d:root window id:%#x:window id:%#x:created vk_surface=%p\n", app_xcb.disp_env, app_xcb.scr_idx, app_xcb.scr->root, app_xcb.win_id, surf_g.vk); } @@ -678,18 +612,10 @@ static void texel_mem_blk_conf_select(void) memset(&info, 0, sizeof(info)); info.type = vk_struct_type_phydev_surf_info; info.surf = surf_g.vk; - - r = vk_get_phydev_surf_texel_mem_blk_confs(surf_g.dev.phydev.vk, &info, - &confs_n, 0); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable get the count of valid surface texel memory block configurations\n", r, surf_g.dev.phydev.vk, surf_g.vk); - exit(1); - } - - if (confs_n > CONFS_N_MAX) { - LOG("0:MAIN:FATAL:physical device:%p:surface:%p:too many surface texel memory block configurations %u/%u\n", surf_g.dev.phydev.vk, surf_g.vk, confs_n, CONFS_N_MAX); - exit(1); - } + vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, 0); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable get the count of valid surface texel memory block configurations\n", r, surf_g.dev.phydev.vk, surf_g.vk) + if (confs_n > CONFS_N_MAX) + FATAL("0:MAIN:FATAL:physical device:%p:surface:%p:too many surface texel memory block configurations %u/%u\n", surf_g.dev.phydev.vk, surf_g.vk, confs_n, CONFS_N_MAX) memset(confs, 0, sizeof(confs[0]) * confs_n); i = 0; @@ -699,29 +625,18 @@ static void texel_mem_blk_conf_select(void) confs[i].type = vk_struct_type_surf_texel_mem_blk_conf; ++i; } - - r = vk_get_phydev_surf_texel_mem_blk_confs(surf_g.dev.phydev.vk, &info, - &confs_n, confs); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable get the valid surface texel memory block configurations\n", r, surf_g.dev.phydev.vk, surf_g.vk); - exit(1); - } - - if (confs_n == 0) { - LOG("0:MAIN:FATAL:physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_g.dev.phydev.vk, surf_g.vk); - exit(1); - } - + vk_get_phydev_surf_texel_mem_blk_confs(&info, &confs_n, confs); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable get the valid surface texel memory block configurations\n", r, surf_g.dev.phydev.vk, surf_g.vk) + if (confs_n == 0) + FATAL("0:MAIN:FATAL:physical device:%p:surface:%p:no valid surface texel memory block configuration\n", surf_g.dev.phydev.vk, surf_g.vk) texel_mem_blk_confs_dump(confs_n, confs); cc = &surf_g.dev.phydev.selected_texel_mem_blk_conf_core; - if ((confs_n == 1) && (confs[0].core.fmt == vk_texel_mem_blk_fmt_undefined)) { /* this means the dev let us choose our the fmt */ cc->fmt = vk_texel_mem_blk_fmt_b8g8r8a8_srgb; LOG("0:MAIN:physical device:%p:surface:%p:using our surface texel memory block format %u\n", surf_g.dev.phydev.vk, surf_g.vk, cc->fmt); - cc->color_space = vk_color_space_srgb_nonlinear; LOG("0:MAIN:physical device:%p:surface:%p:using prefered surface texel memory block color space %u\n", surf_g.dev.phydev.vk, surf_g.vk, cc->color_space); } else { @@ -729,7 +644,6 @@ static void texel_mem_blk_conf_select(void) surf_g.dev.phydev.selected_texel_mem_blk_conf_core.fmt = confs[0].core.fmt; LOG("0:MAIN:physical device:%p:surface:%p:using prefered surface texel memory block format %u\n", surf_g.dev.phydev.vk, surf_g.vk, surf_g.dev.phydev.selected_texel_mem_blk_conf_core.fmt); - cc->color_space = confs[0].core.color_space; LOG("0:MAIN:physical device:%p:surface:%p:using prefered surface texel memory block color space %u\n", surf_g.dev.phydev.vk, surf_g.vk, cc->color_space); } @@ -739,7 +653,6 @@ static void tmp_phydev_mem_props_get(struct tmp_phydev_t *p) { memset(&p->mem_props, 0, sizeof(p->mem_props)); p->mem_props.type = vk_struct_type_phydev_mem_props; - vk_get_phydev_mem_props(p->vk, &p->mem_props); } @@ -785,7 +698,6 @@ static void tmp_phydev_mem_types_dump(struct tmp_phydev_t *p) u8 i; LOG("0:MAIN:physical device:%p:%u memory types\n", p->vk, p->mem_props.core.mem_types_n); - i = 0; loop { if (i == p->mem_props.core.mem_types_n) @@ -801,7 +713,6 @@ static void tmp_phydev_mem_heaps_dump(struct tmp_phydev_t *p) u8 i; LOG("0:MAIN:physical device:%p:%u memory heaps\n", p->vk, p->mem_props.core.mem_heaps_n); - i = 0; loop { if (i == p->mem_props.core.mem_heaps_n) @@ -840,18 +751,11 @@ static void tmp_surf_caps_get(void) memset(&info, 0, sizeof(info)); info.type = vk_struct_type_phydev_surf_info; info.surf = surf_g.vk; - - r = vk_get_phydev_surf_caps(surf_g.dev.phydev.vk, &info, &tmp_surf_caps_g); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable to get our surface capabilities in the context of the selected physical device\n", r, surf_g.dev.phydev.vk, surf_g.vk); - exit(1); - } - + vk_get_phydev_surf_caps(&info); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable to get our surface capabilities in the context of the selected physical device\n", r, surf_g.dev.phydev.vk, surf_g.vk) /* we have room for a maximum of 3 images per swapchain */ - if (tmp_surf_caps_g.core.imgs_n_min > swpchn_imgs_n_max) { - LOG("0:MAIN:FATAL:physical device:%p:surface:%p:we have room for %u images per swapchain, but this swapchain requires a minimum of %u images\n", surf_g.dev.phydev.vk, surf_g.vk, swpchn_imgs_n_max, tmp_surf_caps_g.core.imgs_n_min); - exit(1); - } + if (tmp_surf_caps_g.core.imgs_n_min > swpchn_imgs_n_max) + FATAL("0:MAIN:FATAL:physical device:%p:surface:%p:we have room for %u images per swapchain, but this swapchain requires a minimum of %u images\n", surf_g.dev.phydev.vk, surf_g.vk, swpchn_imgs_n_max, tmp_surf_caps_g.core.imgs_n_min) } static void tmp_surf_caps_dump(void) @@ -873,12 +777,8 @@ static void swpchn_imgs_get(void) s32 r; surf_g.dev.swpchn.imgs_n = swpchn_imgs_n_max; - r = vk_get_swpchn_imgs(surf_g.dev.swpchn.vk, &surf_g.dev.swpchn.imgs_n, - surf_g.dev.swpchn.imgs); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:surface:%p:swapchain:%p:unable to get the swapchain images\n", r, surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk); - exit(1); - } + vk_get_swpchn_imgs(); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:surface:%p:swapchain:%p:unable to get the swapchain images\n", r, surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk) LOG("0:MAIN:device:%p:surface:%p:swapchain:%p:got %u swapchain images\n", surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk, surf_g.dev.swpchn.imgs_n); } @@ -889,9 +789,7 @@ static void swpchn_init(void) s32 r; memset(&info, 0, sizeof(info)); - p = &surf_g.dev.phydev; - info.type = vk_struct_type_swpchn_create_info; info.surf = surf_g.vk; info.imgs_n_min = tmp_surf_caps_g.core.imgs_n_min; @@ -907,12 +805,8 @@ static void swpchn_init(void) info.composite_alpha = vk_composite_alpha_opaque_bit; info.present_mode = vk_present_mode_fifo; info.clipped = vk_true; - - r = vk_create_swpchn(&info, 0, &surf_g.dev.swpchn.vk); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:surface:%p:unable to create the initial swapchain\n", r, surf_g.dev.vk, surf_g.vk); - exit(1); - } + vk_create_swpchn(&info); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:surface:%p:unable to create the initial swapchain\n", r, surf_g.dev.vk, surf_g.vk) LOG("0:MAIN:device:%p:surface:%p:swapchain created %p\n", surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk); } @@ -921,13 +815,8 @@ static void tmp_present_modes_get(void) s32 r; tmp_present_modes_n_g = tmp_present_modes_n_max; - - r = vk_get_phydev_surf_present_modes(surf_g.dev.phydev.vk, surf_g.vk, - &tmp_present_modes_n_g, tmp_present_modes_g); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable to get the physical device present mode for our surface\n", r, surf_g.dev.phydev.vk, surf_g.vk); - exit(1); - } + vk_get_phydev_surf_present_modes(); + VK_FATAL("0:MAIN:FATAL:%d:physical device:%p:surface:%p:unable to get the physical device present mode for our surface\n", r, surf_g.dev.phydev.vk, surf_g.vk) } static u8 *present_mode_to_str(u32 mode) @@ -966,7 +855,6 @@ static void cpu_img_create(u8 i) s32 r; memset(&info, 0, sizeof(info)); - info.type = vk_struct_type_img_create_info; info.flags = vk_img_create_flag_2d_array_compatible_bit; info.img_type = vk_img_type_2d; @@ -980,12 +868,8 @@ static void cpu_img_create(u8 i) info.img_tiling = vk_img_tiling_linear; info.usage = vk_img_usage_transfer_src_bit; info.initial_layout = vk_img_layout_undefined; - - r = vk_create_img(&info, 0, &surf_g.dev.cpu_imgs[i].vk); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:unable to create swapchain cpu image %u\n", r, surf_g.dev.vk, i); - exit(1); - } + vk_create_img(&info, &surf_g.dev.cpu_imgs[i].vk); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create swapchain cpu image %u\n", r, surf_g.dev.vk, i) LOG("0:MAIN:device:%p:swapchain cpu image %u created %p\n", surf_g.dev.vk, i, surf_g.dev.cpu_imgs[i].vk); } @@ -1005,55 +889,36 @@ static void cpu_imgs_create(void) static void img_mem_barrier_run_once(u8 i, struct vk_img_mem_barrier_t *b) { s32 r; - struct vk_cmdbuf_begin_info_t begin_info; + struct vk_cb_begin_info_t begin_info; struct vk_submit_info_t submit_info; memset(&begin_info, 0, sizeof(begin_info)); - begin_info.type = vk_struct_type_cmdbuf_begin_info; - begin_info.flags = vk_cmdbuf_usage_one_time_submit_bit; - - r = vk_begin_cmdbuf(surf_g.dev.cmdbufs[i], &begin_info); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:command buffer:%p:unable to begin recording the initial layout transition command buffer\n", r, surf_g.dev.cmdbufs[i]); - exit(1); - } + begin_info.type = vk_struct_type_cb_begin_info; + begin_info.flags = vk_cb_usage_one_time_submit_bit; + vk_begin_cb(surf_g.dev.cbs[i], &begin_info); + VK_FATAL("0:MAIN:FATAL:%d:command buffer:%p:unable to begin recording the initial layout transition command buffer\n", r, surf_g.dev.cbs[i]) /*--------------------------------------------------------------------*/ - vk_cmd_pipeline_barrier(app_surf.dev.cmdbufs[i], - vk_pipeline_stage_top_of_pipe_bit, - vk_pipeline_stage_top_of_pipe_bit, 0, 0, 0, 0, 0, 1, b); + vk_cmd_pl_barrier(app_surf.dev.cbs[i], b); /*--------------------------------------------------------------------*/ - r = vk_end_cmdbuf(surf_g.dev.cmdbufs[i]); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:command buffer:%p:unable to end recording of the initial layout transition command buffer\n", r, surf_g.dev.cmdbufs[i]); - exit(1); - } + vk_end_cb(surf_g.dev.cbs[i]); + VK_FATAL("0:MAIN:FATAL:%d:command buffer:%p:unable to end recording of the initial layout transition command buffer\n", r, surf_g.dev.cbs[i]) /*--------------------------------------------------------------------*/ memset(&submit_info, 0, sizeof(submit_info)); submit_info.type = vk_struct_type_submit_info; - submit_info.cmdbufs_n = 1; - submit_info.cmdbufs = &surf_g.dev.cmdbufs[i]; - - r = vk_q_submit(surf_g.dev.q, 1, &submit_info, 0); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:queue:%p:unable to submit the initial layout transition command buffer\n", r, surf_g.dev.q); - exit(1); - } + submit_info.cbs_n = 1; + submit_info.cbs = &surf_g.dev.cbs[i]; + vk_q_submit(&submit_info); + VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the initial layout transition command buffer\n", r, surf_g.dev.q) /*--------------------------------------------------------------------*/ - r = vk_q_wait_idle(surf_g.dev.q); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:queue:%p:unable to wait for idle or completion of initial layout transition command buffer\n", r, surf_g.dev.q); - exit(1); - } + vk_q_wait_idle(); + VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to wait for idle or completion of initial layout transition command buffer\n", r, surf_g.dev.q) /*--------------------------------------------------------------------*/ /* * since it is tagged to run once its state_g is invalid, we need to * reset it to the initial state_g */ - r = vk_reset_cmdbuf(surf_g.dev.cmdbufs[i], 0); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:command buffer:%p:unable to reset the initial layout transition command buffer\n", r, surf_g.dev.cmdbufs[i]); - exit(1); - } + vk_reset_cb(surf_g.dev.cbs[i]); + VK_FATAL("0:MAIN:FATAL:%d:command buffer:%p:unable to reset the initial layout transition command buffer\n", r, surf_g.dev.cbs[i]) } static void cpu_img_layout_to_general(u8 i) @@ -1068,12 +933,10 @@ static void cpu_img_layout_to_general(u8 i) b.src_q_fam = vk_q_fam_ignored; b.dst_q_fam = vk_q_fam_ignored; b.img = surf_g.dev.cpu_imgs[i].vk; - r = &b.subrsrc_range; r->aspect = vk_img_aspect_color_bit; r->lvls_n = 1; r->array_layers_n = 1; - img_mem_barrier_run_once(i, &b); LOG("0:MAIN:cpu image:%p[%u]:transition to general layout successful\n", surf_g.dev.cpu_imgs[i].vk, i); } @@ -1101,16 +964,11 @@ static void tmp_cpu_img_mem_rqmts_get(u8 i) memset(&info, 0, sizeof(info)); info.type = vk_struct_type_img_mem_rqmts_info; info.img = surf_g.dev.cpu_imgs[i].vk; - rqmts = &tmp_mem_rqmts_g[i]; memset(rqmts, 0, sizeof(*rqmts)); rqmts->type = vk_struct_type_mem_rqmts; - - r = vk_get_img_mem_rqmts(&info, rqmts); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:unable to get memory requirements for cpu image %u\n", r, surf_g.dev.vk, i); - exit(1); - } + vk_get_img_mem_rqmts(&info, rqmts); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to get memory requirements for cpu image %u\n", r, surf_g.dev.vk, i) LOG("0:MAIN:device:%p:cpu image %u core requirements are size=%lu bytes, alignment=%lu bytes, memory type=%#08x\n", surf_g.dev.vk, i, (long)rqmts->core.sz, (long)rqmts->core.alignment, rqmts->core.mem_type_bits); } @@ -1138,13 +996,10 @@ static bool match_mem_type(u8 mem_type_idx, /* first check this mem type is in our img rqmts */ if (((1 << mem_type_idx) & img_rqmts->core.mem_type_bits) == 0) return false; - mem_type = &surf_g.dev.phydev.mem_types[mem_type_idx]; - if (!ignore_gpu_is_discret) if (surf_g.dev.phydev.is_discret_gpu && IS_DEV_LOCAL(mem_type)) return false; - if ((mem_type->prop_flags & WANTED_MEM_PROPS) == WANTED_MEM_PROPS) return true; return false; @@ -1162,8 +1017,7 @@ static bool try_alloc_cpu_img_dev_mem(u8 i, info.type = vk_struct_type_mem_alloc_info; info.sz = img_rqmts->core.sz; info.mem_type_idx = mem_type_idx; - - r = vk_alloc_mem(&info, 0, &surf_g.dev.cpu_imgs[i].dev_mem); + vk_alloc_mem(&info, &surf_g.dev.cpu_imgs[i].dev_mem); if (r < 0) { LOG("0:MAIN:WARNING:%d:device:%p:cpu image:%u:unable to allocate %lu bytes from physical dev %p memory type %u\n", r, surf_g.dev.vk, img_rqmts->core.sz, surf_g.dev.phydev.vk, mem_type_idx); return false; @@ -1185,12 +1039,10 @@ static void cpu_img_dev_mem_alloc(u8 i) u8 mem_type; img_rqmts = &tmp_mem_rqmts_g[i]; - mem_type = 0; loop { if (mem_type == surf_g.dev.phydev.mem_types_n) break; - if (match_mem_type(mem_type, img_rqmts, !IGNORE_GPU_IS_DISCRET)) { if (try_alloc_cpu_img_dev_mem(i, img_rqmts, @@ -1199,12 +1051,8 @@ static void cpu_img_dev_mem_alloc(u8 i) } ++mem_type; } - - if (!surf_g.dev.phydev.is_discret_gpu) { - LOG("0:MAIN:FATAL:physical device:%p:cpu image:%u:unable to find proper memory type or to allocate memory\n", surf_g.dev.phydev.vk, i); - exit(1); - } - + if (!surf_g.dev.phydev.is_discret_gpu) + FATAL("0:MAIN:FATAL:physical device:%p:cpu image:%u:unable to find proper memory type or to allocate memory\n", surf_g.dev.phydev.vk, i) /* * lookup again, but relax the match based on discret gpu constraint for * gpu @@ -1213,14 +1061,12 @@ static void cpu_img_dev_mem_alloc(u8 i) loop { if (mem_type == surf_g.dev.phydev.mem_types_n) break; - if (match_mem_type(mem_type, img_rqmts, IGNORE_GPU_IS_DISCRET) && try_alloc_cpu_img_dev_mem(i, img_rqmts, mem_type)) return; ++mem_type; } - LOG("0:MAIN:FATAL:physical device:%p:cpu image:%u:unable to find proper memory type or to allocate memory\n", surf_g.dev.phydev.vk, i); - exit(1); + FATAL("0:MAIN:FATAL:physical device:%p:cpu image:%u:unable to find proper memory type or to allocate memory\n", surf_g.dev.phydev.vk, i) } #undef IGNORE_GPU_IS_DISCRET @@ -1244,7 +1090,6 @@ static void cpu_imgs_dev_mem_bind(void) s32 r; memset(&infos, 0, sizeof(infos[0]) * surf_g.dev.swpchn.imgs_n); - i = 0; loop { if (i == surf_g.dev.swpchn.imgs_n) @@ -1254,11 +1099,8 @@ static void cpu_imgs_dev_mem_bind(void) infos[i].mem = surf_g.dev.cpu_imgs[i].dev_mem; ++i; } - r = vk_bind_img_mem(surf_g.dev.swpchn.imgs_n, infos); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:cpu images:unable to bind device memory to images\n", r, surf_g.dev.vk); - exit(1); - } + vk_bind_img_mem(infos); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:cpu images:unable to bind device memory to images\n", r, surf_g.dev.vk) LOG("0:MAIN:device:%p:cpu images:bound device memory to images\n", surf_g.dev.vk); } @@ -1272,12 +1114,9 @@ static void cpu_imgs_dev_mem_map(void) if (i == surf_g.dev.swpchn.imgs_n) break; - r = vk_map_mem(surf_g.dev.cpu_imgs[i].dev_mem, 0, vk_whole_sz, 0, + vk_map_mem(surf_g.dev.cpu_imgs[i].dev_mem, &surf_g.dev.cpu_imgs[i].data); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:cpu image:%u:unable to map image memory\n", r, surf_g.dev.vk, i); - exit(1); - } + VK_FATAL("0:MAIN:FATAL:%d:device:%p:cpu image:%u:unable to map image memory\n", r, surf_g.dev.vk, i) LOG("0:MAIN:device:%p:cpu image:%u:image memory mapped\n", surf_g.dev.vk, i); ++i; } @@ -1288,10 +1127,8 @@ static void cpu_img_subrsrc_layout_get(u8 i) struct vk_img_subrsrc_t s; memset(&s, 0, sizeof(s)); - /* 1 subrsrc = uniq color plane of mip lvl 0 and array 0 */ s.aspect = vk_img_aspect_color_bit; - vk_get_img_subrsrc_layout(surf_g.dev.cpu_imgs[i].vk, &s, &surf_g.dev.cpu_imgs[i].layout); LOG("0:MAIN:device:%p:cpu image:%u:layout:offset=%lu bytes size=%lu bytes row_pitch=%lu bytes array_pitch=%lu bytes depth_pitch=%lu bytes\n", surf_g.dev.vk, i, surf_g.dev.cpu_imgs[i].layout.offset, surf_g.dev.cpu_imgs[i].layout.sz, surf_g.dev.cpu_imgs[i].layout.row_pitch, surf_g.dev.cpu_imgs[i].layout.array_pitch, surf_g.dev.cpu_imgs[i].layout.depth_pitch); @@ -1320,56 +1157,41 @@ static void sems_create(void) loop { if (sem == sems_n) break; - memset(&info, 0, sizeof(info)); info.type = vk_struct_type_sem_create_info; - - r = vk_create_sem(&info, 0, &surf_g.dev.sems[sem]); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:unable to create a semaphore %u for our swapchain\n", r, surf_g.dev.vk, sem); - exit(1); - } + vk_create_sem(&info, &surf_g.dev.sems[sem]); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create a semaphore %u for our swapchain\n", r, surf_g.dev.vk, sem) LOG("0:MAIN:device:%p:semaphore %u for our swapchain created %p\n", surf_g.dev.vk, sem, surf_g.dev.sems[sem]); - ++sem; } } -static void cmdbufs_create(void) +static void cbs_create(void) { s32 r; - struct vk_cmdbuf_alloc_info_t alloc_info; + struct vk_cb_alloc_info_t alloc_info; memset(&alloc_info, 0, sizeof(alloc_info)); - alloc_info.type = vk_struct_type_cmdbuf_alloc_info; - alloc_info.cmdpool = surf_g.dev.cmdpool; - alloc_info.lvl = vk_cmdbuf_lvl_primary; - alloc_info.cmdbufs_n = surf_g.dev.swpchn.imgs_n; - - r = vk_alloc_cmdbufs(&alloc_info, surf_g.dev.cmdbufs); - - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:unable to allocate command buffers for our swapchain images from %p command pool\n", r, surf_g.dev.vk, surf_g.dev.cmdpool); - exit(1); - } - LOG("0:MAIN:device:%p:allocated %u command buffers for our swapchain images from %p command pool\n", surf_g.dev.vk, surf_g.dev.swpchn.imgs_n, surf_g.dev.cmdpool); + alloc_info.type = vk_struct_type_cb_alloc_info; + alloc_info.cp = surf_g.dev.cp; + alloc_info.lvl = vk_cb_lvl_primary; + alloc_info.cbs_n = surf_g.dev.swpchn.imgs_n; + vk_alloc_cbs(&alloc_info); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to allocate command buffers for our swapchain images from %p command pool\n", r, surf_g.dev.vk, surf_g.dev.cp) + LOG("0:MAIN:device:%p:allocated %u command buffers for our swapchain images from %p command pool\n", surf_g.dev.vk, surf_g.dev.swpchn.imgs_n, surf_g.dev.cp); } -static void cmdbuf_record(u8 i) +static void cb_rec(u8 i) { s32 r; - struct vk_cmdbuf_begin_info_t begin_info; + struct vk_cb_begin_info_t begin_info; struct vk_img_mem_barrier_t b; struct vk_img_blit_t region; /*--------------------------------------------------------------------*/ memset(&begin_info, 0, sizeof(begin_info)); - begin_info.type = vk_struct_type_cmdbuf_begin_info; - - r = vk_begin_cmdbuf(surf_g.dev.cmdbufs[i], &begin_info); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to begin recording\n", r, i, surf_g.dev.cmdbufs[i]); - exit(1); - } + begin_info.type = vk_struct_type_cb_begin_info; + vk_begin_cb(surf_g.dev.cbs[i], &begin_info); + VK_FATAL("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to begin recording\n", r, i, surf_g.dev.cbs[i]) /*--------------------------------------------------------------------*/ /* acquired img (undefined layout) to presentation layout */ memset(&b, 0, sizeof(b)); @@ -1379,14 +1201,10 @@ static void cmdbuf_record(u8 i) b.src_q_fam = vk_q_fam_ignored; b.dst_q_fam = vk_q_fam_ignored; b.img = surf_g.dev.swpchn.imgs[i]; - b.subrsrc_range.aspect = vk_img_aspect_color_bit; b.subrsrc_range.lvls_n = 1; b.subrsrc_range.array_layers_n = 1; - - vk_cmd_pipeline_barrier(surf_g.dev.cmdbufs[i], - vk_pipeline_stage_top_of_pipe_bit, - vk_pipeline_stage_top_of_pipe_bit, 0, 0, 0, 0, 0, 1, &b); + vk_cmd_pl_barrier(surf_g.dev.cbs[i], &b); /*--------------------------------------------------------------------*/ /* blit from cpu img to pe img */ memset(®ion, 0, sizeof(region)); @@ -1396,21 +1214,17 @@ static void cmdbuf_record(u8 i) region.src_offsets[1].y = APP_CPU_IMG_HEIGHT; region.dst_subrsrc.aspect = vk_img_aspect_color_bit; region.dst_subrsrc.array_layers_n = 1; + /* XXX: it is a scaling blit: you can use APP_WIN_WIDTH/APP_WIN_HEIGHT */ region.dst_offsets[1].x = APP_CPU_IMG_WIDTH; region.dst_offsets[1].y = APP_CPU_IMG_HEIGHT; - - vk_cmd_blit_img(surf_g.dev.cmdbufs[i], surf_g.dev.cpu_imgs[i].vk, - vk_img_layout_general, surf_g.dev.swpchn.imgs[i], - vk_img_layout_present, 1, ®ion, 0); + vk_cmd_blit_img(surf_g.dev.cbs[i], surf_g.dev.cpu_imgs[i].vk, + surf_g.dev.swpchn.imgs[i], ®ion); /*--------------------------------------------------------------------*/ - r = vk_end_cmdbuf(surf_g.dev.cmdbufs[i]); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to end recording\n", r, i, surf_g.dev.cmdbufs[i]); - exit(1); - } + vk_end_cb(surf_g.dev.cbs[i]); + VK_FATAL("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to end recording\n", r, i, surf_g.dev.cbs[i]) } -static void cmdbufs_record(void) +static void cbs_rec(void) { u8 i; @@ -1418,7 +1232,7 @@ static void cmdbufs_record(void) loop { if (i == surf_g.dev.swpchn.imgs_n) break; - cmdbuf_record(i); + cb_rec(i); ++i; } } @@ -1454,7 +1268,7 @@ static void dev_init(void) dev_create(); dev_syms(); q_get(); - cmdpools_create(); + cp_create(); } static void surf_init(void) @@ -1463,18 +1277,17 @@ static void surf_init(void) dev_init(); swpchn_init(); swpchn_imgs_get(); - /* our cpu imgs for swpchn imgs */ cpu_imgs_create(); sems_create(); - cmdbufs_create(); + cbs_create(); cpu_imgs_layout_to_general(); cpu_imgs_subrsrc_layout_get(); tmp_cpu_imgs_mem_rqmts_get(); cpu_imgs_dev_mem_alloc(); cpu_imgs_dev_mem_bind(); cpu_imgs_dev_mem_map(); - cmdbufs_record(); + cbs_rec(); } static void init_vk(void) @@ -1503,13 +1316,8 @@ static void swpchn_acquire_next_img(u32 *i) info.timeout = u64_max; /* infinite */ info.devs = 0x00000001; /* no device group then 1 */ info.sem = surf_g.dev.sems[sem_acquire_img_done]; - - r = vk_acquire_next_img(&info, i); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:device:%p:unable to acquire next image from swapchain %p\n", r, surf_g.dev.vk, surf_g.dev.swpchn.vk); - exit(1); - } - /* XXX:TRACE */ + vk_acquire_next_img(&info, i); + VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to acquire next image from swapchain %p\n", r, surf_g.dev.vk, surf_g.dev.swpchn.vk) LOG("0:MAIN:device:%p:swapchain:%p:acquired image %u\n", surf_g.dev.vk, surf_g.dev.swpchn.vk, *i); } @@ -1529,18 +1337,14 @@ static void cpu_img_draw(u8 i) loop { struct vk_subrsrc_layout_t *l; u64 o; /* _byte_ offset */ - u64 o_dw; /* _32 bits_ dword offset */ + u64 o_w; /* _32 bits_ word offset */ if (col == APP_CPU_IMG_WIDTH) break; - l = &surf_g.dev.cpu_imgs[i].layout; - o = row * l->row_pitch + col * sizeof(*texel); - o_dw = o >> 2; - - texel[o_dw] = fill_texel_g; - + o_w = o >> 2; + texel[o_w] = fill_texel_g; ++col; } ++row; @@ -1552,22 +1356,23 @@ static void cpu_img_to_pe(u8 i) s32 r; struct vk_submit_info_t submit_info; struct vk_present_info_t present_info; + u32 wait_dst_stage; u32 idxs[1]; memset(&submit_info, 0, sizeof(submit_info)); submit_info.type = vk_struct_type_submit_info; submit_info.wait_sems_n = 1; submit_info.wait_sems = &surf_g.dev.sems[sem_acquire_img_done]; - submit_info.cmdbufs_n = 1; - submit_info.cmdbufs = &surf_g.dev.cmdbufs[i]; + wait_dst_stage = vk_pl_stage_bottom_of_pipe_bit; + submit_info.wait_dst_stages = &wait_dst_stage; + submit_info.cbs_n = 1; + submit_info.cbs = &surf_g.dev.cbs[i]; submit_info.signal_sems_n = 1; submit_info.signal_sems = &surf_g.dev.sems[app_sem_blit_done]; + LOG("MAIN:queue:%p\n", surf_g.dev.q); - r = vk_q_submit(surf_g.dev.q, 1, &submit_info, 0); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:queue:%p:unable to submit the image pre-recorded command buffer\n", r, surf_g.dev.q); - exit(1); - } + vk_q_submit(&submit_info); + VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the image pre-recorded command buffer\n", r, surf_g.dev.q) /*--------------------------------------------------------------------*/ idxs[0] = i; memset(&present_info, 0, sizeof(present_info)); @@ -1578,12 +1383,8 @@ static void cpu_img_to_pe(u8 i) present_info.swpchns = &surf_g.dev.swpchn.vk; present_info.idxs = idxs; present_info.results = 0; - - r = vk_q_present(surf_g.dev.q, &present_info); - if (r < 0) { - LOG("0:MAIN:FATAL:%d:queue:%p:unable to submit the image %u to the presentation engine\n", r, surf_g.dev.q, i); - exit(1); - } + vk_q_present(&present_info); + VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the image %u to the presentation engine\n", r, surf_g.dev.q, i) } static void render(void) @@ -1593,7 +1394,6 @@ static void render(void) swpchn_acquire_next_img(&i); cpu_img_draw(i); /* cpu rendering */ cpu_img_to_pe(i); - do_render_g = false; if (fill_texel_g == 0x0000ff00) fill_texel_g = 0x00ff0000; @@ -1601,7 +1401,6 @@ static void render(void) fill_texel_g = 0x0000ff00; } -/* "main" loop */ static void run(void) { state_g = state_run; @@ -1609,26 +1408,21 @@ static void run(void) xcb_generic_event_t *e; do_render_g = false; - /* "evts which could lead to change what we display" */ e = dl_xcb_wait_for_event(app_xcb.c); if (e == 0) { /* i/o err */ LOG("0:MAIN:xcb:'%s':connection:%p:event:input/output error | x11 server connection lost\n", app_xcb.disp_env, app_xcb.c); break; } - loop { /* drain evts */ app_xcb_evt_handle(e); free(e); - if (state_g == state_quit) return; - e = dl_xcb_poll_for_event(app_xcb.c); if (e == 0) break; } - /* synchronous rendering */ if (do_render_g) render(); @@ -1645,8 +1439,14 @@ int main(void) LOG("0:exiting app\n"); exit(0); } +#undef VK_FATAL +#undef FATAL +/*---------------------------------------------------------------------------*/ #define CLEANUP #include "namespace/app.c" #include "namespace/vk_syms.c" +#include "namespace/app_state_types.h" +#include "namespace/app_state.c" #undef CLEANUP +/*---------------------------------------------------------------------------*/ #endif diff --git a/2d/kickstart/app_core_types.h b/2d/blit/app_core_types.h similarity index 87% rename from 2d/kickstart/app_core_types.h rename to 2d/blit/app_core_types.h index 5c58888..3a23fde 100644 --- a/2d/kickstart/app_core_types.h +++ b/2d/blit/app_core_types.h @@ -4,11 +4,9 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ #define ARRAY_N(x) (sizeof(x) / sizeof(x[0])) - #include - #include #define u8 uint8_t #define u16 uint16_t @@ -18,6 +16,7 @@ #define s32_max 0x7fffffff #define u64 uint64_t #define u64_max 0xffffffffffffffff +#define f32 float #define loop for(;;) #define constant enum #endif /* APP_CORE_TYPES_H */ diff --git a/2d/kickstart/app_state.c b/2d/blit/app_state.c similarity index 78% rename from 2d/kickstart/app_state.c rename to 2d/blit/app_state.c index 4abdb43..8096941 100644 --- a/2d/kickstart/app_state.c +++ b/2d/blit/app_state.c @@ -4,13 +4,16 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ +#include +#include #include "app_core_types.h" +#include "nyanvk/types.h" #include "app_state_types.h" - +/*----------------------------------------------------------------------------*/ #include "namespace/app_state_types.h" #include "namespace/app_state.c" - +/*----------------------------------------------------------------------------*/ static u8 state_g; static bool do_render_g; static u32 fill_texel_g; diff --git a/2d/kickstart/app_state_types.h b/2d/blit/app_state_types.h similarity index 75% rename from 2d/kickstart/app_state_types.h rename to 2d/blit/app_state_types.h index af353aa..c1c4653 100644 --- a/2d/kickstart/app_state_types.h +++ b/2d/blit/app_state_types.h @@ -1,22 +1,23 @@ #ifndef APP_STATE_TYPES_H #define APP_STATE_TYPES_H -//TODO: remove what's not used from vk_types /* * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ +#include +#include #include "app_core_types.h" -#include "vk_types.h" - +#include "nyanvk/types.h" +#include "nyanvk/syms_dev.h" /* this is the default initial cpu rendering size */ #define APP_CPU_IMG_WIDTH 50 #define APP_CPU_IMG_HEIGHT 50 #define APP_WIN_WIDTH 100 #define APP_WIN_HEIGHT 100 - +/*----------------------------------------------------------------------------*/ #include "namespace/app_state_types.h" - +/*----------------------------------------------------------------------------*/ constant { state_run = 1, state_quit = 2 @@ -36,19 +37,15 @@ struct swpchn_t { struct phydev_t { void *vk; u8 q_fam; - bool is_discret_gpu; - struct vk_surf_texel_mem_blk_conf_core_t selected_texel_mem_blk_conf_core; - u32 mem_types_n; struct vk_mem_type_t mem_types[VK_MEM_TYPES_N_MAX]; }; struct cpu_img_t { void *vk; - struct vk_subrsrc_layout_t layout; void *dev_mem; /* TODO: we should use 1 big dev_mem chunk */ void *data; @@ -63,18 +60,13 @@ constant { struct dev_t { void *vk; struct phydev_t phydev; - struct swpchn_t swpchn; - void *q; - void *cmdpool; - void *cmdbufs[swpchn_imgs_n_max]; - + void *cp; + void *cbs[swpchn_imgs_n_max]; void *sems[sems_n]; - struct app_cpu_img_t cpu_imgs[swpchn_imgs_n_max]; - - VK_DEV_SYMS /* all vk dev entry points/symbols we use */ + VK_DEV_SYMS_FULL /* should cherry pick the syms we use */ }; struct surf_t { @@ -91,16 +83,15 @@ constant { struct tmp_phydev_t { void *vk; - u8 q_fams_n; struct vk_q_fam_props_t q_fams[tmp_phydev_q_fams_n_max]; - bool is_discret_gpu; struct vk_phydev_mem_props_t mem_props; - bool q_fams_surf_support[tmp_phydev_q_fams_n_max]; }; +/*----------------------------------------------------------------------------*/ #define CLEANUP #include "namespace/app_state_types.h" #undef CLEANUP +/*----------------------------------------------------------------------------*/ #endif /* APP_STATE_TYPES_H */ diff --git a/2d/kickstart/log.h b/2d/blit/log.h similarity index 81% rename from 2d/kickstart/log.h rename to 2d/blit/log.h index f22c8f9..b51eaf0 100644 --- a/2d/kickstart/log.h +++ b/2d/blit/log.h @@ -4,7 +4,7 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ #include #define LOG(fmt,...) dprintf(2,fmt,##__VA_ARGS__) #endif /* APP_LOG_H */ diff --git a/2d/kickstart/namespace/app.c b/2d/blit/namespace/app.c similarity index 100% rename from 2d/kickstart/namespace/app.c rename to 2d/blit/namespace/app.c diff --git a/2d/kickstart/namespace/app_state.c b/2d/blit/namespace/app_state.c similarity index 100% rename from 2d/kickstart/namespace/app_state.c rename to 2d/blit/namespace/app_state.c diff --git a/2d/kickstart/namespace/app_state_types.h b/2d/blit/namespace/app_state_types.h similarity index 100% rename from 2d/kickstart/namespace/app_state_types.h rename to 2d/blit/namespace/app_state_types.h diff --git a/2d/kickstart/namespace/vk_syms.c b/2d/blit/namespace/vk_syms.c similarity index 100% rename from 2d/kickstart/namespace/vk_syms.c rename to 2d/blit/namespace/vk_syms.c diff --git a/2d/blit/vk_app.h b/2d/blit/vk_app.h new file mode 100644 index 0000000..4c50432 --- /dev/null +++ b/2d/blit/vk_app.h @@ -0,0 +1,184 @@ +#ifndef VK_APP_H +#define VK_APP_H +/* + * this is public domain without any warranties of any kind + * Sylvain BERTRAND + */ +/* + * this is the simplification and taylorization of vk api for the specific + * uses of the app. + */ +#define vk_get_dev_q() \ +app_surf.dev.dl_vk_get_dev_q(app_surf.dev.vk, app_surf.dev.phydev.q_fam, 0, &app_surf.dev.q) + +#define vk_create_cp(info) \ +r = app_surf.dev.dl_vk_create_cp(app_surf.dev.vk, info, 0, &app_surf.dev.cp) + +#define vk_create_swpchn(info) \ +r = app_surf.dev.dl_vk_create_swpchn(app_surf.dev.vk, info, 0, &app_surf.dev.swpchn.vk) + +#define vk_get_swpchn_imgs() \ +r = app_surf.dev.dl_vk_get_swpchn_imgs(app_surf.dev.vk, app_surf.dev.swpchn.vk, &app_surf.dev.swpchn.imgs_n, app_surf.dev.swpchn.imgs) + +#define vk_create_img(info, img) \ +r = app_surf.dev.dl_vk_create_img(app_surf.dev.vk, info, 0, img) + +#define vk_get_img_mem_rqmts(...) \ +r = app_surf.dev.dl_vk_get_img_mem_rqmts(app_surf.dev.vk,##__VA_ARGS__) + +#define vk_alloc_mem(info, dev_mem) \ +r = app_surf.dev.dl_vk_alloc_mem(app_surf.dev.vk, info, 0, dev_mem) + +#define vk_bind_img_mem(infos) \ +r = app_surf.dev.dl_vk_bind_img_mem(app_surf.dev.vk, app_surf.dev.swpchn.imgs_n, infos) + +#define vk_map_mem(dev_mem, data) \ +r = app_surf.dev.dl_vk_map_mem(app_surf.dev.vk, dev_mem, 0, vk_whole_sz, 0, data) + +#define vk_alloc_cbs(info) \ +r = app_surf.dev.dl_vk_alloc_cbs(app_surf.dev.vk, info, app_surf.dev.cbs) + +#define vk_begin_cb(...) \ +r = app_surf.dev.dl_vk_begin_cb(__VA_ARGS__) + +#define vk_end_cb(...) \ +r = app_surf.dev.dl_vk_end_cb(__VA_ARGS__) + +#define vk_cmd_pl_barrier(cb, b) \ +app_surf.dev.dl_vk_cmd_pl_barrier(cb, vk_pl_stage_top_of_pipe_bit, vk_pl_stage_top_of_pipe_bit, 0, 0, 0, 0, 0, 1, b) + +#define vk_q_submit(info) \ +r = app_surf.dev.dl_vk_q_submit(app_surf.dev.q, 1, info, 0) + +#define vk_q_wait_idle() \ +r = app_surf.dev.dl_vk_q_wait_idle(app_surf.dev.q) + +#define vk_get_img_subrsrc_layout(...) \ +app_surf.dev.dl_vk_get_img_subrsrc_layout(app_surf.dev.vk, ##__VA_ARGS__) + +#define vk_acquire_next_img(...) \ +r = app_surf.dev.dl_vk_acquire_next_img(app_surf.dev.vk,##__VA_ARGS__) + +#define vk_reset_cb(cb) \ +r = app_surf.dev.dl_vk_reset_cb(cb, 0) + +#define vk_cmd_blit_img(cb, src_img, dst_img, region) \ +app_surf.dev.dl_vk_cmd_blit_img(cb, src_img, vk_img_layout_general, dst_img, vk_img_layout_present, 1, region, 0) + +#define vk_q_present(info) \ +r = app_surf.dev.dl_vk_q_present(app_surf.dev.q, info) + +#define vk_create_sem(info, sem) \ +r = app_surf.dev.dl_vk_create_sem(app_surf.dev.vk, info, 0, sem) +/******************************************************************************/ +/* cherry picked from nyanvk/syms_global.h */ +#define VK_GLOBAL_SYMS \ + static void *(*dl_vk_get_instance_proc_addr)(void *instance, u8 *name); \ + static void *(*dl_vk_get_dev_proc_addr)(void *dev, u8 *name); \ + static s32 (*dl_vk_enumerate_instance_version)(u32 *version); \ + static s32 (*dl_vk_enumerate_instance_layer_props)( \ + u32 *props_n, \ + struct vk_layer_props_t *props); \ + static s32 (*dl_vk_enumerate_instance_ext_props)( \ + u8 *layer_name, \ + u32 *props_n, \ + struct vk_ext_props_t *props); \ + static s32 (*dl_vk_create_instance)( \ + struct vk_instance_create_info_t *info, \ + void *allocator, \ + void **instance); \ + static s32 (*dl_vk_enumerate_phydevs)( \ + void *instance, \ + u32 *phydevs_n, \ + void **phydevs); \ + static s32 (*dl_vk_enumerate_dev_ext_props)( \ + void *phydev, \ + u8 *layer_name, \ + u32 *props_n, \ + struct vk_ext_props_t *props); \ + static void (*dl_vk_get_phydev_props)( \ + void *phydev, \ + struct vk_phydev_props_t *props); \ + static s32 (*dl_vk_create_dev)( \ + void *phydev, \ + struct vk_dev_create_info_t *create_info, \ + void *allocator, \ + void **dev); \ + static void (*dl_vk_get_phydev_q_fam_props)( \ + void *phydev, \ + u32 *q_fam_props_n, \ + struct vk_q_fam_props_t *props); \ + static s32 (*dl_vk_create_xcb_surf)( \ + void *instance, \ + struct vk_xcb_surf_create_info_t *info, \ + void *allocator, \ + void **surf); \ + static s32 (*dl_vk_get_phydev_surf_support)( \ + void *phydev, \ + u32 q_fam, \ + void *surf, \ + u32 *supported); \ + static s32 (*dl_vk_get_phydev_surf_texel_mem_blk_confs)( \ + void *phydev, \ + struct vk_phydev_surf_info_t *info, \ + u32 *confs_n, \ + struct vk_surf_texel_mem_blk_conf_t *confs); \ + static void (*dl_vk_get_phydev_mem_props)( \ + void *phydev, \ + struct vk_phydev_mem_props_t *props); \ + static s32 (*dl_vk_get_phydev_surf_caps)( \ + void *phydev, \ + struct vk_phydev_surf_info_t *info, \ + struct vk_surf_caps_t *caps); \ + static s32 (*dl_vk_get_phydev_surf_present_modes)( \ + void *phydev, \ + void *surf, \ + u32 *modes_n, \ + u32 *modes); +/******************************************************************************/ +#define vk_get_instance_proc_addr dl_vk_get_instance_proc_addr + +#define vk_get_dev_proc_addr dl_vk_get_dev_proc_addr + +#define vk_enumerate_instance_version \ +r = dl_vk_enumerate_instance_version + +#define vk_enumerate_instance_layer_props \ +r = dl_vk_enumerate_instance_layer_props + +#define vk_enumerate_instance_ext_props(...) \ +r = dl_vk_enumerate_instance_ext_props(0,##__VA_ARGS__) + +#define vk_create_instance(info) \ +r = dl_vk_create_instance(info, 0, &app_instance) + +#define vk_enumerate_phydevs(...) \ +r = dl_vk_enumerate_phydevs(app_instance,##__VA_ARGS__) + +#define vk_enumerate_dev_ext_props(phydev, props_n, props) \ +r = dl_vk_enumerate_dev_ext_props(phydev, 0, props_n, props) + +#define vk_get_phydev_props dl_vk_get_phydev_props + +#define vk_create_dev(info) \ +r = dl_vk_create_dev(app_surf.dev.phydev.vk, info, 0, &app_surf.dev.vk) + +#define vk_get_phydev_q_fam_props dl_vk_get_phydev_q_fam_props + +#define vk_create_xcb_surf(info) \ +r = dl_vk_create_xcb_surf(app_instance, info, 0, &app_surf.vk) + +#define vk_get_phydev_surf_support(phydev, q_fam, supported) \ +r = dl_vk_get_phydev_surf_support(phydev, q_fam, app_surf.vk, supported) + +#define vk_get_phydev_surf_texel_mem_blk_confs(info, ...) \ +r = dl_vk_get_phydev_surf_texel_mem_blk_confs(app_surf.dev.phydev.vk, info, ##__VA_ARGS__) + +#define vk_get_phydev_mem_props dl_vk_get_phydev_mem_props + +#define vk_get_phydev_surf_caps(info) \ +r = dl_vk_get_phydev_surf_caps(app_surf.dev.phydev.vk, info, &app_tmp_surf_caps) + +#define vk_get_phydev_surf_present_modes() \ +r = dl_vk_get_phydev_surf_present_modes(app_surf.dev.phydev.vk, app_surf.vk, &app_tmp_present_modes_n, app_tmp_present_modes) +#endif diff --git a/2d/kickstart/vk_syms.c b/2d/blit/vk_syms.c similarity index 59% rename from 2d/kickstart/vk_syms.c rename to 2d/blit/vk_syms.c index 5b83b0f..e66679f 100644 --- a/2d/kickstart/vk_syms.c +++ b/2d/blit/vk_syms.c @@ -4,101 +4,24 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ #include #include - +#include #include "app_core_types.h" -#include "vk_types.h" +#include "nyanvk/types.h" +#include "vk_app.h" #include "log.h" - #include "app_state.c" - +/*----------------------------------------------------------------------------*/ #include "namespace/vk_syms.c" - +/*----------------------------------------------------------------------------*/ +VK_GLOBAL_SYMS static void *loader_g; /* we put the dl handle in vk namespace */ - -static void *(*vk_get_instance_proc_addr)(void *instance, u8 *name); -static void *(*vk_get_dev_proc_addr)(void *dev, u8 *name); - -/* we don't support vk 1.0 (too broken), then the following must exist */ -static s32 (*vk_enumerate_instance_version)(u32 *version); - -static s32 (*vk_enumerate_instance_layer_props)( - u32 *props_n, - struct vk_layer_props_t *props); - -static s32 (*vk_enumerate_instance_ext_props)( - u8 *layer_name, - u32 *props_n, - struct vk_ext_props_t *props); - -static s32 (*vk_create_instance)( - struct vk_instance_create_info_t *info, - void *allocator, - void **instance); - -static s32 (*vk_enumerate_phydevs)( - void *instance, - u32 *phydevs_n, - void **phydevs); - -static s32 (*vk_enumerate_dev_ext_props)( - void *phydev, - u8 *layer_name, - u32 *props_n, - struct vk_ext_props_t *props); - -static void (*vk_get_phydev_props)( - void *phydev, - struct vk_phydev_props_t *props); - -static s32 (*vk_create_dev)( - void *phydev, - struct vk_dev_create_info_t *create_info, - void *allocator, - void **dev); - -static void (*vk_get_phydev_q_fam_props)( - void *phydev, - u32 *q_fam_props_n, - struct vk_q_fam_props_t *props); - -static s32 (*vk_create_xcb_surf)( - void *instance, - struct vk_xcb_surf_create_info_t *info, - void *allocator, - void **surf); - -static s32 (*vk_get_phydev_surf_support)( - void *phydev, - u32 q_fam, - void *surf, - u32 *supported); - -static s32 (*vk_get_phydev_surf_texel_mem_blk_confs)( - void *phydev, - struct vk_phydev_surf_info_t *info, - u32 *confs_n, - struct vk_surf_texel_mem_blk_conf_t *confs); -static void (*vk_get_phydev_mem_props)( - void *phydev, - struct vk_phydev_mem_props_t *props); - -static s32 (*vk_get_phydev_surf_caps)( - void *phydev, - struct vk_phydev_surf_info_t *info, - struct vk_surf_caps_t *caps); - -static s32 (*vk_get_phydev_surf_present_modes)( - void *phydev, - void *surf, - u32 *modes_n, - u32 *modes); /*----------------------------------------------------------------------------*/ #define INSTANCE_STATIC_SYM(x,y) \ - y = vk_get_instance_proc_addr(0, #x); \ - if (y == 0) { \ + dl_##y = vk_get_instance_proc_addr(0, #x); \ + if (dl_##y == 0) { \ LOG("0:MAIN:FATAL:unable to find vulkan " #x "\n"); \ exit(1); \ } @@ -115,8 +38,8 @@ static void instance_static_syms(void) #undef INSTANCE_STATIC_SYM /*----------------------------------------------------------------------------*/ #define INSTANCE_SYM(x,y) \ - y = vk_get_instance_proc_addr(app_instance, #x); \ - if (y == 0) { \ + dl_##y = vk_get_instance_proc_addr(app_instance, #x); \ + if (dl_##y == 0) { \ LOG("0:MAIN:FATAL:unable to find vulkan " #x "\n"); \ exit(1); \ } @@ -141,8 +64,6 @@ static void instance_syms(void) vk_get_phydev_surf_caps); INSTANCE_SYM(vkGetPhysicalDeviceSurfacePresentModesKHR, vk_get_phydev_surf_present_modes); - INSTANCE_SYM(vkGetPhysicalDeviceSurfacePresentModesKHR, - vk_get_phydev_surf_present_modes); /*--------------------------------------------------------------------*/ } #undef INSTANCE_SYM @@ -156,7 +77,7 @@ static void instance_syms(void) static void dev_syms(void) { DEV_SYM(vkGetDeviceQueue, vk_get_dev_q); - DEV_SYM(vkCreateCommandPool, vk_create_cmdpool); + DEV_SYM(vkCreateCommandPool, vk_create_cp); DEV_SYM(vkCreateSwapchainKHR, vk_create_swpchn); DEV_SYM(vkGetSwapchainImagesKHR, vk_get_swpchn_imgs); DEV_SYM(vkCreateImage, vk_create_img); @@ -164,28 +85,24 @@ static void dev_syms(void) DEV_SYM(vkAllocateMemory, vk_alloc_mem); DEV_SYM(vkBindImageMemory2KHR, vk_bind_img_mem); DEV_SYM(vkMapMemory, vk_map_mem); - DEV_SYM(vkAllocateCommandBuffers, vk_alloc_cmdbufs); - DEV_SYM(vkFreeCommandBuffers, vk_free_cmdbufs); - DEV_SYM(vkBeginCommandBuffer, vk_begin_cmdbuf); - DEV_SYM(vkEndCommandBuffer, vk_end_cmdbuf); - DEV_SYM(vkCmdPipelineBarrier, vk_cmd_pipeline_barrier); + DEV_SYM(vkAllocateCommandBuffers, vk_alloc_cbs); + DEV_SYM(vkBeginCommandBuffer, vk_begin_cb); + DEV_SYM(vkEndCommandBuffer, vk_end_cb); + DEV_SYM(vkCmdPipelineBarrier, vk_cmd_pl_barrier); DEV_SYM(vkQueueSubmit, vk_q_submit); DEV_SYM(vkQueueWaitIdle, vk_q_wait_idle); DEV_SYM(vkGetImageSubresourceLayout, vk_get_img_subrsrc_layout); DEV_SYM(vkAcquireNextImage2KHR, vk_acquire_next_img); - DEV_SYM(vkCreateFence, vk_create_fence); - DEV_SYM(vkResetCommandBuffer, vk_reset_cmdbuf); + DEV_SYM(vkResetCommandBuffer, vk_reset_cb); DEV_SYM(vkCmdBlitImage, vk_cmd_blit_img); - DEV_SYM(vkWaitForFences, vk_wait_for_fences); - DEV_SYM(vkResetFences, vk_reset_fences); DEV_SYM(vkQueuePresentKHR, vk_q_present); DEV_SYM(vkCreateSemaphore, vk_create_sem); } #undef DEVICE_SYM /*----------------------------------------------------------------------------*/ #define DLSYM(x, y) \ - y = dlsym(loader_g, #x); \ - if (y == 0) { \ + dl_##y = dlsym(loader_g, #x); \ + if (dl_##y == 0) { \ LOG("0:MAIN:FATAL:%s:unable to find " #x "\n", dlerror()); \ exit(1); \ } @@ -205,7 +122,9 @@ static void load_vk_loader(void) exit(1); } } +/*----------------------------------------------------------------------------*/ #define CLEANUP #include "namespace/vk_syms.c" #undef CLEANUP +/*----------------------------------------------------------------------------*/ #endif /* VK_SYMS_C */ diff --git a/2d/kickstart/xcb.c b/2d/blit/xcb.c similarity index 99% rename from 2d/kickstart/xcb.c rename to 2d/blit/xcb.c index e9f1d97..1485287 100644 --- a/2d/kickstart/xcb.c +++ b/2d/blit/xcb.c @@ -4,13 +4,12 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ #include #include #include - -#include "log.h" #include "app_core_types.h" +#include "log.h" #include "xcb_syms.c" #include "app_state.c" diff --git a/2d/kickstart/xcb_syms.c b/2d/blit/xcb_syms.c similarity index 98% rename from 2d/kickstart/xcb_syms.c rename to 2d/blit/xcb_syms.c index 9ecddc8..0f8e006 100644 --- a/2d/kickstart/xcb_syms.c +++ b/2d/blit/xcb_syms.c @@ -4,12 +4,10 @@ * this is public domain without any warranties of any kind * Sylvain BERTRAND */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ #include #include - #include - #include "app_core_types.h" #include "log.h" diff --git a/2d/kickstart/vk_gen.c b/2d/kickstart/vk_gen.c deleted file mode 100644 index 0481d9a..0000000 --- a/2d/kickstart/vk_gen.c +++ /dev/null @@ -1,219 +0,0 @@ -//#define _GNU_SOURCE -//#include - -#include -//#include -//#include -//#include -//#include - -#include "ezxml.h" - -/* - * we don't care about memory management - * we don't care about global variables - * something is not expected: - * - corrupted generation - * - more likely a crash (good!) - */ - -/* - * attr(s): attribute(s) - * enum(s): enumeration(s) - * XXX:DO NOT BE MISLEAD-->HERE XML "ENUM" ARE NOT RELATED - * IN ANY WAY TO C ENUM. - * ABBREVIATIONS: - * e: Epilogue - * fd: File Descriptor - * p: Prologue - * str(s): STRing(s) - */ - -/* do fix C */ -#define loop for(;;) -/* #define char u8 */ - -/* log lines */ -#define ERR(fmt, ...) dprintf(2,"ERR:" fmt,##__VA_ARGS__) -#define INFO(fmt, ...) dprintf(2,"INFO:" fmt,##__VA_ARGS__) - -/* - * ezxml_t is a pointer... typedef has really nothing to do in C, *REALLY*!! - * - * tag hierarchy, in order: - * platforms - * platform+ - * tags - * tag+ - * types - * type+ - * enums+ - * enum+ - * commands - * command+ - * feature+ (basically 2 features, vulkan 1.0 and vulkan 1.1) - * extensions - * extension+ - * require+ - * enum+ - */ - -/* major uniq tags */ -static ezxml_t registry; -//static ezxml_t registry_platforms; -//static ezxml_t registry_commands; -//static ezxml_t registry_extensions; -// -//static int fd_h; /* file descriptor for vk_enum_to_str.h */ -//static int fd_c; /* file descriptor for vk_enum_to_str.c */ -// -///* enough or unreasonable */ -//static char path[1024]; -// -///*============================================================================*/ -///* vk_enum_to_str.h template */ -//static char *h_p = "\ -//#ifndef MESA_VK_ENUM_TO_STR_H\n\ -//#define MESA_VK_ENUM_TO_STR_H\n\n\ -//#include \n\ -//#include \n\ -//"; -// -///* here goes the mapping of extension names to their numbers */ -// -///* here goes the function declarations to convert the enums/enum to text */ -// -//static char *h_instance_table_p = "\n\n\ -//struct vk_instance_dispatch_table {\n\ -//PFN_vkGetInstanceProcAddr GetInstanceProcAddr;"; -///* here we fill the name of entry points related to an instance */ -//static char *h_instance_table_e = "\n\ -//};"; -// -//static char *h_device_table_p = "\n\n\ -//struct vk_device_dispatch_table {\n\ -//PFN_vkGetDeviceProcAddr GetDeviceProcAddr;"; -///* here we fill the name of entry points related to an instance */ -//static char *h_device_table_e = "\n\ -//};"; -// -//static char *h_tables_e = "\n\n\ -//void vk_load_instance_commands(VkInstance instance, PFN_vkGetInstanceProcAddr gpa, struct vk_instance_dispatch_table *table);\n\ -//void vk_load_device_commands(VkDevice device, PFN_vkGetDeviceProcAddr gpa, struct vk_device_dispatch_table *table);\ -//"; -//static char *h_e = "\n\ -//#endif"; -///*============================================================================*/ -// -// -///*============================================================================*/ -///* vk_enum_to_str.c template */ -//static char *c_p = "\ -//#include \n\ -//#include \n\ -//#include \n\ -//#include \"util/macros.h\"\n\ -//#include \"vk_enum_to_str.h\"\n\ -//"; -// -///* here goes the enum value conversion to text code */ -// -//static char *c_instance_table_p = "\n\n\ -//void vk_load_instance_commands(VkInstance instance,\n\ -// PFN_vkGetInstanceProcAddr gpa,\n\ -// struct vk_instance_dispatch_table *table)\n\ -//{\n\ -//memset(table, 0, sizeof(*table));\n\ -//table->GetInstanceProcAddr = gpa;"; -///* here the command table entry points are actually initialized */ -//static char *c_instance_table_e = "\n\ -//}"; -// -//static char *c_device_table_p ="\n\n\ -//void vk_load_device_commands(VkDevice device,\n\ -// PFN_vkGetDeviceProcAddr gpa,\n\ -// struct vk_device_dispatch_table *table)\n\ -//{\n\ -//memset(table, 0, sizeof(*table));\n\ -//table->GetDeviceProcAddr = gpa;"; -//static char *c_device_table_e = "\n\ -//}"; -// -///*============================================================================*/ -// -// -//static ezxml_t extension_platform_get(ezxml_t extension) -//{ -// ezxml_t platform; -// -// const char *extension_platform_name = ezxml_attr(extension, "platform"); -// if (extension_platform_name == 0) -// return 0; -// -// platform = ezxml_get(registry_platforms, "platform", -1); -// loop { -// if (platform == 0) -// return 0; -// -// if (strcmp(ezxml_attr(platform, "name"), -// extension_platform_name) == 0) -// return platform; -// -// platform = ezxml_next(platform); -// } -//} - -int main(int args_n, char **args) -{ - if (args_n != 3) { - INFO("usage:%s VULKAN_XML_REGISTRY OUT_DIR\n", args[0]); - return 1; - } - - INFO("VULKAN REGISTRY=%s\n", args[1]); - INFO("OUT_DIR=%s\n", args[2]); - - /* this does return the root "registry" tag */ - registry = ezxml_parse_file(args[1]); - if (registry == 0) { - ERR("unable to load and parse %s\n", args[1]); - return 1; - } - //umask(0); - //#define MODE_0666 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH - - //sprintf(path, "%s/vk_enum_to_str.h", args[2]); - //fd_h = open(path, O_WRONLY|O_CREAT|O_TRUNC, MODE_0666); - //dprintf(fd_h, h_p); - - //sprintf(path, "%s/vk_enum_to_str.c", args[2]); - //fd_c = open(path, O_WRONLY|O_CREAT|O_TRUNC, MODE_0666); - //dprintf(fd_c, c_p); - - ///*--------------------------------------------------------------------*/ - ///* get the major uniq tags once */ - //registry_platforms = ezxml_get(registry, "platforms", -1); - //registry_commands = ezxml_get(registry, "commands", -1); - //registry_extensions = ezxml_get(registry, "extensions", -1); - - ///*--------------------------------------------------------------------*/ - ///* - // * first part, extension name to number, and enums with their - // * extensions - // */ - //extensions_names_to_numbers(); - - //dprintf(fd_h, "\n"); - - //enumss_to_strs(); - - ///*--------------------------------------------------------------------*/ - ///* second part, dispatch tables of commands */ - //instance_dispatch_table_gen(); - //device_dispatch_table_gen(); - //dprintf(fd_h, h_tables_e); - - ///*--------------------------------------------------------------------*/ - //dprintf(fd_h, h_e); - return 0; -} diff --git a/2d/kickstart/vk_types.h b/2d/kickstart/vk_types.h deleted file mode 100644 index 28c778d..0000000 --- a/2d/kickstart/vk_types.h +++ /dev/null @@ -1,795 +0,0 @@ -#ifndef VK_TYPES_H -#define VK_TYPES_H -/* - * this is public domain without any warranties of any kind - * Sylvain BERTRAND - */ -/* XXX: KEEP AN EYE ON ABBREVIATIONS */ -/* - * XXX: we are fixing vulkan ABI which made the huge mistake to use - * enums as function parameters or function return values. - */ -#include -#include /* we use the xcb wsi */ -#include "app_core_types.h" -/* macro */ -/*----------------------------------------------------------------------------*/ -#define vk_true 1 -#define vk_false 0 -#define vk_whole_sz 0xffffffffffffffff -#define vk_q_fam_ignored 0xffffffff -/*----------------------------------------------------------------------------*/ -#define VK_VERSION_MAJOR(x) (x >> 22) -#define VK_VERSION_MINOR(x) ((x >> 12) & 0x3ff) -#define VK_VERSION_PATCH(x) (x & 0xfff) -/* macro */ -/******************************************************************************/ -/* types */ -/* - * 64 bits platforms: enums do default to 32 bits, but can go up to 64 bits - * based on the range of values they hold. this is important for - * vulkan ABI which we will fix. - * _individually_, each value is defaulted to 32bits, if possible, and signed - * or not. - * XXX: All vulkan enums use 32 bits storage - */ -enum { - vk_err_out_of_host_mem = -1, - /*--------------------------------------------------------------------*/ - vk_success = 0, - vk_incomplete = 5, - vk_r_enum_max = 0x7fffffff -}; - -enum { - vk_struct_type_instance_create_info = 1, - vk_struct_type_dev_q_create_info = 2, - vk_struct_type_dev_create_info = 3, - vk_struct_type_submit_info = 4, - vk_struct_type_mem_alloc_info = 5, - vk_struct_type_fence_create_info = 8, - vk_struct_type_sem_create_info = 9, - vk_struct_type_img_create_info = 14, - vk_struct_type_cmdpool_create_info = 39, - vk_struct_type_cmdbuf_alloc_info = 40, - vk_struct_type_cmdbuf_begin_info = 42, - vk_struct_type_img_mem_barrier = 45, - /* extension number 2 or index 1, offset 0 */ - vk_struct_type_swpchn_create_info = 1000000000 + 1000 + 0, - /* extension number 2 or index 1, offset 1 */ - vk_struct_type_present_info = 1000000000 + 1000 + 1, - /* extension number 6 or index 5, offset 0 */ - vk_struct_type_xcb_surf_create_info = 1000000000 + 5000 + 0, - /* extension number 60 or index 59, offset 1 */ - vk_struct_type_phydev_props = 1000000000 + 59000 + 1, - /* extension number 60 or index 59, offset 5 */ - vk_struct_type_q_fam_props = 1000000000 + 59000 + 5, - /* extension number 60 or index 59, offset 6 */ - vk_struct_type_phydev_mem_props = 1000000000 + 59000 + 6, - /* extension number 60 or index 59, offset 10 */ - vk_struct_type_acquire_next_img_info = 1000000000 + 59000 + 10, - /* extension number 91 or index 90, offset 0 */ - vk_struct_type_surf_caps = 1000000000 + 90000 + 0, - /* extension number 120 or index 119, offset 0 */ - vk_struct_type_phydev_surf_info = 1000000000 + 119000 + 0, - /* extension number 120 or index 119, offset 2 */ - vk_struct_type_surf_texel_mem_blk_conf = 1000000000 + 119000 + 2, - /* extension number 147 or index 146, offset 1 */ - vk_struct_type_img_mem_rqmts_info = 1000000000 + 146000 + 1, - /* extension number 147 or index 146, offset 3 */ - vk_struct_type_mem_rqmts = 1000000000 + 146000 + 3, - /* extension number 158 or index 157, offset 1 */ - vk_struct_type_bind_img_mem_info = 1000000000 + 157000 + 1, - vk_struct_type_enum_max = 0x7fffffff -}; - -struct vk_instance_create_info_t { - u32 type; - void *next; - u32 flags; - void *app_info; /* allow easy hidden driver optimizations: no! */ - u32 enabled_layers_n; - u8 **enabled_layer_names; - u32 enabled_exts_n; - u8 **enabled_ext_names; -}; - -#define VK_MAX_EXT_NAME_SZ 256 -struct vk_ext_props_t { - u8 name[VK_MAX_EXT_NAME_SZ]; - u32 spec_version; -}; - -#define VK_MAX_DESC_SZ 256 -struct vk_layer_props_t { - u8 name[VK_MAX_EXT_NAME_SZ]; - u32 spec_version; - u32 implementation_version; - u8 desc[VK_MAX_DESC_SZ]; -}; - -enum { - vk_phydev_type_other = 0, - vk_phydev_type_integrated_gpu = 1, - vk_phydev_type_discrete_gpu = 2, - vk_phydev_type_virtual_gpu = 3, - vk_phydev_type_cpu = 4, - vk_phydev_type_enum_max = 0x7fffffff -}; - -struct vk_phydev_limits_t { - u32 not_used_00[11]; - u64 not_used_01[2]; - u32 not_used_02[51]; - float not_used_03[2]; - u32 not_used_04[3]; - float not_used_05[2]; - u32 not_used_06; - size_t not_used_07; - u64 not_used_08[3]; - u32 not_used_09[4]; - float not_used_10[2]; - u32 not_used_11[16]; - float not_used_12; - u32 not_used_13[4]; - float not_used_14[6]; - u32 not_used_15[2]; - u64 not_used_16[3]; -}; - -struct vk_phydev_sparse_props_t { - u32 not_used[5]; -}; - -/*----------------------------------------------------------------------------*/ -#define VK_MAX_PHYDEV_NAME_SZ 256 -#define VK_UUID_SZ 16 -struct vk_phydev_props_core_t { - u32 api_version; - u32 driver_version; - u32 vendor_id; - u32 dev_id; - u32 dev_type; - u8 name[VK_MAX_PHYDEV_NAME_SZ]; - u8 pipeline_cache_uuid[VK_UUID_SZ]; - struct vk_phydev_limits_t limits; - struct vk_phydev_sparse_props_t sparse_props; -}; -/* the vulkan 1.1 version */ -struct vk_phydev_props_t { - u32 type; - void *next; - struct vk_phydev_props_core_t core; -}; -/*----------------------------------------------------------------------------*/ -enum { - vk_q_gfx_bit = 0x00000001, - vk_q_compute_bit = 0x00000002, - vk_q_transfer_bit = 0x00000004, - vk_q_sparse_binding_bit = 0x00000008, - vk_q_protected_bit = 0x00000010, - vk_q_flag_bits_enum_max = 0x7fffffff -}; - -struct vk_extent_3d_t { - u32 width; - u32 height; - u32 depth; -}; -/*----------------------------------------------------------------------------*/ -struct vk_q_fam_props_core_t { - u32 flags; - u32 qs_n; - u32 timestamp_valid_bits; - struct vk_extent_3d_t min_img_transfer_granularity; -}; - -struct vk_q_fam_props_t { - u32 type; - void *next; - struct vk_q_fam_props_core_t core; -}; -/*----------------------------------------------------------------------------*/ -struct vk_phydev_features_t { - u32 not_used[55]; -}; - -struct vk_dev_q_create_info_t { - u32 type; - void *next; - u32 flags; - u32 q_fam; - u32 qs_n; - float *q_prios; -}; - -struct vk_dev_create_info_t { - u32 type; - void *next; - u32 flags; - u32 q_create_infos_n; - struct vk_dev_q_create_info_t *q_create_infos; - u32 do_not_use_0; - void *do_not_use_1; - u32 enabled_exts_n; - u8 **enabled_ext_names; - void *do_not_use_2; -}; - -enum { - vk_cmdpool_create_transient_bit = 0x00000001, - vk_cmdpool_create_reset_cmdbuf_bit = 0x00000002, - vk_cmdpool_create_flag_bits_enum_max = 0x7fffffff -}; - -struct vk_cmdpool_create_info_t { - u32 type; - void *next; - u32 flags; - u32 q_fam; -}; - -struct vk_xcb_surf_create_info_t { - u32 type; - void *next; - u32 flags; - xcb_connection_t *c; - xcb_window_t win; -}; - -struct vk_phydev_surf_info_t { - u32 type; - void *next; - void *surf; -}; - -enum { - vk_texel_mem_blk_fmt_undefined = 0, - vk_texel_mem_blk_fmt_b8g8r8a8_unorm = 44, - vk_texel_mem_blk_fmt_b8g8r8a8_srgb = 50, - vk_texel_mem_blk_fmt_enum_max = 0x7fffffff -}; - -enum { - vk_color_space_srgb_nonlinear = 0, - vk_color_space_enum_max = 0x7fffffff -}; - -struct vk_surf_texel_mem_blk_conf_core_t { - u32 fmt; - u32 color_space; -}; - -struct vk_surf_texel_mem_blk_conf_t { - u32 type; - void *next; - struct vk_surf_texel_mem_blk_conf_core_t core; -}; -/*----------------------------------------------------------------------------*/ -enum { - vk_mem_prop_dev_local_bit = 0x00000001, - vk_mem_prop_host_visible_bit = 0x00000002, - vk_mem_prop_host_cached_bit = 0x00000008, - vk_mem_prop_flag_bits_enum_max = 0x7fffffff -}; - -struct vk_mem_type_t { - u32 prop_flags; - u32 heap; -}; -/*----------------------------------------------------------------------------*/ -enum { - vk_mem_heap_dev_local_bit = 0x00000001, - vk_mem_heap_multi_instance_bit = 0x00000002, - vk_mem_heap_flag_bits_enum_max = 0x7FFFFFFF -}; - -struct vk_mem_heap_t { - u64 sz; - u32 flags; -}; -/*----------------------------------------------------------------------------*/ -#define VK_MEM_TYPES_N_MAX 32 -#define VK_MEM_HEAPS_N_MAX 16 -struct vk_phydev_mem_props_core_t { - u32 mem_types_n; - struct vk_mem_type_t mem_types[VK_MEM_TYPES_N_MAX]; - u32 mem_heaps_n; - struct vk_mem_heap_t mem_heaps[VK_MEM_HEAPS_N_MAX]; -}; - -struct vk_phydev_mem_props_t { - u32 type; - void *next; - struct vk_phydev_mem_props_core_t core; -}; -/*----------------------------------------------------------------------------*/ -struct vk_extent_2d_t { - u32 width; - u32 height; -}; - -enum { - vk_surf_transform_identity_bit = 0x00000001, - vk_surf_transform_flag_bits_enum_max = 0x7fffffff -}; - -enum { - vk_composite_alpha_opaque_bit = 0x00000001, - vk_composite_alpha_flag_bits_enum_max = 0x7fffffff -}; - -enum { - vk_img_usage_transfer_src_bit = 0x00000001, - vk_img_usage_transfer_dst_bit = 0x00000002, - vk_img_usage_color_attachment_bit = 0x00000010, - vk_img_usage_flag_bits_enum_max = 0x7fffffff -}; - -struct vk_surf_caps_core_t { - u32 imgs_n_min; - u32 imgs_n_max; - struct vk_extent_2d_t current_extent; - struct vk_extent_2d_t img_extent_min; - struct vk_extent_2d_t img_extent_max; - u32 img_array_layers_n_max; - u32 supported_transforms; - u32 current_transform; - u32 supported_composite_alpha; - u32 supported_img_usage_flags; -}; - -struct vk_surf_caps_t { - u32 type; - void *next; - struct vk_surf_caps_core_t core; - u32 flags; - void *surf; - u32 imgs_n; - -}; -/*----------------------------------------------------------------------------*/ -enum { - vk_sharing_mode_exclusive = 0, - vk_sharing_mode_enum_max = 0x7fffffff -}; - -enum { - vk_present_mode_immediate = 0, - vk_present_mode_mailbox = 1, - vk_present_mode_fifo = 2, - vk_present_mode_fifo_relaxed = 3, - vk_present_mode_enum_max = 0x7fffffff -}; - -struct vk_swpchn_create_info_t { - u32 type; - void *next; - u32 flags; - void *surf; - u32 imgs_n_min; - u32 img_texel_mem_blk_fmt; - u32 img_color_space; - struct vk_extent_2d_t img_extent; - u32 img_layers_n; - u32 img_usage; - u32 img_sharing_mode; - u32 q_fams_n; - u32 *q_fams; - u32 pre_transform; - u32 composite_alpha; - u32 present_mode; - u32 clipped; - void *old_swpchn; -}; - -enum { - vk_img_type_2d = 1, - vk_img_type_enum_max = 0x7fffffff -}; - -enum { - vk_samples_n_1_bit = 0x00000001, - vk_samples_n_enum_max = 0x7fffffff -}; - -enum { - vk_img_tiling_optimal = 0, - vk_img_tiling_linear = 1, - vk_img_tiling_enum_max = 0x7fffffff -}; - -enum { - vk_img_create_flag_2d_array_compatible_bit = 0x00000002, - vk_img_create_flag_enum_max = 0x7fffffff -}; - -enum { - vk_img_layout_undefined = 0, - vk_img_layout_general = 1, - /* extension number 2 or index 1, offset 2 */ - vk_img_layout_present = 1000000000 + 1000 + 2, - vk_img_layout_enum_n_max = 0x7fffffff -}; - -struct vk_img_create_info_t { - u32 type; - void *next; - u32 flags; - u32 img_type; - u32 texel_mem_blk_fmt; - struct vk_extent_3d_t extent; - u32 mip_lvls_n; - u32 array_layers_n; - u32 samples_n; /* flags */ - u32 img_tiling; - u32 usage; - u32 sharing_mode; - u32 q_fams_n; - u32 *q_fams; - u32 initial_layout; -}; - -struct vk_img_mem_rqmts_info_t { - u32 type; - void *next; - void *img; -}; - -struct vk_mem_rqmts_core_t { - u64 sz; - u64 alignment; - /*idxs of bits are idxs in mem types of vk_phydev_mem_props_core_t */ - u32 mem_type_bits; -}; - -struct vk_mem_rqmts_t { - u32 type; - void *next; - struct vk_mem_rqmts_core_t core; -}; - -struct vk_mem_alloc_info_t { - u32 type; - void *next; - u64 sz; - u32 mem_type_idx; /* in the physical device array of memory types */ -}; - -struct vk_bind_img_mem_info_t { - u32 type; - void *next; - void *img; - void *mem; - u64 offset; -}; - -enum { - vk_pipeline_stage_top_of_pipe_bit = (1 << 0), - vk_pipeline_stage_bottom_of_pipe_bit = (1 << 13), - vk_pipeline_stage_enum_max = 0x7fffffff -}; - -enum { - vk_img_aspect_color_bit = 1, - vk_img_aspect_enum_max = 0x7fffffff -}; - -struct vk_img_subrsrc_range_t { - u32 aspect; - u32 base_mip_lvl; - u32 lvls_n; - u32 base_array_layer; - u32 array_layers_n; -}; - -struct vk_img_mem_barrier_t { - u32 type; - void *next; - u32 src_access; - u32 dst_access; - u32 old_layout; - u32 new_layout; - u32 src_q_fam; - u32 dst_q_fam; - void *img; - struct vk_img_subrsrc_range_t subrsrc_range; -}; - -enum { - vk_cmdbuf_lvl_primary = 0, - vk_cmdbuf_lvl_enum_max = 0x7fffffff -}; - -struct vk_cmdbuf_alloc_info_t { - u32 type; - void *next; - void *cmdpool; - u32 lvl; - u32 cmdbufs_n; -}; - -enum { - vk_cmdbuf_usage_one_time_submit_bit = 0x00000001, - vk_cmdbuf_usage_enum_max = 0x7fffffff -}; - -struct vk_cmdbuf_begin_info_t { - u32 type; - void *next; - u32 flags; - void *do_not_use; -}; - -struct vk_submit_info_t { - u32 type; - void *next; - u32 wait_sems_n; - void **wait_sems; - u32* wait_dst_stages; - u32 cmdbufs_n; - void **cmdbufs; - u32 signal_sems_n; - void **signal_sems; -}; - -struct vk_img_subrsrc_t { - u32 aspect; - u32 mip_lvl; - u32 array_layer; -}; - -struct vk_subrsrc_layout_t { - u64 offset; - u64 sz; - u64 row_pitch; - u64 array_pitch; - u64 depth_pitch; -}; - -struct vk_acquire_next_img_info_t { - u32 type; - void *next; - void *swpchn; - u64 timeout; - void *sem; - void *fence; - u32 devs; -}; - -struct vk_fence_create_info_t { - u32 type; - void *next; - u32 flags; -}; - -struct vk_img_subrsrc_layers_t { - u32 aspect; - u32 mip_lvl; - u32 base_array_layer; - u32 array_layers_n; -}; - -struct vk_offset_3d_t { - u32 x; - u32 y; - u32 z; -}; - -struct vk_img_blit_t { - struct vk_img_subrsrc_layers_t src_subrsrc; - struct vk_offset_3d_t src_offsets[2]; - struct vk_img_subrsrc_layers_t dst_subrsrc; - struct vk_offset_3d_t dst_offsets[2]; -}; - -struct vk_present_info_t { - u32 type; - void *next; - u32 wait_sems_n; - void **wait_sems; - u32 swpchns_n; - void **swpchns; - u32 *idxs; - s32 *results; -}; - -struct vk_sem_create_info_t { - u32 type; - void *next; - u32 flags; -}; -/******************************************************************************/ -/* dev function pointers prototypes with some namespace/local keywords */ -#define vk_get_dev_q(...) \ -app_surf.dev.dl_vk_get_dev_q(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_create_cmdpool(...) \ -app_surf.dev.dl_vk_create_cmdpool(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_create_swpchn(...) \ -app_surf.dev.dl_vk_create_swpchn(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_get_swpchn_imgs(...) \ -app_surf.dev.dl_vk_get_swpchn_imgs(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_create_img(...) \ -app_surf.dev.dl_vk_create_img(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_get_img_mem_rqmts(...) \ -app_surf.dev.dl_vk_get_img_mem_rqmts(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_alloc_mem(...) \ -app_surf.dev.dl_vk_alloc_mem(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_bind_img_mem(...) \ -app_surf.dev.dl_vk_bind_img_mem(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_map_mem(...) \ -app_surf.dev.dl_vk_map_mem(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_alloc_cmdbufs(...) \ -app_surf.dev.dl_vk_alloc_cmdbufs(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_free_cmdbufs(...) \ -app_surf.dev.dl_vk_free_cmdbufs(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_begin_cmdbuf(...) \ -app_surf.dev.dl_vk_begin_cmdbuf(__VA_ARGS__) - -#define vk_end_cmdbuf(...) \ -app_surf.dev.dl_vk_end_cmdbuf(__VA_ARGS__) - -#define vk_cmd_pipeline_barrier(...) \ -app_surf.dev.dl_vk_cmd_pipeline_barrier(__VA_ARGS__) - -#define vk_q_submit(...) \ -app_surf.dev.dl_vk_q_submit(__VA_ARGS__) - -#define vk_q_wait_idle(...) \ -app_surf.dev.dl_vk_q_wait_idle(__VA_ARGS__) - -#define vk_get_img_subrsrc_layout(...) \ -app_surf.dev.dl_vk_get_img_subrsrc_layout(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_acquire_next_img(...) \ -app_surf.dev.dl_vk_acquire_next_img(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_create_fence(...) \ -app_surf.dev.dl_create_fence(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_reset_cmdbuf(...) \ -app_surf.dev.dl_vk_reset_cmdbuf(__VA_ARGS__) - -#define vk_cmd_blit_img(...) \ -app_surf.dev.dl_vk_cmd_blit_img(__VA_ARGS__) - -#define vk_wait_for_fences(...) \ -app_surf.dev.dl_vk_wait_for_fences(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_reset_fences(...) \ -app_surf.dev.dl_vk_reset_fences(app_surf.dev.vk,##__VA_ARGS__) - -#define vk_q_present(...) \ -app_surf.dev.dl_vk_q_present(__VA_ARGS__) - -#define vk_create_sem(...) \ -app_surf.dev.dl_vk_create_sem(app_surf.dev.vk,##__VA_ARGS__) -/*----------------------------------------------------------------------------*/ -#define VK_DEV_SYMS \ - void (*dl_vk_get_dev_q)(void *dev, u32 fam, u32 q_idx, void **q); \ - s32 (*dl_vk_create_cmdpool)( \ - void *dev, \ - struct vk_cmdpool_create_info_t *create_info, \ - void *allocator, \ - void **vk_cmdpool); \ - s32 (*dl_vk_create_swpchn)( \ - void *dev, \ - struct vk_swpchn_create_info_t *info, \ - void *allocator, \ - void **swpchn); \ - s32 (*dl_vk_get_swpchn_imgs)( \ - void *dev, \ - void *swpchn, \ - u32 *imgs_n, \ - void **imgs); \ - s32 (*dl_vk_create_img)( \ - void *dev, \ - struct vk_img_create_info_t *info, \ - void *allocator, \ - void **img); \ - s32 (*dl_vk_get_img_mem_rqmts)( \ - void *dev, \ - struct vk_img_mem_rqmts_info_t *info, \ - struct vk_mem_rqmts_t *mem_rqmts); \ - s32 (*dl_vk_alloc_mem)( \ - void *dev, \ - struct vk_mem_alloc_info_t *info, \ - void *allocator, \ - void **mem); \ - s32 (*dl_vk_bind_img_mem)( \ - void *dev, \ - u32 infos_n, \ - struct vk_bind_img_mem_info_t *infos); \ - s32 (*dl_vk_map_mem)( \ - void *dev, \ - void *mem, \ - u64 offset, \ - u64 sz, \ - u32 flags, \ - void **data); \ - s32 (*dl_vk_alloc_cmdbufs)( \ - void *dev, \ - struct vk_cmdbuf_alloc_info_t *info, \ - void **cmdbufs); \ - void (*dl_vk_free_cmdbufs)( \ - void *dev, \ - void *cmdpool, \ - u32 cmdbufs_n, \ - void **cmdbufs); \ - s32 (*dl_vk_begin_cmdbuf)( \ - void *cmdbuf, \ - struct vk_cmdbuf_begin_info_t *info); \ - s32 (*dl_vk_end_cmdbuf)(void *cmdbuf); \ - void (*dl_vk_cmd_pipeline_barrier)( \ - void *cmdbuf, \ - u32 src_stage, \ - u32 dst_stage, \ - u32 dependency_flags, \ - u32 mem_barriers_n, \ - void *mem_barriers, \ - u32 buf_mem_barriers_n, \ - void *buf_mem_barriers, \ - u32 img_mem_barriers_n, \ - struct vk_img_mem_barrier_t *img_mem_barriers); \ - s32 (*dl_vk_q_submit)( \ - void *q, \ - u32 submits_n, \ - struct vk_submit_info_t *submits, \ - void *fence); \ - s32 (*dl_vk_q_wait_idle)(void *q); \ - void (*dl_vk_get_img_subrsrc_layout)( \ - void *dev, \ - void *img, \ - struct vk_img_subrsrc_t *subrsrc, \ - struct vk_subrsrc_layout_t *layout); \ - s32 (*dl_vk_acquire_next_img)( \ - void *dev, \ - struct vk_acquire_next_img_info_t *info, \ - u32 *img_idx); \ - s32 (*dl_vk_create_fence)( \ - void *dev, \ - struct vk_fence_create_info_t *info, \ - void *allocator, \ - void **fence); \ - s32 (*dl_vk_reset_cmdbuf)( \ - void *cmdbuf, \ - u32 flags); \ - void (*dl_vk_cmd_blit_img)( \ - void *cmdbuf, \ - void *src_img, \ - u32 src_img_layout, \ - void *dst_img, \ - u32 dst_img_layout, \ - u32 regions_n, \ - struct vk_img_blit_t *regions, \ - u32 filter); \ - s32 (*dl_vk_wait_for_fences)( \ - void *dev, \ - u32 fences_n, \ - void **fences, \ - u32 wail_all, \ - u64 timeout); \ - s32 (*dl_vk_reset_fences)( \ - void *dev, \ - u32 fences_n, \ - void **fences); \ - s32 (*dl_vk_q_present)( \ - void *q, \ - struct vk_present_info_t *info); \ - s32 (*dl_vk_create_sem)( \ - void *dev, \ - struct vk_sem_create_info_t *info, \ - void *allocator, \ - void **sem); -#endif diff --git a/2d/kickstart/ABBREVIATIONS b/nyanvk/ABBREVIATIONS similarity index 61% rename from 2d/kickstart/ABBREVIATIONS rename to nyanvk/ABBREVIATIONS index e6ed355..0b514bc 100644 --- a/2d/kickstart/ABBREVIATIONS +++ b/nyanvk/ABBREVIATIONS @@ -1,59 +1,72 @@ -_g : _global (naming noise for identifier keyword namespace growth) _t : _type (naming noise for identifier keyword namespace growth) + app : APPlication -addr : ADDResse +addr : ADDRess +at(s) : ATtachment(S) blk(s) BLocK(S) buf(s) : BUFfer(S) -c : Connection (often) cap(s) : CAPability(ieS) +cb(s) : CommandBuffer(S) +clr : CLeaR cmdpool(s) : CoMmand POOL(S) -col(s) : COLumn(S) +comp(s) : COMPonent(S) conf(s) : CONFiguration(s) +const(s) : CONSTant(s) +cp(s) : CommandPool(S) cpu : Central Processing Unit +dep(s) : DEPendenc(y/IESES) desc(s) : DESCription(S) dev(s) : DEVice(S) -disp :DISPlay dl : Dynamic Loading +dset(s) : DescriptorSET(s) dst : DeSTination +ena : ENAble enum : ENUMeration -env : ENVironment err : error -evt(s) :EVenT(S) ext(s) : EXTension(S) -Fam(S) : Family(ieS) +fam(s) : FAMily(ieS) +fb(s) : FrameBuffer(S) fmt(s) : ForMaT(S) -gfx : GraFiX +frag : FRAGment +gfx : Gra(F/PH)i(X/CS) gpu : Grafic Processing Unit id : IDentifier idx(s) : InDeX(eS) img(s) : IMaGe(S) +imgview(s) : IMaGe VIEW(S) info(s) : INFOrmation(S) lvl(s): LeVeL(S) max : MAXimum mem : MEMory +mod(s) : MODule(S) n : couNt -obj(s) : OBJect(S) -pe :Presentation Engine (vulkan) +op(s) : OPeration(S) +pe : Presentation Engine +pl : PipeLine (vulkan) phydev(s) : physical devices +prim(s) : PRIMitive(s) prio(s) : PRIOrity(ieS) proc : PROCedure prop(s) : properties q(s) : Queue(S) -r : Result (often) -resz : RESiZe +rp(s) : RenderPass(eS) +ref(s) : REFerence(S) rsrc(s) : ReSouRCe(S) rqmt(s) : ReQuireMenT(S) -scr(s) : SCReen(S) sem(s) : SEMaphore(S) +sh(s) : SHader(S) +shmod(s) : SHader MODule(S) spec : SPECification src : SouRCe struct : STRUCTure +sp(s) : SubPass(eS) surf(s) : SURFage(S) swpchn(s) : SWaPCHaiN(S) sym(s) : SYMbol(S) sz : SiZe -tmp : TeMPorary uuid : Universal Uniq IDentifier +val(s) : VALue(S) vk : VulKan +vtx(s) : VerTeX(eS) win : WINdow wsi : Window System Integration diff --git a/nyanvk/README b/nyanvk/README new file mode 100644 index 0000000..6f26cc4 --- /dev/null +++ b/nyanvk/README @@ -0,0 +1,4 @@ +alternative source kit for the vulkan api + +we renamed the version 2 of some part of the api like it was the default +default diff --git a/nyanvk/consts.h b/nyanvk/consts.h new file mode 100644 index 0000000..465ec4c --- /dev/null +++ b/nyanvk/consts.h @@ -0,0 +1,270 @@ +#ifndef NYANVK_CONSTS_H +#define NYANVK_CONSTS_H +/* + * this is public domain without any warranties of any kind + * Sylvain BERTRAND + */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ +/* + * 64 bits platforms: enums do default to 32 bits, but can go up to 64 bits + * based on the range of vals they hold. this is important for + * vulkan ABI which we will fix. + * _individually_, each val is defaulted to 32bits, if possible, and signed + * or not. + * XXX: All vulkan enums use 32 bits storage + */ +enum { + vk_err_out_of_host_mem = -1, + /*--------------------------------------------------------------------*/ + vk_success = 0, + vk_incomplete = 5, + vk_r_enum_max = 0x7fffffff +}; +enum { + vk_struct_type_instance_create_info = 1, + vk_struct_type_dev_q_create_info = 2, + vk_struct_type_dev_create_info = 3, + vk_struct_type_submit_info = 4, + vk_struct_type_mem_alloc_info = 5, + vk_struct_type_sem_create_info = 9, + vk_struct_type_img_create_info = 14, + vk_struct_type_imgview_create_info = 15, + vk_struct_type_shmod_create_info = 16, + vk_struct_type_pl_sh_stage_create_info = 18, + vk_struct_type_pl_vtx_input_state_create_info = 19, + vk_struct_type_pl_input_assembly_state_create_info = 20, + vk_struct_type_pl_viewport_state_create_info = 22, + vk_struct_type_pl_raster_state_create_info = 23, + vk_struct_type_pl_multisample_state_create_info = 24, + vk_struct_type_pl_color_blend_state_create_info = 26, + vk_struct_type_gfx_pl_create_info = 28, + vk_struct_type_pl_layout_create_info = 30, + vk_struct_type_fb_create_info = 37, + vk_struct_type_rp_create_info = 38, + vk_struct_type_cp_create_info = 39, + vk_struct_type_cb_alloc_info = 40, + vk_struct_type_cb_begin_info = 42, + vk_struct_type_rp_begin_info = 43, + vk_struct_type_img_mem_barrier = 45, + /* extension number 2 or index 1, offset 0 */ + vk_struct_type_swpchn_create_info = 1000000000 + 1000 + 0, + /* extension number 2 or index 1, offset 1 */ + vk_struct_type_present_info = 1000000000 + 1000 + 1, + /* extension number 6 or index 5, offset 0 */ + vk_struct_type_xcb_surf_create_info = 1000000000 + 5000 + 0, + /* extension number 60 or index 59, offset 1 */ + vk_struct_type_phydev_props = 1000000000 + 59000 + 1, + /* extension number 60 or index 59, offset 5 */ + vk_struct_type_q_fam_props = 1000000000 + 59000 + 5, + /* extension number 60 or index 59, offset 6 */ + vk_struct_type_phydev_mem_props = 1000000000 + 59000 + 6, + /* extension number 60 or index 59, offset 10 */ + vk_struct_type_acquire_next_img_info = 1000000000 + 59000 + 10, + /* extension number 91 or index 90, offset 0 */ + vk_struct_type_surf_caps = 1000000000 + 90000 + 0, + /* extension number 120 or index 119, offset 0 */ + vk_struct_type_phydev_surf_info = 1000000000 + 119000 + 0, + /* extension number 120 or index 119, offset 2 */ + vk_struct_type_surf_texel_mem_blk_conf = 1000000000 + 119000 + 2, + /* extension number 147 or index 146, offset 1 */ + vk_struct_type_img_mem_rqmts_info = 1000000000 + 146000 + 1, + /* extension number 147 or index 146, offset 3 */ + vk_struct_type_mem_rqmts = 1000000000 + 146000 + 3, + /* extension number 158 or index 157, offset 1 */ + vk_struct_type_bind_img_mem_info = 1000000000 + 157000 + 1, + vk_struct_type_enum_max = 0x7fffffff +}; +enum { + vk_phydev_type_other = 0, + vk_phydev_type_integrated_gpu = 1, + vk_phydev_type_discrete_gpu = 2, + vk_phydev_type_virtual_gpu = 3, + vk_phydev_type_cpu = 4, + vk_phydev_type_enum_max = 0x7fffffff +}; +enum { + vk_q_gfx_bit = 0x00000001, + vk_q_compute_bit = 0x00000002, + vk_q_transfer_bit = 0x00000004, + vk_q_sparse_binding_bit = 0x00000008, + vk_q_protected_bit = 0x00000010, + vk_q_flag_bits_enum_max = 0x7fffffff +}; +enum { + vk_cp_create_transient_bit = 0x00000001, + vk_cp_create_reset_cb_bit = 0x00000002, + vk_cp_create_flag_bits_enum_max = 0x7fffffff +}; +enum { + vk_texel_mem_blk_fmt_undefined = 0, + vk_texel_mem_blk_fmt_b8g8r8a8_unorm = 44, + vk_texel_mem_blk_fmt_b8g8r8a8_srgb = 50, + vk_texel_mem_blk_fmt_enum_max = 0x7fffffff +}; +enum { + vk_color_space_srgb_nonlinear = 0, + vk_color_space_enum_max = 0x7fffffff +}; +enum { + vk_mem_prop_dev_local_bit = 0x00000001, + vk_mem_prop_host_visible_bit = 0x00000002, + vk_mem_prop_host_cached_bit = 0x00000008, + vk_mem_prop_bits_enum_max = 0x7fffffff +}; +enum { + vk_mem_heap_dev_local_bit = 0x00000001, + vk_mem_heap_multi_instance_bit = 0x00000002, + vk_mem_heap_bits_enum_max = 0x7fffffff +}; +enum { + vk_surf_transform_identity_bit = 0x00000001, + vk_surf_transform_bits_enum_max = 0x7fffffff +}; +enum { + vk_composite_alpha_opaque_bit = 0x00000001, + vk_composite_alpha_bits_enum_max = 0x7fffffff +}; +enum { + vk_img_usage_transfer_src_bit = 0x00000001, + vk_img_usage_transfer_dst_bit = 0x00000002, + vk_img_usage_color_attachment_bit = 0x00000010, + vk_img_usage_bits_enum_max = 0x7fffffff +}; +enum { + vk_sharing_mode_exclusive = 0, + vk_sharing_mode_enum_max = 0x7fffffff +}; +enum { + vk_present_mode_immediate = 0, + vk_present_mode_mailbox = 1, + vk_present_mode_fifo = 2, + vk_present_mode_fifo_relaxed = 3, + vk_present_mode_enum_max = 0x7fffffff +}; +enum { + vk_img_type_2d = 1, + vk_img_type_enum_max = 0x7fffffff +}; +enum { + vk_samples_n_1_bit = 0x00000001, + vk_samples_n_bits_enum_max = 0x7fffffff +}; +enum { + vk_img_tiling_optimal = 0, + vk_img_tiling_linear = 1, + vk_img_tiling_enum_max = 0x7fffffff +}; +enum { + vk_img_create_flag_2d_array_compatible_bit = 0x00000002, + vk_img_create_flag_enum_max = 0x7fffffff +}; +enum { + vk_img_layout_undefined = 0, + vk_img_layout_general = 1, + vk_img_layout_color_at_optimal = 2, + /* extension number 2 or index 1, offset 2 */ + vk_img_layout_present = 1000000000 + 1000 + 2, + vk_img_layout_enum_n_max = 0x7fffffff +}; +enum { + /* more */ + vk_pl_stage_top_of_pipe_bit = (1 << 0), + vk_pl_stage_bottom_of_pipe_bit = (1 << 13), + vk_pl_stage_bits_enum_max = 0x7fffffff +}; +enum { + vk_img_aspect_color_bit = 1, + vk_img_aspect_bits_enum_max = 0x7fffffff +}; +enum { + vk_cb_lvl_primary = 0, + vk_cb_lvl_enum_max = 0x7fffffff +}; +enum { + vk_cb_usage_one_time_submit_bit = 0x00000001, + vk_cb_usage_enum_max = 0x7fffffff +}; +enum { + vk_comp_swizzle_identity = 0, + vk_comp_swizzle_enum_max = 0x7fffffff +}; +enum { + vk_imgview_type_2d = 1, + vk_imgview_type_enum_max = 0x7fffffff +}; +enum { + vk_at_load_op_load = 0, + vk_at_load_op_clr = 1, + vk_at_load_op_dont_care = 2, + vk_at_load_op_enum_max = 0x7fffffff +}; +enum { + vk_at_store_op_store = 0, + vk_at_store_op_dont_care = 1, + vk_at_store_op_enum_max = 0x7fffffff +}; +enum { + vk_pl_bind_point_gfx = 0, + vk_pl_bind_point_compute = 1, + vk_pl_bind_point_enum_max = 0x7fffffff +}; +enum { + vk_sh_stage_vtx_bit = 0x00000001, + vk_sh_stage_frag_bit = 0x00000010, + /* meh */ + vk_sh_stage_compute_bit = 0x00000020, + vk_sh_stage_bits_enum_max = 0x7fffffff +}; +enum { + vk_prim_topology_triangle_list = 3, + /* more */ + vk_prim_topology_enum_max = 0x7fffffff +}; +enum { + vk_logic_op_copy = 3, + vk_logic_op_enum_max = 0x7fffffff +}; +enum { + vk_color_comp_r_bit = 0x00000001, + vk_color_comp_g_bit = 0x00000002, + vk_color_comp_b_bit = 0x00000004, + vk_color_comp_a_bit = 0x00000008, + vk_color_comp_bits_enum_max = 0x7fffffff +}; +enum { + vk_blend_factor_zero = 0, + vk_blend_factor_one = 1, + vk_blend_factor_src_alpha = 6, + vk_blend_factor_one_minus_src_alpha = 7, + vk_blend_factor_enum_max = 0x7fffffff +}; +enum { + vk_blend_op_add = 0, + vk_blend_op_substract = 1, + vk_blend_op_reverse_substract = 2, + vk_blend_op_min = 3, + vk_blend_op_max = 4, + vk_blend_op_enum_max = 0x7fffffff +}; +enum { + vk_sp_contents_inline = 0, + /* more? */ + vk_sp_contents_enum_max = 0x7fffffff +}; +enum { + vk_polygon_mode_fill = 0, + /* more */ + vk_polygon_mode_enum_max = 0x7fffffff +}; +enum { + vk_cull_mode_none = 0, + vk_cull_mode_front_bit = 0x00000001, + vk_cull_mode_back_bit = 0x00000002, + vk_cull_mode_bits_enum_max = 0x7fffffff +}; +enum { + vk_front_face_counter_clockwise = 0, + vk_front_face_clockwise = 1, + vk_front_face_enum_max = 0x7fffffff +}; +#endif diff --git a/nyanvk/syms_dev.h b/nyanvk/syms_dev.h new file mode 100644 index 0000000..8631cab --- /dev/null +++ b/nyanvk/syms_dev.h @@ -0,0 +1,155 @@ +#ifndef NYANVK_SYMS_DEV_H +#define NYANVK_SYMS_DEV_H +/* + * this is public domain without any warranties of any kind + * Sylvain BERTRAND + */ +/* XXX: define VK_DEV_SYMS and cherry pick what you actually use */ +#define VK_DEV_SYMS_FULL \ + void (*dl_vk_get_dev_q)(void *dev, u32 fam, u32 q_idx, void **q); \ + s32 (*dl_vk_create_cp)( \ + void *dev, \ + struct vk_cp_create_info_t *create_info, \ + void *allocator, \ + void **vk_cp); \ + s32 (*dl_vk_create_swpchn)( \ + void *dev, \ + struct vk_swpchn_create_info_t *info, \ + void *allocator, \ + void **swpchn); \ + s32 (*dl_vk_get_swpchn_imgs)( \ + void *dev, \ + void *swpchn, \ + u32 *imgs_n, \ + void **imgs); \ + s32 (*dl_vk_create_img)( \ + void *dev, \ + struct vk_img_create_info_t *info, \ + void *allocator, \ + void **img); \ + s32 (*dl_vk_get_img_mem_rqmts)( \ + void *dev, \ + struct vk_img_mem_rqmts_info_t *info, \ + struct vk_mem_rqmts_t *mem_rqmts); \ + s32 (*dl_vk_alloc_mem)( \ + void *dev, \ + struct vk_mem_alloc_info_t *info, \ + void *allocator, \ + void **mem); \ + s32 (*dl_vk_bind_img_mem)( \ + void *dev, \ + u32 infos_n, \ + struct vk_bind_img_mem_info_t *infos); \ + s32 (*dl_vk_map_mem)( \ + void *dev, \ + void *mem, \ + u64 offset, \ + u64 sz, \ + u32 flags, \ + void **data); \ + s32 (*dl_vk_alloc_cbs)( \ + void *dev, \ + struct vk_cb_alloc_info_t *info, \ + void **cbs); \ + s32 (*dl_vk_begin_cb)( \ + void *cb, \ + struct vk_cb_begin_info_t *info); \ + s32 (*dl_vk_end_cb)(void *cb); \ + void (*dl_vk_cmd_pl_barrier)( \ + void *cb, \ + u32 src_stage, \ + u32 dst_stage, \ + u32 dep_flags, \ + u32 mem_barriers_n, \ + void *mem_barriers, \ + u32 buf_mem_barriers_n, \ + void *buf_mem_barriers, \ + u32 img_mem_barriers_n, \ + struct vk_img_mem_barrier_t *img_mem_barriers); \ + s32 (*dl_vk_q_submit)( \ + void *q, \ + u32 submits_n, \ + struct vk_submit_info_t *submits, \ + void *fence); \ + s32 (*dl_vk_q_wait_idle)(void *q); \ + s32 (*dl_vk_acquire_next_img)( \ + void *dev, \ + struct vk_acquire_next_img_info_t *info, \ + u32 *img_idx); \ + s32 (*dl_vk_q_present)( \ + void *q, \ + struct vk_present_info_t *info); \ + s32 (*dl_vk_create_sem)( \ + void *dev, \ + struct vk_sem_create_info_t *info, \ + void *allocator, \ + void **sem); \ + s32 (*dl_vk_create_imgview)( \ + void *dev, \ + struct vk_imgview_create_info_t *info, \ + void *allocator, \ + void **imgview); \ + s32 (*dl_vk_create_rp)( \ + void *dev, \ + struct vk_rp_create_info_t *info, \ + void *allocator, \ + void **rp); \ + s32 (*dl_vk_create_fb)( \ + void *dev, \ + struct vk_fb_create_info_t *info, \ + void *allocator, \ + void **fb); \ + s32 (*dl_vk_create_shmod)( \ + void *dev, \ + struct vk_shmod_create_info_t *info, \ + void *allocator, \ + void **shmod); \ + s32 (*dl_vk_reset_cb)( \ + void *cb, \ + u32 flags); \ + void (*dl_vk_destroy_shmod)( \ + void *dev, \ + void *shmod, \ + void *allocator); \ + s32 (*dl_vk_create_pl_layout)( \ + void *dev, \ + struct vk_pl_layout_create_info_t *info, \ + void *allocator, \ + void **pl_layout); \ + s32 (*dl_vk_create_gfx_pls)( \ + void *dev, \ + void *pl_cache, \ + u32 create_infos_n, \ + struct vk_gfx_pl_create_info_t *infos, \ + void *allocator, \ + void **pl); \ + void (*dl_vk_get_img_subrsrc_layout)( \ + void *dev, \ + void *img, \ + struct vk_img_subrsrc_t *subrsrc, \ + struct vk_subrsrc_layout_t *layout); \ + void (*dl_vk_cmd_begin_rp)( \ + void *cb, \ + struct vk_rp_begin_info_t *info, \ + u32 contents); \ + void (*dl_vk_cmd_end_rp)(void *cb); \ + void (*dl_vk_cmd_bind_pl)( \ + void *cb, \ + u32 pl_bind_point, \ + void *pl); \ + void (*dl_vk_cmd_blit_img)( \ + void *cb, \ + void *src_img, \ + u32 src_img_layout, \ + void *dst_img, \ + u32 dst_img_layout, \ + u32 regions_n, \ + struct vk_img_blit_t *regions, \ + u32 filter); \ + void (*dl_vk_cmd_draw)( \ + void *cb, \ + u32 vtxs_n, \ + u32 instances_n, \ + u32 first_vtx, \ + u32 first_instance); +#endif diff --git a/nyanvk/syms_global.h b/nyanvk/syms_global.h new file mode 100644 index 0000000..6682082 --- /dev/null +++ b/nyanvk/syms_global.h @@ -0,0 +1,72 @@ +#ifndef NYANVK_SYMS_GLOBAL_H +#define NYANVK_SYMS_GLOBAL_H +/* + * this is public domain without any warranties of any kind + * Sylvain BERTRAND + */ +/* XXX: define VK_GLOBAL_SYMS and cherry pick what you actually use */ +#define VK_GLOBAL_SYMS_FULL \ + static void *(*dl_vk_get_instance_proc_addr)(void *instance, u8 *name);\ + static void *(*dl_vk_get_dev_proc_addr)(void *dev, u8 *name);\ +\ + static s32 (*dl_vk_enumerate_instance_version)(u32 *version);\ + static s32 (*dl_vk_enumerate_instance_layer_props)(\ + u32 *props_n,\ + struct vk_layer_props_t *props);\ + static s32 (*dl_vk_enumerate_instance_ext_props)(\ + u8 *layer_name,\ + u32 *props_n,\ + struct vk_ext_props_t *props);\ + static s32 (*dl_vk_create_instance)(\ + struct vk_instance_create_info_t *info,\ + void *allocator,\ + void **instance);\ + static s32 (*dl_vk_enumerate_phydevs)(\ + void *instance,\ + u32 *phydevs_n,\ + void **phydevs);\ + static s32 (*dl_vk_enumerate_dev_ext_props)(\ + void *phydev,\ + u8 *layer_name,\ + u32 *props_n,\ + struct vk_ext_props_t *props);\ + static void (*dl_vk_get_phydev_props)(\ + void *phydev,\ + struct vk_phydev_props_t *props);\ + static s32 (*dl_vk_create_dev)(\ + void *phydev,\ + struct vk_dev_create_info_t *create_info,\ + void *allocator,\ + void **dev);\ + static void (*dl_vk_get_phydev_q_fam_props)(\ + void *phydev,\ + u32 *q_fam_props_n,\ + struct vk_q_fam_props_t *props);\ + static s32 (*dl_vk_create_xcb_surf)(\ + void *instance,\ + struct vk_xcb_surf_create_info_t *info,\ + void *allocator,\ + void **surf);\ + static s32 (*dl_vk_get_phydev_surf_support)(\ + void *phydev,\ + u32 q_fam,\ + void *surf,\ + u32 *supported);\ + static s32 (*dl_vk_get_phydev_surf_texel_mem_blk_confs)(\ + void *phydev,\ + struct vk_phydev_surf_info_t *info,\ + u32 *confs_n,\ + struct vk_surf_texel_mem_blk_conf_t *confs);\ + static void (*dl_vk_get_phydev_mem_props)(\ + void *phydev,\ + struct vk_phydev_mem_props_t *props);\ + static s32 (*dl_vk_get_phydev_surf_caps)(\ + void *phydev,\ + struct vk_phydev_surf_info_t *info,\ + struct vk_surf_caps_t *caps);\ + static s32 (*dl_vk_get_phydev_surf_present_modes)(\ + void *phydev,\ + void *surf,\ + u32 *modes_n,\ + u32 *modes); +#endif diff --git a/nyanvk/types.h b/nyanvk/types.h new file mode 100644 index 0000000..0272a56 --- /dev/null +++ b/nyanvk/types.h @@ -0,0 +1,593 @@ +#ifndef NYANVK_TYPES_H +#define NYANVK_TYPES_H +/* + * this is public domain without any warranties of any kind + * Sylvain BERTRAND + */ +/* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ +/*----------------------------------------------------------------------------*/ +#define vk_true 1 +#define vk_false 0 +#define vk_whole_sz 0xffffffffffffffff +#define vk_q_fam_ignored 0xffffffff +/*----------------------------------------------------------------------------*/ +#define VK_VERSION_MAJOR(x) (x >> 22) +#define VK_VERSION_MINOR(x) ((x >> 12) & 0x3ff) +#define VK_VERSION_PATCH(x) (x & 0xfff) +/*----------------------------------------------------------------------------*/ +struct vk_offset_2d_t { + u32 x; + u32 y; +}; +struct vk_offset_3d_t { + u32 x; + u32 y; + u32 z; +}; +struct vk_extent_2d_t { + u32 width; + u32 height; +}; +struct vk_extent_3d_t { + u32 width; + u32 height; + u32 depth; +}; +struct vk_rect_2d_t { + struct vk_offset_2d_t offset; + struct vk_extent_2d_t extent; +}; +struct vk_instance_create_info_t { + u32 type; + void *next; + u32 flags; + void *app_info; /* allow easy hidden driver optimizations: no! */ + u32 enabled_layers_n; + u8 **enabled_layer_names; + u32 enabled_exts_n; + u8 **enabled_ext_names; +}; +#define VK_MAX_EXT_NAME_SZ 256 +struct vk_ext_props_t { + u8 name[VK_MAX_EXT_NAME_SZ]; + u32 spec_version; +}; +#define VK_MAX_DESC_SZ 256 +struct vk_layer_props_t { + u8 name[VK_MAX_EXT_NAME_SZ]; + u32 spec_version; + u32 implementation_version; + u8 desc[VK_MAX_DESC_SZ]; +}; +struct vk_phydev_limits_t { + u32 not_used_00[11]; + u64 not_used_01[2]; + u32 not_used_02[51]; + float not_used_03[2]; + u32 not_used_04[3]; + float not_used_05[2]; + u32 not_used_06; + size_t not_used_07; + u64 not_used_08[3]; + u32 not_used_09[4]; + float not_used_10[2]; + u32 not_used_11[16]; + float not_used_12; + u32 not_used_13[4]; + float not_used_14[6]; + u32 not_used_15[2]; + u64 not_used_16[3]; +}; +struct vk_phydev_sparse_props_t { + u32 not_used[5]; +}; +#define VK_MAX_PHYDEV_NAME_SZ 256 +#define VK_UUID_SZ 16 +struct vk_phydev_props_core_t { + u32 api_version; + u32 driver_version; + u32 vendor_id; + u32 dev_id; + u32 dev_type; + u8 name[VK_MAX_PHYDEV_NAME_SZ]; + u8 pl_cache_uuid[VK_UUID_SZ]; + struct vk_phydev_limits_t limits; + struct vk_phydev_sparse_props_t sparse_props; +}; +/* the vulkan 1.1 version */ +struct vk_phydev_props_t { + u32 type; + void *next; + struct vk_phydev_props_core_t core; +}; +struct vk_q_fam_props_core_t { + u32 flags; + u32 qs_n; + u32 timestamp_valid_bits; + struct vk_extent_3d_t min_img_transfer_granularity; +}; +struct vk_q_fam_props_t { + u32 type; + void *next; + struct vk_q_fam_props_core_t core; +}; +struct vk_phydev_features_t { + u32 not_used[55]; +}; +struct vk_dev_q_create_info_t { + u32 type; + void *next; + u32 flags; + u32 q_fam; + u32 qs_n; + float *q_prios; +}; +struct vk_dev_create_info_t { + u32 type; + void *next; + u32 flags; + u32 q_create_infos_n; + struct vk_dev_q_create_info_t *q_create_infos; + u32 do_not_use_0; + void *do_not_use_1; + u32 enabled_exts_n; + u8 **enabled_ext_names; + void *do_not_use_2; +}; +struct vk_cp_create_info_t { + u32 type; + void *next; + u32 flags; + u32 q_fam; +}; +struct vk_xcb_surf_create_info_t { + u32 type; + void *next; + u32 flags; + xcb_connection_t *c; + xcb_window_t win; +}; +struct vk_phydev_surf_info_t { + u32 type; + void *next; + void *surf; +}; +struct vk_surf_texel_mem_blk_conf_core_t { + u32 fmt; + u32 color_space; +}; +struct vk_surf_texel_mem_blk_conf_t { + u32 type; + void *next; + struct vk_surf_texel_mem_blk_conf_core_t core; +}; +struct vk_mem_type_t { + u32 prop_flags; + u32 heap; +}; +struct vk_mem_heap_t { + u64 sz; + u32 flags; +}; +#define VK_MEM_TYPES_N_MAX 32 +#define VK_MEM_HEAPS_N_MAX 16 +struct vk_phydev_mem_props_core_t { + u32 mem_types_n; + struct vk_mem_type_t mem_types[VK_MEM_TYPES_N_MAX]; + u32 mem_heaps_n; + struct vk_mem_heap_t mem_heaps[VK_MEM_HEAPS_N_MAX]; +}; +struct vk_phydev_mem_props_t { + u32 type; + void *next; + struct vk_phydev_mem_props_core_t core; +}; +struct vk_surf_caps_core_t { + u32 imgs_n_min; + u32 imgs_n_max; + struct vk_extent_2d_t current_extent; + struct vk_extent_2d_t img_extent_min; + struct vk_extent_2d_t img_extent_max; + u32 img_array_layers_n_max; + u32 supported_transforms; + u32 current_transform; + u32 supported_composite_alpha; + u32 supported_img_usage_flags; +}; +struct vk_surf_caps_t { + u32 type; + void *next; + struct vk_surf_caps_core_t core; +}; +struct vk_swpchn_create_info_t { + u32 type; + void *next; + u32 flags; + void *surf; + u32 imgs_n_min; + u32 img_texel_mem_blk_fmt; + u32 img_color_space; + struct vk_extent_2d_t img_extent; + u32 img_layers_n; + u32 img_usage; + u32 img_sharing_mode; + u32 q_fams_n; + u32 *q_fams; + u32 pre_transform; + u32 composite_alpha; + u32 present_mode; + u32 clipped; + void *old_swpchn; +}; +struct vk_img_create_info_t { + u32 type; + void *next; + u32 flags; + u32 img_type; + u32 texel_mem_blk_fmt; + struct vk_extent_3d_t extent; + u32 mip_lvls_n; + u32 array_layers_n; + u32 samples_n; /* flags */ + u32 img_tiling; + u32 usage; + u32 sharing_mode; + u32 q_fams_n; + u32 *q_fams; + u32 initial_layout; +}; +struct vk_img_mem_rqmts_info_t { + u32 type; + void *next; + void *img; +}; +struct vk_mem_rqmts_core_t { + u64 sz; + u64 alignment; + /* idxs of bits are idxs in mem types of vk_phydev_mem_props_core_t */ + u32 mem_type_bits; +}; +struct vk_mem_rqmts_t { + u32 type; + void *next; + struct vk_mem_rqmts_core_t core; +}; +struct vk_mem_alloc_info_t { + u32 type; + void *next; + u64 sz; + u32 mem_type_idx; /* in the physical device array of memory types */ +}; +struct vk_bind_img_mem_info_t { + u32 type; + void *next; + void *img; + void *mem; + u64 offset; +}; +struct vk_img_subrsrc_range_t { + u32 aspect; + u32 base_mip_lvl; + u32 lvls_n; + u32 base_array_layer; + u32 array_layers_n; +}; +struct vk_img_mem_barrier_t { + u32 type; + void *next; + u32 src_access; + u32 dst_access; + u32 old_layout; + u32 new_layout; + u32 src_q_fam; + u32 dst_q_fam; + void *img; + struct vk_img_subrsrc_range_t subrsrc_range; +}; +struct vk_cb_alloc_info_t { + u32 type; + void *next; + void *cp; + u32 lvl; + u32 cbs_n; +}; +struct vk_cb_begin_info_t { + u32 type; + void *next; + u32 flags; + void *do_not_use; +}; +struct vk_submit_info_t { + u32 type; + void *next; + u32 wait_sems_n; + void **wait_sems; + u32* wait_dst_stages; + u32 cbs_n; + void **cbs; + u32 signal_sems_n; + void **signal_sems; +}; +struct vk_img_subrsrc_t { + u32 aspect; + u32 mip_lvl; + u32 array_layer; +}; +struct vk_subrsrc_layout_t { + u64 offset; + u64 sz; + u64 row_pitch; + u64 array_pitch; + u64 depth_pitch; +}; +struct vk_img_subrsrc_layers_t { + u32 aspect; + u32 mip_lvl; + u32 base_array_layer; + u32 array_layers_n; +}; +struct vk_acquire_next_img_info_t { + u32 type; + void *next; + void *swpchn; + u64 timeout; + void *sem; + void *fence; + u32 devs; +}; +struct vk_img_blit_t { + struct vk_img_subrsrc_layers_t src_subrsrc; + struct vk_offset_3d_t src_offsets[2]; + struct vk_img_subrsrc_layers_t dst_subrsrc; + struct vk_offset_3d_t dst_offsets[2]; +}; +struct vk_present_info_t { + u32 type; + void *next; + u32 wait_sems_n; + void **wait_sems; + u32 swpchns_n; + void **swpchns; + u32 *idxs; + s32 *results; +}; +struct vk_sem_create_info_t { + u32 type; + void *next; + u32 flags; +}; +struct vk_comp_map_t { + s32 r; + s32 g; + s32 b; + s32 a; +}; +struct vk_imgview_create_info_t { + u32 type; + void *next; + u32 flags; + void *img; + s32 view_type; + s32 fmt; + struct vk_comp_map_t comps; + struct vk_img_subrsrc_range_t subrsrc_range; +}; +struct vk_at_desc_t { + u32 flags; + u32 fmt; + u32 samples_n; + u32 load_op; + u32 store_op; + u32 stencil_load_op; + u32 stencil_store_op; + u32 initial_layout; + u32 final_layout; +}; +struct vk_at_ref_t { + u32 at; + u32 layout; +}; +struct vk_sp_desc_t { + u32 flags; + u32 pl_bind_point; + u32 input_ats_n; + struct vk_at_ref_t *input_ats; + u32 color_ats_n; + struct vk_at_ref_t *color_ats; + struct vk_at_ref_t *resolve_ats; + struct vk_at_ref_t *depth_stencil_ats; + u32 preserve_ats_n; + u32 *preserve_ats; +}; +struct vk_sp_dep_t { + u32 src_sp; + u32 dst_sp; + u32 src_stage_mask; + u32 dst_stage_mask; + u32 src_access_mask; + u32 dst_access_mask; + u32 dep; +}; +struct vk_rp_create_info_t { + u32 type; + void *next; + u32 flags; + u32 ats_n; + struct vk_at_desc_t *ats; + u32 sps_n; + struct vk_sp_desc_t *sps; + u32 deps_n; + struct vk_sp_dep_t *deps; +}; +struct vk_fb_create_info_t { + u32 type; + void *next; + u32 flags; + void *rp; + u32 ats_n; + void *ats; /* imgviews!!! */ + u32 width; + u32 height; + u32 layers_n; +}; +struct vk_shmod_create_info_t { + u32 type; + void *next; + u32 flags; + size_t code_sz; /* bytes_n */ + u32 *code; +}; +struct vk_pl_sh_stage_create_info_t { + u32 type; + void *next; + u32 flags; + u32 stage; + void *shmod; + u8 *name; + void *specialization_info; /* later */ +}; +struct vk_pl_vtx_input_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 not_used_0; + void *not_used_1; + u32 not_used_2; + void *not_used_3; +}; + +struct vk_pl_input_assembly_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 topology; + u32 prim_restart_ena; +}; +/* XXX: this does define a _transformation_ ! */ +struct vk_viewport_t { + f32 x; + f32 y; + f32 width; + f32 height; + f32 depth_min; + f32 depth_max; +}; +struct vk_pl_viewport_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 viewports_n; + struct vk_viewport_t *viewports; + u32 scissors_n; + struct vk_rect_2d_t *scissors; +}; +struct vk_pl_raster_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 depth_clamp_ena; + u32 raster_discard_ena; + u32 polygon_mode; + u32 cull_mode; + u32 front_face; + u32 depth_bias_ena; + f32 depth_bias_constant_factor; + f32 depth_bias_clamp; + f32 depth_bias_slope_factor; + f32 line_width; +}; +struct vk_pl_multisample_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 raster_samples_n; + u32 sample_shading_ena; + f32 sample_shading_min; + u32 sample_mask; + u32 alpha_to_coverage_ena; + u32 alpha_to_one_ena; +}; +struct vk_pl_color_blend_at_state_t { + u32 blend_ena; + + u32 src_color_blend_factor; + u32 dst_color_blend_factor; + /* normalized integer */ + u32 color_blend_op; + + u32 src_alpha_blend_factor; + u32 dst_alpha_blend_factor; + u32 alpha_blend_op; + + /* normalized integer */ + u32 color_write_mask; +}; +struct vk_pl_color_blend_state_create_info_t { + u32 type; + void *next; + u32 flags; + u32 logic_op_ena; + /* floats */ + u32 logic_op; + u32 ats_n; + struct vk_pl_color_blend_at_state_t *ats; + f32 blend_consts[4]; +}; +struct vk_pushconst_range_t { + u32 shader_stages; + u32 offset; + u32 size; +}; +struct vk_pl_layout_create_info_t { + u32 type; + void *next; + u32 flags; + u32 layouts_n; + void **layouts; + u32 pushconst_ranges_n; + struct vk_pushconst_range_t *ranges; +}; +struct vk_gfx_pl_create_info_t { + u32 type; + void *next; + u32 flags; + u32 sh_stages_n; + struct vk_pl_sh_stage_create_info_t *sh_stages; + struct vk_pl_vtx_input_state_create_info_t *vtx_input_state; + struct vk_pl_input_assembly_state_create_info_t *input_assembly_state; + void *dont_use_0; + struct vk_pl_viewport_state_create_info_t *viewport_state; + struct vk_pl_raster_state_create_info_t *raster_state; + struct vk_pl_multisample_state_create_info_t *multisample_state; + void *not_used_0; + struct vk_pl_color_blend_state_create_info_t *color_blend_state; + void *not_used_1; + void *layout; + void *rp; + u32 sp; + void *base_pl; + u32 base_pl_idx; +}; +union vk_clr_color_val_t { + f32 f32s[4]; + u32 u32s[4]; + s32 s32s[4]; +}; +struct vk_clr_depth_stencil_val_t { + f32 depth; + u32 stencil; +}; +union vk_clr_val_t { + union vk_clr_color_val_t color; + struct vk_clr_depth_stencil_val_t depth_stencil; +}; +struct vk_rp_begin_info_t { + u32 type; + void *next; + void *rp; + void *fb; + struct vk_rect_2d_t render_area; + u32 clr_vals_n; + union vk_clr_val_t *clr_vals; +}; +#endif -- 2.11.4.GIT