diff --git a/assets/shaders/convert.comp.spv b/assets/shaders/convert.comp.spv index 9dbec75..495db27 100644 Binary files a/assets/shaders/convert.comp.spv and b/assets/shaders/convert.comp.spv differ diff --git a/src/VulkanRenderer b/src/VulkanRenderer index c6a92fa..7a10601 160000 --- a/src/VulkanRenderer +++ b/src/VulkanRenderer @@ -1 +1 @@ -Subproject commit c6a92fa58a25fc204198bcd158e170847344d799 +Subproject commit 7a10601f51b651db006de6d1c5cafb547f90dc87 diff --git a/src/gears/game.d b/src/gears/game.d index d4119fe..b22bab0 100644 --- a/src/gears/game.d +++ b/src/gears/game.d @@ -1,5 +1,6 @@ import aliases; import includes; +public import vulkan : PlatformHandles; import vulkan : Destroy; import vulkan; import assets; @@ -12,6 +13,8 @@ import std.algorithm.sorting; import fonts; import main; +const UI_COUNT = 50000; + f32 g_DELTA; struct UIVertex @@ -74,8 +77,10 @@ struct Game DescSet ui_desc_set; PipelineLayout ui_layout; - UIVertex[] ui_vertex_buf; - u32[] ui_index_buf; + MappedBuffer!(UIVertex) ui_vertex_mapped_buf; + MappedBuffer!(u32) ui_index_mapped_buf; + UIVertex[] ui_vertex_buf; + u32[] ui_index_buf; u32 ui_count; ImageView default_tex; @@ -95,19 +100,32 @@ struct Game Game InitGame(PlatformWindow* window) { + version(linux) + { + PlatformHandles handles = { + conn: window.conn, + window: window.window, + }; + } + + version(Windows) + { + + } + Game g = { - rd: InitRenderer(window, MB(24), MB(32)), + rd: InitRenderer(handles, MB(24), MB(32)), arena: CreateArena(MB(32)), frame_arena: CreateArena(MB(16)), window: window, timer: CreateTimer(), }; - UVec2 ext = GetExtent(&g.rd); + UVec2 ext = UVec2(GetExtent(&g.rd)); DescLayoutBinding[2] layout_bindings = [ - { binding: 0, descriptorType: VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, descriptorCount: 1, stageFlags: VK_SHADER_STAGE_ALL }, - { binding: 1, descriptorType: VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, descriptorCount: 1, stageFlags: VK_SHADER_STAGE_ALL }, + { binding: 0, descriptorType: DT.Image, descriptorCount: 1, stageFlags: SS.All }, + { binding: 1, descriptorType: DT.Storage, descriptorCount: 1, stageFlags: SS.All }, ]; g.ui_desc_layout = CreateDescSetLayout(&g.rd, layout_bindings); @@ -126,21 +144,20 @@ InitGame(PlatformWindow* window) ]; GfxPipelineInfo ui_info = { - vertex_shader: "shaders/gui.vert.spv", - frag_shader: "shaders/gui.frag.spv", + vertex_shader: LoadAssetData(&g.frame_arena, "shaders/gui.vert.spv"), + frag_shader: LoadAssetData(&g.frame_arena, "shaders/gui.frag.spv"), input_rate: IR.Instance, input_rate_stride: UIVertex.sizeof, layout: g.ui_layout, vertex_attributes: attributes, }; - g.ui_pipeline = CreateGraphicsPipeline(&g.rd, &ui_info); + assert(CreateGraphicsPipeline(&g.rd, &g.ui_pipeline, &ui_info), "Unable to build UI pipeline"); - PrintShaderDisassembly(&g.rd, g.ui_pipeline, VK_SHADER_STAGE_VERTEX_BIT); - PrintShaderDisassembly(&g.rd, g.ui_pipeline, VK_SHADER_STAGE_FRAGMENT_BIT); - - g.ui_vertex_buf = GetUIVertexBuffer(&g.rd); - g.ui_index_buf = GetUIIndexBuffer(&g.rd); + g.ui_vertex_mapped_buf = CreateMappedBuffer!(UIVertex)(&g.rd, BT.Vertex, UIVertex.sizeof * UI_COUNT); + g.ui_index_mapped_buf = CreateMappedBuffer!(u32)(&g.rd, BT.Index, u32.sizeof * UI_COUNT); + g.ui_vertex_buf = g.ui_vertex_mapped_buf.data; + g.ui_index_buf = g.ui_index_mapped_buf.data; u8[] font_data = LoadAssetData(&g.arena, "fonts/NuberNextCondensed-DemiBold.otf"); g.font = OpenFont(font_data); @@ -202,7 +219,7 @@ Cycle(Game* g) BeginFrame(&g.rd); - UVec2 ext = GetExtent(&g.rd); + UVec2 ext = UVec2(GetExtent(&g.rd)); g.ui_pc.res.x = cast(f32)ext.x; g.ui_pc.res.y = cast(f32)ext.y; @@ -212,7 +229,7 @@ Cycle(Game* g) Bind(&g.rd, g.ui_pipeline, g.ui_desc_set); - BindUIBuffers(&g.rd); + BindBuffers(&g.rd, &g.ui_index_mapped_buf, &g.ui_vertex_mapped_buf); DrawIndexed(&g.rd, 6, g.ui_count, 0); @@ -328,16 +345,12 @@ Sort(Game* g, Vec3 pos, Model* model) makeIndex!("a < b")(lengths, model.pos_indices); - Logf("%s", model.positions.length); - foreach(i, v; model.pos_indices) { model.indices[i+0] = cast(u32)((3*v)+0); model.indices[i+1] = cast(u32)((3*v)+1); model.indices[i+2] = cast(u32)((3*v)+2); } - - UpdateIndexBuffer(&g.rd, model); } void diff --git a/src/gears/main.d b/src/gears/main.d index 0d58576..c6c73bd 100644 --- a/src/gears/main.d +++ b/src/gears/main.d @@ -20,6 +20,7 @@ void main(string[] argv) InitFreeType(); PlatformWindow window = CreateWindow("Video Game", 1920, 1080); + Game g = InitGame(&window); while (true) diff --git a/src/shaders/convert.comp.glsl b/src/shaders/convert.comp.glsl index 4a7f785..1fc038d 100644 --- a/src/shaders/convert.comp.glsl +++ b/src/shaders/convert.comp.glsl @@ -1,9 +1,6 @@ #version 460 #extension GL_EXT_shader_8bit_storage : require -#extension GL_GOOGLE_include_directive : require - -#include "structures.layout" layout (constant_id = 0) const int CHANNELS = 3; diff --git a/src/shared/math.d b/src/shared/math.d index b745e7b..84a0392 100644 --- a/src/shared/math.d +++ b/src/shared/math.d @@ -60,6 +60,11 @@ struct Vector(T, int N) w = f; } + this(Arr)(Arr arr) if (is(Arr: typeof(v))) + { + this.v = arr; + } + this(Args...)(Args args) { static if (args.length == 1) diff --git a/src/shared/util.d b/src/shared/util.d index 374755f..dfaeffd 100644 --- a/src/shared/util.d +++ b/src/shared/util.d @@ -653,8 +653,9 @@ MemCpy(void* dst_p, void* src_p, u64 length) } } -void -MemSet(void* dst, char ch, usize length) +u8[] +Embed(string file_name) { - + import std.file; + return cast(u8[])read(file_name); }