diff --git a/src/suyu/bootmanager.cpp b/src/suyu/bootmanager.cpp index a84dcdb3a3..023ece4868 100644 --- a/src/suyu/bootmanager.cpp +++ b/src/suyu/bootmanager.cpp @@ -277,6 +277,14 @@ struct VulkanRenderWidget : public RenderWidget { } }; +struct MetalRenderWidget : public RenderWidget { + explicit MetalRenderWidget(GRenderWindow* parent) : RenderWidget(parent) { + // HACK: manually resize the renderable area + resize(600, 400); + windowHandle()->setSurfaceType(QWindow::MetalSurface); + } +}; + struct NullRenderWidget : public RenderWidget { explicit NullRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {} }; @@ -1056,8 +1064,9 @@ bool GRenderWindow::InitializeVulkan() { } bool GRenderWindow::InitializeMetal() { - // TODO: initialize Metal - child_widget = new NullRenderWidget(this); + auto child = new MetalRenderWidget(this); + child_widget = child; + child_widget->windowHandle()->create(); main_context = std::make_unique(); return true; diff --git a/src/video_core/renderer_metal/renderer_metal.h b/src/video_core/renderer_metal/renderer_metal.h index 12c3396583..852964d5bf 100644 --- a/src/video_core/renderer_metal/renderer_metal.h +++ b/src/video_core/renderer_metal/renderer_metal.h @@ -53,9 +53,6 @@ private: const CAMetalLayer* layer; RasterizerMetal rasterizer; - - // HACK - MTLTexture_t renderTexture; }; } // namespace Metal diff --git a/src/video_core/renderer_metal/renderer_metal.mm b/src/video_core/renderer_metal/renderer_metal.mm index a3416805d3..6009eed606 100644 --- a/src/video_core/renderer_metal/renderer_metal.mm +++ b/src/video_core/renderer_metal/renderer_metal.mm @@ -13,17 +13,16 @@ RendererMetal::RendererMetal(Core::Frontend::EmuWindow& emu_window, std::unique_ptr context_) : RendererBase(emu_window, std::move(context_)), device_memory{device_memory_}, gpu{gpu_}, device{}, - layer(static_cast(render_window.GetWindowInfo().render_surface)), + layer([static_cast(render_window.GetWindowInfo().render_surface) + retain]), rasterizer(gpu_, device, layer) { - // HACK - MTLTextureDescriptor* textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm_sRGB - width:1280 - height:720 - mipmapped:NO]; - renderTexture = [device.GetDevice() newTextureWithDescriptor:textureDescriptor]; + // Give the layer our device + layer.device = device.GetDevice(); } -RendererMetal::~RendererMetal() = default; +RendererMetal::~RendererMetal() { + [layer release]; +} void RendererMetal::Composite(std::span framebuffers) { if (framebuffers.empty()) { @@ -32,18 +31,19 @@ void RendererMetal::Composite(std::span framebuf // HACK @autoreleasepool { - //id drawable = [layer nextDrawable]; + id drawable = [layer nextDrawable]; MTLRenderPassDescriptor* renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor]; renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(1.0, 0.5, 0.0, 1.0); renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear; renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; - renderPassDescriptor.colorAttachments[0].texture = renderTexture;//drawable.texture; + renderPassDescriptor.colorAttachments[0].texture = drawable.texture; id commandBuffer = [device.GetCommandQueue() commandBuffer]; - id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; + id renderEncoder = [commandBuffer + renderCommandEncoderWithDescriptor:renderPassDescriptor]; [renderEncoder endEncoding]; - //[commandBuffer presentDrawable:drawable]; + [commandBuffer presentDrawable:drawable]; [commandBuffer commit]; }