Saving progress. I just realized that my current MaragertMemAllocator is still very very bloated. I am about to change that. Yep, another rewrite

This commit is contained in:
Андреев Григорий 2025-12-08 23:31:05 +03:00
parent f80dc0ded0
commit 202e11ab56
6 changed files with 44 additions and 19 deletions

View File

@ -100,7 +100,7 @@ NODISCARD VecU8 generate_texture_data_struct_and_necc_methods(SpanU8 tex, SpanU8
"}\n\n", resoftex, tex, resoftex, resoftex, memb, resoftex, tex, tex, resoftex));
/* Method _read_from_file */
VecU8_append_vec(&res, VecU8_fmt(
"%s %s_read_from_file(const char* path) {\n"
"%s %s_read_from_file(SpanU8 path) {\n"
SPACE "VecU8 data = read_whole_file_or_abort(path);\n"
SPACE "%s res = %s_from_bitmap_text(VecU8_to_span(&data));\n"
SPACE "if (res.variant != Result_Ok) {\n"

View File

@ -66,6 +66,13 @@ void generate_util_temp_very_base_headers() {
cstr("#include \"../../gen/l1/pixel_masses.h\"\n"), true, false);
generate_guarded_span_company_for_non_primitive_clonable(cstr("l1"), cstr(""), cstr("TextureDataR8"),
cstr("#include \"../../gen/l1/pixel_masses.h\"\n"), true, false);
generate_guarded_span_company_for_primitive(cstr("l1"), cstr(""), cstr("PostponedMemcpy"), cstr(
"typedef struct{\n"
SPACE "void* dest;\n"
SPACE "const void* src;\n"
SPACE "size_t n;\n"
"} PostponedMemcpy;\n"), true, false);
}
#endif

View File

@ -28,11 +28,12 @@ typedef struct {
void Result_ok_or_int_drop(Result_ok_or_int obj) {}
NODISCARD VecU8 read_whole_file_or_abort(const char* filename) {
FILE* fp = fopen(filename, "rb");
if (!fp) {
abortf("Can't open file %s: %s\n", filename, strerror(errno));
}
NODISCARD VecU8 read_whole_file_or_abort(SpanU8 path) {
VecU8 filename = VecU8_fmt("%s%c", path, 0);
FILE* fp = fopen((const char*)filename.buf, "rb");
if (!fp)
abortf("Can't open file %s: %s\n", (const char*)filename.buf, strerror(errno));
VecU8_drop(filename);
if (fseek(fp, 0, SEEK_END) != 0) {
abortf("fseek: %s\n", strerror(errno));
}

View File

@ -5,7 +5,6 @@
typedef struct{
LucyGlyphCache cache;
VkPipelineLayout pipeline_layout;
VkPipeline pipeline;
} LucyGlyphRenderer;
@ -14,7 +13,7 @@ typedef struct{
LucyGlyphRenderer LucyGlyphRenderer_new(
MargaretEngineReference engine_reference, VkCommandBuffer transfer_command_buffer,
VkRenderPass render_pass, U32 renderpass_subpass){
VkRenderPass render_pass, U32 renderpass_subpass, SpanU8 root_dir){
VkDescriptorSetLayout descriptor_set_layout;
check(vkCreateDescriptorSetLayout(engine_reference.device, &(VkDescriptorSetLayoutCreateInfo){
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
@ -28,7 +27,6 @@ LucyGlyphRenderer LucyGlyphRenderer_new(
}, NULL, &descriptor_set_layout) == VK_SUCCESS);
LucyGlyphCache cache = LucyGlyphCache_new(engine_reference, transfer_command_buffer, descriptor_set_layout);
VkPipelineLayout pipeline_layout;
@ -42,11 +40,11 @@ LucyGlyphRenderer LucyGlyphRenderer_new(
}},
}, NULL, &pipeline_layout) == VK_SUCCESS);
/* Configuring font pipeline */
VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(engine_reference.device,
render_pass, renderpass_subpass, (MargaretMostImportantPipelineOptions){
.pipeline_layout = pipeline_layout,});
// todo: create the actual pipeline
return (LucyGlyphRenderer){};
return (LucyGlyphRenderer){.cache = cache, .pipeline_layout = pipeline_layout, .pipeline = pipeline};
}
#endif

View File

@ -176,6 +176,7 @@
// todo: for staging buffers you better use MargaretBufferAllocator. Ou, yeah, I have yet to write them
#include "../../l1/core/int_primitives.h"
#include "../../../gen/l1/VecPostponedMemcpy.h"
/* Demands + Warnings */
typedef U8 MargaretMemAllocatorDemands;
@ -347,6 +348,24 @@ void MargaretMemAllocatorRequests_drop(MargaretMemAllocatorRequests self){
VecMargaretMemAllocatorRequestAllocImage_drop(self.alloc_image);
}
void MargaretMemAllocatorRequests_free_buf(
MargaretMemAllocatorRequests* self, RBTreeNode_KVPU64ToMargaretMAOccupation* occ_it){
}
void MargaretMemAllocatorRequests_shrink_buf(MargaretMemAllocatorRequests* self,
RBTreeNode_KVPU64ToMargaretMAOccupation* occ_it, size_t new_size){
VecMargaretMemAllocatorRequestResizeBuffer_append(&self->shrink_buf,
(MargaretMemAllocatorRequestResizeBuffer){.occ_it = occ_it, .new_size = new_size});
}
void MargaretMemAllocatorRequests_expand_buf(MargaretMemAllocatorRequests* self,
RBTreeNode_KVPU64ToMargaretMAOccupation* occ_it, size_t new_size){
VecMargaretMemAllocatorRequestResizeBuffer_append(&self->expand_buf,
(MargaretMemAllocatorRequestResizeBuffer){.occ_it = occ_it, .new_size = new_size});
}
RBTreeNode_KVPU64ToMargaretMAOccupation* MargaretMemAllocatorRequests_alloc_buf(
MargaretMemAllocatorRequests* self,
U64 allocation_size, VkBufferUsageFlags usage, bool preserve_at_quiet

View File

@ -158,8 +158,8 @@ PipelineHands create_graphics_pipeline_0(
abortf("vkCreatePipelineLayout");
VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/0/vert.spv");
VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/0/frag.spv");
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0/frag.spv"));
VkVertexInputBindingDescription vertex_bindings[2] = {
{
@ -260,8 +260,8 @@ PipelineHands create_graphics_pipeline_0_b(
}, NULL, &pipeline_layout) == VK_SUCCESS);
VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/0b/vert.spv");
VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/0b/frag.spv");
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0b/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0b/frag.spv"));
VkVertexInputBindingDescription vertex_bindings[2] = {
{
@ -429,8 +429,8 @@ PipelineHands create_graphics_pipeline_1(
}, NULL, &pipeline_layout) == VK_SUCCESS);
VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/1/vert.spv");
VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/1/frag.spv");
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/1/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/1/frag.spv"));
VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(device, render_pass, subpass,
(MargaretMostImportantPipelineOptions){