Skip to content

Commit

Permalink
refac: move graphics ext handles to 16 bit indices
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Nov 4, 2024
1 parent 360d455 commit 39f0263
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 192 deletions.
2 changes: 1 addition & 1 deletion examples/example_9.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pl_app_update(plAppData* ptAppData)
camera_update(ptCamera);

// add full screen quad for offscreen render
gptDraw->add_image(ptAppData->ptFGLayer, ptAppData->atColorTextureBg[uCurrentFrameIndex].ulData, (plVec2){0}, ptIO->tMainViewportSize);
gptDraw->add_image(ptAppData->ptFGLayer, ptAppData->atColorTextureBg[uCurrentFrameIndex].uData, (plVec2){0}, ptIO->tMainViewportSize);

// 3d drawing API usage
const plMat4 tOrigin = pl_identity_mat4();
Expand Down
10 changes: 6 additions & 4 deletions extensions/pl_draw_backend_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ pl_build_font_atlas_backend(plCommandBuffer* ptCommandBuffer, plFontAtlas* ptAtl

plTexture* ptTexture = NULL;
plTextureHandle tTexture = gptGfx->create_texture(ptDevice, &tFontTextureDesc, &ptTexture);
ptAtlas->ptUserData = (void*)tTexture.ulData;
uint64_t ulData = (uint64_t)tTexture.uData;
ptAtlas->ptUserData = (void*)ulData;

const plDeviceMemoryAllocation tAllocation = gptGfx->allocate_memory(ptDevice,
ptTexture->tMemoryRequirements.ulSize,
Expand Down Expand Up @@ -267,7 +268,7 @@ pl_build_font_atlas_backend(plCommandBuffer* ptCommandBuffer, plFontAtlas* ptAtl
gptGfx->submit_command_buffer(ptCommandBuffer, NULL);
gptGfx->wait_on_command_buffer(ptCommandBuffer);

ptAtlas->tTexture = pl_create_bind_group_for_texture(tTexture).ulData;
ptAtlas->tTexture = pl_create_bind_group_for_texture(tTexture).uData;

gptGfx->destroy_buffer(ptDevice, tStagingBuffer);
return true;
Expand All @@ -279,7 +280,8 @@ pl_cleanup_font_atlas_backend(plFontAtlas* ptAtlas)
if(ptAtlas == NULL)
ptAtlas = gptDraw->get_current_font_atlas();

plTextureHandle tTexture = {.ulData = (uint64_t)ptAtlas->ptUserData};
uint64_t ulData = (uint64_t)ptAtlas->ptUserData;
plTextureHandle tTexture = {.uData = (uint32_t)ulData};
gptGfx->destroy_texture(gptDrawBackendCtx->ptDevice, tTexture);

gptDraw->cleanup_font_atlas(ptAtlas);
Expand Down Expand Up @@ -758,7 +760,7 @@ pl_submit_2d_drawlist(plDrawList2D* ptDrawlist, plRenderEncoder* ptEncoder, floa
gptGfx->set_scissor_region(ptEncoder, &tScissor);
}

plBindGroupHandle tTexture = {.ulData = cmd.tTextureId};
plBindGroupHandle tTexture = {.uData = cmd.tTextureId};
plBindGroupHandle atBindGroups[] = {
gptDrawBackendCtx->tFontSamplerBindGroup,
tTexture
Expand Down
2 changes: 1 addition & 1 deletion extensions/pl_draw_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef int plDrawRectFlags; // -> enum _plDrawRectFlags // Flags:

// backend texture type
#ifndef plTextureID
typedef uint64_t plTextureID;
typedef uint32_t plTextureID;
#endif

//-----------------------------------------------------------------------------
Expand Down
44 changes: 25 additions & 19 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,14 @@ pl_draw_stream_cleanup(plDrawStream* ptStream)
static void
pl_draw_stream_reset(plDrawStream* ptStream, uint32_t uDrawCount)
{
memset(&ptStream->_tCurrentDraw, 255, sizeof(plDrawStreamData));
ptStream->_tCurrentDraw.uIndexBuffer = UINT32_MAX - 1;
ptStream->_tCurrentDraw.uDynamicBufferOffset0 = 0;
memset(&ptStream->_tCurrentDraw, 0, sizeof(plDrawStreamData));
ptStream->_uStreamCount = 0;
ptStream->_tCurrentDraw.auDynamicBuffers[0] = UINT16_MAX;
ptStream->_tCurrentDraw.uIndexOffset = UINT32_MAX;
ptStream->_tCurrentDraw.uVertexOffset = UINT32_MAX;
ptStream->_tCurrentDraw.uInstanceOffset = UINT32_MAX;
ptStream->_tCurrentDraw.uInstanceCount = UINT32_MAX;
ptStream->_tCurrentDraw.uTriangleCount = UINT32_MAX;

if(uDrawCount * 13 > ptStream->_uStreamCapacity)
{
Expand Down Expand Up @@ -349,6 +353,8 @@ pl__cleanup_common_device(plDevice* ptDevice)
pl_sb_free(ptDevice->sbtBindGroupFreeIndices);
pl_sb_free(ptDevice->sbtSamplerFreeIndices);
pl_sb_free(ptDevice->sbtComputeShaderFreeIndices);
pl_sb_free(ptDevice->sbtRenderPassLayoutFreeIndices);
pl_sb_free(ptDevice->sbtRenderPassFreeIndices);

plTimelineSemaphore* ptCurrentSemaphore = ptDevice->ptSemaphoreFreeList;
while(ptCurrentSemaphore)
Expand Down Expand Up @@ -379,14 +385,14 @@ pl__cleanup_common_device(plDevice* ptDevice)
static plBufferHandle
pl__get_new_buffer_handle(plDevice* ptDevice)
{
uint32_t uBufferIndex = UINT32_MAX;
uint32_t uBufferIndex = 0;
if(pl_sb_size(ptDevice->sbtBufferFreeIndices) > 0)
uBufferIndex = pl_sb_pop(ptDevice->sbtBufferFreeIndices);
else
{
uBufferIndex = pl_sb_size(ptDevice->sbtBuffersCold);
pl_sb_add(ptDevice->sbtBuffersCold);
pl_sb_back(ptDevice->sbtBuffersCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtBuffersCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtBuffersHot);
}

Expand All @@ -400,14 +406,14 @@ pl__get_new_buffer_handle(plDevice* ptDevice)
static plTextureHandle
pl__get_new_texture_handle(plDevice* ptDevice)
{
uint32_t uTextureIndex = UINT32_MAX;
uint32_t uTextureIndex = 0;
if(pl_sb_size(ptDevice->sbtTextureFreeIndices) > 0)
uTextureIndex = pl_sb_pop(ptDevice->sbtTextureFreeIndices);
else
{
uTextureIndex = pl_sb_size(ptDevice->sbtTexturesCold);
pl_sb_add(ptDevice->sbtTexturesCold);
pl_sb_back(ptDevice->sbtTexturesCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtTexturesCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtTexturesHot);
}

Expand All @@ -421,14 +427,14 @@ pl__get_new_texture_handle(plDevice* ptDevice)
static plSamplerHandle
pl__get_new_sampler_handle(plDevice* ptDevice)
{
uint32_t uResourceIndex = UINT32_MAX;
uint32_t uResourceIndex = 0;
if(pl_sb_size(ptDevice->sbtSamplerFreeIndices) > 0)
uResourceIndex = pl_sb_pop(ptDevice->sbtSamplerFreeIndices);
else
{
uResourceIndex = pl_sb_size(ptDevice->sbtSamplersCold);
pl_sb_add(ptDevice->sbtSamplersCold);
pl_sb_back(ptDevice->sbtSamplersCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtSamplersCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtSamplersHot);
}

Expand All @@ -442,14 +448,14 @@ pl__get_new_sampler_handle(plDevice* ptDevice)
static plBindGroupHandle
pl__get_new_bind_group_handle(plDevice* ptDevice)
{
uint32_t uBindGroupIndex = UINT32_MAX;
uint32_t uBindGroupIndex = 0;
if(pl_sb_size(ptDevice->sbtBindGroupFreeIndices) > 0)
uBindGroupIndex = pl_sb_pop(ptDevice->sbtBindGroupFreeIndices);
else
{
uBindGroupIndex = pl_sb_size(ptDevice->sbtBindGroupsCold);
pl_sb_add(ptDevice->sbtBindGroupsCold);
pl_sb_back(ptDevice->sbtBindGroupsCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtBindGroupsCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtBindGroupsHot);
}

Expand All @@ -463,14 +469,14 @@ pl__get_new_bind_group_handle(plDevice* ptDevice)
static plShaderHandle
pl__get_new_shader_handle(plDevice* ptDevice)
{
uint32_t uResourceIndex = UINT32_MAX;
uint32_t uResourceIndex = 0;
if(pl_sb_size(ptDevice->sbtShaderFreeIndices) > 0)
uResourceIndex = pl_sb_pop(ptDevice->sbtShaderFreeIndices);
else
{
uResourceIndex = pl_sb_size(ptDevice->sbtShadersCold);
pl_sb_add(ptDevice->sbtShadersCold);
pl_sb_back(ptDevice->sbtShadersCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtShadersCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtShadersHot);
}

Expand All @@ -484,14 +490,14 @@ pl__get_new_shader_handle(plDevice* ptDevice)
static plComputeShaderHandle
pl__get_new_compute_shader_handle(plDevice* ptDevice)
{
uint32_t uResourceIndex = UINT32_MAX;
uint32_t uResourceIndex = 0;
if(pl_sb_size(ptDevice->sbtComputeShaderFreeIndices) > 0)
uResourceIndex = pl_sb_pop(ptDevice->sbtComputeShaderFreeIndices);
else
{
uResourceIndex = pl_sb_size(ptDevice->sbtComputeShadersCold);
pl_sb_add(ptDevice->sbtComputeShadersCold);
pl_sb_back(ptDevice->sbtComputeShadersCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtComputeShadersCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtComputeShadersHot);
}

Expand All @@ -505,14 +511,14 @@ pl__get_new_compute_shader_handle(plDevice* ptDevice)
static plRenderPassHandle
pl__get_new_render_pass_handle(plDevice* ptDevice)
{
uint32_t uResourceIndex = UINT32_MAX;
uint32_t uResourceIndex = 0;
if(pl_sb_size(ptDevice->sbtRenderPassFreeIndices) > 0)
uResourceIndex = pl_sb_pop(ptDevice->sbtRenderPassFreeIndices);
else
{
uResourceIndex = pl_sb_size(ptDevice->sbtRenderPassesCold);
pl_sb_add(ptDevice->sbtRenderPassesCold);
pl_sb_back(ptDevice->sbtRenderPassesCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtRenderPassesCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtRenderPassesHot);
}

Expand All @@ -526,14 +532,14 @@ pl__get_new_render_pass_handle(plDevice* ptDevice)
static plRenderPassLayoutHandle
pl__get_new_render_pass_layout_handle(plDevice* ptDevice)
{
uint32_t uResourceIndex = UINT32_MAX;
uint32_t uResourceIndex = 0;
if(pl_sb_size(ptDevice->sbtRenderPassLayoutFreeIndices) > 0)
uResourceIndex = pl_sb_pop(ptDevice->sbtRenderPassLayoutFreeIndices);
else
{
uResourceIndex = pl_sb_size(ptDevice->sbtRenderPassLayoutsCold);
pl_sb_add(ptDevice->sbtRenderPassLayoutsCold);
pl_sb_back(ptDevice->sbtRenderPassLayoutsCold)._uGeneration = UINT32_MAX;
pl_sb_back(ptDevice->sbtRenderPassLayoutsCold)._uGeneration = UINT16_MAX;
pl_sb_add(ptDevice->sbtRenderPassLayoutsHot);
}

Expand Down
Loading

0 comments on commit 39f0263

Please sign in to comment.