Skip to content

Commit

Permalink
feat: move to bindless #76 & expose gpu global barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Dec 16, 2024
1 parent b62ea35 commit aba7453
Show file tree
Hide file tree
Showing 30 changed files with 1,381 additions and 895 deletions.
2 changes: 1 addition & 1 deletion examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submit drawlists
plIO* ptIO = gptIO->get_io();
Expand Down
8 changes: 7 additions & 1 deletion examples/example_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

plSwapchainInfo tInfo = gptGfx->get_swapchain_info(ptAppData->ptSwapchain);
const plTextureDesc tColorTextureDesc = {
.tDimensions = {(float)tInfo.uWidth, (float)tInfo.uHeight, 1},
Expand Down Expand Up @@ -249,6 +251,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// set initial usage
gptGfx->set_texture_usage(ptEncoder, ptAppData->tMSAATexture, PL_TEXTURE_USAGE_COLOR_ATTACHMENT, 0);

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -379,6 +382,8 @@ pl_app_resize(plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

plSwapchainInfo tInfo = gptGfx->get_swapchain_info(ptAppData->ptSwapchain);
const plTextureDesc tColorTextureDesc = {
.tDimensions = {(float)tInfo.uWidth, (float)tInfo.uHeight, 1},
Expand Down Expand Up @@ -413,6 +418,7 @@ pl_app_resize(plAppData* ptAppData)
// set initial usage
gptGfx->set_texture_usage(ptEncoder, ptAppData->tMSAATexture, PL_TEXTURE_USAGE_COLOR_ATTACHMENT, 0);

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -518,7 +524,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submits UI drawlist/layers
plIO* ptIO = gptIO->get_io();
Expand Down
2 changes: 1 addition & 1 deletion examples/example_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submit nonindexed draw using basic API
gptGfx->bind_shader(ptEncoder, ptAppData->tShader);
Expand Down
4 changes: 3 additions & 1 deletion examples/example_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);
gptGfx->copy_buffer(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tVertexBuffer, 0, 0, sizeof(float) * 24);
gptGfx->copy_buffer(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tIndexBuffer, 1024, 0, sizeof(uint32_t) * 6);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -474,7 +476,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submit nonindexed draw using basic API
gptGfx->bind_shader(ptEncoder, ptAppData->tShader);
Expand Down
4 changes: 3 additions & 1 deletion examples/example_6.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);
gptGfx->copy_buffer(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tVertexBuffer, 0, 0, sizeof(float) * 16);
gptGfx->copy_buffer(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tIndexBuffer, 1024, 0, sizeof(uint32_t) * 6);

Expand Down Expand Up @@ -417,6 +418,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
gptGfx->copy_buffer_to_texture(ptEncoder, ptAppData->tStagingBuffer, ptAppData->tTexture, 1, &tBufferImageCopy);

// end blit pass
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -626,7 +628,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submit nonindexed draw using basic API
gptGfx->bind_shader(ptEncoder, ptAppData->tShader);
Expand Down
7 changes: 5 additions & 2 deletions examples/example_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

// create main render pass
const plRenderPassDesc tMainRenderPassDesc = {
Expand Down Expand Up @@ -335,7 +336,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
atMainAttachmentSets[i].atViewAttachments[1] = atSwapchainImages[i];
}
ptAppData->tMainRenderPass = gptGfx->create_render_pass(ptAppData->ptDevice, &tMainRenderPassDesc, atMainAttachmentSets);

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -405,6 +406,7 @@ pl_app_resize(plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);
const plTextureDesc tDepthTextureDesc = {
.tDimensions = {gptIO->get_io()->tMainViewportSize.x, gptIO->get_io()->tMainViewportSize.y, 1},
.tFormat = PL_FORMAT_D32_FLOAT_S8_UINT,
Expand Down Expand Up @@ -441,6 +443,7 @@ pl_app_resize(plAppData* ptAppData)
atMainAttachmentSets[i].atViewAttachments[1] = atSwapchainImages[i];
}

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -558,7 +561,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo0);

// begin offscreen renderpass
plRenderEncoder* ptEncoder0 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder0 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

const plMat4 tMVP = pl_mul_mat4(&ptCamera->tProjMat, &ptCamera->tViewMat);
gptDrawBackend->submit_3d_drawlist(ptAppData->pt3dDrawlist,
Expand Down
8 changes: 6 additions & 2 deletions examples/example_9.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

const plTextureDesc tColorTextureDesc = {
.tDimensions = {ptAppData->tOffscreenSize.x, ptAppData->tOffscreenSize.y, 1},
Expand Down Expand Up @@ -392,6 +393,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
atAttachmentSets[i].atViewAttachments[1] = ptAppData->atColorTexture[i];
}

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down Expand Up @@ -623,7 +625,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo0);

// begin offscreen renderpass
plRenderEncoder* ptEncoder0 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tOffscreenRenderPass);
plRenderEncoder* ptEncoder0 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tOffscreenRenderPass, NULL);

const plMat4 tMVP = pl_mul_mat4(&ptCamera->tProjMat, &ptCamera->tViewMat);
gptDrawBackend->submit_3d_drawlist(ptAppData->pt3dDrawlist,
Expand Down Expand Up @@ -657,7 +659,7 @@ pl_app_update(plAppData* ptAppData)
gptGfx->begin_command_recording(ptCommandBuffer, &tBeginInfo1);

// begin main renderpass (directly to swapchain)
plRenderEncoder* ptEncoder1 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass);
plRenderEncoder* ptEncoder1 = gptGfx->begin_render_pass(ptCommandBuffer, ptAppData->tMainRenderPass, NULL);

// submit drawlists
gptDrawBackend->submit_2d_drawlist(ptAppData->ptAppDrawlist, ptEncoder1, ptIO->tMainViewportSize.x, ptIO->tMainViewportSize.y, 1);
Expand Down Expand Up @@ -769,6 +771,7 @@ resize_offscreen_resources(plAppData* ptAppData)

// begin blit pass, copy buffer, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

plIO* ptIO = gptIO->get_io();
ptAppData->tCamera.fAspectRatio = ptIO->tMainViewportSize.x / ptIO->tMainViewportSize.y;
Expand Down Expand Up @@ -835,6 +838,7 @@ resize_offscreen_resources(plAppData* ptAppData)
atAttachmentSets[i].atViewAttachments[1] = ptAppData->atColorTexture[i];
}

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down
3 changes: 3 additions & 0 deletions extensions/pl_draw_backend_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ pl_build_font_atlas_backend(plCommandBuffer* ptCommandBuffer, plFontAtlas* ptAtl
// begin blit pass, copy texture, end pass
plBlitEncoder* ptEncoder = gptGfx->begin_blit_pass(ptCommandBuffer);

gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE);

gptGfx->set_texture_usage(ptEncoder, tTexture, PL_TEXTURE_USAGE_SAMPLED, 0);

const plBufferImageCopy tBufferImageCopy = {
Expand All @@ -293,6 +295,7 @@ pl_build_font_atlas_backend(plCommandBuffer* ptCommandBuffer, plFontAtlas* ptAtl
};

gptGfx->copy_buffer_to_texture(ptEncoder, tStagingBuffer, tTexture, 1, &tBufferImageCopy);
gptGfx->pipeline_barrier_blit(ptEncoder, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ);
gptGfx->end_blit_pass(ptEncoder);

// finish recording
Expand Down
3 changes: 3 additions & 0 deletions extensions/pl_graphics_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
.create_bind_group_pool = pl_create_bind_group_pool,
.cleanup_bind_group_pool = pl_cleanup_bind_group_pool,
.reset_bind_group_pool = pl_reset_bind_group_pool,
.pipeline_barrier_blit = pl_pipeline_barrier_blit,
.pipeline_barrier_render = pl_pipeline_barrier_render,
.pipeline_barrier_compute = pl_pipeline_barrier_compute
};
pl_set_api(ptApiRegistry, plGraphicsI, &tApi);

Expand Down
Loading

0 comments on commit aba7453

Please sign in to comment.