Skip to content

Commit 4e2091b

Browse files
committed
WIP
1 parent 5c5c9b3 commit 4e2091b

5 files changed

Lines changed: 75 additions & 206 deletions

File tree

extensions/pl_graphics_metal.m

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,11 +2153,11 @@
21532153
// previous passes finish running, including this one.
21542154

21552155
// producer queue barrier
2156-
[ptDevice->tRenderEncoder barrierAfterStages:MTLStageFragment
2157-
beforeQueueStages:MTLStageVertex
2158-
visibilityOptions:MTL4VisibilityOptionDevice];
2156+
[ptDevice->tRenderEncoder barrierAfterStages:MTLStageFragment beforeQueueStages:MTLStageVertex visibilityOptions:MTL4VisibilityOptionDevice];
21592157

21602158
[ptDevice->tRenderEncoder endEncoding];
2159+
// [ptDevice->tRenderEncoder release];
2160+
ptDevice->tRenderEncoder = nil;
21612161

21622162
id<MTL4RenderCommandEncoder> tNewRenderEncoder = [ptCmdBuffer->tCmdBuffer4 renderCommandEncoderWithDescriptor:ptMetalRenderPass->atRenderPassDescriptors[gptGraphics->uCurrentFrameIndex].sbptRenderPassDescriptor[ptDevice->uCurrentSubpass]];
21632163
tNewRenderEncoder.label = @"subpass encoder";
@@ -2191,13 +2191,6 @@
21912191

21922192
ptDevice->tCurrentRenderPassHandle = tPass;
21932193
ptDevice->uCurrentSubpass = 0;
2194-
2195-
// Add a consumer queue barrier that blocks any dispatch stages in subsequent passes
2196-
// in the queue, including this one, from running until blit stages in all
2197-
// previous passes finish running, not counting this one.
2198-
// [ptDevice->tRenderEncoder barrierAfterQueueStages:MTLStageAll
2199-
// beforeStages:MTLStageAll
2200-
// visibilityOptions:MTL4VisibilityOptionDevice];
22012194
}
22022195

22032196
void
@@ -2207,15 +2200,8 @@
22072200

22082201
plRenderPass* ptRenderPass = pl_graphics_get_render_pass(ptDevice, ptDevice->tCurrentRenderPassHandle);
22092202
plMetalRenderPass* ptMetalRenderPass = &ptDevice->sbtRenderPassesHot[ptDevice->tCurrentRenderPassHandle.uIndex];
2210-
2211-
// Add a producer queue barrier that blocks any dispatch stages in subsequent passes
2212-
// in the queue, not counting this one, from running until the blit stages in all
2213-
// previous passes finish running, including this one.
2214-
// [ptDevice->tRenderEncoder barrierAfterStages:MTLStageAll
2215-
// beforeQueueStages:MTLStageAll
2216-
// visibilityOptions:MTL4VisibilityOptionDevice];
2217-
22182203
[ptDevice->tRenderEncoder endEncoding];
2204+
// [ptDevice->tRenderEncoder release];
22192205
ptDevice->tRenderEncoder = nil;
22202206
}
22212207

@@ -2264,8 +2250,7 @@
22642250
}
22652251
}
22662252

2267-
[queue signalEvent:ptFrame->tFrameBoundaryEvent
2268-
value:ptCmdBuffer->uEventValue];
2253+
[queue signalEvent:ptFrame->tFrameBoundaryEvent value:ptCmdBuffer->uEventValue];
22692254
}
22702255

22712256
void
@@ -2286,6 +2271,8 @@
22862271
void
22872272
pl_graphics_return_command_buffer(plCommandBuffer* ptCmdBuffer)
22882273
{
2274+
2275+
ptCmdBuffer->tCmdBuffer4.label = nil;
22892276
[ptCmdBuffer->tCmdBuffer4 release];
22902277
ptCmdBuffer->tCmdBuffer4 = nil;
22912278
ptCmdBuffer->ptNext = ptCmdBuffer->ptPool->ptCommandBufferFreeList;
@@ -2297,28 +2284,14 @@
22972284
{
22982285
plDevice* ptDevice = ptCmdBuffer->ptDevice;
22992286
ptDevice->tComputeEncoder = [ptCmdBuffer->tCmdBuffer4 computeCommandEncoder];
2300-
2301-
// Add a consumer queue barrier that blocks any dispatch stages in subsequent passes
2302-
// in the queue, including this one, from running until blit stages in all
2303-
// previous passes finish running, not counting this one.
2304-
// [ptDevice->tComputeEncoder barrierAfterQueueStages:MTLStageAll
2305-
// beforeStages:MTLStageAll
2306-
// visibilityOptions:MTL4VisibilityOptionDevice];
23072287
}
23082288

23092289
void
23102290
pl_graphics_end_compute_pass(plCommandBuffer* ptCmdBuffer)
23112291
{
23122292
plDevice* ptDevice = ptCmdBuffer->ptDevice;
2313-
2314-
// Add a producer queue barrier that blocks any dispatch stages in subsequent passes
2315-
// in the queue, not counting this one, from running until the blit stages in all
2316-
// previous passes finish running, including this one.
2317-
// [ptDevice->tComputeEncoder barrierAfterStages:MTLStageAll
2318-
// beforeQueueStages:MTLStageAll
2319-
// visibilityOptions:MTL4VisibilityOptionDevice];
2320-
23212293
[ptDevice->tComputeEncoder endEncoding];
2294+
// [ptDevice->tComputeEncoder release];
23222295
ptDevice->tComputeEncoder = nil;
23232296
}
23242297

@@ -2346,9 +2319,7 @@
23462319
if(tDstStages & PL_PIPELINE_STAGE_VERTEX) tDstStage |= MTLStageVertex;
23472320
if(tDstStages & PL_PIPELINE_STAGE_FRAGMENT) tDstStage |= MTLStageFragment;
23482321

2349-
[ptDevice->tComputeEncoder barrierAfterEncoderStages:tSrcStage
2350-
beforeEncoderStages:tDstStage
2351-
visibilityOptions:tOptions];
2322+
[ptDevice->tComputeEncoder barrierAfterEncoderStages:tSrcStage beforeEncoderStages:tDstStage visibilityOptions:tOptions];
23522323
}
23532324

23542325
void
@@ -2375,9 +2346,7 @@
23752346
if(tDstStages & PL_PIPELINE_STAGE_VERTEX) tDstStage |= MTLStageVertex;
23762347
if(tDstStages & PL_PIPELINE_STAGE_FRAGMENT) tDstStage |= MTLStageFragment;
23772348

2378-
[ptDevice->tComputeEncoder barrierAfterQueueStages:tSrcStage
2379-
beforeStages:tDstStage
2380-
visibilityOptions:tOptions];
2349+
[ptDevice->tComputeEncoder barrierAfterQueueStages:tSrcStage beforeStages:tDstStage visibilityOptions:tOptions];
23812350
}
23822351

23832352
void
@@ -2404,9 +2373,7 @@
24042373
if(tDstStages & PL_PIPELINE_STAGE_VERTEX) tDstStage |= MTLStageVertex;
24052374
if(tDstStages & PL_PIPELINE_STAGE_FRAGMENT) tDstStage |= MTLStageFragment;
24062375

2407-
[ptDevice->tComputeEncoder barrierAfterStages:tSrcStage
2408-
beforeQueueStages:tDstStage
2409-
visibilityOptions:tOptions];
2376+
[ptDevice->tComputeEncoder barrierAfterStages:tSrcStage beforeQueueStages:tDstStage visibilityOptions:tOptions];
24102377
}
24112378

24122379
void
@@ -2549,7 +2516,7 @@
25492516
indexCount:atDraws[i].uIndexCount
25502517
indexType:MTLIndexTypeUInt32
25512518
indexBuffer:ptDevice->sbtBuffersHot[atDraws[i].tIndexBuffer.uIndex].tBuffer.gpuAddress + atDraws[i].uIndexStart * sizeof(uint32_t)
2552-
indexBufferLength:atDraws[i].uIndexCount * sizeof(uint32_t)
2519+
indexBufferLength:ptDevice->sbtBuffersCold[atDraws[i].tIndexBuffer.uIndex].tMemoryRequirements.ulSize
25532520
instanceCount:atDraws[i].uInstanceCount
25542521
baseVertex:atDraws[i].uVertexStart
25552522
baseInstance:atDraws[i].uInstance
@@ -2778,7 +2745,7 @@
27782745
indexCount:uTriangleCount * 3
27792746
indexType:MTLIndexTypeUInt32
27802747
indexBuffer:ptDevice->sbtBuffersHot[tIndexBuffer.uIndex].tBuffer.gpuAddress + (uint64_t)uIndexBufferOffset * sizeof(uint32_t)
2781-
indexBufferLength:uTriangleCount * 3 * sizeof(uint32_t)
2748+
indexBufferLength:ptDevice->sbtBuffersCold[tIndexBuffer.uIndex].tMemoryRequirements.ulSize
27822749
instanceCount:uInstanceCount
27832750
baseVertex:uVertexBufferOffset
27842751
baseInstance:uInstanceStart

internal/demo/demo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
159159
// this path is taken only during first load, so we
160160
// allocate app memory here
161161
ptAppData = (plAppData*)PL_ALLOC(sizeof(plAppData));
162-
memset(ptAppData, 0, sizeof(plAppData));
162+
memset((void*)ptAppData, 0, sizeof(plAppData));
163163

164164
gptVfs->mount_directory("/gltf-samples", "../assets/gltf-samples/Models", PL_VFS_MOUNT_FLAGS_NONE);
165165
gptVfs->mount_directory("/environments", "../assets/development/environments", PL_VFS_MOUNT_FLAGS_NONE);
@@ -220,7 +220,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
220220
// tStarterInit.tFlags |= PL_STARTER_FLAGS_SCREEN_LOG_EXT;
221221

222222
// initial flags
223-
tStarterInit.tFlags |= PL_STARTER_FLAGS_DEPTH_BUFFER;
223+
// tStarterInit.tFlags |= PL_STARTER_FLAGS_DEPTH_BUFFER;
224224

225225
// from a graphics standpoint, the starter extension is handling device, swapchain, renderpass
226226
// etc. which we will get to in later examples
@@ -742,13 +742,13 @@ pl_app_update(plAppData* ptAppData)
742742
if(ptAppData->bShowImGuiDemo)
743743
ImGui::ShowDemoWindow(&ptAppData->bShowImGuiDemo);
744744

745-
plRenderEncoder* ptRenderEncoder = gptStarter->begin_main_pass();
746-
gptDearImGui->render(ptRenderEncoder, gptGfx->get_encoder_command_buffer(ptRenderEncoder));
745+
plCommandBuffer* ptCommandBuffer = gptStarter->begin_main_pass();
746+
gptDearImGui->render(ptCommandBuffer);
747747

748748
float fWidth = ptIO->tMainViewportSize.x;
749749
float fHeight = ptIO->tMainViewportSize.y;
750750
plDrawList2D* ptMessageDrawlist = gptScreenLog->get_drawlist(tLogOffset.x, tLogOffset.y, fWidth * 0.2f, fHeight);
751-
gptDraw->submit_2d_drawlist(ptMessageDrawlist, ptRenderEncoder, fWidth, fHeight, gptGfx->get_swapchain_info(gptStarter->get_swapchain()).tSampleCount);
751+
gptDraw->submit_2d_drawlist(ptMessageDrawlist, ptCommandBuffer, fWidth, fHeight, gptGfx->get_swapchain_info(gptStarter->get_swapchain()).tSampleCount);
752752
gptStarter->end_main_pass();
753753
PL_PROFILE_END_SAMPLE_API(gptProfile, 0);
754754
gptStarter->end_frame();

src/pl_main_glfw.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ int main(int argc, char *argv[])
469469
// main event loop
470470
while (gptIOCtx->bRunning)
471471
{
472-
472+
#if defined(__APPLE__)
473+
@autoreleasepool
474+
#endif
475+
{
473476
glfwPollEvents();
474477

475478
// queued window changes so swapchain remains valid for frame requesting changes
@@ -683,6 +686,10 @@ int main(int argc, char *argv[])
683686

684687
if(gbApisDirty)
685688
pl__check_apis();
689+
690+
#if defined(__APPLE__)
691+
#endif
692+
}
686693
}
687694

688695
// app cleanup
Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
// dear imgui: Renderer Backend for Metal
2-
// This needs to be used along with a Platform Backend (e.g. OSX)
3-
4-
// Implemented features:
5-
// [X] Renderer: User texture binding. Use 'MTLTexture' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef!
6-
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
7-
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
8-
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
9-
10-
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
11-
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
12-
// Learn about Dear ImGui:
13-
// - FAQ https://dearimgui.com/faq
14-
// - Getting Started https://dearimgui.com/getting-started
15-
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
16-
// - Introduction, links and more at the top of imgui.cpp
17-
181
#pragma once
192
#include "imgui.h" // IMGUI_IMPL_API
20-
#ifndef IMGUI_DISABLE
21-
22-
//-----------------------------------------------------------------------------
23-
// ObjC API
24-
//-----------------------------------------------------------------------------
25-
26-
#ifdef __OBJC__
273

284
@class MTL4RenderPassDescriptor;
295
@protocol MTLDevice, MTL4CommandBuffer, MTL4RenderCommandEncoder;
@@ -42,38 +18,3 @@ IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
4218

4319
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
4420
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
45-
46-
#endif
47-
48-
//-----------------------------------------------------------------------------
49-
// C++ API
50-
//-----------------------------------------------------------------------------
51-
52-
// Enable Metal C++ binding support with '#define IMGUI_IMPL_METAL_CPP' in your imconfig.h file
53-
// More info about using Metal from C++: https://developer.apple.com/metal/cpp/
54-
55-
#ifdef IMGUI_IMPL_METAL_CPP
56-
#include <Metal/Metal.hpp>
57-
#ifndef __OBJC__
58-
59-
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
60-
IMGUI_IMPL_API bool ImGui_ImplMetal_Init(MTL::Device* device);
61-
IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown();
62-
IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTL::RenderPassDescriptor* renderPassDescriptor);
63-
IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data,
64-
MTL::CommandBuffer* commandBuffer,
65-
MTL::RenderCommandEncoder* commandEncoder);
66-
67-
// Called by Init/NewFrame/Shutdown
68-
IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(MTL::Device* device);
69-
IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects();
70-
71-
// (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually.
72-
IMGUI_IMPL_API void ImGui_ImplMetal_UpdateTexture(ImTextureData* tex);
73-
74-
#endif
75-
#endif
76-
77-
//-----------------------------------------------------------------------------
78-
79-
#endif // #ifndef IMGUI_DISABLE

0 commit comments

Comments
 (0)