clean up
This commit is contained in:
parent
281bf66ef6
commit
cf517e0c50
@ -67,6 +67,7 @@ static Arena *ArenaCreateDebug(usize size, u32 init_line_no)
|
|||||||
return ArenaInitDebug(mem, size, init_line_no);
|
return ArenaInitDebug(mem, size, init_line_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: investigate overflows when out of memory because something bad is going on
|
||||||
static rawptr ArenaAllocAlign(Arena *arena, usize size, usize align)
|
static rawptr ArenaAllocAlign(Arena *arena, usize size, usize align)
|
||||||
{
|
{
|
||||||
rawptr ptr = NULL;
|
rawptr ptr = NULL;
|
||||||
|
|||||||
@ -55,20 +55,14 @@ static void gRunCycle(gGameCtx *ctx, pGameInput *inputs, u32 i_count)
|
|||||||
{
|
{
|
||||||
ArenaFree(vFrameArena());
|
ArenaFree(vFrameArena());
|
||||||
|
|
||||||
rBufferQueueReset();
|
|
||||||
|
|
||||||
gPrepareGUICtx(ctx);
|
gPrepareGUICtx(ctx);
|
||||||
|
|
||||||
gHandleInputs(inputs, i_count);
|
gHandleInputs(inputs, i_count);
|
||||||
|
|
||||||
rFrameBegin();
|
rFrameBegin();
|
||||||
|
|
||||||
|
|
||||||
// This is fucked up, it's triggering before even being set
|
|
||||||
vTextureCleanUp();
|
vTextureCleanUp();
|
||||||
|
|
||||||
Printfln("post clean up");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (gButton(ctx, "Show 2", 150.0f, 150.0f, 200.0f, 200.0f))
|
if (gButton(ctx, "Show 2", 150.0f, 150.0f, 200.0f, 200.0f))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,8 +2,3 @@
|
|||||||
#include "renderer_vulkan.c"
|
#include "renderer_vulkan.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if STG_DX11_RENDERER && __linux__
|
|
||||||
#include "renderer_d3d11.c"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
@ -102,12 +102,10 @@ void rDestroy();
|
|||||||
// ::Renderer::Buffers::Header::
|
// ::Renderer::Buffers::Header::
|
||||||
|
|
||||||
static b32 rBufferMap();
|
static b32 rBufferMap();
|
||||||
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count);
|
|
||||||
static rDescHandle rTextureLoad(TextureAsset asset_id);
|
static rDescHandle rTextureLoad(TextureAsset asset_id);
|
||||||
static void rTextureUnload(rDescHandle handle);
|
static void rTextureUnload(rDescHandle handle);
|
||||||
static void rBufferBindVertex(rRenderBuffer *buffer);
|
static void rBufferBindVertex(rRenderBuffer *buffer);
|
||||||
static void rBufferBindIndex(rRenderBuffer *buffer);
|
static void rBufferBindIndex(rRenderBuffer *buffer);
|
||||||
static void rBufferQueueReset();
|
|
||||||
static rawptr rBufferGUIVertMapping();
|
static rawptr rBufferGUIVertMapping();
|
||||||
static rawptr rBufferGUIIdxMapping();
|
static rawptr rBufferGUIIdxMapping();
|
||||||
static void rBufferBindGUIVertex();
|
static void rBufferBindGUIVertex();
|
||||||
@ -136,7 +134,3 @@ static void rPipelineBind(rPipelineHandle handle, rPipelineType type);
|
|||||||
#if STG_VULKAN_RENDERER
|
#if STG_VULKAN_RENDERER
|
||||||
#include "renderer_vulkan.h"
|
#include "renderer_vulkan.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if STG_DX11_RENDERER && __linux__
|
|
||||||
#include "renderer_d3d11.h"
|
|
||||||
#endif
|
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
b32 _InitRenderer(Arena *arena)
|
|
||||||
{
|
|
||||||
ID3D11Device *device;
|
|
||||||
ID3D11DeviceContext *ctx;
|
|
||||||
|
|
||||||
D3D_FEATURE_LEVEL levels[] = { D3D_FEATURE_LEVEL_11_0 };
|
|
||||||
HRESULT hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, levels, Len(levels), D3D11_SDK_VERSION, &device, NULL, &ctx);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _DestroyRenderer()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
b32 _BeginFrame()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
b32 _DrawTriangle()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
b32 _FinishFrame()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _SetRenderResolution(u32 x, u32 y)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DrawGUI(gUICtx *ctx)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include "d3d11.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
b32 _InitRenderer(Arena *arena);
|
|
||||||
void _DestroyRenderer();
|
|
||||||
b32 _BeginFrame();
|
|
||||||
b32 _DrawTriangle();
|
|
||||||
b32 _FinishFrame();
|
|
||||||
void _SetRenderResolution(u32 x, u32 y);
|
|
||||||
static void DrawGUI(gUICtx *ctx);
|
|
||||||
@ -337,7 +337,29 @@ static void vSwapchainResize()
|
|||||||
|
|
||||||
// ::Vulkan::Images::Functions::Start::
|
// ::Vulkan::Images::Functions::Start::
|
||||||
|
|
||||||
static b32 vImageViewCreate(vImageView *view, u32 width, u32 height, u32 channels)
|
static vImageView *vImageViewCreate(TextureAssetMeta meta)
|
||||||
|
{
|
||||||
|
vImageView *view = FLMemAlloc(sizeof(vImageView));
|
||||||
|
Assert(vImageViewInit(view, meta.w, meta.h, meta.ch), "vImageViewCreate failure: vImage");
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
static vTransfer *vTextureTransferInit(Arena *arena, u32 asset_id, VkImage image, u8 *bytes, TextureAssetMeta *meta)
|
||||||
|
{
|
||||||
|
vTransfer *transfer = MakeArray(arena, vTransfer, 1);
|
||||||
|
|
||||||
|
transfer->type = vTT_IMAGE;
|
||||||
|
transfer->data = bytes;
|
||||||
|
transfer->w = meta->w;
|
||||||
|
transfer->h = meta->h;
|
||||||
|
transfer->ch = meta->ch;
|
||||||
|
transfer->asset_id = asset_id;
|
||||||
|
transfer->image = image;
|
||||||
|
|
||||||
|
return transfer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static b32 vImageViewInit(vImageView *view, u32 width, u32 height, u32 channels)
|
||||||
{
|
{
|
||||||
b32 success = true;
|
b32 success = true;
|
||||||
|
|
||||||
@ -375,7 +397,7 @@ static b32 vImageViewCreate(vImageView *view, u32 width, u32 height, u32 channel
|
|||||||
&view->image.image, &view->image.alloc, NULL);
|
&view->image.image, &view->image.alloc, NULL);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
Printfln("vImageViewCreate error: vmaCreateImage failure: %s", vVkResultStr(result));
|
Printfln("vImageViewInit error: vmaCreateImage failure: %s", vVkResultStr(result));
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +416,7 @@ static b32 vImageViewCreate(vImageView *view, u32 width, u32 height, u32 channel
|
|||||||
result = vkCreateImageView(v_Renderer.handles.device, &view_info, NULL, &view->view);
|
result = vkCreateImageView(v_Renderer.handles.device, &view_info, NULL, &view->view);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
Printfln("vImageViewCreate error: vkCreateImageView failure: %s", vVkResultStr(result));
|
Printfln("vImageViewInit error: vkCreateImageView failure: %s", vVkResultStr(result));
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,19 +430,14 @@ static void vTextureCleanUp()
|
|||||||
HashTable *table = &v_Renderer.buffers.images;
|
HashTable *table = &v_Renderer.buffers.images;
|
||||||
b8 *queue = vFrameTexDestroyQueue();
|
b8 *queue = vFrameTexDestroyQueue();
|
||||||
|
|
||||||
Printfln("frame: %llu", v_Renderer.state.renderer.frame_count);
|
|
||||||
|
|
||||||
// NOTE: might need a mutex here at some point, check if crashes related to image access
|
// NOTE: might need a mutex here at some point, check if crashes related to image access
|
||||||
for (u64 i = 0; i < TEXTURE_ASSET_MAX; i++)
|
for (u64 i = 0; i < TEXTURE_ASSET_MAX; i++)
|
||||||
{
|
{
|
||||||
if (queue[i])
|
if (queue[i])
|
||||||
{
|
{
|
||||||
Printfln("fetching handle for id: %llu", i);
|
|
||||||
|
|
||||||
rDescHandle handle = vDescHandlePop(vDT_SAMPLED_IMAGE, (u32)i);
|
rDescHandle handle = vDescHandlePop(vDT_SAMPLED_IMAGE, (u32)i);
|
||||||
vDescIndexPush(vDT_SAMPLED_IMAGE, handle.desc_index);
|
vDescIndexPush(vDT_SAMPLED_IMAGE, handle.desc_index);
|
||||||
|
|
||||||
Printfln("queue %llu %d", i, queue[i]);
|
|
||||||
vImageView *view = vImagePop(i);
|
vImageView *view = vImagePop(i);
|
||||||
Assert(view != NULL, "rTextureUnload failure: value not in hash table");
|
Assert(view != NULL, "rTextureUnload failure: value not in hash table");
|
||||||
|
|
||||||
@ -443,7 +460,6 @@ static void vImagePush(TextureAsset asset_id, vImageView *view)
|
|||||||
|
|
||||||
static vImageView *vImagePop(TextureAsset asset_id)
|
static vImageView *vImagePop(TextureAsset asset_id)
|
||||||
{
|
{
|
||||||
Printfln("popping id: %llu", asset_id);
|
|
||||||
return (vImageView *)HashTableDeleteU64Rawptr(&v_Renderer.buffers.images, asset_id);
|
return (vImageView *)HashTableDeleteU64Rawptr(&v_Renderer.buffers.images, asset_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,6 +484,13 @@ static vImageView *vImageSearch(TextureAsset asset_id)
|
|||||||
|
|
||||||
// ::Vulkan::Descriptors::Functions::Start::
|
// ::Vulkan::Descriptors::Functions::Start::
|
||||||
|
|
||||||
|
|
||||||
|
static void vDescPushImageAndHandle(rDescHandle handle, vImageView *view)
|
||||||
|
{
|
||||||
|
vDescHandlePush(vDT_SAMPLED_IMAGE, handle);
|
||||||
|
vImagePush(handle.asset_id, view);
|
||||||
|
}
|
||||||
|
|
||||||
static u32 vDescPushImage(vImageView *view)
|
static u32 vDescPushImage(vImageView *view)
|
||||||
{
|
{
|
||||||
u32 index = vDescIndexPop(vDT_SAMPLED_IMAGE);
|
u32 index = vDescIndexPop(vDT_SAMPLED_IMAGE);
|
||||||
@ -518,8 +541,6 @@ static rDescHandle vDescHandleSearch(vDescType type, u32 asset_id)
|
|||||||
.asset_id = UINT32_MAX,
|
.asset_id = UINT32_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
Printfln("search asset_id: %llu", asset_id);
|
|
||||||
|
|
||||||
HashTable *table = &v_Renderer.desc_bindings[type].lookup_table;
|
HashTable *table = &v_Renderer.desc_bindings[type].lookup_table;
|
||||||
|
|
||||||
KeyValuePair *kv_pair = HashTableSearchU64(table, asset_id);
|
KeyValuePair *kv_pair = HashTableSearchU64(table, asset_id);
|
||||||
|
|||||||
@ -535,7 +535,9 @@ static void vSwapchainResize();
|
|||||||
|
|
||||||
// ::Vulkan::Images::Functions::Header::
|
// ::Vulkan::Images::Functions::Header::
|
||||||
|
|
||||||
static b32 vImageViewCreate(vImageView *view, u32 width, u32 height, u32 channels);
|
static vTransfer *vTextureTransferInit(Arena *arena, u32 asset_id, VkImage image, u8 *bytes, TextureAssetMeta *meta);
|
||||||
|
static vImageView *vImageViewCreate(TextureAssetMeta meta);
|
||||||
|
static b32 vImageViewInit(vImageView *view, u32 width, u32 height, u32 channels);
|
||||||
static void vTextureCleanUp();
|
static void vTextureCleanUp();
|
||||||
static void vImagePush(TextureAsset asset_id, vImageView *view);
|
static void vImagePush(TextureAsset asset_id, vImageView *view);
|
||||||
static vImageView *vImagePop(TextureAsset asset_id);
|
static vImageView *vImagePop(TextureAsset asset_id);
|
||||||
@ -543,6 +545,7 @@ static vImageView *vImageSearch(TextureAsset asset_id);
|
|||||||
|
|
||||||
// ::Vulkan::Descriptors::Functions::Header::
|
// ::Vulkan::Descriptors::Functions::Header::
|
||||||
|
|
||||||
|
static void vDescPushImageAndHandle(rDescHandle handle, vImageView *view);
|
||||||
static void vDescIndexPush(vDescType type, u32 index);
|
static void vDescIndexPush(vDescType type, u32 index);
|
||||||
static u32 vDescIndexPop(vDescType type);
|
static u32 vDescIndexPop(vDescType type);
|
||||||
static rDescHandle vDescHandleSearch(vDescType type, u32 asset_id);
|
static rDescHandle vDescHandleSearch(vDescType type, u32 asset_id);
|
||||||
|
|||||||
@ -131,32 +131,17 @@ static rDescHandle rTextureLoad(TextureAsset asset_id)
|
|||||||
TextureAssetMeta meta = apGetTextureMeta(asset_id);
|
TextureAssetMeta meta = apGetTextureMeta(asset_id);
|
||||||
|
|
||||||
// TODO: handle errors instead of failing
|
// TODO: handle errors instead of failing
|
||||||
Assert(vImageViewCreate(view, meta.w, meta.h, meta.ch), "rTextureLoad failure: vImageViewCreate failed");
|
Assert(vImageViewInit(view, meta.w, meta.h, meta.ch), "rTextureLoad failure: vImageViewInit failed");
|
||||||
|
|
||||||
Printfln("Loading asset: %llu", asset_id);
|
|
||||||
handle.asset_id = asset_id;
|
handle.asset_id = asset_id;
|
||||||
handle.desc_index = vDescPushImage(view);
|
handle.desc_index = vDescPushImage(view);
|
||||||
|
|
||||||
TicketMutLock(&v_Renderer.upload.mut);
|
TicketMutLock(&v_Renderer.upload.mut);
|
||||||
|
|
||||||
Arena *arena = vFrameArena();
|
vTransfer *transfer = vTextureTransferInit(vFrameArena(), asset_id, view->image.image, asset.bytes, &meta);
|
||||||
|
|
||||||
vTransfer *transfer = MakeArray(arena, vTransfer, 1);
|
|
||||||
|
|
||||||
transfer->type = vTT_IMAGE;
|
|
||||||
transfer->data = asset.bytes;
|
|
||||||
transfer->w = meta.w;
|
|
||||||
transfer->h = meta.h;
|
|
||||||
transfer->ch = meta.ch;
|
|
||||||
transfer->asset_id = asset_id;
|
|
||||||
transfer->image = view->image.image;
|
|
||||||
|
|
||||||
u32 job_idx = JobQueueAdd(&v_Renderer.upload.job_queue, 1);
|
u32 job_idx = JobQueueAdd(&v_Renderer.upload.job_queue, 1);
|
||||||
|
|
||||||
v_Renderer.upload.transfers[job_idx] = transfer;
|
v_Renderer.upload.transfers[job_idx] = transfer;
|
||||||
|
vDescPushImageAndHandle(handle, view);
|
||||||
vDescHandlePush(vDT_SAMPLED_IMAGE, handle);
|
|
||||||
vImagePush(asset_id, view);
|
|
||||||
|
|
||||||
TicketMutUnlock(&v_Renderer.upload.mut);
|
TicketMutUnlock(&v_Renderer.upload.mut);
|
||||||
|
|
||||||
@ -178,20 +163,6 @@ static void rTextureUnload(rDescHandle current_handle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rBufferFree(rRenderBuffer *buffers, u32 buffer_count)
|
|
||||||
{
|
|
||||||
VkDevice device = v_Renderer.handles.device;
|
|
||||||
VmaAllocator alloc = v_Renderer.handles.vma_alloc;
|
|
||||||
u32 frame_index = vFrameIndex();
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: replace it
|
|
||||||
//for (u32 i = 0; i < buffer_count; i++)
|
|
||||||
//{
|
|
||||||
// *buf_count += 1;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rBufferBindVertex(rRenderBuffer *buffer)
|
static void rBufferBindVertex(rRenderBuffer *buffer)
|
||||||
{
|
{
|
||||||
Assert(buffer && buffer->type == rRBT_VERTEX, "rBufferBindVertex: invalid buffer provided");
|
Assert(buffer && buffer->type == rRBT_VERTEX, "rBufferBindVertex: invalid buffer provided");
|
||||||
@ -220,15 +191,6 @@ static void vBufferQueueWait()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rBufferQueueReset()
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i < vDT_MAX; i++)
|
|
||||||
{
|
|
||||||
// TODO: replace
|
|
||||||
//JobQueueReset(&renderer.upload_queues[i].job_queue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static rawptr rBufferGUIVertMapping()
|
static rawptr rBufferGUIVertMapping()
|
||||||
{
|
{
|
||||||
return v_Renderer.buffers.gui_vert.ptr;
|
return v_Renderer.buffers.gui_vert.ptr;
|
||||||
@ -333,18 +295,6 @@ b32 rFrameBegin()
|
|||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// TODO: replace
|
|
||||||
/*
|
|
||||||
u32 *buf_count = vFrameBufferCount();
|
|
||||||
if (*buf_count > 0)
|
|
||||||
{
|
|
||||||
rRenderBuffer *buffers = vFrameRenderBuffers();
|
|
||||||
for (u32 i = 0; i < *buf_count; i++)
|
|
||||||
vmaDestroyBuffer(v_Renderer.handles.vma_alloc, buffers[i].buffer, buffers[i].alloc);
|
|
||||||
*buf_count = 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
result = vkResetFences(device, 1, &fence);
|
result = vkResetFences(device, 1, &fence);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user