@@ -62,7 +62,7 @@ typedef struct _plAppData
6262 // offscreen rendering
6363 bool bResize ;
6464 plSamplerHandle tDefaultSampler ;
65- plRenderPassHandle tOffscreenRenderPass ;
65+ // plRenderPassHandle tOffscreenRenderPass;
6666 plVec2 tOffscreenSize ;
6767 plTextureHandle tColorTexture ;
6868 plBindGroupHandle tColorTextureBg ;
@@ -266,54 +266,6 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
266266 // NOTE: Render passes directly map to render passes in Vulkan. In Metal
267267 // we emulate them by places appropriate barriers & fences.
268268
269- plRenderPassAttachments atAttachmentSets [PL_MAX_FRAMES_IN_FLIGHT ] = {0 };
270-
271- for (uint32_t i = 0 ; i < gptGfx -> get_frames_in_flight (); i ++ )
272- {
273- // add textures to attachment set for render pass
274- atAttachmentSets [i ].atViewAttachments [0 ] = ptAppData -> tDepthTexture ;
275- atAttachmentSets [i ].atViewAttachments [1 ] = ptAppData -> tColorTexture ;
276- }
277-
278- // create offscreen renderpass layout
279- const plRenderPassLayoutDesc tRenderPassLayoutDesc = {
280- .atRenderTargets = {
281- { .tFormat = PL_FORMAT_D32_FLOAT_S8_UINT , .bDepth = true }, // depth buffer
282- { .tFormat = PL_FORMAT_R32G32B32A32_FLOAT } // color
283- },
284- .atSubpasses = {
285- {
286- .uRenderTargetCount = 2 ,
287- .auRenderTargets = {0 , 1 }, // these are indices into the render targets above (depth/resolve must be before colors)
288- },
289- }
290- };
291-
292- // create offscreen renderpass
293- const plRenderPassDesc tRenderPassDesc = {
294- .tLayout = gptGfx -> create_render_pass_layout (ptDevice , & tRenderPassLayoutDesc ),
295- .tDepthTarget = {
296- .tLoadOp = PL_LOAD_OP_CLEAR ,
297- .tStoreOp = PL_STORE_OP_DONT_CARE ,
298- .tStencilLoadOp = PL_LOAD_OP_CLEAR ,
299- .tStencilStoreOp = PL_STORE_OP_DONT_CARE ,
300- .tPreviousUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ,
301- .tNextUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ,
302- .fClearZ = 1.0f
303- },
304- .atColorTargets = {
305- {
306- .tLoadOp = PL_LOAD_OP_CLEAR ,
307- .tStoreOp = PL_STORE_OP_STORE ,
308- .tPreviousUsage = PL_TEXTURE_USAGE_SAMPLED ,
309- .tNextUsage = PL_TEXTURE_USAGE_SAMPLED ,
310- .tClearColor = {0.0f , 0.0f , 0.0f , 1.0f }
311- }
312- },
313- .tDimensions = {.x = ptAppData -> tOffscreenSize .x , .y = ptAppData -> tOffscreenSize .y }
314- };
315- ptAppData -> tOffscreenRenderPass = gptGfx -> create_render_pass (ptDevice , & tRenderPassDesc , atAttachmentSets );
316-
317269 // return app memory
318270 return ptAppData ;
319271}
@@ -442,35 +394,102 @@ pl_app_update(plAppData* ptAppData)
442394 // pass below)
443395
444396 // retrieve command buffer (already in recording state)
445- plCommandBuffer * ptCommandBuffer = gptStarter -> get_command_buffer ();
397+ plFormat tFormat = PL_FORMAT_R32G32B32A32_FLOAT ;
398+ plCommandBuffer * ptCommandBuffer = NULL ;
399+ #if 1
400+ ptCommandBuffer = gptStarter -> get_command_buffer ();
401+
402+ plRenderInfo tRenderInfo = {
403+ .tRenderArea = {
404+ .tMin = {0 },
405+ .tMax = ptAppData -> tOffscreenSize
406+ },
407+ .atColorAttachments = {
408+ {
409+ .tTexture = ptAppData -> tColorTexture ,
410+ .tLoadOp = PL_LOAD_OP_CLEAR ,
411+ .tStoreOp = PL_STORE_OP_STORE ,
412+ .tUsage = PL_TEXTURE_USAGE_COLOR_ATTACHMENT ,
413+ .tClearColor = {0.0f , 0.0f , 0.0f , 1.0f }
414+ }
415+ },
416+ .tDepthAttachment = {
417+ .tTexture = ptAppData -> tDepthTexture ,
418+ .tLoadOp = PL_LOAD_OP_CLEAR ,
419+ .tStoreOp = PL_STORE_OP_DONT_CARE ,
420+ .tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ,
421+ .fClearZ = 1.0f
422+ },
423+ .tStencilAttachment = {
424+ .tTexture = ptAppData -> tDepthTexture ,
425+ .tLoadOp = PL_LOAD_OP_CLEAR ,
426+ .tStoreOp = PL_STORE_OP_DONT_CARE ,
427+ .tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT ,
428+ .uClearStencil = 0
429+ }
430+ };
431+
432+ // begin main renderpass (directly to swapchain)
433+ plPassTextureResource atTextureResources [] = {
434+ {
435+ .tHandle = ptAppData -> tColorTexture ,
436+ .tStages = PL_SHADER_STAGE_FRAGMENT | PL_SHADER_STAGE_VERTEX ,
437+ .tAccess = PL_PASS_RESOURCE_ACCESS_WRITE ,
438+ .eUsage = PL_PASS_RESOURCE_ROLE_ATTACHMENT
439+ },
440+ {
441+ .tHandle = ptAppData -> tDepthTexture ,
442+ .tStages = PL_SHADER_STAGE_FRAGMENT | PL_SHADER_STAGE_VERTEX ,
443+ .tAccess = PL_PASS_RESOURCE_ACCESS_WRITE ,
444+ .eUsage = PL_PASS_RESOURCE_ROLE_ATTACHMENT
445+ }
446+ };
447+ plPassResources tResources = {
448+ .atTextures = atTextureResources ,
449+ .uTextureCount = 2
450+ };
446451
447452 // begin offscreen renderpass
448- plRenderEncoder * ptEncoder = gptGfx -> begin_render_pass (ptCommandBuffer , ptAppData -> tOffscreenRenderPass , NULL );
453+ gptGfx -> set_roles (ptCommandBuffer , & tResources );
454+ gptGfx -> begin_render_pass (ptCommandBuffer , tRenderInfo , & tResources );
449455
450456 // submit our 3D drawlist
457+
458+ plRenderAttachmentFormatInfo tInfo = {
459+ .uColorCount = 1 ,
460+ .atColorFormats = {
461+ PL_FORMAT_R32G32B32A32_FLOAT
462+ },
463+ .tDepthFormat = PL_FORMAT_D32_FLOAT_S8_UINT ,
464+ .tStencilFormat = PL_FORMAT_D32_FLOAT_S8_UINT
465+ };
466+
451467 gptDraw -> submit_3d_drawlist (ptAppData -> pt3dDrawlist ,
452- ptEncoder ,
468+ ptCommandBuffer ,
453469 ptAppData -> tOffscreenSize .x ,
454470 ptAppData -> tOffscreenSize .y ,
455471 & ptAppData -> tCamera .tViewProjMat ,
456- PL_DRAW_FLAG_DEPTH_TEST | PL_DRAW_FLAG_DEPTH_WRITE , 1 );
472+ PL_DRAW_FLAG_DEPTH_TEST | PL_DRAW_FLAG_DEPTH_WRITE , 1 , & tInfo );
457473
458474 // end offscreen render pass
459- gptGfx -> end_render_pass (ptEncoder );
475+ gptGfx -> end_render_pass (ptCommandBuffer );
476+ gptGfx -> reset_roles (ptCommandBuffer );
460477
461478 // submit and return our command buffer
462479 gptStarter -> submit_command_buffer (ptCommandBuffer );
480+ #endif
463481
464482 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~main~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
465483
466484 // add full screen quad for offscreen render
467485 gptDraw -> add_image (ptAppData -> ptFGLayer , ptAppData -> tColorTextureBg .uData , (plVec2 ){0 }, ptIO -> tMainViewportSize );
468486
469487 // begin main renderpass (directly to swapchain)
470- plRenderEncoder * ptMainEncoder = gptStarter -> begin_main_pass ();
488+ ptCommandBuffer = gptStarter -> begin_main_pass ();
471489
472490 // submit drawlists
473- gptDraw -> submit_2d_drawlist (ptAppData -> ptAppDrawlist , ptMainEncoder , ptIO -> tMainViewportSize .x , ptIO -> tMainViewportSize .y , 1 );
491+ tInfo .atColorFormats [0 ] = gptGfx -> get_swapchain_info (gptStarter -> get_swapchain ()).tFormat ;
492+ gptDraw -> submit_2d_drawlist (ptAppData -> ptAppDrawlist , ptCommandBuffer , ptIO -> tMainViewportSize .x , ptIO -> tMainViewportSize .y , 1 , & tInfo );
474493
475494 // allows the starter extension to handle some things then ends the main pass
476495 gptStarter -> end_main_pass ();
@@ -551,15 +570,15 @@ resize_offscreen_resources(plAppData* ptAppData)
551570 };
552571 gptGfx -> update_bind_group (ptDevice , ptAppData -> tColorTextureBg , & tBGData );
553572
554- plRenderPassAttachments atAttachmentSets [PL_MAX_FRAMES_IN_FLIGHT ] = {0 };
573+ // plRenderPassAttachments atAttachmentSets[PL_MAX_FRAMES_IN_FLIGHT] = {0};
555574
556- for (uint32_t i = 0 ; i < gptGfx -> get_frames_in_flight (); i ++ )
557- {
558- // add textures to attachment set for render pass
559- atAttachmentSets [i ].atViewAttachments [0 ] = ptAppData -> tDepthTexture ;
560- atAttachmentSets [i ].atViewAttachments [1 ] = ptAppData -> tColorTexture ;
561- }
575+ // for(uint32_t i = 0; i < gptGfx->get_frames_in_flight(); i++)
576+ // {
577+ // // add textures to attachment set for render pass
578+ // atAttachmentSets[i].atViewAttachments[0] = ptAppData->tDepthTexture;
579+ // atAttachmentSets[i].atViewAttachments[1] = ptAppData->tColorTexture;
580+ // }
562581
563582 // don't create new render pass, just update the attachments
564- gptGfx -> update_render_pass_attachments (ptDevice , ptAppData -> tOffscreenRenderPass , ptAppData -> tOffscreenSize , atAttachmentSets );
583+ // gptGfx->update_render_pass_attachments(ptDevice, ptAppData->tOffscreenRenderPass, ptAppData->tOffscreenSize, atAttachmentSets);
565584}
0 commit comments