build fixes, vulkan debug fix, asset loading, testing pipeline creation
This commit is contained in:
parent
195acae78c
commit
6c66d0211f
BIN
assets/shaders/triangle.frag.spv
Normal file
BIN
assets/shaders/triangle.frag.spv
Normal file
Binary file not shown.
BIN
assets/shaders/triangle.vert.spv
Normal file
BIN
assets/shaders/triangle.vert.spv
Normal file
Binary file not shown.
24
build-vma.sh
24
build-vma.sh
@ -1,6 +1,30 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
# SHADERS
|
||||||
|
|
||||||
|
shader_compiler="glslc"
|
||||||
|
shader_flags="--target-spv=spv1.6 -std=460"
|
||||||
|
shader_out="-oassets/shaders/"
|
||||||
|
|
||||||
|
mkdir -p assets/shaders
|
||||||
|
|
||||||
|
for shader in src/shaders/*.glsl; do
|
||||||
|
base_name=$(basename -- "$shader" .glsl)
|
||||||
|
|
||||||
|
case "$base_name" in
|
||||||
|
*.vert) shader_stage="-fshader-stage=vert" ;;
|
||||||
|
*.frag) shader_stage="-fshader-stage=frag" ;;
|
||||||
|
*.tesc) shader_stage="-fshader-stage=tesc" ;;
|
||||||
|
*.tese) shader_stage="-fshader-stage=tese" ;;
|
||||||
|
*.geom) shader_stage="-fshader-stage=geom" ;;
|
||||||
|
*.comp) shader_stage="-fshader-stage=comp" ;;
|
||||||
|
*) continue ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
$shader_compiler $shader_flags $shader_stage $shader "${shader_out}${base_name}.spv"
|
||||||
|
done
|
||||||
|
|
||||||
if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc";
|
if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc";
|
||||||
elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang";
|
elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang";
|
||||||
else echo "Unable to find c++ cpp_compiler"; exit -1; fi;
|
else echo "Unable to find c++ cpp_compiler"; exit -1; fi;
|
||||||
|
|||||||
3
dub.json
3
dub.json
@ -13,7 +13,7 @@
|
|||||||
"sourcePaths": ["src/gears", "src/shared", "src/generated"],
|
"sourcePaths": ["src/gears", "src/shared", "src/generated"],
|
||||||
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"],
|
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"],
|
||||||
"libs-windows": [],
|
"libs-windows": [],
|
||||||
"preGenerateCommands-linux": ["./build-vma.sh"],
|
"preGenerateCommands-linux": ["./build-vma.sh", "build/Packer"],
|
||||||
"preGenerateCommands-windows": [],
|
"preGenerateCommands-windows": [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -37,6 +37,7 @@
|
|||||||
"sourceFiles-linux": ["build/libxxhash.a", "build/libstb_image.a"],
|
"sourceFiles-linux": ["build/libxxhash.a", "build/libstb_image.a"],
|
||||||
"preGenerateCommands-linux": ["./build-vma.sh"],
|
"preGenerateCommands-linux": ["./build-vma.sh"],
|
||||||
"preGenerateCommands-windows": [],
|
"preGenerateCommands-windows": [],
|
||||||
|
"versions": ["codegen"],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,13 +6,34 @@ import u = util : Result;
|
|||||||
import p = platform;
|
import p = platform;
|
||||||
import a = alloc;
|
import a = alloc;
|
||||||
import vk = vulkan : Vulkan;
|
import vk = vulkan : Vulkan;
|
||||||
|
import ap = assets;
|
||||||
|
import r = renderer;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
p.Window window = p.CreateWindow("Video Game", 1920, 1080);
|
p.Window window = p.CreateWindow("Video Game", 1920, 1080);
|
||||||
|
|
||||||
|
assert(ap.OpenAssetPack(), "OpenAssetPack failure");
|
||||||
|
|
||||||
Result!(Vulkan) result = vk.Init(&window, u.MB(24), u.MB(32));
|
Result!(Vulkan) result = vk.Init(&window, u.MB(24), u.MB(32));
|
||||||
Vulkan vulkan = result.value;
|
Vulkan vulkan = result.value;
|
||||||
|
|
||||||
|
u8[] vert_bytes = ap.LoadAssetData("shaders/triangle.vert");
|
||||||
|
u8[] frag_bytes = ap.LoadAssetData("shaders/triangle.frag");
|
||||||
|
|
||||||
|
assert(vert_bytes != null && frag_bytes != null, "Unable to load shader data");
|
||||||
|
|
||||||
|
auto vert_module = vk.BuildShader(&vulkan, vert_bytes);
|
||||||
|
auto frag_module = vk.BuildShader(&vulkan, frag_bytes);
|
||||||
|
|
||||||
|
assert(vert_module.ok && frag_module.ok, "Unable to build vulkan shaders");
|
||||||
|
|
||||||
|
r.GfxPipelineInfo pipeline_info = {
|
||||||
|
vertex_shader: vert_module.value,
|
||||||
|
frag_shader: frag_module.value,
|
||||||
|
};
|
||||||
|
|
||||||
|
auto pipeline = vk.CreateGraphicsPipeline(&vulkan, &pipeline_info);
|
||||||
|
|
||||||
vk.Destroy(&vulkan);
|
vk.Destroy(&vulkan);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -313,17 +313,18 @@ CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info)
|
|||||||
{
|
{
|
||||||
sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
stage: VK_SHADER_STAGE_VERTEX_BIT,
|
stage: VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
module: cast(VkShaderModule)build_info.vertex_shader,
|
|
||||||
pName: "main",
|
pName: "main",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
stage: VK_SHADER_STAGE_FRAGMENT_BIT,
|
stage: VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
module: cast(VkShaderModule)build_info.frag_shader,
|
|
||||||
pName: "main",
|
pName: "main",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
__traits(getMember, shader_info.ptr + 0, "module") = build_info.vertex_shader;
|
||||||
|
__traits(getMember, shader_info.ptr + 1, "module") = build_info.frag_shader;
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo create_info = {
|
VkGraphicsPipelineCreateInfo create_info = {
|
||||||
sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
sType: VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
pNext: &rendering_info,
|
pNext: &rendering_info,
|
||||||
@ -342,6 +343,9 @@ CreateGraphicsPipeline(Vulkan* vk, GfxPipelineInfo* build_info)
|
|||||||
|
|
||||||
VkPipeline pipeline;
|
VkPipeline pipeline;
|
||||||
|
|
||||||
|
VkResult result = vkCreateGraphicsPipelines(vk.device, null, 1, &create_info, null, &pipeline);
|
||||||
|
assert(VkCheck("CreateGraphicsPipeline failure", result), "Unable to build pipeline");
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
public import includes;
|
public import includes;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import vulkan : Vulkan;
|
import vulkan : Vulkan;
|
||||||
|
import std.conv;
|
||||||
|
import std.string;
|
||||||
|
|
||||||
VkBool32
|
VkBool32
|
||||||
DebugCallback(
|
DebugCallback(
|
||||||
@ -57,7 +59,9 @@ DebugCallback(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
writefln("[%s: %s]\n%s\n", ms, mt, callback_data.pMessage);
|
string msg = to!string(callback_data.pMessage);
|
||||||
|
|
||||||
|
writefln("[%s: %s]\n%r\n", ms, mt, msg);
|
||||||
|
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,30 +26,18 @@ static immutable u64[] MODEL_HASHES = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
static immutable string[] SHADER_FILES = [
|
static immutable string[] SHADER_FILES = [
|
||||||
"shaders/gui.frag.spv",
|
"shaders/triangle.vert.spv",
|
||||||
"shaders/pbr.frag.spv",
|
"shaders/triangle.frag.spv",
|
||||||
"shaders/gui.vert.spv",
|
|
||||||
"shaders/quad.frag.spv",
|
|
||||||
"shaders/quad.vert.spv",
|
|
||||||
"shaders/pbr.vert.spv",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
static immutable string[] SHADER_NAMES = [
|
static immutable string[] SHADER_NAMES = [
|
||||||
"shaders/gui.frag",
|
"shaders/triangle.vert",
|
||||||
"shaders/pbr.frag",
|
"shaders/triangle.frag",
|
||||||
"shaders/gui.vert",
|
|
||||||
"shaders/quad.frag",
|
|
||||||
"shaders/quad.vert",
|
|
||||||
"shaders/pbr.vert",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
static immutable u64[] SHADER_HASHES = [
|
static immutable u64[] SHADER_HASHES = [
|
||||||
15780387719315455808,
|
8769314645675479020,
|
||||||
2230071466542309169,
|
6282520872716708711,
|
||||||
14797956403837654625,
|
|
||||||
8430018914716708078,
|
|
||||||
14432191255225961360,
|
|
||||||
8518761701216801634,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
static immutable string[] TEXTURE_FILES = [
|
static immutable string[] TEXTURE_FILES = [
|
||||||
|
|||||||
@ -149,6 +149,8 @@ TestFile()
|
|||||||
u8[] data = asset.rawRead(new u8[asset.size()]);
|
u8[] data = asset.rawRead(new u8[asset.size()]);
|
||||||
assert(data.length == info.length, "TestFile failure: File length read is incorrect");
|
assert(data.length == info.length, "TestFile failure: File length read is incorrect");
|
||||||
|
|
||||||
|
assert(hashes[i] == info.hash, "TestFile failure: File hash is incorrect");
|
||||||
|
|
||||||
ap.seek(info.offset);
|
ap.seek(info.offset);
|
||||||
u8[] pack_data = ap.rawRead(new u8[info.length]);
|
u8[] pack_data = ap.rawRead(new u8[info.length]);
|
||||||
assert(equal!((a, b) => a == b)(data[], pack_data[]), "TestFile failure: Asset data does not match file data");
|
assert(equal!((a, b) => a == b)(data[], pack_data[]), "TestFile failure: Asset data does not match file data");
|
||||||
|
|||||||
@ -93,3 +93,14 @@ Free(Arena* arena)
|
|||||||
{
|
{
|
||||||
pureFree(arena.mem);
|
pureFree(arena.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FreeArray(T)(T[] arr)
|
||||||
|
{
|
||||||
|
pureFree(arr.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Free(T)(T* ptr)
|
||||||
|
{
|
||||||
|
pureFree(ptr);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,30 @@
|
|||||||
import aliases;
|
import aliases;
|
||||||
import std.file;
|
import std.file;
|
||||||
import assets_codegen;
|
import std.stdio;
|
||||||
|
import util;
|
||||||
|
import std.exception;
|
||||||
|
import alloc;
|
||||||
|
|
||||||
|
version(codegen)
|
||||||
|
{
|
||||||
|
const u64 ASSET_COUNT = 0;
|
||||||
|
|
||||||
|
enum AssetType { None };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
import assets_codegen;
|
||||||
|
|
||||||
|
const u64 ASSET_COUNT = MODEL_FILES.length + SHADER_FILES.length + TEXTURE_FILES.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
File Asset_File;
|
||||||
|
|
||||||
|
FileHeader Asset_Header;
|
||||||
|
|
||||||
|
AssetInfo[ASSET_COUNT] Asset_Info;
|
||||||
|
|
||||||
|
u8[][ASSET_COUNT] Asset_Data;
|
||||||
|
|
||||||
const u32 FILE_VERSION = 1;
|
const u32 FILE_VERSION = 1;
|
||||||
|
|
||||||
@ -36,3 +60,80 @@ struct AssetInfo
|
|||||||
u64 length;
|
u64 length;
|
||||||
AssetType type;
|
AssetType type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OpenAssetPack()
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
string file_path = isFile("build/assets.sgp") ? "build/assets.sgp" : "assets.sgp";
|
||||||
|
|
||||||
|
// TODO: replace this with something that doesn't throw an exception and figure out if this is the best way to handle thing (probably isnt)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Asset_File = File(file_path, "rb");
|
||||||
|
}
|
||||||
|
catch (ErrnoException e)
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
Logf("OpenAssetPack failure: Unable to open file %s", file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileHeader[1] header_arr;
|
||||||
|
|
||||||
|
Asset_File.rawRead(header_arr);
|
||||||
|
|
||||||
|
Asset_Header = header_arr[0];
|
||||||
|
|
||||||
|
assert(Asset_Header.file_version == FILE_VERSION, "OpenAssetPack failure: file version incorrect");
|
||||||
|
|
||||||
|
Asset_File.seek(Asset_Header.asset_info_offset);
|
||||||
|
|
||||||
|
Asset_File.rawRead(Asset_Info);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8[]
|
||||||
|
LoadAssetData(string name)
|
||||||
|
{
|
||||||
|
u64 hash = Hash(name);
|
||||||
|
u8[] data = null;
|
||||||
|
|
||||||
|
foreach(i, info; Asset_Info)
|
||||||
|
{
|
||||||
|
if (info.hash == hash)
|
||||||
|
{
|
||||||
|
if (Asset_Data[i].ptr == null)
|
||||||
|
{
|
||||||
|
Asset_Data[i] = AllocArray!(u8)(info.length);
|
||||||
|
Asset_File.seek(info.offset);
|
||||||
|
Asset_File.rawRead(Asset_Data[i]);
|
||||||
|
assert(Asset_Data[i] != null && Asset_Data[i].length == info.length, "LoadAssetData failure: Asset data loaded incorrectly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
data = Asset_Data[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UnloadAssetData(string name)
|
||||||
|
{
|
||||||
|
u64 hash = Hash(name);
|
||||||
|
|
||||||
|
foreach(i, info; Asset_Info)
|
||||||
|
{
|
||||||
|
if (info.hash == hash)
|
||||||
|
{
|
||||||
|
if (Asset_Data[i] != null)
|
||||||
|
{
|
||||||
|
FreeArray(Asset_Data[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user