update vulkan library (part 1)

This commit is contained in:
Matthew 2026-03-07 10:44:39 +11:00
parent cad7bc94be
commit e7124105aa
5 changed files with 38 additions and 42 deletions

View File

@ -37,6 +37,6 @@
"dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets", "-unittest"], "dflags": ["-P-I/usr/include/freetype2", "-Jbuild", "-Jassets", "-unittest"],
"dflags-ldc2": ["-link-debuglib"], "dflags-ldc2": ["-link-debuglib"],
"dflags-dmd": [] "dflags-dmd": []
}, }
] ]
} }

@ -1 +1 @@
Subproject commit 3390ee9742fbce758941a0dd216ebec5c75876e5 Subproject commit 38f7bcf3d6c48aaa4fb8e663cec45bd4d2767561

View File

@ -21,7 +21,6 @@ f32 g_delta = 0.0;
struct RenderCtx struct RenderCtx
{ {
PlatformWindow* window; PlatformWindow* window;
Renderer rd;
Descriptor[FS][FO] font_descs; Descriptor[FS][FO] font_descs;
Descriptor default_tex; Descriptor default_tex;
Descriptor sampler; Descriptor sampler;

View File

@ -4,6 +4,7 @@ import editor;
import std.stdio; import std.stdio;
import dlib.alloc; import dlib.alloc;
import dlib.util; import dlib.util;
import dlib.math;
void main(string[] argv) void main(string[] argv)
{ {
@ -41,9 +42,12 @@ void main(string[] argv)
break; break;
} }
if(g_ctx.rd.res != Vec2(window.w, window.h).v) Vec2 current_res = Vec2(window.w, window.h);
if(g_ctx.res != current_res)
{ {
SetExtent(&g_ctx.rd, window.w, window.h); SetExtent(window.w, window.h);
g_ctx.res = current_res;
Ortho(&g_ctx.pc.projection, 0.0, 0.0, current_res.x, current_res.y, -10.0, 10.0);
} }
if(inputs.first == null) if(inputs.first == null)

View File

@ -372,24 +372,24 @@ InitUI(Ctx* ctx)
version(ENABLE_RENDERER) version(ENABLE_RENDERER)
{ {
ctx.rd = InitRenderer(handles, MB(16), MB(8)); InitRenderer(handles, MB(16), MB(8));
DescLayoutBinding[2] layout_bindings = [ DescLayoutBinding[2] layout_bindings = [
{ binding: 0, descriptorType: DT.Image, descriptorCount: FONT_SIZES, stageFlags: SS.All }, { binding: 0, descriptorType: DT.Image, descriptorCount: FONT_SIZES, stageFlags: SS.All },
{ binding: 1, descriptorType: DT.Sampler, descriptorCount: 1, stageFlags: SS.All }, { binding: 1, descriptorType: DT.Sampler, descriptorCount: 1, stageFlags: SS.All },
]; ];
ctx.desc_set_layout = CreateDescSetLayout(&ctx.rd, layout_bindings); ctx.desc_set_layout = CreateDescSetLayout(layout_bindings);
ctx.pipeline_layout = CreatePipelineLayout(&ctx.rd, ctx.desc_set_layout, PushConst.sizeof); ctx.pipeline_layout = CreatePipelineLayout(ctx.desc_set_layout, PushConst.sizeof);
for(u64 i = 0; i < FRAME_OVERLAP; i += 1) for(u64 i = 0; i < FRAME_OVERLAP; i += 1)
{ {
ctx.buffers[i].m_vtx = CreateMappedBuffer!(Vertex)(&ctx.rd, BT.Vertex, VERTEX_MAX_COUNT); ctx.buffers[i].m_vtx = CreateMappedBuffer!(Vertex)(BT.Vertex, VERTEX_MAX_COUNT);
ctx.buffers[i].m_idx = CreateMappedBuffer!(u32)(&ctx.rd, BT.Index, 6); ctx.buffers[i].m_idx = CreateMappedBuffer!(u32)(BT.Index, 6);
ctx.buffers[i].vtx = ctx.buffers[i].m_vtx.data; ctx.buffers[i].vtx = ctx.buffers[i].m_vtx.data;
ctx.buffers[i].idx = ctx.buffers[i].m_idx.data; ctx.buffers[i].idx = ctx.buffers[i].m_idx.data;
ctx.buffers[i].idx[0 .. $] = [0, 1, 2, 2, 1, 3]; ctx.buffers[i].idx[0 .. $] = [0, 1, 2, 2, 1, 3];
ctx.desc_sets[i] = AllocDescSet(&ctx.rd, ctx.desc_set_layout); ctx.desc_sets[i] = AllocDescSet(ctx.desc_set_layout);
ctx.str_arenas[i] = CreateArena(MB(1)); ctx.str_arenas[i] = CreateArena(MB(1));
} }
@ -412,7 +412,7 @@ InitUI(Ctx* ctx)
{ {
for(u32 j = 0; j < ctx.font_descs[i].length; j += 1) for(u32 j = 0; j < ctx.font_descs[i].length; j += 1)
{ {
CreateImageViewTex(&ctx.rd, &ctx.font_descs[i][j], ATLAS_DIMENSION, ATLAS_DIMENSION, DT.Image, 0, j); CreateImageViewTex(&ctx.font_descs[i][j], ATLAS_DIMENSION, ATLAS_DIMENSION, DT.Image, 0, j);
ctx.font_sets[j].index = j; ctx.font_sets[j].index = j;
} }
} }
@ -421,25 +421,25 @@ InitUI(Ctx* ctx)
LoadFontSet(); LoadFontSet();
CreateGraphicsPipeline(&ctx.rd, &ctx.pipeline, &ui_info); CreateGraphicsPipeline(&ctx.pipeline, &ui_info);
ctx.sampler = CreateSampler(&ctx.rd, MipmapMode.Nearest, 1); ctx.sampler = CreateSampler(MipmapMode.Nearest, 1);
u8[512*512*4] white_tex = 255; u8[512*512*4] white_tex = 255;
for(u64 i = 0; i < ctx.font_descs.length; i += 1) for(u64 i = 0; i < ctx.font_descs.length; i += 1)
{ {
for(u32 j = 1; j < ctx.font_descs[i].length; j += 1) for(u32 j = 1; j < ctx.font_descs[i].length; j += 1)
{ {
Transfer(&ctx.rd, &ctx.font_descs[i][j].view, white_tex, ATLAS_DIMENSION, ATLAS_DIMENSION); Transfer(&ctx.font_descs[i][j].view, white_tex, ATLAS_DIMENSION, ATLAS_DIMENSION);
} }
} }
for(u64 i = 0; i < FRAME_OVERLAP; i += 1) for(u64 i = 0; i < FRAME_OVERLAP; i += 1)
{ {
Write(&ctx.rd, ctx.desc_sets[i], ctx.font_descs[i]); Write(ctx.desc_sets[i], ctx.font_descs[i]);
Write(&ctx.rd, ctx.desc_sets[i], &ctx.sampler); Write(ctx.desc_sets[i], &ctx.sampler);
} }
SetClearColors(&ctx.rd, [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 0.0]); SetClearColors([0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 0.0]);
} }
} }
@ -529,12 +529,12 @@ LoadFontSet()
FontSet* fs = ctx.font_sets.ptr + i; FontSet* fs = ctx.font_sets.ptr + i;
if(!fs.loaded[fi]) if(!fs.loaded[fi])
{ {
Transfer(&ctx.rd, &ctx.font_descs[fi][i].view, fs.atlas.data, ATLAS_DIMENSION, ATLAS_DIMENSION); Transfer(&ctx.font_descs[fi][i].view, fs.atlas.data, ATLAS_DIMENSION, ATLAS_DIMENSION);
fs.loaded[fi] = true; fs.loaded[fi] = true;
} }
} }
Write(&ctx.rd, ctx.desc_sets[fi], ctx.font_descs[fi]); Write(ctx.desc_sets[fi], ctx.font_descs[fi]);
ctx.fonts_to_load[fi] = false; ctx.fonts_to_load[fi] = false;
} }
@ -551,14 +551,14 @@ Scissor(Ctx* ctx, Rect rect, Style* style)
i32 w = cast(i32)clamp(floor(rect.p1.x-b) - x, 0.0, ctx.res.x); i32 w = cast(i32)clamp(floor(rect.p1.x-b) - x, 0.0, ctx.res.x);
i32 h = cast(i32)clamp(floor(rect.p1.y-b) - y, 0.0, ctx.res.y); i32 h = cast(i32)clamp(floor(rect.p1.y-b) - y, 0.0, ctx.res.y);
SetScissor(&ctx.rd, x, y, w, h); SetScissor(x, y, w, h);
} }
void void
EndScissor(Ctx* ctx) EndScissor(Ctx* ctx)
{ {
DrawUI(ctx); DrawUI(ctx);
ResetScissor(&ctx.rd); ResetScissor();
} }
void void
@ -1461,7 +1461,7 @@ DrawUI(Ctx* ctx, u32 atlas_index)
{ {
DrawUI(ctx); DrawUI(ctx);
ctx.pc.atlas_index = atlas_index; ctx.pc.atlas_index = atlas_index;
PushConstants(&ctx.rd, ctx.pipeline, &ctx.pc); PushConstants(ctx.pipeline, &ctx.pc);
} }
} }
@ -1474,8 +1474,8 @@ DrawUI(Ctx* ctx)
if(b.vtx_offset != b.count) if(b.vtx_offset != b.count)
{ {
u32 count = b.count - b.vtx_offset; u32 count = b.count - b.vtx_offset;
BindBuffers(&ctx.rd, &b.m_idx, &b.m_vtx); BindBuffers(&b.m_idx, &b.m_vtx);
DrawIndexed(&ctx.rd, 6, count, 0, 0, b.vtx_offset); DrawIndexed(6, count, 0, 0, b.vtx_offset);
b.vtx_offset += count; b.vtx_offset += count;
} }
} }
@ -1611,26 +1611,19 @@ BeginUI(Inputs* inputs)
version(ENABLE_RENDERER) version(ENABLE_RENDERER)
{ {
BeginFrame(&ctx.rd); BeginFrame();
if(ctx.fonts_to_load[ctx.f_idx]) if(ctx.fonts_to_load[ctx.f_idx])
{ {
LoadFontSet(); LoadFontSet();
} }
BeginRendering(&ctx.rd); BeginRendering();
SetStencilTest(&ctx.rd, false); SetStencilTest(false);
Vec2 ext = GetExtent(); PushConstants(ctx.pipeline, &ctx.pc);
if(ext != ctx.res) Bind(ctx.pipeline, ctx.desc_sets[ctx.f_idx]);
{
ctx.res = ext;
Ortho(&ctx.pc.projection, 0.0, 0.0, ext.x, ext.y, -10.0, 10.0);
}
PushConstants(&ctx.rd, ctx.pipeline, &ctx.pc);
Bind(&ctx.rd, ctx.pipeline, ctx.desc_sets[ctx.f_idx]);
} }
else else
{ {
@ -1708,8 +1701,8 @@ EndUI()
version(ENABLE_RENDERER) version(ENABLE_RENDERER)
{ {
DrawUI(ctx); DrawUI(ctx);
FinishRendering(&ctx.rd); FinishRendering();
SubmitAndPresent(&ctx.rd); SubmitAndPresent();
} }
if(!ZeroKey(ctx.drag_key)) if(!ZeroKey(ctx.drag_key))
@ -1954,15 +1947,15 @@ BeginScissor(Ctx* ctx, UIItem* item, bool scissor_x = true, bool scissor_y = tru
i32 w = cast(i32)clamp(scissor_x ? floor(item.rect.p1.x) - x : ctx.res.x, 0.0, ctx.res.x); i32 w = cast(i32)clamp(scissor_x ? floor(item.rect.p1.x) - x : ctx.res.x, 0.0, ctx.res.x);
i32 h = cast(i32)clamp(scissor_y ? floor(item.rect.p1.y) - y : ctx.res.y, 0.0, ctx.res.y); i32 h = cast(i32)clamp(scissor_y ? floor(item.rect.p1.y) - y : ctx.res.y, 0.0, ctx.res.y);
SetScissor(&ctx.rd, x, y, w, h); SetScissor(x, y, w, h);
ResetScissor(&ctx.rd); ResetScissor();
} }
Vec2 Vec2
GetExtent() GetExtent()
{ {
version(ENABLE_RENDERER) return Vec2(RendererGetExtent(&g_ctx.rd)); else return Vec2(1280, 720); version(ENABLE_RENDERER) return Vec2(RendererGetExtent()); else return Vec2(1280, 720);
} }
template template