more setup

This commit is contained in:
matthew 2025-10-28 07:16:56 +11:00
parent 20caf5ea4d
commit f9cf8e26ab
9 changed files with 140 additions and 83 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,6 +13,7 @@
"sourcePaths": ["src/gears", "src/dlib", "src/dlib/external/xxhash", "src/VulkanRenderer"],
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++", "xcb-xfixes", "freetype"],
"libs-windows": [],
"versions": ["VULKAN_DEBUG"],
"preGenerateCommands-linux": ["./build.sh"],
"preGenerateCommands-windows": [],
"dflags": ["-Xcc=-mno-sse", "-P-I/usr/include/freetype2", "-vgc", "-Jbuild", "-Jassets/fonts"],
@ -25,7 +26,7 @@
"targetName": "Packer",
"importPaths": ["src/packer", "src/shared", "external/xxhash", "external/inteli"],
"sourcePaths": ["src/packer", "src/shared", "external/xxhash", "external/inteli"],
"sourceFiles-linux": ["build/libstb.a", "build/libm3d.a", "build/libcglm.a"],
"sourceFiles-linux": ["build/libstb.a", "build/libm3d.a", "build/libcglm.a", "build/libspirv_reflect.a"],
"preGenerateCommands-linux": ["./build.sh"],
"postGenerateCommands-linux": [],
"preGenerateCommands-windows": [],

@ -1 +1 @@
Subproject commit 6021713286482893ca0614c894419290c6f425d4
Subproject commit 53c500c302e87799b01bb99356780c9c51b41170

View File

@ -1,60 +0,0 @@
import dlib;
import vulkan;
struct GameState
{
RenderState rds;
}
struct RenderState
{
Renderer rd;
struct
{
Pipeline pbr;
} pipelines;
struct
{
DescSetLayout globals;
DescSetLayout resources;
} desc_layouts;
struct
{
DescSet pbr;
} desc_sets;
struct
{
PipelineLayout pbr;
} layouts;
}
GameState
InitGame(PlatformWindow* window)
{
GameState g;
Init(&g.rds);
}
void
Init(RendererState* rds, PlatformWindow* window)
{
version(linux)
{
PlatformHandles handles = {
conn: window.conn,
window: window.window,
};
}
rds.rd = InitRenderer(handles, MB(24), MB(32));
DescLayoutBinding[5] bindings = [
{ binding: 0, descriptorType: DT.Image, descriptorCount: 1, stageFlags: SS.All },
{ binding: 1, descriptorType: DT.Storage, descriptorCount: 1, stageFlags: SS.All },
{ binding: 2, descriptorType: DT.Uniform, descriptorCount: 1, stageFlags: SS.All },
];
rds.desc_layouts.pbr =
}

127
src/gears/game2.d Normal file
View File

@ -0,0 +1,127 @@
import dlib;
import vulkan;
const u32 IMG_MAX = 100;
const u32 BUF_MAX = 25;
const u32 UNI_MAX = 50;
struct GameState
{
RenderState rds;
}
struct RenderState
{
Renderer rd;
Arena[2] frame_arenas;
Pipeline pipeline_pbr;
DescSetLayout desc_layout_globals;
DescSetLayout desc_layout_resources;
DescSet[2] desc_set_globals;
DescSet[2] desc_set_resources;
PipelineLayout pipeline_layout_pbr;
}
struct PushConst
{
union
{
struct
{
u32 t0;
u32 t1;
u32 t2;
u32 t3;
u32 m0;
u32 s0;
};
struct
{
u32 albedo;
u32 ambient;
u32 specular;
u32 alpha;
u32 material;
u32 state;
};
}
}
struct Vertex
{
Vec4 col;
Vec4 tangent;
Vec3 pos;
Vec3 normal;
Vec2 uv;
}
GameState
InitGame(PlatformWindow* window)
{
GameState g;
Init(&g.rds, window);
return g;
}
void
Init(RenderState* rds, PlatformWindow* window)
{
version(linux)
{
PlatformHandles handles = {
conn: window.conn,
window: window.window,
};
}
DescLayoutBinding[5] global_bindings = [
{ binding: 0, descriptorType: DT.Uniform, descriptorCount: 1, stageFlags: SS.All },
{ binding: 1, descriptorType: DT.StorageTexelBuf, descriptorCount: 1, stageFlags: SS.All },
{ binding: 2, descriptorType: DT.StorageImage, descriptorCount: 1, stageFlags: SS.All },
];
DescLayoutBinding[3] resource_bindings = [
{ binding: 0, descriptorType: DT.Image, descriptorCount: IMG_MAX, stageFlags: SS.All },
{ binding: 1, descriptorType: DT.Uniform, descriptorCount: BUF_MAX, stageFlags: SS.All },
{ binding: 2, descriptorType: DT.Uniform, descriptorCount: UNI_MAX, stageFlags: SS.All },
];
Attribute[5] attributes = [
{ binding: 0, location: 0, format: FMT.RGBA_F32, offset: Vertex.col.offsetof },
{ binding: 0, location: 1, format: FMT.RGBA_F32, offset: Vertex.tangent.offsetof },
{ binding: 0, location: 2, format: FMT.RGB_F32, offset: Vertex.pos.offsetof },
{ binding: 0, location: 3, format: FMT.RGB_F32, offset: Vertex.normal.offsetof },
{ binding: 0, location: 4, format: FMT.RG_F32, offset: Vertex.uv.offsetof },
];
rds.rd = InitRenderer(handles, MB(24), MB(32));
rds.frame_arenas = [
CreateArena(MB(4)),
CreateArena(MB(4)),
];
rds.desc_layout_globals = CreateDescSetLayout(&rds.rd, global_bindings);
rds.desc_layout_resources = CreateDescSetLayout(&rds.rd, resource_bindings);
rds.pipeline_layout_pbr = CreatePipelineLayout(&rds.rd, [rds.desc_layout_globals, rds.desc_layout_resources], PushConst.sizeof);
foreach(i; 0 .. 2)
{
rds.desc_set_globals[i] = AllocDescSet(&rds.rd, rds.desc_layout_globals);
rds.desc_set_resources[i] = AllocDescSet(&rds.rd, rds.desc_layout_resources);
}
GfxPipelineInfo pbr_info = {
vertex_shader: LoadAssetData(&rds.frame_arenas[0], "shaders/pbr.vert.spv"),
frag_shader: LoadAssetData(&rds.frame_arenas[0], "shaders/pbr.frag.spv"),
input_rate: IR.Vertex,
input_rate_stride: Vertex.sizeof,
layout: rds.pipeline_layout_pbr,
vertex_attributes: attributes,
};
bool result = CreateGraphicsPipeline(&rds.rd, &rds.pipeline_pbr, &pbr_info);
assert(result);
}

View File

@ -1,7 +1,7 @@
import dlib;
import std.stdio;
import core.memory;
import game;
import game2;
import core.simd;
import core.stdc.string : memcpy;
@ -9,19 +9,6 @@ void main(string[] argv)
{
PlatformWindow window = CreateWindow("Video Game", 1920, 1080);
Game g = InitGame(&window);
while (true)
{
g.inputs = GetInputs(&window);
if (window.close)
{
break;
}
Cycle(&g);
}
Destroy(&g);
GameState g = InitGame(&window);
}

View File

@ -19,7 +19,9 @@ layout (rgba16f, set = 0, binding = 0) uniform image2D DrawImage;
layout (set = 0, binding = 1) uniform sampler SamplerNearest;
layout (set = 0, binding = 0) uniform Globals {
// SET 1
layout (set = 1, binding = 0) uniform Globals {
mat4 view;
mat4 projection;
vec4 light_color;
@ -28,15 +30,15 @@ layout (set = 0, binding = 0) uniform Globals {
vec2 res;
} G;
layout (set = 0, binding = 1, rg32ui) uniform coherent uimageBuffer ImageABuffer;
layout (set = 1, binding = 1, rg32ui) uniform coherent uimageBuffer ImageABuffer;
layout (set = 0, binding = 2, r32ui) uniform coherent uimage2D ImageAux;
layout (set = 2, binding = 2, r32ui) uniform coherent uimage2D ImageAux;
// SET 2
layout (set = 2, binding = 0) uniform texture2D Textures[IMG_MAX];
layout (set = 1, binding = 0) uniform texture2D Textures[IMG_MAX];
layout (set = 2, binding = 1) uniform Material {
layout (set = 1, binding = 1) uniform Material {
vec4 ambient;
vec4 diffuse;
vec4 specular;
@ -48,7 +50,7 @@ layout (set = 2, binding = 1) uniform Material {
float alpha;
} Materials[BUF_MAX];
layout (set = 2, binding = 2) uniform ModelState {
layout (set = 1, binding = 2) uniform ModelState {
mat4 model_matrix;
} State[UNI_MAX];