update vulkan library, fix bugs

This commit is contained in:
Matthew 2026-03-07 19:58:44 +11:00
parent e7124105aa
commit fc67f2512d
3 changed files with 61 additions and 58 deletions

@ -1 +1 @@
Subproject commit 38f7bcf3d6c48aaa4fb8e663cec45bd4d2767561 Subproject commit 0c5521153f63001273170b09b15a5eaabb289885

View File

@ -20,16 +20,16 @@ f32 g_delta = 0.0;
struct RenderCtx struct RenderCtx
{ {
PlatformWindow* window; PlatformWindow* window;
Descriptor[FS][FO] font_descs; Descriptor[FS] font_descs;
Descriptor default_tex; Descriptor default_tex;
Descriptor sampler; Descriptor sampler;
Pipeline pipeline; Pipeline pipeline;
DescSetLayout desc_set_layout; DescSetLayout desc_set_layout;
DescSet[FO] desc_sets; DescSet[FO] desc_sets;
PipelineLayout pipeline_layout; PipelineLayout pipeline_layout;
PushConst pc; PushConst pc;
Vec2 res; Vec2 res;
} }
struct Ctx struct Ctx

View File

@ -26,14 +26,14 @@ import core.stdc.stdio : sprintf;
- Display string should be separate from key string - Display string should be separate from key string
- If key is 0 then its transient and will be discarded next frame - If key is 0 then its transient and will be discarded next frame
- Events should be created then processed instead of directly from inputs - Events should be created then processed instead of directly from inputs
// Little mode ui thing in the corner thats colored and it slides the colour out (left to right) when mode is changed - Little mode ui thing in the corner thats colored and it slides the colour out (left to right) when mode is changed
*********************************/ *********************************/
enum Vec4 BORDER_COL = SRGBVec4(0.254, 0.254, 0.266, 1.0); enum Vec4 BORDER_COL = SRGBVec4(0.254, 0.254, 0.266, 1.0);
enum Vec4 BORDER_HL_COL = SRGBVec4(0.035, 0.549, 0.824, 1.0); enum Vec4 BORDER_HL_COL = SRGBVec4(0.035, 0.549, 0.824, 1.0);
enum Vec4 TEXT_COL = SRGBVec4(1.0); enum Vec4 TEXT_COL = SRGBVec4(1.0);
enum Vec4 TEXT_HL_COL = SRGBVec4(0.0, 0.0, 0.0, 1.0); enum Vec4 TEXT_HL_COL = SRGBVec4(0.0, 0.0, 0.0, 1.0);
enum Vec4 BG_COL = Vec4(0.18, 0.18, 0.18, 1.0); enum Vec4 BG_COL = Vec4(0.18, 0.18, 0.18, 1.0);
enum Vec4 BG_HL_COL = Vec4(0.160, 0.533, 0.803, 1.0); enum Vec4 BG_HL_COL = Vec4(0.160, 0.533, 0.803, 1.0);
enum Vec4 HL_BORDER_COL = Vec4(0.172, 0.643, 0.988, 1.0); enum Vec4 HL_BORDER_COL = Vec4(0.172, 0.643, 0.988, 1.0);
@ -187,10 +187,11 @@ enum FS = FONT_SIZES;
struct FontSet struct FontSet
{ {
FontAtlas atlas; FontAtlas atlas;
u32 size; u32 size;
u32 index; u32 index;
bool[FRAME_OVERLAP] loaded; bool texture_loaded;
bool[FO] descriptor_written;
alias atlas this; alias atlas this;
} }
@ -408,38 +409,46 @@ InitUI(Ctx* ctx)
alpha_op: BO.Add, alpha_op: BO.Add,
}; };
for(u64 i = 0; i < ctx.font_descs.length; i += 1) for(u32 i = 0; i < ctx.font_descs.length; i += 1)
{ {
for(u32 j = 0; j < ctx.font_descs[i].length; j += 1) CreateDescriptor(&ctx.font_descs[i], DescInfo(
{ type: DT.Image,
CreateImageViewTex(&ctx.font_descs[i][j], ATLAS_DIMENSION, ATLAS_DIMENSION, DT.Image, 0, j); format: FMT.RGBA_UNORM,
ctx.font_sets[j].index = j; usage: IU.Texture,
} w: ATLAS_DIMENSION,
h: ATLAS_DIMENSION,
ch: 4,
binding: 0,
index: i,
));
ctx.font_sets[i].index = i;
} }
FontSet* atlas = GetFontSet(14);
LoadFontSet();
CreateGraphicsPipeline(&ctx.pipeline, &ui_info); CreateGraphicsPipeline(&ctx.pipeline, &ui_info);
ctx.sampler = CreateSampler(MipmapMode.Nearest, 1); CreateDescriptor(&ctx.sampler, DescInfo(
type: DT.Sampler,
mipmap_mode: MipmapMode.Nearest,
binding: 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) Transfer!(true)(&ctx.font_descs[i], white_tex);
{
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.desc_sets[i], ctx.font_descs[i]); Write(ctx.desc_sets[i], ctx.font_descs);
Write(ctx.desc_sets[i], &ctx.sampler); Write(ctx.desc_sets[i], &ctx.sampler);
} }
SetClearColors([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]);
FontSet* atlas = GetFontSet(14);
LoadFontSet();
} }
} }
@ -502,17 +511,15 @@ GetFontSet(u32 size)
if(!fs) if(!fs)
{ {
u32 i = ctx.font_sets_used; fs = &ctx.font_sets[ctx.font_sets_used++];
fs = &ctx.font_sets[i]; ctx.fonts_to_load = true;
assert(ctx.font); assert(ctx.font);
fs.atlas = CreateAtlas(&ctx.arena, ctx.font, size, UVec2(ATLAS_DIMENSION)); fs.atlas = CreateAtlas(&ctx.arena, ctx.font, size, UVec2(ATLAS_DIMENSION));
fs.size = size; fs.size = size;
fs.loaded = false; fs.texture_loaded = false;
fs.descriptor_written = false;
ctx.fonts_to_load = true;
ctx.font_sets_used += 1;
} }
return fs; return fs;
@ -522,20 +529,24 @@ void
LoadFontSet() LoadFontSet()
{ {
Ctx* ctx = GetCtx(); Ctx* ctx = GetCtx();
u64 fi = ctx.f_idx; u64 fi = ctx.f_idx;
for(u64 i = 0; i < ctx.font_sets_used; i += 1) for(u64 i = 0; i < ctx.font_sets_used; i += 1)
{ {
FontSet* fs = ctx.font_sets.ptr + i; FontSet* fs = ctx.font_sets.ptr + i;
if(!fs.loaded[fi]) if(!fs.texture_loaded)
{ {
Transfer(&ctx.font_descs[fi][i].view, fs.atlas.data, ATLAS_DIMENSION, ATLAS_DIMENSION); Transfer!(true)(&ctx.font_descs[i], fs.atlas.data);
fs.loaded[fi] = true; fs.texture_loaded = true;
}
if(!fs.descriptor_written[fi])
{
Write(ctx.desc_sets[fi], ctx.font_descs);
fs.descriptor_written[fi] = true;
} }
} }
Write(ctx.desc_sets[fi], ctx.font_descs[fi]);
ctx.fonts_to_load[fi] = false; ctx.fonts_to_load[fi] = false;
} }
@ -1625,14 +1636,6 @@ BeginUI(Inputs* inputs)
PushConstants(ctx.pipeline, &ctx.pc); PushConstants(ctx.pipeline, &ctx.pc);
Bind(ctx.pipeline, ctx.desc_sets[ctx.f_idx]); Bind(ctx.pipeline, ctx.desc_sets[ctx.f_idx]);
} }
else
{
Vec2 ext = GetExtent();
if(ext != ctx.res)
{
ctx.res = ext;
}
}
memset(ctx.buffers[ctx.f_idx].vtx.ptr, 0, Vertex.sizeof * ctx.buffers[ctx.f_idx].count); memset(ctx.buffers[ctx.f_idx].vtx.ptr, 0, Vertex.sizeof * ctx.buffers[ctx.f_idx].count);
ctx.buffers[ctx.f_idx].count = 0; ctx.buffers[ctx.f_idx].count = 0;