From e85823eed1d0b657d47bfd948af21e3d3e99c022 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Mon, 21 Mar 2022 17:43:15 -0500 Subject: [PATCH] GS:MTL: Experimental small rt mode --- pcsx2/GS/Renderers/Metal/GSDeviceMTL.h | 5 +++-- pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm | 29 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h index e109ead049a04..91382e64fabc0 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.h @@ -202,7 +202,7 @@ class GSDeviceMTL final : public GSDevice // MARK: Configuration simd::float3 m_shadeboost_constants; - int m_mipmap; + bool m_enable_small_rt; // MARK: Permanent resources std::shared_ptr> m_backref; @@ -261,6 +261,7 @@ class GSDeviceMTL final : public GSDevice GSTexture* tex[8] = {}; void* vertex_buffer = nullptr; void* name = nullptr; + GSVector2i size = GSVector2i(0, 0); struct Has { bool cb_vs : 1; @@ -327,7 +328,7 @@ class GSDeviceMTL final : public GSDevice /// End current render pass without flushing void EndRenderPass(); /// Begin a new render pass (may reuse existing) - void BeginRenderPass(NSString* name, GSTexture* color, MTLLoadAction color_load, GSTexture* depth, MTLLoadAction depth_load, GSTexture* stencil = nullptr, MTLLoadAction stencil_load = MTLLoadActionDontCare); + void BeginRenderPass(NSString* name, GSTexture* color, MTLLoadAction color_load, GSTexture* depth, MTLLoadAction depth_load, GSTexture* stencil = nullptr, MTLLoadAction stencil_load = MTLLoadActionDontCare, GSVector2i size = GSVector2i(0, 0)); GSTexture* CreateSurface(GSTexture::Type type, int width, int height, int levels, GSTexture::Format format) override; diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index b3fc0f80de0fa..37ac270477cc4 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -72,7 +72,6 @@ , m_dev(nil) { m_backref->second = this; - m_mipmap = theApp.GetConfigI("mipmap"); } GSDeviceMTL::~GSDeviceMTL() @@ -309,7 +308,7 @@ } } -void GSDeviceMTL::BeginRenderPass(NSString* name, GSTexture* color, MTLLoadAction color_load, GSTexture* depth, MTLLoadAction depth_load, GSTexture* stencil, MTLLoadAction stencil_load) +void GSDeviceMTL::BeginRenderPass(NSString* name, GSTexture* color, MTLLoadAction color_load, GSTexture* depth, MTLLoadAction depth_load, GSTexture* stencil, MTLLoadAction stencil_load, GSVector2i size) { GSTextureMTL* mc = static_cast(color); GSTextureMTL* md = static_cast(depth); @@ -332,6 +331,12 @@ needs_new |= mc && color_load == MTLLoadActionClear; needs_new |= md && depth_load == MTLLoadActionClear; needs_new |= ms && stencil_load == MTLLoadActionClear; + if (m_current_render.size != GSVector2i(0, 0)) + { + needs_new |= size == GSVector2i(0, 0); + needs_new |= size.x > m_current_render.size.x; + needs_new |= size.y > m_current_render.size.y; + } if (!needs_new) { @@ -380,6 +385,12 @@ desc.stencilAttachment.loadAction = stencil_load; } + if (@available(macOS 10.15, iOS 11, *)) + { + desc.renderTargetWidth = size.x; + desc.renderTargetHeight = size.y; + } + EndRenderPass(); m_current_render.encoder = MRCRetain([GetRenderCmdBuf() renderCommandEncoderWithDescriptor:desc]); m_current_render.name = (__bridge void*)name; @@ -390,6 +401,12 @@ m_current_render.color_target = color; m_current_render.depth_target = depth; m_current_render.stencil_target = stencil; + m_current_render.size = size; + if (size != GSVector2i(0, 0)) + { + GSVector2i rtsize = color ? color->GetSize() : depth ? depth->GetSize() : stencil->GetSize(); + [m_current_render.encoder setViewport: (MTLViewport){ .originX = 0, .originY = 0, .width = (double)rtsize.x, .height = (double)rtsize.y, .znear = 0, .zfar = 1 }]; + } pxAssertRel(m_current_render.encoder, "Failed to create render encoder!"); } @@ -652,6 +669,11 @@ static void setFnConstantI(MTLFunctionConstantValues* fc, unsigned int value, GS else m_spin_enable = false; + if (const char* env = getenv("MTL_SMALL_RT")) + m_enable_small_rt = env[0] == '1' || env[0] == 'y' || env[0] == 'Y'; + else + m_enable_small_rt = false; + m_features.geometry_shader = false; m_features.image_load_store = m_dev.features.primid; m_features.texture_barrier = true; @@ -1590,7 +1612,8 @@ void bitcpy(Dst& dst, const Src& src) if (!config.ds && m_current_render.color_target == rt && stencil == m_current_render.stencil_target && m_current_render.depth_target != config.tex) config.ds = m_current_render.depth_target; - BeginRenderPass(@"RenderHW", rt, MTLLoadActionLoad, config.ds, MTLLoadActionLoad, stencil, MTLLoadActionLoad); + GSVector2i rtsize = m_enable_small_rt ? GSVector2i(config.scissor.z, config.scissor.w) : GSVector2i(0, 0); + BeginRenderPass(@"RenderHW", rt, MTLLoadActionLoad, config.ds, MTLLoadActionLoad, stencil, MTLLoadActionLoad, rtsize); id mtlenc = m_current_render.encoder; FlushDebugEntries(mtlenc); MREInitHWDraw(config, allocation);