Skip to content

Commit 9f1816a

Browse files
committed
WIP
1 parent 3439b83 commit 9f1816a

15 files changed

Lines changed: 94 additions & 63 deletions

assets/core/scenes/scene-helmet.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"bPhysicsDebugDraw": false,
1010
"bDrawAllBoundingBoxes": false,
1111
"bFrustumCulling": true,
12-
"bMSAA": false,
12+
"bMSAA": true,
1313
"szIndexBufferSize": 32000000,
1414
"szVertexBufferSize": 32000000,
1515
"szDataBufferSize": 32000000,

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
@@ -1063,6 +1063,7 @@ pl_load_graphics_ext(plApiRegistryI* ptApiRegistry, bool bReload)
10631063
.get_vulkan_image_view = pl_graphics_get_vulkan_image_view,
10641064
.get_vulkan_sampler = pl_graphics_get_vulkan_sampler,
10651065
.get_vulkan_descriptor_set = pl_graphics_get_vulkan_descriptor_set,
1066+
.get_vulkan_format = pl__vulkan_format,
10661067
.get_vulkan_allocation_callbacks = pl_graphics_get_vulkan_allocation_callbacks,
10671068
.get_vulkan_memory_properties = pl_graphics_get_vulkan_memory_properties,
10681069
#endif

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
@@ -762,6 +763,7 @@ typedef struct _plGraphicsI
762763
VkDescriptorSet (*get_vulkan_descriptor_set) (plDevice*, plBindGroupHandle);
763764
VkPhysicalDeviceMemoryProperties (*get_vulkan_memory_properties) (plDevice*);
764765
const VkAllocationCallbacks* (*get_vulkan_allocation_callbacks)(void);
766+
VkFormat (*get_vulkan_format) (plFormat);
765767
#endif
766768

767769
#ifdef PL_GRAPHICS_EXPOSE_METAL

extensions/pl_graphics_vulkan.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21392139
}
21402140
else
21412141
{
2142-
tBarrier.srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2142+
tBarrier.srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT;
21432143
tBarrier.srcStageMask |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
21442144
}
21452145
bPreviousConfigValid = true;
@@ -2198,7 +2198,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21982198
}
21992199
else
22002200
{
2201-
tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT;
2201+
tBarrier.dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT;
22022202
tBarrier.dstStageMask |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT;
22032203
}
22042204
bNextConfigValid = true;
@@ -3843,7 +3843,7 @@ pl_graphics_create_device(const plDeviceInit* ptInit)
38433843
#endif
38443844

38453845
apcDeviceExts[uDeviceExtensionCount++] = VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME;
3846-
apcDeviceExts[uDeviceExtensionCount++] = VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME;
3846+
// apcDeviceExts[uDeviceExtensionCount++] = VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME;
38473847

38483848
// get device features
38493849
VkPhysicalDeviceFeatures tDeviceFeatures = {0};

extensions/pl_renderer_internal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5518,7 +5518,7 @@ pl__renderer_update_probes(plScene* ptScene)
55185518
pl__render_view_deferred_lighting_pass(ptScene, ptCmdBuffer, ptProbe->tViewBG, &tDeferredLightingPassInfo);
55195519

55205520
// gptGfx->next_subpass(ptCmdBuffer, NULL);
5521-
gptGfx->intra_pass_barrier(ptCmdBuffer, PL_PIPELINE_STAGE_FRAGMENT, PL_PIPELINE_STAGE_VERTEX, PL_BARRIER_SCOPE_ALL);
5521+
// gptGfx->intra_pass_barrier(ptCmdBuffer, PL_PIPELINE_STAGE_FRAGMENT, PL_PIPELINE_STAGE_VERTEX, PL_BARRIER_SCOPE_ALL);
55225522

55235523
if(ptScene->tSkyboxTexture.uIndex != 0 && ptProbeComp->tFlags & PL_ENVIRONMENT_PROBE_FLAGS_INCLUDE_SKY)
55245524
{

extensions/pl_starter_ext.c

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,12 @@ pl_starter_begin_main_pass(void)
611611
},
612612
.atColorAttachments = {
613613
{
614-
.tTexture = atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
614+
.tTexture = (gptStarterCtx->tFlags & PL_STARTER_FLAGS_MSAA) ? gptStarterCtx->tResolveTexture : atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
615615
.tLoadOp = PL_LOAD_OP_CLEAR,
616616
.tStoreOp = PL_STORE_OP_STORE,
617617
.tUsage = PL_TEXTURE_USAGE_COLOR_ATTACHMENT,
618-
.tClearColor = {0.0f, 0.0f, 0.0f, 1.0f}
618+
.tClearColor = {0.0f, 0.0f, 0.0f, 1.0f},
619+
.tResolveTexture = (gptStarterCtx->tFlags & PL_STARTER_FLAGS_MSAA) ? atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)] : (plTextureHandle){0}
619620
}
620621
},
621622
.tDepthAttachment = {
@@ -635,9 +636,18 @@ pl_starter_begin_main_pass(void)
635636
};
636637

637638
// begin main renderpass (directly to swapchain)
638-
gptGfx->change_texture_role(ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
639-
PL_PASS_RESOURCE_ROLE_NONE, PL_PASS_RESOURCE_ACCESS_NONE,
640-
PL_PASS_RESOURCE_ROLE_ATTACHMENT, PL_PASS_RESOURCE_ACCESS_WRITE);
639+
if(gptStarterCtx->tFlags & PL_STARTER_FLAGS_MSAA)
640+
{
641+
gptGfx->change_texture_role(ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
642+
PL_PASS_RESOURCE_ROLE_NONE, PL_PASS_RESOURCE_ACCESS_NONE,
643+
PL_PASS_RESOURCE_ROLE_STORAGE, PL_PASS_RESOURCE_ACCESS_WRITE);
644+
}
645+
else
646+
{
647+
gptGfx->change_texture_role(ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
648+
PL_PASS_RESOURCE_ROLE_NONE, PL_PASS_RESOURCE_ACCESS_NONE,
649+
PL_PASS_RESOURCE_ROLE_ATTACHMENT, PL_PASS_RESOURCE_ACCESS_WRITE);
650+
}
641651

642652
gptGfx->begin_render_pass(ptCurrentCommandBuffer, tRenderInfo, NULL);
643653
gptStarterCtx->ptCurrentCommandBuffer = ptCurrentCommandBuffer;
@@ -662,6 +672,22 @@ pl_starter_begin_main_pass(void)
662672
return gptStarterCtx->ptCurrentCommandBuffer;
663673
}
664674

675+
void
676+
pl_starter_get_render_attachment_info(plRenderAttachmentFormatInfo* ptInfoOut)
677+
{
678+
plRenderAttachmentFormatInfo tRenderAttachmentFormatInfo = {
679+
.uColorCount = 1,
680+
.atColorFormats = {
681+
gptGfx->get_swapchain_info(gptStarterCtx->ptSwapchain).tFormat
682+
}
683+
};
684+
685+
if(gptStarterCtx->tFlags & PL_STARTER_FLAGS_DEPTH_BUFFER)
686+
tRenderAttachmentFormatInfo.tDepthFormat = PL_FORMAT_D32_FLOAT_S8_UINT;
687+
688+
*ptInfoOut = tRenderAttachmentFormatInfo;
689+
}
690+
665691
void
666692
pl_starter_end_main_pass(void)
667693
{
@@ -725,9 +751,18 @@ pl_starter_end_main_pass(void)
725751
uint32_t uImageCount = 0;
726752
plTextureHandle* atSwapchainImages = gptGfx->get_swapchain_images(gptStarterCtx->ptSwapchain, &uImageCount);
727753

728-
gptGfx->change_texture_role(gptStarterCtx->ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
729-
PL_PASS_RESOURCE_ROLE_ATTACHMENT, PL_PASS_RESOURCE_ACCESS_WRITE,
730-
PL_PASS_RESOURCE_ROLE_PRESENT, PL_PASS_RESOURCE_ACCESS_READ);
754+
if(gptStarterCtx->tFlags & PL_STARTER_FLAGS_MSAA)
755+
{
756+
gptGfx->change_texture_role(gptStarterCtx->ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
757+
PL_PASS_RESOURCE_ROLE_STORAGE, PL_PASS_RESOURCE_ACCESS_WRITE,
758+
PL_PASS_RESOURCE_ROLE_PRESENT, PL_PASS_RESOURCE_ACCESS_READ);
759+
}
760+
else
761+
{
762+
gptGfx->change_texture_role(gptStarterCtx->ptCurrentCommandBuffer, atSwapchainImages[gptGfx->get_current_swapchain_image_index(gptStarterCtx->ptSwapchain)],
763+
PL_PASS_RESOURCE_ROLE_ATTACHMENT, PL_PASS_RESOURCE_ACCESS_WRITE,
764+
PL_PASS_RESOURCE_ROLE_PRESENT, PL_PASS_RESOURCE_ACCESS_READ);
765+
}
731766

732767
// end recording
733768
gptGfx->end_command_recording(gptStarterCtx->ptCurrentCommandBuffer);
@@ -1332,6 +1367,7 @@ pl_load_starter_ext(plApiRegistryI* ptApiRegistry, bool bReload)
13321367
.deactivate_depth_buffer = pl_starter_deactivate_depth_buffer,
13331368
.activate_vsync = pl_starter_activate_vsync,
13341369
.deactivate_vsync = pl_starter_deactivate_vsync,
1370+
.get_render_attachment_info = pl_starter_get_render_attachment_info,
13351371
};
13361372
pl_set_api(ptApiRegistry, plStarterI, &tApi);
13371373

extensions/pl_starter_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ typedef struct _plStarterI
269269
uint64_t (*increment_current_timeline_value)(void);
270270
plTimelineSemaphore* (*get_last_timeline_semaphore) (void);
271271
uint64_t (*get_last_timeline_value) (void);
272+
void (*get_render_attachment_info) (plRenderAttachmentFormatInfo*);
272273

273274
// resource setting
274275
void (*set_swapchain)(plSwapchain*);

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)