From ae38b3b01e5c1a5ea2d0433399038a64473e83d6 Mon Sep 17 00:00:00 2001 From: Andreew Gregory Date: Sat, 27 Dec 2025 03:03:45 +0300 Subject: [PATCH] Figured a thing or two about haskell ffi --- .gitignore | 2 + src/l1/anne/alice.h | 25 + src/l1/anne/codegen.c | 3 +- src/l1/anne/margaret/margaret_misc.h | 1 + src/l1/anne/some_tests.h | 12 +- src/l2/alice/assets.h | 8 +- src/l2/allie/Allie.hs | 79 ++- src/l2/allie/allie.c | 933 ++++++++++++++------------- src/l3/r4/R4.hs | 2 +- 9 files changed, 596 insertions(+), 469 deletions(-) create mode 100644 src/l1/anne/alice.h diff --git a/.gitignore b/.gitignore index 912e641..9837024 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ vgcore.* GRAPH*.gv GRAPH*.png SICK_JOKE* +*.hi +*_stub.h \ No newline at end of file diff --git a/src/l1/anne/alice.h b/src/l1/anne/alice.h new file mode 100644 index 0000000..9ab1bf3 --- /dev/null +++ b/src/l1/anne/alice.h @@ -0,0 +1,25 @@ +#ifndef prototype1_src_l1_anne_alice_h +#define prototype1_src_l1_anne_alice_h + +#include "../codegen/codegen.h" + +void generate_code_for_alice_on_l1(){ + mkdir_nofail("l1/eve/alice"); + mkdir_nofail("l1/eve/alice"); + SpanU8 l = cstr("l1"), ns = cstr("alice"); + /* Assets: model topology */ + generate_eve_span_company_for_primitive(l, ns, cstr("GenericMeshVertexInc"), true, true); + generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("GenericMeshInSceneTemplate"), true, false); + generate_eve_span_company_for_primitive(l, ns, cstr("ShinyMeshVertexInc"), true, true); + generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("ShinyMeshTopology"), true, false); + + /* Engine stuff */ + generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelOnSceneMem"), true, false); + generate_eve_span_company_for_primitive(l, ns, cstr("ShinyModelOnSceneMem"), true, false); + generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelTexVulkPointers"), true, false); + + + generate_eve_span_company_for_primitive(l, ns, cstr("ObjectInfo"), true, false); // todo: delete this crap +} + +#endif \ No newline at end of file diff --git a/src/l1/anne/codegen.c b/src/l1/anne/codegen.c index 596ebbd..2ac9b74 100644 --- a/src/l1/anne/codegen.c +++ b/src/l1/anne/codegen.c @@ -13,6 +13,7 @@ #include "embassy_l1_5.h" #include "margaret/png_pixel_masses.h" #include "lucy.h" +#include "alice.h" int main() { mkdir_nofail("l1"); @@ -26,10 +27,10 @@ int main() { generate_marie_headers_for_graphics_geom(); generate_liza_l1_headers(); generate_l1_headers_for_l1_5(); - mkdir_nofail("l1/margaret"); generate_margaret_eve_for_vulkan_utils(); /* margaret misc */ generate_margaret_png_pixel_masses_header(); generate_l1_lucy_headers(); + generate_code_for_alice_on_l1(); finish_layer(cstr("l1")); return 0; } diff --git a/src/l1/anne/margaret/margaret_misc.h b/src/l1/anne/margaret/margaret_misc.h index 67fe12d..6d48b1a 100644 --- a/src/l1/anne/margaret/margaret_misc.h +++ b/src/l1/anne/margaret/margaret_misc.h @@ -7,6 +7,7 @@ void generate_margaret_eve_for_vulkan_utils() { SpanU8 l = cstr("l1"); SpanU8 ns = cstr("margaret"); + mkdir_nofail("l1/margaret"); mkdir_nofail("l1/eve/margaret"); generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){ .T = cstr("MargaretScoredPhysicalDevice"), .t_primitive = true, .vec = true, .sort = true diff --git a/src/l1/anne/some_tests.h b/src/l1/anne/some_tests.h index 334e75d..62fc438 100644 --- a/src/l1/anne/some_tests.h +++ b/src/l1/anne/some_tests.h @@ -5,22 +5,12 @@ void generate_headers_for_r0_r1_r2_r3() { SpanU8 l = cstr("l1"); + mkdir_nofail("l1/eve"); mkdir_nofail("l1/eve/r0"); { /* Needed in r0_assets.h */ SpanU8 ns = cstr("r0"); - generate_eve_span_company_for_primitive(l, ns, cstr("GenericMeshVertexInc"), true, true); - generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("GenericMeshInSceneTemplate"), true, false); - generate_eve_span_company_for_primitive(l, ns, cstr("ShinyMeshVertexInc"), true, true); - generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("ShinyMeshTopology"), true, false); generate_eve_span_company_for_primitive(l, ns, cstr("Wimbzle"), true, false); generate_eve_span_company_for_primitive(l, ns, cstr("Nibzle"), true, false); - /* r0_scene.h */ - generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelOnSceneMem"), true, false); - generate_eve_span_company_for_primitive(l, ns, cstr("ShinyModelOnSceneMem"), true, false); - - generate_eve_span_company_for_primitive(l, ns, cstr("ObjectInfo"), true, false); - /* r0 */ - generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelTexVulkPointers"), true, false); } mkdir_nofail("l1/eve/r2"); { /* r2 */ diff --git a/src/l2/alice/assets.h b/src/l2/alice/assets.h index e7e12ff..dc85846 100644 --- a/src/l2/alice/assets.h +++ b/src/l2/alice/assets.h @@ -10,7 +10,7 @@ typedef struct { vec2 tex; } GenericMeshVertexInc; -#include "../../../gen/l1/eve/r0/VecAndSpan_GenericMeshVertexInc.h" +#include "../../../gen/l1/eve/alice/VecAndSpan_GenericMeshVertexInc.h" typedef struct { GenericMeshVertexInc base; @@ -54,7 +54,7 @@ GenericMeshInSceneTemplate GenericMeshInSceneTemplate_clone(const GenericMeshInS .specular_texture_path = VecU8_clone(&self->specular_texture_path)}; } -#include "../../../gen/l1/eve/r0/VecGenericMeshInSceneTemplate.h" +#include "../../../gen/l1/eve/alice/VecGenericMeshInSceneTemplate.h" typedef struct { mat4 model_t; @@ -74,7 +74,7 @@ typedef struct { ShinyMeshVertexInc base; vec3 normal; } ShinyMeshVertex; -#include "../../../gen/l1/eve/r0/VecAndSpan_ShinyMeshVertexInc.h" +#include "../../../gen/l1/eve/alice/VecAndSpan_ShinyMeshVertexInc.h" typedef struct { VecShinyMeshVertexInc vertices; @@ -91,7 +91,7 @@ ShinyMeshTopology ShinyMeshTopology_clone(const ShinyMeshTopology* self) { VecU32_clone(&self->indexes)}; } -#include "../../../gen/l1/eve/r0/VecShinyMeshTopology.h" +#include "../../../gen/l1/eve/alice/VecShinyMeshTopology.h" typedef struct{ mat4 model_t; diff --git a/src/l2/allie/Allie.hs b/src/l2/allie/Allie.hs index a8cb446..cbf0c9b 100644 --- a/src/l2/allie/Allie.hs +++ b/src/l2/allie/Allie.hs @@ -1,5 +1,80 @@ {-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE DisambiguateRecordFields #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE RankNTypes #-} -module Allie (allieRun) where +module Allie (justFuckingDoSomething) where -foreign import ccall "allie_run" allieRun :: IO () +import Data.Word (Word8, Word16, Word32, Word64) +import Data.Int (Int8, Int16, Int32, Int64) +import Foreign.Ptr (Ptr, FunPtr, nullPtr, plusPtr, castPtr) +import Foreign.Marshal.Alloc (alloca) +import Foreign.Storable (Storable(..)) +import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef) +import qualified Data.Text +import Data.Text.Encoding (encodeUtf8) +import Data.ByteString (useAsCStringLen) + +data AliceOpaque +type Alice = Ptr AliceOpaque + +foreign import ccall "Alice_new" newAlice :: IO Alice + +data AliceAnotherFrameCap s = AliceAnotherFrameCap Alice + +foreign import ccall "wrapper" allieMkAliceOnWaylandKeyboardKey :: (Alice -> IO ()) -> IO (FunPtr (Alice -> IO ())) +foreign import ccall "wrapper" allieMkAliceOnAnotherFrame :: (Alice -> IO ()) -> IO (FunPtr (Alice -> IO ())) + +data Callbacks = Callbacks { + onWaylandKeyboardKey :: (Alice -> IO ()), + onAnotherFrame :: (forall s. AliceAnotherFrameCap s -> IO ()) + } + +instance Storable Callbacks where + sizeOf _ = 8 + 8 + alignment _ = 8 + peek _ = error "Зачем тебе?" + poke ptr Callbacks{..} = do + poke (castPtr ptr) =<< allieMkAliceOnWaylandKeyboardKey onWaylandKeyboardKey + poke (castPtr ptr `plusPtr` 8) =<< allieMkAliceOnAnotherFrame onAnotherFramePrepared where + onAnotherFramePrepared = (\alice -> onAnotherFrame (AliceAnotherFrameCap alice)) + +foreign import ccall "Alice_mainloop" allieAliceMainloop :: Alice -> Ptr Callbacks -> IO () + +aliceMainloop :: Alice -> Callbacks -> IO () +aliceMainloop alice cb = alloca $ \ptr -> do + poke ptr cb + allieAliceMainloop alice ptr + +-- These are only correct in another_frame_callback, actually +foreign import ccall "Alice_clear_screen_text" allieAliceClearScreenText :: Alice -> IO () + +aliceClearScreenTextLabel :: AliceAnotherFrameCap s -> IO () +aliceClearScreenTextLabel (AliceAnotherFrameCap alice) = allieAliceClearScreenText alice + +foreign import ccall "allie_Alice_add_screen_text_label" allieAliceAddScreenTextLabel :: Alice -> Ptr Word8 -> Word64 -> IO () + +aliceAddScreenTextLabel :: AliceAnotherFrameCap s -> String -> IO () +aliceAddScreenTextLabel (AliceAnotherFrameCap alice) str = useAsCStringLen (encodeUtf8 $ Data.Text.pack $ str) $ \(cstr, len) -> allieAliceAddScreenTextLabel alice (castPtr cstr) (fromIntegral len) + +-- Function to run the main loop with callbacks +justFuckingDoSomething :: IO () +justFuckingDoSomething = do + alice <- newAlice + state <- newIORef 67 + -- Create the Callbacks structure. + let callbacks = Callbacks myonKeyboardKey myonAnotherFrame where + myonKeyboardKey _ = do + old <- readIORef state + writeIORef state (old + 1) + putStrLn ("Doing" ++ show old ++ "this!") + myonAnotherFrame alicePerm = do + cur <- readIORef state + aliceClearScreenTextLabel alicePerm + aliceAddScreenTextLabel alicePerm ("Current value is = " ++ show cur) + + + -- Allocate space for the struct, poke it, and pass to C. + aliceMainloop alice callbacks diff --git a/src/l2/allie/allie.c b/src/l2/allie/allie.c index 2609e1b..c64f7f4 100644 --- a/src/l2/allie/allie.c +++ b/src/l2/allie/allie.c @@ -1,4 +1,3 @@ - #include "../alice/assets.h" #include "../anne/r4_models.h" // todo: this is very illegal, this is very-very illegal. Please, don't do this #include "../../l1/marie/geom_alg_utils.h" @@ -46,7 +45,7 @@ typedef struct { MargaretImg specular_texture; } GenericModelOnSceneMem; -#include "../../../gen/l1/eve/r0/VecGenericModelOnSceneMem.h" +#include "../../../gen/l1/eve/alice/VecGenericModelOnSceneMem.h" void GenericModelOnSceneMem_set(GenericModelOnSceneMem* self, size_t instance, GenericMeshInstanceInc uncomp){ assert(instance < self->instance_attr.count); @@ -70,7 +69,7 @@ typedef struct { PatriciaBuf instance_attr; } ShinyModelOnSceneMem; -#include "../../../gen/l1/eve/r0/VecShinyModelOnSceneMem.h" +#include "../../../gen/l1/eve/alice/VecShinyModelOnSceneMem.h" void ShinyModelOnSceneMem_set(ShinyModelOnSceneMem* self, size_t instance, ShinyMeshInstanceInc uncomp){ assert(instance < self->instance_attr.count); @@ -139,7 +138,7 @@ typedef struct { MargaretSubbuf device_local; } Pipeline0Transfer; -// Just for a test in r0 +// Just for a test in alice typedef struct { mat3 rotation; vec3 pos; @@ -147,7 +146,7 @@ typedef struct { vec3 color_on; } ObjectInfo; -#include "../../../gen/l1/eve/r0/VecObjectInfo.h" +#include "../../../gen/l1/eve/alice/VecObjectInfo.h" /* Non copyable */ typedef struct { @@ -831,10 +830,10 @@ typedef struct { VkFence in_flight_fence; // For miscellaneous uses (for init) VkFence roxy; -} Jane_r0; +} Jane_alice; -NODISCARD Jane_r0 Jane_r0_create(VkDevice device) { - return (Jane_r0){ +NODISCARD Jane_alice Jane_alice_create(VkDevice device) { + return (Jane_alice){ .in_frame_transfer_complete = margaret_create_semaphore(device), .image_available_semaphore = margaret_create_semaphore(device), .rendered_to_IT1_semaphore = margaret_create_semaphore(device), @@ -843,7 +842,7 @@ NODISCARD Jane_r0 Jane_r0_create(VkDevice device) { }; } -void Jane_r0_destroy(VkDevice device, Jane_r0 jane) { +void Jane_alice_destroy(VkDevice device, Jane_alice jane) { vkDestroySemaphore(device, jane.rendered_to_IT1_semaphore, NULL); vkDestroySemaphore(device, jane.image_available_semaphore, NULL); vkDestroySemaphore(device, jane.in_frame_transfer_complete, NULL); @@ -866,7 +865,7 @@ typedef struct { * Because I am to lazy to create two set layouts for generic model pipeline */ VkDescriptorSet p_0a_set_0; } GenericModelTexVulkPointers; -#include "../../../gen/l1/eve/r0/VecGenericModelTexVulkPointers.h" +#include "../../../gen/l1/eve/alice/VecGenericModelTexVulkPointers.h" void reset_and_record_command_buffer_0( VkCommandBuffer command_buffer, VkRenderPass render_pass_0, @@ -1038,7 +1037,60 @@ void record_copying_entire_scene_from_staging_to_device_local(VkCommandBuffer co } } +void alice_default_callback_on_wl_keyboard_key(){} + +void alice_default_callback_on_another_frame(){} + +typedef struct Alice Alice; + +typedef struct{ + void (*on_wl_keyboard_key)(Alice*); + void (*on_another_frame)(Alice*); +} AliceCallbacks; + +void AliceCallbacks_set_default(AliceCallbacks* self){ + self->on_another_frame = alice_default_callback_on_another_frame; + self->on_wl_keyboard_key = alice_default_callback_on_wl_keyboard_key; +} + typedef struct { + /* Memory settings */ + VkExtent2D sane_image_extent_limit; + /* Globals */ + struct wl_display *wl_display; + struct wl_registry *wl_registry; + struct wl_compositor *wl_compositor; + struct xdg_wm_base *xdg_wm_base; + struct wl_seat *wl_seat; + /* Objects */ + struct wl_surface *wl_surface; + struct wl_callback* wl_callback; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; + /* inputs */ + struct wl_pointer* pointer; + struct wl_keyboard* keyboard; + /* xkb */ + struct xkb_state* xkb_state; + struct xkb_context* xkb_context; + struct xkb_keymap* xkb_keymap; + /* app state */ + uint32_t last_frame_time; + int32_t width_heard; + int32_t height_heard; + int32_t width_confirmed; + int32_t height_confirmed; + bool closed; + bool first_0x80_keys[0x80]; + /* framerate counting */ + U32 frame_count_since_key; + margaret_ns_time prev_key_frame_time; +} AliceWaylandApp; + +struct Alice { + AliceCallbacks callbacks; + AliceWaylandApp wl; + MargaretInstanceAndItsDebug instance_and_debug; VkSurfaceKHR surface; VkPhysicalDevice physical_device; @@ -1068,7 +1120,7 @@ typedef struct { MargaretBufAllocator dev_local_buffers; MargaretBufAllocator staging_buffers; - Jane_r0 jane; // todo: figure out my own design + Jane_alice jane; // todo: figure out my own design MargaretSwapchainBundle swfb; SceneTemplate scene_template; @@ -1083,193 +1135,155 @@ typedef struct { RBTreeNodeLucyFaceFixedSize* font_face_of_size_40; LucyRenderer lucy_renderer; + // todo: move it to AliceGenericModelHand VecGenericModelTexVulkPointers generic_model_tex_vulk_pointers; VkImageView zbuffer_view; VkImageView IT1_view; VkFramebuffer IT1_framebuffer; VkDescriptorSet descriptor_set_for_pipeline_0b; VkDescriptorSet descriptor_set_for_pipeline_1; - // Descriptor sets for pipeline_0a are stored in generic_model_tex_vulk_pointers +}; -} vulkan_ctx_r0; - -typedef struct { - /* Memory settings */ - VkExtent2D sane_image_extent_limit; - /* Globals */ - struct wl_display *wl_display; - struct wl_registry *wl_registry; - struct wl_compositor *wl_compositor; - struct xdg_wm_base *xdg_wm_base; - struct wl_seat *wl_seat; - /* Objects */ - struct wl_surface *wl_surface; - struct wl_callback* wl_callback; - struct xdg_surface *xdg_surface; - struct xdg_toplevel *xdg_toplevel; - /* vulkan objects */ - vulkan_ctx_r0 vk; - /* inputs */ - struct wl_pointer* pointer; - struct wl_keyboard* keyboard; - /* xkb */ - struct xkb_state* xkb_state; - struct xkb_context* xkb_context; - struct xkb_keymap* xkb_keymap; - /* app state */ - uint32_t last_frame_time; - int32_t width_heard; - int32_t height_heard; - int32_t width_confirmed; - int32_t height_confirmed; - bool closed; - bool first_0x80_keys[0x80]; - /* framerate counting */ - U32 frame_count_since_key; - margaret_ns_time prev_key_frame_time; -} state_r0; - -void recreate_swapchain(state_r0 *state) { +void recreate_swapchain(Alice *alice) { // We are stopping program and rebuilding our sem+sem+fence synchronization mechanism - vkDeviceWaitIdle(state->vk.device); // todo: AAAAAAAAAAAAAAA this is all so so wrong AAAAAAAA - Jane_r0_destroy(state->vk.device, state->vk.jane); - state->vk.jane = Jane_r0_create(state->vk.device); + vkDeviceWaitIdle(alice->device); // todo: AAAAAAAAAAAAAAA this is all so so wrong AAAAAAAA + Jane_alice_destroy(alice->device, alice->jane); + alice->jane = Jane_alice_create(alice->device); VkSwapchainKHR old_swapchain = MargaretSwapchainBundle_pop_swapchain_drop_rest( - state->vk.device, state->vk.swfb); + alice->device, alice->swfb); // old swfb is 83% dropped - VkExtent2D extent = state->width_confirmed <= 0 || state->height_confirmed <= 0 ? - state->sane_image_extent_limit : (VkExtent2D){ state->width_confirmed, state->height_confirmed }; + VkExtent2D extent = alice->wl.width_confirmed <= 0 || alice->wl.height_confirmed <= 0 ? + alice->wl.sane_image_extent_limit : (VkExtent2D){ alice->wl.width_confirmed, alice->wl.height_confirmed }; ResultMargaretChosenSwapchainDetailsOrSpanU8 swapchain_details_res = margaret_choose_swapchain_details( - state->vk.physical_device, state->vk.surface, extent); + alice->physical_device, alice->surface, extent); if (swapchain_details_res.variant != Result_Ok) abortf("swapchain_details_res.variant != Result_Ok"); MargaretChosenSwapchainDetails swapchain_details = swapchain_details_res.ok; - MargaretSwapchainBundle new_swfb = MargaretSwapchainBundle_new(state->vk.device, state->vk.queue_fam, - swapchain_details, state->vk.surface, state->vk.render_pass_1, state->vk.swfb.swapchain); - vkDestroySwapchainKHR(state->vk.device, old_swapchain, NULL); + MargaretSwapchainBundle new_swfb = MargaretSwapchainBundle_new(alice->device, alice->queue_fam, + swapchain_details, alice->surface, alice->render_pass_1, alice->swfb.swapchain); + vkDestroySwapchainKHR(alice->device, old_swapchain, NULL); // Now old swfb is 100% dropped - state->vk.swfb = new_swfb; + alice->swfb = new_swfb; } -void update_state(state_r0* state, uint32_t dur) { +void update_state(Alice* alice, uint32_t dur) { float fl = (float)dur / 1000; - state->vk.scene.anim_time += fl; - if (state->first_0x80_keys[XKB_KEY_w]) - CamControlInfo_forward(&state->vk.scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_s]) - CamControlInfo_backward(&state->vk.scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_a]) - CamControlInfo_left(&state->vk.scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_d]) - CamControlInfo_right(&state->vk.scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_q]) - CamControlInfo_down(&state->vk.scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_e]) - CamControlInfo_up(&state->vk.scene.cam, fl); + alice->scene.anim_time += fl; + if (alice->wl.first_0x80_keys[XKB_KEY_w]) + CamControlInfo_forward(&alice->scene.cam, fl); + if (alice->wl.first_0x80_keys[XKB_KEY_s]) + CamControlInfo_backward(&alice->scene.cam, fl); + if (alice->wl.first_0x80_keys[XKB_KEY_a]) + CamControlInfo_left(&alice->scene.cam, fl); + if (alice->wl.first_0x80_keys[XKB_KEY_d]) + CamControlInfo_right(&alice->scene.cam, fl); + if (alice->wl.first_0x80_keys[XKB_KEY_q]) + CamControlInfo_down(&alice->scene.cam, fl); + if (alice->wl.first_0x80_keys[XKB_KEY_e]) + CamControlInfo_up(&alice->scene.cam, fl); - if (state->first_0x80_keys[XKB_KEY_bracketright]) { - for (size_t i = 0; i < state->vk.scene.smeshnyavka_3.len; i++) { - ObjectInfo* oi = &state->vk.scene.smeshnyavka_3.buf[i]; - vec3 p1 = state->vk.scene.cam.pos; + if (alice->wl.first_0x80_keys[XKB_KEY_bracketright]) { + for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) { + ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i]; + vec3 p1 = alice->scene.cam.pos; vec3 r = vec3_normalize(vec3_minus_vec3(p1, oi->pos)); oi->rotation = mat3_mul_mat3(marie_3d_rot_mat3(r, fl * 0.7f), oi->rotation); - Scene_update_smeshnyavka_3(&state->vk.scene, i); + Scene_update_smeshnyavka_3(&alice->scene, i); } } - if (state->first_0x80_keys[XKB_KEY_bracketleft]) { - for (size_t i = 0; i < state->vk.scene.smeshnyavka_1.len; i++) { - ObjectInfo* oi = &state->vk.scene.smeshnyavka_1.buf[i]; + if (alice->wl.first_0x80_keys[XKB_KEY_bracketleft]) { + for (size_t i = 0; i < alice->scene.smeshnyavka_1.len; i++) { + ObjectInfo* oi = &alice->scene.smeshnyavka_1.buf[i]; oi->rotation = mat3_mul_mat3(marie_3d_rot_mat3((vec3){0, 0, 1}, fl * 0.4f), oi->rotation); - Scene_update_smeshnyavka_1(&state->vk.scene, i); + Scene_update_smeshnyavka_1(&alice->scene, i); } } - if (state->first_0x80_keys[XKB_KEY_minus]) { - for (size_t i = 0; i < state->vk.scene.smeshnyavka_3.len; i++) { - ObjectInfo* oi = &state->vk.scene.smeshnyavka_3.buf[i]; - vec3 p1 = state->vk.scene.cam.pos; + if (alice->wl.first_0x80_keys[XKB_KEY_minus]) { + for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) { + ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i]; + vec3 p1 = alice->scene.cam.pos; float dist = vec3_length(vec3_minus_vec3(p1, oi->pos)); float fac = 80/dist; oi->scale *= (1 - 0.01f * fl * fac); - Scene_update_smeshnyavka_3(&state->vk.scene, i); + Scene_update_smeshnyavka_3(&alice->scene, i); } } - if (state->first_0x80_keys[XKB_KEY_equal]) { - for (size_t i = 0; i < state->vk.scene.smeshnyavka_3.len; i++) { - ObjectInfo* oi = &state->vk.scene.smeshnyavka_3.buf[i]; - vec3 p1 = state->vk.scene.cam.pos; + if (alice->wl.first_0x80_keys[XKB_KEY_equal]) { + for (size_t i = 0; i < alice->scene.smeshnyavka_3.len; i++) { + ObjectInfo* oi = &alice->scene.smeshnyavka_3.buf[i]; + vec3 p1 = alice->scene.cam.pos; float dist = vec3_length(vec3_minus_vec3(p1, oi->pos)); float fac = 80/dist; oi->scale *= (1 + 0.01f * fl * fac); - Scene_update_smeshnyavka_3(&state->vk.scene, i); + Scene_update_smeshnyavka_3(&alice->scene, i); } } { - GenericModelOnSceneMem* model = VecGenericModelOnSceneMem_mat(&state->vk.scene.generic_models, 0); + GenericModelOnSceneMem* model = VecGenericModelOnSceneMem_mat(&alice->scene.generic_models, 0); assert(model->instance_attr.count >= 1); - if (state->first_0x80_keys[XKB_KEY_j]) { - state->vk.scene.smeshnyavka_1.buf[0].pos.x -= fl; - Scene_update_smeshnyavka_1(&state->vk.scene, 0); + if (alice->wl.first_0x80_keys[XKB_KEY_j]) { + alice->scene.smeshnyavka_1.buf[0].pos.x -= fl; + Scene_update_smeshnyavka_1(&alice->scene, 0); } - if (state->first_0x80_keys[XKB_KEY_k]) { - state->vk.scene.smeshnyavka_1.buf[0].pos.z -= fl; - Scene_update_smeshnyavka_1(&state->vk.scene, 0); + if (alice->wl.first_0x80_keys[XKB_KEY_k]) { + alice->scene.smeshnyavka_1.buf[0].pos.z -= fl; + Scene_update_smeshnyavka_1(&alice->scene, 0); } - if (state->first_0x80_keys[XKB_KEY_l]) { - state->vk.scene.smeshnyavka_1.buf[0].pos.z += fl; - Scene_update_smeshnyavka_1(&state->vk.scene, 0); + if (alice->wl.first_0x80_keys[XKB_KEY_l]) { + alice->scene.smeshnyavka_1.buf[0].pos.z += fl; + Scene_update_smeshnyavka_1(&alice->scene, 0); } - if (state->first_0x80_keys[XKB_KEY_semicolon]) { - state->vk.scene.smeshnyavka_1.buf[0].pos.x += fl; - Scene_update_smeshnyavka_1(&state->vk.scene, 0); + if (alice->wl.first_0x80_keys[XKB_KEY_semicolon]) { + alice->scene.smeshnyavka_1.buf[0].pos.x += fl; + Scene_update_smeshnyavka_1(&alice->scene, 0); } } } /* It recreates image views, descriptor sets, framebuffers. */ -void recreate_vulkan_references_objects(state_r0* state){ - vulkan_ctx_r0* vk = &state->vk; - vk->zbuffer_view = margaret_create_view_for_image(vk->device, vk->zbuffer_image.a.image, - vk->zbuffer_format, VK_IMAGE_ASPECT_DEPTH_BIT); - vk->IT1_view = margaret_create_view_for_image(vk->device, vk->IT1_image.a.image, - vk->IT1_format, VK_IMAGE_ASPECT_COLOR_BIT); - vk->IT1_framebuffer = create_IT1_framebuffer(vk->device, - vk->IT1_view, vk->zbuffer_view, vk->render_pass_0, - state->sane_image_extent_limit.width, state->sane_image_extent_limit.height); +void recreate_vulkan_references_objects(Alice* alice){ + alice->zbuffer_view = margaret_create_view_for_image(alice->device, alice->zbuffer_image.a.image, + alice->zbuffer_format, VK_IMAGE_ASPECT_DEPTH_BIT); + alice->IT1_view = margaret_create_view_for_image(alice->device, alice->IT1_image.a.image, + alice->IT1_format, VK_IMAGE_ASPECT_COLOR_BIT); + alice->IT1_framebuffer = create_IT1_framebuffer(alice->device, + alice->IT1_view, alice->zbuffer_view, alice->render_pass_0, + alice->wl.sane_image_extent_limit.width, alice->wl.sane_image_extent_limit.height); /* Busy creating views for all my textures */ - vk->generic_model_tex_vulk_pointers = VecGenericModelTexVulkPointers_new_reserved(vk->scene.generic_models.len); - for (size_t i = 0; i < vk->scene.generic_models.len; i++) { - GenericModelOnSceneMem* model = &vk->scene.generic_models.buf[i]; + alice->generic_model_tex_vulk_pointers = VecGenericModelTexVulkPointers_new_reserved(alice->scene.generic_models.len); + for (size_t i = 0; i < alice->scene.generic_models.len; i++) { + GenericModelOnSceneMem* model = &alice->scene.generic_models.buf[i]; GenericModelTexVulkPointers P = (GenericModelTexVulkPointers){ - .diffuse_view = margaret_create_view_for_image(vk->device, model->diffuse_texture.a.image, + .diffuse_view = margaret_create_view_for_image(alice->device, model->diffuse_texture.a.image, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT), - .normal_view = margaret_create_view_for_image(vk->device, model->normal_texture.a.image, + .normal_view = margaret_create_view_for_image(alice->device, model->normal_texture.a.image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT), - .specular_view = margaret_create_view_for_image(vk->device, model->specular_texture.a.image, + .specular_view = margaret_create_view_for_image(alice->device, model->specular_texture.a.image, VK_FORMAT_R8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT), - .p_0a_set_0 = margaret_allocate_descriptor_set( vk->device, - vk->descriptor_pool, vk->pipeline_hands_0a.descriptor_set_layout), + .p_0a_set_0 = margaret_allocate_descriptor_set( alice->device, + alice->descriptor_pool, alice->pipeline_hands_0a.descriptor_set_layout), }; - VecGenericModelTexVulkPointers_append(&vk->generic_model_tex_vulk_pointers, P); + VecGenericModelTexVulkPointers_append(&alice->generic_model_tex_vulk_pointers, P); // Configuring my descriptor sets, that I just allocated // todo: create a separate function for that shit VkDescriptorBufferInfo buffer_info_for_descriptor_0_in_set_0a = { - .buffer = MargaretSubbuf_get_buffer(&vk->scene.pipeline0_ubo.device_local), - .offset = vk->scene.pipeline0_ubo.device_local.start, .range = sizeof(Pipeline0UBO), + .buffer = MargaretSubbuf_get_buffer(&alice->scene.pipeline0_ubo.device_local), + .offset = alice->scene.pipeline0_ubo.device_local.start, .range = sizeof(Pipeline0UBO), }; VkDescriptorImageInfo image_info_for_descriptor_1_in_set_0a = { - .sampler = vk->linear_sampler, .imageView = P.diffuse_view, + .sampler = alice->linear_sampler, .imageView = P.diffuse_view, .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, }; VkDescriptorImageInfo image_info_for_descriptor_2_in_set_0a = { - .sampler = vk->nearest_sampler, .imageView = P.normal_view, + .sampler = alice->nearest_sampler, .imageView = P.normal_view, .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, }; VkDescriptorImageInfo image_info_for_descriptor_3_in_set_0a = { - .sampler = vk->nearest_sampler, .imageView = P.specular_view, + .sampler = alice->nearest_sampler, .imageView = P.specular_view, .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, }; VkWriteDescriptorSet writes_in_descriptor_set[] = { @@ -1310,29 +1324,29 @@ void recreate_vulkan_references_objects(state_r0* state){ .pImageInfo = &image_info_for_descriptor_3_in_set_0a, }, }; - vkUpdateDescriptorSets(vk->device, ARRAY_SIZE(writes_in_descriptor_set), writes_in_descriptor_set, 0, NULL); + vkUpdateDescriptorSets(alice->device, ARRAY_SIZE(writes_in_descriptor_set), writes_in_descriptor_set, 0, NULL); } - vk->descriptor_set_for_pipeline_0b = margaret_allocate_descriptor_set( - vk->device, vk->descriptor_pool, vk->pipeline_hands_0b.descriptor_set_layout); - vk->descriptor_set_for_pipeline_1 = margaret_allocate_descriptor_set( - vk->device, vk->descriptor_pool, vk->pipeline_hands_1.descriptor_set_layout); + alice->descriptor_set_for_pipeline_0b = margaret_allocate_descriptor_set( + alice->device, alice->descriptor_pool, alice->pipeline_hands_0b.descriptor_set_layout); + alice->descriptor_set_for_pipeline_1 = margaret_allocate_descriptor_set( + alice->device, alice->descriptor_pool, alice->pipeline_hands_1.descriptor_set_layout); // todo: update the others + ACTUALLY CARRY OUT DEVIEL LOCAL ALLOCATION MARAGERReeuqs request // todo: separate set0 and set 1 VkDescriptorBufferInfo buffer_info_for_descriptor_0_in_set_0b = { - .buffer = MargaretSubbuf_get_buffer(&vk->scene.pipeline0_ubo.device_local), - .offset = vk->scene.pipeline0_ubo.device_local.start, .range = sizeof(Pipeline0UBO), + .buffer = MargaretSubbuf_get_buffer(&alice->scene.pipeline0_ubo.device_local), + .offset = alice->scene.pipeline0_ubo.device_local.start, .range = sizeof(Pipeline0UBO), }; VkDescriptorImageInfo image_info_for_descriptor_0_in_set_1 = { - .sampler = vk->nearest_sampler, .imageView = vk->IT1_view, + .sampler = alice->nearest_sampler, .imageView = alice->IT1_view, .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, }; VkWriteDescriptorSet writes_in_descriptor_sets[] = { { .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .dstSet = vk->descriptor_set_for_pipeline_0b, + .dstSet = alice->descriptor_set_for_pipeline_0b, .dstBinding = 0, .dstArrayElement = 0, .descriptorCount = 1, @@ -1342,7 +1356,7 @@ void recreate_vulkan_references_objects(state_r0* state){ { .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .dstSet = vk->descriptor_set_for_pipeline_1, + .dstSet = alice->descriptor_set_for_pipeline_1, .dstBinding = 0, .dstArrayElement = 0, .descriptorCount = 1, @@ -1350,12 +1364,12 @@ void recreate_vulkan_references_objects(state_r0* state){ .pImageInfo = &image_info_for_descriptor_0_in_set_1, }, }; - vkUpdateDescriptorSets(vk->device, ARRAY_SIZE(writes_in_descriptor_sets), writes_in_descriptor_sets, 0, NULL); + vkUpdateDescriptorSets(alice->device, ARRAY_SIZE(writes_in_descriptor_sets), writes_in_descriptor_sets, 0, NULL); } /* Needed for defragmentation of memory */ -void destroy_vulkan_reference_objects(state_r0* state){ - vulkan_ctx_r0* vk = &state->vk; +void destroy_vulkan_reference_objects(Alice* alice){ + // todo: vkdestro all the views all the framebuffers // todo: drop everything, } @@ -1399,137 +1413,142 @@ void Scene_swap_talking_buffers(Scene* scene){ } } -void vulkano_frame_drawing(state_r0* state) { - check(vkWaitForFences(state->vk.device, 1, &state->vk.jane.in_flight_fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS); - check(vkResetFences(state->vk.device, 1, &state->vk.jane.in_flight_fence) == VK_SUCCESS); +void alice_frame_drawing(Alice* alice) { + check(vkWaitForFences(alice->device, 1, &alice->jane.in_flight_fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS); + check(vkResetFences(alice->device, 1, &alice->jane.in_flight_fence) == VK_SUCCESS); uint32_t ij; VkResult aq_ret; and_again: aq_ret = vkAcquireNextImageKHR( - state->vk.device, state->vk.swfb.swapchain, - UINT64_MAX, state->vk.jane.image_available_semaphore, VK_NULL_HANDLE, &ij + alice->device, alice->swfb.swapchain, + UINT64_MAX, alice->jane.image_available_semaphore, VK_NULL_HANDLE, &ij ); if (aq_ret == VK_ERROR_OUT_OF_DATE_KHR || aq_ret == VK_SUBOPTIMAL_KHR) { fprintf(stderr, "vkAcquireNextImageKHR in { VK_ERROR_OUT_OF_DATE_KHR, VK_SUBOPTIMAL_KHR }\n"); - recreate_swapchain(state); + recreate_swapchain(alice); goto and_again; } else if (aq_ret != VK_SUCCESS) { abortf("vkAcquireNextImageKHR"); } - Scene_swap_talking_buffers(&state->vk.scene); + Scene_swap_talking_buffers(&alice->scene); - state->vk.scene.color = (VkClearColorValue){{0, 0.5f, 0.9f, 1}}; + alice->scene.color = (VkClearColorValue){{0, 0.5f, 0.9f, 1}}; mat4 projection_matrix = marie_perspective_projection_fov_mat4( - (float)state->width_confirmed, (float)state->height_confirmed, - state->vk.scene.cam.fov, 0.01f, 1000); - mat4 camera_rotation_matrix = marie_mat3_to_mat4_transposed(state->vk.scene.cam.cam_basis); - mat4 camera_translation_matrix = marie_translation_mat4(vec3_minus(state->vk.scene.cam.pos)); + (float)alice->wl.width_confirmed, (float)alice->wl.height_confirmed, + alice->scene.cam.fov, 0.01f, 1000); + mat4 camera_rotation_matrix = marie_mat3_to_mat4_transposed(alice->scene.cam.cam_basis); + mat4 camera_translation_matrix = marie_translation_mat4(vec3_minus(alice->scene.cam.pos)); mat4 t_mat = mat4_mul_mat4(projection_matrix, mat4_mul_mat4(camera_rotation_matrix, camera_translation_matrix)); - margaret_reset_and_begin_command_buffer(state->vk.transfer_command_buf); - record_copying_entire_scene_from_staging_to_device_local(state->vk.transfer_command_buf, &state->vk.scene); - LucyGlyphCache_another_frame(&state->vk.lucy_cache); - LucyRenderer_clear(&state->vk.lucy_renderer); - LucyRenderer_add_text(&state->vk.lucy_renderer, state->vk.font_face_of_size_40, (vec4){1, 0, 0, 1}, 0, - VecU8_to_span(&state->vk.scene.text_on_screen), (ivec2){10, 10}); - LucyRenderer_another_frame(&state->vk.lucy_renderer); - margaret_end_command_buffer(state->vk.transfer_command_buf); + alice->callbacks.on_another_frame(alice); + + margaret_reset_and_begin_command_buffer(alice->transfer_command_buf); + + // todo: replace vector with a list and start supporting handlers + record_copying_entire_scene_from_staging_to_device_local(alice->transfer_command_buf, &alice->scene); + + LucyGlyphCache_another_frame(&alice->lucy_cache); + // LucyRenderer_clear(&alice->lucy_renderer); + // LucyRenderer_add_text(&alice->lucy_renderer, alice->font_face_of_size_40, (vec4){1, 0, 0, 1}, 0, + // VecU8_to_span(&alice->scene.text_on_screen), (ivec2){10, 10}); + LucyRenderer_another_frame(&alice->lucy_renderer); + margaret_end_command_buffer(alice->transfer_command_buf); reset_and_record_command_buffer_0( - state->vk.rendering_command_buf_0, state->vk.render_pass_0, - &state->vk.pipeline_hands_0a, &state->vk.pipeline_hands_0b, - state->vk.IT1_framebuffer, state->vk.swfb.extent, - &state->vk.scene, - &state->vk.generic_model_tex_vulk_pointers, /* Needed just to get descriptor sets for generic models */ - state->vk.descriptor_set_for_pipeline_0b, - t_mat, state->vk.scene.cam.pos); + alice->rendering_command_buf_0, alice->render_pass_0, + &alice->pipeline_hands_0a, &alice->pipeline_hands_0b, + alice->IT1_framebuffer, alice->swfb.extent, + &alice->scene, + &alice->generic_model_tex_vulk_pointers, /* Needed just to get descriptor sets for generic models */ + alice->descriptor_set_for_pipeline_0b, + t_mat, alice->scene.cam.pos); - reset_and_record_command_buffer_1(state->vk.rendering_command_buf_1, state->vk.render_pass_1, - &state->vk.pipeline_hands_1, - *VecVkFramebuffer_at(&state->vk.swfb.framebuffers, ij), - state->vk.swfb.extent, - state->sane_image_extent_limit, &state->vk.scene, state->vk.descriptor_set_for_pipeline_1, - &state->vk.lucy_renderer); + reset_and_record_command_buffer_1(alice->rendering_command_buf_1, alice->render_pass_1, + &alice->pipeline_hands_1, + *VecVkFramebuffer_at(&alice->swfb.framebuffers, ij), + alice->swfb.extent, + alice->wl.sane_image_extent_limit, &alice->scene, alice->descriptor_set_for_pipeline_1, + &alice->lucy_renderer); - check(vkQueueSubmit(state->vk.queues.graphics_queue, 1, &(VkSubmitInfo){ + check(vkQueueSubmit(alice->queues.graphics_queue, 1, &(VkSubmitInfo){ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, - .pCommandBuffers = (VkCommandBuffer[]){ state->vk.transfer_command_buf }, + .pCommandBuffers = (VkCommandBuffer[]){ alice->transfer_command_buf }, .signalSemaphoreCount = 1, - .pSignalSemaphores = (VkSemaphore[]){ state->vk.jane.in_frame_transfer_complete }, + .pSignalSemaphores = (VkSemaphore[]){ alice->jane.in_frame_transfer_complete }, }, NULL) == VK_SUCCESS); - check(vkQueueSubmit(state->vk.queues.graphics_queue, 1, &(VkSubmitInfo){ + check(vkQueueSubmit(alice->queues.graphics_queue, 1, &(VkSubmitInfo){ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .waitSemaphoreCount = 1, - .pWaitSemaphores = (VkSemaphore[]){state->vk.jane.in_frame_transfer_complete}, + .pWaitSemaphores = (VkSemaphore[]){alice->jane.in_frame_transfer_complete}, .pWaitDstStageMask = (VkPipelineStageFlags[]){ VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT }, .commandBufferCount = 1, - .pCommandBuffers = (VkCommandBuffer[]){ state->vk.rendering_command_buf_0 }, + .pCommandBuffers = (VkCommandBuffer[]){ alice->rendering_command_buf_0 }, .signalSemaphoreCount = 1, - .pSignalSemaphores = (VkSemaphore[]){ state->vk.jane.rendered_to_IT1_semaphore }, + .pSignalSemaphores = (VkSemaphore[]){ alice->jane.rendered_to_IT1_semaphore }, }, NULL) == VK_SUCCESS); - check(vkQueueSubmit(state->vk.queues.graphics_queue, 1, &(VkSubmitInfo){ + check(vkQueueSubmit(alice->queues.graphics_queue, 1, &(VkSubmitInfo){ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .waitSemaphoreCount = 2, .pWaitSemaphores = (VkSemaphore[]){ - state->vk.jane.image_available_semaphore, state->vk.jane.rendered_to_IT1_semaphore }, + alice->jane.image_available_semaphore, alice->jane.rendered_to_IT1_semaphore }, .pWaitDstStageMask = (VkPipelineStageFlags[]){ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT }, .commandBufferCount = 1, - .pCommandBuffers = (VkCommandBuffer[]){ state->vk.rendering_command_buf_1 }, + .pCommandBuffers = (VkCommandBuffer[]){ alice->rendering_command_buf_1 }, .signalSemaphoreCount = 1, .pSignalSemaphores = (VkSemaphore[]){ - *VecVkSemaphore_at(&state->vk.swfb.rendering_finished_here_semaphores, ij) }, - }, state->vk.jane.in_flight_fence) == VK_SUCCESS); + *VecVkSemaphore_at(&alice->swfb.rendering_finished_here_semaphores, ij) }, + }, alice->jane.in_flight_fence) == VK_SUCCESS); VkPresentInfoKHR present_info = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1, .pWaitSemaphores = (VkSemaphore[]){ - *VecVkSemaphore_at(&state->vk.swfb.rendering_finished_here_semaphores, ij) }, + *VecVkSemaphore_at(&alice->swfb.rendering_finished_here_semaphores, ij) }, .swapchainCount = 1, - .pSwapchains = (VkSwapchainKHR[]){ state->vk.swfb.swapchain }, + .pSwapchains = (VkSwapchainKHR[]){ alice->swfb.swapchain }, .pImageIndices = (U32[]){ ij }, .pResults = NULL, }; - VkResult present_ret = vkQueuePresentKHR(state->vk.queues.presentation_queue, &present_info); + VkResult present_ret = vkQueuePresentKHR(alice->queues.presentation_queue, &present_info); if (present_ret == VK_ERROR_OUT_OF_DATE_KHR || present_ret == VK_SUBOPTIMAL_KHR) { fprintf(stderr, "vkQueuePresentKHR: VK_ERROR_OUT_OF_DATE_KHR or \n"); - check(vkWaitForFences(state->vk.device, 1, &state->vk.jane.in_flight_fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS); - check(vkResetFences(state->vk.device, 1, &state->vk.jane.in_flight_fence) == VK_SUCCESS); - recreate_swapchain(state); + check(vkWaitForFences(alice->device, 1, &alice->jane.in_flight_fence, VK_TRUE, UINT64_MAX) == VK_SUCCESS); + check(vkResetFences(alice->device, 1, &alice->jane.in_flight_fence) == VK_SUCCESS); + recreate_swapchain(alice); goto and_again; } else if (present_ret != VK_SUCCESS) { abortf("vkQueuePresentKHR"); } margaret_ns_time frame_B0 = margaret_clock_gettime_monotonic_raw(); - state->frame_count_since_key++; - if (margaret_ns_time_sec_diff(state->prev_key_frame_time, frame_B0) > 1.0) { - float fps = (float)state->frame_count_since_key / margaret_ns_time_sec_diff(state->prev_key_frame_time, frame_B0); + alice->wl.frame_count_since_key++; + if (margaret_ns_time_sec_diff(alice->wl.prev_key_frame_time, frame_B0) > 1.0) { + float fps = (float)alice->wl.frame_count_since_key / margaret_ns_time_sec_diff(alice->wl.prev_key_frame_time, frame_B0); printf("FPS: %0.1lf\n", fps); - state->frame_count_since_key = 0; - state->prev_key_frame_time = frame_B0; + alice->wl.frame_count_since_key = 0; + alice->wl.prev_key_frame_time = frame_B0; } } static void main_h_xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial){ - state_r0 *state = data; - printf("XDG surface configured! (%d %d)\n", state->width_heard, state->height_heard); - state->width_confirmed = state->width_heard; - state->height_confirmed = state->height_heard; + Alice* alice = data; + printf("XDG surface configured! (%d %d)\n", alice->wl.width_heard, alice->wl.height_heard); + alice->wl.width_confirmed = alice->wl.width_heard; + alice->wl.height_confirmed = alice->wl.height_heard; xdg_surface_ack_configure(xdg_surface, serial); // todo: omg, I need to fix this crap for real, like, this is all so wrong - recreate_swapchain(state); - vulkano_frame_drawing(state); + recreate_swapchain(alice); + alice_frame_drawing(alice); } static const struct xdg_surface_listener xdg_surface_listener = { @@ -1539,7 +1558,7 @@ static const struct xdg_surface_listener xdg_surface_listener = { static void main_h_xdg_toplevel_configure( void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states ){ - state_r0 *state = data; + Alice* alice = data; uint32_t *conf_state; wl_array_for_each(conf_state, states) { printf("A state of xdg toplevel: %u\n", *conf_state); @@ -1547,13 +1566,13 @@ static void main_h_xdg_toplevel_configure( printf("XDG toplevel configured to (%d %d)\n", width, height); if (width <= 0 || height <= 0) return; - state->width_heard = width; - state->height_heard = height; + alice->wl.width_heard = width; + alice->wl.height_heard = height; } static void main_h_xdg_toplevel_close(void *data, struct xdg_toplevel *toplevel){ - state_r0 *state = data; - state->closed = true; + Alice* alice = data; + alice->wl.closed = true; } static const struct xdg_toplevel_listener main_h_xdg_toplevel_listener = { @@ -1574,81 +1593,82 @@ static const struct xdg_wm_base_listener main_h_xdg_wm_base_listener = { static void main_h_wl_keyboard_keymap( void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size ) { - state_r0* state = data; + Alice* alice = data; if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) abortf("O_o"); char *map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (map_shm == MAP_FAILED) abortf("Couldn't mmap new keymap ha-ha\n"); - xkb_keymap_unref(state->xkb_keymap); - xkb_state_unref(state->xkb_state); - state->xkb_keymap = xkb_keymap_new_from_string( - state->xkb_context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); + xkb_keymap_unref(alice->wl.xkb_keymap); + xkb_state_unref(alice->wl.xkb_state); + alice->wl.xkb_keymap = xkb_keymap_new_from_string( + alice->wl.xkb_context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(map_shm, size); close(fd); - state->xkb_state = xkb_state_new(state->xkb_keymap); + alice->wl.xkb_state = xkb_state_new(alice->wl.xkb_keymap); printf("Keymap changed!\n"); - memset(&state->first_0x80_keys, 0, sizeof(state->first_0x80_keys)); + memset(&alice->wl.first_0x80_keys, 0, sizeof(alice->wl.first_0x80_keys)); } static void main_h_wl_keyboard_enter( void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys ) { - state_r0* state = data; + Alice* alice = data; printf("keyboard enter; keys pressed are:\n"); uint32_t *key; wl_array_for_each(key, keys) { uint32_t actual_key = *key + 8; - xkb_keysym_t sym = xkb_state_key_get_one_sym(state->xkb_state, actual_key); + xkb_keysym_t sym = xkb_state_key_get_one_sym(alice->wl.xkb_state, actual_key); if (sym < 0x80) - state->first_0x80_keys[sym] = true; + alice->wl.first_0x80_keys[sym] = true; } } static void main_h_wl_keyboard_leave( void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface ) { - state_r0* state = data; - memset(&state->first_0x80_keys, 0, sizeof(state->first_0x80_keys)); + Alice* alice = data; + memset(&alice->wl.first_0x80_keys, 0, sizeof(alice->wl.first_0x80_keys)); } static void main_h_wl_keyboard_key( void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t key_action ) { - state_r0* state = data; + Alice* alice = data; uint32_t actual_key = key + 8; /* It actually could be nokey keysym. You never know without checking */ - xkb_keysym_t keysym = xkb_state_key_get_one_sym(state->xkb_state, actual_key); + xkb_keysym_t keysym = xkb_state_key_get_one_sym(alice->wl.xkb_state, actual_key); if (keysym < 0x80 && key_action == WL_KEYBOARD_KEY_STATE_RELEASED) { - state->first_0x80_keys[keysym] = false; + alice->wl.first_0x80_keys[keysym] = false; } else if (keysym < 0x80 && key_action == WL_KEYBOARD_KEY_STATE_PRESSED) { - state->first_0x80_keys[keysym] = true; + alice->wl.first_0x80_keys[keysym] = true; } + alice->callbacks.on_wl_keyboard_key(alice); if (key_action == WL_KEYBOARD_KEY_STATE_RELEASED) { if (keysym == XKB_KEY_1) { - vec3 p = state->vk.scene.cam.pos; + vec3 p = alice->scene.cam.pos; p.y += 1.5f; - ShinyModelOnSceneMem* model = VecShinyModelOnSceneMem_mat(&state->vk.scene.shiny_models, 0); + ShinyModelOnSceneMem* model = VecShinyModelOnSceneMem_mat(&alice->scene.shiny_models, 0); assert(model->instance_attr.count >= 1); - VecObjectInfo_mat(&state->vk.scene.smeshnyavka_3, 0)->pos = p; - Scene_update_smeshnyavka_3(&state->vk.scene, 0); + VecObjectInfo_mat(&alice->scene.smeshnyavka_3, 0)->pos = p; + Scene_update_smeshnyavka_3(&alice->scene, 0); - Pipeline0UBO* ubo = (Pipeline0UBO*)MargaretSubbuf_get_mapped(&state->vk.scene.pipeline0_ubo.staging_updatable); + Pipeline0UBO* ubo = (Pipeline0UBO*)MargaretSubbuf_get_mapped(&alice->scene.pipeline0_ubo.staging_updatable); assert(ubo->point_light_count >= 1); ubo->point_light_arr[0].pos = p; printf("Point light source pos set to %f %f %f\n", p.x, p.y, p.z); } else if (keysym == XKB_KEY_2) { - state->vk.scene.hdr_factor /= 1.05f; - printf("hdr factor decreased to %f\n", state->vk.scene.hdr_factor); + alice->scene.hdr_factor /= 1.05f; + printf("hdr factor decreased to %f\n", alice->scene.hdr_factor); } else if (keysym == XKB_KEY_3) { - state->vk.scene.hdr_factor *= 1.05f; - printf("hdr factor increased to %f\n", state->vk.scene.hdr_factor); + alice->scene.hdr_factor *= 1.05f; + printf("hdr factor increased to %f\n", alice->scene.hdr_factor); } else if (keysym == XKB_KEY_7) { - VecU8_append(&state->vk.scene.text_on_screen, '7'); + VecU8_append(&alice->scene.text_on_screen, '7'); } else if (keysym == XKB_KEY_Return) { - VecU8_append(&state->vk.scene.text_on_screen, '\n'); + VecU8_append(&alice->scene.text_on_screen, '\n'); } } } @@ -1657,8 +1677,8 @@ static void main_h_wl_keyboard_modifiers( void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group ) { - state_r0* state = data; - xkb_state_update_mask(state->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + Alice* alice = data; + xkb_state_update_mask(alice->wl.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); } static void main_h_wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay){ @@ -1679,38 +1699,36 @@ static void main_h_wl_pointer_enter( void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y ) { - state_r0 *state = data; } static void main_h_wl_pointer_leave( void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface ) { - state_r0 *state = data; } static void main_h_wl_pointer_motion( void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y ) { - state_r0 *state = data; - CamControlInfo_update_direction(&state->vk.scene.cam, - state->width_confirmed, state->height_confirmed, + Alice* alice = data; + CamControlInfo_update_direction(&alice->scene.cam, + alice->wl.width_confirmed, alice->wl.height_confirmed, (float)surface_x / 256.f, (float)surface_y / 256.f); } static void main_h_wl_pointer_button( void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t btn_action ) { - state_r0 *state = data; + Alice* alice = data; } static void main_h_wl_pointer_axis( void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value ) { - state_r0 *state = data; + Alice* alice = data; } static void main_h_wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { - state_r0 *state = data; + Alice* alice = data; } const struct wl_pointer_listener main_h_wl_pointer_listener = { @@ -1723,18 +1741,18 @@ const struct wl_pointer_listener main_h_wl_pointer_listener = { }; static void main_h_wl_seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities) { - state_r0* state = data; + Alice* alice = data; if (capabilities & WL_SEAT_CAPABILITY_POINTER) { - state->pointer = wl_seat_get_pointer(wl_seat); - if (!state->pointer) + alice->wl.pointer = wl_seat_get_pointer(wl_seat); + if (!alice->wl.pointer) abortf("wl_seat_get_pointer\n"); - wl_pointer_add_listener(state->pointer, &main_h_wl_pointer_listener, state); + wl_pointer_add_listener(alice->wl.pointer, &main_h_wl_pointer_listener, alice); } if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { - state->keyboard = wl_seat_get_keyboard(wl_seat); - if (!state->keyboard) + alice->wl.keyboard = wl_seat_get_keyboard(wl_seat); + if (!alice->wl.keyboard) abortf("wl_seat_get_keyboard\n"); - wl_keyboard_add_listener(state->keyboard, &main_h_wl_keyboard_listener, state); + wl_keyboard_add_listener(alice->wl.keyboard, &main_h_wl_keyboard_listener, alice); } } @@ -1750,25 +1768,25 @@ static const struct wl_seat_listener main_h_wl_seat_listener = { static void main_h_wl_registry_global( void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version ) { - state_r0 *state = data; + Alice* alice = data; if (strcmp(interface, wl_compositor_interface.name) == 0) { - state->wl_compositor = wl_registry_bind(wl_registry, name, &wl_compositor_interface, 4); - if (!state->wl_compositor) + alice->wl.wl_compositor = wl_registry_bind(wl_registry, name, &wl_compositor_interface, 4); + if (!alice->wl.wl_compositor) abortf("wl_registry_bind\n"); } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { - state->xdg_wm_base = wl_registry_bind(wl_registry, name, &xdg_wm_base_interface, 1); - if (!state->xdg_wm_base) + alice->wl.xdg_wm_base = wl_registry_bind(wl_registry, name, &xdg_wm_base_interface, 1); + if (!alice->wl.xdg_wm_base) abortf("wl_registry_bind\n"); - xdg_wm_base_add_listener(state->xdg_wm_base, &main_h_xdg_wm_base_listener, state); + xdg_wm_base_add_listener(alice->wl.xdg_wm_base, &main_h_xdg_wm_base_listener, alice); } else if (strcmp(interface, wl_seat_interface.name) == 0) { - if (state->wl_seat) { + if (alice->wl.wl_seat) { printf("We got second seat, but we only need one\n"); return; } - state->wl_seat = wl_registry_bind(wl_registry, name, &wl_seat_interface, 4); - if (!state->wl_seat) + alice->wl.wl_seat = wl_registry_bind(wl_registry, name, &wl_seat_interface, 4); + if (!alice->wl.wl_seat) abortf("wl_registry_bind\n"); - wl_seat_add_listener(state->wl_seat, &main_h_wl_seat_listener, state); + wl_seat_add_listener(alice->wl.wl_seat, &main_h_wl_seat_listener, alice); } } @@ -1784,131 +1802,131 @@ static const struct wl_registry_listener main_h_wl_registry_listener = { static const struct wl_callback_listener main_h_wl_surface_frame_listener; static void main_h_wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time){ - state_r0 *state = data; + Alice* alice = data; wl_callback_destroy(cb); - state->wl_callback = wl_surface_frame(state->wl_surface); - if (!state->wl_callback) + alice->wl.wl_callback = wl_surface_frame(alice->wl.wl_surface); + if (!alice->wl.wl_callback) abortf("wl_surface_frame\n"); - wl_callback_add_listener(state->wl_callback, &main_h_wl_surface_frame_listener, state); + wl_callback_add_listener(alice->wl.wl_callback, &main_h_wl_surface_frame_listener, alice); - if (state->last_frame_time != 0) { - update_state(state, time - state->last_frame_time); + if (alice->wl.last_frame_time != 0) { + update_state(alice, time - alice->wl.last_frame_time); } - vulkano_frame_drawing(state); - state->last_frame_time = time; + alice_frame_drawing(alice); + alice->wl.last_frame_time = time; } static const struct wl_callback_listener main_h_wl_surface_frame_listener = { .done = main_h_wl_surface_frame_done, }; -void allie_run() { +Alice* Alice_new(){ + Alice* alice = malloc(sizeof(Alice)); SpanU8 root_dir = cstr("."); SpanU8 GPU = cstr("nvidia"); SpanU8 bugged_GPU = cstr("nothere"); bool ENABLE_VALIDATION_LAYERS = true; const U32 MAX_WIN_WIDTH = 1920; const U32 MAX_WIN_HEIGHT = 1080; + AliceCallbacks_set_default(&alice->callbacks); - state_r0 state = {0}; - state.sane_image_extent_limit = (VkExtent2D){MAX_WIN_WIDTH, MAX_WIN_HEIGHT}; - vulkan_ctx_r0 *vk = &state.vk; + alice->wl.sane_image_extent_limit = (VkExtent2D){MAX_WIN_WIDTH, MAX_WIN_HEIGHT}; - state.wl_display = wl_display_connect(NULL); - if (!state.wl_display) + alice->wl.wl_display = wl_display_connect(NULL); + if (!alice->wl.wl_display) abortf("Could not connect"); - state.wl_registry = wl_display_get_registry(state.wl_display); - if (!state.wl_registry) + alice->wl.wl_registry = wl_display_get_registry(alice->wl.wl_display); + if (!alice->wl.wl_registry) abortf("wl_display_get_registry"); - wl_registry_add_listener(state.wl_registry, &main_h_wl_registry_listener, &state); - wl_display_roundtrip(state.wl_display); - if (!state.wl_compositor) + wl_registry_add_listener(alice->wl.wl_registry, &main_h_wl_registry_listener, alice); + wl_display_roundtrip(alice->wl.wl_display); + if (!alice->wl.wl_compositor) abortf("No wl_compositor"); - if (!state.xdg_wm_base) + if (!alice->wl.xdg_wm_base) abortf("No xdg_wm_base"); - state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - if (!state.xkb_context) + alice->wl.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + if (!alice->wl.xkb_context) abortf("xkb_context_new\n"); - state.wl_surface = wl_compositor_create_surface(state.wl_compositor); - if (!state.wl_surface) + alice->wl.wl_surface = wl_compositor_create_surface(alice->wl.wl_compositor); + if (!alice->wl.wl_surface) abortf("wl_compositor_create_surface\n"); - state.xdg_surface = xdg_wm_base_get_xdg_surface( - state.xdg_wm_base, state.wl_surface); - if (!state.xdg_surface) + alice->wl.xdg_surface = xdg_wm_base_get_xdg_surface( + alice->wl.xdg_wm_base, alice->wl.wl_surface); + if (!alice->wl.xdg_surface) abortf("xdg_wm_base_get_xdg_surface\n"); - xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state); - state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface); - if (!state.xdg_toplevel) + xdg_surface_add_listener(alice->wl.xdg_surface, &xdg_surface_listener, alice); + alice->wl.xdg_toplevel = xdg_surface_get_toplevel(alice->wl.xdg_surface); + if (!alice->wl.xdg_toplevel) abortf("xdg_surface_get_toplevel\n"); - xdg_toplevel_add_listener(state.xdg_toplevel, &main_h_xdg_toplevel_listener, &state); - xdg_toplevel_set_title(state.xdg_toplevel, "r3"); - xdg_toplevel_set_app_id(state.xdg_toplevel, "r3"); - wl_surface_commit(state.wl_surface); + xdg_toplevel_add_listener(alice->wl.xdg_toplevel, &main_h_xdg_toplevel_listener, alice); + xdg_toplevel_set_title(alice->wl.xdg_toplevel, "r3"); + xdg_toplevel_set_app_id(alice->wl.xdg_toplevel, "r3"); + wl_surface_commit(alice->wl.wl_surface); - state.wl_callback = wl_surface_frame(state.wl_surface); - if (!state.wl_callback) + alice->wl.wl_callback = wl_surface_frame(alice->wl.wl_surface); + if (!alice->wl.wl_callback) abortf("wl_surface_frame\n"); - wl_callback_add_listener(state.wl_callback, &main_h_wl_surface_frame_listener, &state); + wl_callback_add_listener(alice->wl.wl_callback, &main_h_wl_surface_frame_listener, alice); - vk->instance_and_debug = MargaretInstanceAndItsDebug_new(ENABLE_VALIDATION_LAYERS); - VkInstance instance = vk->instance_and_debug.instance; + alice->instance_and_debug = MargaretInstanceAndItsDebug_new(ENABLE_VALIDATION_LAYERS); + VkInstance instance = alice->instance_and_debug.instance; // print_instance_available_extensions(instance); // print_instance_available_layers(instance); - vk->surface = margaret_create_surface(instance, state.wl_display, state.wl_surface); + alice->surface = margaret_create_surface(instance, alice->wl.wl_display, alice->wl.wl_surface); - vk->physical_device = margaret_select_one_physical_device( - instance, vk->surface, GPU, bugged_GPU, state.sane_image_extent_limit); + alice->physical_device = margaret_select_one_physical_device( + instance, alice->surface, GPU, bugged_GPU, alice->wl.sane_image_extent_limit); // print_physical_device_available_extensions(physical_device); ResultMargaretChosenQueueFamiliesOrSpanU8 queue_fam_res = margaret_choose_good_queue_families( - vk->physical_device, vk->surface); + alice->physical_device, alice->surface); if (queue_fam_res.variant != Result_Ok) abortf("queue_fam_res.variant != Result_Ok"); - vk->queue_fam = queue_fam_res.ok; + alice->queue_fam = queue_fam_res.ok; - vk->device = margaret_create_logical_device(vk->physical_device, vk->queue_fam); + alice->device = margaret_create_logical_device(alice->physical_device, alice->queue_fam); - vkGetDeviceQueue(vk->device, vk->queue_fam.for_graphics, 0, &vk->queues.graphics_queue); - vkGetDeviceQueue(vk->device, vk->queue_fam.for_presentation, 0, &vk->queues.presentation_queue); + vkGetDeviceQueue(alice->device, alice->queue_fam.for_graphics, 0, &alice->queues.graphics_queue); + vkGetDeviceQueue(alice->device, alice->queue_fam.for_presentation, 0, &alice->queues.presentation_queue); ResultMargaretChosenSwapchainDetailsOrSpanU8 swapchain_details_res = margaret_choose_swapchain_details( - vk->physical_device, vk->surface, state.sane_image_extent_limit); + alice->physical_device, alice->surface, alice->wl.sane_image_extent_limit); if (swapchain_details_res.variant != Result_Ok) abortf("swapchain_details_res.variant != Result_Ok"); - OptionVkFormat zbuffer_format_found = margaret_find_supported_zbuffer_format(vk->physical_device); - vk->zbuffer_format = OptionVkFormat_expect(zbuffer_format_found); - OptionVkFormat IT1_format_found = margaret_find_supported_hdr_buffer_format(vk->physical_device); - vk->IT1_format = OptionVkFormat_expect(IT1_format_found); + OptionVkFormat zbuffer_format_found = margaret_find_supported_zbuffer_format(alice->physical_device); + alice->zbuffer_format = OptionVkFormat_expect(zbuffer_format_found); + OptionVkFormat IT1_format_found = margaret_find_supported_hdr_buffer_format(alice->physical_device); + alice->IT1_format = OptionVkFormat_expect(IT1_format_found); - vk->render_pass_0 = create_render_pass_0(vk->device, vk->IT1_format, vk->zbuffer_format); - vk->pipeline_hands_0a = create_graphics_pipeline_0(vk->device, root_dir, vk->render_pass_0, 0); - vk->pipeline_hands_0b = create_graphics_pipeline_0_b(vk->device, root_dir, vk->render_pass_0, 0); + alice->render_pass_0 = create_render_pass_0(alice->device, alice->IT1_format, alice->zbuffer_format); + alice->pipeline_hands_0a = create_graphics_pipeline_0(alice->device, root_dir, alice->render_pass_0, 0); + alice->pipeline_hands_0b = create_graphics_pipeline_0_b(alice->device, root_dir, alice->render_pass_0, 0); - vk->render_pass_1 = create_render_pass_1(vk->device, swapchain_details_res.ok.surface_format.format); - vk->pipeline_hands_1 = create_graphics_pipeline_1(vk->device, root_dir, vk->render_pass_1, 0); + alice->render_pass_1 = create_render_pass_1(alice->device, swapchain_details_res.ok.surface_format.format); + alice->pipeline_hands_1 = create_graphics_pipeline_1(alice->device, root_dir, alice->render_pass_1, 0); // These samplers are global for a lot of my future textures - vk->linear_sampler = margaret_create_sampler(vk->physical_device, vk->device, true); - vk->nearest_sampler = margaret_create_sampler(vk->physical_device, vk->device, false); + alice->linear_sampler = margaret_create_sampler(alice->physical_device, alice->device, true); + alice->nearest_sampler = margaret_create_sampler(alice->physical_device, alice->device, false); - vk->command_pool = margaret_create_resettable_command_pool(vk->device, vk->queue_fam.for_graphics); - vk->rendering_command_buf_0 = margaret_allocate_command_buffer(vk->device, vk->command_pool); - vk->rendering_command_buf_1 = margaret_allocate_command_buffer(vk->device, vk->command_pool); - vk->transfer_command_buf = margaret_allocate_command_buffer(vk->device, vk->command_pool); - vk->device_local_mem_mv_command_buf = margaret_allocate_command_buffer(vk->device, vk->command_pool); + alice->command_pool = margaret_create_resettable_command_pool(alice->device, alice->queue_fam.for_graphics); + alice->rendering_command_buf_0 = margaret_allocate_command_buffer(alice->device, alice->command_pool); + alice->rendering_command_buf_1 = margaret_allocate_command_buffer(alice->device, alice->command_pool); + alice->transfer_command_buf = margaret_allocate_command_buffer(alice->device, alice->command_pool); + alice->device_local_mem_mv_command_buf = margaret_allocate_command_buffer(alice->device, alice->command_pool); // todo: git rid of this line. Rn it won't even be used, like, at all... I won't actually use it in my test, yes, I am not a psyco - vk->host_visible_mem_mv_command_buf = margaret_allocate_command_buffer(vk->device, vk->command_pool); + alice->host_visible_mem_mv_command_buf = margaret_allocate_command_buffer(alice->device, alice->command_pool); // todo: write a descriptor set allocator (in Margaret) that manages synamic descript or pool allocatrinonsasdasdasd - vk->descriptor_pool = margaret_create_descriptor_set_pool(vk->device, 100, 100, 100); + alice->descriptor_pool = margaret_create_descriptor_set_pool(alice->device, 100, 100, 100); /* Here we search physical device memory types for the one with host-visible flag and the other with device-local flag */ VkPhysicalDeviceMemoryProperties mem_properties; - vkGetPhysicalDeviceMemoryProperties(vk->physical_device, &mem_properties); + vkGetPhysicalDeviceMemoryProperties(alice->physical_device, &mem_properties); const VkMemoryPropertyFlags host_visible_coherent = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; const VkMemoryPropertyFlags device_local = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; int mem_type_id_host_visible_coherent = -1; @@ -1932,163 +1950,163 @@ void allie_run() { abortf("Can't find device local memory\n"); } - vk->staging_buffers = MargaretBufAllocator_new(vk->device, vk->physical_device, + alice->staging_buffers = MargaretBufAllocator_new(alice->device, alice->physical_device, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, mem_type_id_host_visible_coherent, 3, true, 16); // todo: inquire about the uniform buffer alignment and storage buffer alignment - vk->dev_local_buffers = MargaretBufAllocator_new(vk->device, vk->physical_device, + alice->dev_local_buffers = MargaretBufAllocator_new(alice->device, alice->physical_device, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT /* | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT */, mem_type_id_device_local, 6, false, 16); - vk->dev_local_images = MargaretImgAllocator_new(vk->device, vk->physical_device, + alice->dev_local_images = MargaretImgAllocator_new(alice->device, alice->physical_device, mem_type_id_device_local, 16); - vk->jane = Jane_r0_create(vk->device); + alice->jane = Jane_alice_create(alice->device); /* Luckily, swapchain image allocation is not managed by me */ - vk->swfb = MargaretSwapchainBundle_new( - vk->device, vk->queue_fam, swapchain_details_res.ok, - vk->surface, vk->render_pass_1, NULL); + alice->swfb = MargaretSwapchainBundle_new( + alice->device, alice->queue_fam, swapchain_details_res.ok, + alice->surface, alice->render_pass_1, NULL); - vk->scene_template = (SceneTemplate){ + alice->scene_template = (SceneTemplate){ .generic_models = VecGenericMeshInSceneTemplate_new(), .shiny_models = VecShinyMeshTopology_new() }; - VecGenericMeshInSceneTemplate_append(&vk->scene_template.generic_models, + VecGenericMeshInSceneTemplate_append(&alice->scene_template.generic_models, GenericMeshInSceneTemplate_for_log(root_dir, 10, 2, 6)); - VecShinyMeshTopology_append(&vk->scene_template.shiny_models, generate_shiny_cube(0.3f)); + VecShinyMeshTopology_append(&alice->scene_template.shiny_models, generate_shiny_cube(0.3f)); VecGenericModelOnSceneMem generic_model_mem = VecGenericModelOnSceneMem_new(); VecShinyModelOnSceneMem shiny_model_mem = VecShinyModelOnSceneMem_new(); - for (size_t i = 0; i < vk->scene_template.generic_models.len; i++) { - const GenericMeshInSceneTemplate* template = &vk->scene_template.generic_models.buf[i]; + for (size_t i = 0; i < alice->scene_template.generic_models.len; i++) { + const GenericMeshInSceneTemplate* template = &alice->scene_template.generic_models.buf[i]; GenericModelOnSceneMem mem; mem.indexes = template->topology.indexes.len; mem.instance_attr.cap = 100; // todo: patricia method should manage this, not me - mem.instance_attr.staging_busy = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.instance_attr.staging_busy = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.instance_attr.cap * sizeof(GenericMeshInstance)); - mem.instance_attr.staging_updatable = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.instance_attr.staging_updatable = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.instance_attr.cap * sizeof(GenericMeshInstance)); - mem.instance_attr.device_local = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.instance_attr.device_local = MargaretBufAllocator_alloc(&alice->dev_local_buffers, mem.instance_attr.cap * sizeof(GenericMeshInstance)); mem.instance_attr.count = 0; - mem.staging_vbo = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_vbo = MargaretBufAllocator_alloc(&alice->staging_buffers, template->topology.vertices.len * sizeof(GenericMeshVertex)); - mem.staging_ebo = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_ebo = MargaretBufAllocator_alloc(&alice->staging_buffers, template->topology.indexes.len * sizeof(U32)); mem.pixels_diffuse = TextureDataR8G8B8A8_read_from_png_nofail(VecU8_to_span(&template->diffuse_texture_path)), mem.pixels_normal = TextureDataR8G8B8A8_read_from_png_nofail(VecU8_to_span(&template->normal_texture_path)), mem.pixels_specular = TextureDataR8_read_from_png_nofail(VecU8_to_span(&template->specular_texture_path)), - mem.staging_diffuse_tex_buf = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_diffuse_tex_buf = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.pixels_diffuse.pixels.len * sizeof(cvec4)); - mem.staging_normal_tex_buf = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_normal_tex_buf = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.pixels_normal.pixels.len * sizeof(cvec4)); - mem.staging_specular_tex_buf = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_specular_tex_buf = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.pixels_specular.pixels.len * sizeof(U8)); - mem.vbo = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.vbo = MargaretBufAllocator_alloc(&alice->dev_local_buffers, template->topology.vertices.len * sizeof(GenericMeshVertex)); - mem.ebo = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.ebo = MargaretBufAllocator_alloc(&alice->dev_local_buffers, template->topology.indexes.len * sizeof(U32)); - mem.diffuse_texture = MargaretImgAllocator_alloc(&vk->dev_local_images, + mem.diffuse_texture = MargaretImgAllocator_alloc(&alice->dev_local_images, mem.pixels_diffuse.width, mem.pixels_diffuse.height, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); - mem.normal_texture = MargaretImgAllocator_alloc(&vk->dev_local_images, + mem.normal_texture = MargaretImgAllocator_alloc(&alice->dev_local_images, mem.pixels_normal.width, mem.pixels_normal.height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); - mem.specular_texture = MargaretImgAllocator_alloc(&vk->dev_local_images, + mem.specular_texture = MargaretImgAllocator_alloc(&alice->dev_local_images, mem.pixels_specular.width, mem.pixels_specular.height, VK_FORMAT_R8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT); VecGenericModelOnSceneMem_append(&generic_model_mem, mem); } - for (size_t i = 0; i < vk->scene_template.shiny_models.len; i++) { - const ShinyMeshTopology* temp_topology = &vk->scene_template.shiny_models.buf[i]; + for (size_t i = 0; i < alice->scene_template.shiny_models.len; i++) { + const ShinyMeshTopology* temp_topology = &alice->scene_template.shiny_models.buf[i]; ShinyModelOnSceneMem mem; mem.indexes = temp_topology->indexes.len; mem.instance_attr.cap = 100; // todo: patricia method should manage this, not me - mem.instance_attr.staging_busy = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.instance_attr.staging_busy = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.instance_attr.cap * sizeof(ShinyMeshInstance)); - mem.instance_attr.staging_updatable = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.instance_attr.staging_updatable = MargaretBufAllocator_alloc(&alice->staging_buffers, mem.instance_attr.cap * sizeof(ShinyMeshInstance)); - mem.instance_attr.device_local = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.instance_attr.device_local = MargaretBufAllocator_alloc(&alice->dev_local_buffers, mem.instance_attr.cap * sizeof(ShinyMeshInstance)); mem.instance_attr.count = 0; - mem.staging_vbo = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_vbo = MargaretBufAllocator_alloc(&alice->staging_buffers, temp_topology->vertices.len * sizeof(ShinyMeshVertex)); - mem.staging_ebo = MargaretBufAllocator_alloc(&vk->staging_buffers, + mem.staging_ebo = MargaretBufAllocator_alloc(&alice->staging_buffers, temp_topology->indexes.len * sizeof(U32)); - mem.vbo = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.vbo = MargaretBufAllocator_alloc(&alice->dev_local_buffers, temp_topology->vertices.len * sizeof(ShinyMeshVertex)); - mem.ebo = MargaretBufAllocator_alloc(&vk->dev_local_buffers, + mem.ebo = MargaretBufAllocator_alloc(&alice->dev_local_buffers, temp_topology->indexes.len * sizeof(U32)); VecShinyModelOnSceneMem_append(&shiny_model_mem, mem); } Pipeline0Transfer pipeline0_ubo = (Pipeline0Transfer){ - .staging_busy = MargaretBufAllocator_alloc(&vk->staging_buffers, sizeof(Pipeline0UBO)), - .staging_updatable = MargaretBufAllocator_alloc(&vk->staging_buffers, sizeof(Pipeline0UBO)), - .device_local = MargaretBufAllocator_alloc(&vk->dev_local_buffers, sizeof(Pipeline0UBO)), + .staging_busy = MargaretBufAllocator_alloc(&alice->staging_buffers, sizeof(Pipeline0UBO)), + .staging_updatable = MargaretBufAllocator_alloc(&alice->staging_buffers, sizeof(Pipeline0UBO)), + .device_local = MargaretBufAllocator_alloc(&alice->dev_local_buffers, sizeof(Pipeline0UBO)), }; - vk->scene = Scene_new(generic_model_mem, shiny_model_mem, pipeline0_ubo); - vk->IT1_image = MargaretImgAllocator_alloc(&vk->dev_local_images, - MAX_WIN_WIDTH, MAX_WIN_HEIGHT, vk->IT1_format, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); - vk->zbuffer_image = MargaretImgAllocator_alloc(&vk->dev_local_images, - MAX_WIN_WIDTH, MAX_WIN_HEIGHT, vk->zbuffer_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); + alice->scene = Scene_new(generic_model_mem, shiny_model_mem, pipeline0_ubo); + alice->IT1_image = MargaretImgAllocator_alloc(&alice->dev_local_images, + MAX_WIN_WIDTH, MAX_WIN_HEIGHT, alice->IT1_format, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); + alice->zbuffer_image = MargaretImgAllocator_alloc(&alice->dev_local_images, + MAX_WIN_WIDTH, MAX_WIN_HEIGHT, alice->zbuffer_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT); MargaretEngineReference engine_reference = { - .device = vk->device, .physical_device = vk->physical_device, .transfer_cmd_buffer = vk->transfer_command_buf, - .dev_local_images = &vk->dev_local_images, .dev_local_buffers = &vk->dev_local_buffers, - .staging_buffers = &vk->staging_buffers, .descriptor_pool = vk->descriptor_pool, - .linear_sampler = vk->linear_sampler, .nearest_sampler = vk->nearest_sampler + .device = alice->device, .physical_device = alice->physical_device, .transfer_cmd_buffer = alice->transfer_command_buf, + .dev_local_images = &alice->dev_local_images, .dev_local_buffers = &alice->dev_local_buffers, + .staging_buffers = &alice->staging_buffers, .descriptor_pool = alice->descriptor_pool, + .linear_sampler = alice->linear_sampler, .nearest_sampler = alice->nearest_sampler }; - FT_Error ft_init_err = FT_Init_FreeType(&vk->ft_library); + FT_Error ft_init_err = FT_Init_FreeType(&alice->ft_library); if (ft_init_err) abortf("Can't init free type library\n"); - vk->lucy_cache = LucyGlyphCache_new(engine_reference); - vk->font_face = LucyFace_new(vk->ft_library, &vk->lucy_cache, + alice->lucy_cache = LucyGlyphCache_new(engine_reference); + alice->font_face = LucyFace_new(alice->ft_library, &alice->lucy_cache, VecU8_fmt("%s/src/l3/fonts/DMSerifText-Regular.ttf", root_dir)); - vk->font_face_of_size_40 = LucyFace_of_size(&vk->font_face, 40); + alice->font_face_of_size_40 = LucyFace_of_size(&alice->font_face, 40); { VecLucyGlyphCachingRequest lucy_requests = VecLucyGlyphCachingRequest_new(); VecU32Segment ranges_needed = VecU32Segment_new(); VecU32Segment_append(&ranges_needed, (U32Segment){.start = 32, .len = 126 - 32 + 1}); VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){ - .sized_face = vk->font_face_of_size_40, .codepoint_ranges = ranges_needed, + .sized_face = alice->font_face_of_size_40, .codepoint_ranges = ranges_needed, }); LucyGlyphCache_add_glyphs(lucy_requests); } - VecU8_append_span(&vk->scene.text_on_screen, cstr("I am late :(\nExam is in 25 hours...")); - vk->lucy_renderer = LucyRenderer_new(engine_reference, &vk->lucy_cache, root_dir, vk->render_pass_1, 0); + VecU8_append_span(&alice->scene.text_on_screen, cstr("I am late :(\nExam is in 25 hours...")); + alice->lucy_renderer = LucyRenderer_new(engine_reference, &alice->lucy_cache, root_dir, alice->render_pass_1, 0); { - GenericModelOnSceneMem *model_g = VecGenericModelOnSceneMem_mat(&vk->scene.generic_models, 0); + GenericModelOnSceneMem *model_g = VecGenericModelOnSceneMem_mat(&alice->scene.generic_models, 0); assert(model_g->instance_attr.cap >= 100); for (int X = 0; X < 10; X++) { for (int Z = 0; Z < 10; Z++) { - Scene_add_smeshnyavka_1(&vk->scene, (ObjectInfo){ + Scene_add_smeshnyavka_1(&alice->scene, (ObjectInfo){ .pos = (vec3){11.f * (float)X, -6, 4.f * (float)Z}, .scale = 1, .rotation = mat3_E}); } @@ -2096,12 +2114,12 @@ void allie_run() { for (int X = 0; X < 10; X++) { for (int Z = 0; Z < 10; Z++) { - Scene_add_smeshnyavka_3(&vk->scene, (ObjectInfo){.rotation = mat3_E, + Scene_add_smeshnyavka_3(&alice->scene, (ObjectInfo){.rotation = mat3_E, .pos = (vec3){11.f * (float)X - 20, 10, 4.f * (float)Z - 10}, .scale = 1, .color_on = {0, 1, 0}}); } } - Pipeline0UBO* ubo = (Pipeline0UBO*)MargaretSubbuf_get_mapped(&vk->scene.pipeline0_ubo.staging_updatable); + Pipeline0UBO* ubo = (Pipeline0UBO*)MargaretSubbuf_get_mapped(&alice->scene.pipeline0_ubo.staging_updatable); assert(pipeline_0_ubo_point_light_max_count >= 100); ubo->point_light_count = 100; ubo->spotlight_count = 0; @@ -2118,11 +2136,11 @@ void allie_run() { /* Here we both copy from topology + textures to staging buffers and record commands that will copy staging data * to device local memory */ - margaret_reset_and_begin_command_buffer(vk->transfer_command_buf); + margaret_reset_and_begin_command_buffer(alice->transfer_command_buf); SceneTemplate_copy_initial_model_topology_cmd_buf_recording( - &vk->scene_template, &vk->scene, vk->transfer_command_buf); - for (U64 i = 0; i < vk->scene.generic_models.len; i++) { - GenericModelOnSceneMem* model = &vk->scene.generic_models.buf[i]; + &alice->scene_template, &alice->scene, alice->transfer_command_buf); + for (U64 i = 0; i < alice->scene.generic_models.len; i++) { + GenericModelOnSceneMem* model = &alice->scene.generic_models.buf[i]; memcpy(MargaretSubbuf_get_mapped(&model->staging_diffuse_tex_buf), model->pixels_diffuse.pixels.buf, TextureDataR8G8B8A8_get_size_in_bytes(&model->pixels_diffuse)); memcpy(MargaretSubbuf_get_mapped(&model->staging_normal_tex_buf), model->pixels_normal.pixels.buf, @@ -2130,76 +2148,91 @@ void allie_run() { memcpy(MargaretSubbuf_get_mapped(&model->staging_specular_tex_buf), model->pixels_specular.pixels.buf, TextureDataR8_get_size_in_bytes(&model->pixels_specular)); - margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(vk->transfer_command_buf, + margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(alice->transfer_command_buf, &model->staging_diffuse_tex_buf, &model->diffuse_texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); - margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(vk->transfer_command_buf, + margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(alice->transfer_command_buf, &model->staging_normal_tex_buf, &model->normal_texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); - margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(vk->transfer_command_buf, + margaret_rec_cmd_copy_buffer_to_image_one_to_one_color_aspect(alice->transfer_command_buf, &model->staging_specular_tex_buf, &model->specular_texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); } - margaret_end_command_buffer(vk->transfer_command_buf); - check(vkQueueSubmit(vk->queues.graphics_queue, 1, &(VkSubmitInfo){ - .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &vk->transfer_command_buf, - }, vk->jane.roxy) == VK_SUCCESS); - check(vkWaitForFences(vk->device, 1, &vk->jane.roxy, VK_TRUE, UINT64_MAX) == VK_SUCCESS); + margaret_end_command_buffer(alice->transfer_command_buf); + check(vkQueueSubmit(alice->queues.graphics_queue, 1, &(VkSubmitInfo){ + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &alice->transfer_command_buf, + }, alice->jane.roxy) == VK_SUCCESS); + check(vkWaitForFences(alice->device, 1, &alice->jane.roxy, VK_TRUE, UINT64_MAX) == VK_SUCCESS); - recreate_vulkan_references_objects(&state); + recreate_vulkan_references_objects(alice); - state.prev_key_frame_time = margaret_clock_gettime_monotonic_raw(); - state.frame_count_since_key = 0; - /* Will happen mid-frame */ + alice->wl.prev_key_frame_time = margaret_clock_gettime_monotonic_raw(); + alice->wl.frame_count_since_key = 0; + return alice; +} +void Alice_clear_screen_text(Alice* alice){ + LucyRenderer_clear(&alice->lucy_renderer); +} + +void Alice_add_screen_text_label(Alice* alice, SpanU8 text){ + LucyRenderer_add_text(&alice->lucy_renderer, alice->font_face_of_size_40, (vec4){1, 0, 0, 1}, 0, + text, (ivec2){10, 10}); +} + +void allie_Alice_add_screen_text_label(Alice* alice, const U8* data, U64 len){ + Alice_add_screen_text_label(alice, (SpanU8){data, len}); +} + +void Alice_mainloop(Alice* alice, const AliceCallbacks* callbacks) { + alice->callbacks.on_wl_keyboard_key = callbacks->on_wl_keyboard_key; + alice->callbacks.on_another_frame = callbacks->on_another_frame; printf("ENTERING WAYLAND MAINLOOP\n"); - - while (wl_display_dispatch(state.wl_display) >= 0) { - if (state.closed) + while (wl_display_dispatch(alice->wl.wl_display) >= 0) { + if (alice->wl.closed) break; } - - vkDeviceWaitIdle(vk->device); + vkDeviceWaitIdle(alice->device); + AliceCallbacks_set_default(&alice->callbacks); // The End - vkDestroyDescriptorPool(vk->device, vk->descriptor_pool, NULL); - vkDestroySampler(vk->device, vk->linear_sampler, NULL); - vkDestroySampler(vk->device, vk->nearest_sampler, NULL); - - - Scene_drop(vk->scene); - - vkDestroyCommandPool(vk->device, vk->command_pool, NULL); - - SceneTemplate_drop(vk->scene_template); - - MargaretSwapchainBundle_drop_with_device(vk->device, vk->swfb); - Jane_r0_destroy(vk->device, vk->jane); - destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_1); - vkDestroyRenderPass(vk->device, vk->render_pass_1, NULL); - destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_0b); - destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_0a); - vkDestroyRenderPass(vk->device, vk->render_pass_0, NULL); - vkDestroyDevice(vk->device, NULL); - vkDestroySurfaceKHR(instance, vk->surface, NULL); - MargaretInstanceAndItsDebug_drop(vk->instance_and_debug); - - if (state.wl_callback) - wl_callback_destroy(state.wl_callback); - xdg_toplevel_destroy(state.xdg_toplevel); - xdg_surface_destroy(state.xdg_surface); - xdg_wm_base_destroy(state.xdg_wm_base); - wl_surface_destroy(state.wl_surface); - wl_compositor_destroy(state.wl_compositor); - if (state.pointer) - wl_pointer_destroy(state.pointer); - xkb_context_unref(state.xkb_context); - xkb_keymap_unref(state.xkb_keymap); - xkb_state_unref(state.xkb_state); - if (state.keyboard) - wl_keyboard_destroy(state.keyboard); - if (state.wl_seat) - wl_seat_destroy(state.wl_seat); - wl_registry_destroy(state.wl_registry); - wl_display_disconnect(state.wl_display); + // vkDestroyDescriptorPool(vk->device, vk->descriptor_pool, NULL); + // vkDestroySampler(vk->device, vk->linear_sampler, NULL); + // vkDestroySampler(vk->device, vk->nearest_sampler, NULL); + // + // + // Scene_drop(vk->scene); + // + // vkDestroyCommandPool(vk->device, vk->command_pool, NULL); + // + // + // MargaretSwapchainBundle_drop_with_device(vk->device, vk->swfb); + // Jane_alice_destroy(vk->device, vk->jane); + // destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_1); + // vkDestroyRenderPass(vk->device, vk->render_pass_1, NULL); + // destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_0b); + // destroy_graphics_pipeline_hands(vk->device, vk->pipeline_hands_0a); + // vkDestroyRenderPass(vk->device, vk->render_pass_0, NULL); + // vkDestroyDevice(vk->device, NULL); + // vkDestroySurfaceKHR(instance, vk->surface, NULL); + // MargaretInstanceAndItsDebug_drop(vk->instance_and_debug); + // + // if (alice->wl.wl_callback) + // wl_callback_destroy(alice->wl.wl_callback); + // xdg_toplevel_destroy(alice->wl.xdg_toplevel); + // xdg_surface_destroy(alice->wl.xdg_surface); + // xdg_wm_base_destroy(alice->wl.xdg_wm_base); + // wl_surface_destroy(alice->wl.wl_surface); + // wl_compositor_destroy(alice->wl.wl_compositor); + // if (alice->wl.pointer) + // wl_pointer_destroy(alice->wl.pointer); + // xkb_context_unref(alice->wl.xkb_context); + // xkb_keymap_unref(alice->wl.xkb_keymap); + // xkb_state_unref(alice->wl.xkb_state); + // if (alice->wl.keyboard) + // wl_keyboard_destroy(alice->wl.keyboard); + // if (alice->wl.wl_seat) + // wl_seat_destroy(alice->wl.wl_seat); + // wl_registry_destroy(alice->wl.wl_registry); + // wl_display_disconnect(alice->wl.wl_display); } diff --git a/src/l3/r4/R4.hs b/src/l3/r4/R4.hs index e11c8ce..a3fda91 100644 --- a/src/l3/r4/R4.hs +++ b/src/l3/r4/R4.hs @@ -1,4 +1,4 @@ import Allie main :: IO() -main = allieRun \ No newline at end of file +main = justFuckingDoSomething \ No newline at end of file