diff --git a/src/Engine/Graphics/Metal/RenderPass.mm b/src/Engine/Graphics/Metal/RenderPass.mm index 4f04c38..108a8e3 100644 --- a/src/Engine/Graphics/Metal/RenderPass.mm +++ b/src/Engine/Graphics/Metal/RenderPass.mm @@ -25,7 +25,6 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra desc->setStoreAction(cast(color.getStoreOp())); desc->setLevel(0); if (!layout.resolveAttachments.empty()) { - const auto& resolve = layout.resolveAttachments[i]; desc->setResolveLevel(0); // store multisampled attachment as well if(color.getStoreOp() == Gfx::SE_ATTACHMENT_STORE_OP_STORE) { @@ -33,7 +32,6 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra } else { desc->setStoreAction(MTL::StoreActionMultisampleResolve); } - desc->setResolveTexture(resolve.getTexture().cast()->getImage()); } } if (layout.depthAttachment.getTexture() != nullptr) { @@ -49,7 +47,6 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra } else { depth->setStoreAction(MTL::StoreActionMultisampleResolve); } - depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast()->getImage()); } } // TODO: stencil @@ -61,9 +58,16 @@ void RenderPass::updateRenderPass() { const auto& color = layout.colorAttachments[i]; auto desc = renderPass->colorAttachments()->object(i); desc->setTexture(color.getTexture().cast()->getImage()); + if (!layout.resolveAttachments.empty()) { + const auto& resolve = layout.resolveAttachments[i]; + desc->setResolveTexture(resolve.getTexture().cast()->getImage()); + } } if (layout.depthAttachment.getTexture() != nullptr) { auto depth = renderPass->depthAttachment(); depth->setTexture(layout.depthAttachment.getTexture().cast()->getImage()); + if (layout.depthResolveAttachment.getTexture() != nullptr) { + depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast()->getImage()); + } } } diff --git a/src/Engine/Graphics/Metal/Window.h b/src/Engine/Graphics/Metal/Window.h index 8218489..30f52f9 100644 --- a/src/Engine/Graphics/Metal/Window.h +++ b/src/Engine/Graphics/Metal/Window.h @@ -52,6 +52,7 @@ class Window : public Gfx::Window { CA::MetalLayer* metalLayer; CA::MetalDrawable* drawable; OTexture2D backBuffer; + OEvent renderDoneSemaphore; std::function keyCallback; std::function mouseMoveCallback; diff --git a/src/Engine/Graphics/Metal/Window.mm b/src/Engine/Graphics/Metal/Window.mm index 2645508..48712a6 100644 --- a/src/Engine/Graphics/Metal/Window.mm +++ b/src/Engine/Graphics/Metal/Window.mm @@ -92,9 +92,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic [[metalWindow contentView] setLayer:(__bridge id)metalLayer]; [[metalWindow contentView] setWantsLayer:YES]; framebufferFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB; - - drawable = metalLayer->nextDrawable(); - createBackBuffer(); } Window::~Window() { glfwDestroyWindow(static_cast(windowHandle)); } @@ -104,6 +101,8 @@ void Window::show() { glfwShowWindow(windowHandle); } void Window::pollInput() { glfwPollEvents(); } void Window::beginFrame() { + drawable = metalLayer->nextDrawable(); + createBackBuffer(); static double start = glfwGetTime(); double end = glfwGetTime(); currentFrameDelta = end - start; @@ -112,13 +111,10 @@ void Window::beginFrame() { } void Window::endFrame() { - graphics->waitDeviceIdle(); - graphics->getQueue()->getCommands()->present(drawable); graphics->getQueue()->submitCommands(); + graphics->getQueue()->getCommands()->present(drawable); currentFrameIndex++; drawable->release(); - drawable = metalLayer->nextDrawable(); - createBackBuffer(); } void Window::onWindowCloseEvent() {} @@ -181,6 +177,7 @@ void Window::createBackBuffer() { .samples = static_cast(buf->sampleCount()), }, buf); + renderDoneSemaphore = new Event(graphics); } Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) { diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 117205d..d3aa5da 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -410,7 +410,7 @@ void BasePass::publishOutputs() { depthAttachment = Gfx::RenderTargetAttachment(basePassDepth, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE); msDepthAttachment = Gfx::RenderTargetAttachment(msBasePassDepth, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, @@ -418,7 +418,7 @@ void BasePass::publishOutputs() { msDepthAttachment.clear.depthStencil.depth = 0.0f; colorAttachment = Gfx::RenderTargetAttachment(viewport, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, - Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_DONT_CARE); + Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE); msColorAttachment = Gfx::RenderTargetAttachment(msBasePassColor, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,