@@ -165,11 +165,7 @@ typedef struct _plPipelineEntry
165165 plShaderHandle tRegularPipeline ;
166166 plShaderHandle tSecondaryPipeline ;
167167 plDrawFlags tFlags ;
168- uint32_t uSubpassIndex ;
169- plFormat atColorFormats [PL_MAX_RENDER_TARGETS ];
170- plFormat tDepthFormat ;
171- plFormat tStencilFormat ;
172- uint32_t uColorAttachmentCount ;
168+ plRenderAttachmentFormatInfo tFormatInfo ;
173169} plPipelineEntry ;
174170
175171typedef struct _plBufferInfo
@@ -501,8 +497,27 @@ pl__add_3d_path(plDrawList3D* ptDrawlist, uint32_t uCount, const plVec3* atPoint
501497
502498// backend
503499static plBufferHandle pl__create_staging_buffer (const plBufferDesc * , const char * pcName , uint32_t uIdentifier );
504- static const plPipelineEntry * pl__get_3d_pipeline (uint32_t uMSAASampleCount , plDrawFlags , uint32_t uSubpassIndex , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat );
505- static const plPipelineEntry * pl__get_2d_pipeline (uint32_t uMSAASampleCount , uint32_t uSubpassIndex , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat );
500+ static const plPipelineEntry * pl__get_3d_pipeline (uint32_t uMSAASampleCount , plDrawFlags , const plRenderAttachmentFormatInfo * ptFormatInfo );
501+ static const plPipelineEntry * pl__get_2d_pipeline (uint32_t uMSAASampleCount , const plRenderAttachmentFormatInfo * ptFormatInfo );
502+
503+ static inline bool
504+ pl__format_info_equal (const plRenderAttachmentFormatInfo * ptInfo0 , const plRenderAttachmentFormatInfo * ptInfo1 )
505+ {
506+ if (ptInfo0 -> tDepthFormat == ptInfo1 -> tDepthFormat
507+ && ptInfo0 -> tStencilFormat == ptInfo1 -> tStencilFormat
508+ && ptInfo0 -> uColorCount == ptInfo1 -> uColorCount )
509+ {
510+ for (uint32_t i = 0 ; i < ptInfo0 -> uColorCount ; i ++ )
511+ {
512+ if (ptInfo0 -> atColorFormats [i ] != ptInfo0 -> atColorFormats [i ])
513+ {
514+ return false;
515+ }
516+ }
517+ return true;
518+ }
519+ return false;
520+ }
506521
507522//-----------------------------------------------------------------------------
508523// [SECTION] public api implementation
@@ -4073,7 +4088,7 @@ pl_draw_use_linear_sampler(plDrawLayer2D* ptLayer)
40734088}
40744089
40754090void
4076- pl_draw_submit_2d_drawlist (plDrawList2D * ptDrawlist , plCommandBuffer * ptCommandBuffer , float fWidth , float fHeight , uint32_t uMSAASampleCount , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat )
4091+ pl_draw_submit_2d_drawlist (plDrawList2D * ptDrawlist , plCommandBuffer * ptCommandBuffer , float fWidth , float fHeight , uint32_t uMSAASampleCount , const plRenderAttachmentFormatInfo * ptFormatInfo )
40774092{
40784093 gptGfx -> set_depth_bias (ptCommandBuffer , 0.0f , 0.0f , 0.0f );
40794094
@@ -4209,7 +4224,7 @@ pl_draw_submit_2d_drawlist(plDrawList2D* ptDrawlist, plCommandBuffer* ptCommandB
42094224 const int32_t iVertexOffset = ptBufferInfo -> uVertexBufferOffset / sizeof (plDrawVertex );
42104225 const int32_t iIndexOffset = gptDrawCtx -> auIndexBufferOffset [uFrameIdx ] / sizeof (uint32_t );
42114226
4212- const plPipelineEntry * ptEntry = pl__get_2d_pipeline (uMSAASampleCount , gptGfx -> get_current_subpass ( ptCommandBuffer ), uColorAttachmentCount , atColorFormats , tDepthFormat , tStencilFormat );
4227+ const plPipelineEntry * ptEntry = pl__get_2d_pipeline (uMSAASampleCount , ptFormatInfo );
42134228
42144229 const plVec2 tClipScale = gptIOI -> get_io ()-> tMainFramebufferScale ;
42154230
@@ -4344,14 +4359,14 @@ pl_draw_submit_2d_drawlist(plDrawList2D* ptDrawlist, plCommandBuffer* ptCommandB
43444359}
43454360
43464361void
4347- pl_draw_submit_3d_drawlist (plDrawList3D * ptDrawlist , plCommandBuffer * ptCommandBuffer , float fWidth , float fHeight , const plMat4 * ptMVP , plDrawFlags tFlags , uint32_t uMSAASampleCount , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat )
4362+ pl_draw_submit_3d_drawlist (plDrawList3D * ptDrawlist , plCommandBuffer * ptCommandBuffer , float fWidth , float fHeight , const plMat4 * ptMVP , plDrawFlags tFlags , uint32_t uMSAASampleCount , const plRenderAttachmentFormatInfo * ptFormatInfo )
43484363{
43494364 gptGfx -> push_debug_group (ptCommandBuffer , "3D Draw" , (plVec4 ){0.33f , 0.02f , 0.10f , 1.0f });
43504365
43514366 plDevice * ptDevice = gptDrawCtx -> ptDevice ;
43524367 const uint32_t uFrameIdx = gptGfx -> get_current_frame_index ();
43534368
4354- const plPipelineEntry * ptEntry = pl__get_3d_pipeline (uMSAASampleCount , tFlags , gptGfx -> get_current_subpass ( ptCommandBuffer ), uColorAttachmentCount , atColorFormats , tDepthFormat , tStencilFormat );
4369+ const plPipelineEntry * ptEntry = pl__get_3d_pipeline (uMSAASampleCount , tFlags , ptFormatInfo );
43554370
43564371 const float fAspectRatio = fWidth / fHeight ;
43574372
@@ -4582,7 +4597,7 @@ pl_draw_submit_3d_drawlist(plDrawList3D* ptDrawlist, plCommandBuffer* ptCommandB
45824597 }
45834598
45844599 pl_draw_submit_2d_layer (ptDrawlist -> ptLayer );
4585- pl_draw_submit_2d_drawlist (ptDrawlist -> pt2dDrawlist , ptCommandBuffer , fWidth , fHeight , uMSAASampleCount , uColorAttachmentCount , atColorFormats , tDepthFormat , tStencilFormat );
4600+ pl_draw_submit_2d_drawlist (ptDrawlist -> pt2dDrawlist , ptCommandBuffer , fWidth , fHeight , uMSAASampleCount , ptFormatInfo );
45864601 gptGfx -> pop_debug_group (ptCommandBuffer );
45874602}
45884603
@@ -4730,29 +4745,14 @@ pl__create_staging_buffer(const plBufferDesc* ptDesc, const char* pcName, uint32
47304745}
47314746
47324747static const plPipelineEntry *
4733- pl__get_3d_pipeline (uint32_t uMSAASampleCount , plDrawFlags tFlags , uint32_t uSubpassIndex , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat )
4748+ pl__get_3d_pipeline (uint32_t uMSAASampleCount , plDrawFlags tFlags , const plRenderAttachmentFormatInfo * ptFormatInfo )
47344749{
47354750 // check if pipeline exists
47364751 for (uint32_t i = 0 ; i < pl_sb_size (gptDrawCtx -> sbt3dPipelineEntries ); i ++ )
47374752 {
47384753 const plPipelineEntry * ptEntry = & gptDrawCtx -> sbt3dPipelineEntries [i ];
4739- if (ptEntry -> uMSAASampleCount == uMSAASampleCount
4740- && ptEntry -> tFlags == tFlags
4741- && ptEntry -> tDepthFormat == tDepthFormat
4742- && ptEntry -> tStencilFormat == tStencilFormat
4743- && ptEntry -> uColorAttachmentCount == uColorAttachmentCount
4744- && ptEntry -> uSubpassIndex == uSubpassIndex )
4754+ if (ptEntry -> uMSAASampleCount == uMSAASampleCount && pl__format_info_equal (& ptEntry -> tFormatInfo , ptFormatInfo ))
47454755 {
4746- bool bEqual = true;
4747- for (uint32_t j = 0 ; j < uColorAttachmentCount ; j ++ )
4748- {
4749- if (ptEntry -> atColorFormats [i ] != atColorFormats [i ])
4750- {
4751- bEqual = false;
4752- break ;
4753- }
4754- }
4755- if (bEqual )
47564756 return ptEntry ;
47574757 }
47584758 }
@@ -4762,13 +4762,8 @@ pl__get_3d_pipeline(uint32_t uMSAASampleCount, plDrawFlags tFlags, uint32_t uSub
47624762 pl_sb_add (gptDrawCtx -> sbt3dPipelineEntries );
47634763 plPipelineEntry * ptEntry = & gptDrawCtx -> sbt3dPipelineEntries [pl_sb_size (gptDrawCtx -> sbt3dPipelineEntries ) - 1 ];
47644764 ptEntry -> tFlags = tFlags ;
4765- ptEntry -> tDepthFormat = tDepthFormat ;
4766- ptEntry -> tStencilFormat = tStencilFormat ;
4767- ptEntry -> uColorAttachmentCount = uColorAttachmentCount ;
4765+ ptEntry -> tFormatInfo = * ptFormatInfo ;
47684766 ptEntry -> uMSAASampleCount = uMSAASampleCount ;
4769- ptEntry -> uSubpassIndex = uSubpassIndex ;
4770- for (uint32_t j = 0 ; j < uColorAttachmentCount ; j ++ )
4771- ptEntry -> atColorFormats [j ] = atColorFormats [j ];
47724767
47734768 uint64_t ulCullMode = PL_CULL_MODE_NONE ;
47744769 if (tFlags & PL_DRAW_FLAG_CULL_FRONT )
@@ -4813,16 +4808,10 @@ pl__get_3d_pipeline(uint32_t uMSAASampleCount, plDrawFlags tFlags, uint32_t uSub
48134808 .tAlphaOp = PL_BLEND_OP_ADD
48144809 }
48154810 },
4816- // .tRenderPassLayout = gptGfx->get_render_pass(ptDevice, tRenderPass)->tDesc.tLayout,
4817- .uSubpassIndex = uSubpassIndex ,
48184811 .tMSAASampleCount = uMSAASampleCount ,
4819- .uColorAttachmentCount = uColorAttachmentCount ,
4820- .tDepthAttachmentFormat = tDepthFormat ,
4821- .tStencilAttachmentFormat = tStencilFormat ,
4812+ .tRenderAttachmentFormatInfo = * ptFormatInfo
48224813 };
4823- for (uint32_t i = 0 ; i < uColorAttachmentCount ; i ++ )
4824- t3DShaderDesc .atColorAttachmentFormats [i ] = atColorFormats [i ];
4825- ptEntry -> tRegularPipeline = gptGfx -> create_shader2 (ptDevice , & t3DShaderDesc );
4814+ ptEntry -> tRegularPipeline = gptGfx -> create_shader (ptDevice , & t3DShaderDesc );
48264815 pl_temp_allocator_reset (& gptDrawCtx -> tTempAllocator );
48274816 }
48284817
@@ -4865,43 +4854,24 @@ pl__get_3d_pipeline(uint32_t uMSAASampleCount, plDrawFlags tFlags, uint32_t uSub
48654854 .tAlphaOp = PL_BLEND_OP_ADD
48664855 }
48674856 },
4868- .uSubpassIndex = uSubpassIndex ,
48694857 .tMSAASampleCount = uMSAASampleCount ,
4870- .uColorAttachmentCount = uColorAttachmentCount ,
4871- .tDepthAttachmentFormat = tDepthFormat ,
4872- .tStencilAttachmentFormat = tStencilFormat ,
4858+ .tRenderAttachmentFormatInfo = * ptFormatInfo
48734859 };
4874- for (uint32_t i = 0 ; i < uColorAttachmentCount ; i ++ )
4875- t3DLineShaderDesc .atColorAttachmentFormats [i ] = atColorFormats [i ];
4876- ptEntry -> tSecondaryPipeline = gptGfx -> create_shader2 (ptDevice , & t3DLineShaderDesc );
4860+ ptEntry -> tSecondaryPipeline = gptGfx -> create_shader (ptDevice , & t3DLineShaderDesc );
48774861 pl_temp_allocator_reset (& gptDrawCtx -> tTempAllocator );
48784862 }
48794863 return ptEntry ;
48804864}
48814865
48824866static const plPipelineEntry *
4883- pl__get_2d_pipeline (uint32_t uMSAASampleCount , uint32_t uSubpassIndex , uint32_t uColorAttachmentCount , plFormat * atColorFormats , plFormat tDepthFormat , plFormat tStencilFormat )
4867+ pl__get_2d_pipeline (uint32_t uMSAASampleCount , const plRenderAttachmentFormatInfo * ptFormatInfo )
48844868{
48854869 // check if pipeline exists
48864870 for (uint32_t i = 0 ; i < pl_sb_size (gptDrawCtx -> sbt2dPipelineEntries ); i ++ )
48874871 {
48884872 const plPipelineEntry * ptEntry = & gptDrawCtx -> sbt2dPipelineEntries [i ];
4889- if (ptEntry -> uMSAASampleCount == uMSAASampleCount
4890- && ptEntry -> tDepthFormat == tDepthFormat
4891- && ptEntry -> tStencilFormat == tStencilFormat
4892- && ptEntry -> uColorAttachmentCount == uColorAttachmentCount
4893- && ptEntry -> uSubpassIndex == uSubpassIndex )
4873+ if (ptEntry -> uMSAASampleCount == uMSAASampleCount && pl__format_info_equal (& ptEntry -> tFormatInfo , ptFormatInfo ))
48944874 {
4895- bool bEqual = true;
4896- for (uint32_t j = 0 ; j < uColorAttachmentCount ; j ++ )
4897- {
4898- if (ptEntry -> atColorFormats [i ] != atColorFormats [i ])
4899- {
4900- bEqual = false;
4901- break ;
4902- }
4903- }
4904- if (bEqual )
49054875 return ptEntry ;
49064876 }
49074877 }
@@ -4911,13 +4881,9 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, uint32_t uSubpassIndex, uint32_t
49114881 pl_sb_add (gptDrawCtx -> sbt2dPipelineEntries );
49124882 plPipelineEntry * ptEntry = & gptDrawCtx -> sbt2dPipelineEntries [pl_sb_size (gptDrawCtx -> sbt2dPipelineEntries ) - 1 ];
49134883 ptEntry -> tFlags = 0 ;
4914- ptEntry -> tDepthFormat = tDepthFormat ;
4915- ptEntry -> tStencilFormat = tStencilFormat ;
4916- ptEntry -> uColorAttachmentCount = uColorAttachmentCount ;
4884+ ptEntry -> tFormatInfo = * ptFormatInfo ;
49174885 ptEntry -> uMSAASampleCount = uMSAASampleCount ;
4918- ptEntry -> uSubpassIndex = uSubpassIndex ;
4919- for (uint32_t j = 0 ; j < uColorAttachmentCount ; j ++ )
4920- ptEntry -> atColorFormats [j ] = atColorFormats [j ];
4886+
49214887
49224888 plShaderDesc tRegularShaderDesc = {
49234889 .tFragmentShader = gptShader -> load_glsl ("pl_draw_2d.frag" , "main" , NULL , NULL ),
@@ -4956,8 +4922,6 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, uint32_t uSubpassIndex, uint32_t
49564922 .tAlphaOp = PL_BLEND_OP_ADD
49574923 }
49584924 },
4959- // .tRenderPassLayout = gptGfx->get_render_pass(ptDevice, tRenderPass)->tDesc.tLayout,
4960- .uSubpassIndex = uSubpassIndex ,
49614925 .atBindGroupLayouts = {
49624926 {
49634927 .atSamplerBindings = {
@@ -4971,15 +4935,9 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, uint32_t uSubpassIndex, uint32_t
49714935 }
49724936 },
49734937 .tMSAASampleCount = uMSAASampleCount ,
4974- .uSubpassIndex = uSubpassIndex ,
4975- .tMSAASampleCount = uMSAASampleCount ,
4976- .uColorAttachmentCount = uColorAttachmentCount ,
4977- .tDepthAttachmentFormat = tDepthFormat ,
4978- .tStencilAttachmentFormat = tStencilFormat ,
4938+ .tRenderAttachmentFormatInfo = * ptFormatInfo
49794939 };
4980- for (uint32_t i = 0 ; i < uColorAttachmentCount ; i ++ )
4981- tRegularShaderDesc .atColorAttachmentFormats [i ] = atColorFormats [i ];
4982- ptEntry -> tRegularPipeline = gptGfx -> create_shader2 (ptDevice , & tRegularShaderDesc );
4940+ ptEntry -> tRegularPipeline = gptGfx -> create_shader (ptDevice , & tRegularShaderDesc );
49834941 pl_temp_allocator_reset (& gptDrawCtx -> tTempAllocator );
49844942
49854943 plShaderDesc tSecondaryShaderDesc = {
@@ -5019,8 +4977,6 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, uint32_t uSubpassIndex, uint32_t
50194977 .tAlphaOp = PL_BLEND_OP_ADD
50204978 }
50214979 },
5022- // .tRenderPassLayout = gptGfx->get_render_pass(ptDevice, tRenderPass)->tDesc.tLayout,
5023- .uSubpassIndex = uSubpassIndex ,
50244980 .atBindGroupLayouts = {
50254981 {
50264982 .atSamplerBindings = {
@@ -5034,14 +4990,9 @@ pl__get_2d_pipeline(uint32_t uMSAASampleCount, uint32_t uSubpassIndex, uint32_t
50344990 }
50354991 },
50364992 .tMSAASampleCount = uMSAASampleCount ,
5037- .tMSAASampleCount = uMSAASampleCount ,
5038- .uColorAttachmentCount = uColorAttachmentCount ,
5039- .tDepthAttachmentFormat = tDepthFormat ,
5040- .tStencilAttachmentFormat = tStencilFormat ,
4993+ .tRenderAttachmentFormatInfo = * ptFormatInfo
50414994 };
5042- for (uint32_t i = 0 ; i < uColorAttachmentCount ; i ++ )
5043- tSecondaryShaderDesc .atColorAttachmentFormats [i ] = atColorFormats [i ];
5044- ptEntry -> tSecondaryPipeline = gptGfx -> create_shader2 (ptDevice , & tSecondaryShaderDesc );
4995+ ptEntry -> tSecondaryPipeline = gptGfx -> create_shader (ptDevice , & tSecondaryShaderDesc );
50454996 pl_temp_allocator_reset (& gptDrawCtx -> tTempAllocator );
50464997 return ptEntry ;
50474998}
0 commit comments