add codegen for asset structures for asset rework, wip rework

This commit is contained in:
Matthew 2025-05-25 20:44:36 +10:00
parent 31d4066acf
commit 2054fad364
23 changed files with 1348 additions and 747 deletions

View File

@ -112,6 +112,9 @@ if ! [ -f libvma.a ]; then
rm vma.o
fi
# Packer Codegen
$compile $packer_source_files $compile_link $link_os_gfx $packer_flags -DBUILD_ASSET_CODEGEN $packer_include_flags $out PackerCodegen
# Packer
if [ -v packer ] || ! [ -f Packer ]; then
$compile $packer_source_files $compile_link $link_os_gfx $packer_flags $packer_include_flags $out $packer_out_name
@ -121,5 +124,6 @@ if [ -v pack ] || ! [ -f assets.sgp ]; then
./Packer
fi
if ! [ -v packer ]; then
$compile $source_files $compile_link $link_os_gfx $out $out_name
fi

View File

@ -1,16 +1,23 @@
// ::Allocator::Globals::
FLAlloc FL_ALLOC = {0};
Allocator ALLOC = {0};
read_only FLNode FL_NIL_NODE = {0};
read_only FreeList FL_NIL_LIST = {0};
FLAlloc
FL_ALLOC = {0};
Allocator
ALLOC = {0};
read_only FLNode
FL_NIL_NODE = {0};
read_only FreeList
FL_NIL_LIST = {0};
constexpr usize FL_GLOBAL_SIZE = MB(32);
static b32 FL_GLOBAL_INIT = false;
constexpr usize
FL_GLOBAL_SIZE = MB(32);
static b32
FL_GLOBAL_INIT = false;
// ::Allocator::Util::Header::
static inline usize CalcPaddingWithHeader(uintptr ptr, uintptr alignment, usize header_size)
static inline usize
CalcPaddingWithHeader(uintptr ptr, uintptr alignment, usize header_size)
{
Assert(IsPow2(alignment), "Alignment provided to CalcPaddingWithHeader is not a power of two");
@ -30,7 +37,8 @@ static inline usize CalcPaddingWithHeader(uintptr ptr, uintptr alignment, usize
return (usize)padding;
}
static inline usize CalcPadding(uintptr ptr, uintptr alignment)
static inline usize
CalcPadding(uintptr ptr, uintptr alignment)
{
Assert(IsPow2(alignment), "CalcPadding failure: IsPow2 failed");
@ -44,7 +52,8 @@ static inline usize CalcPadding(uintptr ptr, uintptr alignment)
// ::Allocator::Arena::Start::
static Arena *ArenaInit(rawptr buffer, usize size)
static Arena *
ArenaInit(rawptr buffer, usize size)
{
Arena *arena = (Arena *)buffer;
buffer = PtrAdd(buffer, ARENA_HEADER_SIZE);
@ -56,20 +65,23 @@ static Arena *ArenaInit(rawptr buffer, usize size)
return arena;
}
static Arena *ArenaCreate(usize size)
static Arena *
ArenaCreate(usize size)
{
u8 *mem = pMemAllocZeroed(size);
return ArenaInit(mem, size);
}
static Arena *ArenaCreateDebug(usize size, u32 init_line_no)
static Arena *
ArenaCreateDebug(usize size, u32 init_line_no)
{
u8 *mem = pMemAllocZeroed(size);
return ArenaInitDebug(mem, size, init_line_no);
}
// TODO: investigate overflows when out of memory because something bad is going on
static rawptr ArenaAllocAlign(Arena *arena, usize size, usize align)
static rawptr
ArenaAllocAlign(Arena *arena, usize size, usize align)
{
rawptr ptr = NULL;
@ -91,28 +103,33 @@ static rawptr ArenaAllocAlign(Arena *arena, usize size, usize align)
return ptr;
}
static rawptr ArenaAlloc(Arena *arena, usize size)
static rawptr
ArenaAlloc(Arena *arena, usize size)
{
return ArenaAllocAlign(arena, size, DEFAULT_ALIGNMENT);
}
static void ArenaFree(Arena *arena)
static void
ArenaFree(Arena *arena)
{
arena->pos = 0;
}
static void ArenaFreeZeroed(Arena *arena)
static void
ArenaFreeZeroed(Arena *arena)
{
MemZero(arena->buffer, arena->pos);
ArenaFree(arena);
}
static void DeallocArena(Arena *arena)
static void
DeallocArena(Arena *arena)
{
pMemFree(arena, arena->length);
}
static Arena * ArenaInitDebug(rawptr buffer, usize size, u32 init_line_no)
static Arena *
ArenaInitDebug(rawptr buffer, usize size, u32 init_line_no)
{
Arena *arena = ArenaInit(buffer, size);
arena->init_line_no = init_line_no;
@ -125,7 +142,8 @@ static Arena * ArenaInitDebug(rawptr buffer, usize size, u32 init_line_no)
// ::Allocator::GlobalAlloc::Start::
static void InitAllocator(usize init_size)
static void
InitAllocator(usize init_size)
{
ALLOC.grow_size = init_size;
ALLOC.buffer = pMemAllocZeroed(init_size);
@ -141,17 +159,20 @@ static void InitAllocator(usize init_size)
RBTreeInsert(ALLOC.tree, init_size, ALLOC.buffer);
}
static void DeinitAlloc()
static void
DeinitAlloc()
{
pMemFree(ALLOC.buffer, ALLOC.size);
}
static rawptr Alloc(usize size)
static rawptr
Alloc(usize size)
{
return AllocAlign(size, DEFAULT_ALIGNMENT);
}
static rawptr AllocAlign(usize size, usize alignment)
static rawptr
AllocAlign(usize size, usize alignment)
{
if (size == 0) return NULL;
@ -178,14 +199,16 @@ static rawptr AllocAlign(usize size, usize alignment)
// TODO: finish allocator
// need an idea
static void Free(rawptr ptr)
static void
Free(rawptr ptr)
{
if (ptr == NULL) return;
}
static void AllocGrow(usize size)
static void
AllocGrow(usize size)
{
usize grow_size = size < ALLOC.grow_size ? ALLOC.grow_size : ALLOC.grow_size + size;
pMemRealloc(ALLOC.buffer, ALLOC.size, ALLOC.size + grow_size);
@ -202,13 +225,15 @@ static void AllocGrow(usize size)
// ::Allocator::FreeList::Start::
static void GlobalFreeListInit(usize size)
static void
GlobalFreeListInit(usize size)
{
FreeListInit(&FL_ALLOC, size);
FL_GLOBAL_INIT = true;
}
static rawptr FLMemAlloc(usize size)
static rawptr
FLMemAlloc(usize size)
{
if (!FL_GLOBAL_INIT)
{
@ -218,14 +243,16 @@ static rawptr FLMemAlloc(usize size)
return FreeListAlloc(&FL_ALLOC, size);
}
static rawptr FLMemAllocZeroed(usize size)
static rawptr
FLMemAllocZeroed(usize size)
{
rawptr ptr = FLMemAlloc(size);
MemZero(ptr, size);
return ptr;
}
static rawptr FLMemRealloc(rawptr old_ptr, usize size)
static rawptr
FLMemRealloc(rawptr old_ptr, usize size)
{
if (!FL_GLOBAL_INIT)
{
@ -241,7 +268,8 @@ static rawptr FLMemRealloc(rawptr old_ptr, usize size)
return ptr;
}
static void FLMemFree(rawptr ptr)
static void
FLMemFree(rawptr ptr)
{
if (!FL_GLOBAL_INIT)
{
@ -254,7 +282,8 @@ static void FLMemFree(rawptr ptr)
/*
* Should be async safe given no other thread frees a pointer in the middle of a realloc
*/
static rawptr FreeListRealloc(FLAlloc *alloc, rawptr old_ptr, usize size)
static rawptr
FreeListRealloc(FLAlloc *alloc, rawptr old_ptr, usize size)
{
rawptr ptr = FreeListAlloc(alloc, size);
usize old_size = FreeListPtrSize(alloc, old_ptr);
@ -266,7 +295,8 @@ static rawptr FreeListRealloc(FLAlloc *alloc, rawptr old_ptr, usize size)
return ptr;
}
static usize FreeListPtrSize(FLAlloc *alloc, rawptr ptr)
static usize
FreeListPtrSize(FLAlloc *alloc, rawptr ptr)
{
if (ptr == NULL) return 0;
@ -286,7 +316,8 @@ static usize FreeListPtrSize(FLAlloc *alloc, rawptr ptr)
return size;
}
static void FreeListInit(FLAlloc *alloc, usize size)
static void
FreeListInit(FLAlloc *alloc, usize size)
{
alloc->list_head = pMemAllocZeroed(sizeof(FreeList));
alloc->nil = &FL_NIL_NODE;
@ -297,7 +328,8 @@ static void FreeListInit(FLAlloc *alloc, usize size)
FreeListFreeAll(alloc);
}
static void _FreeListInit(FreeList **alloc, usize size)
static void
_FreeListInit(FreeList **alloc, usize size)
{
*alloc = (FreeList *)pMemAllocZeroed(size);
(*alloc)->data = (rawptr)(((uintptr)*alloc) + ((uintptr)sizeof(FreeList)));
@ -306,7 +338,8 @@ static void _FreeListInit(FreeList **alloc, usize size)
(*alloc)->next = &FL_NIL_LIST;
}
static void FreeListFreeAll(FLAlloc *alloc)
static void
FreeListFreeAll(FLAlloc *alloc)
{
TicketMutLock(&alloc->mut);
@ -331,7 +364,8 @@ static void FreeListFreeAll(FLAlloc *alloc)
TicketMutUnlock(&alloc->mut);
}
static FLNode *FreeListSearch(FreeList *alloc, usize size, usize alignment, usize *out_padding, FLNode **prev_node)
static FLNode *
FreeListSearch(FreeList *alloc, usize size, usize alignment, usize *out_padding, FLNode **prev_node)
{
FLNode *node = alloc->head;
FLNode *prev = &FL_NIL_NODE;
@ -361,7 +395,8 @@ static FLNode *FreeListSearch(FreeList *alloc, usize size, usize alignment, usiz
/*
* NOT SAFE TO CALL OUTSIDE OF FreeListAlloc
*/
static FreeList *FreeListGrow(FLAlloc *alloc, usize alloc_size)
static FreeList *
FreeListGrow(FLAlloc *alloc, usize alloc_size)
{
usize grow_size = alloc->grow_size;
if (alloc_size > grow_size)
@ -392,7 +427,8 @@ static FreeList *FreeListGrow(FLAlloc *alloc, usize alloc_size)
return list;
}
static rawptr _FreeListAllocAlign(FreeList *alloc, usize size, usize alignment)
static rawptr
_FreeListAllocAlign(FreeList *alloc, usize size, usize alignment)
{
if (size == 0) return NULL;
@ -434,12 +470,14 @@ static rawptr _FreeListAllocAlign(FreeList *alloc, usize size, usize alignment)
return (rawptr)(((c8 *)header) + sizeof(FLAllocHeader));
}
static rawptr FreeListAlloc(FLAlloc *alloc, usize size)
static rawptr
FreeListAlloc(FLAlloc *alloc, usize size)
{
return FreeListAllocAlign(alloc, size, DEFAULT_ALIGNMENT);
}
static rawptr FreeListAllocAlign(FLAlloc *alloc, usize size, usize alignment)
static rawptr
FreeListAllocAlign(FLAlloc *alloc, usize size, usize alignment)
{
TicketMutLock(&alloc->mut);
@ -469,7 +507,8 @@ static rawptr FreeListAllocAlign(FLAlloc *alloc, usize size, usize alignment)
return ptr;
}
static FreeList *_FreeListFindList(FLAlloc *alloc, rawptr ptr)
static FreeList *
_FreeListFindList(FLAlloc *alloc, rawptr ptr)
{
FreeList *list = NULL;
FreeList *current = alloc->list_head;
@ -488,7 +527,8 @@ static FreeList *_FreeListFindList(FLAlloc *alloc, rawptr ptr)
return list;
}
static void _FreeListFree(FreeList *alloc, rawptr ptr)
static void
_FreeListFree(FreeList *alloc, rawptr ptr)
{
FLAllocHeader *header = cast(FLAllocHeader *, u8ptr(ptr) - sizeof(FLAllocHeader));
FLNode *free_node = cast(FLNode *,header);
@ -514,7 +554,8 @@ static void _FreeListFree(FreeList *alloc, rawptr ptr)
FreeListCoalescence(alloc, prev_node, free_node);
}
static void FreeListFree(FLAlloc *alloc, rawptr ptr)
static void
FreeListFree(FLAlloc *alloc, rawptr ptr)
{
if (ptr == NULL) return;
@ -529,7 +570,8 @@ static void FreeListFree(FLAlloc *alloc, rawptr ptr)
TicketMutUnlock(&alloc->mut);
}
static void FreeListCoalescence(FreeList *alloc, FLNode *prev_node, FLNode *free_node)
static void
FreeListCoalescence(FreeList *alloc, FLNode *prev_node, FLNode *free_node)
{
if (free_node->next != &FL_NIL_NODE && (rawptr)(((c8 *)free_node) + free_node->size) == free_node->next)
{
@ -544,7 +586,8 @@ static void FreeListCoalescence(FreeList *alloc, FLNode *prev_node, FLNode *free
}
}
static void FreeListRemove(FLNode **head, FLNode *prev_node, FLNode *del_node)
static void
FreeListRemove(FLNode **head, FLNode *prev_node, FLNode *del_node)
{
if (prev_node == &FL_NIL_NODE)
*head = del_node->next;
@ -552,7 +595,8 @@ static void FreeListRemove(FLNode **head, FLNode *prev_node, FLNode *del_node)
prev_node->next = del_node->next;
}
static void FreeListInsert(FLNode **head, FLNode *prev_node, FLNode *new_node)
static void
FreeListInsert(FLNode **head, FLNode *prev_node, FLNode *new_node)
{
if (prev_node == &FL_NIL_NODE)
{

View File

@ -80,6 +80,41 @@ static void apInit()
// ::Assets::Loading::Functions::Start::
static Asset
apLoad(c8 *str)
{
Asset asset = {0};
return asset;
}
static Asset
apLoadS8(String8 str)
{
return apLoad(str.value);
}
static void
apUnload(c8 *str)
{
Asset asset = {0};
return asset;
}
static void
apUnloadS8(String8 str)
{
apUnload(str.value);
}
static u64
apAssetIndex(c8 *str)
{
return 0;
}
/*
static Asset apLoadTexture(TextureAsset asset_id)
{
if (!ASSET_HEADER_LOADED)
@ -163,10 +198,8 @@ static TexMeta apGetTextureMeta(TextureAsset asset_id)
static ModelMeta apGetModelMeta(ModelAsset asset_id)
{
/*
AssetFile *asset_file = Model_Assets + asset_id;
return asset_file->model_meta;
*/
//AssetFile *asset_file = Model_Assets + asset_id;
//return asset_file->model_meta;
ModelMeta meta = {0};
Asset asset = Model_Asset_Lookup[asset_id];
@ -211,6 +244,8 @@ static void apUnloadModel(ModelAsset asset_id)
}
}
*/
// ::Assets::Loading::Functions::End::

View File

@ -6,70 +6,13 @@
#define CreateMagicValue(a, b, c, d) ((u32)(d << 24) | (u32)(c << 16) | (u32)(b << 8) | (u32)(a))
// ::Assets::Globals::Header::
#ifndef BUILD_ASSET_CODEGEN
# include "codegen_assets.h"
#endif
// ::Assets::Types::Header::
typedef enum AssetType_e : u32
{
SHADER_ASSET,
TEXTURE_ASSET,
SOUND_ASSET,
MODEL_ASSET,
ASSET_TYPE_MAX,
} AssetType;
typedef enum ShaderAsset_e : u32
{
QUAD_FRAG_SPIRV_SHADER,
QUAD_VERT_SPIRV_SHADER,
GUI_FRAG_SPIRV_SHADER,
GUI_VERT_SPIRV_SHADER,
PBR_FRAG_SPIRV_SHADER,
PBR_VERT_SPIRV_SHADER,
SHADER_ASSET_MAX,
} ShaderAsset;
typedef enum TextureAsset_e : u32
{
PATTERMON_OBESE,
PATTERMON_PURPLOID,
PATTERMON_YUKATA,
HAMSTER,
HAMSMOKER,
CHEESOID,
HOG,
TEXTURE_ASSET_MAX
} TextureAsset;
typedef enum TextureAssetTag_e : u32
{
TEXTURE_ASSET_TAG_MAX,
} TextureAssetTag;
typedef enum SoundAsset_e : u32
{
SOUND_ASSET_MAX,
} SoundAsset;
typedef enum SoundAssetTag_e : u32
{
SOUND_ASSET_TAG_MAX,
} SoundAssetTag;
typedef enum ModelAsset_e : u32
{
MODEL_YODA,
MODEL_BLOCK_CHAR,
MODEL_ASSET_MAX,
} ModelAsset;
typedef enum ModelAssetTag_e : u32
{
MODEL_ASSET_TAG_MAX,
} ModelAssetTag;
typedef struct TexMeta
{
u32 w;
@ -100,6 +43,7 @@ typedef struct AssetTag
typedef struct AssetFile
{
u64 hash;
u64 data_offset;
u64 len;
union
@ -113,11 +57,7 @@ typedef struct FileHeader
{
u32 magic_num;
u32 version;
u32 tag_counts[ASSET_TYPE_MAX];
u32 asset_counts[ASSET_TYPE_MAX];
u64 tag_offsets[ASSET_TYPE_MAX];
u64 asset_offsets[ASSET_TYPE_MAX];
} FileHeader;
@ -127,20 +67,17 @@ static void apInit();
// ::Assets::Loading::Functions::Header::
static Asset apLoadTexture(TextureAsset asset_id);
static Asset apLoadShader(ShaderAsset asset_id);
static Asset apLoadModel(ModelAsset asset_id);
static TexMeta apGetTextureMeta(TextureAsset asset_id);
static ModelMeta apGetModelMeta(ModelAsset asset_id);
static void apUnloadTexture(TextureAsset asset_id);
static void apUnloadShader(ShaderAsset asset_id);
static void apUnloadModel(ModelAsset asset_id);
static Asset apLoad(c8 *str);
static Asset apLoadS8(String8 str);
static void apUnload(c8 *str);
static void apUnloadS8(String8 str);
static u64 apAssetIndex(c8 *str);
// ::Assets::Util::Functions::Header::
// TODO(MA): Implement async asset handling
static inline b32 apMarkUnloaded(AssetType type, u32 index);
static inline void apMarkLoaded(AssetType type, u32 index);
static inline b32 apMarkUnloaded(c8 *str);
static inline void apMarkLoaded(c8 *str);
// ::Assets::Models::Functions::Header::

66
src/codegen_assets.h Normal file
View File

@ -0,0 +1,66 @@
static c8 *
g_Shader_Asset_Names[] =
{
"shaders/gui.frag",
"shaders/pbr.frag",
"shaders/gui.vert",
"shaders/quad.frag",
"shaders/quad.vert",
"shaders/pbr.vert",
};
static u64
g_Shader_Asset_Hashes[] =
{
4076561469468128204U,
12546533630435803654U,
17203805968697784249U,
1277283055956479971U,
12273814537638279648U,
1941995729991819811U,
};
#define SHADER_ASSET_MAX 6
static c8 *
g_Model_Asset_Names[] =
{
"models/test_char",
"models/yoda",
};
static u64
g_Model_Asset_Hashes[] =
{
17106564331948230266U,
1379945611816585992U,
};
#define MODEL_ASSET_MAX 2
static c8 *
g_Texture_Asset_Names[] =
{
"textures/ham_smoke",
"textures/cheesoid",
"textures/hog",
"textures/patamon",
"textures/pattermon",
"textures/hamster",
"textures/purplemon",
};
static u64
g_Texture_Asset_Hashes[] =
{
3672471465693847963U,
17853259469867187617U,
12925726572206082157U,
1223697967736380744U,
16704275018603890077U,
13194708417649827129U,
12400748618931758111U,
};
#define TEXTURE_ASSET_MAX 7

102
src/ds.c
View File

@ -1,13 +1,19 @@
// ::DataStructures::Globals::Start::
RBNode RB_NIL = { .color = RB_BLACK };
RBNode *P_RB_NIL = &RB_NIL;
RBNode
RB_NIL = { .color = RB_BLACK };
RBNode *
P_RB_NIL = &RB_NIL;
RBDataNode RB_DN_NIL = {0};
RBDataNode *P_RB_DN_NIL = &RB_DN_NIL;
RBDataNode
RB_DN_NIL = {0};
RBDataNode *
P_RB_DN_NIL = &RB_DN_NIL;
HashNode HT_NIL = {0};
HashNode *P_HT_NIL = &HT_NIL;
HashNode
HT_NIL = {0};
HashNode *
P_HT_NIL = &HT_NIL;
// ::DataStructures::Globals::End::
@ -15,7 +21,8 @@ HashNode *P_HT_NIL = &HT_NIL;
// ::DataStructures::RedBlackTree::Functions::Start::
static void RBTreeInit(RBTree *tree)
static void
RBTreeInit(RBTree *tree)
{
Assert(tree != NULL, "RBTree is null");
RB_NIL.right = RB_NIL.left = RB_NIL.parent = P_RB_NIL;
@ -25,14 +32,16 @@ static void RBTreeInit(RBTree *tree)
tree->nil = P_RB_NIL;
}
static inline void RBTreePushDataNode(RBDataNode *first, RBDataNode *last, rawptr value)
static inline void
RBTreePushDataNode(RBDataNode *first, RBDataNode *last, rawptr value)
{
RBDataNode *data_node = FLMemAllocZeroed(sizeof(RBDataNode));
data_node->data = value;
RBQueuePush(first, last, data_node);
}
static inline RBNode *RBTreeInitNode(u64 key, rawptr value)
static inline RBNode *
RBTreeInitNode(u64 key, rawptr value)
{
RBNode *node = FLMemAllocZeroed(sizeof(RBNode));
node->parent = node->left = node->right = P_RB_NIL;
@ -44,7 +53,8 @@ static inline RBNode *RBTreeInitNode(u64 key, rawptr value)
return node;
}
static void RBTreeInsert(RBTree *tree, u64 key, rawptr value)
static void
RBTreeInsert(RBTree *tree, u64 key, rawptr value)
{
RBNode *node = P_RB_NIL;
@ -104,7 +114,8 @@ static void RBTreeInsert(RBTree *tree, u64 key, rawptr value)
RBTreeCorrect(tree, node);
}
static void RBTreeCorrect(RBTree *tree, RBNode *node)
static void
RBTreeCorrect(RBTree *tree, RBNode *node)
{
RBNode *gp = node->parent->parent;
RBNode *p = node->parent;
@ -147,7 +158,8 @@ static void RBTreeCorrect(RBTree *tree, RBNode *node)
} while ((p = node->parent));
}
static void RBTreeDelete(RBTree *tree, u64 key, rawptr value)
static void
RBTreeDelete(RBTree *tree, u64 key, rawptr value)
{
RBNode *node = NULL;
Assert(RBTreeSearch(tree, key, &node), "Unable to find node in RBTreeDelete");
@ -286,7 +298,8 @@ static void RBTreeDelete(RBTree *tree, u64 key, rawptr value)
}
}
static b32 RBTreeSearchNearest(RBTree *tree, u64 key, RBNode **out_node)
static b32
RBTreeSearchNearest(RBTree *tree, u64 key, RBNode **out_node)
{
if (tree->root == tree->nil) return false;
@ -325,7 +338,8 @@ static b32 RBTreeSearchNearest(RBTree *tree, u64 key, RBNode **out_node)
return *out_node != tree->nil;
}
static b32 RBTreeSearch(RBTree *tree, u64 key, RBNode **out_node)
static b32
RBTreeSearch(RBTree *tree, u64 key, RBNode **out_node)
{
if (tree->root == tree->nil) return false;
@ -355,7 +369,8 @@ static b32 RBTreeSearch(RBTree *tree, u64 key, RBNode **out_node)
return found;
}
static inline void RBTreeTransplant(RBTree *tree, RBNode *node, RBNode *placed_node)
static inline void
RBTreeTransplant(RBTree *tree, RBNode *node, RBNode *placed_node)
{
if (node->parent == tree->nil)
tree->root = placed_node;
@ -367,7 +382,8 @@ static inline void RBTreeTransplant(RBTree *tree, RBNode *node, RBNode *placed_n
placed_node->parent = node->parent;
}
static void RBTreeRotate(RBTree *tree, RBNode *node, RBNodeDir dir)
static void
RBTreeRotate(RBTree *tree, RBNode *node, RBNodeDir dir)
{
RBNode *p = node->parent;
RBNode *root = node->child[1 - dir];
@ -388,7 +404,8 @@ static void RBTreeRotate(RBTree *tree, RBNode *node, RBNodeDir dir)
tree->root = root;
}
static void RBTreeLeftRotate(RBTree *tree, RBNode *node)
static void
RBTreeLeftRotate(RBTree *tree, RBNode *node)
{
RBNode *right = node->right;
if (right->left != tree->nil)
@ -406,7 +423,8 @@ static void RBTreeLeftRotate(RBTree *tree, RBNode *node)
node->parent = right;
}
static void RBTreeRightRotate(RBTree *tree, RBNode *node)
static void
RBTreeRightRotate(RBTree *tree, RBNode *node)
{
RBNode *left = node->left;
if (left->right != tree->nil)
@ -430,7 +448,8 @@ static void RBTreeRightRotate(RBTree *tree, RBNode *node)
// ::DataStructures::HashTable::Functions::Start::
static void HashTableInit(HashTable *table, u32 init_size)
static void
HashTableInit(HashTable *table, u32 init_size)
{
table->cap = init_size;
table->count = 0;
@ -445,12 +464,14 @@ static void HashTableInit(HashTable *table, u32 init_size)
}
}
static void HashTableConcatInPlace(HashList *list, HashList *to_concat)
static void
HashTableConcatInPlace(HashList *list, HashList *to_concat)
{
SLLConcatInPlaceNoCount(list, to_concat);
}
static void HashTableClear(HashTable *table)
static void
HashTableClear(HashTable *table)
{
table->count = 0;
for (u32 i = 0; i < table->count; i++)
@ -459,14 +480,16 @@ static void HashTableClear(HashTable *table)
}
}
static HashNode *HashListPop(HashList *list)
static HashNode *
HashListPop(HashList *list)
{
HashNode *result = list->first;
HTQueuePop(list->first, list->last);
return result;
}
static HashNode *HashTablePush(HashTable *table, u64 hash, KeyValuePair value)
static HashNode *
HashTablePush(HashTable *table, u64 hash, KeyValuePair value)
{
HashNode *node = NULL;
if (table->free_lists.first != P_HT_NIL)
@ -484,43 +507,50 @@ static HashNode *HashTablePush(HashTable *table, u64 hash, KeyValuePair value)
return node;
}
static HashNode *HashTablePushU64U32(HashTable *table, u64 key, u32 value)
static HashNode *
HashTablePushU64U32(HashTable *table, u64 key, u32 value)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_u64 = key, .value_u32 = value });
}
static HashNode *HashTablePushU64U64(HashTable *table, u64 key, u64 value)
static HashNode *
HashTablePushU64U64(HashTable *table, u64 key, u64 value)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_u64 = key, .value_u64 = value });
}
static HashNode *HashTablePushU64String8(HashTable *table, u64 key, String8 value)
static HashNode *
HashTablePushU64String8(HashTable *table, u64 key, String8 value)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_u64 = key, .value_string = value });
}
static HashNode *HashTablePushU64Rawptr(HashTable *table, u64 key, rawptr value)
static HashNode *
HashTablePushU64Rawptr(HashTable *table, u64 key, rawptr value)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_u64 = key, .value_rawptr = value });
}
static HashNode *HashTablePushU64U64Split(HashTable *table, u64 key, u32 upper, u32 lower)
static HashNode *
HashTablePushU64U64Split(HashTable *table, u64 key, u32 upper, u32 lower)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_u64 = key, .value_u64_split = { .upper = upper, .lower = lower }});
}
static HashNode *HashTablePushRawptrU64(HashTable *table, rawptr key, u64 value)
static HashNode *
HashTablePushRawptrU64(HashTable *table, rawptr key, u64 value)
{
u64 hash = HashFromString(String8Struct(&key));
return HashTablePush(table, hash, (KeyValuePair){ .key_rawptr = key, .value_u64 = value });
}
static KeyValuePair *HashTableSearchU64(HashTable *table, u64 key)
static KeyValuePair *
HashTableSearchU64(HashTable *table, u64 key)
{
KeyValuePair *result = NULL;
@ -539,7 +569,8 @@ static KeyValuePair *HashTableSearchU64(HashTable *table, u64 key)
return result;
}
static KeyValuePair *HashTableSearchRawptr(HashTable *table, rawptr key)
static KeyValuePair *
HashTableSearchRawptr(HashTable *table, rawptr key)
{
KeyValuePair *result = NULL;
@ -558,7 +589,8 @@ static KeyValuePair *HashTableSearchRawptr(HashTable *table, rawptr key)
return result;
}
static void HashTableDeleteU64(HashTable *table, u64 key)
static void
HashTableDeleteU64(HashTable *table, u64 key)
{
u64 hash = HashFromString(String8Struct(&key));
u64 index = hash % table->cap;
@ -579,7 +611,8 @@ static void HashTableDeleteU64(HashTable *table, u64 key)
}
}
static rawptr HashTableDeleteU64Rawptr(HashTable *table, u64 key)
static rawptr
HashTableDeleteU64Rawptr(HashTable *table, u64 key)
{
rawptr value = NULL;
@ -606,7 +639,8 @@ static rawptr HashTableDeleteU64Rawptr(HashTable *table, u64 key)
return value;
}
static U64Split HashTableDeleteU64U64Split(HashTable *table, u64 key)
static U64Split
HashTableDeleteU64U64Split(HashTable *table, u64 key)
{
U64Split value = { .upper = UINT32_MAX };

View File

@ -24,9 +24,10 @@ int PROGRAM_FAILED = false;
# include "tests.c"
#endif
static_assert(__COUNTER__ < Len(GLOBAL_PROFILER.anchors));
static_assert(__COUNTER__ < Len(g_Global_Profiler.anchors));
void TraverseNode(RBTree *tree, RBNode *node, RBNodeDir *dir)
void
TraverseNode(RBTree *tree, RBNode *node, RBNodeDir *dir)
{
char *dir_str = dir == NULL ? "Root" : *dir == RB_RIGHT ? "Right" : "Left";
Printfln("Color: %s Value: %d Dir: %s", node->color == RB_RED ? "Red" : "Black", node->key, dir_str);
@ -42,12 +43,14 @@ void TraverseNode(RBTree *tree, RBNode *node, RBNodeDir *dir)
}
}
void Traverse(RBTree *tree)
void
Traverse(RBTree *tree)
{
TraverseNode(tree, tree->root, NULL);
}
int main(int argc, char **argv)
int
main(int argc, char **argv)
{
#ifdef BUILD_TEST
{
@ -70,7 +73,7 @@ int main(int argc, char **argv)
gInit(&ctx);
while (!global_quit)
while (!g_Global_Quit)
{
pWindowEventsGet(inputs, &i_count);
gRunCycle(&ctx, inputs, i_count);

View File

@ -15,9 +15,10 @@
#include "renderer.c"
#include "game.c"
int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line, int show_code)
int CALLBACK
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line, int show_code)
{
win32_instance = instance;
g_Win32_Instance = instance;
#ifdef BUILD_DEBUG
{
@ -44,7 +45,7 @@ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line
gInit(&ctx);
while (!global_quit)
while (!g_Global_Quit)
{
pWindowEventsGet();
gRunCycle(&ctx, inputs, i_count);

View File

@ -2,13 +2,20 @@
// TEMP
u32 selected_rect = 0;
b8 mouse_pressed = false;
b8 mouse_clicked = false;
i16 mouse_prev_pos_x = 0;
i16 mouse_prev_pos_y = 0;
i16 mouse_pos_x = 0;
i16 mouse_pos_y = 0;
u32
selected_rect = 0;
b8
mouse_pressed = false;
b8
mouse_clicked = false;
i16
mouse_prev_pos_x = 0;
i16
mouse_prev_pos_y = 0;
i16
mouse_pos_x = 0;
i16
mouse_pos_y = 0;
// ::Game::Globals::End::
@ -16,7 +23,8 @@ i16 mouse_pos_y = 0;
// ::Game::Init::Functions::Start::
static void gInit(gGameCtx *ctx)
static void
gInit(gGameCtx *ctx)
{
Assert(rInit(), "Failed to initialize the renderer");
@ -35,7 +43,8 @@ static void gInit(gGameCtx *ctx)
ctx->btn_len = 0;
}
static void gDestroy()
static void
gDestroy()
{
rDestroy();
}
@ -46,12 +55,14 @@ static void gDestroy()
// ::Game::GameLoop::Functions::Start::
static void gFrameStartNew()
static void
gFrameStartNew()
{
}
static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
static void
gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
{
ArenaFree(vFrameArena());
@ -65,10 +76,10 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
u64 index = vFrameIndex();
/*
rDescHandle yoder = rMeshLoad(MODEL_YODA);
ctx->pc.mesh_index = yoder.desc_index;
ModelMeta model_meta = apGetModelMeta(MODEL_YODA);
*/
rViewportSize(&ctx->pc.res);
ctx->pc.time = (f32)pCPUTimerRead();
@ -89,9 +100,9 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
//rBufferBindGUIVertex();
//rBufferBindGUIIndex();
rBufferBindMesh(&ctx->pc, yoder);
//rBufferBindMesh(&ctx->pc, yoder);
rDrawIndexed(model_meta.i_count, 1);
//rDrawIndexed(model_meta.i_count, 1);
rFrameFinish();
@ -107,7 +118,8 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
// ::Game::Inputs::Functions::Start::
static void gHandleInputs(pGameInput *inputs, u32 count)
static void
gHandleInputs(pGameInput *inputs, u32 count)
{
mouse_clicked = false;
@ -161,12 +173,14 @@ static void gHandleInputs(pGameInput *inputs, u32 count)
// ::Game::GUI::Functions::Start::
static inline void gPrepareGUICtx(gGameCtx *ctx)
static inline void
gPrepareGUICtx(gGameCtx *ctx)
{
ctx->gui.has_grabbed = false;
}
static b32 gButton(gGameCtx *ctx, char *label, f32 x0, f32 y0, f32 x1, f32 y1)
static b32
gButton(gGameCtx *ctx, char *label, f32 x0, f32 y0, f32 x1, f32 y1)
{
gButtonWidget *btn = NULL;
u64 id = HashFromString(String8CStr(label));
@ -226,7 +240,8 @@ static b32 gButton(gGameCtx *ctx, char *label, f32 x0, f32 y0, f32 x1, f32 y1)
return btn->pressed;
}
static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1, rDescHandle handle)
static b32
gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1, rDescHandle handle)
{
gWindowWidget *win = NULL;
u32 id = HashFromString(String8CStr(title));
@ -307,7 +322,8 @@ static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1, r
}
static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col, rDescHandle handle)
static void
gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col, rDescHandle handle)
{
ctx->vertices[ctx->vertices_len].p0 = p0;
ctx->vertices[ctx->vertices_len].p1 = p1;

View File

@ -17,108 +17,201 @@
# include <fcntl.h>
#endif
// ::Packer::Includes::CFiles::End::
// ::Packer::Globals::Start::
const FileMapping g_Shader_File_Map[] = {
{ .file_name = "quad.frag.spv", .ix = QUAD_FRAG_SPIRV_SHADER },
{ .file_name = "quad.vert.spv", .ix = QUAD_VERT_SPIRV_SHADER },
{ .file_name = "gui.frag.spv", .ix = GUI_FRAG_SPIRV_SHADER },
{ .file_name = "gui.vert.spv", .ix = GUI_VERT_SPIRV_SHADER },
{ .file_name = "pbr.frag.spv", .ix = PBR_FRAG_SPIRV_SHADER },
{ .file_name = "pbr.vert.spv", .ix = PBR_VERT_SPIRV_SHADER },
};
const FileMapping g_Texture_File_Map[] = {
{ .file_name = "pattermon.png", .ix = PATTERMON_OBESE },
{ .file_name = "patamon.png", .ix = PATTERMON_YUKATA },
{ .file_name = "purplemon.png", .ix = PATTERMON_PURPLOID },
{ .file_name = "hamster.png", .ix = HAMSTER },
{ .file_name = "ham_smoke.png", .ix = HAMSMOKER },
{ .file_name = "cheesoid.png", .ix = CHEESOID },
{ .file_name = "hog.jpg", .ix = HOG },
};
const FileMapping g_Model_File_Map[] = {
{ .file_name = "yoda.m3d", .ix = MODEL_YODA },
{ .file_name = "test_char.m3d", .ix = MODEL_BLOCK_CHAR },
};
c8 *g_Shader_File_Names[SHADER_ASSET_MAX] = {0};
c8 *g_Texture_File_Names[TEXTURE_ASSET_MAX] = {0};
c8 *g_Model_File_Names[MODEL_ASSET_MAX] = {0};
// ::Packer::Globals::End::
// ::Packer::Packing::Functions::Start::
void SetArrayLookups()
{
for (i32 i = 0; i < Len(g_Shader_File_Map); i++)
{
FileMapping file_mapping = g_Shader_File_Map[i];
g_Shader_File_Names[file_mapping.ix] = file_mapping.file_name;
}
#ifdef BUILD_ASSET_CODEGEN
for (int i = 0; i < SHADER_ASSET_MAX; i++)
u64
WriteArrayToFile(Arena *arena, pFile file, String8 array_name, rawptr elements, u32 count, String8 type, u64 offset)
{
Assert(g_Shader_File_Names[i] != NULL, "Spirv shader file name is null");
}
b32 is_string = StrEq(type.value, "c8 *");
c8 *decl = MakeArray(arena, c8, 2048);
i32 decl_len = SPrintf(decl, 2048, "static %s\n%s[] = \n{\n\t", type.value, array_name.value);
String8 result = {
.value = decl,
.len = u64(decl_len),
};
for (i32 i = 0; i < Len(g_Texture_File_Map); i++)
if (is_string)
{
FileMapping file_mapping = g_Texture_File_Map[i];
g_Texture_File_Names[file_mapping.ix] = file_mapping.file_name;
String8 *strs = (String8 *)elements;
for (u32 i = 0; i < count; i += 1)
{
c8 *f = i == count-1 ? "\"%s\"," : "\"%s\",\n\t";
c8 buf[512];
decl_len = SPrintf(buf, 512, f, strs[i].value);
result = String8Concat(arena, result, MakeString8(buf, decl_len));
}
for (int i = 0; i < TEXTURE_ASSET_MAX; i++)
{
Assert(g_Texture_File_Names[i] != NULL, "Texture file name is null");
}
for (i32 i = 0; i < Len(g_Model_File_Map); i++)
else
{
FileMapping file_mapping = g_Model_File_Map[i];
g_Model_File_Names[file_mapping.ix] = file_mapping.file_name;
}
for (int i = 0; i < MODEL_ASSET_MAX; i++)
u64 *ints = (u64 *)elements;
for (u32 i = 0; i < count; i += 1)
{
Assert(g_Model_File_Names[i] != NULL, "Model file name is null");
c8 *f = i == count-1 ? "%lluU," : "%lluU,\n\t";
c8 buf[512];
decl_len = SPrintf(buf, 512, f, ints[i]);
result = String8Concat(arena, result, MakeString8(buf, decl_len));
}
}
i32 WriteHeader(pFile file, FileHeader *header)
result = String8Concat(arena, result, String8CStr("\n};\n\n"));
return pFileWrite(file, offset, result.value, result.len);
}
static String8 *
ConvertCStrs(Arena *arena, c8 **strs, u32 count)
{
String8 *str8s = MakeArray(arena, String8, count);
for (u32 i = 0; i < count; i += 1)
{
str8s[i].value = strs[i];
str8s[i].len = StrLen(strs[i]);
}
return str8s;
}
void
CodeGenAssetLookups(Arena *arena)
{
pFile file = pFileOpen("../src/codegen_assets.h", pFS_WRITE | pFS_CREATE | pFS_TRUNC);
Assert(file > 0, "CodeGenAssetLookups failure: unable to open/create file");
Assert(pDirNavigate("../assets") == 0, "Unable to navigate to asset directory");
struct AssetDirInfo {
c8 *prefix, *struct_name, *hash_struct_name, *dir, *define;
};
struct AssetDirInfo dirs[] = {
{
.prefix = "shaders/",
.struct_name = "g_Shader_Asset_Names",
.hash_struct_name = "g_Shader_Asset_Hashes",
.dir = "shaders",
.define = "SHADER_ASSET",
},
{
.prefix = "models/",
.struct_name = "g_Model_Asset_Names",
.hash_struct_name = "g_Model_Asset_Hashes",
.dir = "models",
.define = "MODEL_ASSET",
},
{
.prefix = "textures/",
.struct_name = "g_Texture_Asset_Names",
.hash_struct_name = "g_Texture_Asset_Hashes",
.dir = "textures",
.define = "TEXTURE_ASSET",
},
};
u64 offset = 0;
u32 dir_count = sizeof(dirs) / sizeof(struct AssetDirInfo);
for (u32 i = 0; i < dir_count; i += 1)
{
Assert(pDirNavigate(dirs[i].dir) == 0, "Unable to navigate to asset sub directory.");
u32 count = 0;
c8 **cstrs = pDirGetFileNames(arena, &count);
u64 *hashes = MakeArray(arena, u64, count);
String8 *strs = ConvertCStrs(arena, cstrs, count);
for (u32 j = 0; j < count; j += 1)
{
strs[j] = String8Concat(arena, String8CStr(dirs[i].prefix), strs[j]);
i64 offset = String8FindLast(strs[j], '.');
hashes[j] = XXH3_64bits_withSeed(strs[j].value, strs[j].len - offset, HASH_SEED);
}
offset += WriteArrayToFile(
arena,
file,
String8CStr(dirs[i].struct_name),
strs,
count,
String8CStr("c8 *"),
offset
);
offset += WriteArrayToFile(
arena,
file,
String8CStr(dirs[i].hash_struct_name),
hashes,
count,
String8CStr("u64"),
offset
);
c8 buf[128];
i32 decl_len = SPrintf(buf, 128, "#define %s_MAX %llu\n\n#define %s %llu\n\n", dirs[i].define, count, dirs[i].define, i);
offset += pFileWrite(file, offset, buf, decl_len);
Assert(pDirNavigate("..") == 0, "CodeGenAssetLookups failure: unable to move back to build directory");
}
pFileClose(file);
}
int
main(int argc, c8 **argv)
{
#ifdef _WIN32
{
_set_fmode(_O_BINARY);
}
#endif
if (pDirIsVisible("build"))
{
Assert(pDirNavigate("./build") == 0, "Unable to change to build directory");
}
void *mem = pMemAllocZeroed(GB(1));
Arena *arena = ArenaInitDebug(mem, GB(1), __LINE__);
CodeGenAssetLookups(arena);
}
#else
i32
WriteHeader(pFile file, FileHeader *header)
{
i32 offset = 0;
return offset;
}
void MoveToShaderDir(c8 **return_dir)
void
MoveToShaderDir(c8 **return_dir)
{
Assert(pDirNavigate("../assets/shaders") == 0, "Unable to change to shader directory");
*return_dir = "../../build";
}
void MoveToTextureDir(c8 **return_dir)
void
MoveToTextureDir(c8 **return_dir)
{
Assert(pDirNavigate("../assets/textures") == 0, "Unable to change to assets directory");
*return_dir = "../../build";
}
void MoveToModelDir(c8 **return_dir)
void
MoveToModelDir(c8 **return_dir)
{
Assert(pDirNavigate("../assets/models") == 0, "Unable to change to assets directory");
*return_dir = "../../build";
}
void InitHeader(FileHeader *header)
void
InitHeader(FileHeader *header)
{
Assert(header != NULL, "File header is null");
@ -126,29 +219,14 @@ void InitHeader(FileHeader *header)
header->version = FILE_VERSION;
header->asset_counts[SHADER_ASSET] = SHADER_ASSET_MAX;
header->tag_counts[SHADER_ASSET] = 0;
header->asset_counts[TEXTURE_ASSET] = TEXTURE_ASSET_MAX;
header->tag_counts[TEXTURE_ASSET] = TEXTURE_ASSET_TAG_MAX;
header->asset_counts[SOUND_ASSET] = SOUND_ASSET_MAX;
header->tag_counts[SOUND_ASSET] = SOUND_ASSET_TAG_MAX;
header->asset_counts[MODEL_ASSET] = MODEL_ASSET_MAX;
header->tag_counts[MODEL_ASSET] = MODEL_ASSET_TAG_MAX;
u64 offset = sizeof(FileHeader);
for (u32 i = 0; i < ASSET_TYPE_MAX; i++)
{
if (header->tag_counts[i] > 0)
{
header->tag_offsets[i] = offset;
offset += sizeof(AssetTag) * header->tag_counts[i];
}
else
header->tag_offsets[i] = 0;
if (header->asset_counts[i] > 0)
{
header->asset_offsets[i] = offset;
@ -159,7 +237,8 @@ void InitHeader(FileHeader *header)
}
}
void PackFiles(Arena *arena, FileHeader *header)
void
PackFiles(Arena *arena, FileHeader *header)
{
pFile file = pFileOpen("assets.sgp", pFS_WRITE | pFS_TRUNC);
@ -168,10 +247,6 @@ void PackFiles(Arena *arena, FileHeader *header)
u64 data_offset = 0;
for (u32 i = 0; i < ASSET_TYPE_MAX; i++)
{
u64 tag_offset = header->tag_offsets[i] + (header->tag_counts[i] * sizeof(AssetTag));
if (tag_offset > data_offset)
data_offset = tag_offset;
u64 asset_offset = header->asset_offsets[i] + (header->asset_counts[i] * sizeof(AssetFile));
if (asset_offset > data_offset)
data_offset = asset_offset;
@ -184,7 +259,7 @@ void PackFiles(Arena *arena, FileHeader *header)
AssetFile *shader_assets = MakeArray(arena, AssetFile, SHADER_ASSET_MAX);
for (u32 i = 0; i < SHADER_ASSET_MAX; i++)
{
c8 *asset_name = g_Shader_File_Names[i];
c8 *asset_name = g_Shader_Asset_Names[i];
Printfln("Packing file: %s...", asset_name);
@ -211,7 +286,7 @@ void PackFiles(Arena *arena, FileHeader *header)
AssetFile *texture_assets = MakeArray(arena, AssetFile, TEXTURE_ASSET_MAX);
for (u32 i = 0; i < TEXTURE_ASSET_MAX; i++)
{
c8 *asset_name = g_Texture_File_Names[i];
c8 *asset_name = g_Texture_Asset_Names[i];
Printfln("Packing file: %s...", asset_name);
@ -254,7 +329,7 @@ void PackFiles(Arena *arena, FileHeader *header)
AssetFile *model_assets = MakeArray(arena, AssetFile, MODEL_ASSET_MAX);
for (u32 i = 0; i < MODEL_ASSET_MAX; i++)
{
c8 *asset_name = g_Model_File_Names[i];
c8 *asset_name = g_Model_Asset_Names[i];
Printfln("Packing file: %s...", asset_name);
@ -288,7 +363,8 @@ void PackFiles(Arena *arena, FileHeader *header)
// ::Packer::Tests::Functions::Start::
static inline void TestAssetIsCorrect(Arena *arena, c8 *file_name, AssetFile *file_info, AssetType type, pFile file)
static inline void
TestAssetIsCorrect(Arena *arena, c8 *file_name, AssetFile *file_info, AssetType type, pFile file)
{
pFile asset_file = pFileOpen(file_name, pFS_READ);
u64 size = pFileLength(asset_file);
@ -331,7 +407,8 @@ static inline void TestAssetIsCorrect(Arena *arena, c8 *file_name, AssetFile *fi
pFileClose(asset_file);
}
void TestAssetPack(Arena *arena)
void
TestAssetPack(Arena *arena)
{
pFile file = pFileOpen("assets.sgp", pFS_READ);
@ -341,16 +418,9 @@ void TestAssetPack(Arena *arena)
Assert(header.magic_num == CreateMagicValue('s', 't', 'e', 'g'), "Magic number is incorrect");
Assert(header.version == FILE_VERSION, "File version is incorrect");
Assert(header.tag_counts[SHADER_ASSET] == 0, "Shader tag count incorrect");
Assert(header.asset_counts[SHADER_ASSET] == SHADER_ASSET_MAX, "Shader count incorrect");
Assert(header.tag_counts[TEXTURE_ASSET] == TEXTURE_ASSET_TAG_MAX, "Texture tag count incorrect");
Assert(header.asset_counts[TEXTURE_ASSET] == TEXTURE_ASSET_MAX, "Texture count incorrect");
Assert(header.tag_counts[SOUND_ASSET] == SOUND_ASSET_TAG_MAX, "Sound tag count incorrect");
Assert(header.asset_counts[SOUND_ASSET] == SOUND_ASSET_MAX, "Sound count incorrect");
Assert(header.tag_counts[MODEL_ASSET] == MODEL_ASSET_TAG_MAX, "Model tag count incorrect");
Assert(header.asset_counts[MODEL_ASSET] == MODEL_ASSET_MAX, "Model count incorrect");
AssetTag *tags[ASSET_TYPE_MAX];
@ -358,12 +428,6 @@ void TestAssetPack(Arena *arena)
for (u32 i = 0; i < ASSET_TYPE_MAX; i++)
{
if (header.tag_counts[i] > 0)
{
tags[i] = MakeArray(arena, AssetTag, header.tag_counts[i]);
pFileRead(file, header.tag_offsets[i], tags[i], sizeof(AssetTag)*header.tag_counts[i]);
}
if (header.asset_counts[i] > 0)
{
files[i] = MakeArray(arena, AssetFile, header.asset_counts[i]);
@ -376,7 +440,7 @@ void TestAssetPack(Arena *arena)
for (u32 i = 0; i < SHADER_ASSET_MAX; i++)
{
TestAssetIsCorrect(arena, g_Shader_File_Names[i], &files[SHADER_ASSET][i], SHADER_ASSET, file);
TestAssetIsCorrect(arena, g_Shader_Asset_Names[i], &files[SHADER_ASSET][i], SHADER_ASSET, file);
}
pDirNavigate(return_dir);
@ -384,7 +448,7 @@ void TestAssetPack(Arena *arena)
for (u32 i = 0; i < TEXTURE_ASSET_MAX; i++)
{
TestAssetIsCorrect(arena, g_Texture_File_Names[i], &files[TEXTURE_ASSET][i], TEXTURE_ASSET, file);
TestAssetIsCorrect(arena, g_Texture_Asset_Names[i], &files[TEXTURE_ASSET][i], TEXTURE_ASSET, file);
}
pDirNavigate(return_dir);
@ -392,7 +456,7 @@ void TestAssetPack(Arena *arena)
for (u32 i = 0; i < MODEL_ASSET_MAX; i++)
{
TestAssetIsCorrect(arena, g_Model_File_Names[i], &files[MODEL_ASSET][i], MODEL_ASSET, file);
TestAssetIsCorrect(arena, g_Model_Asset_Names[i], &files[MODEL_ASSET][i], MODEL_ASSET, file);
}
}
@ -402,7 +466,8 @@ void TestAssetPack(Arena *arena)
// ::Packer::Main::Functions::Start::
int main(int argc, c8 **argv)
int
main(int argc, c8 **argv)
{
#ifdef _WIN32
{
@ -415,8 +480,6 @@ int main(int argc, c8 **argv)
Assert(pDirNavigate("./build") == 0, "Unable to change to build directory");
}
SetArrayLookups();
void *mem = pMemAllocZeroed(GB(1));
Arena *arena = ArenaInitDebug(mem, GB(1), __LINE__);
@ -433,4 +496,8 @@ int main(int argc, c8 **argv)
TestAssetPack(arena);
}
#endif // BUILD_ASSET_CODEGEN
// ::Packer::Main::Functions::End::

View File

@ -51,6 +51,7 @@ typedef struct FileMapping
// ::Packer::Packing::Functions::Header::
void SetArrayLookups();
void CodeGenAssetLookups(Arena *arena);
void InitHeader(FileHeader *header);
i32 WriteHeader(pFile file, FileHeader *header);
void PackFiles(Arena *arena, FileHeader *header);

View File

@ -1,41 +1,49 @@
// ::Platform::Linux::Globals::Start::
static pPlatformWindow linux_window = {
static pPlatformWindow
linux_window =
{
.w = 1920,
.h = 1080,
};
b32 global_quit = false;
b32
g_Global_Quit = false;
// ::Platform::Linux::Globals::End::
// ::Platform::Linux::Print::Functions::Start::
i32 pWriteStdOut(rawptr buf, i32 len)
i32
pWriteStdOut(rawptr buf, i32 len)
{
return (i32)write(STDOUT, buf, len);
}
i32 pWriteStdErr(rawptr buf, i32 len)
i32
pWriteStdErr(rawptr buf, i32 len)
{
return (i32)write(STDERR, buf, len);
}
// ::Platform::Linux::Window::Functions::Start::
void pWindowEventsGet(pGameInput *inputs, u32 *i_count)
void
pWindowEventsGet(pGameInput *inputs, u32 *i_count)
{
pWindowEventHandle(inputs, i_count, false);
}
b32 pWindowEventWaitFor(pGameInput *input)
b32
pWindowEventWaitFor(pGameInput *input)
{
u32 i_count;
pWindowEventHandle(input, &i_count, true);
return i_count > 0;
}
void pWindowEventHandle(pGameInput *inputs, u32 *i_count, b32 wait_for_event)
void
pWindowEventHandle(pGameInput *inputs, u32 *i_count, b32 wait_for_event)
{
b32 has_max_inputs = false;
*i_count = 0;
@ -60,7 +68,7 @@ void pWindowEventHandle(pGameInput *inputs, u32 *i_count, b32 wait_for_event)
break;
if (msg->data.data32[0] == linux_window.close_event)
global_quit = true;
g_Global_Quit = true;
} break;
case XCB_CONFIGURE_NOTIFY:
{
@ -145,7 +153,8 @@ void pWindowEventHandle(pGameInput *inputs, u32 *i_count, b32 wait_for_event)
} while(!wait_for_event && !has_max_inputs);
}
pKeyboardInput pInputEventConvert(u32 x_key)
pKeyboardInput
pInputEventConvert(u32 x_key)
{
switch (x_key)
{
@ -287,7 +296,8 @@ pKeyboardInput pInputEventConvert(u32 x_key)
// ::Platform::Linux::Utils::Functions::Start::
b32 pSyscallErrCheck(void *ptr)
b32
pSyscallErrCheck(void *ptr)
{
return (isize)ptr == SYS_ERR ? true : false;
}
@ -298,7 +308,8 @@ b32 pSyscallErrCheck(void *ptr)
// ::Platform::Linux::Async::Start::
static pThread pThreadInit(rawptr proc, rawptr param)
static pThread
pThreadInit(rawptr proc, rawptr param)
{
pThread thread = {0};
Assert(pthread_mutex_init(&thread.mut, NULL) == 0, "pthread_mutex_init failure");
@ -308,19 +319,22 @@ static pThread pThreadInit(rawptr proc, rawptr param)
return thread;
}
static void pThreadSuspend(pThread *thread)
static void
pThreadSuspend(pThread *thread)
{
pthread_mutex_lock(&thread->mut);
pthread_cond_wait(&thread->cond, &thread->mut);
pthread_mutex_unlock(&thread->mut);
}
static void pThreadWake(pThread *thread)
static void
pThreadWake(pThread *thread)
{
pthread_cond_signal(&thread->cond);
}
static void pThreadKill()
static void
pThreadKill()
{
pthread_exit(NULL);
}

View File

@ -1,6 +1,7 @@
// ::Platform::Functions::pLibrary::Start::
b32 pLibraryLoad(const char *name, pLibrary *out_lib)
b32
pLibraryLoad(const char *name, pLibrary *out_lib)
{
if (!name) {
return false;
@ -14,7 +15,8 @@ b32 pLibraryLoad(const char *name, pLibrary *out_lib)
return true;
}
b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
b32
pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
{
if (!name) {
return false;
@ -42,7 +44,8 @@ b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
// ::Platform::Functions::Memory::Start::
rawptr pMemAlloc(usize size)
rawptr
pMemAlloc(usize size)
{
rawptr addr = mmap(
NULL,
@ -58,14 +61,16 @@ rawptr pMemAlloc(usize size)
return addr;
}
rawptr pMemAllocZeroed(usize size)
rawptr
pMemAllocZeroed(usize size)
{
rawptr ptr = pMemAlloc(size);
MemZero(ptr, size);
return ptr;
}
rawptr pMemRealloc(rawptr ptr, usize old_size, usize new_size)
rawptr
pMemRealloc(rawptr ptr, usize old_size, usize new_size)
{
rawptr addr = mremap(
ptr,
@ -79,12 +84,14 @@ rawptr pMemRealloc(rawptr ptr, usize old_size, usize new_size)
return addr;
}
void pMemFree(rawptr ptr, usize size)
void
pMemFree(rawptr ptr, usize size)
{
Assert(munmap(ptr, size) == 0, "munmap failed");
}
usize pPageSize()
usize
pPageSize()
{
return (usize)sysconf(_SC_PAGESIZE);
}
@ -95,7 +102,8 @@ usize pPageSize()
// ::Platform::Functions::Window::Start::
b32 pWindowInit(const char *window_name)
b32
pWindowInit(const char *window_name)
{
pPlatformWindow *window = &linux_window;
@ -203,7 +211,8 @@ b32 pWindowInit(const char *window_name)
return true;
}
pWindowSize pWindowGetSize()
pWindowSize
pWindowGetSize()
{
return (pWindowSize) {
.w = linux_window.w,
@ -211,12 +220,14 @@ pWindowSize pWindowGetSize()
};
}
pPlatformWindow *pWindowGet()
pPlatformWindow
*pWindowGet()
{
return &linux_window;
}
b32 pWindowShouldQuit()
b32
pWindowShouldQuit()
{
return false;
}
@ -227,12 +238,14 @@ b32 pWindowShouldQuit()
// ::Platform::FileSystem::Functions::Start::
b32 pDirNavigate(c8 *dir)
b32
pDirNavigate(c8 *dir)
{
return chdir(dir);
}
static pFile pFileOpen(c8 *file_name, pFSAccess acc)
static pFile
pFileOpen(c8 *file_name, pFSAccess acc)
{
int flags = 0;
if (BitEq(acc, pFS_READ) && BitEq(acc, pFS_WRITE))
@ -255,30 +268,35 @@ static pFile pFileOpen(c8 *file_name, pFSAccess acc)
return open(file_name, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
}
static void pFileClose(pFile file)
static void
pFileClose(pFile file)
{
close(file);
}
// TODO: make these more resilient
static u64 pFileRead(pFile file, u64 offset, rawptr buf, u64 len)
static u64
pFileRead(pFile file, u64 offset, rawptr buf, u64 len)
{
lseek(file, (isize)offset, SEEK_SET);
return read(file, buf, (usize)len);
}
static u64 pFileWrite(pFile file, u64 offset, rawptr buf, u64 len)
static u64
pFileWrite(pFile file, u64 offset, rawptr buf, u64 len)
{
lseek(file, (isize)offset, SEEK_SET);
return write(file, buf, (usize)len);
}
static u64 pFileSeek(pFile file, u64 pos)
static u64
pFileSeek(pFile file, u64 pos)
{
return (u64)lseek(file, (isize)pos, SEEK_SET);
}
static u64 pFileLength(pFile file)
static u64
pFileLength(pFile file)
{
isize offset = lseek(file, 0, SEEK_CUR);
isize size = lseek(file, 0, SEEK_END);
@ -290,7 +308,8 @@ static u64 pFileLength(pFile file)
return (u64)size;
}
c8 **pDirGetFileNames(Arena *arena, u32 *count)
c8 **
pDirGetFileNames(Arena *arena, u32 *count)
{
struct dirent *dir;
@ -327,7 +346,8 @@ c8 **pDirGetFileNames(Arena *arena, u32 *count)
return (c8 **)file_names;
}
static b32 pFSIsVisible(c8 *name, b32 is_dir)
static b32
pFSIsVisible(c8 *name, b32 is_dir)
{
b32 found = false;
@ -350,17 +370,20 @@ static b32 pFSIsVisible(c8 *name, b32 is_dir)
return found;
}
static b32 pDirIsVisible(c8 *dir_name)
static b32
pDirIsVisible(c8 *dir_name)
{
return pFSIsVisible(dir_name, true);
}
static b32 pFileIsVisible(c8 *file_name)
static b32
pFileIsVisible(c8 *file_name)
{
return pFSIsVisible(file_name, false);
}
static b32 pFileCanAccess(c8 *file_name, pFSAccess file_access)
static b32
pFileCanAccess(c8 *file_name, pFSAccess file_access)
{
int a = 0;
if (BitEq(file_access, pFS_READ))
@ -377,12 +400,14 @@ static b32 pFileCanAccess(c8 *file_name, pFSAccess file_access)
// ::Platform::Profiling::Functions::Start::
static u64 pOSTimerFreq()
static u64
pOSTimerFreq()
{
return 1000000;
}
static u64 pOSTimerRead()
static u64
pOSTimerRead()
{
struct timeval value;
gettimeofday(&value, 0);
@ -390,7 +415,8 @@ static u64 pOSTimerRead()
return pOSTimerFreq() * u64(value.tv_sec) + u64(value.tv_usec);
}
static inline u64 pCPUTimerRead()
static inline u64
pCPUTimerRead()
{
return __rdtsc();
}
@ -401,37 +427,44 @@ static inline u64 pCPUTimerRead()
// ::Platform::Atomics::Functions::Start::
static inline void pAtomicSignalFenceSeqCst()
static inline void
pAtomicSignalFenceSeqCst()
{
__atomic_signal_fence(__ATOMIC_SEQ_CST);
}
static inline u32 pAtomicFetchSubU32(u32 volatile *ptr, u32 count)
static inline u32
pAtomicFetchSubU32(u32 volatile *ptr, u32 count)
{
return __atomic_fetch_sub(ptr, count, __ATOMIC_ACQUIRE);
}
static inline u32 pAtomicFetchIncrU32(u32 volatile *ptr)
static inline u32
pAtomicFetchIncrU32(u32 volatile *ptr)
{
return __atomic_fetch_add(ptr, (u32)1, __ATOMIC_ACQUIRE);
}
static inline void pAtomicIncrU32(u32 volatile *ptr)
static inline void
pAtomicIncrU32(u32 volatile *ptr)
{
__atomic_fetch_add(ptr, (u32)1, __ATOMIC_RELEASE);
}
static inline u32 pAtomicLoadU32(u32 volatile *ptr)
static inline u32
pAtomicLoadU32(u32 volatile *ptr)
{
return __atomic_load_n(ptr, __ATOMIC_ACQUIRE);
}
static inline void pAtomicStoreB32(b32 volatile *ptr, b32 value)
static inline void
pAtomicStoreB32(b32 volatile *ptr, b32 value)
{
__atomic_store_n(ptr, value, __ATOMIC_RELEASE);
}
static inline b32 pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expected, b32 desired)
static inline b32
pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expected, b32 desired)
{
return __atomic_compare_exchange_n(ptr, expected, desired, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
}

View File

@ -1,8 +1,16 @@
HINSTANCE win32_instance = {0};
pPlatformWindow win32_window = {0};
b32 global_quit = false;
// ::Platform::Windows::Globals::Start::
LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
HINSTANCE
g_Win32_Instance = {0};
pPlatformWindow
g_Win32_Window = {0};
b32
g_Global_Quit = false;
// ::Platform::Windows::Globals::End::
LRESULT CALLBACK
WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
{
LRESULT result = 0;
@ -11,15 +19,15 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_
case WM_SIZE:
{
Printfln("Window resizing");
win32_window.w = LOWORD(l_param);
win32_window.h = HIWORD(l_param);
rResolutionSet(win32_window.w, win32_window.h);
g_Win32_Window.w = LOWORD(l_param);
g_Win32_Window.h = HIWORD(l_param);
rResolutionSet(g_Win32_Window.w, g_Win32_Window.h);
} break;
case WM_DESTROY: // TODO(MA): Probably handle these separately but for now, they're together
case WM_CLOSE:
{
Printf("quitting");
global_quit = true;
g_Global_Quit = true;
} break;
case WM_ACTIVATEAPP:
{
@ -34,7 +42,8 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_
return result;
}
b32 pLibraryLoad(const char *name, pLibrary *out_lib)
b32
pLibraryLoad(const char *name, pLibrary *out_lib)
{
b32 success = true;
@ -45,7 +54,8 @@ b32 pLibraryLoad(const char *name, pLibrary *out_lib)
return success;
}
b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
b32
pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
{
b32 success = true;
@ -56,26 +66,29 @@ b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
return success;
}
usize pPageSize()
usize
pPageSize()
{
return 0;
}
i32 _Write(void const *str, DWORD std_handle)
i32
_Write(void const *str, DWORD std_handle)
{
DWORD written;
BOOL success = WriteFile(GetStdHandle(std_handle), str, StrLen(str), &written, NULL);
return success ? (i32)written : -1;
}
b32 pWindowInit(const char *window_name)
b32
pWindowInit(const char *window_name)
{
b32 success = true;
WNDCLASS window_class = {
.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
.lpfnWndProc = WindowProc,
.hInstance = win32_instance,
.hInstance = g_Win32_Instance,
.lpszClassName = WINDOW_CLASS_NAME,
};
@ -96,25 +109,27 @@ b32 pWindowInit(const char *window_name)
CW_USEDEFAULT,
0,
0,
win32_instance,
g_Win32_Instance,
0
);
if (!window_handle)
success = false;
else
win32_window.handle = window_handle;
g_Win32_Window.handle = window_handle;
}
return success;
}
pPlatformWindow *pWindowGet()
pPlatformWindow *
pWindowGet()
{
return &win32_window;
return &g_Win32_Window;
}
void pWindowEventsGet()
void
pWindowEventsGet()
{
BOOL has_msg = false;
MSG message;
@ -130,7 +145,8 @@ void pWindowEventsGet()
while (has_msg);
}
void pWindowEventWaitFor()
void
pWindowEventWaitFor()
{
MSG message;
BOOL message_result = GetMessageA(&message, 0, 0, 0);
@ -141,14 +157,16 @@ void pWindowEventWaitFor()
}
}
b32 pWindowShouldQuit()
b32
pWindowShouldQuit()
{
return global_quit;
return g_Global_Quit;
}
pWindowSize pWindowGetSize()
pWindowSize
pWindowGetSize()
{
return (pWindowSize){ .w = win32_window.w, .h = win32_window.h };
return (pWindowSize){ .w = g_Win32_Window.w, .h = g_Win32_Window.h };
}
// ::Platform::Windows::Includes::CFile::

View File

@ -1,19 +1,22 @@
// ::Platform::Windows::Memory::Start::
rawptr pMemAlloc(usize size)
rawptr
pMemAlloc(usize size)
{
return (rawptr)VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
}
rawptr pMemAllocZeroed(usize size)
rawptr
pMemAllocZeroed(usize size)
{
rawptr mem = pMemAlloc(size);
MemZero(mem, size);
return mem;
}
void pMemFree(rawptr ptr, usize size)
void
pMemFree(rawptr ptr, usize size)
{
Assert(VirtualFree(ptr, size, MEM_RELEASE), "pMemFree failure");
}
@ -24,12 +27,14 @@ void pMemFree(rawptr ptr, usize size)
// ::Platform::Windows::Print::Start::
i32 pWriteStdOut(rawptr buf, i32 len)
i32
pWriteStdOut(rawptr buf, i32 len)
{
return WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buf, len, NULL, NULL);
}
i32 pWriteStdErr(rawptr buf, i32 len)
i32
pWriteStdErr(rawptr buf, i32 len)
{
return WriteConsole(GetStdHandle(STD_ERROR_HANDLE), buf, len, NULL, NULL);
}
@ -40,7 +45,8 @@ i32 pWriteStdErr(rawptr buf, i32 len)
// ::Platform::Functions::Directory::Start::
b32 pDirNavigate(c8 *dir)
b32
pDirNavigate(c8 *dir)
{
return !(b32)SetCurrentDirectory(dir);
}
@ -51,7 +57,8 @@ b32 pDirNavigate(c8 *dir)
// ::Platform::Windows::Profiling::Functions::Start::
static inline u64 pCPUTimerRead()
static inline u64
pCPUTimerRead()
{
return __rdtsc();
}
@ -62,7 +69,8 @@ static inline u64 pCPUTimerRead()
// ::Platform::Windows::Async::Start::
static pThread pThreadInit(rawptr proc, rawptr param)
static pThread
pThreadInit(rawptr proc, rawptr param)
{
pThread thread = {0};
CreateThread(NULL, 0, proc, param, 0, NULL);
@ -70,17 +78,20 @@ static pThread pThreadInit(rawptr proc, rawptr param)
return thread;
}
static void pThreadSuspend(pThread *thread)
static void
pThreadSuspend(pThread *thread)
{
SuspendThread(thread->handle);
}
static void pThreadWake(pThread *thread)
static void
pThreadWake(pThread *thread)
{
ResumeThread(thread->handle);
}
static void pThreadKill()
static void
pThreadKill()
{
ExitThread(0);
}
@ -92,38 +103,45 @@ static void pThreadKill()
// ::Platform::Windows::Atomics::Start::
static inline void pAtomicSignalFenceSeqCst()
static inline void
pAtomicSignalFenceSeqCst()
{
_ReadWriteBarrier();
}
static inline u32 pAtomicFetchSubU32(u32 volatile *ptr, u32 count)
static inline u32
pAtomicFetchSubU32(u32 volatile *ptr, u32 count)
{
LONG decrement = (LONG)count;
return (u32)InterlockedAddAcquire((LONG volatile *)ptr, -decrement) + decrement;
}
static inline u32 pAtomicFetchIncrU32(u32 volatile *ptr)
static inline u32
pAtomicFetchIncrU32(u32 volatile *ptr)
{
return (u32)InterlockedIncrementAcquire((LONG volatile *)ptr) - 1;
}
static inline void pAtomicIncrU32(u32 volatile *ptr)
static inline void
pAtomicIncrU32(u32 volatile *ptr)
{
InterlockedIncrementRelease((LONG volatile *)ptr);
}
static inline u32 pAtomicLoadU32(u32 volatile *ptr)
static inline u32
pAtomicLoadU32(u32 volatile *ptr)
{
return (u32)InterlockedOrAcquire((LONG volatile *)ptr, 0);
}
static inline void pAtomicStoreB32(b32 volatile *ptr, b32 value)
static inline void
pAtomicStoreB32(b32 volatile *ptr, b32 value)
{
_InterlockedExchange_HLERelease((LONG volatile *)ptr, (LONG)value);
}
static inline b32 pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expect, b32 desired)
static inline b32
pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expect, b32 desired)
{
return (b32)InterlockedCompareExchangeAcquire((LONG volatile *)ptr, (LONG)desired, (LONG)*expect);
}
@ -134,7 +152,8 @@ static inline b32 pAtomicCompareExchangeB32(b32 volatile *ptr, b32 *expect, b32
// ::Platform::Windows::Files::Start::
static b8 pDirIsVisible(c8 *dir_name)
static b8
pDirIsVisible(c8 *dir_name)
{
WIN32_FIND_DATA find_data;
HANDLE handle;

File diff suppressed because it is too large Load Diff

View File

@ -38,9 +38,9 @@ static char *vulkan_libs[] = {
#endif
#define VERTEX_BUFFER_CAP MB(32)
#define INDEX_BUFFER_CAP MB(8)
#define TRANSFER_BUFFER_CAP MB(64)
constexpr u64 VERTEX_BUFFER_CAP = MB(32);
constexpr u64 INDEX_BUFFER_CAP = MB(8);
constexpr u64 TRANSFER_BUFFER_CAP = MB(64);
// ::Vulkan::Macros::Header::
@ -578,9 +578,9 @@ static vTransfer *vMeshTransferInit(Arena *arena, u32 asset_id, vMeshBuffer *mes
static vTransfer *vBufferTransferInit(Arena *arena, u32 asset_id, vBuffer *index, rawptr bytes, u64 size);
static VkResult vBufferCreate(vBuffer* buf, rRenderBufferType type, u64 size);
static rawptr vMapBuffer(VmaAllocation alloc);
static void vModelPush(ModelAsset asset_id, vModelBuffers *buffer);
static vModelBuffers *vModelPop(ModelAsset asset_id);
static vModelBuffers *vModelSearch(ModelAsset asset_id);
static void vModelPush(c8 *name, vModelBuffers *buffer);
static vModelBuffers *vModelPop(c8 *name);
static vModelBuffers *vModelSearch(c8 *name);
// ::Vulkan::CleanUp::Functions::Header::

View File

@ -1,6 +1,7 @@
// ::Vulkan::Renderer::Initialization::Functions::Start::
b32 rInit()
b32
rInit()
{
vArenasInit();
vCustomizePipelines();
@ -34,7 +35,8 @@ b32 rInit()
return true;
}
void rDestroy()
void
rDestroy()
{
VkDevice device = v_Renderer.handles.device;
VkInstance instance = v_Renderer.handles.inst;
@ -119,7 +121,8 @@ void rDestroy()
// ::Vulkan::Renderer::Buffers::Functions::Start::
static rDescHandle rTextureLoad(TextureAsset asset_id)
static rDescHandle
rTextureLoad(TextureAsset asset_id)
{
rDescHandle handle = vDescHandleSearch(vDT_SAMPLED_IMAGE, asset_id);
@ -152,7 +155,8 @@ static rDescHandle rTextureLoad(TextureAsset asset_id)
return handle;
}
static rDescHandle rMeshLoad(ModelAsset asset_id)
static rDescHandle
rMeshLoad(ModelAsset asset_id)
{
rDescHandle handle = vDescHandleSearch(vDT_MESH, asset_id);
@ -193,7 +197,8 @@ static rDescHandle rMeshLoad(ModelAsset asset_id)
return handle;
}
static void rTextureUnload(rDescHandle current_handle)
static void
rTextureUnload(rDescHandle current_handle)
{
rDescHandle handle = vDescHandleSearch(vDT_SAMPLED_IMAGE, current_handle.asset_id);
@ -205,7 +210,8 @@ static void rTextureUnload(rDescHandle current_handle)
}
}
static void rBufferBindVertex(rRenderBuffer *buffer)
static void
rBufferBindVertex(rRenderBuffer *buffer)
{
Assert(buffer && buffer->type == rRBT_VERTEX, "rBufferBindVertex: invalid buffer provided");
@ -215,7 +221,8 @@ static void rBufferBindVertex(rRenderBuffer *buffer)
vkCmdBindVertexBuffers(cmd, 0, 1, &buffer->buffer, &offsets);
}
static void rBufferBindIndex(rRenderBuffer *buffer)
static void
rBufferBindIndex(rRenderBuffer *buffer)
{
Assert(buffer && buffer->type == rRBT_INDEX, "rBufferBindIndex: invalid buffer provided");
@ -224,7 +231,8 @@ static void rBufferBindIndex(rRenderBuffer *buffer)
vkCmdBindIndexBuffer(cmd, buffer->buffer, 0, VK_INDEX_TYPE_UINT32);
}
static void vBufferQueueWait()
static void
vBufferQueueWait()
{
while (!JobQueueCompleted(&v_Renderer.upload.job_queue))
{
@ -233,17 +241,20 @@ static void vBufferQueueWait()
}
}
static rawptr rBufferGUIVertMapping()
static rawptr
rBufferGUIVertMapping()
{
return v_Renderer.buffers.gui_vert.ptr;
}
static rawptr rBufferGUIIdxMapping()
static rawptr
rBufferGUIIdxMapping()
{
return v_Renderer.buffers.gui_idx.ptr;
}
static void rBufferBindGUIVertex()
static void
rBufferBindGUIVertex()
{
VkCommandBuffer cmd = vFrameCmdBuf();
VkDeviceSize offsets = 0;
@ -252,7 +263,8 @@ static void rBufferBindGUIVertex()
vkCmdBindVertexBuffers(cmd, 0, 1, &buffer, &offsets);
}
static void rBufferBindGUIIndex()
static void
rBufferBindGUIIndex()
{
VkCommandBuffer cmd = vFrameCmdBuf();
VkBuffer buffer = v_Renderer.buffers.gui_idx.alloc.buffer;
@ -260,12 +272,12 @@ static void rBufferBindGUIIndex()
vkCmdBindIndexBuffer(cmd, buffer, 0, VK_INDEX_TYPE_UINT32);
}
static void rBufferBindMesh(rPushConst *pc, rDescHandle handle)
static void
rBufferBindMesh(rPushConst *pc, rDescHandle handle)
{
vModelBuffers *buffers = vModelSearch(handle.asset_id);
if (buffers != NULL)
{
Printfln("binding index buffer");
vkCmdBindIndexBuffer(vFrameCmdBuf(), buffers->index->buffer, 0, VK_INDEX_TYPE_UINT32);
}
}
@ -277,18 +289,21 @@ static void rBufferBindMesh(rPushConst *pc, rDescHandle handle)
// ::Vulkan::Renderer::Uniforms::Functions::Start::
// ::Vulkan::Renderer::PushConstants::Functions::Start::
static void rViewportSize(Vec2 *size)
static void
rViewportSize(Vec2 *size)
{
size->x = (f32)v_Renderer.state.swapchain.extent.width;
size->y = (f32)v_Renderer.state.swapchain.extent.height;
}
static void rGlobalUniformSet(rShaderGlobals *globals)
static void
rGlobalUniformSet(rShaderGlobals *globals)
{
}
static void rPushConstantsSet(rPushConst *pc)
static void
rPushConstantsSet(rPushConst *pc)
{
VkCommandBuffer cmd = vFrameCmdBuf();
@ -307,7 +322,8 @@ static void rPushConstantsSet(rPushConst *pc)
// ::Vulkan::Renderer::Config::Functions::Start::
static void rResolutionSet(u32 x, u32 y)
static void
rResolutionSet(u32 x, u32 y)
{
v_Renderer.state.renderer.width = x;
v_Renderer.state.renderer.height = y;
@ -319,7 +335,8 @@ static void rResolutionSet(u32 x, u32 y)
// ::Vulkan::Renderer::Rendering::Functions::Start::
b32 rFrameBegin()
b32
rFrameBegin()
{
b32 success = true;
VkResult result;
@ -399,7 +416,8 @@ b32 rFrameBegin()
return success;
}
b32 rFrameFinish()
b32
rFrameFinish()
{
b32 success = true;
VkResult result;
@ -502,14 +520,16 @@ b32 rFrameFinish()
return success;
}
static void rDrawIndexed(u32 index_count, u32 instance_count)
static void
rDrawIndexed(u32 index_count, u32 instance_count)
{
VkCommandBuffer cmd = vFrameCmdBuf();
vkCmdDrawIndexed(cmd, index_count, instance_count, 0, 0, 0);
}
static void rPipelineBind(rPipelineHandle handle, rPipelineType type)
static void
rPipelineBind(rPipelineHandle handle, rPipelineType type)
{
VkCommandBuffer cmd = vFrameCmdBuf();

View File

@ -50,7 +50,7 @@ typedef void * rawptr;
typedef struct String8
{
u8 *value;
c8 *value;
u64 len;
} String8;

View File

@ -1,12 +1,14 @@
// TODO: Make the tests actually decent
void RunTests()
void
RunTests()
{
TestFreeListAlloc();
TestHashTable();
}
void TestFreeListAlloc()
void
TestFreeListAlloc()
{
Printfln("Starting free list allocator tests...");
@ -51,7 +53,8 @@ void TestFreeListAlloc()
}
}
void TestHashTable()
void
TestHashTable()
{
Printfln("Starting hash table tests...");
HashTable table;

View File

@ -1,6 +1,7 @@
// ::Util::Globals::Start::
static Profiler GLOBAL_PROFILER;
static Profiler
g_Global_Profiler;
// ::Util::Globals::End::
@ -8,7 +9,9 @@ static Profiler GLOBAL_PROFILER;
// ::Util::Strings::Functions::Start::
static void StrConcat(c8 *str, c8 *append)
static void
StrConcat(c8 *str, c8 *append)
{
u32 len = StrLen(str);
u32 i = 0;
@ -20,12 +23,22 @@ static void StrConcat(c8 *str, c8 *append)
str[i] = '\0';
}
b32 StrEq(const char *l, const char *r) {
static b32
StrEqL(const char *l, const char *r, u64 len)
{
for (u64 i = 0; *l == *r && *l && i < len; l++, r++, i++);
return *l == *r;
}
static b32
StrEq(const char *l, const char *r)
{
for (; *l == *r && *l; l++, r++);
return *l == '\0' && *r == '\0';
}
u32 StrLen(const char *str)
static u32
StrLen(const char *str)
{
const char *start;
@ -35,23 +48,88 @@ u32 StrLen(const char *str)
return (u32)(str - start);
}
i32 SPrintf(char *buf, rawptr fmt, ...)
static i32
SPrintf(char *buf, int len, rawptr fmt, ...)
{
va_list arg;
va_start(arg, fmt);
int sprf_res = stbsp_vsnprintf(buf, sizeof(buf), fmt, arg);
int sprf_res = stbsp_vsnprintf(buf, len, fmt, arg);
va_end(arg);
return sprf_res;
}
String8 MakeString8(u8 *str, u64 len)
static String8
MakeString8(c8 *str, u64 len)
{
return (String8){ .len = len, .value = str };
}
String8 PreSplitString8(String8 string, String8 delimiter)
static String8
String8Concat(Arena *arena, String8 string, String8 append)
{
u64 str_len = string.len + append.len;
String8 str = {
.value = MakeArray(arena, c8, str_len),
.len = str_len,
};
MemCpy(str.value, string.value, string.len);
MemCpy(str.value+string.len, append.value, append.len);
return str;
}
static void
String8TrimSuffix(String8 *str, c8 delimiter)
{
if (!str || str->len == 0) return;
for (i64 i = i64(str->len)-1; i > 0; i -= 1)
{
if (str->value[i] == delimiter)
{
str->value[i] = '\0';
str->len = i == 0 ? 0 : u64(i - 1);
break;
}
}
}
static i64
String8FindLast(String8 str, c8 delimiter)
{
if (str.len == 0) return -1;
i64 result = 1;
for (i64 i = i64(str.len)-1; i >= 0; i -= 1)
{
if (str.value[i] == delimiter)
{
result = i;
break;
}
}
return result;
}
static b32
String8Eq(String8 l, String8 r)
{
return StrEqL(l.value, r.value, l.len);
}
static b32
String8StartsWith(String8 string, String8 cmp)
{
return StrEqL(string.value, cmp.value, cmp.len);
}
static String8
PreSplitString8(String8 string, String8 delimiter)
{
if (string.len == 0 || delimiter.len == 0) return string;
@ -76,7 +154,8 @@ String8 PreSplitString8(String8 string, String8 delimiter)
return (String8){ .len = new_len, .value = string.value };
}
String8 PreSplitNewString8(Arena *arena, String8 string, String8 delimiter)
static String8
PreSplitNewString8(Arena *arena, String8 string, String8 delimiter)
{
String8 result = PreSplitString8(string, delimiter);
@ -96,7 +175,8 @@ String8 PreSplitNewString8(Arena *arena, String8 string, String8 delimiter)
// ::Util::Memory::Functions::Start::
void MemZero(void *ptr, isize size)
void
MemZero(void *ptr, isize size)
{
if (!size || !ptr) return;
@ -129,7 +209,8 @@ void MemZero(void *ptr, isize size)
}
}
void MemCpy(rawptr dst, rawptr src, usize size)
void
MemCpy(rawptr dst, rawptr src, usize size)
{
if (size == 0) return;
@ -189,9 +270,10 @@ DefMathImpl(Abs);
// ::Util::Hashing::Functions::Start::
u64 static inline HashFromString(String8 string)
u64 static inline
HashFromString(String8 string)
{
return XXH3_64bits(string.value, string.len);
return XXH3_64bits_withSeed(string.value, string.len, HASH_SEED);
}
// ::Util::Hashing::Functions::End::
@ -200,7 +282,8 @@ u64 static inline HashFromString(String8 string)
// ::Util::Print::Functions::Start::
i32 Printf(char *fmt, ...)
i32
Printf(char *fmt, ...)
{
va_list arg;
@ -211,7 +294,8 @@ i32 Printf(char *fmt, ...)
return result;
}
i32 Printfln(char *fmt, ...)
i32
Printfln(char *fmt, ...)
{
va_list arg;
@ -222,7 +306,8 @@ i32 Printfln(char *fmt, ...)
return result;
}
i32 EPrintf(char *fmt, ...)
i32
EPrintf(char *fmt, ...)
{
va_list arg;
@ -233,12 +318,14 @@ i32 EPrintf(char *fmt, ...)
return result;
}
i32 EPrint(void *str)
i32
EPrint(void *str)
{
return pWriteStdErr(str, (isize)StrLen(str));
}
i32 _EPrintf(char *fmt, va_list arg)
i32
_EPrintf(char *fmt, va_list arg)
{
char buffer[1024];
@ -249,7 +336,8 @@ i32 _EPrintf(char *fmt, va_list arg)
return EPrint(&buffer);
}
i32 _Printf(char *fmt, va_list arg)
i32
_Printf(char *fmt, va_list arg)
{
char buffer[1024];
@ -264,7 +352,8 @@ i32 _Printf(char *fmt, va_list arg)
return pr_res;
}
i32 _Printfln(char *fmt, va_list arg)
i32
_Printfln(char *fmt, va_list arg)
{
char buffer[1024];
@ -291,18 +380,20 @@ i32 _Printfln(char *fmt, va_list arg)
// ::Util::Profiling::Functions::Start::
static inline void StartProfileBlock(ProfileBlock *block, c8 *label, u32 anchor_index)
static inline void
StartProfileBlock(ProfileBlock *block, c8 *label, u32 anchor_index)
{
block->anchor_index = anchor_index;
block->label = label;
block->start_tsc = pCPUTimerRead();
}
static inline void EndProfileBlock(ProfileBlock *block)
static inline void
EndProfileBlock(ProfileBlock *block)
{
u64 elapsed = pCPUTimerRead() - block->start_tsc;
ProfileAnchor *anchor = GLOBAL_PROFILER.anchors + block->anchor_index;
ProfileAnchor *anchor = g_Global_Profiler.anchors + block->anchor_index;
anchor->tsc_elapsed += elapsed;
anchor->hit_count += 1;
anchor->label = block->label;
@ -314,35 +405,41 @@ static inline void EndProfileBlock(ProfileBlock *block)
// ::Util::Async::Functions::Start::
static inline b32 MutTryLock(Mut *mut)
static inline b32
MutTryLock(Mut *mut)
{
b32 lock = false;
return pAtomicCompareExchangeB32(&mut->lock, &lock, 1);
}
static inline void MutUnlock(Mut *mut)
static inline void
MutUnlock(Mut *mut)
{
pAtomicStoreB32(&mut->lock, 0);
}
static inline void TicketMutInit(TicketMut *mut)
static inline void
TicketMutInit(TicketMut *mut)
{
mut->ticket = 0;
mut->next_ticket = 1;
}
static inline void TicketMutLock(TicketMut *mut)
static inline void
TicketMutLock(TicketMut *mut)
{
u32 ticket = pAtomicFetchIncrU32(&mut->ticket);
while (ticket != mut->next_ticket);
}
static inline void TicketMutUnlock(TicketMut *mut)
static inline void
TicketMutUnlock(TicketMut *mut)
{
pAtomicIncrU32(&mut->next_ticket);
}
static inline u32 JobQueueAdd(JobQueue *queue, u32 count)
static inline u32
JobQueueAdd(JobQueue *queue, u32 count)
{
u32 job_idx = pAtomicFetchIncrU32(&queue->queued);
pAtomicFetchIncrU32(&queue->remaining);
@ -350,30 +447,35 @@ static inline u32 JobQueueAdd(JobQueue *queue, u32 count)
return job_idx;
}
static inline u32 JobQueueGetCount(JobQueue *queue)
static inline u32
JobQueueGetCount(JobQueue *queue)
{
return pAtomicLoadU32(&queue->queued);
}
static inline void JobQueueMarkUnqueued(JobQueue *queue, u32 count)
static inline void
JobQueueMarkUnqueued(JobQueue *queue, u32 count)
{
Assert(queue->queued != 0, "queue queued is 0 before trying to mark dequeued");
pAtomicFetchSubU32(&queue->queued, count);
}
static inline void JobQueueMarkCompleted(JobQueue *queue, u32 count)
static inline void
JobQueueMarkCompleted(JobQueue *queue, u32 count)
{
Assert(queue->remaining != 0, "queue remaining is 0 before trying to mark completed");
pAtomicFetchSubU32(&queue->remaining, count);
}
static inline void JobQueueReset(JobQueue *queue)
static inline void
JobQueueReset(JobQueue *queue)
{
pAtomicFetchSubU32(&queue->queued, queue->queued);
pAtomicFetchSubU32(&queue->remaining, queue->remaining);
}
static inline b32 JobQueueCompleted(JobQueue *queue)
static inline b32
JobQueueCompleted(JobQueue *queue)
{
u32 remaining = pAtomicLoadU32(&queue->remaining);
return remaining == 0;

View File

@ -136,25 +136,30 @@ arr.cap = len
// ::Util::String8::Macros::
#define String8Array(v, c) MakeString8((u8 *)(v), sizeof(*(v))*(c))
#define String8Struct(v) MakeString8((u8 *)(v), sizeof(*(v)))
#define String8CStr(v) MakeString8((u8 *)v, StrLen(v))
#define String8Array(v, c) MakeString8((c8 *)(v), sizeof(*(v))*(c))
#define String8Struct(v) MakeString8((c8 *)(v), sizeof(*(v)))
#define String8CStr(v) MakeString8((c8 *)v, StrLen(v))
// ::Util::Defines::Header::
#define HM_MAX_SYMBOLS 256
#define DEFAULT_ALIGNMENT (2*sizeof(rawptr))
#define HASH_SEED 5995
constexpr u32 HM_MAX_SYMBOLS = 256;
constexpr usize DEFAULT_ALIGNMENT = (2*sizeof(rawptr));
constexpr u64 HASH_SEED = 5995;
// ::Util::Strings::Functions::Header::
String8 MakeString8(u8 *str, u64 len);
u32 StrLen(const char *str);
b32 StrEq(const char *l, const char *r);
i32 SPrintf(char *buf, rawptr fmt, ...);
String8 PreSplitString8(String8 string, String8 delimiter);
String8 PreSplitNewString8(Arena *arena, String8 string, String8 delimiter);
static b32 String8Eq(String8 l, String8 r);
static u32 StrLen(const char *str);
static b32 StrEqL(const char *l, const char *r, u64 len);
static b32 StrEq(const char *l, const char *r);
static i32 SPrintf(char *buf, int len, rawptr fmt, ...);
static void StrConcat(c8 *str, c8 *append);
static String8 MakeString8(c8 *str, u64 len);
static String8 String8Concat(Arena *arena, String8 string, String8 append);
static void String8TrimSuffix(String8 *str, c8 delimiter);
static i64 String8FindLast(String8 str, c8 delimiter);
static String8 PreSplitString8(String8 string, String8 delimiter);
static String8 PreSplitNewString8(Arena *arena, String8 string, String8 delimiter);
// ::Util::Memory::Functions::Header::

View File

@ -1,12 +1,14 @@
// VULKAN CONFIG
static const VkFormat VK_IMAGE_FORMATS[] = {
static const VkFormat
VK_IMAGE_FORMATS[] = {
VK_FORMAT_R16G16B16A16_UNORM,
VK_FORMAT_R8G8B8A8_UNORM,
};
static VkApplicationInfo app_info = {
static VkApplicationInfo
g_App_Info = {
.sType = STYPE(APPLICATION_INFO),
.pApplicationName = "Video Game",
.applicationVersion = VK_MAKE_API_VERSION(0, 0, 0, 1),
@ -15,14 +17,18 @@ static VkApplicationInfo app_info = {
.apiVersion = VK_API_VERSION_1_3,
};
static const char *instance_layers[] = {
static const char *
instance_layers[] =
{
#ifdef BUILD_DEBUG
"VK_LAYER_KHRONOS_validation"
#endif
};
static const char *instance_extensions[] = {
static const char *
g_Instance_Extensions[] =
{
VK_KHR_SURFACE_EXTENSION_NAME,
#ifdef __linux__
@ -36,25 +42,30 @@ static const char *instance_extensions[] = {
#ifdef BUILD_DEBUG
VK_EXT_DEBUG_UTILS_EXTENSION_NAME,
#endif
};
static VkInstanceCreateInfo inst_info = {
static VkInstanceCreateInfo
g_Instance_Info =
{
.sType = STYPE(INSTANCE_CREATE_INFO),
.pApplicationInfo = &app_info,
.pApplicationInfo = &g_App_Info,
.enabledLayerCount = sizeof(instance_layers) / sizeof(char *),
.ppEnabledLayerNames = instance_layers,
.enabledExtensionCount = sizeof(instance_extensions) / sizeof(char *),
.ppEnabledExtensionNames = instance_extensions,
.enabledExtensionCount = sizeof(g_Instance_Extensions) / sizeof(char *),
.ppEnabledExtensionNames = g_Instance_Extensions,
};
const char *device_extensions[] = {
const char *
g_Device_Extensions[] =
{
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME,
};
#ifdef BUILD_DEBUG
static VkDebugUtilsMessengerCreateInfoEXT debug_msg_info = {
static VkDebugUtilsMessengerCreateInfoEXT
g_Debug_Message_Info =
{
.sType = STYPE(DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT),
.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
@ -65,15 +76,19 @@ static VkDebugUtilsMessengerCreateInfoEXT debug_msg_info = {
};
#endif
static VkPhysicalDeviceVulkan13Features vk_13_features = {
static VkPhysicalDeviceVulkan13Features
g_Vk_13_Features =
{
.sType = STYPE(PHYSICAL_DEVICE_VULKAN_1_3_FEATURES),
.synchronization2 = VK_TRUE,
.dynamicRendering = VK_TRUE
};
static VkPhysicalDeviceVulkan12Features vk_12_features = {
static VkPhysicalDeviceVulkan12Features
g_Vk_12_Features =
{
.sType = STYPE(PHYSICAL_DEVICE_VULKAN_1_2_FEATURES),
.pNext = &vk_13_features,
.pNext = &g_Vk_13_Features,
.descriptorIndexing = VK_TRUE,
.bufferDeviceAddress = VK_TRUE,
.descriptorBindingUniformBufferUpdateAfterBind = VK_TRUE,
@ -86,14 +101,18 @@ static VkPhysicalDeviceVulkan12Features vk_12_features = {
.runtimeDescriptorArray = VK_TRUE,
};
static VkPhysicalDeviceVulkan11Features vk_11_features = {
static VkPhysicalDeviceVulkan11Features
g_Vk_11_Features =
{
.sType = STYPE(PHYSICAL_DEVICE_VULKAN_1_1_FEATURES),
.pNext = &vk_12_features
.pNext = &g_Vk_12_Features
};
static const VkPhysicalDeviceFeatures2 vk_features_2 = {
static const VkPhysicalDeviceFeatures2
g_Vk_Features_2 =
{
.sType = STYPE(PHYSICAL_DEVICE_FEATURES_2),
.pNext = &vk_11_features,
.pNext = &g_Vk_11_Features,
.features = {
.shaderUniformBufferArrayDynamicIndexing = VK_TRUE,
.shaderSampledImageArrayDynamicIndexing = VK_TRUE,
@ -103,40 +122,54 @@ static const VkPhysicalDeviceFeatures2 vk_features_2 = {
},
};
static VkDeviceCreateInfo device_info = {
static VkDeviceCreateInfo
g_Device_Info =
{
.sType = STYPE(DEVICE_CREATE_INFO),
.pNext = &vk_features_2,
.ppEnabledExtensionNames = device_extensions,
.enabledExtensionCount = Len(device_extensions),
.pNext = &g_Vk_Features_2,
.ppEnabledExtensionNames = g_Device_Extensions,
.enabledExtensionCount = Len(g_Device_Extensions),
.pEnabledFeatures = NULL,
};
static VmaAllocatorCreateInfo vma_create_info = {
static VmaAllocatorCreateInfo
g_VMA_Create_Info =
{
.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT,
.vulkanApiVersion = VK_API_VERSION_1_3,
};
static VkCommandPoolCreateInfo pool_create_info = {
static VkCommandPoolCreateInfo
g_Pool_Create_Info =
{
.sType = STYPE(COMMAND_POOL_CREATE_INFO),
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
};
static VkFenceCreateInfo fence_create_info = {
static VkFenceCreateInfo
g_Fence_Create_Info =
{
.sType = STYPE(FENCE_CREATE_INFO),
.flags = VK_FENCE_CREATE_SIGNALED_BIT,
};
static VkSemaphoreCreateInfo semaphore_create_info = {
static VkSemaphoreCreateInfo
g_Semaphore_Create_info =
{
.sType = STYPE(SEMAPHORE_CREATE_INFO),
};
static VkCommandBufferAllocateInfo cmd_buf_info = {
static VkCommandBufferAllocateInfo
g_Command_Buffer_Info =
{
.sType = STYPE(COMMAND_BUFFER_ALLOCATE_INFO),
.commandBufferCount = 1,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
};
static VkSwapchainCreateInfoKHR swapchain_create_info = {
static VkSwapchainCreateInfoKHR
g_Swap_Info =
{
.sType = STYPE(SWAPCHAIN_CREATE_INFO_KHR),
.imageArrayLayers = 1,
.imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
@ -145,7 +178,9 @@ static VkSwapchainCreateInfoKHR swapchain_create_info = {
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
static VkImageViewCreateInfo sc_image_view_create_info = {
static VkImageViewCreateInfo
g_Swap_View_Info =
{
.sType = STYPE(IMAGE_VIEW_CREATE_INFO),
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.components = {
@ -163,7 +198,9 @@ static VkImageViewCreateInfo sc_image_view_create_info = {
},
};
static VkImageCreateInfo draw_image_create_info = {
static VkImageCreateInfo
g_Draw_Image_Info =
{
.sType = STYPE(IMAGE_CREATE_INFO),
.imageType = VK_IMAGE_TYPE_2D,
.mipLevels = 1,
@ -173,7 +210,9 @@ static VkImageCreateInfo draw_image_create_info = {
.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
};
static VkImageViewCreateInfo draw_image_view_create_info = {
static VkImageViewCreateInfo
g_Draw_View_Info =
{
.sType = STYPE(IMAGE_VIEW_CREATE_INFO),
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.subresourceRange = {
@ -185,7 +224,9 @@ static VkImageViewCreateInfo draw_image_view_create_info = {
},
};
static VkImageCreateInfo depth_image_create_info = {
static VkImageCreateInfo
g_Depth_Image_Info =
{
.sType = STYPE(IMAGE_CREATE_INFO),
.imageType = VK_IMAGE_TYPE_2D,
.mipLevels = 1,
@ -196,7 +237,9 @@ static VkImageCreateInfo depth_image_create_info = {
.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
static VkImageViewCreateInfo depth_image_view_create_info = {
static VkImageViewCreateInfo
g_Depth_View_Info =
{
.sType = STYPE(IMAGE_VIEW_CREATE_INFO),
.viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = VK_FORMAT_D32_SFLOAT,
@ -213,93 +256,120 @@ static VkImageViewCreateInfo depth_image_view_create_info = {
// PIPELINES & DESCRIPTORS
//
static VkDescriptorPoolSize descriptor_pool_sizes[] = {
static VkDescriptorPoolSize
g_Desc_Pool_Sizes[] =
{
{ .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, .descriptorCount = 4096 },
{ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .descriptorCount = 4096},
{ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorCount = 4096},
{ .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorCount = 4096},
};
static VkDescriptorPoolCreateInfo desc_pool_info = {
static VkDescriptorPoolCreateInfo
g_Desc_Pool_Info =
{
.sType = STYPE(DESCRIPTOR_POOL_CREATE_INFO),
.poolSizeCount = Len(descriptor_pool_sizes),
.pPoolSizes = descriptor_pool_sizes,
.poolSizeCount = Len(g_Desc_Pool_Sizes),
.pPoolSizes = g_Desc_Pool_Sizes,
.maxSets = 12, // Not sure if this is correct
.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
};
static VkDescriptorBindingFlags shared_desc_binding_flags[] = {
static VkDescriptorBindingFlags
g_Shared_Binding_Flags[] =
{
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT,
};
static VkDescriptorSetLayoutBindingFlagsCreateInfo shared_layout_binding_flags_info = {
static VkDescriptorSetLayoutBindingFlagsCreateInfo
g_Shared_Desc_Flag_Info =
{
.sType = STYPE(DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO),
.bindingCount = Len(shared_desc_binding_flags),
.pBindingFlags = shared_desc_binding_flags,
.bindingCount = Len(g_Shared_Binding_Flags),
.pBindingFlags = g_Shared_Binding_Flags,
};
static VkDescriptorSetLayoutBinding shared_layout_bindings[] = {
static VkDescriptorSetLayoutBinding
g_Shared_Desc_Bindings[] =
{
{ .binding = 0, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_ALL },
{ .binding = 1, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_ALL },
{ .binding = 2, .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_ALL },
{ .binding = 3, .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER, .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_ALL },
};
static VkDescriptorSetLayoutCreateInfo shared_layout_create_info = {
static VkDescriptorSetLayoutCreateInfo
g_Shared_Desc_Layout_Info =
{
.sType = STYPE(DESCRIPTOR_SET_LAYOUT_CREATE_INFO),
.pNext = &shared_layout_binding_flags_info,
.bindingCount = Len(shared_layout_bindings),
.pBindings = shared_layout_bindings,
.pNext = &g_Shared_Desc_Flag_Info,
.bindingCount = Len(g_Shared_Desc_Bindings),
.pBindings = g_Shared_Desc_Bindings,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
};
static VkDescriptorType desc_type_map[vDT_MAX] = {
static VkDescriptorType
g_Desc_Type_Map[vDT_MAX] =
{
[vDT_SAMPLED_IMAGE] = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
[vDT_MATERIAL] = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
[vDT_MESH] = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
};
static VkDescriptorBindingFlags bindless_desc_binding_flags = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT;
static VkDescriptorBindingFlags
g_Bindless_Binding_Flags = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT;
static VkDescriptorSetLayoutBindingFlagsCreateInfo bindless_layout_flag_create_info = {
static VkDescriptorSetLayoutBindingFlagsCreateInfo
g_Bindless_Desc_Flag_Info =
{
.sType = STYPE(DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO),
.bindingCount = 1,
.pBindingFlags = &bindless_desc_binding_flags,
.pBindingFlags = &g_Bindless_Binding_Flags,
};
static VkDescriptorSetLayoutBinding bindless_layout_binding = {
static VkDescriptorSetLayoutBinding
g_Bindless_Desc_Binding =
{
.binding = 0,
.descriptorCount = 1024,
.stageFlags = VK_SHADER_STAGE_ALL,
};
static VkDescriptorSetLayoutCreateInfo bindless_layout_create_info = {
static VkDescriptorSetLayoutCreateInfo
g_Bindless_Desc_Info =
{
.sType = STYPE(DESCRIPTOR_SET_LAYOUT_CREATE_INFO),
.pNext = &bindless_layout_flag_create_info,
.pNext = &g_Bindless_Desc_Flag_Info,
.bindingCount = 1,
.pBindings = &bindless_layout_binding,
.pBindings = &g_Bindless_Desc_Binding,
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
};
static VkDescriptorSetAllocateInfo set_allocate_info = {
static VkDescriptorSetAllocateInfo
g_Descriptor_Alloc_Info =
{
.sType = STYPE(DESCRIPTOR_SET_ALLOCATE_INFO),
.descriptorSetCount = vDT_MAX,
};
static VkPushConstantRange push_const_range = {
static VkPushConstantRange
g_Push_Const_Range =
{
.offset = 0,
.size = sizeof(rPushConst),
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT,
};
static VkPipelineLayoutCreateInfo pipeline_layout_create_info = {
static VkPipelineLayoutCreateInfo
g_Pipeline_Layout_Info =
{
.sType = STYPE(PIPELINE_LAYOUT_CREATE_INFO),
.setLayoutCount = vDT_MAX,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &push_const_range,
.pPushConstantRanges = &g_Push_Const_Range,
};
//
@ -309,15 +379,17 @@ static VkPipelineLayoutCreateInfo pipeline_layout_create_info = {
#define PIPELINE_DYNAMIC_STATE { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }
static VkDynamicState pipeline_dynamic_state[] = PIPELINE_DYNAMIC_STATE;
static VkDynamicState
g_Pipeline_Dynamic_State[] = PIPELINE_DYNAMIC_STATE;
#define PIPELINE_DEFAULT_DYN_STATE_INFO { \
.sType = STYPE(PIPELINE_DYNAMIC_STATE_CREATE_INFO), \
.pDynamicStates = pipeline_dynamic_state, \
.dynamicStateCount = Len(pipeline_dynamic_state), \
.pDynamicStates = g_Pipeline_Dynamic_State, \
.dynamicStateCount = Len(g_Pipeline_Dynamic_State), \
}
static VkPipelineDynamicStateCreateInfo pipeline_default_dyn_state_info = PIPELINE_DEFAULT_DYN_STATE_INFO;
static VkPipelineDynamicStateCreateInfo
g_Pipeline_Default_Dynamic_Info = PIPELINE_DEFAULT_DYN_STATE_INFO;
#define PIPELINE_DEFAULT_ASSEMBLY_INFO { \
.sType = STYPE(PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO), \
@ -325,7 +397,8 @@ static VkPipelineDynamicStateCreateInfo pipeline_default_dyn_state_info = PIPELI
.primitiveRestartEnable = VK_FALSE, \
}
static VkPipelineInputAssemblyStateCreateInfo pipeline_default_assembly_info = PIPELINE_DEFAULT_ASSEMBLY_INFO;
static VkPipelineInputAssemblyStateCreateInfo
g_Pipeline_Default_Assembly_Info = PIPELINE_DEFAULT_ASSEMBLY_INFO;
#define PIPELINE_DEFAULT_RASTERIZATION_INFO { \
.sType = STYPE(PIPELINE_RASTERIZATION_STATE_CREATE_INFO), \
@ -334,7 +407,8 @@ static VkPipelineInputAssemblyStateCreateInfo pipeline_default_assembly_info = P
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, \
}
static VkPipelineRasterizationStateCreateInfo pipeline_default_rasterization_info = PIPELINE_DEFAULT_RASTERIZATION_INFO;
static VkPipelineRasterizationStateCreateInfo
g_Pipeline_Default_Rasterization_Info = PIPELINE_DEFAULT_RASTERIZATION_INFO;
#define PIPELINE_DEFAULT_MULTISAMPLE_INFO { \
.sType = STYPE(PIPELINE_MULTISAMPLE_STATE_CREATE_INFO), \
@ -344,7 +418,8 @@ static VkPipelineRasterizationStateCreateInfo pipeline_default_rasterization_inf
.alphaToOneEnable = VK_FALSE, \
}
static VkPipelineMultisampleStateCreateInfo pipeline_default_multisample_info = PIPELINE_DEFAULT_MULTISAMPLE_INFO;
static VkPipelineMultisampleStateCreateInfo
g_Pipeline_Default_Multisample_Info = PIPELINE_DEFAULT_MULTISAMPLE_INFO;
#define PIPELINE_DEFAULT_DEPTH_INFO { \
.sType = STYPE(PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO), \
@ -357,37 +432,42 @@ static VkPipelineMultisampleStateCreateInfo pipeline_default_multisample_info =
.maxDepthBounds = 1.0, \
}
static VkPipelineDepthStencilStateCreateInfo pipeline_default_depth_info = PIPELINE_DEFAULT_DEPTH_INFO;
static VkPipelineDepthStencilStateCreateInfo
g_Pipeline_Default_Depth_Info = PIPELINE_DEFAULT_DEPTH_INFO;
#define PIPELINE_DEFAULT_RENDERING_INFO { \
.sType = STYPE(PIPELINE_RENDERING_CREATE_INFO), \
.colorAttachmentCount = 1, \
}
static VkPipelineRenderingCreateInfo pipeline_default_rendering_info = PIPELINE_DEFAULT_RENDERING_INFO;
static VkPipelineRenderingCreateInfo
g_Pipeline_Default_Rendering_Info = PIPELINE_DEFAULT_RENDERING_INFO;
#define PIPELINE_DEFAULT_BLEND_ATTACH_STATE { \
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, \
.blendEnable = VK_FALSE, \
}
static VkPipelineColorBlendAttachmentState pipeline_default_blend_attach_state = PIPELINE_DEFAULT_BLEND_ATTACH_STATE;
static VkPipelineColorBlendAttachmentState
g_Pipeline_Default_Blend_State = PIPELINE_DEFAULT_BLEND_ATTACH_STATE;
#define PIPELINE_DEFAULT_BLEND_INFO { \
.sType = STYPE(PIPELINE_COLOR_BLEND_STATE_CREATE_INFO), \
.logicOpEnable = VK_FALSE, \
.logicOp = VK_LOGIC_OP_COPY, \
.attachmentCount = 1, \
.pAttachments = &pipeline_default_blend_attach_state, \
.pAttachments = &g_Pipeline_Default_Blend_State, \
}
static VkPipelineColorBlendStateCreateInfo pipeline_default_blend_info = PIPELINE_DEFAULT_BLEND_INFO;
static VkPipelineColorBlendStateCreateInfo
g_Pipeline_Default_Blend_Info = PIPELINE_DEFAULT_BLEND_INFO;
#define PIPELINE_DEFAULT_VERTEX_INFO { \
.sType = STYPE(PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO), \
}
static VkPipelineVertexInputStateCreateInfo pipeline_default_vertex_info = PIPELINE_DEFAULT_VERTEX_INFO;
static VkPipelineVertexInputStateCreateInfo
g_Pipeline_Default_Vertex_Info = PIPELINE_DEFAULT_VERTEX_INFO;
#define PIPELINE_DEFAULT_VIEWPORT_INFO { \
.sType = STYPE(PIPELINE_VIEWPORT_STATE_CREATE_INFO), \
@ -395,51 +475,56 @@ static VkPipelineVertexInputStateCreateInfo pipeline_default_vertex_info = PIPEL
.scissorCount = 1, \
}
const static VkPipelineViewportStateCreateInfo pipeline_default_viewport_info = PIPELINE_DEFAULT_VIEWPORT_INFO;
const static VkPipelineViewportStateCreateInfo
g_Pipeline_Default_Viewport_Info = PIPELINE_DEFAULT_VIEWPORT_INFO;
#define INIT_PIPELINE_DEFAULTS(pipeline) \
VkPipelineDynamicStateCreateInfo pipeline##_default_dynamic_info = PIPELINE_DEFAULT_DYN_STATE_INFO; \
VkPipelineInputAssemblyStateCreateInfo pipeline##_default_assembly_info = PIPELINE_DEFAULT_ASSEMBLY_INFO; \
VkPipelineRasterizationStateCreateInfo pipeline##_default_rasterization_info = PIPELINE_DEFAULT_RASTERIZATION_INFO; \
VkPipelineMultisampleStateCreateInfo pipeline##_default_multisample_info = PIPELINE_DEFAULT_MULTISAMPLE_INFO; \
VkPipelineDepthStencilStateCreateInfo pipeline##_default_depth_info = PIPELINE_DEFAULT_DEPTH_INFO; \
VkPipelineRenderingCreateInfo pipeline##_default_rendering_info = PIPELINE_DEFAULT_RENDERING_INFO; \
VkPipelineColorBlendStateCreateInfo pipeline##_default_blend_info = PIPELINE_DEFAULT_BLEND_INFO; \
VkPipelineVertexInputStateCreateInfo pipeline##_default_vertex_info = PIPELINE_DEFAULT_VERTEX_INFO; \
VkPipelineViewportStateCreateInfo pipeline##_default_viewport_info = PIPELINE_DEFAULT_VIEWPORT_INFO; \
VkGraphicsPipelineCreateInfo pipeline##_create_info = { \
VkPipelineDynamicStateCreateInfo g_##pipeline##_Default_Dynamic_Info = PIPELINE_DEFAULT_DYN_STATE_INFO; \
VkPipelineInputAssemblyStateCreateInfo g_##pipeline##_Default_Assembly_Info = PIPELINE_DEFAULT_ASSEMBLY_INFO; \
VkPipelineRasterizationStateCreateInfo g_##pipeline##_Default_Rasterization_Info = PIPELINE_DEFAULT_RASTERIZATION_INFO; \
VkPipelineMultisampleStateCreateInfo g_##pipeline##_Default_Multisample_Info = PIPELINE_DEFAULT_MULTISAMPLE_INFO; \
VkPipelineDepthStencilStateCreateInfo g_##pipeline##_Default_Depth_Info = PIPELINE_DEFAULT_DEPTH_INFO; \
VkPipelineRenderingCreateInfo g_##pipeline##_Default_Rendering_Info = PIPELINE_DEFAULT_RENDERING_INFO; \
VkPipelineColorBlendStateCreateInfo g_##pipeline##_Default_Blend_Info = PIPELINE_DEFAULT_BLEND_INFO; \
VkPipelineVertexInputStateCreateInfo g_##pipeline##_Default_Vertex_Info = PIPELINE_DEFAULT_VERTEX_INFO; \
VkPipelineViewportStateCreateInfo g_##pipeline##_Default_Viewport_Info = PIPELINE_DEFAULT_VIEWPORT_INFO; \
VkGraphicsPipelineCreateInfo g_##pipeline##_Create_Info = { \
.sType = STYPE(GRAPHICS_PIPELINE_CREATE_INFO), \
.pNext = &pipeline##_default_rendering_info, \
.pVertexInputState = &pipeline##_default_vertex_info, \
.pInputAssemblyState = &pipeline##_default_assembly_info, \
.pViewportState = &pipeline##_default_viewport_info, \
.pRasterizationState = &pipeline##_default_rasterization_info,\
.pMultisampleState = &pipeline##_default_multisample_info, \
.pColorBlendState = &pipeline##_default_blend_info, \
.pDepthStencilState = &pipeline##_default_depth_info, \
.pDynamicState = &pipeline##_default_dynamic_info, \
.pNext = &g_##pipeline##_Default_Rendering_Info, \
.pVertexInputState = &g_##pipeline##_Default_Vertex_Info, \
.pInputAssemblyState = &g_##pipeline##_Default_Assembly_Info, \
.pViewportState = &g_##pipeline##_Default_Viewport_Info, \
.pRasterizationState = &g_##pipeline##_Default_Rasterization_Info,\
.pMultisampleState = &g_##pipeline##_Default_Multisample_Info, \
.pColorBlendState = &g_##pipeline##_Default_Blend_Info, \
.pDepthStencilState = &g_##pipeline##_Default_Depth_Info, \
.pDynamicState = &g_##pipeline##_Default_Dynamic_Info, \
};
INIT_PIPELINE_DEFAULTS(cube);
INIT_PIPELINE_DEFAULTS(CUBE);
// GUI Pipeline
INIT_PIPELINE_DEFAULTS(gui);
INIT_PIPELINE_DEFAULTS(GUI);
VkVertexInputBindingDescription gui_input_bind_desc = {
VkVertexInputBindingDescription
gui_input_bind_desc = {
.binding = 0,
.stride = sizeof(rUIVertex),
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
};
VkVertexInputAttributeDescription gui_input_descriptions[] = {
VkVertexInputAttributeDescription
gui_input_descriptions[] = {
{ .binding = 0, .location = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = 0 },
{ .binding = 0, .location = 1, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(rUIVertex, p1) },
{ .binding = 0, .location = 2, .format = VK_FORMAT_R32G32B32A32_SFLOAT, .offset = offsetof(rUIVertex, col) },
{ .binding = 0, .location = 3, .format = VK_FORMAT_R32_UINT, .offset = offsetof(rUIVertex, tex_idx) },
};
VkPipelineVertexInputStateCreateInfo gui_vertex_input_info = {
VkPipelineVertexInputStateCreateInfo
gui_vertex_input_info =
{
.sType = STYPE(PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO),
.vertexBindingDescriptionCount = 1,
.pVertexBindingDescriptions = &gui_input_bind_desc,
@ -447,40 +532,49 @@ VkPipelineVertexInputStateCreateInfo gui_vertex_input_info = {
.pVertexAttributeDescriptions = gui_input_descriptions,
};
VkPipelineInputAssemblyStateCreateInfo gui_assembly_info = {
VkPipelineInputAssemblyStateCreateInfo
gui_assembly_info =
{
.sType = STYPE(PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO),
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
// PBR Pipeline
INIT_PIPELINE_DEFAULTS(pbr);
INIT_PIPELINE_DEFAULTS(PBR);
VkVertexInputBindingDescription pbr_input_bind_desc = {
VkVertexInputBindingDescription
pbr_input_bind_desc =
{
.binding = 0,
.stride = sizeof(rPBRVertex),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
};
VkPipelineVertexInputStateCreateInfo pbr_vertex_input_info = {
VkPipelineVertexInputStateCreateInfo
pbr_vertex_input_info =
{
.sType = STYPE(PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO),
.vertexBindingDescriptionCount = 1,
.pVertexBindingDescriptions = &pbr_input_bind_desc,
};
VkPipelineInputAssemblyStateCreateInfo pbr_assembly_info = {
VkPipelineInputAssemblyStateCreateInfo
pbr_assembly_info =
{
.sType = STYPE(PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO),
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
static void vCustomizePipelines()
static void
vCustomizePipelines()
{
// GUI
gui_create_info.pVertexInputState = &gui_vertex_input_info;
gui_create_info.pInputAssemblyState = &gui_assembly_info;
g_GUI_Create_Info.pVertexInputState = &gui_vertex_input_info;
g_GUI_Create_Info.pInputAssemblyState = &gui_assembly_info;
// PBR
pbr_create_info.pVertexInputState = &pbr_vertex_input_info;
pbr_create_info.pInputAssemblyState = &pbr_assembly_info;
g_PBR_Create_Info.pVertexInputState = &pbr_vertex_input_info;
g_PBR_Create_Info.pInputAssemblyState = &pbr_assembly_info;
}