From fb5932082971216b670d429589483603bde6c97d Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Fri, 7 Mar 2025 17:36:09 +0200 Subject: [PATCH] More iOS work --- include/ios_driver.h | 2 +- include/renderer.hpp | 4 ++-- include/renderer_mtl/renderer_mtl.hpp | 5 ++--- src/core/renderer_mtl/renderer_mtl.cpp | 25 +++++-------------------- src/ios_driver.mm | 6 ++++-- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/include/ios_driver.h b/include/ios_driver.h index 2d745ed5..5158fead 100644 --- a/include/ios_driver.h +++ b/include/ios_driver.h @@ -1,4 +1,4 @@ #pragma once void iosCreateEmulator(); -void iosRunFrame(void* drawable, void* drawableTexture); \ No newline at end of file +void iosRunFrame(void* drawable); \ No newline at end of file diff --git a/include/renderer.hpp b/include/renderer.hpp index 583057aa..ef1d27d4 100644 --- a/include/renderer.hpp +++ b/include/renderer.hpp @@ -87,8 +87,8 @@ class Renderer { virtual void setupGLES() {} // Only relevant for Metal renderer on iOS - // Passes a SwiftUI MTKView Drawable & its texture to the renderer - virtual void setMTKDrawable(void* drawable, void* drawableTexture) {}; + // Passes a SwiftUI MTKView Drawable to the renderer + virtual void setMTKDrawable(void* drawable) {}; // This function is called on every draw call before parsing vertex data. // It is responsible for things like looking up which vertex/fragment shaders to use, recompiling them if they don't exist, choosing between diff --git a/include/renderer_mtl/renderer_mtl.hpp b/include/renderer_mtl/renderer_mtl.hpp index 3f842466..e11485bd 100644 --- a/include/renderer_mtl/renderer_mtl.hpp +++ b/include/renderer_mtl/renderer_mtl.hpp @@ -42,13 +42,11 @@ class RendererMTL final : public Renderer { virtual void initGraphicsContext([[maybe_unused]] GL::Context* context) override {} #endif - virtual void setMTKDrawable(void* drawable, void* drawableTexture) override; + virtual void setMTKDrawable(void* drawable) override; private: CA::MetalLayer* metalLayer = nullptr; - CA::MetalDrawable* metalDrawable = nullptr; - MTL::Texture* drawableTexture = nullptr; MTL::Device* device = nullptr; MTL::CommandQueue* commandQueue = nullptr; @@ -103,6 +101,7 @@ class RendererMTL final : public Renderer { void endRenderPass() { if (renderCommandEncoder) { renderCommandEncoder->endEncoding(); + renderCommandEncoder->release(); renderCommandEncoder = nullptr; } } diff --git a/src/core/renderer_mtl/renderer_mtl.cpp b/src/core/renderer_mtl/renderer_mtl.cpp index f6361709..4c40f064 100644 --- a/src/core/renderer_mtl/renderer_mtl.cpp +++ b/src/core/renderer_mtl/renderer_mtl.cpp @@ -55,39 +55,29 @@ void RendererMTL::reset() { colorRenderTargetCache.reset(); } -void RendererMTL::setMTKDrawable(void* drawable, void* tex) { - this->metalDrawable = (CA::MetalDrawable*)drawable; - this->drawableTexture = (MTL::Texture*)tex; +void RendererMTL::setMTKDrawable(void* drawable) { + metalDrawable = (CA::MetalDrawable*)drawable; } void RendererMTL::display() { - static int frameCount = 0; - frameCount++; - - auto manager = MTL::CaptureManager::sharedCaptureManager(); - auto captureDescriptor = MTL::CaptureDescriptor::alloc()->init(); - if (frameCount == 200) { - captureDescriptor->setCaptureObject(device); - manager->startCapture(captureDescriptor, nullptr); - } - #ifdef PANDA3DS_IOS CA::MetalDrawable* drawable = metalDrawable; if (!drawable) { return; } - MTL::Texture* texture = drawableTexture; + MTL::Texture* texture = drawable->texture(); #else CA::MetalDrawable* drawable = metalLayer->nextDrawable(); if (!drawable) { return; } - MTL::Texture* texture = drawable->getTexture(); + MTL::Texture* texture = drawable->texture(); #endif using namespace PICA::ExternalRegs; + printf("Device pointer: %p\nDrawable pointer: %p\nTexture pointer: %p\n", device, drawable, texture); // Top screen const u32 topActiveFb = externalRegs[Framebuffer0Select] & 1; @@ -149,11 +139,6 @@ void RendererMTL::display() { #ifndef PANDA3DS_IOS drawable->release(); #endif - - if (frameCount == 200) { - manager->stopCapture(); - } - captureDescriptor->release(); } void RendererMTL::initGraphicsContext(SDL_Window* window) { diff --git a/src/ios_driver.mm b/src/ios_driver.mm index cd2ac655..c09768c7 100644 --- a/src/ios_driver.mm +++ b/src/ios_driver.mm @@ -30,7 +30,9 @@ IOS_EXPORT void iosCreateEmulator() { printf("Created emulator\n"); } -IOS_EXPORT void iosRunFrame(void* drawable, void* drawableTexture) { - emulator->getRenderer()->setMTKDrawable(drawable, drawableTexture); +IOS_EXPORT void iosRunFrame(void* drawable) { + printf("Running a frame\n"); + emulator->getRenderer()->setMTKDrawable(drawable); emulator->runFrame(); + printf("Ran a frame\n"); } \ No newline at end of file