Fixing metal swapchain
This commit is contained in:
@@ -25,6 +25,7 @@ void Command::beginRenderPass(PRenderPass renderPass) {
|
||||
blitEncoder->endEncoding();
|
||||
blitEncoder = nullptr;
|
||||
}
|
||||
renderPass->updateRenderPass();
|
||||
parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ void Graphics::init(GraphicsInitializer)
|
||||
queue = new CommandQueue(this);
|
||||
ioQueue = new IOCommandQueue(this);
|
||||
cache = new PipelineCache(this, "pipelines.metal");
|
||||
meshShadingEnabled = true;
|
||||
meshShadingEnabled = false;
|
||||
}
|
||||
|
||||
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
|
||||
|
||||
@@ -12,6 +12,7 @@ class RenderPass : public Gfx::RenderPass
|
||||
public:
|
||||
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport);
|
||||
virtual ~RenderPass();
|
||||
void updateRenderPass();
|
||||
MTL::RenderPassDescriptor* getDescriptor() const
|
||||
{
|
||||
return renderPass;
|
||||
@@ -20,8 +21,6 @@ private:
|
||||
PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
MTL::RenderPassDescriptor* renderPass;
|
||||
MTL::RenderPassDepthAttachmentDescriptor* depth;
|
||||
MTL::RenderPassStencilAttachmentDescriptor* stencil;
|
||||
};
|
||||
DEFINE_REF(RenderPass)
|
||||
} // namespace Metal
|
||||
|
||||
@@ -7,55 +7,53 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
|
||||
Array<Gfx::SubPassDependency> dependencies,
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
|
||||
Gfx::PViewport viewport)
|
||||
: Gfx::RenderPass(layout, dependencies), graphics(graphics),
|
||||
viewport(viewport) {
|
||||
renderPass = MTL::RenderPassDescriptor::alloc()->init();
|
||||
: Gfx::RenderPass(layout, dependencies), graphics(graphics), viewport(viewport) {
|
||||
renderPass = MTL::RenderPassDescriptor::renderPassDescriptor();
|
||||
renderPass->setRenderTargetArrayLength(1);
|
||||
renderPass->setRenderTargetWidth(viewport->getWidth());
|
||||
renderPass->setRenderTargetHeight(viewport->getHeight());
|
||||
renderPass->setDefaultRasterSampleCount(viewport->getSamples());
|
||||
|
||||
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
|
||||
const auto &color = layout.colorAttachments[i];
|
||||
MTL::RenderPassColorAttachmentDescriptor *desc =
|
||||
renderPass->colorAttachments()->object(i);
|
||||
desc->setClearColor(MTL::ClearColor(
|
||||
color.clear.color.float32[0], color.clear.color.float32[1],
|
||||
color.clear.color.float32[2], color.clear.color.float32[3]));
|
||||
const auto& color = layout.colorAttachments[i];
|
||||
MTL::RenderPassColorAttachmentDescriptor* desc = renderPass->colorAttachments()->object(i);
|
||||
desc->setClearColor(MTL::ClearColor(color.clear.color.float32[0], color.clear.color.float32[1],
|
||||
color.clear.color.float32[2], color.clear.color.float32[3]));
|
||||
desc->setLoadAction(cast(color.getLoadOp()));
|
||||
desc->setStoreAction(cast(color.getStoreOp()));
|
||||
desc->setLevel(0);
|
||||
desc->setTexture(color.getTexture().cast<TextureBase>()->getTexture());
|
||||
if (!layout.resolveAttachments.empty()) {
|
||||
const auto &resolve = layout.resolveAttachments[i];
|
||||
const auto& resolve = layout.resolveAttachments[i];
|
||||
desc->setResolveLevel(0);
|
||||
desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
|
||||
desc->setResolveTexture(
|
||||
resolve.getTexture().cast<TextureBase>()->getTexture());
|
||||
desc->setResolveTexture(resolve.getTexture().cast<TextureBase>()->getTexture());
|
||||
}
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
depth = MTL::RenderPassDepthAttachmentDescriptor::alloc()->init();
|
||||
auto depth = renderPass->depthAttachment();
|
||||
depth->setClearDepth(layout.depthAttachment.clear.depthStencil.depth);
|
||||
depth->setLoadAction(cast(layout.depthAttachment.getLoadOp()));
|
||||
depth->setStoreAction(cast(layout.depthAttachment.getStoreOp()));
|
||||
depth->setTexture(
|
||||
layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
|
||||
|
||||
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
||||
depth->setResolveTexture(layout.depthResolveAttachment.getTexture()
|
||||
.cast<TextureBase>()
|
||||
->getTexture());
|
||||
depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast<TextureBase>()->getTexture());
|
||||
depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
|
||||
}
|
||||
renderPass->setDepthAttachment(depth);
|
||||
}
|
||||
// TODO: stencil
|
||||
}
|
||||
RenderPass::~RenderPass() {
|
||||
depth->release();
|
||||
stencil->release();
|
||||
renderPass->release();
|
||||
RenderPass::~RenderPass() {}
|
||||
|
||||
void RenderPass::updateRenderPass() {
|
||||
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
|
||||
const auto& color = layout.colorAttachments[i];
|
||||
auto desc = renderPass->colorAttachments()->object(i);
|
||||
desc->setTexture(color.getTexture().cast<TextureBase>()->getTexture());
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
auto depth = renderPass->depthAttachment();
|
||||
depth->setTexture(layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "Foundation/NSAutoreleasePool.hpp"
|
||||
#include "Graphics.h"
|
||||
#include "Graphics/Window.h"
|
||||
#include "Resources.h"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Window.h"
|
||||
#include "Command.h"
|
||||
#include "Foundation/NSAutoreleasePool.hpp"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Graphics/Metal/Enums.h"
|
||||
#include "Graphics/Texture.h"
|
||||
@@ -80,8 +81,6 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
|
||||
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
||||
metalWindow.contentView.layer = metalLayer;
|
||||
metalWindow.contentView.wantsLayer = YES;
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
}
|
||||
|
||||
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
||||
@@ -89,9 +88,6 @@ Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
||||
void Window::pollInput() { glfwPollEvents(); }
|
||||
|
||||
void Window::beginFrame() {
|
||||
if (drawable) {
|
||||
drawable->release();
|
||||
}
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
}
|
||||
@@ -146,7 +142,7 @@ void Window::resize(int width, int height) {
|
||||
framebufferWidth = width;
|
||||
framebufferHeight = height;
|
||||
// Deallocate the textures if they have been created
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
drawable = (__bridge CA::MetalDrawable*)[[metalLayer nextDrawable] autorelease];
|
||||
createBackBuffer();
|
||||
resizeCallback(width, height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user