@@ -1074,6 +1074,60 @@ pl_renderer_create_view(plScene* ptScene, plVec2 tDimensions)
10741074 ptView -> tFinalTexture = pl__renderer_create_texture (& tRawOutputTextureDesc , "offscreen final" , 0 , PL_TEXTURE_USAGE_SAMPLED );
10751075 ptView -> tFinalTextureHandle = gptDrawBackend -> create_bind_group_for_texture (ptView -> tFinalTexture );
10761076
1077+
1078+ const plBindGroupDesc tJFABindGroupDesc = {
1079+ .ptPool = gptData -> ptBindGroupPool ,
1080+ .tLayout = gptShaderVariant -> get_compute_bind_group_layout ("jumpfloodalgo" , 0 ),
1081+ .pcDebugName = "temp jfa bind group"
1082+ };
1083+
1084+ ptView -> atJFABindGroups [0 ] = gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc );
1085+ ptView -> atJFABindGroups [1 ] = gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc );
1086+
1087+ const plBindGroupUpdateTextureData atJFATextureData0 [] =
1088+ {
1089+ {
1090+ .tTexture = ptView -> atUVMaskTexture0 ,
1091+ .uSlot = 0 ,
1092+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1093+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1094+ },
1095+ {
1096+ .tTexture = ptView -> atUVMaskTexture1 ,
1097+ .uSlot = 1 ,
1098+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1099+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1100+ }
1101+ };
1102+
1103+ const plBindGroupUpdateTextureData atJFATextureData1 [] =
1104+ {
1105+ {
1106+ .tTexture = ptView -> atUVMaskTexture1 ,
1107+ .uSlot = 0 ,
1108+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1109+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1110+ },
1111+ {
1112+ .tTexture = ptView -> atUVMaskTexture0 ,
1113+ .uSlot = 1 ,
1114+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1115+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1116+ }
1117+ };
1118+
1119+ const plBindGroupUpdateData tJFABGData0 = {
1120+ .uTextureCount = 2 ,
1121+ .atTextureBindings = atJFATextureData0
1122+ };
1123+ const plBindGroupUpdateData tJFABGData1 = {
1124+ .uTextureCount = 2 ,
1125+ .atTextureBindings = atJFATextureData1
1126+ };
1127+
1128+ gptGfx -> update_bind_group (gptData -> ptDevice , ptView -> atJFABindGroups [0 ], & tJFABGData0 );
1129+ gptGfx -> update_bind_group (gptData -> ptDevice , ptView -> atJFABindGroups [1 ], & tJFABGData1 );
1130+
10771131 // lighting bind group
10781132 const plBindGroupDesc tLightingBindGroupDesc = {
10791133 .ptPool = gptData -> ptBindGroupPool ,
@@ -1114,7 +1168,6 @@ pl_renderer_create_view(plScene* ptScene, plVec2 tDimensions)
11141168
11151169 for (uint32_t i = 0 ; i < gptGfx -> get_frames_in_flight (); i ++ )
11161170 {
1117-
11181171 const plBufferDesc tPickBufferDesc = {
11191172 .tUsage = PL_BUFFER_USAGE_STAGING | PL_BUFFER_USAGE_STORAGE ,
11201173 .szByteSize = sizeof (uint32_t ) * 2 ,
@@ -1143,6 +1196,25 @@ pl_renderer_create_view(plScene* ptScene, plVec2 tDimensions)
11431196 // buffers
11441197 ptView -> atView2Buffers [i ] = pl__renderer_create_staging_buffer (& atView2BuffersDesc , "scene" , i );
11451198
1199+ const plBindGroupDesc tDeferredBG1Desc = {
1200+ .ptPool = gptData -> ptBindGroupPool ,
1201+ .tLayout = gptShaderVariant -> get_graphics_bind_group_layout ("gbuffer_fill" , 1 ),
1202+ .pcDebugName = "view specific bindgroup"
1203+ };
1204+
1205+ const plBindGroupUpdateBufferData tView2BufferBGData = {
1206+ .tBuffer = ptView -> atView2Buffers [i ],
1207+ .uSlot = 0 ,
1208+ .szBufferRange = sizeof (plGpuViewData )
1209+ };
1210+
1211+ plBindGroupUpdateData tView2BGData = {
1212+ .uBufferCount = 1 ,
1213+ .atBufferBindings = & tView2BufferBGData
1214+ };
1215+
1216+ ptView -> atDeferredBG1 [i ] = gptGfx -> create_bind_group (gptData -> ptDevice , & tDeferredBG1Desc );
1217+ gptGfx -> update_bind_group (gptData -> ptDevice , ptView -> atDeferredBG1 [i ], & tView2BGData );
11461218
11471219 pl_temp_allocator_reset (& gptData -> tTempAllocator );
11481220
@@ -1411,6 +1483,8 @@ pl_renderer_resize_view(plView* ptView, plVec2 tDimensions)
14111483 gptGfx -> queue_texture_for_deletion (ptDevice , ptView -> tDepthTexture );
14121484 gptGfx -> queue_texture_for_deletion (ptDevice , ptView -> tPickTexture );
14131485 gptGfx -> queue_bind_group_for_deletion (ptDevice , ptView -> tLightingBindGroup );
1486+ gptGfx -> queue_bind_group_for_deletion (ptDevice , ptView -> atJFABindGroups [0 ]);
1487+ gptGfx -> queue_bind_group_for_deletion (ptDevice , ptView -> atJFABindGroups [1 ]);
14141488 ptView -> tPickTexture = pl__renderer_create_texture (& tPickTextureDesc , "pick" , 0 , PL_TEXTURE_USAGE_SAMPLED );
14151489
14161490 // textures
@@ -1424,6 +1498,59 @@ pl_renderer_resize_view(plView* ptView, plVec2 tDimensions)
14241498 ptView -> tFinalTexture = pl__renderer_create_texture (& tRawOutputTextureDesc , "offscreen final" , 0 , PL_TEXTURE_USAGE_SAMPLED );
14251499 ptView -> tFinalTextureHandle = gptDrawBackend -> create_bind_group_for_texture (ptView -> tFinalTexture );
14261500
1501+ const plBindGroupDesc tJFABindGroupDesc = {
1502+ .ptPool = gptData -> ptBindGroupPool ,
1503+ .tLayout = gptShaderVariant -> get_compute_bind_group_layout ("jumpfloodalgo" , 0 ),
1504+ .pcDebugName = "temp jfa bind group"
1505+ };
1506+
1507+ ptView -> atJFABindGroups [0 ] = gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc );
1508+ ptView -> atJFABindGroups [1 ] = gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc );
1509+
1510+ const plBindGroupUpdateTextureData atJFATextureData0 [] =
1511+ {
1512+ {
1513+ .tTexture = ptView -> atUVMaskTexture0 ,
1514+ .uSlot = 0 ,
1515+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1516+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1517+ },
1518+ {
1519+ .tTexture = ptView -> atUVMaskTexture1 ,
1520+ .uSlot = 1 ,
1521+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1522+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1523+ }
1524+ };
1525+
1526+ const plBindGroupUpdateTextureData atJFATextureData1 [] =
1527+ {
1528+ {
1529+ .tTexture = ptView -> atUVMaskTexture1 ,
1530+ .uSlot = 0 ,
1531+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1532+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1533+ },
1534+ {
1535+ .tTexture = ptView -> atUVMaskTexture0 ,
1536+ .uSlot = 1 ,
1537+ .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
1538+ .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
1539+ }
1540+ };
1541+
1542+ const plBindGroupUpdateData tJFABGData0 = {
1543+ .uTextureCount = 2 ,
1544+ .atTextureBindings = atJFATextureData0
1545+ };
1546+ const plBindGroupUpdateData tJFABGData1 = {
1547+ .uTextureCount = 2 ,
1548+ .atTextureBindings = atJFATextureData1
1549+ };
1550+
1551+ gptGfx -> update_bind_group (gptData -> ptDevice , ptView -> atJFABindGroups [0 ], & tJFABGData0 );
1552+ gptGfx -> update_bind_group (gptData -> ptDevice , ptView -> atJFABindGroups [1 ], & tJFABGData1 );
1553+
14271554 // lighting bind group
14281555 const plBindGroupDesc tLightingBindGroupDesc = {
14291556 .ptPool = gptData -> ptBindGroupPool ,
@@ -2495,36 +2622,6 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
24952622
24962623 const plEcsTypeKey tTransformComponentType = gptECS -> get_ecs_type_key_transform ();
24972624
2498- // common
2499- const plBindGroupUpdateSamplerData tSkyboxSamplerData = {
2500- .tSampler = gptData -> tSamplerLinearRepeat ,
2501- .uSlot = 1
2502- };
2503-
2504- const plBindGroupDesc tDeferredBG1Desc = {
2505- .ptPool = gptData -> aptTempGroupPools [uFrameIdx ],
2506- .tLayout = gptShaderVariant -> get_graphics_bind_group_layout ("gbuffer_fill" , 1 ),
2507- .pcDebugName = "view specific bindgroup"
2508- };
2509-
2510- const plBindGroupDesc tViewBGDesc = {
2511- .ptPool = gptData -> aptTempGroupPools [gptGfx -> get_current_frame_index ()],
2512- .tLayout = gptData -> tViewBGLayout ,
2513- .pcDebugName = "light bind group 2"
2514- };
2515-
2516- const plBindGroupDesc tPickBGDesc = {
2517- .ptPool = gptData -> aptTempGroupPools [uFrameIdx ],
2518- .tLayout = gptShaderVariant -> get_graphics_bind_group_layout ("picking" , 0 ),
2519- .pcDebugName = "temp pick bind group"
2520- };
2521-
2522- const plBindGroupDesc tJFABindGroupDesc = {
2523- .ptPool = gptData -> aptTempGroupPools [uFrameIdx ],
2524- .tLayout = gptShaderVariant -> get_compute_bind_group_layout ("jumpfloodalgo" , 0 ),
2525- .pcDebugName = "temp jfa bind group"
2526- };
2527-
25282625 const plMat4 tMVP = pl_mul_mat4 (& ptCamera -> tProjMat , & ptCamera -> tViewMat );
25292626
25302627 pl_begin_cpu_sample (gptProfile , 0 , "Scene Prep" );
@@ -2570,21 +2667,6 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
25702667 .tCameraViewProjection = pl_mul_mat4 (& ptCamera -> tProjMat , & ptCamera -> tViewMat )
25712668 };
25722669 memcpy (gptGfx -> get_buffer (ptDevice , ptView -> atView2Buffers [uFrameIdx ])-> tMemoryAllocation .pHostMapped , & tBindGroupBuffer , sizeof (plGpuViewData ));
2573-
2574- const plBindGroupUpdateBufferData tDeferredBG1BufferData = {
2575- .tBuffer = ptView -> atView2Buffers [uFrameIdx ],
2576- .uSlot = 0 ,
2577- .szBufferRange = sizeof (plGpuViewData )
2578- };
2579-
2580- plBindGroupUpdateData tDeferredBG1Data = {
2581- .uBufferCount = 1 ,
2582- .atBufferBindings = & tDeferredBG1BufferData
2583- };
2584-
2585- plBindGroupHandle tDeferredBG1 = gptGfx -> create_bind_group (ptDevice , & tDeferredBG1Desc );
2586- gptGfx -> update_bind_group (gptData -> ptDevice , tDeferredBG1 , & tDeferredBG1Data );
2587- gptGfx -> queue_bind_group_for_deletion (ptDevice , tDeferredBG1 );
25882670
25892671 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~render scene~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25902672
@@ -2696,7 +2778,7 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
26962778 .uVertexOffset = tDrawable .uStaticVertexOffset ,
26972779 .atBindGroups = {
26982780 ptScene -> atBindGroups [uFrameIdx ],
2699- tDeferredBG1
2781+ ptView -> atDeferredBG1 [ uFrameIdx ]
27002782 },
27012783 .auDynamicBufferOffsets = {
27022784 tDynamicBinding .uByteOffset
@@ -2729,6 +2811,13 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
27292811 .uBufferCount = 6 ,
27302812 .atBufferBindings = atViewBGBufferData ,
27312813 };
2814+
2815+ const plBindGroupDesc tViewBGDesc = {
2816+ .ptPool = gptData -> aptTempGroupPools [gptGfx -> get_current_frame_index ()],
2817+ .tLayout = gptData -> tViewBGLayout ,
2818+ .pcDebugName = "light bind group 2"
2819+ };
2820+
27322821 plBindGroupHandle tViewBG = gptGfx -> create_bind_group (ptDevice , & tViewBGDesc );
27332822 gptGfx -> update_bind_group (gptData -> ptDevice , tViewBG , & tViewBGData );
27342823 gptGfx -> queue_bind_group_for_deletion (ptDevice , tViewBG );
@@ -3184,56 +3273,6 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
31843273 .uThreadPerGroupZ = 1
31853274 };
31863275
3187- plBindGroupHandle atJFABindGroups [] = {
3188- gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc ),
3189- gptGfx -> create_bind_group (gptData -> ptDevice , & tJFABindGroupDesc )
3190- };
3191-
3192- const plBindGroupUpdateTextureData atJFATextureData0 [] =
3193- {
3194- {
3195- .tTexture = ptView -> atUVMaskTexture0 ,
3196- .uSlot = 0 ,
3197- .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
3198- .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
3199- },
3200- {
3201- .tTexture = ptView -> atUVMaskTexture1 ,
3202- .uSlot = 1 ,
3203- .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
3204- .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
3205- }
3206- };
3207-
3208- const plBindGroupUpdateTextureData atJFATextureData1 [] =
3209- {
3210- {
3211- .tTexture = ptView -> atUVMaskTexture1 ,
3212- .uSlot = 0 ,
3213- .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
3214- .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
3215- },
3216- {
3217- .tTexture = ptView -> atUVMaskTexture0 ,
3218- .uSlot = 1 ,
3219- .tType = PL_TEXTURE_BINDING_TYPE_STORAGE ,
3220- .tCurrentUsage = PL_TEXTURE_USAGE_STORAGE
3221- }
3222- };
3223-
3224- const plBindGroupUpdateData tJFABGData0 = {
3225- .uTextureCount = 2 ,
3226- .atTextureBindings = atJFATextureData0
3227- };
3228- const plBindGroupUpdateData tJFABGData1 = {
3229- .uTextureCount = 2 ,
3230- .atTextureBindings = atJFATextureData1
3231- };
3232- gptGfx -> update_bind_group (gptData -> ptDevice , atJFABindGroups [0 ], & tJFABGData0 );
3233- gptGfx -> update_bind_group (gptData -> ptDevice , atJFABindGroups [1 ], & tJFABGData1 );
3234- gptGfx -> queue_bind_group_for_deletion (gptData -> ptDevice , atJFABindGroups [0 ]);
3235- gptGfx -> queue_bind_group_for_deletion (gptData -> ptDevice , atJFABindGroups [1 ]);
3236-
32373276 plComputeShaderHandle tJFAShader = gptShaderVariant -> get_compute_shader ("jumpfloodalgo" , NULL );
32383277 for (uint32_t i = 0 ; i < uJumpSteps ; i ++ )
32393278 {
@@ -3262,7 +3301,7 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
32623301 ptJumpDistance -> y = tDimensions .y ;
32633302 ptJumpDistance -> z = fJumpDistance ;
32643303
3265- gptGfx -> bind_compute_bind_groups (ptJumpEncoder , tJFAShader , 0 , 1 , & atJFABindGroups [i % 2 ], 1 , & tDynamicBinding );
3304+ gptGfx -> bind_compute_bind_groups (ptJumpEncoder , tJFAShader , 0 , 1 , & ptView -> atJFABindGroups [i % 2 ], 1 , & tDynamicBinding );
32663305 gptGfx -> dispatch (ptJumpEncoder , 1 , & tDispach );
32673306
32683307 // end render pass
0 commit comments