From e65ada9d29141bf519398dd301002ade4d3811ff Mon Sep 17 00:00:00 2001 From: Jonathan Hoffstadt Date: Thu, 12 Dec 2024 22:18:13 -0600 Subject: [PATCH] WIP --- examples/example_3.c | 6 ++ examples/example_5.c | 2 + examples/example_6.c | 2 + examples/example_8.c | 5 +- examples/example_9.c | 4 ++ extensions/pl_draw_backend_ext.c | 3 + extensions/pl_ecs_ext.c | 2 +- extensions/pl_graphics_ext.c | 2 + extensions/pl_graphics_ext.h | 101 +++++++++++++++++------------- extensions/pl_graphics_metal.m | 10 +++ extensions/pl_graphics_vulkan.c | 87 +++++++++++++------------ extensions/pl_renderer_ext.c | 38 ++++++++--- extensions/pl_renderer_internal.c | 25 +++++--- 13 files changed, 182 insertions(+), 105 deletions(-) diff --git a/examples/example_3.c b/examples/example_3.c index b1040d7..87f5992 100644 --- a/examples/example_3.c +++ b/examples/example_3.c @@ -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}, @@ -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 @@ -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}, @@ -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 diff --git a/examples/example_5.c b/examples/example_5.c index e5a166e..8e59706 100644 --- a/examples/example_5.c +++ b/examples/example_5.c @@ -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 diff --git a/examples/example_6.c b/examples/example_6.c index d386c5d..b2f5b4c 100644 --- a/examples/example_6.c +++ b/examples/example_6.c @@ -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); @@ -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 diff --git a/examples/example_8.c b/examples/example_8.c index f7c461e..0d95e5f 100644 --- a/examples/example_8.c +++ b/examples/example_8.c @@ -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 = { @@ -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 @@ -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, @@ -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 diff --git a/examples/example_9.c b/examples/example_9.c index f61ad5f..faf7c36 100644 --- a/examples/example_9.c +++ b/examples/example_9.c @@ -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}, @@ -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 @@ -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; @@ -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 diff --git a/extensions/pl_draw_backend_ext.c b/extensions/pl_draw_backend_ext.c index 4fedcdd..a23e65c 100644 --- a/extensions/pl_draw_backend_ext.c +++ b/extensions/pl_draw_backend_ext.c @@ -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 = { @@ -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 diff --git a/extensions/pl_ecs_ext.c b/extensions/pl_ecs_ext.c index 982b71f..1da7f77 100644 --- a/extensions/pl_ecs_ext.c +++ b/extensions/pl_ecs_ext.c @@ -332,7 +332,7 @@ pl_ecs_remove_entity(plComponentLibrary* ptLibrary, plEntity tEntity) { plEntity tLastEntity = pl_sb_back(ptLibrary->_ptManagers[i]->sbtEntities); pl_hm_remove(ptLibrary->_ptManagers[i]->ptHashmap, tLastEntity.uIndex); - uint32_t _unUsed = pl_hm_get_free_index(ptLibrary->_ptManagers[i]->ptHashmap); // burn slot + uint64_t _unUsed = pl_hm_get_free_index(ptLibrary->_ptManagers[i]->ptHashmap); // burn slot pl_hm_insert(ptLibrary->_ptManagers[i]->ptHashmap, tLastEntity.uIndex, uEntityValue); } diff --git a/extensions/pl_graphics_ext.c b/extensions/pl_graphics_ext.c index 2760da7..1cc5cef 100644 --- a/extensions/pl_graphics_ext.c +++ b/extensions/pl_graphics_ext.c @@ -769,6 +769,8 @@ 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_compute = pl_pipeline_barrier_compute }; pl_set_api(ptApiRegistry, plGraphicsI, &tApi); diff --git a/extensions/pl_graphics_ext.h b/extensions/pl_graphics_ext.h index 1736bec..b0f82ce 100644 --- a/extensions/pl_graphics_ext.h +++ b/extensions/pl_graphics_ext.h @@ -1,6 +1,6 @@ /* pl_graphics_ext.h - * a light wrapper over Vulkan & Metal 2.0 + * a light wrapper over Vulkan & Metal 3.0 */ /* @@ -47,7 +47,7 @@ Index of this file: // [SECTION] apis //----------------------------------------------------------------------------- -#define plGraphicsI_version (plVersion){1, 0, 2} +#define plGraphicsI_version (plVersion){2, 0, 0} //----------------------------------------------------------------------------- // [SECTION] includes @@ -90,12 +90,10 @@ typedef struct _plSwapchainInfo plSwapchainInfo; // swapchain information typedef struct _plSwapchainInit plSwapchainInit; // swapchain creation options // encoders -typedef struct _plRenderEncoder plRenderEncoder; // opaque type for command buffer encoder for render ops -typedef struct _plComputeEncoder plComputeEncoder; // opaque type for command buffer encoder for compute ops -typedef struct _plBlitEncoder plBlitEncoder; // opaque type for command buffer encoder for blit ops -typedef struct _plBufferImageCopy plBufferImageCopy;// used for copying between buffers & textures with blit encoder - -// new +typedef struct _plRenderEncoder plRenderEncoder; // opaque type for command buffer encoder for render ops +typedef struct _plComputeEncoder plComputeEncoder; // opaque type for command buffer encoder for compute ops +typedef struct _plBlitEncoder plBlitEncoder; // opaque type for command buffer encoder for blit ops +typedef struct _plBufferImageCopy plBufferImageCopy; // used for copying between buffers & textures with blit encoder typedef struct _plPassTextureResource plPassTextureResource; typedef struct _plPassBufferResource plPassBufferResource; typedef struct _plPassResources plPassResources; @@ -169,35 +167,36 @@ PL_DEFINE_HANDLE(plRenderPassHandle); PL_DEFINE_HANDLE(plRenderPassLayoutHandle); // enums -typedef int plMipmapMode; // -> enum _plMipmapMode // Enum: mipmap filter modes (PL_MIPMAP_MODE_XXXX) -typedef int plAddressMode; // -> enum _plAddressMode // Enum: addressing mode sampling textures outside image (PL_ADDRESS_MODE_XXXX) -typedef int plFilter; // -> enum _plFilter // Enum: texture lookup filters (PL_FILTER_XXXX) -typedef int plSampleCount; // -> enum _plSampleCount // Enum: texture sample count (PL_SAMPLE_COUNT_XXXX) -typedef int plTextureType; // -> enum _plTextureType // Enum: texture type (PL_TEXTURE_TYPE_XXXX) -typedef int plTextureUsage; // -> enum _plTextureUsage // Flag: texture type (PL_TEXTURE_USAGE_XXXX) -typedef int plCompareMode; // -> enum _plCompareMode // Enum: texture sampling comparison modes (PL_COMPARE_MODE_XXXX) -typedef int plFormat; // -> enum _plFormat // Enum: formats (PL_FORMAT_XXXX) -typedef int plVertexFormat; // -> enum _plVertexFormat // Enum: formats (PL_FORMAT_VERTEX_XXXX) -typedef int plBufferUsage; // -> enum _plBufferUsage // Flag: buffer usage flags (PL_BUFFER_USAGE_XXXX) -typedef int plStageFlags; // -> enum _plStageFlags // Flag: GPU pipeline stage (PL_STAGE_XXXX) -typedef int plCullMode; // -> enum _plCullMode // Flag: face culling mode (PL_CULL_MODE_XXXX) -typedef int plBufferBindingType; // -> enum _plBufferBindingType // Enum: buffer binding type for bind groups (PL_BUFFER_BINDING_TYPE_XXXX) -typedef int plTextureBindingType; // -> enum _plTextureBindingType // Enum: image binding type for bind groups (PL_TEXTURE_BINDING_TYPE_XXXX) -typedef int plBindGroupPoolFlags; // -> enum _plBindGroupPoolFlags // Flags: flags for creating bind group pools (PL_BIND_GROUP_POOL_FLAGS_XXXX) -typedef int plMemoryMode; // -> enum _plMemoryMode // Enum: memory modes for allocating memory (PL_MEMORY_XXXX) -typedef int plStencilOp; // -> enum _plStencilOp // Enum: stencil operations (PL_STENCIL_OP_XXXX) -typedef int plLoadOp; // -> enum _plLoadOp // Enum: render pass target load operations (PL_LOAD_OP_XXXX) -typedef int plStoreOp; // -> enum _plStoreOp // Enum: render pass target store operations (PL_STORE_OP_XXXX) -typedef int plBlendOp; // -> enum _plBlendOp // Enum: blend operations (PL_BLEND_OP_XXXX) -typedef int plBlendFactor; // -> enum _plBlendFactor // Enum: blend operation factors (PL_BLEND_FACTOR_XXXX) -typedef int plDataType; // -> enum _plDataType // Enum: data types -typedef int plGraphicsInitFlags; // -> enum _plGraphicsInitFlags // Flags: graphics initialization flags (PL_GRAPHICS_INIT_FLAGS_XXXX) -typedef int plDeviceInitFlags; // -> enum _plDeviceInitFlags // Flags: device initialization flags (PL_DEVICE_INIT_FLAGS_XXXX) -typedef int plVendorId; // -> enum _plVendorId // Enum: device vendors (PL_VENDOR_ID_XXXX) -typedef int plDeviceType; // -> enum _plDeviceType // Enum: device type (PL_DEVICE_TYPE_XXXX) -typedef int plDeviceCapability; // -> enum _plDeviceCapability // Flags: device capabilities (PL_DEVICE_CAPABILITY_XXXX) -typedef int plCommandPoolResetFlags; // -> enum _plCommandPoolResetFlags // Flags: device capabilities (PL_DEVICE_CAPABILITY_XXXX) -typedef int plPassResourceUsageFlags; +typedef int plMipmapMode; // -> enum _plMipmapMode // Enum: mipmap filter modes (PL_MIPMAP_MODE_XXXX) +typedef int plAddressMode; // -> enum _plAddressMode // Enum: addressing mode sampling textures outside image (PL_ADDRESS_MODE_XXXX) +typedef int plFilter; // -> enum _plFilter // Enum: texture lookup filters (PL_FILTER_XXXX) +typedef int plSampleCount; // -> enum _plSampleCount // Enum: texture sample count (PL_SAMPLE_COUNT_XXXX) +typedef int plTextureType; // -> enum _plTextureType // Enum: texture type (PL_TEXTURE_TYPE_XXXX) +typedef int plTextureUsage; // -> enum _plTextureUsage // Flag: texture type (PL_TEXTURE_USAGE_XXXX) +typedef int plCompareMode; // -> enum _plCompareMode // Enum: texture sampling comparison modes (PL_COMPARE_MODE_XXXX) +typedef int plFormat; // -> enum _plFormat // Enum: formats (PL_FORMAT_XXXX) +typedef int plVertexFormat; // -> enum _plVertexFormat // Enum: formats (PL_FORMAT_VERTEX_XXXX) +typedef int plBufferUsage; // -> enum _plBufferUsage // Flag: buffer usage flags (PL_BUFFER_USAGE_XXXX) +typedef int plStageFlags; // -> enum _plStageFlags // Flag: GPU pipeline stage (PL_STAGE_XXXX) +typedef int plAccessFlags; // -> enum _plAccessFlags // Flag: GPU pipeline stage (PL_ACCESS_XXXX) +typedef int plCullMode; // -> enum _plCullMode // Flag: face culling mode (PL_CULL_MODE_XXXX) +typedef int plBufferBindingType; // -> enum _plBufferBindingType // Enum: buffer binding type for bind groups (PL_BUFFER_BINDING_TYPE_XXXX) +typedef int plTextureBindingType; // -> enum _plTextureBindingType // Enum: image binding type for bind groups (PL_TEXTURE_BINDING_TYPE_XXXX) +typedef int plBindGroupPoolFlags; // -> enum _plBindGroupPoolFlags // Flags: flags for creating bind group pools (PL_BIND_GROUP_POOL_FLAGS_XXXX) +typedef int plMemoryMode; // -> enum _plMemoryMode // Enum: memory modes for allocating memory (PL_MEMORY_XXXX) +typedef int plStencilOp; // -> enum _plStencilOp // Enum: stencil operations (PL_STENCIL_OP_XXXX) +typedef int plLoadOp; // -> enum _plLoadOp // Enum: render pass target load operations (PL_LOAD_OP_XXXX) +typedef int plStoreOp; // -> enum _plStoreOp // Enum: render pass target store operations (PL_STORE_OP_XXXX) +typedef int plBlendOp; // -> enum _plBlendOp // Enum: blend operations (PL_BLEND_OP_XXXX) +typedef int plBlendFactor; // -> enum _plBlendFactor // Enum: blend operation factors (PL_BLEND_FACTOR_XXXX) +typedef int plDataType; // -> enum _plDataType // Enum: data types +typedef int plGraphicsInitFlags; // -> enum _plGraphicsInitFlags // Flags: graphics initialization flags (PL_GRAPHICS_INIT_FLAGS_XXXX) +typedef int plDeviceInitFlags; // -> enum _plDeviceInitFlags // Flags: device initialization flags (PL_DEVICE_INIT_FLAGS_XXXX) +typedef int plVendorId; // -> enum _plVendorId // Enum: device vendors (PL_VENDOR_ID_XXXX) +typedef int plDeviceType; // -> enum _plDeviceType // Enum: device type (PL_DEVICE_TYPE_XXXX) +typedef int plDeviceCapability; // -> enum _plDeviceCapability // Flags: device capabilities (PL_DEVICE_CAPABILITY_XXXX) +typedef int plCommandPoolResetFlags; // -> enum _plCommandPoolResetFlags // Flags: device capabilities (PL_DEVICE_CAPABILITY_XXXX) +typedef int plPassResourceUsageFlags; // -> enum _plPassResourceUsageFlags // Flags: resource usage (PL_PASS_RESOURCE_USAGE_XXXX) // external typedef struct _plWindow plWindow; // pl_os.h @@ -302,6 +301,10 @@ typedef struct _plGraphicsI void (*generate_mipmaps) (plBlitEncoder*, plTextureHandle); void (*copy_buffer) (plBlitEncoder*, plBufferHandle source, plBufferHandle destination, uint32_t sourceOffset, uint32_t destinationOffset, size_t); + // global barriers + void (*pipeline_barrier_blit) (plBlitEncoder*, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses); + void (*pipeline_barrier_compute)(plComputeEncoder*, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses); + //----------------------------------------------------------------------------- // buffers @@ -497,9 +500,7 @@ typedef struct _plTextureBinding uint32_t uSlot; uint32_t uDescriptorCount; // 0 - will become 1 plStageFlags tStages; - - // [INTERNAL] - bool _bVariableDescriptorCount; + bool bNonUniformIndexing; // only available if device capability has PL_DEVICE_CAPABILITY_BIND_GROUP_INDEXING } plTextureBinding; typedef struct _plBufferBinding @@ -1124,11 +1125,21 @@ enum _plGraphicsInitFlags enum _plStageFlags { - PL_STAGE_NONE = 0, - PL_STAGE_VERTEX = 1 << 0, - PL_STAGE_PIXEL = 1 << 1, - PL_STAGE_COMPUTE = 1 << 2, - PL_STAGE_ALL = PL_STAGE_VERTEX | PL_STAGE_PIXEL | PL_STAGE_COMPUTE + PL_STAGE_NONE = 0, + PL_STAGE_VERTEX = 1 << 0, + PL_STAGE_PIXEL = 1 << 1, + PL_STAGE_COMPUTE = 1 << 2, + PL_STAGE_TRANSFER = 1 << 3, + PL_STAGE_ALL = PL_STAGE_VERTEX | PL_STAGE_PIXEL | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER +}; + +enum _plAccessFlags +{ + PL_ACCESS_NONE = 0, + PL_ACCESS_SHADER_READ = 1 << 0, + PL_ACCESS_SHADER_WRITE = 1 << 1, + PL_ACCESS_TRANSFER_WRITE = 1 << 2, + PL_ACCESS_TRANSFER_READ = 1 << 3 }; enum _plCullMode diff --git a/extensions/pl_graphics_metal.m b/extensions/pl_graphics_metal.m index 0fcdb06..c8b5294 100644 --- a/extensions/pl_graphics_metal.m +++ b/extensions/pl_graphics_metal.m @@ -1954,6 +1954,16 @@ pl__return_blit_encoder(ptEncoder); } +void +pl_pipeline_barrier_blit(plBlitEncoder* ptEncoder, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses) +{ +} + +void +pl_pipeline_barrier_compute(plComputeEncoder* ptEncoder, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses) +{ +} + static plComputeEncoder* pl_begin_compute_pass(plCommandBuffer* ptCmdBuffer, const plPassResources* ptResources) { diff --git a/extensions/pl_graphics_vulkan.c b/extensions/pl_graphics_vulkan.c index 53d4ab1..9e475ae 100644 --- a/extensions/pl_graphics_vulkan.c +++ b/extensions/pl_graphics_vulkan.c @@ -351,6 +351,7 @@ static plFormat pl__pilotlight_format (VkFormat); static VkStencilOp pl__vulkan_stencil_op (plStencilOp); static VkBlendFactor pl__vulkan_blend_factor (plBlendFactor); static VkBlendOp pl__vulkan_blend_op (plBlendOp); +static VkAccessFlags pl__vulkan_access_flags (plAccessFlags); // misc static plDeviceMemoryAllocation pl__allocate_staging_dynamic(struct plDeviceMemoryAllocatorO*, uint32_t uTypeFilter, uint64_t ulSize, uint64_t ulAlignment, const char* pcName); @@ -843,7 +844,7 @@ pl_create_bind_group(plDevice* ptDevice, const plBindGroupDesc* ptDesc) tBinding.descriptorCount = 1; atDescriptorSetLayoutFlags[uCurrentBinding] = 0; - if (ptLayout->atTextureBindings[i]._bVariableDescriptorCount) + if (ptLayout->atTextureBindings[i].bNonUniformIndexing) { atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT; bHasVariableDescriptors = true; @@ -3335,20 +3336,33 @@ pl_cleanup_device(plDevice* ptDevice) pl__cleanup_common_device(ptDevice); } -plComputeEncoder* -pl_begin_compute_pass(plCommandBuffer* ptCmdBuffer, const plPassResources* ptResources) +void +pl_pipeline_barrier_blit(plBlitEncoder* ptEncoder, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses) { VkMemoryBarrier tMemoryBarrier = { .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, - .srcAccessMask = VK_ACCESS_SHADER_READ_BIT, - .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT + .srcAccessMask = pl__vulkan_access_flags(beforeAccesses), + .dstAccessMask = pl__vulkan_access_flags(afterAccesses) }; - vkCmdPipelineBarrier(ptCmdBuffer->tCmdBuffer, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); + vkCmdPipelineBarrier(ptEncoder->ptCommandBuffer->tCmdBuffer, pl__vulkan_stage_flags(beforeStages), pl__vulkan_stage_flags(afterStages), 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); +} + +void +pl_pipeline_barrier_compute(plComputeEncoder* ptEncoder, plStageFlags beforeStages, plAccessFlags beforeAccesses, plStageFlags afterStages, plAccessFlags afterAccesses) +{ + VkMemoryBarrier tMemoryBarrier = { + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .srcAccessMask = pl__vulkan_access_flags(beforeAccesses), + .dstAccessMask = pl__vulkan_access_flags(afterAccesses) + }; + vkCmdPipelineBarrier(ptEncoder->ptCommandBuffer->tCmdBuffer, pl__vulkan_stage_flags(beforeStages), pl__vulkan_stage_flags(afterStages), 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); +} + +plComputeEncoder* +pl_begin_compute_pass(plCommandBuffer* ptCmdBuffer, const plPassResources* ptResources) +{ plComputeEncoder* ptEncoder = pl__get_new_compute_encoder(); ptEncoder->ptCommandBuffer = ptCmdBuffer; return ptEncoder; @@ -3357,35 +3371,12 @@ pl_begin_compute_pass(plCommandBuffer* ptCmdBuffer, const plPassResources* ptRes void pl_end_compute_pass(plComputeEncoder* ptEncoder) { - plCommandBuffer* ptCmdBuffer = ptEncoder->ptCommandBuffer; - - VkMemoryBarrier tMemoryBarrier = { - .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, - .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, - .dstAccessMask = VK_ACCESS_SHADER_READ_BIT - }; - vkCmdPipelineBarrier(ptCmdBuffer->tCmdBuffer, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); - pl__return_compute_encoder(ptEncoder); } plBlitEncoder* pl_begin_blit_pass(plCommandBuffer* ptCmdBuffer) { - - VkMemoryBarrier tMemoryBarrier = { - .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, - .srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT, - .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT - }; - vkCmdPipelineBarrier(ptCmdBuffer->tCmdBuffer, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); - plBlitEncoder* ptEncoder = pl__get_new_blit_encoder(); ptEncoder->ptCommandBuffer = ptCmdBuffer; return ptEncoder; @@ -3394,17 +3385,6 @@ pl_begin_blit_pass(plCommandBuffer* ptCmdBuffer) void pl_end_blit_pass(plBlitEncoder* ptEncoder) { - plCommandBuffer* ptCmdBuffer = ptEncoder->ptCommandBuffer; - - VkMemoryBarrier tMemoryBarrier = { - .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, - .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, - .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT - }; - vkCmdPipelineBarrier(ptCmdBuffer->tCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, - 0, 1, &tMemoryBarrier, 0, NULL, 0, NULL); - pl__return_blit_encoder(ptEncoder); } @@ -4045,7 +4025,7 @@ pl__create_bind_group_layout(plDevice* ptDevice, plBindGroupLayout* ptLayout, co if (tBinding.descriptorCount == 0) tBinding.descriptorCount = 1; atDescriptorSetLayoutFlags[uCurrentBinding] = 0; - if (ptLayout->atTextureBindings[i]._bVariableDescriptorCount) + if (ptLayout->atTextureBindings[i].bNonUniformIndexing) atDescriptorSetLayoutFlags[uCurrentBinding] |= VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT; atDescriptorSetLayoutBindings[uCurrentBinding++] = tBinding; } @@ -5057,6 +5037,25 @@ pl__vulkan_stage_flags(plStageFlags tFlags) tResult |= VK_SHADER_STAGE_FRAGMENT_BIT; if (tFlags & PL_STAGE_COMPUTE) tResult |= VK_SHADER_STAGE_COMPUTE_BIT; + if(tFlags & PL_STAGE_TRANSFER) + tResult |= VK_PIPELINE_STAGE_TRANSFER_BIT; + + return tResult; +} + +static VkAccessFlags +pl__vulkan_access_flags(plAccessFlags tFlags) +{ + VkAccessFlags tResult = 0; + + if (tFlags & PL_ACCESS_SHADER_READ) + tResult |= VK_ACCESS_SHADER_READ_BIT; + if (tFlags & PL_ACCESS_SHADER_WRITE) + tResult |= VK_ACCESS_SHADER_WRITE_BIT; + if (tFlags & PL_ACCESS_TRANSFER_WRITE) + tResult |= VK_ACCESS_TRANSFER_WRITE_BIT; + if(tFlags & PL_ACCESS_TRANSFER_READ) + tResult |= VK_ACCESS_TRANSFER_READ_BIT; return tResult; } diff --git a/extensions/pl_renderer_ext.c b/extensions/pl_renderer_ext.c index 879c87d..2d85314 100644 --- a/extensions/pl_renderer_ext.c +++ b/extensions/pl_renderer_ext.c @@ -423,6 +423,8 @@ pl_refr_initialize(plWindow* ptWindow) // 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); + // retrieve textures plTexture* ptColorTexture = gptGfx->get_texture(gptData->ptDevice, gptData->tMSAATexture); @@ -440,6 +442,7 @@ pl_refr_initialize(plWindow* ptWindow) // set initial usage gptGfx->set_texture_usage(ptEncoder, gptData->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 @@ -514,8 +517,8 @@ pl_refr_create_scene(void) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }; @@ -1407,9 +1410,11 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; plComputeEncoder* ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, &tPassResources); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); gptGfx->bind_compute_bind_groups(ptComputeEncoder, tPanoramaShader, 0, 1, &tComputeBindGroup, 0, NULL); gptGfx->bind_compute_shader(ptComputeEncoder, tPanoramaShader); gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1430,6 +1435,8 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE); + for(uint32_t i = 0; i < 6; i++) { const plBufferImageCopy tBufferImageCopy = { @@ -1442,6 +1449,7 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; gptGfx->copy_buffer_to_texture(ptBlitEncoder, atComputeBuffers[i + 1], ptScene->tSkyboxTexture, 1, &tBufferImageCopy); } + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1715,9 +1723,11 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; plComputeEncoder* ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, &tPassResources); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); gptGfx->bind_compute_bind_groups(ptComputeEncoder, tLUTShader, 0, 1, &tLutBindGroup, 0, NULL); gptGfx->bind_compute_shader(ptComputeEncoder, tLUTShader); gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1740,9 +1750,11 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, &tPassResources); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); gptGfx->bind_compute_bind_groups(ptComputeEncoder, tIrradianceShader, 0, 1, &tLutBindGroup, 0, NULL); gptGfx->bind_compute_shader(ptComputeEncoder, tIrradianceShader); gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1763,6 +1775,7 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE); for(uint32_t i = 0; i < 6; i++) { @@ -1776,7 +1789,7 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; gptGfx->copy_buffer_to_texture(ptBlitEncoder, atLutBuffers[i], ptScene->tLambertianEnvTexture, 1, &tBufferImageCopy); } - + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1896,9 +1909,11 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; plComputeEncoder* ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, &tInnerPassResources); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); gptGfx->bind_compute_bind_groups(ptComputeEncoder, atSpecularComputeShaders[i], 0, 1, &tLutBindGroup, 0, NULL); gptGfx->bind_compute_shader(ptComputeEncoder, atSpecularComputeShaders[i]); gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -1909,6 +1924,7 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE); for(uint32_t j = 0; j < 6; j++) { @@ -1923,6 +1939,7 @@ pl_refr_load_skybox_from_panorama(uint32_t uSceneHandle, const char* pcPath, int }; gptGfx->copy_buffer_to_texture(ptBlitEncoder, atInnerComputeBuffers[j], ptScene->tGGXEnvTexture, 1, &tBufferImageCopy); } + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -2266,8 +2283,8 @@ pl_refr_reload_scene_shaders(uint32_t uSceneHandle) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }, { @@ -2836,8 +2853,8 @@ pl_refr_finalize_scene(uint32_t uSceneHandle) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }, { @@ -3706,6 +3723,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions memset(ptCachedStagingBuffer->tMemoryAllocation.pHostMapped, 0, ptCachedStagingBuffer->tDesc.szByteSize); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE); plTexture* ptTexture = gptGfx->get_texture(ptDevice, ptView->tPickTexture); const plBufferImageCopy tBufferImageCopy = { @@ -3715,6 +3733,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions .uLayerCount = 1 }; gptGfx->copy_texture_to_buffer(ptBlitEncoder, ptView->tPickTexture, gptData->tCachedStagingBuffer, 1, &tBufferImageCopy); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); } @@ -3876,6 +3895,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions // begin main renderpass (directly to swapchain) plComputeEncoder* ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, NULL); + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); ptView->tLastUVMask = (i % 2 == 0) ? ptView->atUVMaskTexture1[uFrameIdx] : ptView->atUVMaskTexture0[uFrameIdx]; @@ -3890,6 +3910,7 @@ pl_refr_render_scene(uint32_t uSceneHandle, uint32_t uViewHandle, plViewOptions gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); // end render pass + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); // end recording @@ -3963,6 +3984,8 @@ pl_refr_resize(void) // 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(gptData->ptSwap); const plTextureDesc tColorTextureDesc = { .tDimensions = {(float)tInfo.uWidth, (float)tInfo.uHeight, 1}, @@ -3997,6 +4020,7 @@ pl_refr_resize(void) // set initial usage gptGfx->set_texture_usage(ptEncoder, gptData->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 diff --git a/extensions/pl_renderer_internal.c b/extensions/pl_renderer_internal.c index 2441e63..2392cb6 100644 --- a/extensions/pl_renderer_internal.c +++ b/extensions/pl_renderer_internal.c @@ -169,7 +169,9 @@ pl__refr_create_texture(const plTextureDesc* ptDesc, const char* pcName, uint32_ plCommandBuffer* ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder, tHandle, tInitialUsage, 0); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -210,6 +212,7 @@ pl__refr_create_texture_with_data(const plTextureDesc* ptDesc, const char* pcNam plCommandBuffer* ptCommandBuffer = gptGfx->request_command_buffer(ptCmdPool); gptGfx->begin_command_recording(ptCommandBuffer, NULL); plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder, tHandle, PL_TEXTURE_USAGE_SAMPLED, 0); @@ -235,6 +238,7 @@ pl__refr_create_texture_with_data(const plTextureDesc* ptDesc, const char* pcNam gptGfx->generate_mipmaps(ptBlitEncoder, tHandle); } + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); gptGfx->end_command_recording(ptCommandBuffer); gptGfx->submit_command_buffer(ptCommandBuffer, NULL); @@ -335,7 +339,10 @@ pl__refr_create_local_buffer(const plBufferDesc* ptDesc, const char* pcName, uin // 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, gptData->tStagingBufferHandle[0], tHandle, 0, 0, ptDesc->szByteSize); + 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 @@ -618,6 +625,8 @@ pl_refr_update_skin_textures(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHa plDevice* ptDevice = gptData->ptDevice; plRefScene* ptScene = &gptData->sbtScenes[uSceneHandle]; plBlitEncoder* ptBlitEncoder = gptGfx->begin_blit_pass(ptCommandBuffer); + gptGfx->pipeline_barrier_blit(ptBlitEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE | PL_STAGE_TRANSFER, PL_ACCESS_SHADER_READ | PL_ACCESS_TRANSFER_READ, PL_STAGE_TRANSFER, PL_ACCESS_TRANSFER_WRITE); + uint32_t uFrameIdx = gptGfx->get_current_frame_index(); // update skin textures @@ -666,6 +675,7 @@ pl_refr_update_skin_textures(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHa gptGfx->copy_buffer_to_texture(ptBlitEncoder, gptData->tStagingBufferHandle[uFrameIdx], ptScene->sbtSkinData[i].atDynamicTexture[uFrameIdx], 1, &tBufferImageCopy); } + gptGfx->pipeline_barrier_blit(ptBlitEncoder, 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(ptBlitEncoder); pl_end_cpu_sample(gptProfile, 0); @@ -704,7 +714,7 @@ pl_refr_perform_skinning(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHandle }; plComputeEncoder* ptComputeEncoder = gptGfx->begin_compute_pass(ptCommandBuffer, &tPassResources); - + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE); for(uint32_t i = 0; i < uSkinCount; i++) { plDynamicBinding tDynamicBinding = pl__allocate_dynamic_data(ptDevice); @@ -729,6 +739,7 @@ pl_refr_perform_skinning(plCommandBuffer* ptCommandBuffer, uint32_t uSceneHandle gptGfx->bind_compute_shader(ptComputeEncoder, ptScene->sbtSkinData[i].tShader); gptGfx->dispatch(ptComputeEncoder, 1, &tDispach); } + gptGfx->pipeline_barrier_compute(ptComputeEncoder, PL_STAGE_COMPUTE, PL_ACCESS_SHADER_WRITE, PL_STAGE_VERTEX | PL_STAGE_COMPUTE, PL_ACCESS_SHADER_READ); gptGfx->end_compute_pass(ptComputeEncoder); } pl_end_cpu_sample(gptProfile, 0); @@ -1208,8 +1219,8 @@ pl_refr_create_global_shaders(void) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }, { @@ -1277,8 +1288,8 @@ pl_refr_create_global_shaders(void) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }, { @@ -1350,8 +1361,8 @@ pl_refr_create_global_shaders(void) {.uSlot = 3, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL} }, .atTextureBindings = { - {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true}, - {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, ._bVariableDescriptorCount = true} + {.uSlot = 4, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true}, + {.uSlot = 4100, .tStages = PL_STAGE_VERTEX | PL_STAGE_PIXEL, .tType = PL_TEXTURE_BINDING_TYPE_SAMPLED, .uDescriptorCount = PL_MAX_BINDLESS_TEXTURES, .bNonUniformIndexing = true} } }, {