Skip to content

Commit f9d8600

Browse files
WIP FORWARD
1 parent 7e7ab3a commit f9d8600

10 files changed

Lines changed: 62 additions & 20 deletions

extensions/pl_dear_imgui_ext.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,26 @@ static const plMemoryI *gptMemory = NULL;
5050
//-----------------------------------------------------------------------------
5151

5252
void
53-
pl_dear_imgui_initialize(plDevice *ptDevice, plSwapchain *ptSwap, plRenderPassHandle tMainRenderPass)
53+
pl_dear_imgui_initialize(plDevice *ptDevice, plSwapchain *ptSwap, const plRenderAttachmentFormatInfo* ptInfo)
5454
{
5555

5656
ImPlotContext *ptImPlotContext = ImPlot::CreateContext();
5757
gptDataRegistry->set_data("implot", ptImPlotContext);
5858

5959
#ifdef PL_CPU_BACKEND
6060
#elif defined(PL_VULKAN_BACKEND)
61+
62+
VkFormat atColorFormats[PL_MAX_RENDER_TARGETS] = {};
63+
for(uint32_t i = 0; i < ptInfo->uColorCount; i++)
64+
atColorFormats[i] = gptGfx->get_vulkan_format(ptInfo->atColorFormats[i]);
65+
VkPipelineRenderingCreateInfo tPipelineRenderingCreateInfo = {};
66+
tPipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
67+
tPipelineRenderingCreateInfo.pNext = NULL;
68+
tPipelineRenderingCreateInfo.colorAttachmentCount = ptInfo->uColorCount;
69+
tPipelineRenderingCreateInfo.pColorAttachmentFormats = atColorFormats;
70+
tPipelineRenderingCreateInfo.depthAttachmentFormat = ptInfo->tDepthFormat == 0 ? VK_FORMAT_UNDEFINED : gptGfx->get_vulkan_format(ptInfo->tDepthFormat);
71+
tPipelineRenderingCreateInfo.stencilAttachmentFormat = ptInfo->tStencilFormat == 0 ? VK_FORMAT_UNDEFINED : gptGfx->get_vulkan_format(ptInfo->tStencilFormat);
72+
6173
ImGui_ImplVulkan_InitInfo tImguiVulkanInfo = PL_ZERO_INIT;
6274
tImguiVulkanInfo.ApiVersion = gptGfx->get_vulkan_api_version();
6375
tImguiVulkanInfo.Instance = gptGfx->get_vulkan_instance();
@@ -68,11 +80,14 @@ pl_dear_imgui_initialize(plDevice *ptDevice, plSwapchain *ptSwap, plRenderPassHa
6880
// tImguiVulkanInfo.DescriptorPool = gptGfx->get_vulkan_descriptor_pool(gptDraw->get_bind_group_pool());
6981
tImguiVulkanInfo.DescriptorPoolSize = 100000;
7082
tImguiVulkanInfo.MinImageCount = 2;
83+
tImguiVulkanInfo.UseDynamicRendering = true;
7184
tImguiVulkanInfo.Allocator = gptGfx->get_vulkan_allocation_callbacks();
7285
tImguiVulkanInfo.PipelineInfoMain.MSAASamples = (VkSampleCountFlagBits)gptGfx->get_swapchain_info(ptSwap).tSampleCount;
73-
tImguiVulkanInfo.PipelineInfoMain.RenderPass = gptGfx->get_vulkan_render_pass(ptDevice, tMainRenderPass);
86+
tImguiVulkanInfo.PipelineInfoMain.PipelineRenderingCreateInfo = tPipelineRenderingCreateInfo;
87+
tImguiVulkanInfo.PipelineInfoForViewports.PipelineRenderingCreateInfo = tPipelineRenderingCreateInfo;
88+
// tImguiVulkanInfo.PipelineInfoMain.RenderPass = gptGfx->get_vulkan_render_pass(ptDevice, tMainRenderPass);
7489
tImguiVulkanInfo.PipelineInfoForViewports.MSAASamples = (VkSampleCountFlagBits)gptGfx->get_swapchain_info(ptSwap).tSampleCount;
75-
tImguiVulkanInfo.PipelineInfoForViewports.RenderPass = gptGfx->get_vulkan_render_pass(ptDevice, tMainRenderPass);
90+
// tImguiVulkanInfo.PipelineInfoForViewports.RenderPass = gptGfx->get_vulkan_render_pass(ptDevice, tMainRenderPass);
7691
gptGfx->get_swapchain_images(ptSwap, &tImguiVulkanInfo.ImageCount);
7792
ImGui_ImplVulkan_Init(&tImguiVulkanInfo);
7893
#elif defined(PL_METAL_BACKEND)
@@ -97,7 +112,7 @@ pl_dear_imgui_cleanup(void)
97112
}
98113

99114
void
100-
pl_dear_imgui_new_frame(plDevice *ptDevice, plRenderPassHandle tMainRenderPass)
115+
pl_dear_imgui_new_frame(plDevice *ptDevice)
101116
{
102117
#ifdef PL_CPU_BACKEND
103118
#elif defined(PL_VULKAN_BACKEND)

extensions/pl_dear_imgui_ext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ Index of this file:
3939
//-----------------------------------------------------------------------------
4040

4141
// external (pl_graphics_ext.h)
42-
typedef union plRenderPassHandle plRenderPassHandle;
4342
typedef union plBindGroupHandle plBindGroupHandle;
4443
typedef struct _plSwapchain plSwapchain;
4544
typedef struct _plCommandBuffer plCommandBuffer;
4645
typedef struct _plDevice plDevice;
46+
typedef struct _plRenderAttachmentFormatInfo plRenderAttachmentFormatInfo;
4747

4848
//-----------------------------------------------------------------------------
4949
// [SECTION] public api
@@ -54,11 +54,11 @@ PL_API void pl_load_dear_imgui_ext (const plApiRegistryI*, bool reload);
5454
PL_API void pl_unload_dear_imgui_ext(const plApiRegistryI*, bool reload);
5555

5656
// setup/shutdown
57-
PL_API void pl_dear_imgui_initialize(plDevice*, plSwapchain*, plRenderPassHandle tMainRenderPass);
57+
PL_API void pl_dear_imgui_initialize(plDevice*, plSwapchain*, const plRenderAttachmentFormatInfo*);
5858
PL_API void pl_dear_imgui_cleanup (void);
5959

6060
// per frame
61-
PL_API void pl_dear_imgui_new_frame(plDevice*, plRenderPassHandle tMainRenderPass);
61+
PL_API void pl_dear_imgui_new_frame(plDevice*);
6262
PL_API void pl_dear_imgui_render (plCommandBuffer*);
6363

6464
// for using texture in Dear ImGui specifically
@@ -71,11 +71,11 @@ PL_API ImTextureID pl_dear_imgui_get_texture_id_from_bindgroup(plDevice*, plBind
7171
typedef struct _plDearImGuiI
7272
{
7373
// setup/shutdown
74-
void (*initialize)(plDevice*, plSwapchain*, plRenderPassHandle tMainRenderPass);
74+
void (*initialize)(plDevice*, plSwapchain*, const plRenderAttachmentFormatInfo*);
7575
void (*cleanup) (void);
7676

7777
// per frame
78-
void (*new_frame)(plDevice*, plRenderPassHandle tMainRenderPass);
78+
void (*new_frame)(plDevice*);
7979
void (*render) (plCommandBuffer*);
8080

8181
ImTextureID (*get_texture_id_from_bindgroup)(plDevice*, plBindGroupHandle);

extensions/pl_graphics_ext.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
10491049
.calculate_mip_count = pl_graphics_calculate_mip_count,
10501050

10511051
#if defined(PL_GRAPHICS_EXPOSE_VULKAN) && defined(PL_VULKAN_BACKEND)
1052+
.get_vulkan_format = pl__vulkan_format,
10521053
.get_vulkan_instance = pl_graphics_get_vulkan_instance,
10531054
.get_vulkan_api_version = pl_graphics_get_vulkan_api_version,
10541055
.get_vulkan_device = pl_graphics_get_vulkan_device,

extensions/pl_graphics_ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ typedef struct VkDescriptorSet_T* VkDescriptorSet;
292292

293293
typedef struct VkAllocationCallbacks VkAllocationCallbacks;
294294
typedef struct VkPhysicalDeviceMemoryProperties VkPhysicalDeviceMemoryProperties;
295+
typedef enum VkFormat VkFormat;
295296
#endif
296297

297298
#ifdef PL_GRAPHICS_EXPOSE_METAL
@@ -754,6 +755,7 @@ typedef struct _plGraphicsI
754755
VkQueue (*get_vulkan_present_queue) (plDevice*);
755756
uint32_t (*get_vulkan_queue_family) (plDevice*);
756757
VkDescriptorPool (*get_vulkan_descriptor_pool) (plBindGroupPool*);
758+
VkFormat (*get_vulkan_format) (plFormat);
757759
int (*get_vulkan_sample_count) (plSwapchain*);
758760
VkCommandBuffer (*get_vulkan_command_buffer) (plCommandBuffer*);
759761
VkImageView (*get_vulkan_image_view) (plDevice*, plTextureHandle);

extensions/pl_graphics_vulkan.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,8 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21332133
else
21342134
{
21352135
tBarrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
2136-
// tBarrier.srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT;
2137-
tBarrier.srcStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT;
2136+
tBarrier.srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2137+
tBarrier.srcStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
21382138
bPreviousConfigValid = true;
21392139
}
21402140

@@ -2210,8 +2210,8 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
22102210
else
22112211
{
22122212
tBarrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
2213-
// tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT;
2214-
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT;
2213+
tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2214+
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
22152215
bNextConfigValid = true;
22162216
}
22172217

extensions/pl_renderer_ext.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,7 @@ pl_renderer_render_view(plView* ptView, const plRenderViewDesc* ptViewDesc)
32833283

32843284
// gptGfx->set_roles(ptSceneCmdBuffer, &tMainResources);
32853285
gptGfx->begin_render_pass(ptSceneCmdBuffer, tMainRenderInfo, NULL);
3286+
gptGfx->set_depth_bias(ptSceneCmdBuffer, 0.0f, 0.0f, 0.0f);
32863287

32873288
const plVec2 tDimensions = ptView->tTargetSize;
32883289

@@ -3396,15 +3397,15 @@ pl_renderer_render_view(plView* ptView, const plRenderViewDesc* ptViewDesc)
33963397
.tLoadOp = PL_LOAD_OP_LOAD,
33973398
.tStoreOp = PL_STORE_OP_STORE,
33983399
.tUsage = PL_TEXTURE_USAGE_COLOR_ATTACHMENT,
3399-
.tClearColor = {0.0f, 0.0f, 0.0f, 1.0f}
3400+
.tClearColor = {0.0f, 0.0f, 0.0f, 0.0f}
34003401
}
34013402
},
34023403
.tDepthAttachment = {
34033404
.tTexture = ptView->tDepthTexture,
34043405
.tLoadOp = PL_LOAD_OP_LOAD,
34053406
.tStoreOp = PL_STORE_OP_STORE,
34063407
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
3407-
.fClearZ = 1.0f
3408+
.fClearZ = 0.0f
34083409
},
34093410
.tStencilAttachment = {
34103411
.tTexture = ptView->tDepthTexture,

extensions/pl_renderer_internal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ pl__render_view_debug_pass(plView* ptView, const plCamera* ptCamera, const plCam
39353935
.tLoadOp = PL_LOAD_OP_LOAD,
39363936
.tStoreOp = PL_STORE_OP_STORE,
39373937
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
3938-
.fClearZ = 1.0f
3938+
.fClearZ = 0.0f
39393939
},
39403940
.tStencilAttachment = {
39413941
.tTexture = ptView->tDepthTexture,
@@ -4197,7 +4197,7 @@ pl__render_view_uv_pass(plView* ptView)
41974197
.tLoadOp = PL_LOAD_OP_LOAD,
41984198
.tStoreOp = PL_STORE_OP_STORE,
41994199
.tUsage = PL_TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT,
4200-
.fClearZ = 1.0f
4200+
.fClearZ = 0.0f
42014201
},
42024202
.tStencilAttachment = {
42034203
.tTexture = ptView->tDepthTexture,

extensions/pl_starter_ext.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,22 @@ pl_starter_begin_main_pass(void)
674674
return gptStarterCtx->ptCurrentCommandBuffer;
675675
}
676676

677+
void
678+
pl_starter_get_render_attachment_info(plRenderAttachmentFormatInfo* ptInfoOut)
679+
{
680+
plRenderAttachmentFormatInfo tRenderAttachmentFormatInfo = {
681+
.uColorCount = 1,
682+
.atColorFormats = {
683+
gptGfx->get_swapchain_info(gptStarterCtx->ptSwapchain).tFormat
684+
}
685+
};
686+
687+
if(gptStarterCtx->tFlags & PL_STARTER_FLAGS_DEPTH_BUFFER)
688+
tRenderAttachmentFormatInfo.tDepthFormat = PL_FORMAT_D32_FLOAT_S8_UINT;
689+
690+
*ptInfoOut = tRenderAttachmentFormatInfo;
691+
}
692+
677693
void
678694
pl_starter_end_main_pass(void)
679695
{
@@ -1325,6 +1341,7 @@ pl_load_starter_ext(plApiRegistryI* ptApiRegistry, bool bReload)
13251341
.end_frame = pl_starter_end_frame,
13261342
.begin_main_pass = pl_starter_begin_main_pass,
13271343
.end_main_pass = pl_starter_end_main_pass,
1344+
.get_render_attachment_info = pl_starter_get_render_attachment_info,
13281345
.resize = pl_starter_resize,
13291346
.create_device = pl_starter_create_device,
13301347
.get_device = pl_starter_get_device,

extensions/pl_starter_ext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ typedef struct _plStarterI
237237
// resize
238238
void (*resize)(void);
239239

240+
void (*get_render_attachment_info)(plRenderAttachmentFormatInfo*);
241+
240242
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~mid level API~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241243

242244
// command buffers

internal/demo/demo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
323323

324324
pl__find_models(ptAppData);
325325

326-
gptDearImGui->initialize(ptAppData->ptDevice, gptStarter->get_swapchain(), gptStarter->get_render_pass());
326+
plRenderAttachmentFormatInfo tRenderInfo = {};
327+
gptStarter->get_render_attachment_info(&tRenderInfo);
328+
gptDearImGui->initialize(ptAppData->ptDevice, gptStarter->get_swapchain(), &tRenderInfo);
327329
// ImGui::GetIO().ConfigFlags &= ~ImGuiBackendFlags_PlatformHasViewports;
328330
ImPlot::SetCurrentContext((ImPlotContext*)ptDataRegistry->get_data("implot"));
329331
ImGuiIO& tImGuiIO = ImGui::GetIO();
@@ -412,7 +414,7 @@ pl_app_update(plAppData* ptAppData)
412414

413415
gptRenderer->begin_frame();
414416

415-
gptDearImGui->new_frame(ptAppData->ptDevice, gptStarter->get_render_pass());
417+
gptDearImGui->new_frame(ptAppData->ptDevice);
416418

417419
if(ptAppData->bResize)
418420
{
@@ -748,7 +750,9 @@ pl_app_update(plAppData* ptAppData)
748750
float fWidth = ptIO->tMainViewportSize.x;
749751
float fHeight = ptIO->tMainViewportSize.y;
750752
plDrawList2D* ptMessageDrawlist = gptScreenLog->get_drawlist(tLogOffset.x, tLogOffset.y, fWidth * 0.2f, fHeight);
751-
gptDraw->submit_2d_drawlist(ptMessageDrawlist, ptCommandBuffer, fWidth, fHeight, gptGfx->get_swapchain_info(gptStarter->get_swapchain()).tSampleCount);
753+
plRenderAttachmentFormatInfo tRenderInfo = {};
754+
gptStarter->get_render_attachment_info(&tRenderInfo);
755+
gptDraw->submit_2d_drawlist(ptMessageDrawlist, ptCommandBuffer, fWidth, fHeight, gptGfx->get_swapchain_info(gptStarter->get_swapchain()).tSampleCount, &tRenderInfo);
752756
gptStarter->end_main_pass();
753757
PL_PROFILE_END_SAMPLE_API(gptProfile, 0);
754758
gptStarter->end_frame();

0 commit comments

Comments
 (0)