diff --git a/CMakeLists.txt b/CMakeLists.txt index b4cfcf2..37a54ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ add_compile_options(-fno-trapping-math) add_executable(codegen_l1_5 src/l1_5/anne/codegen.c) add_executable(0_render_test src/l2/tests/r0/r0.c gen/l_wl_protocols/xdg-shell-private.c) -target_link_libraries(0_render_test -lvulkan -lwayland-client -lm -lxkbcommon -lpng) +target_link_libraries(0_render_test -lvulkan -lwayland-client -lm -lxkbcommon -lpng -lfreetype) #add_executable(0r_tex_init_prep src/l2/tests/r0/r0_tex_init_prep.c) #target_link_libraries(0r_tex_init_prep -lm -lpng) diff --git a/Makefile b/Makefile index cae85c1..0342987 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,20 @@ -find_headers = $(shell find src/$(1) -type f -name '*.h') +find_headers = $(shell find src/$(1) -type f -name '*.h' ) +find_assets = $(shell find src/$(1) -type f \( -name "*.vert" -o -name "*.frag" -o -name "*.geom" -o -name "*.comp" \) ) HEADERS_src_l1 := $(call find_headers,l1) -HEADERS_gen_l1 := $(HEADERS_src_l1) gen/l1/dorothy.txt +#HEADERS_gen_l1 := $(HEADERS_src_l1) gen/l1/dorothy.txt +HEADERS_gen_l1 := gen/l1/dorothy.txt HEADERS_src_l1_5 = $(HEADERS_gen_l1) $(call find_headers,l1_5) -HEADERS_gen_l1_5 := $(HEADERS_src_l1_5) gen/l1_5/dorothy.txt +#HEADERS_gen_l1_5 := $(HEADERS_src_l1_5) gen/l1_5/dorothy.txt +HEADERS_gen_l1_5 := gen/l1_5/dorothy.txt + +ASSETS_src_l_adele = $($call find_assets,l_adele) +ASSETS_gen_l_adele = gen/l_adele/dorothy.txt HEADERS_src_l2 := $(HEADERS_gen_l1_5) $(call find_headers,l2) -HEADERS_gen_l2 := $(HEADERS_src_l2) gen/l2/dorothy.txt +#HEADERS_gen_l2 := $(HEADERS_src_l2) gen/l2/dorothy.txt +HEADERS_gen_l2 := gen/l2/dorothy.txt cflags := -Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type -Wno-unused-parameter \ --std=c99 -g -ggdb -O0 \ @@ -17,6 +24,9 @@ cc := gcc wl_protocols := $(shell pkg-config --variable=pkgdatadir wayland-protocols) libpipewire_flags := $(shell pkg-config --cflags --libs libpipewire-0.3) +xdg_shell_private := gen/l_wl_protocols/xdg-shell-private.c +l_wl_protocols := gen/l_wl_protocols/xdg-shell-client.h $(xdg_shell_private) + out/l1/codegen: src/l1/anne/codegen.c $(HEADERS_src_l1) mkdir -p out/l1 $(cc) $(cflags) -D PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8 -o $@ $< @@ -50,13 +60,23 @@ gen/l_wl_protocols/xdg-shell-private.c: $(wl_protocols)/stable/xdg-shell/xdg-she mkdir -p gen/l_wl_protocols wayland-scanner private-code $< $@ -xdg_shell_private := gen/l_wl_protocols/xdg-shell-private.c -l_wl_protocols := gen/l_wl_protocols/xdg-shell-client.h $(xdg_shell_private) - .PHONY: gen/l_wl_protocols gen/l_wl_protocols : $(l_wl_protocols) +compile_vert_shader = glslc -o gen/l_adele/$(1)/vert.spv src/l_adele/$(1)/$(1).vert +compile_frag_shader = glslc -o gen/l_adele/$(1)/frag.spv src/l_adele/$(1)/$(1).frag + +define compile_shader +mkdir -p gen/l_adele/$(1) +$(call compile_vert_shader,$(1)) +$(call compile_frag_shader,$(1)) +endef + +gen/l_adele/dorothy.txt: $(ASSETS_src_l_adele) + $(call compile_shader,lucy) + touch gen/l_adele/dorothy.txt + out/l2/t0: src/l2/tests/data_structures/t0.c $(HEADERS_gen_l1_5) mkdir -p out/l2 $(cc) $(cflags) -o $@ $< @@ -108,15 +128,6 @@ out/l2/r3: src/l2/tests/r3/r3.c $(HEADERS_src_l2) $(l_wl_protocols) run_r3: out/l2/r3 ./out/l2/r3 -out/SICK_JOKE_H.c: src/l2/tests/r_alg/H.c $(HEADERS_gen_l1_5) - python src/l1/sobiralka.py $< $@ - -out/SICK_JOKE_I.c: src/l2/tests/r_alg/I.c $(HEADERS_gen_l1_5) - python src/l1/sobiralka.py $< $@ - -out/SICK_JOKE_J.c: src/l2/tests/r_alg/J.c $(HEADERS_gen_l1_5) - python src/l1/sobiralka.py $< $@ - .PHONY: clean clean: diff --git a/src/l1/anne/codegen.c b/src/l1/anne/codegen.c index 61e876d..596ebbd 100644 --- a/src/l1/anne/codegen.c +++ b/src/l1/anne/codegen.c @@ -12,6 +12,7 @@ #include "liza.h" #include "embassy_l1_5.h" #include "margaret/png_pixel_masses.h" +#include "lucy.h" int main() { mkdir_nofail("l1"); @@ -28,6 +29,7 @@ int main() { mkdir_nofail("l1/margaret"); generate_margaret_eve_for_vulkan_utils(); /* margaret misc */ generate_margaret_png_pixel_masses_header(); + generate_l1_lucy_headers(); finish_layer(cstr("l1")); return 0; } diff --git a/src/l1/anne/lucy.h b/src/l1/anne/lucy.h new file mode 100644 index 0000000..2a3352e --- /dev/null +++ b/src/l1/anne/lucy.h @@ -0,0 +1,17 @@ +#ifndef prototype1_src_l1_anne_lucy_h +#define prototype1_src_l1_anne_lucy_h + +#include "../codegen/util_template_inst.h" +#include "../codegen/list_template_inst.h" + +void generate_l1_lucy_headers(){ + SpanU8 l = cstr("l1"), ns = cstr("lucy"); + mkdir_nofail("l1/eve/lucy"); + generate_List_templ_inst_eve_header(l, ns, (list_instantiation_op){ + .T = cstr("LucyImage"), .t_primitive = true}, true); + generate_eve_span_company_for_primitive(l, ns, cstr("KVPU32ToLucyStoredGlyph"), true, false); + generate_eve_span_company_for_primitive(l, ns, cstr("KVPU32ToLucyFaceFixedSize"), true, false); + +} + +#endif \ No newline at end of file diff --git a/src/l1_5/anne/codegen.c b/src/l1_5/anne/codegen.c index 4f172b3..52ec26d 100644 --- a/src/l1_5/anne/codegen.c +++ b/src/l1_5/anne/codegen.c @@ -4,6 +4,7 @@ #include "liza.h" #include "l1_5_templ_very_base.h" #include "margaret.h" +#include "lucy.h" int main() { mkdir_nofail("l1_5"); @@ -12,6 +13,7 @@ int main() { generate_l1_5_liza_headers(); generate_l1_5_template_instantiation_for_base_types(); generate_l1_5_template_instantiations_for_margaret(); + generate_l1_5_lucy_headers(); finish_layer(cstr("l1_5")); return 0; } diff --git a/src/l1_5/anne/lucy.h b/src/l1_5/anne/lucy.h new file mode 100644 index 0000000..6db735e --- /dev/null +++ b/src/l1_5/anne/lucy.h @@ -0,0 +1,16 @@ +#ifndef prototype1_src_l1_5_anne_lucy_h +#define prototype1_src_l1_5_anne_lucy_h + +#include "../codegen/buff_rbtree_set_map_template_inst.h" + +void generate_l1_5_lucy_headers(){ + SpanU8 l = cstr("l1_5"), ns = cstr("lucy"); + mkdir_nofail("l1_5/eve/lucy"); + generate_buf_rbtree_Map_templ_inst_eve_header(l, ns, (map_instantiation_op){ + .K = cstr("U32"), .k_integer = true, .V = cstr("LucyStoredGlyph"), .v_primitive = true}); + generate_buf_rbtree_Map_templ_inst_eve_header(l, ns, (map_instantiation_op){ + .K = cstr("U32"), .k_integer = true, .V = cstr("LucyFaceFixedSize"), .v_primitive = true}); + +} + +#endif \ No newline at end of file diff --git a/src/l2/lucy/glyph_cache.h b/src/l2/lucy/glyph_cache.h new file mode 100644 index 0000000..e179a4e --- /dev/null +++ b/src/l2/lucy/glyph_cache.h @@ -0,0 +1,71 @@ +#ifndef prototype1_src_l2_lucy_glyph_cache_h +#define prototype1_src_l2_lucy_glyph_cache_h + +#include "../margaret/vulkan_utils.h" +#include +#include FT_FREETYPE_H + +/* Right now my glyph cache is static, but I am planning to change that */ + +#include "../../l1_5/core/buff_rb_tree_node.h" + +typedef struct { + MargaretMAIterator img; + U64 usage; + U64 pos_in_desc_array; +} LucyImage; +#include "../../../gen/l1/eve/lucy/ListLucyImage.h" + +typedef struct { + ListNodeLucyImage* img; + U32 x, y, w, h; +} LucyStoredGlyph; + +typedef struct { + U32 key; + LucyStoredGlyph value; +} KVPU32ToLucyStoredGlyph; +#include "../../../gen/l1/eve/lucy/VecKVPU32ToLucyStoredGlyph.h" +#include "../../../gen/l1_5/eve/lucy/BufRBTree_MapU32ToLucyStoredGlyph.h" + +typedef struct { + U64 usage; + BufRBTree_MapU32ToLucyStoredGlyph glyphs; +} LucyFaceFixedSize; + +typedef struct { + U32 key; + LucyFaceFixedSize value; +} KVPU64ToLucyFaceFixedSize; +#include "../../../gen/l1/eve/lucy/VecKVPU32ToLucyFaceFixedSize.h" +#include "../../../gen/l1_5/eve/lucy/BufRBTree_MapU32ToLucyFaceFixedSize.h" + +typedef struct{ + FT_Face ft_face; + BufRBTree_MapU32ToLucyFaceFixedSize sizes; +} LucyFace; + +typedef struct { + MargaretEngineReference ve; + VkCommandBuffer transfer_cmd_buffer; + MargaretMAIterator staging_buffer; + ListLucyImage images; +} LucyGlyphCache; + +LucyGlyphCache LucyGlyphCache_new(MargaretEngineReference ve){ + return (LucyGlyphCache){.ve = ve}; +} + +void LucyGlyphCache_add_glyphs(){ + +} + +void LucyGlyphCache_delete(LucyGlyphCache* self){ + +} + +void LucyGlyphCache_drop(LucyGlyphCache self){ + ListLucyImage_drop(self.images); +} + +#endif \ No newline at end of file diff --git a/src/l2/margaret/vulkan_memory.h b/src/l2/margaret/vulkan_memory.h new file mode 100644 index 0000000..61f7f24 --- /dev/null +++ b/src/l2/margaret/vulkan_memory.h @@ -0,0 +1,7 @@ +#ifndef prototype1_src_l2_margaret_vulkan_memory_h +#define prototype1_src_l2_margaret_vulkan_memory_h + +#include +#include "vulkan_memory_claire.h" + +#endif \ No newline at end of file diff --git a/src/l2/margaret/vulkan_utils.h b/src/l2/margaret/vulkan_utils.h index 845de30..da9daa9 100644 --- a/src/l2/margaret/vulkan_utils.h +++ b/src/l2/margaret/vulkan_utils.h @@ -1012,4 +1012,18 @@ void margaret_end_command_buffer(VkCommandBuffer command_buffer){ check(vkEndCommandBuffer(command_buffer) == VK_SUCCESS); } +#include "vulkan_memory.h" + +// for users of memory that should be aware whether we are using two memory types or one +typedef struct { + VkDevice device; + MargaretMemAllocator* host_visible_mem; + MargaretMemAllocatorRequests* host_visible_mem_requests; + MargaretMemAllocator* device_local_mem; + MargaretMemAllocatorRequests* device_local_mem_requests; + bool device_local_is_host_visible; +} MargaretEngineReference; + +// todo: move image copying function here + #endif diff --git a/src/l2/tests/r0/r0.c b/src/l2/tests/r0/r0.c index 89d58d5..250137e 100644 --- a/src/l2/tests/r0/r0.c +++ b/src/l2/tests/r0/r0.c @@ -11,7 +11,7 @@ #include #include "../../../l1/system/creating_child_proc.h" #include "../../../../gen/l1/margaret/png_pixel_masses.h" -#include "../../../../gen/l1/VecAndSpan_U64.h" +#include "../../lucy/glyph_cache.h" // todo: generate this structure in l2 typedef struct { diff --git a/src/l2/tests/r0/r0_scene.h b/src/l2/tests/r0/r0_scene.h index 6a15cd2..0b38fe9 100644 --- a/src/l2/tests/r0/r0_scene.h +++ b/src/l2/tests/r0/r0_scene.h @@ -4,7 +4,6 @@ #include "r0_assets.h" #include "../../margaret/vulkan_utils.h" -#include "../../margaret/vulkan_memory_claire.h" typedef struct { size_t indexes; diff --git a/src/l_adele/lucy/lucy.frag b/src/l_adele/lucy/lucy.frag new file mode 100644 index 0000000..972aac8 --- /dev/null +++ b/src/l_adele/lucy/lucy.frag @@ -0,0 +1,16 @@ +#version 460 + +#extension GL_EXT_nonuniform_qualifier : require + +layout (location=0) in vec4 color; +layout (location=1) in vec2 tex_cord; +layout (location=2) flat in uint tex_ind; + +layout (location=0) out vec4 fin_color; + +layout (binding=0) uniform sampler2D images[]; + +void main(){ + float I = texture(images[nonuniformEXT(tex_ind)], tex_cord).r; + fin_color = color * vec4(I, I, I, I); +} diff --git a/src/l_adele/lucy/lucy.vert b/src/l_adele/lucy/lucy.vert new file mode 100644 index 0000000..5a9f3ce --- /dev/null +++ b/src/l_adele/lucy/lucy.vert @@ -0,0 +1,30 @@ +#version 450 + +layout(location = 0) in vec4 color; +layout(location = 1) in vec2 pos; +layout(location = 2) in vec2 tex_cord; +layout(location = 3) in uint tex_ind; + +layout(push_constant, std430) uniform pc { + float width; + float height; +}; + +layout (location=0) flat out vec4 vsout_color; +layout (location=1) out vec2 vsout_tex_cord; +layout (location=2) flat out uint vsout_tex_ind; + +float lint(float A1, float B1, float A2, float B2, float x){ + return A2 + (B2 - A2) * (x - A1) / (B1 - A1); +} + +float deng(float B1, float x){ + return lint(0, B1, -1, 1, x); +} + +void main(){ + vsout_color = color; + vsout_tex_cord = tex_cord; + vsout_tex_ind = tex_ind; + gl_Position = vec4(deng(width, pos.x), deng(height, pos.y), 0, 1); +}