From 6c66d0211f58554153084ccb5dcc080d57573290 Mon Sep 17 00:00:00 2001 From: matthew Date: Fri, 11 Jul 2025 08:15:43 +1000 Subject: [PATCH] build fixes, vulkan debug fix, asset loading, testing pipeline creation --- assets/shaders/triangle.frag.spv | Bin 0 -> 572 bytes assets/shaders/triangle.vert.spv | Bin 0 -> 1512 bytes build-vma.sh | 24 +++++++ dub.json | 3 +- src/gears/main.d | 21 +++++++ src/gears/vulkan.d | 8 ++- src/gears/vulkan_logging.d | 6 +- src/generated/assets_codegen.d | 24 ++----- src/packer/packer.d | 2 + src/shared/alloc.d | 11 ++++ src/shared/assets.d | 103 ++++++++++++++++++++++++++++++- 11 files changed, 179 insertions(+), 23 deletions(-) create mode 100644 assets/shaders/triangle.frag.spv create mode 100644 assets/shaders/triangle.vert.spv diff --git a/assets/shaders/triangle.frag.spv b/assets/shaders/triangle.frag.spv new file mode 100644 index 0000000000000000000000000000000000000000..c9fb61090d888854d1b7a96b39eb906f3430f92c GIT binary patch literal 572 zcmYjNO-sW-6nssZq&D`;g5IR!Q79g?2-12G*-M~`KVT_Il!cg-G!?x01N}i>1ZUPn zvSs@A&Cc7Ijq98T;&&vJflTFZO~jE7wxRg8s^~eI@2X^eb$v<2P+TjdW+Z`hQHi&W z$$4-990FtL$OnLnpM&~^p|12rMOv-bDtgfIcB^;QN0#c$-K6Gt|0B{f{}I4>>Uqu_E4cDKJo`b)8{iko CJunIY literal 0 HcmV?d00001 diff --git a/assets/shaders/triangle.vert.spv b/assets/shaders/triangle.vert.spv new file mode 100644 index 0000000000000000000000000000000000000000..291e27e7f3c2d208014be6b535c7ceef4428fae1 GIT binary patch literal 1512 zcmYk5ZBNud6oqGZ=`OkgA_Bf37EpWvS5zP-MvXyIO*R2T;@4)=tz?qg-E50dKl#u6 z1O6btn0TJHv+0n#_nvdl?c6&vw3=HT({7lqnKOr`T#Ke@8Vb9nUHG7X*6(Hcu(yA( zhhpBe3L%;WbGe9T^!s&SQ@|D3s%%rXEqf+w>8~mOM@2KL3Ho7hauW29!)QDXv;0RA zhlx$&aA+rSl-qAHy4jk}rcrV+tP4CT>ic@eEA}3bGMn2`nrS~Y^b(Dd(L{u&nS9~% zBs`5LpW{g$e-{*6^2Fq-Pl)XldS)$no91Wsr@Eu2%rTd8M~NN3w^=?&qj;L*q{v+) z$u#HbEI1n${cuLol+Aohhjhd&oZFYl;QWZ*6$h&G<=O9p^2Dre>82dL!r`5c8aVoK z95Ebc80eQiz>h1;{_8Tr4#7QnzD+OSy$W;I)Ps4SXvn{ir=I+w-U4rs znOSK5it*&%2=S)4TVn2pb9*f{y*-f8*E^}{>5&XQJR17r{{#M$H0-%kadJ~`x8j)j zR8`FJM240e_srd~53@d%ah{wReSy)tzMd;~eKG64jNakVF!zBBo_fv({7 a == b)(data[], pack_data[]), "TestFile failure: Asset data does not match file data"); diff --git a/src/shared/alloc.d b/src/shared/alloc.d index 75d3579..e051024 100644 --- a/src/shared/alloc.d +++ b/src/shared/alloc.d @@ -93,3 +93,14 @@ Free(Arena* arena) { pureFree(arena.mem); } + +void +FreeArray(T)(T[] arr) +{ + pureFree(arr.ptr); +} + +void Free(T)(T* ptr) +{ + pureFree(ptr); +} diff --git a/src/shared/assets.d b/src/shared/assets.d index ffc1985..87af0d8 100644 --- a/src/shared/assets.d +++ b/src/shared/assets.d @@ -1,6 +1,30 @@ import aliases; 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; @@ -36,3 +60,80 @@ struct AssetInfo u64 length; 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; + } + } + } +} +