compiling with vulkan as external library

This commit is contained in:
matthew 2025-08-16 09:38:53 +10:00
parent 89d2cb7407
commit acbfe339ab
7 changed files with 44 additions and 27 deletions

Binary file not shown.

@ -1 +1 @@
Subproject commit c6a92fa58a25fc204198bcd158e170847344d799
Subproject commit 7a10601f51b651db006de6d1c5cafb547f90dc87

View File

@ -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,6 +77,8 @@ struct Game
DescSet ui_desc_set;
PipelineLayout ui_layout;
MappedBuffer!(UIVertex) ui_vertex_mapped_buf;
MappedBuffer!(u32) ui_index_mapped_buf;
UIVertex[] ui_vertex_buf;
u32[] ui_index_buf;
u32 ui_count;
@ -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

View File

@ -20,6 +20,7 @@ void main(string[] argv)
InitFreeType();
PlatformWindow window = CreateWindow("Video Game", 1920, 1080);
Game g = InitGame(&window);
while (true)

View File

@ -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;

View File

@ -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)

View File

@ -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);
}