Subject | Hash | Author | Date (UTC) |
---|---|---|---|
3d kickstart from clip coords | e9729e6b6072cc0bf8aa30b133c3404c62b48bac | Sylvain BERTRAND | 2020-01-16 23:54:44 |
render a first frame | ae37f575961a8645c967c774d5ce7db6ec50e118 | Sylvain BERTRAND | 2020-01-16 23:41:31 |
fix from debug mode | d62a1ebe64c1c6257c13507a30e4bb66e53c3db9 | Sylvain BERTRAND | 2020-01-16 20:31:06 |
simplification/taylorization and fix | cf73091d7461b2d872020e0ea3db3b8f75b27c80 | Sylvain BERTRAND | 2020-01-14 17:16:45 |
sync-ing asm and dis for minimal shaders | a1aec48b7011a11632eb42acae562e0cee6110df | Sylvain BERTRAND | 2020-01-03 17:40:13 |
spirv: introducing asm and dis improvement | 9275a362039315e40a5328743846754f47f9559f | Sylvain BERTRAND | 2019-12-31 03:52:33 |
adjust and confirm some register acronymes | 1f0d098ac18f61f6d9dbc00694da84b5a7d0274e | Sylvain BERTRAND | 2019-12-02 14:25:44 |
partial and brainded pm4 disassembler | 88bd38675091a9164583a05abb672c6d1962d133 | Sylvain BERTRAND | 2019-11-30 19:10:22 |
untested amd gcn gfx6 disassembler | 942c2b45ce87dd3c031289acf662679933997c21 | Sylvain BERTRAND | 2019-11-28 18:45:56 |
typos | 729922e37ff800683763794352533924250e8579 | Sylvain BERTRAND | 2019-11-17 16:33:36 |
braindead partial spir-v disassembler | a347cbcc8284301ad6989d486373f0d2ffb9657c | Sylvain BERTRAND | 2019-11-16 17:48:29 |
Initial commit | 1cd013eaa1466522d61c7b0e64d5858055fedbfa | Sylvain BERTRAND | 2019-10-25 18:49:16 |
File | Lines added | Lines deleted |
---|---|---|
3d/clip_coords/ABBREVIATIONS | 4 | 0 |
3d/clip_coords/NAMESPACE | 0 | 0 |
3d/clip_coords/README | 26 | 0 |
3d/clip_coords/TODO | 3 | 0 |
3d/clip_coords/app.c | 362 | 456 |
3d/clip_coords/app_core_types.h | 0 | 0 |
3d/clip_coords/app_state.c | 10 | 3 |
3d/clip_coords/app_state_types.h | 15 | 22 |
3d/clip_coords/fs.S | 32 | 0 |
3d/clip_coords/log.h | 0 | 0 |
3d/clip_coords/namespace/app.c | 36 | 49 |
3d/clip_coords/namespace/app_state.c | 0 | 4 |
3d/clip_coords/namespace/app_state_types.h | 2 | 4 |
3d/clip_coords/namespace/vk_syms.c | 0 | 0 |
3d/clip_coords/vk_app.h | 188 | 0 |
3d/clip_coords/vk_syms.c | 15 | 15 |
3d/clip_coords/vs.S | 73 | 0 |
3d/clip_coords/xcb.c | 1 | 1 |
3d/clip_coords/xcb_syms.c | 0 | 0 |
nyanvk/types.h | 2 | 1 |
spirv/asm/asm.c | 84 | 2 |
File 3d/clip_coords/ABBREVIATIONS copied from file 2d/blit/ABBREVIATIONS (similarity 69%) (mode: 100644) (index ea340d8..67ff39d) | |||
... | ... | c : Connection (often) | |
6 | 6 | disp :DISPlay | disp :DISPlay |
7 | 7 | env : ENVironment | env : ENVironment |
8 | 8 | evt(s) :EVenT(S) | evt(s) :EVenT(S) |
9 | fs : Fragment Shader (=pixel shader) | ||
9 | 10 | obj(s) : OBJect(S) | obj(s) : OBJect(S) |
11 | ps : Pixel Shader (=fragment shader) | ||
10 | 12 | r : Result (often) | r : Result (often) |
13 | rp(s) : RenderPass(eS) | ||
11 | 14 | rec : RECord | rec : RECord |
12 | 15 | resz : RESiZe | resz : RESiZe |
13 | 16 | scr(s) : SCReen(S) | scr(s) : SCReen(S) |
14 | 17 | tmp : TeMPorary | tmp : TeMPorary |
18 | vs : Vertex Shader |
File 3d/clip_coords/NAMESPACE copied from file 2d/blit/NAMESPACE (similarity 100%) |
File 3d/clip_coords/README added (mode: 100644) (index 0000000..ffdfa90) | |||
1 | The vulkan API is, here, simplified and taylored for the app using the | ||
2 | C preprocessor. In other words, when there is no ambiguity in the context of | ||
3 | this code, vulkan API function parameters get simplified out in a C preprocessor | ||
4 | macros. | ||
5 | |||
6 | The spirv code for the vertex shader and the pixel shader is handcrafted. | ||
7 | Everybody should code straight spirv with a spirv assembler in order to work | ||
8 | around the nastyness of many "compilers". | ||
9 | |||
10 | We used the braindead spirv asm (which comes with a companion disassembler). | ||
11 | -------------------------------------------------------------------------------- | ||
12 | BUILD: | ||
13 | # preprocess the shaders (care, gcc cpp is broken regarding line continuation). | ||
14 | cpp vs.S >/tmp/vs.cpp | ||
15 | cpp fs.S >/tmp/fs.cpp | ||
16 | |||
17 | # assemble the shaders | ||
18 | asm </tmp/vs.cpp >/tmp/vs.spirv | ||
19 | asm </tmp/fs.cpp >/tmp/fs.spirv | ||
20 | |||
21 | # build the app | ||
22 | gcc -o /tmp/app app.c -I$xcb_headers_path -ldl | ||
23 | |||
24 | RUN: | ||
25 | cd /tmp | ||
26 | ./app |
File 3d/clip_coords/TODO added (mode: 100644) (index 0000000..82aac29) | |||
1 | - check and use vk_create_renderpass_2 | ||
2 | - check and use vk_cmdbuf_begin_renderpass_2 | ||
3 | - remove posix stuff for std c library stuff (the way we read the shaders). |
File 3d/clip_coords/app.c copied from file 2d/blit/app.c (similarity 68%) (mode: 100644) (index e483138..13dc075) | |||
5 | 5 | * Sylvain BERTRAND | * Sylvain BERTRAND |
6 | 6 | */ | */ |
7 | 7 | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ |
8 | /* | ||
9 | * XXX vk abstraction is much more complex than real hardware, aka the cost of | ||
10 | * most software generalisation/abstraction (and some hardware has lost its | ||
11 | * way...). Better know some real hardware programming (for instance AMD | ||
12 | * open gpu) and keep that in mind while dealing with vk. | ||
13 | * since it's complex, have a "safe mode", kind of minimal use of vk. doing | ||
14 | * fancy stuff above this "safe mode" must be validated by hardware vendors | ||
15 | * then the user... or you literally walking on eggs. | ||
16 | * | ||
17 | * The vulkan API is, here, simplified and taylored for the app using the C | ||
18 | * preprocessor. In other words, when there is no ambiguity in the context of | ||
19 | * this code, vulkan API function parameters get simplified out in C | ||
20 | * preprocessor macros. | ||
21 | * | ||
22 | * XXX: this is a "One Compilation Unit" source code with preprocessor | ||
23 | * namespace support. this allow the project to grow to very large and keep the | ||
24 | * global identifier space in check (= tradeoff). Each source file, *.h *.c, | ||
25 | * should compile without errors. | ||
26 | * | ||
27 | * XXX: you may have to track the dependencies of vk objs that in order to be | ||
28 | * able to deal with any of their brutal state changes: | ||
29 | * - a dev can be lost (i.e. power management evt or bad hardware) | ||
30 | * - a surf can be lost (i.e. power management evt or something went | ||
31 | * really bad) | ||
32 | * - a swpchn can become out-of-date. for instance the win system did resz | ||
33 | * the parent surf of the swpchn... if you did allow it to happen | ||
34 | * asynchronously. | ||
35 | * here we choose that any of those evts will be fatal for simplicity. for | ||
36 | * instance, if you choose to support the swpchn out-of-date state, if your | ||
37 | * rendering state was too much "pre-configured", you would have to | ||
38 | * "re-pre-configure" everything... or you should drop "pre-configuring" and | ||
39 | * program everything *again* for each swpchn img you draw. | ||
40 | * | ||
41 | * display programing is demonstrated "officially" in khronos vk cube.c and | ||
42 | * there is a tutorial slide "1-Vulkan-Tutorial.pdf" (just abstract away c++ | ||
43 | * cr*p) which is "the programming manual" on top of specs. this code is | ||
44 | * different: | ||
45 | * - only 1 "main" synchronous loop | ||
46 | * - only xcb wsi. xcb is a client library on top of the x11 protocol. | ||
47 | * we know wayland ("x12") should be added. | ||
48 | * - dynamic loading of xcb. | ||
49 | * - no need of vk headers (using directly the ABI with custom headers). | ||
50 | * | ||
51 | * WARNING: vk core q fam props discovery is not used for the discovery of | ||
52 | * q fams able to support disp, aka wsi. This is the case because disp | ||
53 | * handling (wsi), is done as an ext and is not core (vk can be use without | ||
54 | * a wsi). | ||
55 | * | ||
56 | * a phydev must have a q with gfx and compute. additionally, any q with gfx or | ||
57 | * compute does implicitely support transfer. basically, it is possible to have | ||
58 | * qs with only transfer support, and we are guaranteed to have a q with gfx | ||
59 | * and compute and transfer support. Keep in mind that many vk resources must | ||
60 | * pay the cost of transfering from 1 q fam to another q fam: then think twice | ||
61 | * on how you want to spread your work load on the q fams. | ||
62 | * | ||
63 | * for proper keyboard support, joypad way or/and text input way, read the | ||
64 | * included KEYBOARD file. here, since we use basic layout independent standard | ||
65 | * keys, the x11 core keyboard protocol is fairly enough. | ||
66 | * | ||
67 | * TODO: use as less as possible device memory object, namely try to allocate | ||
68 | * one big chunk and manage alignment constraint ourself. vk api does provide | ||
69 | * a way to query for the memory alignment constraints. | ||
70 | */ | ||
8 | /* C */ | ||
71 | 9 | #include <stdlib.h> | #include <stdlib.h> |
72 | 10 | #include <string.h> | #include <string.h> |
11 | /* posix, _must_ move that to C */ | ||
12 | #include <sys/stat.h> | ||
13 | #include <sys/mman.h> | ||
14 | #include <fcntl.h> | ||
15 | /* x11 */ | ||
73 | 16 | #include <xcb.h> | #include <xcb.h> |
74 | 17 | #include "app_core_types.h" | #include "app_core_types.h" |
75 | 18 | #include "nyanvk/consts.h" | #include "nyanvk/consts.h" |
79 | 22 | #include "log.h" | #include "log.h" |
80 | 23 | #include "vk_syms.c" | #include "vk_syms.c" |
81 | 24 | #include "app_state.c" | #include "app_state.c" |
25 | #include "xcb_syms.c" | ||
82 | 26 | #include "xcb.c" | #include "xcb.c" |
83 | 27 | /*---------------------------------------------------------------------------*/ | /*---------------------------------------------------------------------------*/ |
84 | 28 | #include "namespace/app.c" | #include "namespace/app.c" |
86 | 30 | #include "namespace/app_state_types.h" | #include "namespace/app_state_types.h" |
87 | 31 | #include "namespace/app_state.c" | #include "namespace/app_state.c" |
88 | 32 | /*---------------------------------------------------------------------------*/ | /*---------------------------------------------------------------------------*/ |
33 | /* | ||
34 | * In "wc", 'w' is the "standard" 4th 3d coord, and 'c' stands for 'C'lipped. | ||
35 | * the clip coords in vk is a 3d "cube": | ||
36 | * -"wc" <= x <= "wc" (w is the "standard" 4th coord, n | ||
37 | * -"wc" <= y <= "wc" | ||
38 | * 0.0f <= z <= "wc" | ||
39 | * y axis is pointing down | ||
40 | * x axis is pointing to the right | ||
41 | * z axis is pointing away from you | ||
42 | * "wc" is from the "projection matrix" _WITHOUT_ the "wc" division (you must | ||
43 | * understand the related 3d maths). | ||
44 | * | ||
45 | * Z | ||
46 | * ^ | ||
47 | * / | ||
48 | * / | ||
49 | * center(0,0,0) +-------> | ||
50 | * | X | ||
51 | * | | ||
52 | * | | ||
53 | * v Y | ||
54 | * | ||
55 | * | ||
56 | * the vtx position which is output by the vtx sh must be in those | ||
57 | * "clip coords", because the fixed-function GPU hardware will expect it. | ||
58 | * You must understand the different 3d coords from a math point of view. | ||
59 | * | ||
60 | * In "3d" we have 4 coords, x,y, z, w due to the fact | ||
61 | * that "perpective projection", with linear adjustment of z, is a linear | ||
62 | * transformation only in 4D. Linear adjustment of z is VERY important | ||
63 | * or you won't be able to write this projection as a 4x4 matrix. | ||
64 | * This is a "math trick", to allow classic 4x4 linear algebra to just "work". | ||
65 | * | ||
66 | * "clip coords" means the final w division for a complete "perspective | ||
67 | * projection" was not done. See the vk specs, "chapter 23.2 primitive | ||
68 | * clipping" (at the time of writing). | ||
69 | * | ||
70 | */ | ||
89 | 71 | #define VK_FATAL(fmt, ...) \ | #define VK_FATAL(fmt, ...) \ |
90 | 72 | if (r < 0) {\ | if (r < 0) {\ |
91 | 73 | LOG(fmt, ##__VA_ARGS__);\ | LOG(fmt, ##__VA_ARGS__);\ |
... | ... | if (r < 0) {\ | |
97 | 79 | LOG(fmt, ##__VA_ARGS__);\ | LOG(fmt, ##__VA_ARGS__);\ |
98 | 80 | exit(1);\ | exit(1);\ |
99 | 81 | } | } |
82 | static void file_mmap(u8 *path, u8 **map, u64 *sz) | ||
83 | { | ||
84 | struct stat file_stat; | ||
85 | int r; | ||
86 | int fd; | ||
87 | |||
88 | r = stat(path, &file_stat); | ||
89 | if (r != 0) | ||
90 | FATAL("0:MAIN:FATAL:%d:file_mmap:%s:error stating the file\n", r, path) | ||
91 | *sz = (u64)file_stat.st_size; | ||
92 | fd = open(path, O_RDONLY); | ||
93 | if (fd == -1) | ||
94 | FATAL("0:MAIN:FATAL:%d:file_mmap:%s:error openning the file\n", r, path) | ||
95 | *map = mmap(0, *sz, PROT_READ, MAP_PRIVATE, fd, 0); | ||
96 | if (*map == 0) | ||
97 | FATAL("0:MAIN:FATAL:%d:file_mmap:%s:fd=%d:error mmaping the file\n", r, path, fd) | ||
98 | } | ||
99 | |||
100 | 100 | /* the phydev q fam selected */ | /* the phydev q fam selected */ |
101 | 101 | static void dev_create(void) | static void dev_create(void) |
102 | 102 | { | { |
... | ... | static void dev_create(void) | |
109 | 109 | /* 1.1 promoted */ | /* 1.1 promoted */ |
110 | 110 | "VK_KHR_get_memory_requirements2", | "VK_KHR_get_memory_requirements2", |
111 | 111 | "VK_KHR_swapchain"}; | "VK_KHR_swapchain"}; |
112 | |||
113 | 112 | s32 r; | s32 r; |
114 | 113 | ||
115 | 114 | memset(&info, 0, sizeof(info)); | memset(&info, 0, sizeof(info)); |
... | ... | static void tmp_phydevs_q_fams_surf_support_get(void) | |
494 | 493 | break; | break; |
495 | 494 | supported = vk_false; | supported = vk_false; |
496 | 495 | vk_get_phydev_surf_support(p->vk, j, &supported); | vk_get_phydev_surf_support(p->vk, j, &supported); |
497 | 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) | ||
496 | 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); | ||
498 | 497 | if (supported == vk_true) { | if (supported == vk_true) { |
499 | 498 | 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); | 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); |
500 | 499 | p->q_fams_surf_support[j] = true; | p->q_fams_surf_support[j] = true; |
... | ... | static void texel_mem_blk_conf_select(void) | |
616 | 615 | 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) | 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) |
617 | 616 | if (confs_n > CONFS_N_MAX) | if (confs_n > CONFS_N_MAX) |
618 | 617 | 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) | 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) |
619 | |||
620 | 618 | memset(confs, 0, sizeof(confs[0]) * confs_n); | memset(confs, 0, sizeof(confs[0]) * confs_n); |
621 | 619 | i = 0; | i = 0; |
622 | 620 | loop { | loop { |
... | ... | static void texel_mem_blk_conf_select(void) | |
630 | 628 | if (confs_n == 0) | if (confs_n == 0) |
631 | 629 | 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) | 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) |
632 | 630 | texel_mem_blk_confs_dump(confs_n, confs); | texel_mem_blk_confs_dump(confs_n, confs); |
633 | |||
634 | 631 | cc = &surf_g.dev.phydev.selected_texel_mem_blk_conf_core; | cc = &surf_g.dev.phydev.selected_texel_mem_blk_conf_core; |
635 | 632 | if ((confs_n == 1) && (confs[0].core.fmt | if ((confs_n == 1) && (confs[0].core.fmt |
636 | 633 | == vk_texel_mem_blk_fmt_undefined)) { | == vk_texel_mem_blk_fmt_undefined)) { |
... | ... | static void tmp_phydevs_mem_props_get(void) | |
669 | 666 | } | } |
670 | 667 | } | } |
671 | 668 | ||
672 | static void phydev_mem_heap_dump(void *phydev, u8 i, | ||
673 | struct vk_mem_heap_t *heap) | ||
669 | static void phydev_mem_heap_dump(void *phydev, u8 i, struct vk_mem_heap_t *heap) | ||
674 | 670 | { | { |
675 | 671 | LOG("0:MAIN:physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz); | LOG("0:MAIN:physical device:%p:memory heap:%u:size:%u bytes\n", phydev, i, heap->sz); |
676 | 672 | LOG("0:MAIN:physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags); | LOG("0:MAIN:physical device:%p:memory heap:%u:flags:%#08x\n", phydev, i, heap->flags); |
... | ... | static void phydev_mem_heap_dump(void *phydev, u8 i, | |
680 | 676 | LOG("0:MAIN:physical device:%p:memory type:%u:multi instance_g\n", phydev, i); | LOG("0:MAIN:physical device:%p:memory type:%u:multi instance_g\n", phydev, i); |
681 | 677 | } | } |
682 | 678 | ||
683 | static void phydev_mem_type_dump(void *phydev, u8 i, | ||
684 | struct vk_mem_type_t *type) | ||
679 | static void phydev_mem_type_dump(void *phydev, u8 i, struct vk_mem_type_t *type) | ||
685 | 680 | { | { |
686 | 681 | LOG("0:MAIN:physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap); | LOG("0:MAIN:physical device:%p:memory type:%u:heap:%u\n", phydev, i, type->heap); |
687 | 682 | LOG("0:MAIN:physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags); | LOG("0:MAIN:physical device:%p:memory type:%u:flags:%#08x\n", phydev, i, type->prop_flags); |
... | ... | static void swpchn_imgs_get(void) | |
784 | 779 | 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); | 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); |
785 | 780 | } | } |
786 | 781 | ||
782 | static void swpchn_imgview_create(u8 i) | ||
783 | { | ||
784 | struct vk_imgview_create_info_t info; | ||
785 | s32 r; | ||
786 | |||
787 | memset(&info, 0, sizeof(info)); | ||
788 | info.type = vk_struct_type_imgview_create_info; | ||
789 | info.img = surf_g.dev.swpchn.imgs[i]; | ||
790 | info.view_type = vk_imgview_type_2d; | ||
791 | info.fmt = surf_g.dev.phydev.selected_texel_mem_blk_conf_core.fmt; | ||
792 | info.subrsrc_range.aspect = vk_img_aspect_color_bit; | ||
793 | info.subrsrc_range.lvls_n = 1; | ||
794 | info.subrsrc_range.array_layers_n = 1; | ||
795 | vk_create_imgview(&info, &surf_g.dev.swpchn.imgviews[i]); | ||
796 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:swapchain:%p:image:%u:unable to create image view\n", r, surf_g.dev.vk, surf_g.dev.swpchn.vk, i) | ||
797 | LOG("0:MAIN:device:%p:swapchain:%p:image:%u:image view created %p\n", surf_g.dev.vk, surf_g.dev.swpchn.vk, i, surf_g.dev.swpchn.imgviews[i]); | ||
798 | } | ||
799 | |||
800 | static void swpchn_imgviews_create(void) | ||
801 | { | ||
802 | u8 i; | ||
803 | |||
804 | i = 0; | ||
805 | loop { | ||
806 | if (i == surf_g.dev.swpchn.imgs_n) | ||
807 | break; | ||
808 | swpchn_imgview_create(i); | ||
809 | ++i; | ||
810 | } | ||
811 | } | ||
812 | |||
787 | 813 | static void swpchn_init(void) | static void swpchn_init(void) |
788 | 814 | { | { |
789 | 815 | struct vk_swpchn_create_info_t info; | struct vk_swpchn_create_info_t info; |
... | ... | static void swpchn_init(void) | |
807 | 833 | info.composite_alpha = vk_composite_alpha_opaque_bit; | info.composite_alpha = vk_composite_alpha_opaque_bit; |
808 | 834 | info.present_mode = vk_present_mode_fifo; | info.present_mode = vk_present_mode_fifo; |
809 | 835 | info.clipped = vk_true; | info.clipped = vk_true; |
810 | vk_create_swpchn(&info); | ||
836 | vk_create_swpchn(&info, &surf_g.dev.swpchn.vk); | ||
811 | 837 | 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) | 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) |
812 | 838 | LOG("0:MAIN:device:%p:surface:%p:swapchain created %p\n", surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk); | LOG("0:MAIN:device:%p:surface:%p:swapchain created %p\n", surf_g.dev.vk, surf_g.vk, surf_g.dev.swpchn.vk); |
813 | 839 | } | } |
... | ... | static void tmp_present_modes_dump(void) | |
851 | 877 | } | } |
852 | 878 | } | } |
853 | 879 | ||
854 | static void cpu_img_create(u8 i) | ||
855 | { | ||
856 | struct vk_img_create_info_t info; | ||
857 | s32 r; | ||
858 | |||
859 | memset(&info, 0, sizeof(info)); | ||
860 | info.type = vk_struct_type_img_create_info; | ||
861 | info.flags = vk_img_create_flag_2d_array_compatible_bit; | ||
862 | info.img_type = vk_img_type_2d; | ||
863 | info.texel_mem_blk_fmt = vk_texel_mem_blk_fmt_b8g8r8a8_unorm; | ||
864 | info.extent.width = APP_CPU_IMG_WIDTH; | ||
865 | info.extent.height = APP_CPU_IMG_HEIGHT; | ||
866 | info.extent.depth = 1; | ||
867 | info.mip_lvls_n = 1; | ||
868 | info.samples_n = vk_samples_n_1_bit; | ||
869 | info.array_layers_n = 1; | ||
870 | info.img_tiling = vk_img_tiling_linear; | ||
871 | info.usage = vk_img_usage_transfer_src_bit; | ||
872 | info.initial_layout = vk_img_layout_undefined; | ||
873 | vk_create_img(&info, &surf_g.dev.cpu_imgs[i].vk); | ||
874 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create swapchain cpu image %u\n", r, surf_g.dev.vk, i) | ||
875 | LOG("0:MAIN:device:%p:swapchain cpu image %u created %p\n", surf_g.dev.vk, i, surf_g.dev.cpu_imgs[i].vk); | ||
876 | } | ||
877 | |||
878 | static void cpu_imgs_create(void) | ||
879 | { | ||
880 | u8 i; | ||
881 | |||
882 | i = 0; | ||
883 | loop { | ||
884 | if (i == surf_g.dev.swpchn.imgs_n) | ||
885 | break; | ||
886 | cpu_img_create(i); | ||
887 | ++i; | ||
888 | } | ||
889 | } | ||
890 | |||
891 | static void img_mem_barrier_run_once(u8 i, struct vk_img_mem_barrier_t *b) | ||
892 | { | ||
893 | s32 r; | ||
894 | struct vk_cb_begin_info_t begin_info; | ||
895 | struct vk_submit_info_t submit_info; | ||
896 | |||
897 | memset(&begin_info, 0, sizeof(begin_info)); | ||
898 | begin_info.type = vk_struct_type_cb_begin_info; | ||
899 | begin_info.flags = vk_cb_usage_one_time_submit_bit; | ||
900 | vk_begin_cb(surf_g.dev.cbs[i], &begin_info); | ||
901 | 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]) | ||
902 | /*--------------------------------------------------------------------*/ | ||
903 | vk_cmd_pl_barrier(app_surf.dev.cbs[i], b); | ||
904 | /*--------------------------------------------------------------------*/ | ||
905 | vk_end_cb(surf_g.dev.cbs[i]); | ||
906 | 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]) | ||
907 | /*--------------------------------------------------------------------*/ | ||
908 | memset(&submit_info, 0, sizeof(submit_info)); | ||
909 | submit_info.type = vk_struct_type_submit_info; | ||
910 | submit_info.cbs_n = 1; | ||
911 | submit_info.cbs = &surf_g.dev.cbs[i]; | ||
912 | vk_q_submit(&submit_info); | ||
913 | VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the initial layout transition command buffer\n", r, surf_g.dev.q) | ||
914 | /*--------------------------------------------------------------------*/ | ||
915 | vk_q_wait_idle(); | ||
916 | 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) | ||
917 | /*--------------------------------------------------------------------*/ | ||
918 | /* | ||
919 | * since it is tagged to run once its state_g is invalid, we need to | ||
920 | * reset it to the initial state_g | ||
921 | */ | ||
922 | vk_reset_cb(surf_g.dev.cbs[i]); | ||
923 | 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]) | ||
924 | } | ||
925 | |||
926 | static void cpu_img_layout_to_general(u8 i) | ||
927 | { | ||
928 | struct vk_img_mem_barrier_t b; | ||
929 | struct vk_img_subrsrc_range_t *r; | ||
930 | |||
931 | memset(&b, 0, sizeof(b)); | ||
932 | b.type = vk_struct_type_img_mem_barrier; | ||
933 | b.old_layout = vk_img_layout_undefined; | ||
934 | b.new_layout = vk_img_layout_general; | ||
935 | b.src_q_fam = vk_q_fam_ignored; | ||
936 | b.dst_q_fam = vk_q_fam_ignored; | ||
937 | b.img = surf_g.dev.cpu_imgs[i].vk; | ||
938 | r = &b.subrsrc_range; | ||
939 | r->aspect = vk_img_aspect_color_bit; | ||
940 | r->lvls_n = 1; | ||
941 | r->array_layers_n = 1; | ||
942 | img_mem_barrier_run_once(i, &b); | ||
943 | LOG("0:MAIN:cpu image:%p[%u]:transition to general layout successful\n", surf_g.dev.cpu_imgs[i].vk, i); | ||
944 | } | ||
945 | |||
946 | /* once in general layout, the dev sees the img */ | ||
947 | static void cpu_imgs_layout_to_general(void) | ||
948 | { | ||
949 | u8 i; | ||
950 | |||
951 | i = 0; | ||
952 | loop { | ||
953 | if (i == surf_g.dev.swpchn.imgs_n) | ||
954 | break; | ||
955 | cpu_img_layout_to_general(i); | ||
956 | ++i; | ||
957 | } | ||
958 | } | ||
959 | |||
960 | static void tmp_cpu_img_mem_rqmts_get(u8 i) | ||
961 | { | ||
962 | struct vk_img_mem_rqmts_info_t info; | ||
963 | struct vk_mem_rqmts_t *rqmts; | ||
964 | s32 r; | ||
965 | |||
966 | memset(&info, 0, sizeof(info)); | ||
967 | info.type = vk_struct_type_img_mem_rqmts_info; | ||
968 | info.img = surf_g.dev.cpu_imgs[i].vk; | ||
969 | rqmts = &tmp_mem_rqmts_g[i]; | ||
970 | memset(rqmts, 0, sizeof(*rqmts)); | ||
971 | rqmts->type = vk_struct_type_mem_rqmts; | ||
972 | vk_get_img_mem_rqmts(&info, rqmts); | ||
973 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to get memory requirements for cpu image %u\n", r, surf_g.dev.vk, i) | ||
974 | 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); | ||
975 | } | ||
976 | |||
977 | static void tmp_cpu_imgs_mem_rqmts_get(void) | ||
978 | { | ||
979 | u8 i; | ||
980 | |||
981 | i = 0; | ||
982 | loop { | ||
983 | if (i == surf_g.dev.swpchn.imgs_n) | ||
984 | break; | ||
985 | tmp_cpu_img_mem_rqmts_get(i); | ||
986 | ++i; | ||
987 | } | ||
988 | } | ||
989 | |||
990 | #define WANTED_MEM_PROPS (vk_mem_prop_host_visible_bit \ | ||
991 | | vk_mem_prop_host_cached_bit) | ||
992 | #define IS_DEV_LOCAL(x) (((x)->prop_flags & vk_mem_prop_dev_local_bit) != 0) | ||
993 | static bool match_mem_type(u8 mem_type_idx, | ||
994 | struct vk_mem_rqmts_t *img_rqmts, bool ignore_gpu_is_discret) | ||
995 | { | ||
996 | struct vk_mem_type_t *mem_type; | ||
997 | |||
998 | /* first check this mem type is in our img rqmts */ | ||
999 | if (((1 << mem_type_idx) & img_rqmts->core.mem_type_bits) == 0) | ||
1000 | return false; | ||
1001 | mem_type = &surf_g.dev.phydev.mem_types[mem_type_idx]; | ||
1002 | if (!ignore_gpu_is_discret) | ||
1003 | if (surf_g.dev.phydev.is_discret_gpu && IS_DEV_LOCAL(mem_type)) | ||
1004 | return false; | ||
1005 | if ((mem_type->prop_flags & WANTED_MEM_PROPS) == WANTED_MEM_PROPS) | ||
1006 | return true; | ||
1007 | return false; | ||
1008 | } | ||
1009 | #undef WANTED_MEM_PROPS | ||
1010 | #undef IS_DEV_LOCAL | ||
1011 | |||
1012 | static bool try_alloc_cpu_img_dev_mem(u8 i, | ||
1013 | struct vk_mem_rqmts_t *img_rqmts, u8 mem_type_idx) | ||
1014 | { | ||
1015 | struct vk_mem_alloc_info_t info; | ||
1016 | s32 r; | ||
1017 | |||
1018 | memset(&info, 0, sizeof(info)); | ||
1019 | info.type = vk_struct_type_mem_alloc_info; | ||
1020 | info.sz = img_rqmts->core.sz; | ||
1021 | info.mem_type_idx = mem_type_idx; | ||
1022 | vk_alloc_mem(&info, &surf_g.dev.cpu_imgs[i].dev_mem); | ||
1023 | if (r < 0) { | ||
1024 | 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); | ||
1025 | return false; | ||
1026 | } | ||
1027 | LOG("0:MAIN:device:%p:physical device:%p:cpu image:%u:%lu bytes allocated from memory type %u\n", surf_g.dev.vk, surf_g.dev.phydev.vk, i, img_rqmts->core.sz, mem_type_idx); | ||
1028 | return true; | ||
1029 | } | ||
1030 | |||
1031 | /* | ||
1032 | * we are looking for host visible and host cached mem. on discret gpu we would | ||
1033 | * like non dev local mem that in order to avoid wasting video ram. if we have | ||
1034 | * a discret gpu but could not find a mem type without dev local mem, let's | ||
1035 | * retry with only host visible and host cached mem. | ||
1036 | */ | ||
1037 | #define IGNORE_GPU_IS_DISCRET true | ||
1038 | static void cpu_img_dev_mem_alloc(u8 i) | ||
1039 | { | ||
1040 | struct vk_mem_rqmts_t *img_rqmts; | ||
1041 | u8 mem_type; | ||
1042 | |||
1043 | img_rqmts = &tmp_mem_rqmts_g[i]; | ||
1044 | mem_type = 0; | ||
1045 | loop { | ||
1046 | if (mem_type == surf_g.dev.phydev.mem_types_n) | ||
1047 | break; | ||
1048 | if (match_mem_type(mem_type, img_rqmts, | ||
1049 | !IGNORE_GPU_IS_DISCRET)) { | ||
1050 | if (try_alloc_cpu_img_dev_mem(i, img_rqmts, | ||
1051 | mem_type)) | ||
1052 | return; | ||
1053 | } | ||
1054 | ++mem_type; | ||
1055 | } | ||
1056 | if (!surf_g.dev.phydev.is_discret_gpu) | ||
1057 | 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) | ||
1058 | /* | ||
1059 | * lookup again, but relax the match based on discret gpu constraint for | ||
1060 | * gpu | ||
1061 | */ | ||
1062 | mem_type = 0; | ||
1063 | loop { | ||
1064 | if (mem_type == surf_g.dev.phydev.mem_types_n) | ||
1065 | break; | ||
1066 | if (match_mem_type(mem_type, img_rqmts, IGNORE_GPU_IS_DISCRET) | ||
1067 | && try_alloc_cpu_img_dev_mem(i, img_rqmts, mem_type)) | ||
1068 | return; | ||
1069 | ++mem_type; | ||
1070 | } | ||
1071 | 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) | ||
1072 | } | ||
1073 | #undef IGNORE_GPU_IS_DISCRET | ||
1074 | |||
1075 | static void cpu_imgs_dev_mem_alloc(void) | ||
1076 | { | ||
1077 | u8 i; | ||
1078 | |||
1079 | i = 0; | ||
1080 | loop { | ||
1081 | if (i == surf_g.dev.swpchn.imgs_n) | ||
1082 | break; | ||
1083 | cpu_img_dev_mem_alloc(i); | ||
1084 | ++i; | ||
1085 | } | ||
1086 | } | ||
1087 | |||
1088 | static void cpu_imgs_dev_mem_bind(void) | ||
1089 | { | ||
1090 | struct vk_bind_img_mem_info_t infos[swpchn_imgs_n_max]; | ||
1091 | u8 i; | ||
1092 | s32 r; | ||
1093 | |||
1094 | memset(&infos, 0, sizeof(infos[0]) * surf_g.dev.swpchn.imgs_n); | ||
1095 | i = 0; | ||
1096 | loop { | ||
1097 | if (i == surf_g.dev.swpchn.imgs_n) | ||
1098 | break; | ||
1099 | infos[i].type = vk_struct_type_bind_img_mem_info; | ||
1100 | infos[i].img = surf_g.dev.cpu_imgs[i].vk; | ||
1101 | infos[i].mem = surf_g.dev.cpu_imgs[i].dev_mem; | ||
1102 | ++i; | ||
1103 | } | ||
1104 | vk_bind_img_mem(infos); | ||
1105 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:cpu images:unable to bind device memory to images\n", r, surf_g.dev.vk) | ||
1106 | LOG("0:MAIN:device:%p:cpu images:bound device memory to images\n", surf_g.dev.vk); | ||
1107 | } | ||
1108 | |||
1109 | static void cpu_imgs_dev_mem_map(void) | ||
1110 | { | ||
1111 | u8 i; | ||
1112 | |||
1113 | i = 0; | ||
1114 | loop { | ||
1115 | s32 r; | ||
1116 | |||
1117 | if (i == surf_g.dev.swpchn.imgs_n) | ||
1118 | break; | ||
1119 | vk_map_mem(surf_g.dev.cpu_imgs[i].dev_mem, | ||
1120 | &surf_g.dev.cpu_imgs[i].data); | ||
1121 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:cpu image:%u:unable to map image memory\n", r, surf_g.dev.vk, i) | ||
1122 | LOG("0:MAIN:device:%p:cpu image:%u:image memory mapped\n", surf_g.dev.vk, i); | ||
1123 | ++i; | ||
1124 | } | ||
1125 | } | ||
1126 | |||
1127 | static void cpu_img_subrsrc_layout_get(u8 i) | ||
1128 | { | ||
1129 | struct vk_img_subrsrc_t s; | ||
1130 | |||
1131 | memset(&s, 0, sizeof(s)); | ||
1132 | /* 1 subrsrc = uniq color plane of mip lvl 0 and array 0 */ | ||
1133 | s.aspect = vk_img_aspect_color_bit; | ||
1134 | vk_get_img_subrsrc_layout(surf_g.dev.cpu_imgs[i].vk, &s, | ||
1135 | &surf_g.dev.cpu_imgs[i].layout); | ||
1136 | 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); | ||
1137 | } | ||
1138 | |||
1139 | static void cpu_imgs_subrsrc_layout_get(void) | ||
1140 | { | ||
1141 | u8 i; | ||
1142 | |||
1143 | i = 0; | ||
1144 | loop { | ||
1145 | if (i == surf_g.dev.swpchn.imgs_n) | ||
1146 | break; | ||
1147 | cpu_img_subrsrc_layout_get(i); | ||
1148 | ++i; | ||
1149 | } | ||
1150 | } | ||
1151 | |||
1152 | 880 | static void sems_create(void) | static void sems_create(void) |
1153 | 881 | { | { |
1154 | 882 | s32 r; | s32 r; |
... | ... | static void sems_create(void) | |
1164 | 892 | vk_create_sem(&info, &surf_g.dev.sems[sem]); | vk_create_sem(&info, &surf_g.dev.sems[sem]); |
1165 | 893 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create a semaphore %u for our swapchain\n", r, surf_g.dev.vk, 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) |
1166 | 894 | LOG("0:MAIN:device:%p:semaphore %u for our swapchain created %p\n", surf_g.dev.vk, sem, surf_g.dev.sems[sem]); | LOG("0:MAIN:device:%p:semaphore %u for our swapchain created %p\n", surf_g.dev.vk, sem, surf_g.dev.sems[sem]); |
895 | |||
1167 | 896 | ++sem; | ++sem; |
1168 | 897 | } | } |
1169 | 898 | } | } |
... | ... | static void cbs_create(void) | |
1186 | 915 | static void cb_rec(u8 i) | static void cb_rec(u8 i) |
1187 | 916 | { | { |
1188 | 917 | s32 r; | s32 r; |
1189 | struct vk_cb_begin_info_t begin_info; | ||
1190 | struct vk_img_mem_barrier_t b; | ||
1191 | struct vk_img_blit_t region; | ||
918 | struct vk_cb_begin_info_t cb_info; | ||
919 | struct vk_rp_begin_info_t rp_info; | ||
920 | union vk_clr_val_t clr_val; | ||
1192 | 921 | /*--------------------------------------------------------------------*/ | /*--------------------------------------------------------------------*/ |
1193 | memset(&begin_info, 0, sizeof(begin_info)); | ||
1194 | begin_info.type = vk_struct_type_cb_begin_info; | ||
1195 | vk_begin_cb(surf_g.dev.cbs[i], &begin_info); | ||
922 | memset(&cb_info, 0, sizeof(cb_info)); | ||
923 | cb_info.type = vk_struct_type_cb_begin_info; | ||
924 | vk_begin_cb(surf_g.dev.cbs[i], &cb_info); | ||
1196 | 925 | VK_FATAL("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to begin recording\n", r, i, surf_g.dev.cbs[i]) | VK_FATAL("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to begin recording\n", r, i, surf_g.dev.cbs[i]) |
1197 | 926 | /*--------------------------------------------------------------------*/ | /*--------------------------------------------------------------------*/ |
1198 | /* acquired img (undefined layout) to presentation layout */ | ||
1199 | memset(&b, 0, sizeof(b)); | ||
1200 | b.type = vk_struct_type_img_mem_barrier; | ||
1201 | b.old_layout = vk_img_layout_undefined; | ||
1202 | b.new_layout = vk_img_layout_present; | ||
1203 | b.src_q_fam = vk_q_fam_ignored; | ||
1204 | b.dst_q_fam = vk_q_fam_ignored; | ||
1205 | b.img = surf_g.dev.swpchn.imgs[i]; | ||
1206 | b.subrsrc_range.aspect = vk_img_aspect_color_bit; | ||
1207 | b.subrsrc_range.lvls_n = 1; | ||
1208 | b.subrsrc_range.array_layers_n = 1; | ||
1209 | vk_cmd_pl_barrier(surf_g.dev.cbs[i], &b); | ||
927 | /*XXX this is where the link between a rp and a fb is created */ | ||
928 | memset(&rp_info, 0, sizeof(rp_info)); | ||
929 | rp_info.type = vk_struct_type_rp_begin_info; | ||
930 | rp_info.rp = surf_g.dev.rp; | ||
931 | rp_info.fb = surf_g.dev.swpchn.fbs[i]; | ||
932 | rp_info.render_area.offset.x = 0; | ||
933 | rp_info.render_area.offset.y = 0; | ||
934 | rp_info.render_area.extent.width = APP_WIN_WIDTH; | ||
935 | rp_info.render_area.extent.height = APP_WIN_HEIGHT; | ||
936 | clr_val.color.f32s[0] = 0.0f; | ||
937 | clr_val.color.f32s[1] = 0.0f; | ||
938 | clr_val.color.f32s[2] = 0.0f; | ||
939 | clr_val.color.f32s[3] = 1.0f; | ||
940 | rp_info.clr_vals_n = 1; | ||
941 | rp_info.clr_vals = &clr_val; | ||
1210 | 942 | /*--------------------------------------------------------------------*/ | /*--------------------------------------------------------------------*/ |
1211 | /* blit from cpu img to pe img */ | ||
1212 | memset(®ion, 0, sizeof(region)); | ||
1213 | region.src_subrsrc.aspect = vk_img_aspect_color_bit; | ||
1214 | region.src_subrsrc.array_layers_n = 1; | ||
1215 | region.src_offsets[1].x = APP_CPU_IMG_WIDTH; | ||
1216 | region.src_offsets[1].y = APP_CPU_IMG_HEIGHT; | ||
1217 | region.dst_subrsrc.aspect = vk_img_aspect_color_bit; | ||
1218 | region.dst_subrsrc.array_layers_n = 1; | ||
1219 | /* XXX: it is a scaling blit: you can use APP_WIN_WIDTH/APP_WIN_HEIGHT */ | ||
1220 | region.dst_offsets[1].x = APP_CPU_IMG_WIDTH; | ||
1221 | region.dst_offsets[1].y = APP_CPU_IMG_HEIGHT; | ||
1222 | vk_cmd_blit_img(surf_g.dev.cbs[i], surf_g.dev.cpu_imgs[i].vk, | ||
1223 | surf_g.dev.swpchn.imgs[i], ®ion); | ||
943 | vk_cmd_begin_rp(surf_g.dev.cbs[i], &rp_info); | ||
944 | vk_cmd_bind_pl(surf_g.dev.cbs[i]); | ||
945 | vk_cmd_draw(surf_g.dev.cbs[i], 3, 1, 0, 0); | ||
946 | vk_cmd_end_rp(surf_g.dev.cbs[i]); | ||
1224 | 947 | /*--------------------------------------------------------------------*/ | /*--------------------------------------------------------------------*/ |
1225 | 948 | vk_end_cb(surf_g.dev.cbs[i]); | vk_end_cb(surf_g.dev.cbs[i]); |
1226 | 949 | VK_FATAL("0:MAIN:FATAL:%d:swapchain img:%u:command buffer:%p:unable to end recording\n", r, i, 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 phydev_init(void) | |
1263 | 986 | tmp_present_modes_dump(); | tmp_present_modes_dump(); |
1264 | 987 | } | } |
1265 | 988 | ||
989 | static void rp_create(void) | ||
990 | { | ||
991 | s32 r; | ||
992 | struct vk_rp_create_info_t info; | ||
993 | struct vk_at_desc_t color_at; /* only one color at for all sps */ | ||
994 | struct vk_sp_desc_t sp; /* our only sp */ | ||
995 | struct vk_at_ref_t color_at_ref; /* for our only sp */ | ||
996 | |||
997 | memset(&info, 0, sizeof(info)); | ||
998 | memset(&sp, 0, sizeof(sp)); | ||
999 | memset(&color_at, 0, sizeof(color_at)); | ||
1000 | memset(&color_at_ref, 0, sizeof(color_at_ref)); | ||
1001 | /* our rp, namely all its supasses will need only 1 color at */ | ||
1002 | color_at.fmt = surf_g.dev.phydev.selected_texel_mem_blk_conf_core.fmt; | ||
1003 | color_at.samples_n = vk_samples_n_1_bit; | ||
1004 | color_at.load_op = vk_at_load_op_clr; | ||
1005 | color_at.store_op = vk_at_store_op_store; | ||
1006 | color_at.stencil_load_op = vk_at_load_op_dont_care; | ||
1007 | color_at.stencil_store_op = vk_at_store_op_dont_care; | ||
1008 | color_at.initial_layout = vk_img_layout_undefined; | ||
1009 | color_at.final_layout = vk_img_layout_present; | ||
1010 | /* | ||
1011 | * our rp will include 1 sp which will use the above | ||
1012 | * color at, hence we declare its ref | ||
1013 | */ | ||
1014 | color_at_ref.at = 0; /* idx of the only at in our rp */ | ||
1015 | color_at_ref.layout = vk_img_layout_color_at_optimal; | ||
1016 | /* | ||
1017 | * our only sp using a ref to the only color at. In the | ||
1018 | * frag/pixel shader, outputting to this attachment will have to be done | ||
1019 | * using "location 0" spirv decoration | ||
1020 | */ | ||
1021 | sp.pl_bind_point = vk_pl_bind_point_gfx; | ||
1022 | sp.color_ats_n = 1; | ||
1023 | sp.color_ats = &color_at_ref; | ||
1024 | /* | ||
1025 | * we use a full gfx pl which we sync with the presentation | ||
1026 | * engine using semaphore. Then default/automatic sps sync is ok. | ||
1027 | */ | ||
1028 | info.type = vk_struct_type_rp_create_info; | ||
1029 | info.ats_n = 1; | ||
1030 | info.ats = &color_at; | ||
1031 | info.sps_n = 1; | ||
1032 | info.sps = &sp; | ||
1033 | vk_create_rp(&info); | ||
1034 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create the render pass\n", r, surf_g.dev.vk) | ||
1035 | LOG("0:MAIN:device:%p:created render pass %p\n", surf_g.dev.vk, surf_g.dev.rp); | ||
1036 | } | ||
1037 | |||
1038 | static void shmods_create(void) | ||
1039 | { | ||
1040 | s32 r; | ||
1041 | struct vk_shmod_create_info_t info; | ||
1042 | |||
1043 | /* vs */ | ||
1044 | file_mmap("./vs.spirv", (u8**)&tmp_vs_g, &tmp_vs_sz_g); | ||
1045 | memset(&info, 0, sizeof(info)); | ||
1046 | info.type = vk_struct_type_shmod_create_info; | ||
1047 | info.code_sz = tmp_vs_sz_g; | ||
1048 | info.code = tmp_vs_g; | ||
1049 | vk_create_shmod(&info, &tmp_vs_mod_g); | ||
1050 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create the vertex shader module", r, surf_g.dev.vk) | ||
1051 | LOG("0:MAIN:device:%p:created vertex shader module %p\n", surf_g.dev.vk, tmp_vs_mod_g); | ||
1052 | /* fs/ps */ | ||
1053 | file_mmap("./fs.spirv", (u8**)&tmp_fs_g, &tmp_fs_sz_g); | ||
1054 | memset(&info, 0, sizeof(info)); | ||
1055 | info.type = vk_struct_type_shmod_create_info; | ||
1056 | info.code_sz = tmp_fs_sz_g; | ||
1057 | info.code = tmp_fs_g; | ||
1058 | vk_create_shmod(&info, &tmp_fs_mod_g); | ||
1059 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create the fragment/pixel shader module", r, surf_g.dev.vk) | ||
1060 | LOG("0:MAIN:device:%p:created fragment/pixel shader module %p\n", surf_g.dev.vk, tmp_fs_mod_g); | ||
1061 | } | ||
1062 | |||
1063 | static void shmods_destroy(void) | ||
1064 | { | ||
1065 | vk_destroy_shmod(tmp_vs_mod_g); | ||
1066 | munmap(tmp_vs_g, tmp_vs_sz_g); | ||
1067 | vk_destroy_shmod(tmp_fs_mod_g); | ||
1068 | munmap(tmp_fs_g, tmp_fs_sz_g); | ||
1069 | } | ||
1070 | |||
1071 | static void *pl_layout_empty_create(void) | ||
1072 | { | ||
1073 | struct vk_pl_layout_create_info_t layout_info; | ||
1074 | s32 r; | ||
1075 | void *pl_layout; | ||
1076 | |||
1077 | memset(&layout_info, 0, sizeof(layout_info)); | ||
1078 | layout_info.type = vk_struct_type_pl_layout_create_info; | ||
1079 | vk_create_pl_layout(&layout_info, &pl_layout); | ||
1080 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create the pipeline layout", r, surf_g.dev.vk) | ||
1081 | return pl_layout; | ||
1082 | } | ||
1083 | |||
1084 | static void pl_create(void) | ||
1085 | { | ||
1086 | struct vk_gfx_pl_create_info_t pl_info; | ||
1087 | struct vk_pl_sh_stage_create_info_t sh_stage_infos[2]; | ||
1088 | struct vk_pl_vtx_input_state_create_info_t vtx_info; | ||
1089 | struct vk_pl_input_assembly_state_create_info_t assembly_info; | ||
1090 | struct vk_pl_viewport_state_create_info_t viewport_info; | ||
1091 | struct vk_viewport_t viewport; | ||
1092 | struct vk_rect_2d_t scissor; | ||
1093 | struct vk_pl_raster_state_create_info_t raster_info; | ||
1094 | struct vk_pl_multisample_state_create_info_t multisample_info; | ||
1095 | struct vk_pl_color_blend_at_state_t color_blend_at; | ||
1096 | struct vk_pl_color_blend_state_create_info_t color_blend_info; | ||
1097 | s32 r; | ||
1098 | /*--------------------------------------------------------------------*/ | ||
1099 | memset(sh_stage_infos, 0, sizeof(sh_stage_infos)); | ||
1100 | sh_stage_infos[0].type = vk_struct_type_pl_sh_stage_create_info; | ||
1101 | sh_stage_infos[0].stage = vk_sh_stage_vtx_bit; | ||
1102 | sh_stage_infos[0].shmod = tmp_vs_mod_g; | ||
1103 | sh_stage_infos[0].name = "main"; | ||
1104 | sh_stage_infos[1].type = vk_struct_type_pl_sh_stage_create_info; | ||
1105 | sh_stage_infos[1].stage = vk_sh_stage_frag_bit; | ||
1106 | sh_stage_infos[1].shmod = tmp_fs_mod_g; | ||
1107 | sh_stage_infos[1].name = "main"; | ||
1108 | /*--------------------------------------------------------------------*/ | ||
1109 | memset(&vtx_info, 0, sizeof(vtx_info)); | ||
1110 | vtx_info.type = vk_struct_type_pl_vtx_input_state_create_info; | ||
1111 | /* our triangle vtxs are hardcoded in the vtx shader */ | ||
1112 | /*--------------------------------------------------------------------*/ | ||
1113 | memset(&assembly_info, 0, sizeof(assembly_info)); | ||
1114 | assembly_info.type = vk_struct_type_pl_input_assembly_state_create_info; | ||
1115 | assembly_info.topology = vk_prim_topology_triangle_list; | ||
1116 | /*--------------------------------------------------------------------*/ | ||
1117 | /* "viewport" is actually a transformation from "normalized" coords */ | ||
1118 | memset(&viewport_info, 0, sizeof(viewport_info)); | ||
1119 | viewport_info.type = vk_struct_type_pl_viewport_state_create_info; | ||
1120 | viewport_info.viewports_n = 1; | ||
1121 | viewport.x = 0.0f; | ||
1122 | viewport.y = 0.0f; | ||
1123 | viewport.width = (f32)APP_WIN_WIDTH; | ||
1124 | viewport.height = (f32)APP_WIN_HEIGHT; | ||
1125 | viewport.depth_min = 0.0f; | ||
1126 | viewport.depth_max = 1.0f; | ||
1127 | viewport_info.viewports = &viewport; | ||
1128 | memset(&scissor, 0, sizeof(scissor)); | ||
1129 | viewport_info.scissors_n = 1; | ||
1130 | scissor.offset.x = 0; | ||
1131 | scissor.offset.y = 0; | ||
1132 | scissor.extent.width = APP_WIN_WIDTH; /* same than our swpchn imgs */ | ||
1133 | scissor.extent.height = APP_WIN_HEIGHT; /* same than our swpchn imgs */ | ||
1134 | viewport_info.scissors = &scissor; | ||
1135 | /*--------------------------------------------------------------------*/ | ||
1136 | memset(&raster_info, 0, sizeof(raster_info)); | ||
1137 | raster_info.type = vk_struct_type_pl_raster_state_create_info; | ||
1138 | raster_info.polygon_mode = vk_polygon_mode_fill; | ||
1139 | raster_info.cull_mode = vk_cull_mode_back_bit; | ||
1140 | raster_info.front_face = vk_front_face_clockwise; | ||
1141 | /*--------------------------------------------------------------------*/ | ||
1142 | memset(&multisample_info, 0, sizeof(multisample_info)); | ||
1143 | multisample_info.type = vk_struct_type_pl_multisample_state_create_info; | ||
1144 | multisample_info.raster_samples_n = vk_samples_n_1_bit; | ||
1145 | /*--------------------------------------------------------------------*/ | ||
1146 | memset(&color_blend_at, 0, sizeof(color_blend_at)); | ||
1147 | /* | ||
1148 | * XXX: we do not use any of the hw fixed stage color bleand ops, but we | ||
1149 | * init some vals anyway (will have to remove those, probably) | ||
1150 | */ | ||
1151 | color_blend_at.color_write_mask = vk_color_comp_r_bit | ||
1152 | | vk_color_comp_g_bit | ||
1153 | | vk_color_comp_b_bit | ||
1154 | | vk_color_comp_a_bit; | ||
1155 | memset(&color_blend_info, 0, sizeof(color_blend_info)); | ||
1156 | color_blend_info.type = vk_struct_type_pl_color_blend_state_create_info; | ||
1157 | color_blend_info.ats_n = 1; | ||
1158 | color_blend_info.ats = &color_blend_at; | ||
1159 | /*--------------------------------------------------------------------*/ | ||
1160 | memset(&pl_info, 0, sizeof(pl_info)); | ||
1161 | pl_info.type = vk_struct_type_gfx_pl_create_info; | ||
1162 | pl_info.sh_stages_n = 2; | ||
1163 | pl_info.sh_stages = sh_stage_infos; | ||
1164 | pl_info.vtx_input_state = &vtx_info; | ||
1165 | pl_info.input_assembly_state = &assembly_info; | ||
1166 | pl_info.viewport_state = &viewport_info; | ||
1167 | pl_info.raster_state = &raster_info; | ||
1168 | pl_info.multisample_state = &multisample_info; | ||
1169 | pl_info.color_blend_state = &color_blend_info; | ||
1170 | pl_info.layout = pl_layout_empty_create(); | ||
1171 | pl_info.rp = surf_g.dev.rp; | ||
1172 | pl_info.sp = 0; /* idx */ | ||
1173 | /*--------------------------------------------------------------------*/ | ||
1174 | vk_create_gfx_pls(&pl_info); | ||
1175 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:unable to create the pipeline", r, surf_g.dev.vk) | ||
1176 | } | ||
1177 | |||
1266 | 1178 | static void dev_init(void) | static void dev_init(void) |
1267 | 1179 | { | { |
1268 | 1180 | phydev_init(); | phydev_init(); |
1269 | /*--------------------------------------------------------------------*/ | ||
1270 | 1181 | dev_create(); | dev_create(); |
1271 | 1182 | dev_syms(); | dev_syms(); |
1272 | 1183 | q_get(); | q_get(); |
1273 | 1184 | cp_create(); | cp_create(); |
1185 | rp_create(); | ||
1186 | shmods_create(); | ||
1187 | pl_create(); | ||
1188 | shmods_destroy(); /* we can destroy the shmods after pl creation */ | ||
1189 | } | ||
1190 | |||
1191 | static void swpchn_fb_create(u8 i) | ||
1192 | { | ||
1193 | s32 r; | ||
1194 | struct vk_fb_create_info_t info; | ||
1195 | |||
1196 | memset(&info, 0, sizeof(info)); | ||
1197 | info.type = vk_struct_type_fb_create_info; | ||
1198 | /* all fbs use the same rp */ | ||
1199 | info.rp = surf_g.dev.rp; | ||
1200 | info.ats_n = 1; | ||
1201 | info.ats = &surf_g.dev.swpchn.imgviews[i]; | ||
1202 | info.width = APP_WIN_WIDTH; | ||
1203 | info.height = APP_WIN_HEIGHT; | ||
1204 | info.layers_n = 1; | ||
1205 | vk_create_fb(&info, &surf_g.dev.swpchn.fbs[i]); | ||
1206 | VK_FATAL("0:MAIN:FATAL:%d:device:%p:swapchain:%p:image:%u:unable to create the framebuffer\n", r, surf_g.dev.vk, surf_g.dev.swpchn.vk, i) | ||
1207 | LOG("0:MAIN:FATAL:%d:device:%p:swapchain:%p:image:%u:framebuffer created %p\n", r, surf_g.dev.vk, surf_g.dev.swpchn.vk, i, surf_g.dev.swpchn.fbs[i]); | ||
1208 | } | ||
1209 | |||
1210 | static void swpchn_fbs_create(void) | ||
1211 | { | ||
1212 | u8 i; | ||
1213 | |||
1214 | i = 0; | ||
1215 | loop { | ||
1216 | if (i == surf_g.dev.swpchn.imgs_n) | ||
1217 | break; | ||
1218 | swpchn_fb_create(i); | ||
1219 | ++i; | ||
1220 | } | ||
1274 | 1221 | } | } |
1275 | 1222 | ||
1276 | 1223 | static void surf_init(void) | static void surf_init(void) |
... | ... | static void surf_init(void) | |
1279 | 1226 | dev_init(); | dev_init(); |
1280 | 1227 | swpchn_init(); | swpchn_init(); |
1281 | 1228 | swpchn_imgs_get(); | swpchn_imgs_get(); |
1282 | /* our cpu imgs for swpchn imgs */ | ||
1283 | cpu_imgs_create(); | ||
1229 | swpchn_imgviews_create(); | ||
1230 | /* | ||
1231 | * the link between one of the fbs and our only rp/pl is | ||
1232 | * done while recording cmds, namely it is per cb. | ||
1233 | */ | ||
1234 | swpchn_fbs_create(); | ||
1284 | 1235 | sems_create(); | sems_create(); |
1285 | 1236 | cbs_create(); | cbs_create(); |
1286 | cpu_imgs_layout_to_general(); | ||
1287 | cpu_imgs_subrsrc_layout_get(); | ||
1288 | tmp_cpu_imgs_mem_rqmts_get(); | ||
1289 | cpu_imgs_dev_mem_alloc(); | ||
1290 | cpu_imgs_dev_mem_bind(); | ||
1291 | cpu_imgs_dev_mem_map(); | ||
1292 | 1237 | cbs_rec(); | cbs_rec(); |
1293 | 1238 | } | } |
1294 | 1239 | ||
... | ... | static void init_vk(void) | |
1300 | 1245 | check_vk_version(); | check_vk_version(); |
1301 | 1246 | instance_exts_dump(); | instance_exts_dump(); |
1302 | 1247 | instance_layers_dump(); | instance_layers_dump(); |
1303 | /*--------------------------------------------------------------------*/ | ||
1304 | 1248 | instance_create(); | instance_create(); |
1305 | 1249 | instance_syms(); | instance_syms(); |
1306 | /*--------------------------------------------------------------------*/ | ||
1307 | 1250 | surf_init(); | surf_init(); |
1308 | 1251 | } | } |
1309 | 1252 | ||
... | ... | static void swpchn_acquire_next_img(u32 *i) | |
1323 | 1266 | LOG("0:MAIN:device:%p:swapchain:%p:acquired image %u\n", surf_g.dev.vk, surf_g.dev.swpchn.vk, *i); | LOG("0:MAIN:device:%p:swapchain:%p:acquired image %u\n", surf_g.dev.vk, surf_g.dev.swpchn.vk, *i); |
1324 | 1267 | } | } |
1325 | 1268 | ||
1326 | /* solid color */ | ||
1327 | static void cpu_img_draw(u8 i) | ||
1328 | { | ||
1329 | u32 *texel; | ||
1330 | u64 row; | ||
1331 | u64 col; | ||
1332 | |||
1333 | texel = (u32*)surf_g.dev.cpu_imgs[i].data; | ||
1334 | row = 0; | ||
1335 | loop { | ||
1336 | if (row == APP_CPU_IMG_HEIGHT) | ||
1337 | break; | ||
1338 | col = 0; | ||
1339 | loop { | ||
1340 | struct vk_subrsrc_layout_t *l; | ||
1341 | u64 o; /* _byte_ offset */ | ||
1342 | u64 o_w; /* _32 bits_ word offset */ | ||
1343 | |||
1344 | if (col == APP_CPU_IMG_WIDTH) | ||
1345 | break; | ||
1346 | l = &surf_g.dev.cpu_imgs[i].layout; | ||
1347 | o = row * l->row_pitch + col * sizeof(*texel); | ||
1348 | o_w = o >> 2; | ||
1349 | texel[o_w] = fill_texel_g; | ||
1350 | ++col; | ||
1351 | } | ||
1352 | ++row; | ||
1353 | } | ||
1354 | } | ||
1355 | |||
1356 | static void cpu_img_to_pe(u8 i) | ||
1269 | static void draw(u8 i) | ||
1357 | 1270 | { | { |
1358 | 1271 | s32 r; | s32 r; |
1359 | 1272 | struct vk_submit_info_t submit_info; | struct vk_submit_info_t submit_info; |
... | ... | static void cpu_img_to_pe(u8 i) | |
1370 | 1283 | submit_info.cbs_n = 1; | submit_info.cbs_n = 1; |
1371 | 1284 | submit_info.cbs = &surf_g.dev.cbs[i]; | submit_info.cbs = &surf_g.dev.cbs[i]; |
1372 | 1285 | submit_info.signal_sems_n = 1; | submit_info.signal_sems_n = 1; |
1373 | submit_info.signal_sems = &surf_g.dev.sems[app_sem_blit_done]; | ||
1374 | LOG("MAIN:queue:%p\n", surf_g.dev.q); | ||
1375 | |||
1286 | submit_info.signal_sems = &surf_g.dev.sems[app_sem_draw_done]; | ||
1376 | 1287 | vk_q_submit(&submit_info); | vk_q_submit(&submit_info); |
1377 | VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the image pre-recorded command buffer\n", r, surf_g.dev.q) | ||
1288 | VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the image/framebuffer pre-recorded drawing command buffer\n", r, surf_g.dev.q) | ||
1378 | 1289 | /*--------------------------------------------------------------------*/ | /*--------------------------------------------------------------------*/ |
1379 | 1290 | idxs[0] = i; | idxs[0] = i; |
1380 | 1291 | memset(&present_info, 0, sizeof(present_info)); | memset(&present_info, 0, sizeof(present_info)); |
1381 | 1292 | present_info.type = vk_struct_type_present_info; | present_info.type = vk_struct_type_present_info; |
1382 | 1293 | present_info.wait_sems_n = 1; | present_info.wait_sems_n = 1; |
1383 | present_info.wait_sems = &surf_g.dev.sems[sem_blit_done]; | ||
1294 | present_info.wait_sems = &surf_g.dev.sems[sem_draw_done]; | ||
1384 | 1295 | present_info.swpchns_n = 1; | present_info.swpchns_n = 1; |
1385 | 1296 | present_info.swpchns = &surf_g.dev.swpchn.vk; | present_info.swpchns = &surf_g.dev.swpchn.vk; |
1386 | 1297 | present_info.idxs = idxs; | present_info.idxs = idxs; |
1387 | 1298 | present_info.results = 0; | present_info.results = 0; |
1388 | 1299 | vk_q_present(&present_info); | vk_q_present(&present_info); |
1389 | 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) | ||
1300 | VK_FATAL("0:MAIN:FATAL:%d:queue:%p:unable to submit the image/framebuffer %u to the presentation engine\n", r, surf_g.dev.q, i) | ||
1390 | 1301 | } | } |
1391 | 1302 | ||
1392 | 1303 | static void render(void) | static void render(void) |
... | ... | static void render(void) | |
1394 | 1305 | u32 i; | u32 i; |
1395 | 1306 | ||
1396 | 1307 | swpchn_acquire_next_img(&i); | swpchn_acquire_next_img(&i); |
1397 | cpu_img_draw(i); /* cpu rendering */ | ||
1398 | cpu_img_to_pe(i); | ||
1308 | draw(i); | ||
1399 | 1309 | do_render_g = false; | do_render_g = false; |
1400 | if (fill_texel_g == 0x0000ff00) | ||
1401 | fill_texel_g = 0x00ff0000; | ||
1402 | else | ||
1403 | fill_texel_g = 0x0000ff00; | ||
1404 | 1310 | } | } |
1405 | 1311 | ||
1312 | /* "main" loop */ | ||
1406 | 1313 | static void run(void) | static void run(void) |
1407 | 1314 | { | { |
1408 | 1315 | state_g = state_run; | state_g = state_run; |
... | ... | int main(void) | |
1439 | 1346 | LOG("0:starting app\n"); | LOG("0:starting app\n"); |
1440 | 1347 | app_xcb_init(); | app_xcb_init(); |
1441 | 1348 | init_vk(); | init_vk(); |
1442 | fill_texel_g = 0x0000ff00; | ||
1443 | 1349 | run(); | run(); |
1444 | 1350 | LOG("0:exiting app\n"); | LOG("0:exiting app\n"); |
1445 | 1351 | exit(0); | exit(0); |
File 3d/clip_coords/app_core_types.h copied from file 2d/blit/app_core_types.h (similarity 100%) |
File 3d/clip_coords/app_state.c copied from file 2d/blit/app_state.c (similarity 77%) (mode: 100644) (index 8096941..a33723a) | |||
5 | 5 | * Sylvain BERTRAND | * Sylvain BERTRAND |
6 | 6 | */ | */ |
7 | 7 | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ |
8 | #include <stddef.h> | ||
9 | 8 | #include <xcb.h> | #include <xcb.h> |
10 | 9 | #include "app_core_types.h" | #include "app_core_types.h" |
11 | 10 | #include "nyanvk/types.h" | #include "nyanvk/types.h" |
16 | 15 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
17 | 16 | static u8 state_g; | static u8 state_g; |
18 | 17 | static bool do_render_g; | static bool do_render_g; |
19 | static u32 fill_texel_g; | ||
20 | 18 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
21 | 19 | static void *instance_g; | static void *instance_g; |
22 | 20 | static struct surf_t surf_g; | static struct surf_t surf_g; |
... | ... | static u32 tmp_phydevs_n_g; | |
27 | 25 | static struct vk_surf_caps_t tmp_surf_caps_g; | static struct vk_surf_caps_t tmp_surf_caps_g; |
28 | 26 | static u32 tmp_present_modes_g[tmp_present_modes_n_max]; | static u32 tmp_present_modes_g[tmp_present_modes_n_max]; |
29 | 27 | static u32 tmp_present_modes_n_g; | static u32 tmp_present_modes_n_g; |
30 | static struct vk_mem_rqmts_t tmp_mem_rqmts_g[swpchn_imgs_n_max]; | ||
28 | /* NSPC */ | ||
29 | static u32 *tmp_vs_g; | ||
30 | static u64 tmp_vs_sz_g; | ||
31 | static void *tmp_vs_mod_g; | ||
32 | /* NSPC */ | ||
33 | static u32 *tmp_fs_g; | ||
34 | static u64 tmp_fs_sz_g; | ||
35 | static void *tmp_fs_mod_g; | ||
36 | /*----------------------------------------------------------------------------*/ | ||
31 | 37 | #define CLEANUP | #define CLEANUP |
32 | 38 | #include "namespace/app_state_types.h" | #include "namespace/app_state_types.h" |
33 | 39 | #include "namespace/app_state.c" | #include "namespace/app_state.c" |
34 | 40 | #undef CLEANUP | #undef CLEANUP |
41 | /*----------------------------------------------------------------------------*/ | ||
35 | 42 | #endif /* APP_STATE_C */ | #endif /* APP_STATE_C */ |
File 3d/clip_coords/app_state_types.h copied from file 2d/blit/app_state_types.h (similarity 75%) (mode: 100644) (index c1c4653..1b21ab8) | |||
5 | 5 | * Sylvain BERTRAND | * Sylvain BERTRAND |
6 | 6 | */ | */ |
7 | 7 | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ |
8 | #include <stddef.h> | ||
9 | 8 | #include <xcb.h> | #include <xcb.h> |
10 | 9 | #include "app_core_types.h" | #include "app_core_types.h" |
10 | #include "nyanvk/consts.h" | ||
11 | 11 | #include "nyanvk/types.h" | #include "nyanvk/types.h" |
12 | 12 | #include "nyanvk/syms_dev.h" | #include "nyanvk/syms_dev.h" |
13 | /* this is the default initial cpu rendering size */ | ||
14 | #define APP_CPU_IMG_WIDTH 50 | ||
15 | #define APP_CPU_IMG_HEIGHT 50 | ||
13 | #include "vk_app.h" | ||
16 | 14 | #define APP_WIN_WIDTH 100 | #define APP_WIN_WIDTH 100 |
17 | 15 | #define APP_WIN_HEIGHT 100 | #define APP_WIN_HEIGHT 100 |
18 | 16 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
19 | 17 | #include "namespace/app_state_types.h" | #include "namespace/app_state_types.h" |
20 | 18 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
21 | 19 | constant { | constant { |
22 | state_run = 1, | ||
23 | state_quit = 2 | ||
20 | state_run = 1, | ||
21 | state_quit = 2 | ||
24 | 22 | }; | }; |
25 | 23 | ||
26 | 24 | constant { | constant { |
... | ... | constant { | |
29 | 27 | ||
30 | 28 | struct swpchn_t { | struct swpchn_t { |
31 | 29 | void *vk; | void *vk; |
32 | |||
33 | 30 | u32 imgs_n; | u32 imgs_n; |
34 | 31 | void *imgs[swpchn_imgs_n_max]; | void *imgs[swpchn_imgs_n_max]; |
32 | void *imgviews[swpchn_imgs_n_max]; | ||
33 | void *fbs[swpchn_imgs_n_max]; | ||
35 | 34 | }; | }; |
36 | 35 | ||
37 | 36 | struct phydev_t { | struct phydev_t { |
... | ... | struct phydev_t { | |
44 | 43 | struct vk_mem_type_t mem_types[VK_MEM_TYPES_N_MAX]; | struct vk_mem_type_t mem_types[VK_MEM_TYPES_N_MAX]; |
45 | 44 | }; | }; |
46 | 45 | ||
47 | struct cpu_img_t { | ||
48 | void *vk; | ||
49 | struct vk_subrsrc_layout_t layout; | ||
50 | void *dev_mem; /* TODO: we should use 1 big dev_mem chunk */ | ||
51 | void *data; | ||
52 | }; | ||
53 | |||
54 | 46 | constant { | constant { |
55 | sem_acquire_img_done = 0, | ||
56 | sem_blit_done = 1, | ||
57 | sems_n = 2, | ||
47 | sem_acquire_img_done = 0, | ||
48 | sem_draw_done = 1, | ||
49 | sems_n = 2, | ||
58 | 50 | }; | }; |
59 | 51 | ||
60 | 52 | struct dev_t { | struct dev_t { |
... | ... | struct dev_t { | |
65 | 57 | void *cp; | void *cp; |
66 | 58 | void *cbs[swpchn_imgs_n_max]; | void *cbs[swpchn_imgs_n_max]; |
67 | 59 | void *sems[sems_n]; | void *sems[sems_n]; |
68 | struct app_cpu_img_t cpu_imgs[swpchn_imgs_n_max]; | ||
69 | VK_DEV_SYMS_FULL /* should cherry pick the syms we use */ | ||
60 | void *rp; | ||
61 | void *pl; | ||
62 | VK_DEV_SYMS_FULL /* XXX: cherry pick the symbols we use */ | ||
70 | 63 | }; | }; |
71 | 64 | ||
72 | 65 | struct surf_t { | struct surf_t { |
... | ... | struct surf_t { | |
76 | 69 | /*============================================================================*/ | /*============================================================================*/ |
77 | 70 | /* tmp state */ | /* tmp state */ |
78 | 71 | constant { | constant { |
79 | tmp_phydevs_n_max = 16, | ||
80 | tmp_phydev_q_fams_n_max = 16, | ||
81 | tmp_present_modes_n_max = 16 | ||
72 | tmp_phydevs_n_max = 16, | ||
73 | tmp_phydev_q_fams_n_max = 16, | ||
74 | tmp_present_modes_n_max = 16 | ||
82 | 75 | }; | }; |
83 | 76 | ||
84 | 77 | struct tmp_phydev_t { | struct tmp_phydev_t { |
File 3d/clip_coords/fs.S added (mode: 100644) (index 0000000..d6b64b5) | |||
1 | capability shader | ||
2 | //============================================================================== | ||
3 | memory_model addressing_model=logical memory_model=glsl450 | ||
4 | |||
5 | //============================================================================== | ||
6 | entry_point execution_model=fragment entry_point=%13 name="main" \ | ||
7 | /*interfaces[0]=*/%9 | ||
8 | //============================================================================== | ||
9 | decorate target=%9 decoration=location 0 | ||
10 | //============================================================================== | ||
11 | /* %2 */ type_void %2 | ||
12 | /* %3 */ type_function id=%3 return_type=%2 | ||
13 | /* %6 */ type_float id=%6 width=32 | ||
14 | /* %7 */ type_vector id=%7 component_type=%6 components_n=4 | ||
15 | /* %8 */ type_pointer id=%8 storage_class=output type=%7 | ||
16 | /* %9 */ variable pointer_id=%9 type=%8 storage_class=output | ||
17 | //============================================================================== | ||
18 | // section end: non function declarations, breaking opcode=function(54) | ||
19 | /* %10 */ constant type=%6 id=%10 /*values[0]=*/0.0 | ||
20 | /* %11 */ constant type=%6 id=%11 /*values[0]=*/1.0 | ||
21 | // {1.0f, 1.0f, 1.0f, 1.0f} | ||
22 | /* %12 */ constant_composite type=%7 id=%12 \ | ||
23 | /*constituents[0]=*/%11 \ | ||
24 | /*constituents[1]=*/%11 \ | ||
25 | /*constituents[2]=*/%11 \ | ||
26 | /*constituents[3]=*/%11 | ||
27 | //============================================================================== | ||
28 | /* %13 */ function id=%13 return_type=%2 control=none type=%3 | ||
29 | /* %14 */ label id=%14 | ||
30 | store pointer=%9 object=%12 | ||
31 | return | ||
32 | function_end |
File 3d/clip_coords/log.h copied from file 2d/blit/log.h (similarity 100%) |
File 3d/clip_coords/namespace/app.c copied from file 2d/blit/namespace/app.c (similarity 61%) (mode: 100644) (index 689caec..eed91db) | |||
1 | 1 | #ifndef CLEANUP | #ifndef CLEANUP |
2 | 2 | #define check_vk_version app_check_vk_version | #define check_vk_version app_check_vk_version |
3 | #define cmdbuf_record app_cmdbuf_record | ||
4 | #define cmdbufs_create app_cmdbufs_create | ||
5 | #define cmdbufs_record app_cmdbufs_record | ||
6 | #define cmdpools_create app_cmdpools_create | ||
7 | #define cpu_img_create app_cpu_img_create | ||
8 | #define cpu_img_dev_mem_alloc app_cpu_img_dev_mem_alloc | ||
9 | #define cpu_img_draw app_cpu_img_draw | ||
10 | #define cpu_img_layout_to_general app_cpu_img_layout_to_general | ||
11 | #define cpu_img_subrsrc_layout_get app_cpu_img_subrsrc_layout_get | ||
12 | #define cpu_img_to_pe app_cpu_img_to_pe | ||
13 | #define cpu_imgs_create app_cpu_imgs_create | ||
14 | #define cpu_imgs_dev_mem_alloc app_cpu_imgs_dev_mem_alloc | ||
15 | #define cpu_imgs_dev_mem_bind app_cpu_imgs_dev_mem_bind | ||
16 | #define cpu_imgs_dev_mem_map app_cpu_imgs_dev_mem_map | ||
17 | #define cpu_imgs_subrsrc_layout_get app_cpu_imgs_subrsrc_layout_get | ||
3 | #define cb_rec app_cb_rec | ||
4 | #define cbs_create app_cbs_create | ||
5 | #define cbs_rec app_cbs_rec | ||
6 | #define cp_create app_cp_create | ||
18 | 7 | #define dev_create app_dev_create | #define dev_create app_dev_create |
19 | 8 | #define dev_init app_dev_init | #define dev_init app_dev_init |
20 | 9 | #define dev_type_str app_dev_type_str | #define dev_type_str app_dev_type_str |
21 | #define img_mem_barrier_run_once app_img_mem_barrier_run_once | ||
10 | #define draw app_draw | ||
11 | #define file_mmap app_file_mmap | ||
22 | 12 | #define init_vk app_init_vk | #define init_vk app_init_vk |
23 | 13 | #define instance_create app_instance_create | #define instance_create app_instance_create |
24 | 14 | #define instance_exts_dump app_instance_exts_dump | #define instance_exts_dump app_instance_exts_dump |
25 | 15 | #define instance_layers_dump app_instance_layers_dump | #define instance_layers_dump app_instance_layers_dump |
26 | #define match_mem_type app_match_mem_type | ||
27 | 16 | #define phydev_exts_dump app_phydev_exts_dup | #define phydev_exts_dump app_phydev_exts_dup |
28 | 17 | #define phydev_init app_phydev_init | #define phydev_init app_phydev_init |
29 | #define phydevs_exts_dump app_phydevs_exts_dup | ||
30 | #define phydevs_props_dump app_phydevs_props_dump | ||
18 | #define phydev_mem_heap_dump app_phydev_mem_heap_dump | ||
19 | #define phydev_mem_type_dump app_phydev_mem_type_dump | ||
20 | #define pl_layout_empty_create app_pl_layout_empty_create | ||
21 | #define pl_create app_pl_create | ||
31 | 22 | #define present_mode_to_str app_present_mode_to_str | #define present_mode_to_str app_present_mode_to_str |
32 | 23 | #define q_get app_q_get | #define q_get app_q_get |
33 | 24 | #define render app_render | #define render app_render |
25 | #define rp_create app_rp_create | ||
34 | 26 | #define run app_run | #define run app_run |
35 | 27 | #define sems_create app_sems_create | #define sems_create app_sems_create |
28 | #define shmods_create app_shmods_create | ||
29 | #define shmods_destroy app_shmods_destroy | ||
36 | 30 | #define surf_create app_surf_create | #define surf_create app_surf_create |
37 | 31 | #define surf_init app_surf_init | #define surf_init app_surf_init |
38 | 32 | #define swpchn_acquire_next_img app_swpchn_acquire_next_img | #define swpchn_acquire_next_img app_swpchn_acquire_next_img |
33 | #define swpchn_fb_create app_swpchn_fb_create | ||
34 | #define swpchn_fbs_create app_swpchn_fbs_create | ||
39 | 35 | #define swpchn_imgs_get app_swpchn_imgs_get | #define swpchn_imgs_get app_swpchn_imgs_get |
36 | #define swpchn_imgview_create app_swpchn_imgview_create | ||
37 | #define swpchn_imgviews_create app_swpchn_imgviews_create | ||
40 | 38 | #define swpchn_init app_swpchn_init | #define swpchn_init app_swpchn_init |
39 | #define texel_mem_blk_conf_select app_texel_mem_blk_conf_select | ||
41 | 40 | #define texel_mem_blk_confs_dump app_texel_mem_blk_confs_dump | #define texel_mem_blk_confs_dump app_texel_mem_blk_confs_dump |
42 | #define tmp_cpu_img_mem_rqmts_get app_tmp_cpu_img_mem_rqmts_get | ||
43 | #define tmp_cpu_imgs_mem_rqmts_get app_cpu_imgs_mem_rqmts_get | ||
44 | 41 | #define tmp_phydev_and_q_fam_select app_tmp_phydev_and_q_fam_select | #define tmp_phydev_and_q_fam_select app_tmp_phydev_and_q_fam_select |
45 | #define tmp_phydev_mem_heap_dump app_phydev_mem_heap_dump | ||
46 | 42 | #define tmp_phydev_mem_heaps_dump app_phydev_mem_heaps_dump | #define tmp_phydev_mem_heaps_dump app_phydev_mem_heaps_dump |
47 | 43 | #define tmp_phydev_mem_props_dump app_tmp_phydev_mem_props_dump | #define tmp_phydev_mem_props_dump app_tmp_phydev_mem_props_dump |
48 | 44 | #define tmp_phydev_mem_props_get app_tmp_phydev_mem_props_get | #define tmp_phydev_mem_props_get app_tmp_phydev_mem_props_get |
49 | #define tmp_phydev_mem_type_dump app_tmp_phydev_mem_type_dump | ||
50 | 45 | #define tmp_phydev_mem_types_dump app_tmp_phydev_mem_types_dump | #define tmp_phydev_mem_types_dump app_tmp_phydev_mem_types_dump |
51 | 46 | #define tmp_phydev_q_fams_get app_tmp_phydev_q_fams_get | #define tmp_phydev_q_fams_get app_tmp_phydev_q_fams_get |
52 | 47 | #define tmp_phydev_q_fams_dump app_tmp_phydev_q_fams_dump | #define tmp_phydev_q_fams_dump app_tmp_phydev_q_fams_dump |
62 | 57 | #define tmp_selected_phydev_cherry_pick app_tmp_selected_phydev_cherry_pick | #define tmp_selected_phydev_cherry_pick app_tmp_selected_phydev_cherry_pick |
63 | 58 | #define tmp_surf_caps_dump app_surf_caps_dump | #define tmp_surf_caps_dump app_surf_caps_dump |
64 | 59 | #define tmp_surf_caps_get app_surf_caps_get | #define tmp_surf_caps_get app_surf_caps_get |
65 | #define tmp_texel_mem_blk_conf_select app_tmp_texel_mem_blk_conf_select | ||
66 | #define try_alloc_cpu_img_dev_mem app_try_alloc_cpu_img_dev_mem | ||
67 | 60 | #define uuid_str app_uuid_str | #define uuid_str app_uuid_str |
68 | 61 | /******************************************************************************/ | /******************************************************************************/ |
69 | 62 | #else | #else |
70 | 63 | #undef check_vk_version | #undef check_vk_version |
71 | #undef cmdbuf_record | ||
72 | #undef cmdbufs_create | ||
73 | #undef cmdbufs_record | ||
74 | #undef cmdpools_create | ||
75 | #undef cpu_img_create | ||
76 | #undef cpu_img_dev_mem_alloc | ||
77 | #undef cpu_img_draw | ||
78 | #undef cpu_img_layout_to_general | ||
79 | #undef cpu_img_subrsrc_layout_get | ||
80 | #undef cpu_img_to_pe | ||
81 | #undef cpu_imgs_create | ||
82 | #undef cpu_imgs_dev_mem_alloc | ||
83 | #undef cpu_imgs_dev_mem_bind | ||
84 | #undef cpu_imgs_dev_mem_map | ||
85 | #undef cpu_imgs_layout_to_general | ||
86 | #undef cpu_imgs_subrsrc_layout_get | ||
64 | #undef cb_rec | ||
65 | #undef cbs_create | ||
66 | #undef cbs_rec | ||
67 | #undef cp_create | ||
87 | 68 | #undef dev_create | #undef dev_create |
88 | 69 | #undef dev_init | #undef dev_init |
89 | 70 | #undef dev_type_str | #undef dev_type_str |
90 | #undef img_mem_barrier_run_once | ||
71 | #undef draw | ||
72 | #undef file_mmap | ||
91 | 73 | #undef init_vk | #undef init_vk |
92 | 74 | #undef instance_create | #undef instance_create |
93 | 75 | #undef instance_exts_dump | #undef instance_exts_dump |
94 | 76 | #undef instance_layers_dump | #undef instance_layers_dump |
95 | #undef match_mem_type | ||
96 | 77 | #undef phydev_exts_dump | #undef phydev_exts_dump |
97 | 78 | #undef phydev_init | #undef phydev_init |
98 | #undef phydevs_exts_dump | ||
99 | #undef phydevs_props_dump | ||
79 | #undef phydev_mem_heap_dump | ||
80 | #undef phydev_mem_type_dump | ||
81 | #undef pl_create | ||
82 | #undef pl_layout_empty_create | ||
100 | 83 | #undef present_mode_to_str | #undef present_mode_to_str |
101 | 84 | #undef q_get | #undef q_get |
102 | 85 | #undef render | #undef render |
86 | #undef rp_create | ||
103 | 87 | #undef run | #undef run |
104 | 88 | #undef sems_create | #undef sems_create |
89 | #undef shmods_create | ||
90 | #undef shmods_destroy | ||
105 | 91 | #undef surf_create | #undef surf_create |
106 | 92 | #undef surf_init | #undef surf_init |
107 | 93 | #undef swpchn_acquire_next_img | #undef swpchn_acquire_next_img |
94 | #undef swpchn_fb_create | ||
95 | #undef swpchn_fbs_create | ||
108 | 96 | #undef swpchn_imgs_get | #undef swpchn_imgs_get |
97 | #undef swpchn_imgview_create | ||
98 | #undef swpchn_imgviews_create | ||
109 | 99 | #undef swpchn_init | #undef swpchn_init |
100 | #undef texel_mem_blk_conf_select | ||
110 | 101 | #undef texel_mem_blk_confs_dump | #undef texel_mem_blk_confs_dump |
111 | #undef tmp_cpu_img_mem_rqmts_get | ||
112 | #undef tmp_cpu_imgs_mem_rqmts_get | ||
113 | 102 | #undef tmp_phydev_and_q_fam_select | #undef tmp_phydev_and_q_fam_select |
114 | 103 | #undef tmp_phydev_mem_heap_dump | #undef tmp_phydev_mem_heap_dump |
115 | 104 | #undef tmp_phydev_mem_heaps_dump | #undef tmp_phydev_mem_heaps_dump |
131 | 120 | #undef tmp_selected_phydev_cherry_pick | #undef tmp_selected_phydev_cherry_pick |
132 | 121 | #undef tmp_surf_caps_dump | #undef tmp_surf_caps_dump |
133 | 122 | #undef tmp_surf_caps_get | #undef tmp_surf_caps_get |
134 | #undef tmp_texel_mem_blk_conf_select | ||
135 | #undef try_alloc_cpu_img_dev_mem | ||
136 | 123 | #undef uuid_str | #undef uuid_str |
137 | 124 | #endif | #endif |
File 3d/clip_coords/namespace/app_state.c copied from file 2d/blit/namespace/app_state.c (similarity 84%) (mode: 100644) (index 5d2f8b3..a74008d) | |||
1 | 1 | #ifndef CLEANUP | #ifndef CLEANUP |
2 | 2 | #define do_render_g app_do_render | #define do_render_g app_do_render |
3 | #define fill_texel_g app_fill_texel | ||
4 | 3 | #define instance_g app_instance | #define instance_g app_instance |
5 | 4 | #define state_g app_state | #define state_g app_state |
6 | 5 | #define surf_g app_surf | #define surf_g app_surf |
7 | #define tmp_mem_rqmts_g app_tmp_mem_rqmts | ||
8 | 6 | #define tmp_phydevs_g app_tmp_phydevs | #define tmp_phydevs_g app_tmp_phydevs |
9 | 7 | #define tmp_phydevs_n_g app_tmp_phydevs_n | #define tmp_phydevs_n_g app_tmp_phydevs_n |
10 | 8 | #define tmp_present_modes_g app_tmp_present_modes | #define tmp_present_modes_g app_tmp_present_modes |
13 | 11 | /******************************************************************************/ | /******************************************************************************/ |
14 | 12 | #else | #else |
15 | 13 | #undef do_render_g | #undef do_render_g |
16 | #undef fill_texel_g | ||
17 | 14 | #undef instance_g | #undef instance_g |
18 | 15 | #undef state_g | #undef state_g |
19 | 16 | #undef surf_g | #undef surf_g |
20 | #undef tmp_mem_rqmts_g | ||
21 | 17 | #undef tmp_phydevs_g | #undef tmp_phydevs_g |
22 | 18 | #undef tmp_phydevs_n_g | #undef tmp_phydevs_n_g |
23 | 19 | #undef tmp_present_modes_g | #undef tmp_present_modes_g |
File 3d/clip_coords/namespace/app_state_types.h copied from file 2d/blit/namespace/app_state_types.h (similarity 88%) (mode: 100644) (index a1d2e76..46825b6) | |||
1 | 1 | #ifndef CLEANUP | #ifndef CLEANUP |
2 | #define cpu_img_t app_cpu_img_t | ||
3 | 2 | #define dev_t app_dev_t | #define dev_t app_dev_t |
4 | 3 | #define phydev_t app_phydev_t | #define phydev_t app_phydev_t |
5 | 4 | #define sems_n app_sems_n | #define sems_n app_sems_n |
6 | 5 | #define sem_acquire_img_done app_sem_acquire_img_done | #define sem_acquire_img_done app_sem_acquire_img_done |
7 | #define sem_blit_done app_sem_blit_done | ||
6 | #define sem_draw_done app_sem_draw_done | ||
8 | 7 | #define state_quit app_state_quit | #define state_quit app_state_quit |
9 | 8 | #define state_run app_state_run | #define state_run app_state_run |
10 | 9 | #define surf_t app_surf_t | #define surf_t app_surf_t |
16 | 15 | #define tmp_present_modes_n_max app_tmp_present_modes_n_max | #define tmp_present_modes_n_max app_tmp_present_modes_n_max |
17 | 16 | /******************************************************************************/ | /******************************************************************************/ |
18 | 17 | #else | #else |
19 | #undef cpu_img_t | ||
20 | 18 | #undef dev_t | #undef dev_t |
21 | 19 | #undef phydev_t | #undef phydev_t |
22 | 20 | #undef sems_n | #undef sems_n |
23 | 21 | #undef sem_acquire_img_done | #undef sem_acquire_img_done |
24 | #undef sem_blit_done | ||
22 | #undef sem_draw_done | ||
25 | 23 | #undef state_run | #undef state_run |
26 | 24 | #undef surf_t | #undef surf_t |
27 | 25 | #undef state_quit | #undef state_quit |
File 3d/clip_coords/namespace/vk_syms.c copied from file 2d/blit/namespace/vk_syms.c (similarity 100%) |
File 3d/clip_coords/vk_app.h added (mode: 100644) (index 0000000..bb55aa6) | |||
1 | #ifndef VK_APP_H | ||
2 | #define VK_APP_H | ||
3 | /* | ||
4 | * this is public domain without any warranties of any kind | ||
5 | * Sylvain BERTRAND | ||
6 | */ | ||
7 | /* XXX: KEEP AN EYE ON ABBREVIATIONS, ALWAYS */ | ||
8 | /* | ||
9 | * this is the simplification and taylorization of vk api for the specific | ||
10 | * uses of the app. | ||
11 | */ | ||
12 | #define vk_get_dev_q() \ | ||
13 | app_surf.dev.dl_vk_get_dev_q(app_surf.dev.vk, app_surf.dev.phydev.q_fam, 0, &app_surf.dev.q) | ||
14 | |||
15 | #define vk_create_cp(info) \ | ||
16 | r = app_surf.dev.dl_vk_create_cp(app_surf.dev.vk, info, 0, &app_surf.dev.cp) | ||
17 | |||
18 | /* a swpchn can become "out of date" */ | ||
19 | #define vk_create_swpchn(info, swpchn) \ | ||
20 | r = app_surf.dev.dl_vk_create_swpchn(app_surf.dev.vk, info, 0, swpchn) | ||
21 | |||
22 | #define vk_get_swpchn_imgs() \ | ||
23 | 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) | ||
24 | |||
25 | #define vk_alloc_cbs(info) \ | ||
26 | r = app_surf.dev.dl_vk_alloc_cbs(app_surf.dev.vk, info, app_surf.dev.cbs) | ||
27 | |||
28 | #define vk_begin_cb(...) \ | ||
29 | r = app_surf.dev.dl_vk_begin_cb(__VA_ARGS__) | ||
30 | |||
31 | #define vk_end_cb(...) \ | ||
32 | r = app_surf.dev.dl_vk_end_cb(__VA_ARGS__) | ||
33 | |||
34 | #define vk_q_submit(info) \ | ||
35 | r = app_surf.dev.dl_vk_q_submit(app_surf.dev.q, 1, info, 0) | ||
36 | |||
37 | #define vk_acquire_next_img(...) \ | ||
38 | r = app_surf.dev.dl_vk_acquire_next_img(app_surf.dev.vk,##__VA_ARGS__) | ||
39 | |||
40 | #define vk_q_present(...) \ | ||
41 | r = app_surf.dev.dl_vk_q_present(app_surf.dev.q,##__VA_ARGS__) | ||
42 | |||
43 | #define vk_create_sem(info, sem) \ | ||
44 | r = app_surf.dev.dl_vk_create_sem(app_surf.dev.vk, info, 0, sem) | ||
45 | |||
46 | #define vk_create_imgview(info, imgview) \ | ||
47 | r = app_surf.dev.dl_vk_create_imgview(app_surf.dev.vk, info, 0, imgview) | ||
48 | |||
49 | #define vk_create_rp(info) \ | ||
50 | r = app_surf.dev.dl_vk_create_rp(app_surf.dev.vk, info, 0, &app_surf.dev.rp) | ||
51 | |||
52 | #define vk_create_shmod(info, shmod) \ | ||
53 | r = app_surf.dev.dl_vk_create_shmod(app_surf.dev.vk, info, 0, shmod) | ||
54 | |||
55 | #define vk_destroy_shmod(shmod) \ | ||
56 | app_surf.dev.dl_vk_destroy_shmod(app_surf.dev.vk, shmod, 0) | ||
57 | |||
58 | #define vk_create_pl_layout(info, layout) \ | ||
59 | r = app_surf.dev.dl_vk_create_pl_layout(app_surf.dev.vk, info, 0, layout) | ||
60 | |||
61 | #define vk_create_gfx_pls(info) \ | ||
62 | r = app_surf.dev.dl_vk_create_gfx_pls(app_surf.dev.vk, 0, 1, info, 0, &app_surf.dev.pl) | ||
63 | |||
64 | #define vk_create_fb(info, fb) \ | ||
65 | r = app_surf.dev.dl_vk_create_fb(app_surf.dev.vk, info, 0, fb) | ||
66 | |||
67 | #define vk_cmd_begin_rp(cb, info) \ | ||
68 | app_surf.dev.dl_vk_cmd_begin_rp(cb, info, vk_sp_contents_inline) | ||
69 | |||
70 | #define vk_cmd_bind_pl(cb) \ | ||
71 | app_surf.dev.dl_vk_cmd_bind_pl(cb, vk_pl_bind_point_gfx, app_surf.dev.pl) | ||
72 | |||
73 | #define vk_cmd_end_rp app_surf.dev.dl_vk_cmd_end_rp | ||
74 | |||
75 | #define vk_cmd_draw app_surf.dev.dl_vk_cmd_draw | ||
76 | /******************************************************************************/ | ||
77 | /* from nyanvk/syms_global.h */ | ||
78 | #define VK_GLOBAL_SYMS \ | ||
79 | static void *(*dl_vk_get_instance_proc_addr)(void *instance, u8 *name);\ | ||
80 | static void *(*dl_vk_get_dev_proc_addr)(void *dev, u8 *name);\ | ||
81 | \ | ||
82 | static s32 (*dl_vk_enumerate_instance_version)(u32 *version);\ | ||
83 | static s32 (*dl_vk_enumerate_instance_layer_props)(\ | ||
84 | u32 *props_n,\ | ||
85 | struct vk_layer_props_t *props);\ | ||
86 | static s32 (*dl_vk_enumerate_instance_ext_props)(\ | ||
87 | u8 *layer_name,\ | ||
88 | u32 *props_n,\ | ||
89 | struct vk_ext_props_t *props);\ | ||
90 | static s32 (*dl_vk_create_instance)(\ | ||
91 | struct vk_instance_create_info_t *info,\ | ||
92 | void *allocator,\ | ||
93 | void **instance);\ | ||
94 | static s32 (*dl_vk_enumerate_phydevs)(\ | ||
95 | void *instance,\ | ||
96 | u32 *phydevs_n,\ | ||
97 | void **phydevs);\ | ||
98 | static s32 (*dl_vk_enumerate_dev_ext_props)(\ | ||
99 | void *phydev,\ | ||
100 | u8 *layer_name,\ | ||
101 | u32 *props_n,\ | ||
102 | struct vk_ext_props_t *props);\ | ||
103 | static void (*dl_vk_get_phydev_props)(\ | ||
104 | void *phydev,\ | ||
105 | struct vk_phydev_props_t *props);\ | ||
106 | static s32 (*dl_vk_create_dev)(\ | ||
107 | void *phydev,\ | ||
108 | struct vk_dev_create_info_t *create_info,\ | ||
109 | void *allocator,\ | ||
110 | void **dev);\ | ||
111 | static void (*dl_vk_get_phydev_q_fam_props)(\ | ||
112 | void *phydev,\ | ||
113 | u32 *q_fam_props_n,\ | ||
114 | struct vk_q_fam_props_t *props);\ | ||
115 | static s32 (*dl_vk_create_xcb_surf)(\ | ||
116 | void *instance,\ | ||
117 | struct vk_xcb_surf_create_info_t *info,\ | ||
118 | void *allocator,\ | ||
119 | void **surf);\ | ||
120 | static s32 (*dl_vk_get_phydev_surf_support)(\ | ||
121 | void *phydev,\ | ||
122 | u32 q_fam,\ | ||
123 | void *surf,\ | ||
124 | u32 *supported);\ | ||
125 | static s32 (*dl_vk_get_phydev_surf_texel_mem_blk_confs)(\ | ||
126 | void *phydev,\ | ||
127 | struct vk_phydev_surf_info_t *info,\ | ||
128 | u32 *confs_n,\ | ||
129 | struct vk_surf_texel_mem_blk_conf_t *confs);\ | ||
130 | static void (*dl_vk_get_phydev_mem_props)(\ | ||
131 | void *phydev,\ | ||
132 | struct vk_phydev_mem_props_t *props);\ | ||
133 | static s32 (*dl_vk_get_phydev_surf_caps)(\ | ||
134 | void *phydev,\ | ||
135 | struct vk_phydev_surf_info_t *info,\ | ||
136 | struct vk_surf_caps_t *caps);\ | ||
137 | static s32 (*dl_vk_get_phydev_surf_present_modes)(\ | ||
138 | void *phydev,\ | ||
139 | void *surf,\ | ||
140 | u32 *modes_n,\ | ||
141 | u32 *modes); | ||
142 | /******************************************************************************/ | ||
143 | #define vk_get_instance_proc_addr dl_vk_get_instance_proc_addr | ||
144 | |||
145 | #define vk_get_dev_proc_addr dl_vk_get_dev_proc_addr | ||
146 | |||
147 | #define vk_enumerate_instance_version(...) \ | ||
148 | r = dl_vk_enumerate_instance_version(__VA_ARGS__) | ||
149 | |||
150 | #define vk_enumerate_instance_layer_props(...) \ | ||
151 | r = dl_vk_enumerate_instance_layer_props(__VA_ARGS__) | ||
152 | |||
153 | #define vk_enumerate_instance_ext_props(props_n, props) \ | ||
154 | r = dl_vk_enumerate_instance_ext_props(0, props_n, props) | ||
155 | |||
156 | #define vk_create_instance(info) \ | ||
157 | r = dl_vk_create_instance(info, 0, &app_instance) | ||
158 | |||
159 | #define vk_enumerate_phydevs(...) \ | ||
160 | r = dl_vk_enumerate_phydevs(app_instance,##__VA_ARGS__) | ||
161 | |||
162 | #define vk_enumerate_dev_ext_props(phydev, props_n, props) \ | ||
163 | r = dl_vk_enumerate_dev_ext_props(phydev, 0, props_n, props) | ||
164 | |||
165 | #define vk_get_phydev_props dl_vk_get_phydev_props | ||
166 | |||
167 | #define vk_create_dev(info) \ | ||
168 | r = dl_vk_create_dev(app_surf.dev.phydev.vk, info, 0, &app_surf.dev.vk) | ||
169 | |||
170 | #define vk_get_phydev_q_fam_props dl_vk_get_phydev_q_fam_props | ||
171 | |||
172 | #define vk_create_xcb_surf(info) \ | ||
173 | r = dl_vk_create_xcb_surf(app_instance, info, 0, &app_surf.vk) | ||
174 | |||
175 | #define vk_get_phydev_surf_support(phydev, q_fam, supported) \ | ||
176 | r = dl_vk_get_phydev_surf_support(phydev, q_fam, app_surf.vk, supported) | ||
177 | |||
178 | #define vk_get_phydev_surf_texel_mem_blk_confs(...) \ | ||
179 | r = dl_vk_get_phydev_surf_texel_mem_blk_confs(app_surf.dev.phydev.vk,##__VA_ARGS__) | ||
180 | |||
181 | #define vk_get_phydev_mem_props dl_vk_get_phydev_mem_props | ||
182 | |||
183 | #define vk_get_phydev_surf_caps(info, caps) \ | ||
184 | r = dl_vk_get_phydev_surf_caps(app_surf.dev.phydev.vk, info, caps) | ||
185 | |||
186 | #define vk_get_phydev_surf_present_modes() \ | ||
187 | 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) | ||
188 | #endif |
File 3d/clip_coords/vk_syms.c copied from file 2d/blit/vk_syms.c (similarity 84%) (mode: 100644) (index e66679f..51b551c) | |||
17 | 17 | #include "namespace/vk_syms.c" | #include "namespace/vk_syms.c" |
18 | 18 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
19 | 19 | VK_GLOBAL_SYMS | VK_GLOBAL_SYMS |
20 | static void *loader_g; /* we put the dl handle in vk namespace */ | ||
21 | /*----------------------------------------------------------------------------*/ | ||
20 | static void *loader_g; | ||
22 | 21 | #define INSTANCE_STATIC_SYM(x,y) \ | #define INSTANCE_STATIC_SYM(x,y) \ |
23 | 22 | dl_##y = vk_get_instance_proc_addr(0, #x); \ | dl_##y = vk_get_instance_proc_addr(0, #x); \ |
24 | 23 | if (dl_##y == 0) { \ | if (dl_##y == 0) { \ |
... | ... | static void instance_static_syms(void) | |
39 | 38 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
40 | 39 | #define INSTANCE_SYM(x,y) \ | #define INSTANCE_SYM(x,y) \ |
41 | 40 | dl_##y = vk_get_instance_proc_addr(app_instance, #x); \ | dl_##y = vk_get_instance_proc_addr(app_instance, #x); \ |
42 | if (dl_##y == 0) { \ | ||
41 | if (dl_##y == 0) { \ | ||
43 | 42 | LOG("0:MAIN:FATAL:unable to find vulkan " #x "\n"); \ | LOG("0:MAIN:FATAL:unable to find vulkan " #x "\n"); \ |
44 | 43 | exit(1); \ | exit(1); \ |
45 | 44 | } | } |
... | ... | static void dev_syms(void) | |
80 | 79 | DEV_SYM(vkCreateCommandPool, vk_create_cp); | DEV_SYM(vkCreateCommandPool, vk_create_cp); |
81 | 80 | DEV_SYM(vkCreateSwapchainKHR, vk_create_swpchn); | DEV_SYM(vkCreateSwapchainKHR, vk_create_swpchn); |
82 | 81 | DEV_SYM(vkGetSwapchainImagesKHR, vk_get_swpchn_imgs); | DEV_SYM(vkGetSwapchainImagesKHR, vk_get_swpchn_imgs); |
83 | DEV_SYM(vkCreateImage, vk_create_img); | ||
84 | DEV_SYM(vkGetImageMemoryRequirements2KHR, vk_get_img_mem_rqmts); | ||
85 | DEV_SYM(vkAllocateMemory, vk_alloc_mem); | ||
86 | DEV_SYM(vkBindImageMemory2KHR, vk_bind_img_mem); | ||
87 | DEV_SYM(vkMapMemory, vk_map_mem); | ||
88 | 82 | DEV_SYM(vkAllocateCommandBuffers, vk_alloc_cbs); | DEV_SYM(vkAllocateCommandBuffers, vk_alloc_cbs); |
89 | 83 | DEV_SYM(vkBeginCommandBuffer, vk_begin_cb); | DEV_SYM(vkBeginCommandBuffer, vk_begin_cb); |
90 | 84 | DEV_SYM(vkEndCommandBuffer, vk_end_cb); | DEV_SYM(vkEndCommandBuffer, vk_end_cb); |
91 | DEV_SYM(vkCmdPipelineBarrier, vk_cmd_pl_barrier); | ||
92 | 85 | DEV_SYM(vkQueueSubmit, vk_q_submit); | DEV_SYM(vkQueueSubmit, vk_q_submit); |
93 | DEV_SYM(vkQueueWaitIdle, vk_q_wait_idle); | ||
94 | DEV_SYM(vkGetImageSubresourceLayout, vk_get_img_subrsrc_layout); | ||
95 | 86 | DEV_SYM(vkAcquireNextImage2KHR, vk_acquire_next_img); | DEV_SYM(vkAcquireNextImage2KHR, vk_acquire_next_img); |
96 | DEV_SYM(vkResetCommandBuffer, vk_reset_cb); | ||
97 | DEV_SYM(vkCmdBlitImage, vk_cmd_blit_img); | ||
98 | 87 | DEV_SYM(vkQueuePresentKHR, vk_q_present); | DEV_SYM(vkQueuePresentKHR, vk_q_present); |
99 | 88 | DEV_SYM(vkCreateSemaphore, vk_create_sem); | DEV_SYM(vkCreateSemaphore, vk_create_sem); |
89 | DEV_SYM(vkCreateImageView, vk_create_imgview); | ||
90 | DEV_SYM(vkCreateRenderPass, vk_create_rp); | ||
91 | DEV_SYM(vkCreateFramebuffer, vk_create_fb); | ||
92 | DEV_SYM(vkCreateShaderModule, vk_create_shmod); | ||
93 | DEV_SYM(vkDestroyShaderModule, vk_destroy_shmod); | ||
94 | DEV_SYM(vkCreatePipelineLayout, vk_create_pl_layout); | ||
95 | DEV_SYM(vkCreateGraphicsPipelines, vk_create_gfx_pls); | ||
96 | DEV_SYM(vkCmdBeginRenderPass, vk_cmd_begin_rp); | ||
97 | DEV_SYM(vkCmdBindPipeline, vk_cmd_bind_pl); | ||
98 | DEV_SYM(vkCmdDraw, vk_cmd_draw); | ||
99 | DEV_SYM(vkCmdEndRenderPass, vk_cmd_end_rp); | ||
100 | 100 | } | } |
101 | 101 | #undef DEVICE_SYM | #undef DEVICE_SYM |
102 | 102 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
103 | 103 | #define DLSYM(x, y) \ | #define DLSYM(x, y) \ |
104 | dl_##y = dlsym(loader_g, #x); \ | ||
104 | dl_##y = dlsym(loader_g, #x); \ | ||
105 | 105 | if (dl_##y == 0) { \ | if (dl_##y == 0) { \ |
106 | 106 | LOG("0:MAIN:FATAL:%s:unable to find " #x "\n", dlerror()); \ | LOG("0:MAIN:FATAL:%s:unable to find " #x "\n", dlerror()); \ |
107 | 107 | exit(1); \ | exit(1); \ |
... | ... | static void loader_syms(void) | |
115 | 115 | /*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ |
116 | 116 | static void load_vk_loader(void) | static void load_vk_loader(void) |
117 | 117 | { | { |
118 | /* no '/' in the shared dynamic lib path name, then standard lookup */ | ||
118 | /* no '/' in the shared dynamic lib path, then standard lookup */ | ||
119 | 119 | loader_g = dlopen("libvulkan.so.1", RTLD_LAZY); | loader_g = dlopen("libvulkan.so.1", RTLD_LAZY); |
120 | 120 | if (loader_g == 0) { | if (loader_g == 0) { |
121 | 121 | LOG("0:MAIN:FATAL:%s:unable to load the vulkan loader dynamic shared library\n", dlerror()); | LOG("0:MAIN:FATAL:%s:unable to load the vulkan loader dynamic shared library\n", dlerror()); |
File 3d/clip_coords/vs.S added (mode: 100644) (index 0000000..9db39d4) | |||
1 | capability shader | ||
2 | //============================================================================== | ||
3 | memory_model addressing_model=logical memory_model=glsl450 | ||
4 | //============================================================================== | ||
5 | entry_point execution_model=vertex entry_point=%23 name="main" \ | ||
6 | /*interface[0]=*/%9 \ | ||
7 | /*interface[1]=*/%10 | ||
8 | //============================================================================== | ||
9 | decorate target=%9 decoration=builtin vertex_index | ||
10 | decorate target=%10 decoration=builtin position | ||
11 | //============================================================================== | ||
12 | /* %1 */ type_void %1 | ||
13 | /* %2 */ type_bool %2 | ||
14 | /* %3 */ type_function id=%3 return_type=%1 | ||
15 | /* %4 */ type_int id=%4 width=32 signedness=unsigned | ||
16 | //------------------------------------------------------------------------------ | ||
17 | /* %5 */ type_float id=%5 width=32 | ||
18 | /* %6 */ type_vector id=%6 component_type=%5 components_n=4 | ||
19 | //------------------------------------------------------------------------------ | ||
20 | /* %7 */ type_pointer id=%7 storage_class=input type=%4 | ||
21 | /* %8 */ type_pointer id=%8 storage_class=output type=%6 | ||
22 | //------------------------------------------------------------------------------ | ||
23 | // vertex_index | ||
24 | /* %9 */ variable type=%7 pointer_id=%9 storage_class=input | ||
25 | // position | ||
26 | /* %10 */ variable type=%8 pointer_id=%10 storage_class=output | ||
27 | //------------------------------------------------------------------------------ | ||
28 | /* %14 */ constant type=%5 id=%14 /*values[0]=*/0.0 | ||
29 | /* %15 */ constant type=%5 id=%15 /*values[0]=*/1.0 | ||
30 | /* %16 */ constant type=%5 id=%16 /*values[0]=*/0.5 | ||
31 | /* %17 */ constant type=%5 id=%17 /*values[0]=*/0.1 | ||
32 | /* %18 */ constant type=%5 id=%18 /*values[0]=*/-1.0 | ||
33 | /* %19 */ constant type=%5 id=%19 /*values[0]=*/-0.5 | ||
34 | //------------------------------------------------------------------------------ | ||
35 | // the following are the vertexes of our triangle IN CLIP COORDINATES. | ||
36 | // our wc = 1.0f (wc --> 'w' is the forth 3D coord/'c' stands for 'C'lipped. | ||
37 | |||
38 | // {0.0f, -0.5f, 0.1f, 1.0f} | ||
39 | /* %20 */ constant_composite type=%6 id=%20 \ | ||
40 | /*constituents[0]=*/%14 \ | ||
41 | /*constituents[1]=*/%19 \ | ||
42 | /*constituents[2]=*/%17 \ | ||
43 | /*constituents[3]=*/%15 | ||
44 | // {0.5f, 0.5f, 0.1f, 1.0f} | ||
45 | /* %21 */ constant_composite type=%6 id=%21 \ | ||
46 | /*constituents[0]=*/%16 \ | ||
47 | /*constituents[1]=*/%16 \ | ||
48 | /*constituents[2]=*/%17 \ | ||
49 | /*constituents[3]=*/%15 | ||
50 | // {-0.5f, 0.5f, 0.1f, 1.0f} | ||
51 | /* %22 */ constant_composite type=%6 id=%22 \ | ||
52 | /*constituents[0]=*/%19 \ | ||
53 | /*constituents[1]=*/%16 \ | ||
54 | /*constituents[2]=*/%17 \ | ||
55 | /*constituents[3]=*/%15 | ||
56 | //============================================================================== | ||
57 | /* %23 */ function return_type=%1 id=%23 control=none type=%3 | ||
58 | /* %24 */ label id=%24 | ||
59 | /* %25 */ load id=%25 type=%4 pointer=%9 | ||
60 | selection_merge block=%29 selection_control=none | ||
61 | switch selector=%25 default=%29 0 %26 1 %27 2 %28 | ||
62 | /* %26 */ label id=%26 | ||
63 | store pointer=%10 object=%20 | ||
64 | return | ||
65 | /* %27 */ label id=%27 | ||
66 | store pointer=%10 object=%21 | ||
67 | return | ||
68 | /* %28 */ label id=%28 | ||
69 | store pointer=%10 object=%22 | ||
70 | return | ||
71 | /* %29 */ label id=%29 /* switch merge block */ | ||
72 | return | ||
73 | function_end |
File 3d/clip_coords/xcb.c copied from file 2d/blit/xcb.c (similarity 100%) (mode: 100644) (index 1485287..322d32c) | |||
8 | 8 | #include <string.h> | #include <string.h> |
9 | 9 | #include <stdlib.h> | #include <stdlib.h> |
10 | 10 | #include <xcb.h> | #include <xcb.h> |
11 | #include "app_core_types.h" | ||
12 | 11 | #include "log.h" | #include "log.h" |
12 | #include "app_core_types.h" | ||
13 | 13 | #include "xcb_syms.c" | #include "xcb_syms.c" |
14 | 14 | #include "app_state.c" | #include "app_state.c" |
15 | 15 |
File 3d/clip_coords/xcb_syms.c copied from file 2d/blit/xcb_syms.c (similarity 100%) |
File nyanvk/types.h changed (mode: 100644) (index 0bf3648..0c81e9d) | |||
... | ... | struct vk_pl_color_blend_at_state_t { | |
518 | 518 | u32 dst_alpha_blend_factor; | u32 dst_alpha_blend_factor; |
519 | 519 | u32 alpha_blend_op; | u32 alpha_blend_op; |
520 | 520 | ||
521 | /* normalized integer */ | ||
521 | /* normalized integer */ | ||
522 | /* XXX: must always be set, blending enabled or disabled */ | ||
522 | 523 | u32 color_write_mask; | u32 color_write_mask; |
523 | 524 | }; | }; |
524 | 525 | struct vk_pl_color_blend_state_create_info_t { | struct vk_pl_color_blend_state_create_info_t { |
File spirv/asm/asm.c changed (mode: 100644) (index 141c14c..a0f885a) | |||
... | ... | static u32 ids_bound(void) | |
114 | 114 | break; | break; |
115 | 115 | bit--; | bit--; |
116 | 116 | } | } |
117 | return 32 * word + bit; | ||
117 | return (32 * word + bit) + 1; | ||
118 | 118 | } | } |
119 | 119 | if (word == 0) | if (word == 0) |
120 | 120 | break; | break; |
... | ... | static void out_hdr(void) | |
129 | 129 | word = 0x07230203; /* magic number */ | word = 0x07230203; /* magic number */ |
130 | 130 | fwrite(&word, sizeof(word), 1, stdout); | fwrite(&word, sizeof(word), 1, stdout); |
131 | 131 | ||
132 | word = 0x0001000; /* version 0xxx1.xxx0 */ | ||
132 | word = 0x00010000; /* version 0xxx1.xxx0 */ | ||
133 | 133 | fwrite(&word, sizeof(word), 1, stdout); | fwrite(&word, sizeof(word), 1, stdout); |
134 | 134 | ||
135 | 135 | word = 0xdeadbeef; /* generator magic number, namely ours */ | word = 0xdeadbeef; /* generator magic number, namely ours */ |
... | ... | static void op_store(void) | |
2468 | 2468 | } | } |
2469 | 2469 | } | } |
2470 | 2470 | ||
2471 | static void op_load(void) | ||
2472 | { | ||
2473 | u8 r; | ||
2474 | bool have_type; | ||
2475 | u32 type; | ||
2476 | bool have_id; | ||
2477 | u32 id; | ||
2478 | bool have_pointer; | ||
2479 | u32 pointer; | ||
2480 | u8 *err_str; | ||
2481 | |||
2482 | u32 memory_opds[VAR_OPDS_N_MAX]; | ||
2483 | u32 memory_opds_n; | ||
2484 | |||
2485 | u32 word; | ||
2486 | |||
2487 | have_type = false; | ||
2488 | have_pointer = false; | ||
2489 | have_id = false; | ||
2490 | memory_opds_n = 0; | ||
2491 | |||
2492 | loop { | ||
2493 | u8 *opd_s; | ||
2494 | u8 *opd_e; | ||
2495 | |||
2496 | r = ws_skip(); | ||
2497 | if (r == EOL) { | ||
2498 | err("ERROR:%u:type_function:missing operands\n", line_num); | ||
2499 | exit(1); | ||
2500 | } | ||
2501 | |||
2502 | opd_s = b; | ||
2503 | ws_or_eol_or_eq_reach(); | ||
2504 | opd_e = b; | ||
2505 | |||
2506 | if (str_slice_cmp("type", opd_s, opd_e)) { | ||
2507 | type = opd_id("load", "type", "type id"); | ||
2508 | have_type= true; | ||
2509 | } else if (str_slice_cmp("id", opd_s, opd_e)) { | ||
2510 | id = opd_id("load", "id", "id"); | ||
2511 | |||
2512 | r = id_use(id, &err_str); | ||
2513 | if (r != OK) { | ||
2514 | err("ERROR:%u:load:something is wrong with the id:%s\n", line_num, err_str); | ||
2515 | exit(1); | ||
2516 | } | ||
2517 | have_id = true; | ||
2518 | } else if (str_slice_cmp("pointer", opd_s, opd_e)) { | ||
2519 | pointer = opd_id("load", "pointer", "pointer id"); | ||
2520 | have_pointer = true; | ||
2521 | } else { | ||
2522 | err("ERROR:%u:load:unknown operand \"%.*s\"\n", line_num, opd_e - opd_s, opd_s); | ||
2523 | exit(1); | ||
2524 | } | ||
2525 | |||
2526 | if (have_type && have_id && have_pointer) | ||
2527 | break; | ||
2528 | } | ||
2529 | |||
2530 | r = ws_skip(); | ||
2531 | if (r == OK) /* have memory opd(s) */ | ||
2532 | memory_opds_collect("load", memory_opds, &memory_opds_n); | ||
2533 | |||
2534 | word = 61; | ||
2535 | word |= (4 + memory_opds_n) << 16; | ||
2536 | emit(word); | ||
2537 | |||
2538 | emit(type); | ||
2539 | emit(id); | ||
2540 | emit(pointer); | ||
2541 | |||
2542 | word = 0; | ||
2543 | loop { | ||
2544 | if (word == memory_opds_n) | ||
2545 | break; | ||
2546 | emit(memory_opds[word]); | ||
2547 | ++word; | ||
2548 | } | ||
2549 | } | ||
2550 | |||
2471 | 2551 | static void op_dispatch(void) | static void op_dispatch(void) |
2472 | 2552 | { | { |
2473 | 2553 | u8 *op_s; | u8 *op_s; |
... | ... | static void op_dispatch(void) | |
2521 | 2601 | op_switch(); | op_switch(); |
2522 | 2602 | else if (str_slice_cmp("store", op_s, op_e)) | else if (str_slice_cmp("store", op_s, op_e)) |
2523 | 2603 | op_store(); | op_store(); |
2604 | else if (str_slice_cmp("load", op_s, op_e)) | ||
2605 | op_load(); | ||
2524 | 2606 | /* TODO: MORE */ | /* TODO: MORE */ |
2525 | 2607 | else { | else { |
2526 | 2608 | err("ERROR:%u:unknown instruction \"%.*s\"\n", line_num, op_e - op_s, op_s); | err("ERROR:%u:unknown instruction \"%.*s\"\n", line_num, op_e - op_s, op_s); |