Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glsl shader asset loader #910

Merged
merged 51 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
41bb903
asset: Add asset_source_open util
BastianBlokland Jun 27, 2024
4bc4dfe
asset: Add asset_watch util
BastianBlokland Jun 27, 2024
e882f11
asset: Skeleton glsl loader
BastianBlokland Jun 30, 2024
becb70c
asset: Added glsl global comp
BastianBlokland Jun 30, 2024
7d1d760
asset: Fix const-correctness issue in spv loader
BastianBlokland Jun 30, 2024
f55c57a
asset: Initial error handling for glsl loader
BastianBlokland Jun 30, 2024
251624b
asset: Load libshaderc library
BastianBlokland Jun 30, 2024
1771099
asset: Configure shaderc library name for win32
BastianBlokland Jun 30, 2024
60fa0ec
asset: Tiny cleanup in glsl loader
BastianBlokland Jun 30, 2024
4601795
core: Fix typo
BastianBlokland Jun 30, 2024
78bb1a7
core: Limit max env var val size on linux
BastianBlokland Jun 30, 2024
1e4d16e
core: Add env_var_scratch util
BastianBlokland Jun 30, 2024
d72701a
core: Add dynlib_load_first util
BastianBlokland Jun 30, 2024
17e08fc
asset: Support using libshaderc from the vulkan sdk
BastianBlokland Jun 30, 2024
97975c9
asset: Assert manager entries are never re-used
BastianBlokland Jun 30, 2024
c7c60b9
asset: Fix unsafe pattern loader tests
BastianBlokland Jun 30, 2024
765c448
asset: Support shaderc compiler from VulkanSdk
BastianBlokland Jun 30, 2024
7ea062b
asset: Initialize shaderc compiler
BastianBlokland Jun 30, 2024
ef52ea2
asset: Add error if glsl compiler failed to initialize
BastianBlokland Jun 30, 2024
34e46b8
asset: Initialize shaderc compile options
BastianBlokland Jun 30, 2024
7aa2730
asset: Initialize shaderc optimization settings
BastianBlokland Jun 30, 2024
fad98d9
asset: Initialize shaderc versions
BastianBlokland Jun 30, 2024
01a5668
asset: Preserve shaderc bindings
BastianBlokland Jun 30, 2024
b95fb74
asset: Load shaderc compilation symbol
BastianBlokland Jun 30, 2024
9c150c8
asset: Configure shaderc glsl version
BastianBlokland Jun 30, 2024
f0fbc24
asset: Invoke shaderc compiler
BastianBlokland Jun 30, 2024
01e02df
asset: Output glsl compilation errors
BastianBlokland Jun 30, 2024
1935943
asset: Skeleton for glsl include logic
BastianBlokland Jun 30, 2024
b504751
asset: Add glsl include context
BastianBlokland Jun 30, 2024
ac065f4
asset: Glsl include context
BastianBlokland Jun 30, 2024
7eda686
asset: Glsl result obj alloc logic
BastianBlokland Jun 30, 2024
afe32c9
asset: Initial glsl asset source opening
BastianBlokland Jun 30, 2024
f5c45e4
asset: Batch repo fs source allocations
BastianBlokland Jun 30, 2024
5fefe01
asset: Refactor glsl result object allocation
BastianBlokland Jun 30, 2024
7633188
asset: Initial include resolve logic
BastianBlokland Jun 30, 2024
7bc5fc7
asset: Provide resolved include source id
BastianBlokland Jun 30, 2024
7720a3f
asset: Use asset_repo_source_close util in glsl loader
BastianBlokland Jun 30, 2024
88313bc
asset: Support formats without loaders
BastianBlokland Jun 30, 2024
eb451a9
asset: Define loaders in an array
BastianBlokland Jun 30, 2024
f26096b
asset: Verify include file formats
BastianBlokland Jun 30, 2024
73e2d59
asset: Retrieve spv output in glsl loader
BastianBlokland Jun 30, 2024
4645536
asset: Support memory shader sources
BastianBlokland Jun 30, 2024
9e6833c
asset: Add asset_init_spv_from_mem util
BastianBlokland Jun 30, 2024
620e95a
asset: Add shader init to glsl loader
BastianBlokland Jun 30, 2024
9c30545
asset: Register glsl include dependencies
BastianBlokland Jun 30, 2024
1c92061
asset: Rename asset_shader_spv_init_from_mem util
BastianBlokland Jun 30, 2024
ce1cd09
asset: Restructure glsl compilation
BastianBlokland Jun 30, 2024
620835b
asset: Cleanup glsl spirv init
BastianBlokland Jun 30, 2024
12bcf8a
asset: Fix leaking SpirV allocation
BastianBlokland Jun 30, 2024
b4ac8d2
asset: Make various shaderc symbols optional
BastianBlokland Jun 30, 2024
711a184
asset: Lower Vulkan requirement to 1.2
BastianBlokland Jun 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/asset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_library(lib_asset STATIC
src/loader_product.c
src/loader_raw.c
src/loader_script.c
src/loader_shader_glsl.c
src/loader_shader_spv.c
src/loader_shader.c
src/loader_sound_wav.c
Expand Down
60 changes: 31 additions & 29 deletions libs/asset/src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,38 @@
#include "format_internal.h"

String asset_format_str(const AssetFormat fmt) {
static const String g_names[] = {
string_static("arraytex"),
string_static("atlas"),
string_static("bin"),
string_static("cursor"),
string_static("decal"),
string_static("fonttex"),
string_static("gltf"),
string_static("graphic"),
string_static("inputs"),
string_static("level"),
string_static("obj"),
string_static("ppm"),
string_static("prefabs"),
string_static("procmesh"),
string_static("proctex"),
string_static("products"),
string_static("r16"),
string_static("r32"),
string_static("raw"),
string_static("script"),
string_static("spv"),
string_static("terrain"),
string_static("tga"),
string_static("ttf"),
string_static("vfx"),
string_static("wav"),
string_static("weapons"),
static const String g_names[AssetFormat_Count] = {
[AssetFormat_ArrayTex] = string_static("arraytex"),
[AssetFormat_Atlas] = string_static("atlas"),
[AssetFormat_Bin] = string_static("bin"),
[AssetFormat_Cursor] = string_static("cursor"),
[AssetFormat_Decal] = string_static("decal"),
[AssetFormat_FontTex] = string_static("fonttex"),
[AssetFormat_Glsl] = string_static("glsl"),
[AssetFormat_GlslFrag] = string_static("frag"),
[AssetFormat_GlslVert] = string_static("vert"),
[AssetFormat_Gltf] = string_static("gltf"),
[AssetFormat_Graphic] = string_static("graphic"),
[AssetFormat_Inputs] = string_static("inputs"),
[AssetFormat_Level] = string_static("level"),
[AssetFormat_Obj] = string_static("obj"),
[AssetFormat_Ppm] = string_static("ppm"),
[AssetFormat_Prefabs] = string_static("prefabs"),
[AssetFormat_ProcMesh] = string_static("procmesh"),
[AssetFormat_ProcTex] = string_static("proctex"),
[AssetFormat_Products] = string_static("products"),
[AssetFormat_R16] = string_static("r16"),
[AssetFormat_R32] = string_static("r32"),
[AssetFormat_Raw] = string_static("raw"),
[AssetFormat_Script] = string_static("script"),
[AssetFormat_Spv] = string_static("spv"),
[AssetFormat_Terrain] = string_static("terrain"),
[AssetFormat_Tga] = string_static("tga"),
[AssetFormat_Ttf] = string_static("ttf"),
[AssetFormat_Vfx] = string_static("vfx"),
[AssetFormat_Wav] = string_static("wav"),
[AssetFormat_Weapons] = string_static("weapons"),
};
ASSERT(array_elems(g_names) == AssetFormat_Count, "Incorrect number of asset-format names");
return g_names[fmt];
}

Expand Down
3 changes: 3 additions & 0 deletions libs/asset/src/format_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ typedef enum {
AssetFormat_Cursor,
AssetFormat_Decal,
AssetFormat_FontTex,
AssetFormat_Glsl,
AssetFormat_GlslFrag,
AssetFormat_GlslVert,
AssetFormat_Gltf,
AssetFormat_Graphic,
AssetFormat_Inputs,
Expand Down
92 changes: 48 additions & 44 deletions libs/asset/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,51 @@

#include "loader_internal.h"

#define asset_loader_name(_NAME_) asset_load_##_NAME_

AssetLoader asset_loader(const AssetFormat format) {
#define RET_LOADER(_NAME_) \
void asset_loader_name(_NAME_)(EcsWorld*, String, EcsEntityId, AssetSource*); \
return &asset_loader_name(_NAME_)

// clang-format off
switch (format) {
case AssetFormat_ArrayTex: { RET_LOADER(arraytex); }
case AssetFormat_Atlas: { RET_LOADER(atlas); }
case AssetFormat_Bin: { RET_LOADER(raw); }
case AssetFormat_Cursor: { RET_LOADER(cursor); }
case AssetFormat_Decal: { RET_LOADER(decal); }
case AssetFormat_FontTex: { RET_LOADER(fonttex); }
case AssetFormat_Gltf: { RET_LOADER(gltf); }
case AssetFormat_Graphic: { RET_LOADER(graphic); }
case AssetFormat_Inputs: { RET_LOADER(inputs); }
case AssetFormat_Level: { RET_LOADER(level); }
case AssetFormat_Obj: { RET_LOADER(obj); }
case AssetFormat_Ppm: { RET_LOADER(ppm); }
case AssetFormat_Prefabs: { RET_LOADER(prefabs); }
case AssetFormat_ProcMesh: { RET_LOADER(procmesh); }
case AssetFormat_ProcTex: { RET_LOADER(proctex); }
case AssetFormat_Products: { RET_LOADER(products); }
case AssetFormat_R16: { RET_LOADER(r16); }
case AssetFormat_R32: { RET_LOADER(r32); }
case AssetFormat_Raw: { RET_LOADER(raw); }
case AssetFormat_Script: { RET_LOADER(script); }
case AssetFormat_Spv: { RET_LOADER(spv); }
case AssetFormat_Terrain: { RET_LOADER(terrain); }
case AssetFormat_Tga: { RET_LOADER(tga); }
case AssetFormat_Ttf: { RET_LOADER(ttf); }
case AssetFormat_Vfx: { RET_LOADER(vfx); }
case AssetFormat_Wav: { RET_LOADER(wav); }
case AssetFormat_Weapons: { RET_LOADER(weapons); }
case AssetFormat_Count:
break;
}
// clang-format off

#undef RET_LOADER
diag_crash_msg("No asset loader defined for format: {}", fmt_int(format));
}
// clang-format off

#define ASSET_FOREACH_LOADER(_X_) \
_X_(AssetFormat_ArrayTex, arraytex ) \
_X_(AssetFormat_Atlas, atlas ) \
_X_(AssetFormat_Bin, raw ) \
_X_(AssetFormat_Cursor, cursor ) \
_X_(AssetFormat_Decal, decal ) \
_X_(AssetFormat_FontTex, fonttex ) \
_X_(AssetFormat_GlslFrag, glsl_frag ) \
_X_(AssetFormat_GlslVert, glsl_vert ) \
_X_(AssetFormat_Gltf, gltf ) \
_X_(AssetFormat_Graphic, graphic ) \
_X_(AssetFormat_Inputs, inputs ) \
_X_(AssetFormat_Level, level ) \
_X_(AssetFormat_Obj, obj ) \
_X_(AssetFormat_Ppm, ppm ) \
_X_(AssetFormat_Prefabs, prefabs ) \
_X_(AssetFormat_ProcMesh, procmesh ) \
_X_(AssetFormat_ProcTex, proctex ) \
_X_(AssetFormat_Products, products ) \
_X_(AssetFormat_R16, r16 ) \
_X_(AssetFormat_R32, r32 ) \
_X_(AssetFormat_Raw, raw ) \
_X_(AssetFormat_Script, script ) \
_X_(AssetFormat_Spv, spv ) \
_X_(AssetFormat_Terrain, terrain ) \
_X_(AssetFormat_Tga, tga ) \
_X_(AssetFormat_Ttf, ttf ) \
_X_(AssetFormat_Vfx, vfx ) \
_X_(AssetFormat_Wav, wav ) \
_X_(AssetFormat_Weapons, weapons )

#define ASSET_LOADER_DECLARE(_FORMAT_, _NAME_) void asset_load_##_NAME_(EcsWorld*, String, EcsEntityId, AssetSource*);
ASSET_FOREACH_LOADER(ASSET_LOADER_DECLARE)
#undef ASSET_LOADER_DECLARE

static const AssetLoader g_assetLoaders[AssetFormat_Count] = {
#define ASSET_LOADER_REGISTER(_FORMAT_, _NAME_) [_FORMAT_] = &asset_load_##_NAME_,
ASSET_FOREACH_LOADER(ASSET_LOADER_REGISTER)
};
#undef ASSET_LOADER_REGISTER

#undef ASSET_FOREACH_LOADER

// clang-format on

AssetLoader asset_loader(const AssetFormat format) { return g_assetLoaders[format]; }
9 changes: 8 additions & 1 deletion libs/asset/src/loader_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ static void ecs_destruct_shader_comp(void* data) {

static void ecs_destruct_shader_source_comp(void* data) {
AssetShaderSourceComp* comp = data;
asset_repo_source_close(comp->src);
switch (comp->type) {
case AssetShaderSource_Repository:
asset_repo_source_close(comp->srcRepo);
break;
case AssetShaderSource_Memory:
alloc_free(g_allocHeap, comp->srcMem);
break;
}
}

ecs_view_define(UnloadView) {
Expand Down
Loading