refactor of function/type names

This commit is contained in:
Matthew 2025-04-26 13:15:41 +10:00
parent fee5f311f2
commit 7a3844013e
23 changed files with 764 additions and 850 deletions

View File

@ -57,13 +57,13 @@ static Arena *ArenaInit(rawptr buffer, usize size)
static Arena *ArenaCreate(usize size)
{
u8 *mem = MemAllocZeroed(size);
u8 *mem = pMemAllocZeroed(size);
return ArenaInit(mem, size);
}
static Arena *ArenaCreateDebug(usize size, u32 init_line_no)
{
u8 *mem = MemAllocZeroed(size);
u8 *mem = pMemAllocZeroed(size);
return ArenaInitDebug(mem, size, init_line_no);
}
@ -107,7 +107,7 @@ static void ArenaFreeZeroed(Arena *arena)
static void DeallocArena(Arena *arena)
{
MemFree(arena, arena->length);
pMemFree(arena, arena->length);
}
static Arena * ArenaInitDebug(rawptr buffer, usize size, u32 init_line_no)
@ -126,7 +126,7 @@ static Arena * ArenaInitDebug(rawptr buffer, usize size, u32 init_line_no)
static void InitAllocator(usize init_size)
{
ALLOC.grow_size = init_size;
ALLOC.buffer = MemAllocZeroed(init_size);
ALLOC.buffer = pMemAllocZeroed(init_size);
ALLOC.size = init_size;
ALLOC.free_size = init_size;
@ -141,7 +141,7 @@ static void InitAllocator(usize init_size)
static void DeinitAlloc()
{
MemFree(ALLOC.buffer, ALLOC.size);
pMemFree(ALLOC.buffer, ALLOC.size);
}
static rawptr Alloc(usize size)
@ -186,7 +186,7 @@ static void Free(rawptr ptr)
static void AllocGrow(usize size)
{
usize grow_size = size < ALLOC.grow_size ? ALLOC.grow_size : ALLOC.grow_size + size;
MemRealloc(ALLOC.buffer, ALLOC.size, ALLOC.size + grow_size);
pMemRealloc(ALLOC.buffer, ALLOC.size, ALLOC.size + grow_size);
RBTreeInsert(ALLOC.tree, grow_size, ALLOC.buffer + ALLOC.size); // TODO: check this if things fuck up it could be wrong
@ -225,7 +225,7 @@ static void FLMemFree(rawptr ptr)
static void FreeListInit(FLAlloc *alloc, usize size)
{
alloc->lists = MemAllocZeroed(sizeof(FreeList *) * 16);
alloc->lists = pMemAllocZeroed(sizeof(FreeList *) * 16);
alloc->list_count = 1;
alloc->list_capacity = 16;
alloc->nil = &FL_NIL_NODE;
@ -238,7 +238,7 @@ static void FreeListInit(FLAlloc *alloc, usize size)
static void _FreeListInit(FreeList **alloc, usize size)
{
*alloc = (FreeList *)MemAllocZeroed(size);
*alloc = (FreeList *)pMemAllocZeroed(size);
(*alloc)->data = (rawptr)(((uintptr)*alloc) + ((uintptr)sizeof(FreeList)));
(*alloc)->size = size;
(*alloc)->used = sizeof(FreeList);
@ -252,7 +252,7 @@ static void FreeListFreeAll(FLAlloc *alloc)
{
for (u32 i = 1; i < alloc->list_count; i++)
{
MemFree(alloc->lists[i], alloc->lists[i]->size);
pMemFree(alloc->lists[i], alloc->lists[i]->size);
alloc->lists[i] = NULL;
}
@ -306,9 +306,9 @@ static void FreeListGrow(FLAlloc *alloc, usize alloc_size)
if (i >= alloc->list_capacity)
{
alloc->list_capacity += 16;
rawptr new_mem = MemAlloc(sizeof(FreeList *) * alloc->list_capacity);
rawptr new_mem = pMemAlloc(sizeof(FreeList *) * alloc->list_capacity);
MemCpy(new_mem, alloc->lists, i);
MemFree(alloc->lists, sizeof(FreeList *) * i);
pMemFree(alloc->lists, sizeof(FreeList *) * i);
alloc->lists = new_mem;
}

View File

@ -27,7 +27,7 @@ static b32 ASSET_HEADER_LOADED = false;
// ::Assets::Init::Functions::Start::
static void LoadAssetPackHeader()
static void apInit()
{
MemCpy(&File_Header, ASSET_PACK, sizeof(FileHeader));
@ -46,11 +46,11 @@ static void LoadAssetPackHeader()
// ::Assets::Loading::Functions::Start::
static Asset AssetPackLoadTexture(TextureAsset asset_id)
static Asset apLoadTexture(TextureAsset asset_id)
{
if (!ASSET_HEADER_LOADED)
{
LoadAssetPackHeader();
apInit();
}
Assert(asset_id < i32(TEXTURE_ASSET_MAX), "LoadTextureAsset failure: asset_id is higher than TEXTURE_ASSET_MAX");
@ -79,11 +79,11 @@ static Asset AssetPackLoadTexture(TextureAsset asset_id)
return asset;
}
static Asset AssetPackLoadShader(ShaderAsset asset_id)
static Asset apLoadShader(ShaderAsset asset_id)
{
if (!ASSET_HEADER_LOADED)
{
LoadAssetPackHeader();
apInit();
}
Assert(asset_id < SHADER_ASSET_MAX, "LoadShaderAsset failure: asset_id is higher than SHADER_ASSET_MAX");
@ -101,7 +101,7 @@ static Asset AssetPackLoadShader(ShaderAsset asset_id)
return asset;
}
static void AssetPackUnloadTexture(Asset asset)
static void apUnloadTexture(Asset asset)
{
Assert(asset.bytes != NULL, "UnloadTextureAsset assert failure: ptr is NULL");
@ -118,7 +118,7 @@ static void AssetPackUnloadTexture(Asset asset)
}
}
static void AssetPackUnloadShader(Asset asset)
static void apUnloadShader(Asset asset)
{
Assert(asset.bytes != NULL, "UnloadShaderAsset assert failure: ptr is NULL");

View File

@ -104,17 +104,17 @@ typedef struct FileHeader
// ::Assets::Init::Functions::Header::
static void AssetPackLoadHeader();
static void apInit();
// ::Assets::Loading::Functions::Header::
static Asset AssetPackLoadTexture(TextureAsset asset_id);
static Asset AssetPackLoadShader(ShaderAsset asset_id);
static void AssetPackUnloadTexture(Asset asset);
static void AssetPackUnloadShader(Asset asset);
static Asset apLoadTexture(TextureAsset asset_id);
static Asset apLoadShader(ShaderAsset asset_id);
static void apUnloadTexture(Asset asset);
static void apUnloadShader(Asset asset);
// ::Assets::Util::Functions::Header::
// TODO(MA): Implement async asset handling
static inline b32 AssetPackMarkUnloaded(AssetType type, u32 index);
static inline void AssetPackMarkLoaded(AssetType type, u32 index);
static inline b32 apMarkUnloaded(AssetType type, u32 index);
static inline void apMarkLoaded(AssetType type, u32 index);

View File

@ -54,24 +54,24 @@ int main(int argc, char **argv)
Arena *renderer_arena = ArenaCreateDebug(MB(16), __LINE__);
Arena *game_arena = ArenaCreateDebug(MB(16), __LINE__);
Assert(CreatePlatformWindow(WINDOW_NAME), "Failed to initialize the window");
Assert(pWindowInit(WINDOW_NAME), "Failed to initialize the window");
GameInput *inputs = MakeArray(arena, GameInput, 10);
pGameInput *inputs = MakeArray(arena, pGameInput, 10);
u32 i_count = 0;
WaitForWindowEvent(inputs);
pWindowEventWaitFor(inputs);
GameContext ctx = {0};
gGameCtx ctx = {0};
InitializeGame(renderer_arena, &ctx, game_arena);
gInit(renderer_arena, &ctx, game_arena);
while (!global_quit)
{
GetWindowEvents(inputs, &i_count);
RunCycle(&ctx, inputs, i_count);
pWindowEventsGet(inputs, &i_count);
gRunCycle(&ctx, inputs, i_count);
}
DestroyGame();
gDestroy();
}
#endif // __linux__

View File

@ -20,7 +20,7 @@ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line
}
#endif
u8 *mem = (u8 *)MemAllocZeroed(MB(32));
u8 *mem = (u8 *)pMemAllocZeroed(MB(32));
Arena *arena = ArenaInitDebug(mem, MB(32), 1);
isize renderer_mem_size = MB(16);
@ -32,20 +32,20 @@ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line
rawptr game_mem = ArenaAlloc(arena, game_mem_size);
Arena *game_arena = ArenaInitDebug(game_mem, game_mem_size, 3);
Assert(CreatePlatformWindow(WINDOW_NAME), "Failed to initialize window");
Assert(pWindowInit(WINDOW_NAME), "Failed to initialize window");
GameInput *inputs = MakeArray(arena, GameInput, 10);
pGameInput *inputs = MakeArray(arena, pGameInput, 10);
u32 i_count = 0;
InitializeGame(renderer_arena);
gInit(renderer_arena);
while (!global_quit)
{
GetWindowEvents();
RunCycle(game_arena, inputs, i_count);
pWindowEventsGet();
gRunCycle(game_arena, inputs, i_count);
}
DestroyGame();
gDestroy();
}
#endif // _WIN32

View File

@ -16,28 +16,28 @@ i16 mouse_pos_y = 0;
// ::Game::Init::Functions::Start::
static void InitializeGame(Arena *arena, GameContext *ctx, Arena *ctx_arena)
static void gInit(Arena *arena, gGameCtx *ctx, Arena *ctx_arena)
{
Assert(InitRenderer(arena), "Failed to initialize the renderer");
Assert(rInit(arena), "Failed to initialize the renderer");
ctx->gui.vertices = MakeArray(ctx_arena, GUIVertex, 128);
ctx->gui.vertices = MakeArray(ctx_arena, rUIVertex, 128);
ctx->gui.vertices_len = 0;
ctx->gui.indices = MakeArray(ctx_arena, u32, 768);
ctx->gui.indices_len = 0;
ctx->gui.instance_count = 0;
ctx->windows = MakeArray(ctx_arena, GUIWindow, 32);
ctx->windows = MakeArray(ctx_arena, gWindowWidget, 32);
ctx->window_len = 0;
ctx->buttons = MakeArray(ctx_arena, GUIButton, 64);
ctx->buttons = MakeArray(ctx_arena, gButtonWidget, 64);
ctx->btn_len = 0;
ctx->arena = arena;
}
static void DestroyGame()
static void gDestroy()
{
DestroyRenderer();
rDestroy();
}
// ::Game::Init::Functions::End::
@ -46,62 +46,62 @@ static void DestroyGame()
// ::Game::GameLoop::Functions::Start::
static void RunCycle(GameContext *ctx, GameInput *inputs, u32 i_count)
static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
{
ResetBufferQueue();
rBufferQueueReset();
PrepareGUICtx(ctx);
gPrepareGUICtx(ctx);
HandleInputs(inputs, i_count);
gHandleInputs(inputs, i_count);
if (UIButton(ctx, "Show 2", 150.0f, 150.0f, 200.0f, 200.0f))
if (gButton(ctx, "Show 2", 150.0f, 150.0f, 200.0f, 200.0f))
{
UIWindow(ctx, "Window 2", 500.0f, 500.0f, 600.0f, 600.0f);
gWindow(ctx, "Window 2", 500.0f, 500.0f, 600.0f, 600.0f);
}
if (UIButton(ctx, "Show 1", 50.0f, 50.0f, 100.0f, 100.0f))
if (gButton(ctx, "Show 1", 50.0f, 50.0f, 100.0f, 100.0f))
{
UIWindow(ctx, "Window 1", 200.0f, 200.0f, 400.0f, 400.0f);
gWindow(ctx, "Window 1", 200.0f, 200.0f, 400.0f, 400.0f);
}
if (UIButton(ctx, "Show 3", 150.0f, 300.0f, 200.0f, 350.0f))
if (gButton(ctx, "Show 3", 150.0f, 300.0f, 200.0f, 350.0f))
{
UIWindow(ctx, "Window 3", 250.0f, 500.0f, 400.0f, 650.0f);
gWindow(ctx, "Window 3", 250.0f, 500.0f, 400.0f, 650.0f);
}
GetViewportSize(&ctx->pc.res);
rViewportSize(&ctx->pc.res);
//DescHandle pattermon = CreateAndUploadToTexture(PATTERMON_OBESE);
//rDescHandle pattermon = rTextureCreateAndUpload(PATTERMON_OBESE);
RenderBuffer *vertex_buffer = MakeArray(ctx->arena, RenderBuffer, 1);
rRenderBuffer *vertex_buffer = MakeArray(ctx->arena, rRenderBuffer, 1);
vertex_buffer->type = RENDER_BUFFER_TYPE_VERTEX;
vertex_buffer->size = sizeof(GUIVertex) * ctx->gui.vertices_len;
vertex_buffer->size = sizeof(rUIVertex) * ctx->gui.vertices_len;
RenderBuffer *index_buffer = MakeArray(ctx->arena, RenderBuffer, 1);
rRenderBuffer *index_buffer = MakeArray(ctx->arena, rRenderBuffer, 1);
index_buffer->type = RENDER_BUFFER_TYPE_INDEX,
index_buffer->size = sizeof(u32) * ctx->gui.indices_len,
CreateAndUploadToBuffer(vertex_buffer, ctx->gui.vertices);
CreateAndUploadToBuffer(index_buffer, ctx->gui.indices);
rBufferCreateAndUpload(vertex_buffer, ctx->gui.vertices);
rBufferCreateAndUpload(index_buffer, ctx->gui.indices);
WaitForBufferQueue();
BeginFrame();
rFrameBegin();
BindPipeline(PIPELINE_GUI, PIPELINE_TYPE_GRAPHICS);
rPipelineBind(PIPELINE_GUI, PIPELINE_TYPE_GRAPHICS);
SetPushConstants(&ctx->pc);
rPushConstantsSet(&ctx->pc);
BindVertexBuffer(vertex_buffer);
BindIndexBuffer(index_buffer);
rBufferBindVertex(vertex_buffer);
rBufferBindIndex(index_buffer);
DrawIndexed(6, ctx->gui.instance_count);
rDrawIndexed(6, ctx->gui.instance_count);
FinishFrame();
FreeBuffers(vertex_buffer, 1);
FreeBuffers(index_buffer, 1);
rBufferFree(vertex_buffer, 1);
rBufferFree(index_buffer, 1);
ctx->gui.vertices_len = 0;
ctx->gui.indices_len = 0;
@ -115,7 +115,7 @@ static void RunCycle(GameContext *ctx, GameInput *inputs, u32 i_count)
// ::Game::Inputs::Functions::Start::
static void HandleInputs(GameInput *inputs, u32 count)
static void gHandleInputs(pGameInput *inputs, u32 count)
{
mouse_clicked = false;
@ -169,14 +169,14 @@ static void HandleInputs(GameInput *inputs, u32 count)
// ::Game::GUI::Functions::Start::
static inline void PrepareGUICtx(GameContext *ctx)
static inline void gPrepareGUICtx(gGameCtx *ctx)
{
ctx->gui.has_grabbed = false;
}
static b32 UIButton(GameContext *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)
{
GUIButton *btn = NULL;
gButtonWidget *btn = NULL;
u64 id = HashFromString(String8CStr(label));
if (ctx->btn_len == 0)
{
@ -229,14 +229,14 @@ static b32 UIButton(GameContext *ctx, char *label, f32 x0, f32 y0, f32 x1, f32 y
btn->pressed = !btn->pressed;
}
DrawRect(&ctx->gui, btn->p0, btn->p1, (Vec4){ .r = 0.1f, .g = 0.9f, .b = 0.4f, .a = 1.0f });
gRect(&ctx->gui, btn->p0, btn->p1, (Vec4){ .r = 0.1f, .g = 0.9f, .b = 0.4f, .a = 1.0f });
return btn->pressed;
}
static b32 UIWindow(GameContext *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1)
static b32 gWindow(gGameCtx *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y1)
{
GUIWindow *win = NULL;
gWindowWidget *win = NULL;
u32 id = HashFromString(String8CStr(title));
if (ctx->window_len == 0)
{
@ -309,13 +309,13 @@ static b32 UIWindow(GameContext *ctx, char *title, f32 x0, f32 y0, f32 x1, f32 y
ctx->gui.has_grabbed = true;
}
DrawRect(&ctx->gui, win->p0, win->p1, (Vec4){ .r = 0.1f, .g = 0.3f, .b = 0.8f, .a = 1.0f });
gRect(&ctx->gui, win->p0, win->p1, (Vec4){ .r = 0.1f, .g = 0.3f, .b = 0.8f, .a = 1.0f });
return true;
}
static void DrawRect(GUIContext *ctx, Vec2 p0, Vec2 p1, Vec4 col)
static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col)
{
ctx->vertices[ctx->vertices_len].p0 = p0;
ctx->vertices[ctx->vertices_len].p1 = p1;

View File

@ -2,51 +2,61 @@
// ::Game::Types::Header::
typedef struct GUIWindow
typedef struct gUICtx
{
rUIVertex *vertices;
u32 vertices_len;
u32 *indices;
u32 indices_len;
u32 instance_count;
b8 has_grabbed;
} gUICtx;
typedef struct gWindowWidget
{
Vec2 p0;
Vec2 p1;
Vec2 grabbed_pos;
u64 id;
b8 grabbed;
} GUIWindow;
} gWindowWidget;
typedef struct GUIButton
typedef struct gButtonWidget
{
Vec2 p0;
Vec2 p1;
u64 id;
b8 pressed;
b8 pressed_prev;
} GUIButton;
} gButtonWidget;
typedef struct GameContext
typedef struct gGameCtx
{
GUIContext gui;
PushConst pc;
gUICtx gui;
rPushConst pc;
Arena *arena;
GUIWindow *windows;
gWindowWidget *windows;
u32 window_len;
GUIButton *buttons;
gButtonWidget *buttons;
u32 btn_len;
} GameContext;
} gGameCtx;
// ::Game::Init::Functions::Header::
static void InitializeGame(Arena *arena, GameContext *ctx, Arena *ctx_arena);
static void DestroyGame();
static void gInit(Arena *arena, gGameCtx *ctx, Arena *ctx_arena);
static void gDestroy();
// ::Game::GameLoop::Functions::Header::
static void RunCycle(GameContext *ctx, GameInput *inputs, u32 i_count);
static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count);
// ::Game::Inputs::Functions::Header::
static void HandleInputs(GameInput *inputs, u32 count);
static void gHandleInputs(pGameInput *inputs, u32 count);
// ::Game::GUI::Functions::Header::
static inline void PrepareGUICtx(GameContext *ctx);
static void DrawRect(GUIContext *ctx, Vec2 p0, Vec2 p1, Vec4 col);
static b32 UIWindow(GameContext *ctx, c8 *title, f32 x0, f32 y0, f32 x1, f32 y1);
static b32 UIButton(GameContext *ctx, c8 *label, f32 x0, f32 y0, f32 x1, f32 y1);
static inline void gPrepareGUICtx(gGameCtx *ctx);
static void gRect(gUICtx *ctx, Vec2 p0, Vec2 p1, Vec4 col);
static b32 gWindow(gGameCtx *ctx, c8 *title, f32 x0, f32 y0, f32 x1, f32 y1);
static b32 gButton(gGameCtx *ctx, c8 *label, f32 x0, f32 y0, f32 x1, f32 y1);

View File

@ -113,14 +113,14 @@ i32 WriteHeader(FILE *file, FileHeader *header)
void MoveToShaderDir(c8 **return_dir)
{
if (DirVisible("build"))
if (pDirIsVisible("build"))
{
Assert(ChangeDir("./build/shaders/glsl") == 0, "Unable to change to shader directory");
Assert(pDirNavigate("./build/shaders/glsl") == 0, "Unable to change to shader directory");
*return_dir = "../../..";
}
else if (DirVisible("shaders"))
else if (pDirIsVisible("shaders"))
{
Assert(ChangeDir("./shaders/glsl") == 0 , "Unable to change to shader directory");
Assert(pDirNavigate("./shaders/glsl") == 0 , "Unable to change to shader directory");
*return_dir = "../..";
}
else
@ -129,14 +129,14 @@ void MoveToShaderDir(c8 **return_dir)
void MoveToTextureDir(c8 **return_dir)
{
if (DirVisible("assets"))
if (pDirIsVisible("assets"))
{
Assert(ChangeDir("./assets") == 0, "Unable to change to assets directory");
Assert(pDirNavigate("./assets") == 0, "Unable to change to assets directory");
*return_dir = "..";
}
else if (DirVisible("shaders"))
else if (pDirIsVisible("shaders"))
{
Assert(ChangeDir("../assets") == 0, "Unable to change to assets directory");
Assert(pDirNavigate("../assets") == 0, "Unable to change to assets directory");
*return_dir = "../build";
}
else
@ -230,7 +230,7 @@ void PackFiles(Arena *arena, FileHeader *header)
CloseFile(asset_file);
}
Assert(ChangeDir(return_dir) == 0, "Unable to return to previous directory");
Assert(pDirNavigate(return_dir) == 0, "Unable to return to previous directory");
MoveToTextureDir(&return_dir);
AssetFile *texture_assets = MakeArray(arena, AssetFile, TEXTURE_ASSET_MAX);
@ -261,7 +261,7 @@ void PackFiles(Arena *arena, FileHeader *header)
WriteData(shader_assets, header->asset_offsets[SHADER_ASSET], sizeof(AssetFile)*SHADER_ASSET_MAX, file);
WriteData(texture_assets, header->asset_offsets[TEXTURE_ASSET], sizeof(AssetFile)*TEXTURE_ASSET_MAX, file);
ChangeDir(return_dir);
pDirNavigate(return_dir);
}
// ::Packer::Packing::Functions::End::
@ -354,7 +354,7 @@ void TestAssetPack(Arena *arena)
TestAssetIsCorrect(arena, g_Shader_File_Names[i], &files[SHADER_ASSET][i], file);
}
ChangeDir(return_dir);
pDirNavigate(return_dir);
MoveToTextureDir(&return_dir);
for (u32 i = 0; i < TEXTURE_ASSET_MAX; i++)
@ -375,7 +375,7 @@ int main(int argc, c8 **argv)
SetArrayLookups();
void *mem = MemAllocZeroed(GB(1));
void *mem = pMemAllocZeroed(GB(1));
Arena *arena = ArenaInitDebug(mem, GB(1), __LINE__);
FILE *file = fopen("assets.sgp", "w+");

View File

@ -2,8 +2,13 @@
// ::Platform::Types::Header::
typedef struct Library Library;
typedef struct Function Function;
typedef struct pLibrary pLibrary;
typedef struct pFunction pFunction;
// ::Platform::Declarations::Header::
typedef enum KeyboardInput_e pKeyboardInput;
typedef struct pGameInput pGameInput;
// ::Platform::Includes::Header::
@ -23,62 +28,116 @@ typedef struct Function Function;
#error Not yet implemented
#endif
// ::Platform::Enum::Header::
typedef enum KeyboardInput_e
{
KB_NONE,
KB_A, KB_B, KB_C, KB_D, KB_E, KB_F, KB_G, KB_H, KB_I, KB_J, KB_K, KB_L, KB_M,
KB_N, KB_O, KB_P, KB_Q, KB_R, KB_S, KB_T, KB_U, KB_V, KB_W, KB_X, KB_Y, KB_Z,
KB_0, KB_1, KB_2, KB_3, KB_4, KB_5, KB_6, KB_7, KB_8, KB_9,
KB_NUM_0, KB_NUM_1, KB_NUM_2, KB_NUM_3, KB_NUM_4, KB_NUM_5, KB_NUM_6, KB_NUM_7, KB_NUM_8, KB_NUM_9,
KB_NUM_LOCK, KB_NUM_SLASH, KB_NUM_STAR, KB_NUM_MINUS, KB_NUM_PLUS, KB_NUM_ENTER, KB_NUM_PERIOD,
KB_INSERT, KB_DELETE, KB_HOME, KB_END, KB_PAGE_UP, KB_PAGE_DOWN,
KB_PRINT_SCREEN, KB_SCROLL_LOCK, KB_PAUSE,
KB_COMMA, KB_PERIOD, KB_BACK_SLASH, KB_BACKSPACE, KB_FORWARD_SLASH, KB_MINUS, KB_PLUS,
KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12,
KB_UP, KB_DOWN, KB_LEFT, KB_RIGHT,
KB_LEFT_CTRL, KB_LEFT_ALT, KB_LEFT_SHIFT, KB_LEFT_SUPER,
KB_TAB, KB_CAPS_LOCK,
KB_RIGHT_CTRL, KB_RIGHT_ALT, KB_RIGHT_SUPER, KB_RIGHT_SHIFT,
KB_ENTER, KB_SPACE,
KB_TILDE, KB_ESC,
KB_SEMICOLON, KB_QUOTE, KB_LEFT_BRACE, KB_RIGHT_BRACE, KB_BACK_SPACE,
KB_MAX
} pKeyboardInput;
typedef enum MouseInput_e
{
M_NONE,
M_LEFT_CLICK,
M_MIDDLE_CLICK,
M_RIGHT_CLICK,
} pMouseInput;
typedef enum GameInputType_e
{
GI_NONE,
GI_KEYBOARD,
GI_MOUSE,
GI_MOTION,
GI_GAMEPAD,
} pGameInputType;
// ::Platform::Types::Header::
typedef struct WindowSize
typedef u16Vec2 pWindowSize;
typedef i16Vec2 pMouseMotion;
typedef struct pGameInput
{
u16 h, w;
} WindowSize;
union
{
pKeyboardInput kb_code;
pMouseInput m_code;
pMouseMotion motion_ev;
};
b8 pressed;
pGameInputType type;
} pGameInput; // TODO: add gamepad input
// ::Platform::ConsoleOut::Functions::Header::
i32 WriteStdOut(void *buf, i32 len);
i32 WriteStdErr(void *buf, i32 len);
i32 pWriteStdOut(void *buf, i32 len);
i32 pWriteStdErr(void *buf, i32 len);
// ::Platform::Library::Functions::Header::
// ::Platform::pLibrary::Functions::Header::
b32 LoadLib(const char *name, Library *out_lib);
b32 LoadFn(const char *name, Library *lib, Function *out_fn);
b32 pLibraryLoad(const char *name, pLibrary *out_lib);
b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn);
// ::Platform::Memory::Functions::Header::
rawptr MemAlloc(usize size);
rawptr MemAllocZeroed(usize size);
rawptr MemRealloc(rawptr ptr, usize old_size, usize new_size);
void MemFree(rawptr ptr, usize size);
usize GetPageSize();
rawptr pMemAlloc(usize size);
rawptr pMemAllocZeroed(usize size);
rawptr pMemRealloc(rawptr ptr, usize old_size, usize new_size);
void pMemFree(rawptr ptr, usize size);
usize pPageSize();
// ::Platform::Window::Functions::Header::
b32 CreatePlatformWindow(const char *window_name);
WindowSize GetWindowSize();
b32 ShouldQuit();
PlatformWindow *GetPlatformWindow();
b32 pWindowInit(const char *window_name);
pWindowSize pWindowGetSize();
b32 pWindowShouldQuit();
pPlatformWindow *pWindowGet();
// ::Platform::SystemInfo::Functions::Header::
u32 AvailableCPUCount();
u32 pCPUCountGet();
// ::Platform::FileSystem::Functions::Header::
b32 ChangeDir(c8 *dir);
c8 **GetFileNamesInDir(Arena *arena, u32 *count);
b8 DirVisible(c8 *dir_name);
b32 pDirNavigate(c8 *dir);
c8 **pDirGetFileNames(Arena *arena, u32 *count);
b8 pDirIsVisible(c8 *dir_name);
// ::Platform::Profiling::Functions::Header::
static u64 GetOSTimerFreq();
static u64 ReadOSTimer();
static inline u64 ReadCPUTimer();
static u64 pOSTimerFreq();
static u64 pOSTimerRead();
static inline u64 pCPUTimerRead();
// ::Platform::Atomics::Header::
#define DefSigAtomicFetchIncr(T) static inline T AtomicFetchIncr##T(T *ptr)
#define DefSigAtomicFetchSub(T) static inline T AtomicFetchSub##T(T *ptr, T count)
#define DefSigAtomicIncr(T) static inline void AtomicIncr##T(T *ptr)
#define DefSigAtomicStore(T) static inline void AtomicStore##T(T *ptr, T value)
#define DefSigAtomicLoad(T) static inline T AtomicLoad##T(T *ptr)
#define DefSigAtomicCompareExchange(T) static inline b32 AtomicCompareExchange##T(T *ptr, T *expected, T desired)
#define DefSigAtomicFetchIncr(T) static inline T p##T##AtomicFetchIncr(T *ptr)
#define DefSigAtomicFetchSub(T) static inline T p##T##AtomicFetchSub(T *ptr, T count)
#define DefSigAtomicIncr(T) static inline void p##T##AtomicIncr(T *ptr)
#define DefSigAtomicStore(T) static inline void p##T##AtomicStore(T *ptr, T value)
#define DefSigAtomicLoad(T) static inline T p##T##AtomicLoad(T *ptr)
#define DefSigAtomicCompareExchange(T) static inline b32 p##T##AtomicCompareExchange(T *ptr, T *expected, T desired)
DefScalarSig(AtomicFetchIncr);
DefScalarSig(AtomicFetchSub);
@ -87,13 +146,3 @@ DefScalarSig(AtomicStore);
DefScalarSig(AtomicLoad);
DefScalarSig(AtomicCompareExchange);
/*
static inline u32 AtomicFetchIncrU32(u32 *ptr);
static inline u32 AtomicFetchSubU32(u32 *ptr, u32 count);
static inline void AtomicIncrU32(u32 *ptr);
static inline u32 AtomicFetchU32(u32 *ptr);
static inline void AtomicStoreB32(b32 *ptr, b32 value);
static inline u32 AtomicLoadU32(u32 *ptr);
static inline b32 AtomicCompareExchangeU32(u32 *ptr, u32 *expected, u32 desired);
static inline b32 AtomicCompareExchangeB32(b32 *ptr, b32 *expected, b32 desired);
*/

View File

@ -1,6 +1,6 @@
// ::Platform::Linux::Globals::Start::
static PlatformWindow linux_window = {
static pPlatformWindow linux_window = {
.w = 1920,
.h = 1080,
};
@ -11,31 +11,31 @@ b32 global_quit = false;
// ::Platform::Linux::Print::Functions::Start::
i32 WriteStdOut(rawptr buf, i32 len)
i32 pWriteStdOut(rawptr buf, i32 len)
{
return (i32)write(STDOUT, buf, len);
}
i32 WriteStdErr(rawptr buf, i32 len)
i32 pWriteStdErr(rawptr buf, i32 len)
{
return (i32)write(STDERR, buf, len);
}
// ::Platform::Linux::Window::Functions::Start::
void GetWindowEvents(GameInput *inputs, u32 *i_count)
void pWindowEventsGet(pGameInput *inputs, u32 *i_count)
{
HandleWindowEvent(inputs, i_count, false);
pWindowEventHandle(inputs, i_count, false);
}
b32 WaitForWindowEvent(GameInput *input)
b32 pWindowEventWaitFor(pGameInput *input)
{
u32 i_count;
HandleWindowEvent(input, &i_count, true);
pWindowEventHandle(input, &i_count, true);
return i_count > 0;
}
void HandleWindowEvent(GameInput *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;
@ -79,7 +79,7 @@ void HandleWindowEvent(GameInput *inputs, u32 *i_count, b32 wait_for_event)
b8 pressed = e->response_type == XCB_KEY_PRESS;
xcb_keycode_t code = keyboard_e->detail;
KeySym keysym = XkbKeycodeToKeysym(linux_window.display, (KeyCode)code, 0, 0);
KeyboardInput input = ConvertInputEvent(keysym);
pKeyboardInput input = pInputEventConvert(keysym);
if (input != KB_NONE)
{
inputs[*i_count].kb_code = input;
@ -97,7 +97,7 @@ void HandleWindowEvent(GameInput *inputs, u32 *i_count, b32 wait_for_event)
{
xcb_button_press_event_t *mouse_ev = (xcb_button_press_event_t *)e;
b8 pressed = e->response_type == XCB_BUTTON_PRESS;
MouseInput input = M_NONE;
pMouseInput input = M_NONE;
if (mouse_ev->detail == XCB_BUTTON_INDEX_1)
input = M_LEFT_CLICK;
@ -145,7 +145,7 @@ void HandleWindowEvent(GameInput *inputs, u32 *i_count, b32 wait_for_event)
} while(!wait_for_event && !has_max_inputs);
}
KeyboardInput ConvertInputEvent(u32 x_key)
pKeyboardInput pInputEventConvert(u32 x_key)
{
switch (x_key)
{
@ -287,7 +287,7 @@ KeyboardInput ConvertInputEvent(u32 x_key)
// ::Platform::Linux::Utils::Functions::Start::
b32 CheckSyscallErr(void *ptr)
b32 pSyscallErrCheck(void *ptr)
{
return (isize)ptr == SYS_ERR ? true : false;
}

View File

@ -52,7 +52,7 @@
// ::Platform::Linux::Types::Header
typedef struct PlatformWindow
typedef struct pPlatformWindow
{
Display *display;
xcb_connection_t *connection;
@ -60,67 +60,67 @@ typedef struct PlatformWindow
xcb_atom_t close_event;
xcb_atom_t minimize_event;
u16 w, h;
} PlatformWindow;
} pPlatformWindow;
typedef struct Library
typedef struct pLibrary
{
void *lib;
} Library;
} pLibrary;
typedef struct Function
typedef struct pFunction
{
void *fn;
} Function;
} pFunction;
// ::Platform::Linux::Print::Functions::Header::
i32 Write(int fd, void const *str, isize count);
i32 pWrite(int fd, void const *str, isize count);
// ::Platform::Linux::Window::Functions::Header::
void GetWindowEvents(GameInput *inputs, u32 *i_count);
b32 WaitForWindowEvent(GameInput *input);
void HandleWindowEvent(GameInput *inputs, u32 *input_count, b32 wait_for_event);
KeyboardInput ConvertInputEvent(u32 x_key);
void pWindowEventsGet(pGameInput *inputs, u32 *i_count);
b32 pWindowEventWaitFor(pGameInput *input);
void pWindowEventHandle(pGameInput *inputs, u32 *input_count, b32 wait_for_event);
pKeyboardInput pInputEventConvert(u32 x_key);
// ::Platform::Linux::Utils::Functions::Header::
b32 CheckSyscallErr(void *ptr);
b32 pSyscallErrCheck(void *ptr);
// ::Platform::Linux::Atomics::Header::
#define DefAtomicFetchIncr(T) \
static inline T AtomicFetchIncr##T(T *ptr) \
static inline T p##T##AtomicFetchIncr(T *ptr) \
{ \
return __atomic_fetch_add(ptr, (T)1, __ATOMIC_ACQUIRE); \
}
#define DefAtomicIncr(T) \
static inline void AtomicIncr##T(T *ptr) \
static inline void p##T##AtomicIncr(T *ptr) \
{ \
__atomic_fetch_add(ptr, (T)1, __ATOMIC_RELEASE); \
}
#define DefAtomicStore(T) \
static inline void AtomicStore##T(T *ptr, T value) \
static inline void p##T##AtomicStore(T *ptr, T value) \
{ \
__atomic_store_n(ptr, value, __ATOMIC_RELEASE); \
}
#define DefAtomicLoad(T) \
static inline T AtomicLoad##T(T *ptr) \
static inline T p##T##AtomicLoad(T *ptr) \
{ \
return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); \
}
#define DefAtomicFetchSub(T) \
static inline T AtomicFetchSub##T(T *ptr, T count) \
static inline T p##T##AtomicFetchSub(T *ptr, T count) \
{ \
return __atomic_fetch_sub(ptr, count, __ATOMIC_ACQUIRE); \
}
#define DefAtomicCompareExchange(T) \
static inline b32 AtomicCompareExchange##T(T *ptr, T *expected, T desired) \
static inline b32 p##T##AtomicCompareExchange(T *ptr, T *expected, T desired) \
{ \
return __atomic_compare_exchange_n(ptr, expected, desired, true, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); \
}

View File

@ -1,6 +1,6 @@
// ::Platform::Functions::Library::Start::
// ::Platform::Functions::pLibrary::Start::
b32 LoadLib(const char *name, Library *out_lib)
b32 pLibraryLoad(const char *name, pLibrary *out_lib)
{
if (!name) {
return false;
@ -14,7 +14,7 @@ b32 LoadLib(const char *name, Library *out_lib)
return true;
}
b32 LoadFn(const char *name, Library *lib, Function *out_fn)
b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
{
if (!name) {
return false;
@ -29,7 +29,7 @@ b32 LoadFn(const char *name, Library *lib, Function *out_fn)
return true;
}
// ::Platform::Functions::Library::End::
// ::Platform::Functions::pLibrary::End::
@ -42,7 +42,7 @@ b32 LoadFn(const char *name, Library *lib, Function *out_fn)
// ::Platform::Functions::Memory::Start::
rawptr MemAlloc(usize size)
rawptr pMemAlloc(usize size)
{
rawptr addr = mmap(
NULL,
@ -53,19 +53,19 @@ rawptr MemAlloc(usize size)
0
);
if (CheckSyscallErr(addr)) addr = NULL;
if (pSyscallErrCheck(addr)) addr = NULL;
return addr;
}
rawptr MemAllocZeroed(usize size)
rawptr pMemAllocZeroed(usize size)
{
rawptr ptr = MemAlloc(size);
rawptr ptr = pMemAlloc(size);
MemZero(ptr, size);
return ptr;
}
rawptr MemRealloc(rawptr ptr, usize old_size, usize new_size)
rawptr pMemRealloc(rawptr ptr, usize old_size, usize new_size)
{
rawptr addr = mremap(
ptr,
@ -74,17 +74,17 @@ rawptr MemRealloc(rawptr ptr, usize old_size, usize new_size)
MAP_ANON | MAP_PRIVATE
);
if (CheckSyscallErr(addr)) addr = NULL;
if (pSyscallErrCheck(addr)) addr = NULL;
return addr;
}
void MemFree(rawptr ptr, usize size)
void pMemFree(rawptr ptr, usize size)
{
Assert(munmap(ptr, size) == 0, "munmap failed");
}
usize GetPageSize()
usize pPageSize()
{
return (usize)sysconf(_SC_PAGESIZE);
}
@ -95,9 +95,9 @@ usize GetPageSize()
// ::Platform::Functions::Window::Start::
b32 CreatePlatformWindow(const char *window_name)
b32 pWindowInit(const char *window_name)
{
PlatformWindow *window = &linux_window;
pPlatformWindow *window = &linux_window;
window->display = XOpenDisplay(NULL);
if (!window->display)
@ -203,20 +203,20 @@ b32 CreatePlatformWindow(const char *window_name)
return true;
}
WindowSize GetWindowSize()
pWindowSize pWindowGetSize()
{
return (WindowSize) {
return (pWindowSize) {
.w = linux_window.w,
.h = linux_window.h,
};
}
PlatformWindow *GetPlatformWindow()
pPlatformWindow *pWindowGet()
{
return &linux_window;
}
b32 ShouldQuit()
b32 pWindowShouldQuit()
{
return false;
}
@ -227,7 +227,7 @@ b32 ShouldQuit()
// ::Platform::Functions::SystemInfo::Start::
u32 AvailableCPUCount()
u32 pCPUCountGet()
{
cpu_set_t cpu_set;
sched_getaffinity(0, sizeof(cpu_set), &cpu_set);
@ -240,12 +240,12 @@ u32 AvailableCPUCount()
// ::Platform::Functions::Directory::Start::
b32 ChangeDir(c8 *dir)
b32 pDirNavigate(c8 *dir)
{
return chdir(dir);
}
c8 **GetFileNamesInDir(Arena *arena, u32 *count)
c8 **pDirGetFileNames(Arena *arena, u32 *count)
{
struct dirent *dir;
@ -282,7 +282,7 @@ c8 **GetFileNamesInDir(Arena *arena, u32 *count)
return (c8 **)file_names;
}
b8 DirVisible(c8 *dir_name)
b8 pDirIsVisible(c8 *dir_name)
{
b8 found = false;
@ -310,20 +310,20 @@ b8 DirVisible(c8 *dir_name)
// ::Platform::Profiling::Functions::Start::
static u64 GetOSTimerFreq()
static u64 pOSTimerFreq()
{
return 1000000;
}
static u64 ReadOSTimer()
static u64 pOSTimerRead()
{
struct timeval value;
gettimeofday(&value, 0);
return GetOSTimerFreq() * u64(value.tv_sec) + u64(value.tv_usec);
return pOSTimerFreq() * u64(value.tv_sec) + u64(value.tv_usec);
}
static inline u64 ReadCPUTimer()
static inline u64 pCPUTimerRead()
{
return __rdtsc();
}

View File

@ -1,5 +1,5 @@
HINSTANCE win32_instance = {0};
PlatformWindow win32_window = {0};
pPlatformWindow win32_window = {0};
b32 global_quit = false;
LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
@ -13,7 +13,7 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_
Printfln("Window resizing");
win32_window.w = LOWORD(l_param);
win32_window.h = HIWORD(l_param);
SetRenderResolution(win32_window.w, win32_window.h);
rResolutionSet(win32_window.w, win32_window.h);
} break;
case WM_DESTROY: // TODO(MA): Probably handle these separately but for now, they're together
case WM_CLOSE:
@ -34,7 +34,7 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_
return result;
}
b32 LoadLib(const char *name, Library *out_lib)
b32 pLibraryLoad(const char *name, pLibrary *out_lib)
{
b32 success = true;
@ -45,7 +45,7 @@ b32 LoadLib(const char *name, Library *out_lib)
return success;
}
b32 LoadFn(const char *name, Library *lib, Function *out_fn)
b32 pFunctionLoad(const char *name, pLibrary *lib, pFunction *out_fn)
{
b32 success = true;
@ -56,17 +56,17 @@ b32 LoadFn(const char *name, Library *lib, Function *out_fn)
return success;
}
rawptr MemAlloc(isize size)
rawptr pMemAlloc(isize size)
{
return (rawptr)VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
}
rawptr MemAllocZeroed(isize size)
rawptr pMemAllocZeroed(isize size)
{
return _MemAlloc(size);
}
isize GetPageSize()
isize pPageSize()
{
return 0;
}
@ -128,7 +128,7 @@ i32 _EPrintf(const char *fmt, va_list arg)
return EPrint(&buffer);
}
b32 CreatePlatformWindow(const char *window_name)
b32 pWindowInit(const char *window_name)
{
b32 success = true;
@ -169,12 +169,12 @@ b32 CreatePlatformWindow(const char *window_name)
return success;
}
PlatformWindow *GetPlatformWindow()
pPlatformWindow *pWindowGet()
{
return &win32_window;
}
void GetWindowEvents()
void pWindowEventsGet()
{
BOOL has_msg = false;
MSG message;
@ -190,7 +190,7 @@ void GetWindowEvents()
while (has_msg);
}
void WaitForWindowEvent()
void pWindowEventWaitFor()
{
MSG message;
BOOL message_result = GetMessageA(&message, 0, 0, 0);
@ -201,13 +201,13 @@ void WaitForWindowEvent()
}
}
b32 ShouldQuit()
b32 pWindowShouldQuit()
{
return global_quit;
}
WindowSize _GetWindowSize()
pWindowSize pWindowGetSize()
{
return (WindowSize){ .w = win32_window.w, .h = win32_window.h };
return (pWindowSize){ .w = win32_window.w, .h = win32_window.h };
}

View File

@ -10,23 +10,23 @@
// ::Platform::Windows::Types::Header::
typedef struct PlatformWindow
typedef struct pPlatformWindow
{
HINSTANCE instance;
HWND handle;
u16 h, w;
b32 resize_requested;
} PlatformWindow;
} pPlatformWindow;
typedef struct Library
typedef struct pLibrary
{
HMODULE module;
} Library;
} pLibrary;
typedef struct
{
FARPROC fn;
} Function;
} pFunction;
// ::Platform::Windows::Functions::::Header::
@ -34,5 +34,5 @@ rawptr _MemAlloc(isize size);
rawptr _MemAllocZeroed(isize size);
isize _GetPageSize();
void GetWindowEvents();
void WaitForWindowEvent();
void pWindowEventsGet();
void pWindowEventWaitFor();

View File

@ -2,21 +2,21 @@
// ::Renderer::Declarations::Header::
typedef u32 DescHandle;
typedef u32 rDescHandle;
// @requirement RenderBufferType type
// @requirement rRenderBufferType type
// @requirement u32 size
// @requirement u32 index
typedef struct RenderBuffer RenderBuffer;
typedef struct rRenderBuffer rRenderBuffer;
// @requirement TextureBufferType type
// @requirement rTextureBufferType type
// @requirement u32 width
// @requirement u32 height
// @requirement u32 index
typedef struct TextureBuffer TextureBuffer;
typedef struct rTextureBuffer rTextureBuffer;
typedef struct PushConst PushConst;
typedef struct ShaderGlobals ShaderGlobals;
typedef struct rPushConst rPushConst;
typedef struct rShaderGlobals rShaderGlobals;
// ::Renderer::Enums::Header::
@ -26,13 +26,13 @@ typedef enum Pipeline_e
PIPELINE_GUI,
PIPELINE_MAX,
} PipelineHandle;
} rPipelineHandle;
typedef enum PipelineType_e
{
PIPELINE_TYPE_GRAPHICS = 0,
PIPELINE_TYPE_COMPUTE = 1,
} PipelineType;
} rPipelineType;
typedef enum RenderBufferType_e
{
@ -42,66 +42,82 @@ typedef enum RenderBufferType_e
RENDER_BUFFER_TYPE_UNIFORM = 0x0004,
RENDER_BUFFER_TYPE_STAGING = 0x0008,
RENDER_BUFFER_TYPE_STORAGE = 0x0010,
} RenderBufferType;
} rRenderBufferType;
typedef enum TextureBufferType_e
{
TEXTURE_BUFFER_TYPE_NONE = 0x0000,
TEXTURE_BUFFER_TYPE_IMAGE = 0x0001,
TEXTURE_BUFFER_TYPE_SAMPLER = 0x0002,
} TextureBufferType;
} rTextureBufferType;
typedef enum VertexAttrType_e
{
VERTEX_ATTRIBUTE_TYPE_VERTEX = 0,
VERTEX_ATTRIBUTE_TYPE_COLOR = 1,
} VertexAttrType;
} rVertexAttrType;
// ::Renderer::Types::Header::
typedef struct RenderBuffers
typedef struct rUIVertex
{
RenderBuffer *buffers;
u32 len;
} RenderBuffers;
Vec2 p0;
Vec2 p1;
Vec4 col;
u32 tex_idx;
} rUIVertex;
typedef u32 AssetHandle;
typedef struct rUploadQueue
{
union
{
rRenderBuffer **queued_buffers;
rTextureBuffer **queued_textures;
rawptr *queued_ptrs;
};
rawptr *data;
TicketMut ticket_mut;
Mut mut;
JobQueue job_queue;
} rUploadQueue;
typedef u32 rAssetHandle;
// ::Renderer::Initialization::Header::
b32 InitRenderer(Arena *arena);
void DestroyRenderer();
b32 rInit(Arena *arena);
void rDestroy();
// ::Renderer::Buffers::Header::
static b32 CreateBuffer(RenderBuffer *buffer);
static void FreeBuffers(RenderBuffer *buffers, u32 buffer_count);
static b32 UploadToBuffer(RenderBuffer **buffer, rawptr *ptr, u32 count, u32 thr_ix);
static void CreateAndUploadToBuffer(RenderBuffer *buffer, rawptr ptr);
static DescHandle CreateAndUploadToTexture(TextureAsset asset_id);
static void BindVertexBuffer(RenderBuffer *buffer);
static void BindIndexBuffer(RenderBuffer *buffer);
static AssetHandle RendererLoadTexture(TextureAsset asset_id);
static void ResetBufferQueue();
static b32 rBufferCreate(rRenderBuffer *buffer);
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count);
static b32 rBufferUpload(rRenderBuffer **buffer, rawptr *ptr, u32 count, u32 thr_ix);
static void rBufferCreateAndUpload(rRenderBuffer *buffer, rawptr ptr);
static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id);
static void rBufferBindVertex(rRenderBuffer *buffer);
static void rBufferBindIndex(rRenderBuffer *buffer);
static rAssetHandle rTextureLoad(TextureAsset asset_id);
static void rBufferQueueReset();
// ::Renderer::Uniforms::Header::
// ::Renderer::PushConstants::Header::
static void GetViewportSize(Vec2 *size);
static void SetGlobalUniform(ShaderGlobals *globals);
static void SetPushConstants(PushConst *pc);
static void rViewportSize(Vec2 *size);
static void rGlobalUniformSet(rShaderGlobals *globals);
static void rPushConstantsSet(rPushConst *pc);
// ::Renderer::Config::Header::
static void SetRenderResolution(u32 x, u32 y);
static void SetRendererAvailableThreads(u32 n);
static void rResolutionSet(u32 x, u32 y);
static void rThreadCountSet(u32 n);
// ::Renderer::Rendering::Header::
static b32 BeginFrame();
static b32 rFrameBegin();
static b32 FinishFrame();
static void DrawIndexed(u32 index_count, u32 instance_count);
static void BindPipeline(PipelineHandle handle, PipelineType type);
static void rDrawIndexed(u32 index_count, u32 instance_count);
static void rPipelineBind(rPipelineHandle handle, rPipelineType type);
// ::Renderer::Includes::Header::

View File

@ -34,7 +34,7 @@ void _SetRenderResolution(u32 x, u32 y)
}
static void DrawGUI(GUIContext *ctx)
static void DrawGUI(gUICtx *ctx)
{
}

View File

@ -10,4 +10,4 @@ b32 _BeginFrame();
b32 _DrawTriangle();
b32 _FinishFrame();
void _SetRenderResolution(u32 x, u32 y);
static void DrawGUI(GUIContext *ctx);
static void DrawGUI(gUICtx *ctx);

View File

@ -1,6 +1,6 @@
// ::Vulkan::Globals::Start::
static Renderer renderer = {
static vRenderer renderer = {
.vk = {
.queues = {
.graphics = -1,
@ -36,42 +36,42 @@ pthread_cond_t cond;
// ::Vulkan::Util::Functions::Start::
static inline u32 GetFrameIndex()
static inline u32 vFrameIndex()
{
return renderer.frame_state.frame_cnt % FRAME_OVERLAP;
}
static inline VkCommandBuffer GetFrameCmdBuf()
static inline VkCommandBuffer vFrameCmdBuf()
{
return renderer.vk.frame.buffers[GetFrameIndex()];
return renderer.vk.frame.buffers[vFrameIndex()];
}
static inline VkFence *GetFrameRenderFence()
static inline VkFence *vFrameRenderFence()
{
return &renderer.vk.frame.render_fences[GetFrameIndex()];
return &renderer.vk.frame.render_fences[vFrameIndex()];
}
static inline VkSemaphore GetFrameRenderSem()
static inline VkSemaphore vFrameRenderSem()
{
return renderer.vk.frame.render_sems[GetFrameIndex()];
return renderer.vk.frame.render_sems[vFrameIndex()];
}
static inline VkSemaphore GetFrameSwapSem()
static inline VkSemaphore vFrameSwapSem()
{
return renderer.vk.frame.swapchain_sems[GetFrameIndex()];
return renderer.vk.frame.swapchain_sems[vFrameIndex()];
}
static inline u32 *GetFrameBufferCount()
static inline u32 *vFrameBufferCount()
{
return &renderer.vk.frame.buffer_counts[GetFrameIndex()];
return &renderer.vk.frame.buffer_counts[vFrameIndex()];
}
static inline RenderBuffer *GetFrameRenderBuffers()
static inline rRenderBuffer *vFrameRenderBuffers()
{
return renderer.vk.frame.buffer_destroy_queues[GetFrameIndex()];
return renderer.vk.frame.buffer_destroy_queues[vFrameIndex()];
}
static inline void CopyImageToImage(VkCommandBuffer cmd, VkImage src, VkImage dst, VkExtent2D src_ext, VkExtent2D dst_ext)
static inline void vImageCopyToImage(VkCommandBuffer cmd, VkImage src, VkImage dst, VkExtent2D src_ext, VkExtent2D dst_ext)
{
VkImageBlit2 blit = {
.sType = STYPE(IMAGE_BLIT_2),
@ -111,7 +111,7 @@ static inline void CopyImageToImage(VkCommandBuffer cmd, VkImage src, VkImage ds
vkCmdBlitImage2(cmd, &blit_info);
}
static inline void TransitionImageLayout(VkCommandBuffer cmd, VkImage img, VkImageLayout curr, VkImageLayout new)
static inline void vImageTransitionLayout(VkCommandBuffer cmd, VkImage img, VkImageLayout curr, VkImageLayout new)
{
VkImageMemoryBarrier2 barrier = {
.sType = STYPE(IMAGE_MEMORY_BARRIER_2),
@ -140,9 +140,9 @@ static inline void TransitionImageLayout(VkCommandBuffer cmd, VkImage img, VkIma
vkCmdPipelineBarrier2(cmd, &dep_info);
}
static inline void TransitionImage(VkCommandBuffer cmd, Image *img, VkImageLayout new)
static inline void vImageTransition(VkCommandBuffer cmd, vImage *img, VkImageLayout new)
{
TransitionImageLayout(cmd, img->img, img->curr_layout, new);
vImageTransitionLayout(cmd, img->img, img->curr_layout, new);
img->curr_layout = new;
}
@ -152,15 +152,15 @@ static inline void TransitionImage(VkCommandBuffer cmd, Image *img, VkImageLayou
// ::Vulkan::Rendering::Functions::Start::
static void BeginRendering()
static void vRenderingBegin()
{
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
VkImage curr_img = renderer.vk.sc.imgs[renderer.frame_state.img_ix];
TransitionImage(cmd, &renderer.vk.sc.draw_img, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
TransitionImage(cmd, &renderer.vk.sc.depth_img, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL);
vImageTransition(cmd, &renderer.vk.sc.draw_img, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
vImageTransition(cmd, &renderer.vk.sc.depth_img, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL);
TransitionImageLayout(cmd, curr_img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
vImageTransitionLayout(cmd, curr_img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkRenderingAttachmentInfo col_attach_info = {
.sType = STYPE(RENDERING_ATTACHMENT_INFO),
@ -204,7 +204,7 @@ static void BeginRendering()
// ::Vulkan::ImmediateSubmit::Functions::Start::
static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd)
static b32 vImmSubmitBegin(VkDevice device, VkFence fence, VkCommandBuffer cmd)
{
b32 success = true;
@ -212,7 +212,7 @@ static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd)
VkResult result = vkResetFences(device, 1, &f);
if (result != VK_SUCCESS)
{
Printfln("vkResetFences failure: %s", VkResultStr(result));
Printfln("vkResetFences failure: %s", vVkResultStr(result));
success = false;
}
@ -221,7 +221,7 @@ static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd)
result = vkResetCommandBuffer(cmd, 0);
if (result != VK_SUCCESS)
{
Printfln("vkResetCommandBuffer failure: %s", VkResultStr(result));
Printfln("vkResetCommandBuffer failure: %s", vVkResultStr(result));
success = false;
}
}
@ -236,7 +236,7 @@ static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd)
result = vkBeginCommandBuffer(cmd, &buf_info);
if (result != VK_SUCCESS)
{
Printfln("vkBeginCommandBuffer failure: %s", VkResultStr(result));
Printfln("vkBeginCommandBuffer failure: %s", vVkResultStr(result));
success = false;
}
}
@ -244,7 +244,7 @@ static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd)
return success;
}
static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd, VkQueue queue)
static b32 vImmSubmitFinish(VkDevice device, VkFence fence, VkCommandBuffer cmd, VkQueue queue)
{
b32 success = true;
VkFence f = fence;
@ -252,7 +252,7 @@ static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd,
VkResult result = vkEndCommandBuffer(cmd);
if (result != VK_SUCCESS)
{
Printfln("vkEndCommandBuffer imm failure: %s", VkResultStr(result));
Printfln("vkEndCommandBuffer imm failure: %s", vVkResultStr(result));
success = false;
}
@ -272,7 +272,7 @@ static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd,
result = vkQueueSubmit2(queue, 1, &submit_info, f);
if (result != VK_SUCCESS)
{
Printfln("vkQueueSubmit2 imm failure: %s", VkResultStr(result));
Printfln("vkQueueSubmit2 imm failure: %s", vVkResultStr(result));
success = false;
}
}
@ -282,7 +282,7 @@ static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd,
result = vkWaitForFences(device, 1, &f, true, 9999999999);
if (result != VK_SUCCESS)
{
Printfln("vkWaitForFences imm failure: %s", VkResultStr(result));
Printfln("vkWaitForFences imm failure: %s", vVkResultStr(result));
success = false;
}
}
@ -296,19 +296,19 @@ static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd,
// ::Vulkan::Swapchain::Functions::Start::
static void ResizeSwapchain()
static void vSwapchainResize()
{
vkDeviceWaitIdle(renderer.vk.device);
DestroySwapchain();
vSwapchainDestroy();
DestroyDrawImages();
vDrawImagesDestroy();
renderer.vk.sc.extent.width = renderer.pending.render_width;
renderer.vk.sc.extent.height = renderer.pending.render_height;
Assert(CreateSwapchain(), "Unable to recreate swapchain");
Assert(CreateDrawImages(), "Unable to recreate draw images");
Assert(vSwapchainInit(), "Unable to recreate swapchain");
Assert(vDrawImagesInit(), "Unable to recreate draw images");
renderer.pending.resized = false;
}
@ -319,12 +319,12 @@ static void ResizeSwapchain()
// ::Vulkan::Images::Functions::Start::
static b32 CreateVkSampler(TextureBuffer *buffer)
static b32 vSamplerCreate(rTextureBuffer *buffer)
{
b32 success = true;
Image *image = &buffer->image;
vImage *image = &buffer->image;
RenderBuffer staging_buffer = {
rRenderBuffer staging_buffer = {
.type = RENDER_BUFFER_TYPE_STAGING,
.size = buffer->width * buffer->height,
};
@ -364,7 +364,7 @@ static b32 CreateVkSampler(TextureBuffer *buffer)
if (result != VK_SUCCESS)
{
success = false;
Printfln("vmaCreateImage failure: %s", VkResultStr(result));
Printfln("vmaCreateImage failure: %s", vVkResultStr(result));
}
if (success)
@ -416,7 +416,7 @@ static b32 CreateVkSampler(TextureBuffer *buffer)
return success;
}
static void UploadToImage(TextureBuffer *buffer, u8 *data, u32 thread_idx)
static void vImageUpload(rTextureBuffer *buffer, u8 *data, u32 thread_idx)
{
b32 success = true;
@ -424,21 +424,21 @@ static void UploadToImage(TextureBuffer *buffer, u8 *data, u32 thread_idx)
VkCommandBuffer cmd = renderer.vk.imm.cmds[thread_idx];
VkFence fence = renderer.vk.imm.fences[thread_idx];
VkQueue queue = renderer.vk.queues.transfer_queue;
Image *image = &buffer->image;
vImage *image = &buffer->image;
u32 width = buffer->width;
u32 height = buffer->height;
u32 channels = buffer->channels;
RenderBuffer staging_buffer = {
rRenderBuffer staging_buffer = {
.type = RENDER_BUFFER_TYPE_STAGING,
.size = width * height * channels,
};
TransitionImage(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
vImageTransition(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
success = BeginImmSubmit(device, fence, cmd);
success = vImmSubmitBegin(device, fence, cmd);
if (success)
Assert(CreateBuffer(&staging_buffer), "UploadToImage failure: error creating buffer");
Assert(rBufferCreate(&staging_buffer), "vImageUpload failure: error creating buffer");
if (success)
{
@ -465,7 +465,7 @@ static void UploadToImage(TextureBuffer *buffer, u8 *data, u32 thread_idx)
vmaUnmapMemory(renderer.vk.alloc, staging_buffer.alloc);
vmaDestroyBuffer(renderer.vk.alloc, staging_buffer.buffer, staging_buffer.alloc);
success = FinishImmSubmit(device, fence, cmd, queue);
success = vImmSubmitFinish(device, fence, cmd, queue);
}
}
@ -475,44 +475,44 @@ static void UploadToImage(TextureBuffer *buffer, u8 *data, u32 thread_idx)
// ::Vulkan::Descriptors::Functions::Start::
static void DescriptorHandlePush(DescType type, DescHandle handle)
static void vDescHandlePush(vDescType type, rDescHandle handle)
{
DescBindings *bindings = renderer.vk.pipe.bindings + type;
vDescBindings *bindings = renderer.vk.pipe.bindings + type;
Assert(bindings->free_count < DESC_MAX_BINDINGS-1, "DescriptorHandlePush failure: free_count equal to DESC_MAX_BINDINGS-1");
Assert(bindings->free_count < DESC_MAX_BINDINGS-1, "vDescHandlePush failure: free_count equal to DESC_MAX_BINDINGS-1");
bindings->free[bindings->free_count] = handle;
bindings->free_count += 1;
}
static DescHandle DescriptorHandlePop(DescType type)
static rDescHandle vDescHandlePop(vDescType type)
{
DescBindings *bindings = renderer.vk.pipe.bindings + type;
vDescBindings *bindings = renderer.vk.pipe.bindings + type;
Assert(bindings->free_count > 0, "DescriptorHandlePop failure: free_count is 0");
Assert(bindings->free_count > 0, "vDescHandlePop failure: free_count is 0");
bindings->free_count -= 1;
return bindings->free[bindings->free_count];
}
static DescAssetInfo *DescriptorTableSearch(DescType type, u64 asset_id)
static vAssetInfo *vDescHandleSearch(vDescType type, u64 asset_id)
{
DescAssetInfo *asset_info = NULL;
vAssetInfo *asset_info = NULL;
HashTable *table = &renderer.vk.pipe.bindings[type].lookup_table;
KeyValuePair *kv_pair = HashTableSearchU64(table, asset_id);
if (kv_pair != NULL)
{
asset_info = (DescAssetInfo *)kv_pair->value_rawptr;
asset_info = (vAssetInfo *)kv_pair->value_rawptr;
}
return asset_info;
}
static void DescriptorTableInsert(DescType type, u64 asset_id, DescHandle handle)
static void DescriptorTableInsert(vDescType type, u64 asset_id, rDescHandle handle)
{
DescAssetInfo *asset_info = FLMemAlloc(sizeof(DescAssetInfo));
vAssetInfo *asset_info = FLMemAlloc(sizeof(vAssetInfo));
asset_info->handle = handle;
asset_info->type = type;
@ -522,7 +522,7 @@ static void DescriptorTableInsert(DescType type, u64 asset_id, DescHandle handle
HashTablePushU64Rawptr(table, asset_id, asset_info);
}
static void DescriptorTableDelete(DescType type, u64 asset_id)
static void vDescHandleDelete(vDescType type, u64 asset_id)
{
HashTable *table = &renderer.vk.pipe.bindings[type].lookup_table;
HashTableDeleteU64(table, asset_id);
@ -534,7 +534,7 @@ static void DescriptorTableDelete(DescType type, u64 asset_id)
// ::Vulkan::Init::Functions::Start::
static b32 CreateVmaAllocator()
static b32 vVmaAllocatorInit()
{
VmaVulkanFunctions vk_functions = {
.vkGetInstanceProcAddr = vkGetInstanceProcAddr,
@ -554,16 +554,16 @@ static b32 CreateVmaAllocator()
return result == VK_SUCCESS;
}
static b32 CheckQueueSurfaceSupport(i32 index, VkPhysicalDevice device, VkSurfaceKHR surface)
static b32 vQueueCheckSurfaceSupport(i32 index, VkPhysicalDevice device, VkSurfaceKHR surface)
{
b32 surface_supported;
vkGetPhysicalDeviceSurfaceSupportKHR(device, (u32)index, surface, &surface_supported);
return surface_supported;
}
static DeviceQueues CheckDeviceQueueSupport(VkPhysicalDevice device, VkSurfaceKHR surface)
static vDeviceQueues vQueueCheckSupport(VkPhysicalDevice device, VkSurfaceKHR surface)
{
DeviceQueues queues = { .graphics = -1, .transfer = -1 };
vDeviceQueues queues = { .graphics = -1, .transfer = -1 };
u32 queue_count;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queue_count, NULL);
@ -583,7 +583,7 @@ static DeviceQueues CheckDeviceQueueSupport(VkPhysicalDevice device, VkSurfaceKH
b8 transfer_only = false;
for (i32 i = 0; i < queue_count; i++)
{
if (queues.graphics < 0 && CheckQueueSurfaceSupport(i, device, surface) && BitEq(families[i].queueFlags, VK_QUEUE_GRAPHICS_BIT))
if (queues.graphics < 0 && vQueueCheckSurfaceSupport(i, device, surface) && BitEq(families[i].queueFlags, VK_QUEUE_GRAPHICS_BIT))
{
queues.graphics = i;
continue;
@ -622,7 +622,7 @@ static DeviceQueues CheckDeviceQueueSupport(VkPhysicalDevice device, VkSurfaceKH
return queues;
}
static b32 CheckDevicePropertiesSupport(VkPhysicalDevice device, VkSurfaceKHR surface, b32 *discrete)
static b32 vDeviceCheckPropertiesSupport(VkPhysicalDevice device, VkSurfaceKHR surface, b32 *discrete)
{
b32 success = false;
VkPhysicalDeviceProperties properties = {0};
@ -660,7 +660,7 @@ static b32 CheckDevicePropertiesSupport(VkPhysicalDevice device, VkSurfaceKHR su
return success;
}
static b32 CheckDeviceFeatureSupport(VkPhysicalDevice device)
static b32 vDeviceCheckFeatureSupport(VkPhysicalDevice device)
{
VkPhysicalDeviceFeatures2 features2 = { .sType = STYPE(PHYSICAL_DEVICE_FEATURES_2) };
@ -690,7 +690,7 @@ static b32 CheckDeviceFeatureSupport(VkPhysicalDevice device)
return result;
}
static b32 CreateDevice()
static b32 vDeviceInit()
{
VkInstance inst = renderer.vk.inst;
VkSurfaceKHR surface = renderer.vk.surface;
@ -701,19 +701,19 @@ static b32 CreateDevice()
vkEnumeratePhysicalDevices(inst, &device_count, devices);
b32 discrete_device = false;
DeviceQueues *queues = &renderer.vk.queues;
vDeviceQueues *queues = &renderer.vk.queues;
VkPhysicalDevice *phys_device = &renderer.vk.phys_device;
for (u32 i = 0; i < device_count; i++) {
DeviceQueues current_queues = CheckDeviceQueueSupport(devices[i], surface);
vDeviceQueues current_queues = vQueueCheckSupport(devices[i], surface);
b32 discrete = false;
if (current_queues.graphics < 0)
continue;
if (!CheckDevicePropertiesSupport(devices[i], surface, &discrete))
if (!vDeviceCheckPropertiesSupport(devices[i], surface, &discrete))
continue;
if (discrete_device && !discrete)
continue;
if (!CheckDeviceFeatureSupport(devices[i]))
if (!vDeviceCheckFeatureSupport(devices[i]))
continue;
discrete_device = discrete;
@ -760,7 +760,7 @@ static b32 CreateDevice()
}
else
{
Assert(InitVkDeviceFunctions(), "Failed to initialize device functions");
Assert(vDeviceFunctionsInit(), "Failed to initialize device functions");
vkGetDeviceQueue(renderer.vk.device, queues->graphics, 0, &queues->graphics_queue);
vkGetDeviceQueue(renderer.vk.device, queues->transfer, transfer_queue_index, &queues->transfer_queue);
@ -771,9 +771,9 @@ static b32 CreateDevice()
return success;
}
static b32 InitVkGlobalFunctions()
static b32 vGlobalFunctionsInit()
{
b32 result = LoadVulkanLib();
b32 result = vLibraryLoad();
if (result)
{
INIT_FN(vkGetInstanceProcAddr);
@ -784,7 +784,7 @@ static b32 InitVkGlobalFunctions()
return result;
}
static b32 InitVkInstanceFunctions()
static b32 vInstanceFunctionsInit()
{
VkInstance instance = renderer.vk.inst;
@ -827,7 +827,7 @@ static b32 InitVkInstanceFunctions()
return true;
}
static b32 InitVkDeviceFunctions() {
static b32 vDeviceFunctionsInit() {
VkDevice device = renderer.vk.device;
INIT_DEV_FN(vkCreateSwapchainKHR);
@ -894,9 +894,9 @@ static b32 InitVkDeviceFunctions() {
// TODO(MA): implement other platforms
#ifdef __linux__
static b32 CreateSurface()
static b32 vSurfaceInit()
{
PlatformWindow *window = GetPlatformWindow();
pPlatformWindow *window = pWindowGet();
VkXcbSurfaceCreateInfoKHR surface_info = {
.sType = STYPE(XCB_SURFACE_CREATE_INFO_KHR),
.connection = window->connection,
@ -911,11 +911,11 @@ static b32 CreateSurface()
return result == VK_SUCCESS;
}
#elif _WIN32
static b32 CreateSurface()
static b32 vSurfaceInit()
{
b32 success = true;
PlatformWindow *window = GetPlatformWindow();
pPlatformWindow *window = pWindowGet();
VkWin32SurfaceCreateInfoKHR surface_info = {
.sType = STYPE(WIN32_SURFACE_CREATE_INFO_KHR),
.hinstance = window->instance,
@ -925,7 +925,7 @@ static b32 CreateSurface()
VkResult result = vkCreateWin32SurfaceKHR(renderer.vk.inst, &surface_info, NULL, &renderer.vk.surface);
if (result != VK_SUCCESS)
{
Printfln("Unable to create surface: %s", VkResultStr(result));
Printfln("Unable to create surface: %s", vVkResultStr(result));
success = false;
}
@ -933,15 +933,15 @@ static b32 CreateSurface()
}
#endif
static b32 LoadVulkanLib()
static b32 vLibraryLoad()
{
Library *lib = &renderer.vk.lib;
b32 lib_found; Function fn;
pLibrary *lib = &renderer.vk.lib;
b32 lib_found; pFunction fn;
for (i32 i = 0; i < Len(vulkan_libs); i++) {
lib_found = LoadLib(vulkan_libs[i], lib);
lib_found = pLibraryLoad(vulkan_libs[i], lib);
if (lib_found) {
lib_found = LoadFn("vkGetInstanceProcAddr", lib, &fn);
lib_found = pFunctionLoad("vkGetInstanceProcAddr", lib, &fn);
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)fn.fn;
break;
}
@ -950,10 +950,10 @@ static b32 LoadVulkanLib()
return lib_found;
}
static b32 CreateFrameStructures()
static b32 vFrameStructuresInit()
{
b32 success = true;
FrameStructures *data = &renderer.vk.frame;
vFrameStructures *data = &renderer.vk.frame;
u32 img_count = renderer.vk.sc.img_count;
pool_create_info.queueFamilyIndex = renderer.vk.queues.graphics;
@ -963,7 +963,7 @@ static b32 CreateFrameStructures()
renderer.vk.frame.swapchain_sems = MakeArray(renderer.perm_arena, VkSemaphore, img_count);
renderer.vk.frame.render_sems = MakeArray(renderer.perm_arena, VkSemaphore, img_count);
renderer.vk.frame.render_fences = MakeArray(renderer.perm_arena, VkFence, img_count);
renderer.vk.frame.buffer_destroy_queues = MakeArray(renderer.perm_arena, RenderBuffer *, FRAME_OVERLAP);
renderer.vk.frame.buffer_destroy_queues = MakeArray(renderer.perm_arena, rRenderBuffer *, FRAME_OVERLAP);
renderer.vk.frame.buffer_counts = MakeArray(renderer.perm_arena, u32, FRAME_OVERLAP);
for (u32 i = 0; i < FRAME_OVERLAP; i++)
@ -993,18 +993,18 @@ static b32 CreateFrameStructures()
if (result != VK_SUCCESS)
success = false;
renderer.vk.frame.buffer_destroy_queues[i] = ArenaAlloc(renderer.perm_arena, sizeof(RenderBuffer) * 64);
renderer.vk.frame.buffer_destroy_queues[i] = ArenaAlloc(renderer.perm_arena, sizeof(rRenderBuffer) * 64);
}
return success;
}
static b32 CreateImmediateStructures()
static b32 vImmediateStructuresInit()
{
b32 success = true;
VkResult result;
VkDevice device = renderer.vk.device;
ImmediateStructures *imm = &renderer.vk.imm;
vImmediateStructures *imm = &renderer.vk.imm;
pool_create_info.queueFamilyIndex = renderer.vk.queues.transfer;
if (renderer.vk_conf.avail_threads >= 4 && !renderer.vk.queues.single_queue)
@ -1036,7 +1036,7 @@ static b32 CreateImmediateStructures()
return success;
}
static void CreateUploadQueues()
static void vUploadQueuesInit()
{
for (u32 i = 0; i < DESC_TYPE_MAX; i++)
{
@ -1045,7 +1045,7 @@ static void CreateUploadQueues()
}
}
static b32 CreateSwapchain()
static b32 vSwapchainInit()
{
b32 success = true;
VkPhysicalDevice phys_device = renderer.vk.phys_device;
@ -1137,12 +1137,12 @@ static b32 CreateSwapchain()
return success;
}
static b32 CreateDrawImages()
static b32 vDrawImagesInit()
{
b32 success = true;
VkResult result;
VkFormat image_format = GetImageFormat();
VkFormat image_format = vImageFormatGet();
VkExtent3D extent = renderer.vk.sc.extent;
VkDevice device = renderer.vk.device;
@ -1151,7 +1151,7 @@ static b32 CreateDrawImages()
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
};
// Draw Image
// Draw vImage
draw_image_create_info.format = image_format;
draw_image_create_info.extent = extent;
@ -1160,7 +1160,7 @@ static b32 CreateDrawImages()
if (result != VK_SUCCESS)
success = false;
// Draw Image View
// Draw vImage View
draw_image_view_create_info.image = renderer.vk.sc.draw_img.img;
draw_image_view_create_info.format = image_format;
@ -1168,7 +1168,7 @@ static b32 CreateDrawImages()
if (result != VK_SUCCESS)
success = false;
// Depth Image
// Depth vImage
depth_image_create_info.extent = extent;
result = vmaCreateImage(renderer.vk.alloc, &depth_image_create_info,
@ -1176,7 +1176,7 @@ static b32 CreateDrawImages()
if (result != VK_SUCCESS)
success = false;
// Depth Image View
// Depth vImage View
depth_image_view_create_info.image = renderer.vk.sc.depth_img.img;
result = vkCreateImageView(device, &depth_image_view_create_info, NULL, &renderer.vk.sc.depth_img.view);
if (result != VK_SUCCESS)
@ -1192,7 +1192,7 @@ static b32 CreateDrawImages()
return success;
}
static VkFormat GetImageFormat()
static VkFormat vImageFormatGet()
{
VkPhysicalDevice phys_device = renderer.vk.phys_device;
VkImageType image_type = VK_IMAGE_TYPE_2D;
@ -1224,15 +1224,15 @@ static VkFormat GetImageFormat()
return format;
}
static b32 CreateDescriptors()
static b32 vDescriptorsInit()
{
b32 success = true;
renderer.vk.pipe.bindings = ArenaAlloc(renderer.perm_arena, sizeof(DescBindings) * DESC_TYPE_MAX);
renderer.vk.pipe.bindings = ArenaAlloc(renderer.perm_arena, sizeof(vDescBindings) * DESC_TYPE_MAX);
VkDevice device = renderer.vk.device;
VkResult result;
DescBindings *bindings = renderer.vk.pipe.bindings;
vDescBindings *bindings = renderer.vk.pipe.bindings;
result = vkCreateDescriptorPool(device, &desc_pool_info, NULL, &renderer.vk.pipe.pool);
if (result != VK_SUCCESS)
@ -1283,18 +1283,18 @@ static b32 CreateDescriptors()
return success;
}
static b32 CreatePipelines()
static b32 vPipelinesInit()
{
b32 success = true;
VkResult result;
VkDevice device = renderer.vk.device;
Asset quad_vert_shader = AssetPackLoadShader(QUAD_VERT_SPIRV_SHADER);
Asset quad_frag_shader = AssetPackLoadShader(QUAD_FRAG_SPIRV_SHADER);
Asset quad_vert_shader = apLoadShader(QUAD_VERT_SPIRV_SHADER);
Asset quad_frag_shader = apLoadShader(QUAD_FRAG_SPIRV_SHADER);
VkShaderModule cube_vert, cube_frag;
success &= CreateShaderModule(quad_vert_shader.bytes, quad_vert_shader.len, &cube_vert);
success &= CreateShaderModule(quad_frag_shader.bytes, quad_frag_shader.len, &cube_frag);
success &= vShaderModuleInit(quad_vert_shader.bytes, quad_vert_shader.len, &cube_vert);
success &= vShaderModuleInit(quad_frag_shader.bytes, quad_frag_shader.len, &cube_frag);
VkPipelineRenderingCreateInfo pipeline_render_info = {
.sType = STYPE(PIPELINE_RENDERING_CREATE_INFO),
@ -1326,22 +1326,22 @@ static b32 CreatePipelines()
result = vkCreateGraphicsPipelines(device, 0, 1, &cube_create_info, NULL, &renderer.vk.pipe.pipelines[PIPELINE_CUBE]);
if (result != VK_SUCCESS)
{
Printf("vkCreateGraphicsPipelines failure: %s", VkResultStr(result));
Printf("vkCreateGraphicsPipelines failure: %s", vVkResultStr(result));
success = false;
}
vkDestroyShaderModule(device, cube_vert, NULL);
vkDestroyShaderModule(device, cube_frag, NULL);
AssetPackUnloadShader(quad_vert_shader);
AssetPackUnloadShader(quad_frag_shader);
apUnloadShader(quad_vert_shader);
apUnloadShader(quad_frag_shader);
Asset gui_vert_shader = AssetPackLoadShader(GUI_VERT_SPIRV_SHADER);
Asset gui_frag_shader = AssetPackLoadShader(GUI_FRAG_SPIRV_SHADER);
Asset gui_vert_shader = apLoadShader(GUI_VERT_SPIRV_SHADER);
Asset gui_frag_shader = apLoadShader(GUI_FRAG_SPIRV_SHADER);
VkShaderModule gui_vert, gui_frag;
success &= CreateShaderModule(gui_vert_shader.bytes, gui_vert_shader.len, &gui_vert);
success &= CreateShaderModule(gui_frag_shader.bytes, gui_frag_shader.len, &gui_frag);
success &= vShaderModuleInit(gui_vert_shader.bytes, gui_vert_shader.len, &gui_vert);
success &= vShaderModuleInit(gui_frag_shader.bytes, gui_frag_shader.len, &gui_frag);
VkPipelineShaderStageCreateInfo gui_shader_stages[] = {
{
@ -1366,20 +1366,20 @@ static b32 CreatePipelines()
result = vkCreateGraphicsPipelines(device, 0, 1, &gui_create_info, NULL, &renderer.vk.pipe.pipelines[PIPELINE_GUI]);
if (result != VK_SUCCESS)
{
Printfln("vkCreateGraphicsPipelines failure: %s", VkResultStr(result));
Printfln("vkCreateGraphicsPipelines failure: %s", vVkResultStr(result));
success = false;
}
vkDestroyShaderModule(device, gui_vert, NULL);
vkDestroyShaderModule(device, gui_frag, NULL);
AssetPackUnloadShader(gui_vert_shader);
AssetPackUnloadShader(gui_frag_shader);
apUnloadShader(gui_vert_shader);
apUnloadShader(gui_frag_shader);
return success;
}
static b32 CreateShaderModule(u8 *bytes, u32 len, VkShaderModule *module)
static b32 vShaderModuleInit(u8 *bytes, u32 len, VkShaderModule *module)
{
VkResult result;
b32 success = true;
@ -1393,7 +1393,7 @@ static b32 CreateShaderModule(u8 *bytes, u32 len, VkShaderModule *module)
result = vkCreateShaderModule(renderer.vk.device, &module_info, NULL, module);
if (result != VK_SUCCESS)
{
Printf("vkCreateShaderModule failure: %s", VkResultStr(result));
Printf("vkCreateShaderModule failure: %s", vVkResultStr(result));
success = false;
}
@ -1402,7 +1402,7 @@ static b32 CreateShaderModule(u8 *bytes, u32 len, VkShaderModule *module)
#if __linux__
static void StartVkLoaderThreads()
static void vLoaderStartThreads()
{
if (renderer.vk_conf.avail_threads == 0)
return;
@ -1413,7 +1413,7 @@ static void StartVkLoaderThreads()
for (u32 i = 0; i < count; i++)
{
vk_thread_indices[i] = i;
pthread_create(&threads[i], NULL, VkLoaderStart, &vk_thread_indices[i]);
pthread_create(&threads[i], NULL, vLoaderStart, &vk_thread_indices[i]);
}
}
@ -1429,11 +1429,11 @@ static void StartVkLoaderThreads()
// ::Vulkan::Async::Functions::Start::
static u32 VkLoaderProcessBuffers(u32 thread_index)
static u32 vLoaderProcessBuffers(u32 thread_index)
{
JobQueue *job_queue = &renderer.upload_queues[DESC_TYPE_BUFFER].job_queue;
TicketMut *ticket_mut = &renderer.upload_queues[DESC_TYPE_BUFFER].ticket_mut;
RenderBuffer **render_buffers = renderer.upload_queues[DESC_TYPE_BUFFER].queued_buffers;
rRenderBuffer **render_buffers = renderer.upload_queues[DESC_TYPE_BUFFER].queued_buffers;
rawptr *buffer_data = renderer.upload_queues[DESC_TYPE_BUFFER].data;
u32 buffer_count = JobQueueGetCount(job_queue);
@ -1442,7 +1442,7 @@ static u32 VkLoaderProcessBuffers(u32 thread_index)
{
TicketMutLock(ticket_mut);
RenderBuffer *buffers[16];
rRenderBuffer *buffers[16];
rawptr data[16];
for (i32 i = i32(buffer_count - 1); i >= 0 && count < 16; i--)
{
@ -1456,9 +1456,9 @@ static u32 VkLoaderProcessBuffers(u32 thread_index)
TicketMutUnlock(ticket_mut);
for (u32 i = 0; i < count; i++)
Assert(CreateBuffer(buffers[i]), "VkLoaderProcessBuffers failure: CreateBuffer failed");
Assert(rBufferCreate(buffers[i]), "vLoaderProcessBuffers failure: rBufferCreate failed");
Assert(UploadToBuffer(buffers, data, count, thread_index), "VkLoaderProcessBuffers failure: UploadToBuffer failed");
Assert(rBufferUpload(buffers, data, count, thread_index), "vLoaderProcessBuffers failure: rBufferUpload failed");
JobQueueMarkCompleted(job_queue, count);
}
@ -1466,11 +1466,11 @@ static u32 VkLoaderProcessBuffers(u32 thread_index)
return count;
}
static u32 VkLoaderProcessSamplers(u32 thread_index)
static u32 vLoaderProcessSamplers(u32 thread_index)
{
JobQueue *job_queue = &renderer.upload_queues[DESC_TYPE_SAMPLER].job_queue;
TicketMut *ticket_mut = &renderer.upload_queues[DESC_TYPE_SAMPLER].ticket_mut;
TextureBuffer **texture_buffers = renderer.upload_queues[DESC_TYPE_SAMPLER].queued_textures;
rTextureBuffer **texture_buffers = renderer.upload_queues[DESC_TYPE_SAMPLER].queued_textures;
rawptr *texture_data = renderer.upload_queues[DESC_TYPE_SAMPLER].data;
u32 buffer_count = JobQueueGetCount(job_queue);
@ -1479,7 +1479,7 @@ static u32 VkLoaderProcessSamplers(u32 thread_index)
{
TicketMutLock(ticket_mut);
TextureBuffer *buffers[16];
rTextureBuffer *buffers[16];
rawptr data[16];
for (i32 i = i32(buffer_count - 1); i >= 0 && count < 16; i--)
{
@ -1494,8 +1494,8 @@ static u32 VkLoaderProcessSamplers(u32 thread_index)
for (u32 i = 0; i < count; i++)
{
Assert(CreateVkSampler(buffers[i]), "Unable to create VkSampler");
UploadToImage(buffers[i], data[i], thread_index);
Assert(vSamplerCreate(buffers[i]), "Unable to create VkSampler");
vImageUpload(buffers[i], data[i], thread_index);
}
JobQueueMarkCompleted(job_queue, count);
@ -1512,7 +1512,7 @@ static u32 VkLoaderProcessSamplers(u32 thread_index)
#ifdef __linux__
void *VkLoaderStart(void *i)
void *vLoaderStart(void *i)
{
u32 index = *(u32 *)i;
pthread_t self = pthread_self();
@ -1532,11 +1532,11 @@ void *VkLoaderStart(void *i)
{
case DESC_TYPE_BUFFER:
{
processed_count += VkLoaderProcessBuffers(index);
processed_count += vLoaderProcessBuffers(index);
} break;
case DESC_TYPE_SAMPLER:
{
processed_count += VkLoaderProcessSamplers(index);
processed_count += vLoaderProcessSamplers(index);
} break;
default:
break;
@ -1557,12 +1557,12 @@ void *VkLoaderStart(void *i)
pthread_mutex_lock(&mut);
pthread_cond_wait(&cond, &mut);
pthread_mutex_unlock(&mut);
AtomicFetchSubu8(&renderer.vk_conf.sleeping_threads, 1);
pu8AtomicFetchSub(&renderer.vk_conf.sleeping_threads, 1);
}
}
}
void VkLoaderWake()
void vLoaderWake()
{
for (u32 i = 0; i < renderer.vk_conf.avail_threads; i++)
pthread_cond_signal(&cond);
@ -1580,7 +1580,7 @@ void VkLoaderWake()
// ::Vulkan::CleanUp::Functions::Start::
static void DestroySwapchain()
static void vSwapchainDestroy()
{
for (u32 i = 0; i < renderer.vk.sc.img_count; i++)
{
@ -1590,9 +1590,9 @@ static void DestroySwapchain()
vkDestroySwapchainKHR(renderer.vk.device, renderer.vk.swapchain, NULL);
}
static void DestroyDrawImages()
static void vDrawImagesDestroy()
{
SwapchainStructures *sc = &renderer.vk.sc;
vSwapchainStructures *sc = &renderer.vk.sc;
VkDevice device = renderer.vk.device;
VmaAllocator vma_alloc = renderer.vk.alloc;
@ -1609,17 +1609,17 @@ static void DestroyDrawImages()
// ::Vulkan::Logging::Functions::Start::
void VkInfo(const char *str)
void vInfo(const char *str)
{
Printfln("[INFO] %s", str);
}
void VkWarn(const char *str)
void vWarn(const char *str)
{
Printfln("[WARN] %s", str);
}
void VkError(const char *str)
void vError(const char *str)
{
Printfln("[ERROR] %s", str);
}
@ -1630,7 +1630,7 @@ void VkError(const char *str)
// ::Vulkan::Debug::Functions::Start::
const char *VkResultStr(VkResult result)
const char *vVkResultStr(VkResult result)
{
switch (result)
{
@ -1743,7 +1743,7 @@ const char *VkResultStr(VkResult result)
}
}
static VKAPI_ATTR VkBool32 DebugCallback(
static VKAPI_ATTR VkBool32 vDebugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
VkDebugUtilsMessageTypeFlagsEXT message_type,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
@ -1801,13 +1801,13 @@ static VKAPI_ATTR VkBool32 DebugCallback(
return VK_FALSE;
}
static b32 VLayersSupported()
static b32 vValidationSupported()
{
b32 success = false;
u32 count;
vkEnumerateInstanceLayerProperties(&count, NULL);
Assert(count, "VLayersSupported(): vkEnumerateInstanceLayerProperties returned a count of 0");
Assert(count, "vValidationSupported(): vkEnumerateInstanceLayerProperties returned a count of 0");
VkLayerProperties *layers = ArenaAlloc(renderer.arena, sizeof(VkLayerProperties) * count);
vkEnumerateInstanceLayerProperties(&count, layers);

View File

@ -179,14 +179,9 @@ typedef enum DescType_e
DESC_TYPE_BUFFER,
DESC_TYPE_MAX,
} DescType;
} vDescType;
typedef struct ShaderGlobals
{
Vec2 res;
} ShaderGlobals;
typedef struct Image
typedef struct vImage
{
VkImage img;
VkImageView view;
@ -194,114 +189,69 @@ typedef struct Image
VmaAllocation alloc;
VkFormat fmt;
VkImageLayout curr_layout;
} Image;
} vImage;
typedef struct TextureBuffer
typedef struct vMeshBuffer
{
TextureBufferType type;
Image image;
u32 width;
u32 height;
u32 channels;
u32 index;
} TextureBuffer;
typedef struct RenderBuffer
{
RenderBufferType type;
VkBuffer buffer;
VmaAllocation alloc;
VmaAllocationInfo info;
u32 size;
u32 index; // TODO(MA): use this
} RenderBuffer;
typedef struct MeshBuffer
{
RenderBuffer index_buf, vertex_buf;
rRenderBuffer index_buf, vertex_buf;
u32 index_count;
} MeshBuffer;
} vMeshBuffer;
typedef struct GlobalUniforms
typedef struct vAssetInfo
{
f32 res[2];
} GlobalUniforms;
typedef struct DescAssetInfo
{
DescHandle handle;
DescType type;
rDescHandle handle;
vDescType type;
union
{
u64 asset_id;
TextureAsset texture_id;
};
} DescAssetInfo;
} vAssetInfo;
typedef struct DescBindings
typedef struct vDescBindings
{
u32 *free;
u32 free_count;
HashTable lookup_table;
} DescBindings;
} vDescBindings;
typedef struct PipelineStructures
typedef struct vPipelineStructures
{
VkPipelineLayout pipeline_layout;
VkDescriptorPool pool;
VkDescriptorSetLayout layouts[DESC_TYPE_MAX];
VkDescriptorSet sets[DESC_TYPE_MAX];
DescBindings *bindings;
vDescBindings *bindings;
u16 bindings_count;
VkPipeline pipelines[PIPELINE_MAX];
} PipelineStructures;
} vPipelineStructures;
typedef struct PushConst
{
Vec2 res;
Vec2 img_res;
} PushConst;
typedef struct FrameStructures
typedef struct vFrameStructures
{
VkCommandPool *pools;
VkCommandBuffer *buffers;
VkSemaphore *swapchain_sems;
VkSemaphore *render_sems;
VkFence *render_fences;
RenderBuffer **buffer_destroy_queues;
rRenderBuffer **buffer_destroy_queues;
u32 *buffer_counts;
} FrameStructures;
} vFrameStructures;
typedef struct UploadQueue
{
union
{
RenderBuffer **queued_buffers;
TextureBuffer **queued_textures;
rawptr *queued_ptrs;
};
rawptr *data;
TicketMut ticket_mut;
Mut mut;
JobQueue job_queue;
} UploadQueue;
typedef struct ImmediateStructures
typedef struct vImmediateStructures
{
VkCommandPool *pools;
VkCommandBuffer *cmds;
VkFence *fences;
} ImmediateStructures;
} vImmediateStructures;
typedef struct DeviceQueues
typedef struct vDeviceQueues
{
i32 graphics, transfer;
VkQueue graphics_queue, transfer_queue;
b8 single_queue;
} DeviceQueues;
} vDeviceQueues;
typedef struct SwapchainStructures
typedef struct vSwapchainStructures
{
VkFormat format;
VkColorSpaceKHR color_space;
@ -310,48 +260,48 @@ typedef struct SwapchainStructures
VkImage *imgs;
VkImageView *views;
u32 img_count;
Image draw_img;
Image depth_img;
} SwapchainStructures;
vImage draw_img;
vImage depth_img;
} vSwapchainStructures;
typedef struct FrameState
typedef struct vFrameState
{
u32 img_ix;
u64 frame_cnt;
u64 prev_frame;
b8 begin_rendering;
PipelineHandle last_pipeline;
RenderBuffer *prev_buffers;
rPipelineHandle last_pipeline;
rRenderBuffer *prev_buffers;
u32 prev_buffer_count;
} FrameState;
} vFrameState;
typedef struct Vulkan
typedef struct vVulkan
{
Library lib;
pLibrary lib;
VkInstance inst;
VkSurfaceKHR surface;
VkDevice device;
VkSwapchainKHR swapchain;
VkPhysicalDevice phys_device;
DeviceQueues queues;
vDeviceQueues queues;
VmaAllocator alloc;
FrameStructures frame;
ImmediateStructures imm;
SwapchainStructures sc;
PipelineStructures pipe;
vFrameStructures frame;
vImmediateStructures imm;
vSwapchainStructures sc;
vPipelineStructures pipe;
#ifdef BUILD_DEBUG
VkDebugUtilsMessengerEXT debug;
#endif
} Vulkan;
} vVulkan;
typedef struct PendingUpdates
typedef struct vPendingUpdates
{
u16 render_width;
u16 render_height;
b8 resized;
} PendingUpdates;
} vPendingUpdates;
typedef struct VulkanConfig
typedef struct vVulkanConfig
{
u8 avail_threads;
u8 volatile sleeping_threads;
@ -360,115 +310,153 @@ typedef struct VulkanConfig
#elif _WIN32
#error not yet implemented
#endif
} VulkanConfig;
} vVulkanConfig;
typedef struct Renderer
typedef struct vRenderer
{
Vulkan vk;
VulkanConfig vk_conf;
FrameState frame_state;
PendingUpdates pending;
vVulkan vk;
vVulkanConfig vk_conf;
vFrameState frame_state;
vPendingUpdates pending;
Arena *arena;
Arena *perm_arena;
UploadQueue upload_queues[DESC_TYPE_MAX];
} Renderer;
rUploadQueue upload_queues[DESC_TYPE_MAX];
} vRenderer;
// ::Vulkan::FrontEndTypes::Header::
typedef struct rShaderGlobals
{
Vec2 res;
} rShaderGlobals;
typedef struct rTextureBuffer
{
rTextureBufferType type;
vImage image;
u32 width;
u32 height;
u32 channels;
u32 index;
} rTextureBuffer;
typedef struct rRenderBuffer
{
rRenderBufferType type;
VkBuffer buffer;
VmaAllocation alloc;
VmaAllocationInfo info;
u32 size;
u32 index; // TODO(MA): use this
} rRenderBuffer;
typedef struct rPushConst
{
Vec2 res;
Vec2 img_res;
} rPushConst;
typedef struct rGlobalUniforms
{
f32 res[2];
} rGlobalUniforms;
// ::Vulkan::Debug::Functions::Header::
static b32 VLayersSupported();
static VKAPI_ATTR VkBool32 DebugCallback(
static b32 vValidationSupported();
static VKAPI_ATTR VkBool32 vDebugCallback(
VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
VkDebugUtilsMessageTypeFlagsEXT message_types,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData
);
const char *VkResultStr(VkResult result);
const char *vVkResultStr(VkResult result);
// ::Vulkan::Init::Functions::Header::
static b32 LoadVulkanLib();
static b32 InitVkInstanceFunctions();
static b32 InitVkGlobalFunctions();
static b32 CreateSurface();
static b32 CreateDevice();
static b32 CheckQueueSurfaceSupport(i32 index, VkPhysicalDevice device, VkSurfaceKHR surface);
static DeviceQueues CheckDeviceQueueSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
static b32 CheckDevicePropertiesSupport(VkPhysicalDevice device, VkSurfaceKHR surface, b32 *discrete);
static b32 CheckDeviceFeatureSupport(VkPhysicalDevice device);
static b32 InitVkDeviceFunctions();
static b32 CreateVmaAllocator();
static b32 CreateFrameStructures();
static b32 CreateImmediateStructures();
static b32 CreateSwapchain();
static b32 CreateDrawImages();
static VkFormat GetImageFormat();
static b32 CreateDescriptors();
static b32 CreatePipelines();
static b32 CreateShaderModule(u8 *bytes, u32 len, VkShaderModule *module);
static void CreateUploadQueues();
static void StartVkLoaderThreads();
static b32 vLibraryLoad();
static b32 vInstanceFunctionsInit();
static b32 vGlobalFunctionsInit();
static b32 vDeviceFunctionsInit();
static b32 vSurfaceInit();
static b32 vDeviceInit();
static b32 vQueueCheckSurfaceSupport(i32 index, VkPhysicalDevice device, VkSurfaceKHR surface);
static vDeviceQueues vQueueCheckSupport(VkPhysicalDevice device, VkSurfaceKHR surface);
static b32 vDeviceCheckPropertiesSupport(VkPhysicalDevice device, VkSurfaceKHR surface, b32 *discrete);
static b32 vDeviceCheckFeatureSupport(VkPhysicalDevice device);
static b32 vVmaAllocatorInit();
static b32 vFrameStructuresInit();
static b32 vImmediateStructuresInit();
static b32 vSwapchainInit();
static b32 vDrawImagesInit();
static VkFormat vImageFormatGet();
static b32 vDescriptorsInit();
static b32 vPipelinesInit();
static b32 vShaderModuleInit(u8 *bytes, u32 len, VkShaderModule *module);
static void vUploadQueuesInit();
static void vLoaderStartThreads();
// ::Vulkan::Util::Functions::Header::
static inline VkCommandBuffer GetFrameCmdBuf();
static inline VkFence *GetFrameRenderFence();
static inline VkSemaphore GetFrameRenderSem();
static inline VkSemaphore GetFrameSwapSem();
static inline u32 GetFrameIndex();
static inline VkImage GetFrameSwapImage();
static inline u32 *GetFrameBufferCount();
static inline RenderBuffer *GetFrameRenderBuffers();
static inline void TransitionImage(VkCommandBuffer cmd, Image *img, VkImageLayout new);
static inline void TransitionImageLayout(VkCommandBuffer cmd, VkImage img, VkImageLayout curr, VkImageLayout new);
static inline void CopyImageToImage(VkCommandBuffer cmd, VkImage src, VkImage dst, VkExtent2D src_ext, VkExtent2D dst_ext);
static inline VkCommandBuffer vFrameCmdBuf();
static inline VkFence *vFrameRenderFence();
static inline VkSemaphore vFrameRenderSem();
static inline VkSemaphore vFrameSwapSem();
static inline u32 vFrameIndex();
static inline VkImage vFrameSwapImage();
static inline u32 *vFrameBufferCount();
static inline rRenderBuffer *vFrameRenderBuffers();
static inline void vImageTransition(VkCommandBuffer cmd, vImage *img, VkImageLayout new);
static inline void vImageTransitionLayout(VkCommandBuffer cmd, VkImage img, VkImageLayout curr, VkImageLayout new);
static inline void vImageCopyToImage(VkCommandBuffer cmd, VkImage src, VkImage dst, VkExtent2D src_ext, VkExtent2D dst_ext);
// ::Vulkan::Async::Functions::Header::
#ifdef __linux__
void *VkLoaderStart(void *thread_data);
void *vLoaderStart(void *thread_data);
#elif _WIN32
# error not yet implemented
#endif
void VkLoaderWake();
static u32 VkLoaderProcessBuffers(u32 thread_index);
static u32 VkLoaderProcessSamplers(u32 thread_index);
void vLoaderWake();
static u32 vLoaderProcessBuffers(u32 thread_index);
static u32 vLoaderProcessSamplers(u32 thread_index);
// ::Vulkan::ImmediateSubmit::Functions::Header::
static b32 BeginImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd);
static b32 FinishImmSubmit(VkDevice device, VkFence fence, VkCommandBuffer cmd, VkQueue queue);
static b32 vImmSubmitBegin(VkDevice device, VkFence fence, VkCommandBuffer cmd);
static b32 vImmSubmitFinish(VkDevice device, VkFence fence, VkCommandBuffer cmd, VkQueue queue);
// ::Vulkan::Rendering::Functions::Header::
static void BeginRendering();
static void vRenderingBegin();
// ::Vulkan::Swapchain::Functions::Header::
static void ResizeSwapchain();
static void vSwapchainResize();
// ::Vulkan::Images::Functions::Header::
static b32 CreateVkSampler(TextureBuffer *buffer);
static void UploadToImage(TextureBuffer *buffer, u8 *data, u32 thread_idx);
static b32 vSamplerCreate(rTextureBuffer *buffer);
static void vImageUpload(rTextureBuffer *buffer, u8 *data, u32 thread_idx);
// ::Vulkan::Descriptors::Functions::Header::
static void DescriptorHandlePush(DescType type, DescHandle handle);
static DescHandle DescriptorHandlePop(DescType type);
static DescAssetInfo *DescriptorTableSearch(DescType type, u64 asset_id);
static void DescriptorTableDelete(DescType type, u64 asset_id);
static void vDescHandlePush(vDescType type, rDescHandle handle);
static rDescHandle vDescHandlePop(vDescType type);
static vAssetInfo *vDescHandleSearch(vDescType type, u64 asset_id);
static void vDescHandleDelete(vDescType type, u64 asset_id);
// ::Vulkan::CleanUp::Functions::Header::
static void DestroySwapchain();
static void DestroyDrawImages();
static void vSwapchainDestroy();
static void vDrawImagesDestroy();
// ::Vulkan::Logging::Functions::Header::
static void VkInfo(const char *str);
static void VkWarn(const char *str);
static void VkError(const char *str);
static void vInfo(const char *str);
static void vWarn(const char *str);
static void vError(const char *str);
#include "vulkan_config.c"

View File

@ -1,8 +1,8 @@
// ::Vulkan::Renderer::Initialization::Functions::Start::
b32 InitRenderer(Arena *arena)
b32 rInit(Arena *arena)
{
SetRendererAvailableThreads(AvailableCPUCount());
rThreadCountSet(pCPUCountGet());
CustomizePipelines();
@ -11,54 +11,54 @@ b32 InitRenderer(Arena *arena)
void *mem = ArenaAlloc(arena, MB(8));
renderer.arena = ArenaInit(mem, MB(8));
Assert(InitVkGlobalFunctions(), "Unable to load vulkan functions");
Assert(vGlobalFunctionsInit(), "Unable to load vulkan functions");
{
VkResult result = vkCreateInstance(&inst_info, NULL, &renderer.vk.inst);
if (result != VK_SUCCESS)
{
Printfln("vkCreateInstance failure: %s", VkResultStr(result));
Printfln("vkCreateInstance failure: %s", vVkResultStr(result));
assert(false && "Failed to initialize instance");
}
}
Assert(InitVkInstanceFunctions(), "Unable to initialize instance functions");
Assert(vInstanceFunctionsInit(), "Unable to initialize instance functions");
#ifdef BUILD_DEBUG
{
Assert(VLayersSupported(), "DEBUG_BUILD ERROR: Validation layers are not supported");
Assert(vValidationSupported(), "DEBUG_BUILD ERROR: Validation layers are not supported");
Assert(vkCreateDebugUtilsMessengerEXT(renderer.vk.inst, &debug_msg_info, NULL, &renderer.vk.debug) == VK_SUCCESS,
"Unable to initialize debug messenger");
}
#endif
Assert(CreateSurface(), "Unable to create surface");
Assert(CreateDevice(), "Unable to create device");
Assert(vSurfaceInit(), "Unable to create surface");
Assert(vDeviceInit(), "Unable to create device");
Assert(CreateVmaAllocator(), "Unable to create VMA allocator");
Assert(CreateSwapchain(), "Unable to initialize swapchain and draw images");
Assert(CreateDrawImages(), "Unable to create draw images");
Assert(CreateFrameStructures(), "Unable to create frame structures");
Assert(CreateImmediateStructures(), "Unable to create immediate structures");
Assert(CreateDescriptors(), "Unable to initialize descriptors.");
Assert(CreatePipelines(), "Unable to initialize pipelines.");
CreateUploadQueues();
Assert(vVmaAllocatorInit(), "Unable to create VMA allocator");
Assert(vSwapchainInit(), "Unable to initialize swapchain and draw images");
Assert(vDrawImagesInit(), "Unable to create draw images");
Assert(vFrameStructuresInit(), "Unable to create frame structures");
Assert(vImmediateStructuresInit(), "Unable to create immediate structures");
Assert(vDescriptorsInit(), "Unable to initialize descriptors.");
Assert(vPipelinesInit(), "Unable to initialize pipelines.");
vUploadQueuesInit();
StartVkLoaderThreads();
vLoaderStartThreads();
ArenaFree(renderer.arena);
return true;
}
void DestroyRenderer()
void rDestroy()
{
VkDevice device = renderer.vk.device;
VkInstance instance = renderer.vk.inst;
FrameStructures data = renderer.vk.frame;
ImmediateStructures imm = renderer.vk.imm;
SwapchainStructures sc = renderer.vk.sc;
vFrameStructures data = renderer.vk.frame;
vImmediateStructures imm = renderer.vk.imm;
vSwapchainStructures sc = renderer.vk.sc;
VmaAllocator vma_alloc = renderer.vk.alloc;
VkSwapchainKHR swapchain = renderer.vk.swapchain;
PipelineStructures pipe = renderer.vk.pipe;
vPipelineStructures pipe = renderer.vk.pipe;
vkDeviceWaitIdle(device);
@ -72,9 +72,9 @@ void DestroyRenderer()
vkDestroyDescriptorPool(device, pipe.pool, NULL);
DestroyDrawImages();
vDrawImagesDestroy();
DestroySwapchain();
vSwapchainDestroy();
for (u32 i = 0; i < renderer.vk_conf.avail_threads; i++)
{
@ -120,15 +120,15 @@ void DestroyRenderer()
// ::Vulkan::Renderer::Buffers::Functions::Start::
static b32 CreateBuffer(RenderBuffer *buffer)
static b32 rBufferCreate(rRenderBuffer *buffer)
{
Assert(buffer, "CreateBuffer: RenderBuffer must not be null");
Assert(buffer->type != RENDER_BUFFER_TYPE_NONE, "CreateBuffer: RenderBuffer type must not be RENDER_BUFFER_TYPE_NONE");
Assert(buffer, "rBufferCreate: rRenderBuffer must not be null");
Assert(buffer->type != RENDER_BUFFER_TYPE_NONE, "rBufferCreate: rRenderBuffer type must not be RENDER_BUFFER_TYPE_NONE");
b32 success = true;
VkResult result;
DeviceQueues *queues = &renderer.vk.queues;
vDeviceQueues *queues = &renderer.vk.queues;
VmaAllocator alloc = renderer.vk.alloc;
VkBufferCreateInfo buffer_info = {
@ -178,7 +178,7 @@ static b32 CreateBuffer(RenderBuffer *buffer)
} break;
case RENDER_BUFFER_TYPE_NONE:
default:
Assert(false, "CreateBuffer: Unknown buffer type provided");
Assert(false, "rBufferCreate: Unknown buffer type provided");
}
if (queues->graphics != queues->transfer)
@ -191,17 +191,17 @@ static b32 CreateBuffer(RenderBuffer *buffer)
result = vmaCreateBuffer(alloc, &buffer_info, &alloc_info, &buffer->buffer, &buffer->alloc, &buffer->info);
if (result != VK_SUCCESS)
{
Printfln("vmaCreateBuffer failure: %s", VkResultStr(result));
Printfln("vmaCreateBuffer failure: %s", vVkResultStr(result));
success = false;
}
return success;
}
static b32 UploadToBuffer(RenderBuffer **buffers, rawptr *ptrs, u32 count, u32 thr_ix)
static b32 rBufferUpload(rRenderBuffer **buffers, rawptr *ptrs, u32 count, u32 thr_ix)
{
Assert(buffers, "UploadToBuffer: buffer must not be null");
Assert(ptrs, "UploadToBuffer: ptr must not be null");
Assert(buffers, "rBufferUpload: buffer must not be null");
Assert(ptrs, "rBufferUpload: ptr must not be null");
b32 success = true;
@ -211,11 +211,11 @@ static b32 UploadToBuffer(RenderBuffer **buffers, rawptr *ptrs, u32 count, u32 t
VkQueue queue = renderer.vk.queues.transfer_queue;
VmaAllocator alloc = renderer.vk.alloc;
rawptr mapped_buffers[16] = {0};
RenderBuffer staging_buffers[16] = {0};
rRenderBuffer staging_buffers[16] = {0};
u32 copy_count = 0;
b32 imm_started = success = BeginImmSubmit(device, fence, cmd);
b32 imm_started = success = vImmSubmitBegin(device, fence, cmd);
for (u32 i = 0; i < count && success; i++)
{
b32 host_visible = buffers[i]->type & HOST_VISIBLE_BUFFERS;
@ -229,7 +229,7 @@ static b32 UploadToBuffer(RenderBuffer **buffers, rawptr *ptrs, u32 count, u32 t
staging_buffers[copy_count].type = RENDER_BUFFER_TYPE_STAGING;
staging_buffers[copy_count].size = buffers[i]->size;
success = CreateBuffer(&staging_buffers[i]);
success = rBufferCreate(&staging_buffers[i]);
if (success)
{
@ -244,7 +244,7 @@ static b32 UploadToBuffer(RenderBuffer **buffers, rawptr *ptrs, u32 count, u32 t
}
}
FinishImmSubmit(device, fence, cmd, queue);
vImmSubmitFinish(device, fence, cmd, queue);
vkWaitForFences(device, 1, &fence, VK_TRUE, 999999999);
for (u32 i = 0; i < copy_count; i++)
@ -256,7 +256,7 @@ static b32 UploadToBuffer(RenderBuffer **buffers, rawptr *ptrs, u32 count, u32 t
return success;
}
static void CreateAndUploadToBuffer(RenderBuffer *buffer, rawptr ptr)
static void rBufferCreateAndUpload(rRenderBuffer *buffer, rawptr ptr)
{
TicketMutLock(&renderer.upload_queues[DESC_TYPE_BUFFER].ticket_mut);
@ -266,19 +266,19 @@ static void CreateAndUploadToBuffer(RenderBuffer *buffer, rawptr ptr)
TicketMutUnlock(&renderer.upload_queues[DESC_TYPE_BUFFER].ticket_mut);
VkLoaderWake();
vLoaderWake();
}
static DescHandle CreateAndUploadToTexture(TextureAsset asset_id)
static rDescHandle rTextureCreateAndUpload(TextureAsset asset_id)
{
DescHandle handle = 0;
rDescHandle handle = 0;
DescAssetInfo *info = DescriptorTableSearch(DESC_TYPE_SAMPLER, asset_id);
vAssetInfo *info = vDescHandleSearch(DESC_TYPE_SAMPLER, asset_id);
if (info == NULL)
{
Asset asset = AssetPackLoadTexture(asset_id);
Asset asset = apLoadTexture(asset_id);
TextureBuffer *buffer = FLMemAlloc(sizeof(TextureBuffer));
rTextureBuffer *buffer = FLMemAlloc(sizeof(rTextureBuffer));
buffer->type = TEXTURE_BUFFER_TYPE_SAMPLER;
buffer->width = asset.texture_meta.w;
buffer->height = asset.texture_meta.h;
@ -290,11 +290,11 @@ static DescHandle CreateAndUploadToTexture(TextureAsset asset_id)
renderer.upload_queues[DESC_TYPE_SAMPLER].queued_textures[job_idx] = buffer;
renderer.upload_queues[DESC_TYPE_SAMPLER].data[job_idx] = asset.bytes;
handle = DescriptorHandlePop(DESC_TYPE_SAMPLER);
handle = vDescHandlePop(DESC_TYPE_SAMPLER);
TicketMutUnlock(&renderer.upload_queues[DESC_TYPE_SAMPLER].ticket_mut);
VkLoaderWake();
vLoaderWake();
}
else
{
@ -304,7 +304,7 @@ static DescHandle CreateAndUploadToTexture(TextureAsset asset_id)
return handle;
}
static void FreeBuffers(RenderBuffer *buffers, u32 buffer_count)
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count)
{
VkDevice device = renderer.vk.device;
VmaAllocator alloc = renderer.vk.alloc;
@ -321,28 +321,28 @@ static void FreeBuffers(RenderBuffer *buffers, u32 buffer_count)
}
}
static void BindVertexBuffer(RenderBuffer *buffer)
static void rBufferBindVertex(rRenderBuffer *buffer)
{
Assert(buffer && buffer->type == RENDER_BUFFER_TYPE_VERTEX, "BindVertexBuffer: invalid buffer provided");
Assert(buffer && buffer->type == RENDER_BUFFER_TYPE_VERTEX, "rBufferBindVertex: invalid buffer provided");
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
VkDeviceSize offsets = 0;
vkCmdBindVertexBuffers(cmd, 0, 1, &buffer->buffer, &offsets);
}
static void BindIndexBuffer(RenderBuffer *buffer)
static void rBufferBindIndex(rRenderBuffer *buffer)
{
Assert(buffer && buffer->type == RENDER_BUFFER_TYPE_INDEX, "BindIndexBuffer: invalid buffer provided");
Assert(buffer && buffer->type == RENDER_BUFFER_TYPE_INDEX, "rBufferBindIndex: invalid buffer provided");
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
vkCmdBindIndexBuffer(cmd, buffer->buffer, 0, VK_INDEX_TYPE_UINT32);
}
static AssetHandle RendererLoadTexture(TextureAsset asset_id)
static rAssetHandle rTextureLoad(TextureAsset asset_id)
{
AssetHandle handle = 0;
rAssetHandle handle = 0;
return handle;
}
@ -354,12 +354,12 @@ static void WaitForBufferQueue()
while (!JobQueueCompleted(&renderer.upload_queues[DESC_TYPE_BUFFER].job_queue))
{
if (renderer.vk_conf.sleeping_threads > 0)
VkLoaderWake();
vLoaderWake();
}
}
}
static void ResetBufferQueue()
static void rBufferQueueReset()
{
for (u32 i = 0; i < DESC_TYPE_MAX; i++)
{
@ -374,26 +374,26 @@ static void ResetBufferQueue()
// ::Vulkan::Renderer::Uniforms::Functions::Start::
// ::Vulkan::Renderer::PushConstants::Functions::Start::
static void GetViewportSize(Vec2 *size)
static void rViewportSize(Vec2 *size)
{
size->x = (f32)renderer.vk.sc.extent.width;
size->y = (f32)renderer.vk.sc.extent.height;
}
static void SetGlobalUniform(ShaderGlobals *globals)
static void rGlobalUniformSet(rShaderGlobals *globals)
{
}
static void SetPushConstants(PushConst *pc)
static void rPushConstantsSet(rPushConst *pc)
{
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
vkCmdPushConstants(cmd,
renderer.vk.pipe.pipeline_layout,
VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT|VK_SHADER_STAGE_COMPUTE_BIT,
0,
sizeof(PushConst),
sizeof(rPushConst),
pc);
}
@ -404,14 +404,14 @@ static void SetPushConstants(PushConst *pc)
// ::Vulkan::Renderer::Config::Functions::Start::
static void SetRenderResolution(u32 x, u32 y)
static void rResolutionSet(u32 x, u32 y)
{
renderer.pending.render_width = x;
renderer.pending.render_height = y;
renderer.pending.resized = true;
}
static void SetRendererAvailableThreads(u32 n)
static void rThreadCountSet(u32 n)
{
renderer.vk_conf.avail_threads = n;
}
@ -422,35 +422,35 @@ static void SetRendererAvailableThreads(u32 n)
// ::Vulkan::Renderer::Rendering::Functions::Start::
b32 BeginFrame()
b32 rFrameBegin()
{
b32 success = true;
VkResult result;
if (renderer.pending.resized)
ResizeSwapchain();
vSwapchainResize();
VkDevice device = renderer.vk.device;
VkSwapchainKHR swapchain = renderer.vk.swapchain;
VkCommandBuffer cmd = GetFrameCmdBuf();
VkFence *fence = GetFrameRenderFence();
VkSemaphore sc_sem = GetFrameSwapSem();
VkSemaphore rndr_sem = GetFrameRenderSem();
VkCommandBuffer cmd = vFrameCmdBuf();
VkFence *fence = vFrameRenderFence();
VkSemaphore sc_sem = vFrameSwapSem();
VkSemaphore rndr_sem = vFrameRenderSem();
// TODO(MA): make this work with VK_PRESENT_MODE_MAILBOX_KHR and remove assignment of present mode to FIFO
result = vkWaitForFences(device, 1, fence, VK_TRUE, 1000000000);
if (result != VK_SUCCESS)
{
Printf("vkWaitForFences failure: %s", VkResultStr(result));
Printf("vkWaitForFences failure: %s", vVkResultStr(result));
success = false;
}
if (success)
{
u32 *buf_count = GetFrameBufferCount();
u32 *buf_count = vFrameBufferCount();
if (*buf_count > 0)
{
RenderBuffer *buffers = GetFrameRenderBuffers();
rRenderBuffer *buffers = vFrameRenderBuffers();
for (u32 i = 0; i < *buf_count; i++)
vmaDestroyBuffer(renderer.vk.alloc, buffers[i].buffer, buffers[i].alloc);
*buf_count = 0;
@ -459,7 +459,7 @@ b32 BeginFrame()
result = vkResetFences(device, 1, fence);
if (result != VK_SUCCESS)
{
Printf("vkResetFences failure: %s", VkResultStr(result));
Printf("vkResetFences failure: %s", vVkResultStr(result));
success = false;
}
}
@ -468,10 +468,10 @@ b32 BeginFrame()
{
result = vkAcquireNextImageKHR(device, swapchain, 1000000000, sc_sem, 0, &renderer.frame_state.img_ix);
if (result == VK_ERROR_OUT_OF_DATE_KHR)
ResizeSwapchain();
vSwapchainResize();
else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
{
Printf("vkAcquireNextImageKHR failure: %s", VkResultStr(result));
Printf("vkAcquireNextImageKHR failure: %s", vVkResultStr(result));
success = false;
}
}
@ -481,7 +481,7 @@ b32 BeginFrame()
result = vkResetCommandBuffer(cmd, 0);
if (result != VK_SUCCESS)
{
Printf("vkResetCommandBuffer failure: %s", VkResultStr(result));
Printf("vkResetCommandBuffer failure: %s", vVkResultStr(result));
success = false;
}
}
@ -497,7 +497,7 @@ b32 BeginFrame()
result = vkBeginCommandBuffer(cmd, &cmd_info);
if (result != VK_SUCCESS)
{
Printf("vkBeginCommandBuffer failure: %s", VkResultStr(result));
Printf("vkBeginCommandBuffer failure: %s", vVkResultStr(result));
success = false;
}
}
@ -515,29 +515,29 @@ b32 FinishFrame()
b32 success = true;
VkResult result;
VkCommandBuffer cmd = GetFrameCmdBuf();
VkSemaphore sc_sem = GetFrameSwapSem();
VkSemaphore rndr_sem = GetFrameRenderSem();
VkFence *fence = GetFrameRenderFence();
VkCommandBuffer cmd = vFrameCmdBuf();
VkSemaphore sc_sem = vFrameSwapSem();
VkSemaphore rndr_sem = vFrameRenderSem();
VkFence *fence = vFrameRenderFence();
VkImage curr_img = renderer.vk.sc.imgs[renderer.frame_state.img_ix];
vkCmdEndRendering(cmd);
TransitionImage(cmd, &renderer.vk.sc.draw_img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
vImageTransition(cmd, &renderer.vk.sc.draw_img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
VkExtent2D extent = {
.width = renderer.vk.sc.extent.width,
.height = renderer.vk.sc.extent.height,
};
CopyImageToImage(cmd, renderer.vk.sc.draw_img.img, curr_img, extent, extent);
vImageCopyToImage(cmd, renderer.vk.sc.draw_img.img, curr_img, extent, extent);
TransitionImageLayout(cmd, curr_img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
vImageTransitionLayout(cmd, curr_img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
result = vkEndCommandBuffer(cmd);
if (result != VK_SUCCESS)
{
Printf("vkEndCommandBuffer failure: %s", VkResultStr(result));
Printf("vkEndCommandBuffer failure: %s", vVkResultStr(result));
success = false;
}
@ -575,7 +575,7 @@ b32 FinishFrame()
result = vkQueueSubmit2(renderer.vk.queues.graphics_queue, 1, &submit_info, *fence);
if (result != VK_SUCCESS)
{
Printf("vkQueueSubmit2 failure: %s", VkResultStr(result));
Printf("vkQueueSubmit2 failure: %s", vVkResultStr(result));
success = false;
}
}
@ -593,10 +593,10 @@ b32 FinishFrame()
result = vkQueuePresentKHR(renderer.vk.queues.graphics_queue, &present_info);
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || renderer.pending.resized)
ResizeSwapchain();
vSwapchainResize();
else if (result != VK_SUCCESS)
{
Printf("vkQueuePresentKHR failure: %s", VkResultStr(result));
Printf("vkQueuePresentKHR failure: %s", vVkResultStr(result));
success = false;
}
}
@ -607,22 +607,22 @@ b32 FinishFrame()
return success;
}
static void DrawIndexed(u32 index_count, u32 instance_count)
static void rDrawIndexed(u32 index_count, u32 instance_count)
{
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
vkCmdDrawIndexed(cmd, index_count, instance_count, 0, 0, 0);
}
static void BindPipeline(PipelineHandle handle, PipelineType type)
static void rPipelineBind(rPipelineHandle handle, rPipelineType type)
{
if (!renderer.frame_state.begin_rendering)
{
BeginRendering();
vRenderingBegin();
renderer.frame_state.begin_rendering = true;
}
VkCommandBuffer cmd = GetFrameCmdBuf();
VkCommandBuffer cmd = vFrameCmdBuf();
vkCmdBindPipeline(cmd, (VkPipelineBindPoint)type, renderer.vk.pipe.pipelines[handle]);

View File

@ -23,135 +23,6 @@ typedef struct Arena Arena;
# error read_only not implemented for compiler/target
#endif
// ::SharedTypes::Enums::Header::
typedef enum KeyboardInput_e
{
KB_NONE,
KB_A,
KB_B,
KB_C,
KB_D,
KB_E,
KB_F,
KB_G,
KB_H,
KB_I,
KB_J,
KB_K,
KB_L,
KB_M,
KB_N,
KB_O,
KB_P,
KB_Q,
KB_R,
KB_S,
KB_T,
KB_U,
KB_V,
KB_W,
KB_X,
KB_Y,
KB_Z,
KB_0,
KB_1,
KB_2,
KB_3,
KB_4,
KB_5,
KB_6,
KB_7,
KB_8,
KB_9,
KB_NUM_0,
KB_NUM_1,
KB_NUM_2,
KB_NUM_3,
KB_NUM_4,
KB_NUM_5,
KB_NUM_6,
KB_NUM_7,
KB_NUM_8,
KB_NUM_9,
KB_NUM_LOCK,
KB_NUM_SLASH,
KB_NUM_STAR,
KB_NUM_MINUS,
KB_NUM_PLUS,
KB_NUM_ENTER,
KB_NUM_PERIOD,
KB_INSERT,
KB_DELETE,
KB_HOME,
KB_END,
KB_PAGE_UP,
KB_PAGE_DOWN,
KB_PRINT_SCREEN,
KB_SCROLL_LOCK,
KB_PAUSE,
KB_COMMA,
KB_PERIOD,
KB_BACK_SLASH,
KB_BACKSPACE,
KB_FORWARD_SLASH,
KB_MINUS,
KB_PLUS,
KB_F1,
KB_F2,
KB_F3,
KB_F4,
KB_F5,
KB_F6,
KB_F7,
KB_F8,
KB_F9,
KB_F10,
KB_F11,
KB_F12,
KB_UP,
KB_DOWN,
KB_LEFT,
KB_RIGHT,
KB_LEFT_CTRL,
KB_LEFT_ALT,
KB_LEFT_SHIFT,
KB_TAB,
KB_CAPS_LOCK,
KB_LEFT_SUPER,
KB_RIGHT_CTRL,
KB_RIGHT_ALT,
KB_RIGHT_SUPER,
KB_RIGHT_SHIFT,
KB_ENTER,
KB_TILDE,
KB_ESC,
KB_SEMICOLON,
KB_QUOTE,
KB_LEFT_BRACE,
KB_RIGHT_BRACE,
KB_BACK_SPACE,
KB_SPACE,
KB_MAX
} KeyboardInput;
typedef enum MouseInput_e
{
M_NONE,
M_LEFT_CLICK,
M_MIDDLE_CLICK,
M_RIGHT_CLICK,
} MouseInput;
typedef enum GameInputType_e
{
GI_KEYBOARD,
GI_MOUSE,
GI_MOTION,
GI_GAMEPAD,
} GameInputType;
// ::SharedTypes::Types::Header::
typedef int8_t i8;
@ -196,6 +67,7 @@ typedef int64_t isize;
typedef uint64_t usize;
#elif defined ( _WIN32 )
typedef int32_t isize;
typedef uint32_t usize;
@ -223,6 +95,13 @@ typedef union
struct { f32 r, g, b, a; };
} Vec4;
typedef union
{
struct { u16 x, y; };
struct { u16 r, g; };
struct { u16 w, h; };
} u16Vec2;
typedef union
{
struct { i32 x, y; };
@ -241,6 +120,13 @@ typedef union
struct { i32 r, g, b, a; };
} iVec4;
typedef union
{
struct { i16 x, y; };
struct { i16 r, g; };
struct { i16 w, h; };
} i16Vec2;
typedef f32 Mat2[4];
typedef f32 Mat3[9];
typedef f32 Mat4[16];
@ -249,38 +135,3 @@ typedef f64 dMat2[4];
typedef f64 dMat3[9];
typedef f64 dMat4[16];
typedef struct MouseMotionEvent
{
i16 x;
i16 y;
} MouseMotionEvent;
typedef struct GameInput
{
union
{
KeyboardInput kb_code;
MouseInput m_code;
MouseMotionEvent motion_ev;
};
b8 pressed;
GameInputType type;
} GameInput; // TODO: add gamepad input
typedef struct GUIVertex
{
Vec2 p0;
Vec2 p1;
Vec4 col;
u32 tex_idx;
} GUIVertex;
typedef struct GUIContext
{
GUIVertex *vertices;
u32 vertices_len;
u32 *indices;
u32 indices_len;
u32 instance_count;
b8 has_grabbed;
} GUIContext;

View File

@ -223,7 +223,7 @@ i32 EPrintf(char *fmt, ...)
i32 EPrint(void *str)
{
return WriteStdErr(str, (isize)StrLen(str));
return pWriteStdErr(str, (isize)StrLen(str));
}
i32 _EPrintf(char *fmt, va_list arg)
@ -247,7 +247,7 @@ i32 _Printf(char *fmt, va_list arg)
if (sprf_res < 0)
pr_res = sprf_res;
else
pr_res = WriteStdOut(&buffer, sprf_res);
pr_res = pWriteStdOut(&buffer, sprf_res);
return pr_res;
}
@ -267,7 +267,7 @@ i32 _Printfln(char *fmt, va_list arg)
{
buffer[sprf_res] = '\n';
buffer[sprf_res+1] = '\0';
pr_res = WriteStdOut(&buffer, sprf_res+1);
pr_res = pWriteStdOut(&buffer, sprf_res+1);
}
return pr_res;
@ -283,12 +283,12 @@ static inline void StartProfileBlock(ProfileBlock *block, c8 *label, u32 anchor_
{
block->anchor_index = anchor_index;
block->label = label;
block->start_tsc = ReadCPUTimer();
block->start_tsc = pCPUTimerRead();
}
static inline void EndProfileBlock(ProfileBlock *block)
{
u64 elapsed = ReadCPUTimer() - block->start_tsc;
u64 elapsed = pCPUTimerRead() - block->start_tsc;
ProfileAnchor *anchor = GLOBAL_PROFILER.anchors + block->anchor_index;
anchor->tsc_elapsed += elapsed;
@ -305,57 +305,57 @@ static inline void EndProfileBlock(ProfileBlock *block)
static inline b32 MutTryLock(Mut *mut)
{
b32 lock = false;
return AtomicCompareExchangeb32(&mut->lock, &lock, 1);
return pb32AtomicCompareExchange(&mut->lock, &lock, 1);
}
static inline void MutUnlock(Mut *mut)
{
AtomicStoreb32(&mut->lock, 0);
pb32AtomicStore(&mut->lock, 0);
}
static inline void TicketMutLock(TicketMut *mut)
{
u32 ticket = AtomicFetchIncru32(&mut->ticket);
u32 ticket = pu32AtomicFetchIncr(&mut->ticket);
while (ticket != mut->next_ticket);
}
static inline void TicketMutUnlock(TicketMut *mut)
{
AtomicIncru32(&mut->next_ticket);
pu32AtomicIncr(&mut->next_ticket);
}
static inline u32 JobQueueAdd(JobQueue *queue, u32 count)
{
u32 job_idx = AtomicFetchIncru32(&queue->queued);
AtomicFetchIncru32(&queue->remaining);
u32 job_idx = pu32AtomicFetchIncr(&queue->queued);
pu32AtomicFetchIncr(&queue->remaining);
return job_idx;
}
static inline u32 JobQueueGetCount(JobQueue *queue)
{
return AtomicLoadu32(&queue->queued);
return pu32AtomicLoad(&queue->queued);
}
static inline void JobQueueMarkUnqueued(JobQueue *queue, u32 count)
{
AtomicFetchSubu32(&queue->queued, count);
pu32AtomicFetchSub(&queue->queued, count);
}
static inline void JobQueueMarkCompleted(JobQueue *queue, u32 count)
{
AtomicFetchSubu32(&queue->remaining, count);
pu32AtomicFetchSub(&queue->remaining, count);
}
static inline void JobQueueReset(JobQueue *queue)
{
AtomicFetchSubu32(&queue->queued, queue->queued);
AtomicFetchSubu32(&queue->remaining, queue->remaining);
pu32AtomicFetchSub(&queue->queued, queue->queued);
pu32AtomicFetchSub(&queue->remaining, queue->remaining);
}
static inline b32 JobQueueCompleted(JobQueue *queue)
{
u32 remaining = AtomicLoadu32(&queue->remaining);
u32 remaining = pu32AtomicLoad(&queue->remaining);
return remaining == 0;
}

View File

@ -61,7 +61,7 @@ static VkDebugUtilsMessengerCreateInfoEXT debug_msg_info = {
.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
.pfnUserCallback = (PFN_vkDebugUtilsMessengerCallbackEXT)DebugCallback,
.pfnUserCallback = (PFN_vkDebugUtilsMessengerCallbackEXT)vDebugCallback,
};
#endif
@ -286,7 +286,7 @@ static VkDescriptorSetAllocateInfo set_allocate_info = {
static VkPushConstantRange push_const_range = {
.offset = 0,
.size = sizeof(PushConst),
.size = sizeof(rPushConst),
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_VERTEX_BIT,
};
@ -423,15 +423,15 @@ INIT_PIPELINE_DEFAULTS(gui);
VkVertexInputBindingDescription gui_input_bind_desc = {
.binding = 0,
.stride = sizeof(GUIVertex),
.stride = sizeof(rUIVertex),
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
};
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(GUIVertex, p1) },
{ .binding = 0, .location = 2, .format = VK_FORMAT_R32G32B32A32_SFLOAT, .offset = offsetof(GUIVertex, col) },
{ .binding = 0, .location = 3, .format = VK_FORMAT_R32_UINT, .offset = offsetof(GUIVertex, tex_idx) },
{ .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 = {