Cocoa Port: Display views now run using Apple Metal, if available.

- An Apple Metal display view requires macOS 10.11 El Capitan or later,
in addition to a Metal-compatible GPU.
- Apple Metal display views have significantly lower CPU usage then
OpenGL display views.
This commit is contained in:
rogerman 2017-02-10 12:33:34 -08:00
parent 3799af3a01
commit 72fa455ca0
7 changed files with 4697 additions and 2 deletions

View File

@ -146,6 +146,8 @@
AB3BF4381E25D9AE003E2B24 /* DisplayViewCALayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF4371E25D9AE003E2B24 /* DisplayViewCALayer.mm */; };
AB3BF4391E25D9AE003E2B24 /* DisplayViewCALayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF4371E25D9AE003E2B24 /* DisplayViewCALayer.mm */; };
AB3BF43A1E25D9AE003E2B24 /* DisplayViewCALayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF4371E25D9AE003E2B24 /* DisplayViewCALayer.mm */; };
AB3BF43E1E26289E003E2B24 /* MacMetalDisplayView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF43B1E26289E003E2B24 /* MacMetalDisplayView.mm */; };
AB3BF4421E262959003E2B24 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB3BF4401E262943003E2B24 /* Metal.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
AB3E34C9134AF4500056477A /* cocoa_output.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3E34C8134AF4500056477A /* cocoa_output.mm */; };
AB40562A169F5DBB0016AC3E /* assembler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB405600169F5DBB0016AC3E /* assembler.cpp */; };
AB40562B169F5DBB0016AC3E /* assembler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB405600169F5DBB0016AC3E /* assembler.cpp */; };
@ -245,6 +247,9 @@
AB4FCEBD1692AB82000F498F /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB4FCEBC1692AB82000F498F /* Accelerate.framework */; };
AB4FCEBE1692AB82000F498F /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB4FCEBC1692AB82000F498F /* Accelerate.framework */; };
AB4FCEBF1692AB82000F498F /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB4FCEBC1692AB82000F498F /* Accelerate.framework */; };
AB54718B1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = AB54718A1E27610500508C5C /* MacMetalDisplayViewShaders.metal */; };
AB54718C1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = AB54718A1E27610500508C5C /* MacMetalDisplayViewShaders.metal */; };
AB54718D1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = AB54718A1E27610500508C5C /* MacMetalDisplayViewShaders.metal */; };
AB5648FF186E6EA8002740F4 /* cocoa_slot2.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB5648FE186E6EA8002740F4 /* cocoa_slot2.mm */; };
AB564900186E6EA8002740F4 /* cocoa_slot2.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB5648FE186E6EA8002740F4 /* cocoa_slot2.mm */; };
AB564901186E6EA8002740F4 /* cocoa_slot2.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB5648FE186E6EA8002740F4 /* cocoa_slot2.mm */; };
@ -278,6 +283,10 @@
AB6FBEF6139B6258007BB045 /* slot1_retail_nand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB6FBEF5139B6258007BB045 /* slot1_retail_nand.cpp */; };
AB74EC8A1738499C0026C41E /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB74EC891738499C0026C41E /* Carbon.framework */; };
AB75226E14C7BB51009B97B3 /* AppIcon_FirmwareConfig.icns in Resources */ = {isa = PBXBuildFile; fileRef = AB75226D14C7BB51009B97B3 /* AppIcon_FirmwareConfig.icns */; };
AB78B5C11E384F2100297FED /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB3BF4401E262943003E2B24 /* Metal.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
AB78B5C21E384F2200297FED /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB3BF4401E262943003E2B24 /* Metal.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
AB78B5C31E384F4F00297FED /* MacMetalDisplayView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF43B1E26289E003E2B24 /* MacMetalDisplayView.mm */; };
AB78B5C41E384F4F00297FED /* MacMetalDisplayView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AB3BF43B1E26289E003E2B24 /* MacMetalDisplayView.mm */; };
AB796C9C15CDCB0F00C59155 /* arm_jit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB796C9B15CDCB0F00C59155 /* arm_jit.cpp */; };
AB796C9F15CDCB0F00C59155 /* arm_jit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB796C9B15CDCB0F00C59155 /* arm_jit.cpp */; };
AB796CA715CDCBA200C59155 /* KeyNames.plist in Resources */ = {isa = PBXBuildFile; fileRef = AB02475B13886BF300E9F9AB /* KeyNames.plist */; };
@ -1361,6 +1370,9 @@
AB3BF4321E2562F2003E2B24 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
AB3BF4361E25D6B4003E2B24 /* DisplayViewCALayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayViewCALayer.h; sourceTree = "<group>"; };
AB3BF4371E25D9AE003E2B24 /* DisplayViewCALayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayViewCALayer.mm; sourceTree = "<group>"; };
AB3BF43B1E26289E003E2B24 /* MacMetalDisplayView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MacMetalDisplayView.mm; sourceTree = "<group>"; };
AB3BF43F1E2628B6003E2B24 /* MacMetalDisplayView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MacMetalDisplayView.h; sourceTree = "<group>"; };
AB3BF4401E262943003E2B24 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
AB3E34C7134AF4500056477A /* cocoa_output.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_output.h; sourceTree = "<group>"; };
AB3E34C8134AF4500056477A /* cocoa_output.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_output.mm; sourceTree = "<group>"; };
AB4055ED169F59380016AC3E /* AsmJit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsmJit.h; sourceTree = "<group>"; };
@ -1436,6 +1448,7 @@
AB47B52C18A3F722009A42AF /* xbrz.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xbrz.cpp; sourceTree = "<group>"; };
AB4C81E31B21676C00ACECD5 /* hq3x.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hq3x.cpp; sourceTree = "<group>"; };
AB4FCEBC1692AB82000F498F /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
AB54718A1E27610500508C5C /* MacMetalDisplayViewShaders.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = MacMetalDisplayViewShaders.metal; sourceTree = "<group>"; };
AB5648FD186E6EA8002740F4 /* cocoa_slot2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoa_slot2.h; sourceTree = "<group>"; };
AB5648FE186E6EA8002740F4 /* cocoa_slot2.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = cocoa_slot2.mm; sourceTree = "<group>"; };
AB564902186E6EBC002740F4 /* Slot2WindowDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Slot2WindowDelegate.h; sourceTree = "<group>"; };
@ -1902,6 +1915,7 @@
AB564908186E6F1F002740F4 /* ForceFeedback.framework in Frameworks */,
ABC572101344347000E7B0B1 /* Foundation.framework in Frameworks */,
AB350BA51478AC96007165AC /* IOKit.framework in Frameworks */,
AB3BF4421E262959003E2B24 /* Metal.framework in Frameworks */,
ABC570D5134431DA00E7B0B1 /* OpenGL.framework in Frameworks */,
AB3BF4341E256309003E2B24 /* QuartzCore.framework in Frameworks */,
AB4676F314AB12D60002FF94 /* libz.dylib in Frameworks */,
@ -1922,6 +1936,7 @@
AB564907186E6F0C002740F4 /* ForceFeedback.framework in Frameworks */,
AB796D6915CDCBA200C59155 /* Foundation.framework in Frameworks */,
AB796D6A15CDCBA200C59155 /* IOKit.framework in Frameworks */,
AB78B5C21E384F2200297FED /* Metal.framework in Frameworks */,
AB796D6B15CDCBA200C59155 /* OpenGL.framework in Frameworks */,
AB3BF4331E2562F2003E2B24 /* QuartzCore.framework in Frameworks */,
AB796D6C15CDCBA200C59155 /* libz.dylib in Frameworks */,
@ -1942,6 +1957,7 @@
AB8F3D251A53AC2600A80BF6 /* ForceFeedback.framework in Frameworks */,
AB8F3D261A53AC2600A80BF6 /* Foundation.framework in Frameworks */,
AB8F3D271A53AC2600A80BF6 /* IOKit.framework in Frameworks */,
AB78B5C11E384F2100297FED /* Metal.framework in Frameworks */,
AB8F3D281A53AC2600A80BF6 /* OpenGL.framework in Frameworks */,
AB3BF4351E256309003E2B24 /* QuartzCore.framework in Frameworks */,
AB8F3D291A53AC2600A80BF6 /* libz.dylib in Frameworks */,
@ -2032,6 +2048,7 @@
AB564906186E6F0C002740F4 /* ForceFeedback.framework */,
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
AB350BA41478AC96007165AC /* IOKit.framework */,
AB3BF4401E262943003E2B24 /* Metal.framework */,
ABC570D4134431DA00E7B0B1 /* OpenGL.framework */,
AB3BF4321E2562F2003E2B24 /* QuartzCore.framework */,
AB0A0D1914AACA9600E83E91 /* libz.dylib */,
@ -2389,11 +2406,13 @@
AB29B32F16D4BEBF000EF671 /* InputManager.h */,
AB3ACB6E14C2361100D7D192 /* inputPrefsView.h */,
AB01005C170D07AF00D70FBE /* InputProfileController.h */,
AB3BF43F1E2628B6003E2B24 /* MacMetalDisplayView.h */,
AB3BF4051E22FEA8003E2B24 /* MacOGLDisplayView.h */,
AB3ACB7014C2361100D7D192 /* preferencesWindowDelegate.h */,
ABAF0A3F1A96E67200B95B75 /* RomInfoPanel.h */,
AB564902186E6EBC002740F4 /* Slot2WindowDelegate.h */,
ABF2B9F81690412A000FF7C0 /* troubleshootingWindowDelegate.h */,
AB54718A1E27610500508C5C /* MacMetalDisplayViewShaders.metal */,
AB3ACB6714C2361100D7D192 /* appDelegate.mm */,
AB3ACB6914C2361100D7D192 /* cheatWindowDelegate.mm */,
AB3BF4371E25D9AE003E2B24 /* DisplayViewCALayer.mm */,
@ -2403,6 +2422,7 @@
AB29B33016D4BEBF000EF671 /* InputManager.mm */,
AB3ACB6F14C2361100D7D192 /* inputPrefsView.mm */,
AB01005D170D07B000D70FBE /* InputProfileController.mm */,
AB3BF43B1E26289E003E2B24 /* MacMetalDisplayView.mm */,
AB3BF4011E22FE01003E2B24 /* MacOGLDisplayView.mm */,
AB3ACB7114C2361100D7D192 /* preferencesWindowDelegate.mm */,
ABAF0A401A96E67200B95B75 /* RomInfoPanel.mm */,
@ -3856,12 +3876,14 @@
ABD1FEFE1345AC8400AF11D1 /* wifi.cpp in Sources */,
ABFEA8051BB4EC1000B08C25 /* ftbbox.c in Sources */,
AB9038B317C5ED2200F410BD /* slot1_retail_mcrom.cpp in Sources */,
AB54718D1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */,
ABD1FF691345ACBF00AF11D1 /* xstring.cpp in Sources */,
ABD104281346653B00AF11D1 /* main.m in Sources */,
AB2ABA411C9F9CFA00173B15 /* rsemaphore.c in Sources */,
ABA6574B14511EC90077E5E9 /* cocoa_cheat.mm in Sources */,
ABD1041D1346652500AF11D1 /* cocoa_core.mm in Sources */,
AB58F32D1364F44B0074C376 /* cocoa_file.mm in Sources */,
AB3BF43E1E26289E003E2B24 /* MacMetalDisplayView.mm in Sources */,
AB3BF4041E22FE01003E2B24 /* MacOGLDisplayView.mm in Sources */,
ABE7F53E13EE1C7900FD3A71 /* cocoa_firmware.mm in Sources */,
ABD1041C1346652500AF11D1 /* cocoa_input.mm in Sources */,
@ -4043,6 +4065,7 @@
AB2EE12C17D57ED500F68622 /* slot1_retail_mcrom_debug.cpp in Sources */,
AB5648FF186E6EA8002740F4 /* cocoa_slot2.mm in Sources */,
AB796D2A15CDCBA200C59155 /* slot1_r4.cpp in Sources */,
AB78B5C41E384F4F00297FED /* MacMetalDisplayView.mm in Sources */,
AB796D2C15CDCBA200C59155 /* slot1_retail_nand.cpp in Sources */,
AB35BD8F1DEBF40800844310 /* encoding_utf.c in Sources */,
ABE6840C189E33BC007FD69C /* OGLDisplayOutput.cpp in Sources */,
@ -4101,6 +4124,7 @@
AB000DD01CCC6B0700413F02 /* retro_stat.c in Sources */,
AB796D5B15CDCBA200C59155 /* 2xsai.cpp in Sources */,
ABADF1181DEA4C1200A142B1 /* Database.cpp in Sources */,
AB54718B1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */,
AB796D5C15CDCBA200C59155 /* bilinear.cpp in Sources */,
ABA7316B1BB51FDC00B26147 /* psaux.c in Sources */,
AB796D5D15CDCBA200C59155 /* epx.cpp in Sources */,
@ -4174,6 +4198,7 @@
buildActionMask = 2147483647;
files = (
ABFEA8CC1BB4EC1100B08C25 /* smooth.c in Sources */,
AB54718C1E27610500508C5C /* MacMetalDisplayViewShaders.metal in Sources */,
ABFEA8421BB4EC1100B08C25 /* ftpatent.c in Sources */,
ABFEA8A51BB4EC1100B08C25 /* sfnt.c in Sources */,
ABFEA81B1BB4EC1000B08C25 /* ftfntfmt.c in Sources */,
@ -4236,6 +4261,7 @@
AB8F3C921A53AC2600A80BF6 /* firmware.cpp in Sources */,
AB8F3C941A53AC2600A80BF6 /* gfx3d.cpp in Sources */,
AB000DD41CCC6B3D00413F02 /* retro_dirent.c in Sources */,
AB78B5C31E384F4F00297FED /* MacMetalDisplayView.mm in Sources */,
AB8F3C951A53AC2600A80BF6 /* GPU.cpp in Sources */,
AB8F3C971A53AC2600A80BF6 /* guid.cpp in Sources */,
AB8F3C981A53AC2600A80BF6 /* header.cpp in Sources */,

View File

@ -90,6 +90,8 @@
<dict/>
<key>General_AutoloadROMOption</key>
<integer>10000</integer>
<key>General_DisplayViewsPreferMetal</key>
<true/>
<key>General_DisplayWindowRestorableStates</key>
<array/>
<key>General_DoNotAskMigrate</key>

View File

@ -27,7 +27,7 @@
#endif
#if defined(MAC_OS_X_VERSION_10_11) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11)
//#define ENABLE_APPLE_METAL
#define ENABLE_APPLE_METAL
#endif
class GPUEventHandlerOSX;

View File

@ -156,7 +156,7 @@ public:
fetchObject = NULL;
#ifdef ENABLE_APPLE_METAL
if (IsOSXVersionSupported(10, 11, 0))
if (IsOSXVersionSupported(10, 11, 0) && [[NSUserDefaults standardUserDefaults] boolForKey:@"General_DisplayViewsPreferMetal"])
{
fetchObject = new MacMetalFetchObject;
if (fetchObject->GetClientData() == nil)

View File

@ -0,0 +1,261 @@
/*
Copyright (C) 2017 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the this software. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MAC_METALDISPLAYVIEW_H
#define _MAC_METALDISPLAYVIEW_H
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import "DisplayViewCALayer.h"
#import "../cocoa_GPU.h"
#include "../ClientDisplayView.h"
#ifdef BOOL
#undef BOOL
#endif
class MacMetalFetchObject;
class MacMetalDisplayView;
struct DisplayViewShaderProperties
{
float width;
float height;
float rotation;
float viewScale;
uint32_t lowerHUDMipMapLevel;
};
typedef DisplayViewShaderProperties DisplayViewShaderProperties;
@interface MetalDisplayViewSharedData : MacClientSharedObject
{
id<MTLDevice> device;
id<MTLCommandQueue> commandQueue;
id<MTLLibrary> defaultLibrary;
id<MTLComputePipelineState> load16To32Pipeline;
id<MTLComputePipelineState> deposterizePipeline;
id<MTLRenderPipelineState> hudPipeline;
id<MTLBlitCommandEncoder> _fetchEncoder;
id<MTLSamplerState> samplerHUDBox;
id<MTLSamplerState> samplerHUDText;
id<MTLBuffer> hudIndexBuffer;
id<MTLBuffer> _bufDisplayFetchNative[2][2];
id<MTLBuffer> _bufDisplayFetchCustom[2][2];
id<MTLTexture> texDisplayFetch16NativeMain;
id<MTLTexture> texDisplayFetch16NativeTouch;
id<MTLTexture> texDisplayFetch32NativeMain;
id<MTLTexture> texDisplayFetch32NativeTouch;
id<MTLTexture> texDisplayFetch16CustomMain;
id<MTLTexture> texDisplayFetch16CustomTouch;
id<MTLTexture> texDisplayFetch32CustomMain;
id<MTLTexture> texDisplayFetch32CustomTouch;
id<MTLTexture> texLQ2xLUT;
id<MTLTexture> texHQ2xLUT;
id<MTLTexture> texHQ3xLUT;
id<MTLTexture> texHQ4xLUT;
id<MTLTexture> texCurrentHQnxLUT;
MTLSize load16To32ThreadsPerGroup;
MTLSize load16To32ThreadGroupsPerGridNative;
MTLSize load16To32ThreadGroupsPerGridCustom;
MTLSize deposterizeThreadsPerGroup;
MTLSize deposterizeThreadGroupsPerGrid;
size_t displayFetchNativeBufferSize;
size_t displayFetchCustomBufferSize;
pthread_mutex_t _mutexFetch;
}
@property (readonly, nonatomic) id<MTLDevice> device;
@property (readonly, nonatomic) id<MTLCommandQueue> commandQueue;
@property (readonly, nonatomic) id<MTLLibrary> defaultLibrary;
@property (readonly, nonatomic) id<MTLComputePipelineState> load16To32Pipeline;
@property (readonly, nonatomic) id<MTLComputePipelineState> deposterizePipeline;
@property (readonly, nonatomic) id<MTLRenderPipelineState> hudPipeline;
@property (readonly, nonatomic) id<MTLSamplerState> samplerHUDBox;
@property (readonly, nonatomic) id<MTLSamplerState> samplerHUDText;
@property (readonly, nonatomic) id<MTLBuffer> hudIndexBuffer;
@property (readonly, nonatomic) id<MTLTexture> texDisplayFetch16NativeMain;
@property (readonly, nonatomic) id<MTLTexture> texDisplayFetch16NativeTouch;
@property (readonly, nonatomic) id<MTLTexture> texDisplayFetch32NativeMain;
@property (readonly, nonatomic) id<MTLTexture> texDisplayFetch32NativeTouch;
@property (retain) id<MTLTexture> texDisplayFetch16CustomMain;
@property (retain) id<MTLTexture> texDisplayFetch16CustomTouch;
@property (retain) id<MTLTexture> texDisplayFetch32CustomMain;
@property (retain) id<MTLTexture> texDisplayFetch32CustomTouch;
@property (readonly, nonatomic) id<MTLTexture> texLQ2xLUT;
@property (readonly, nonatomic) id<MTLTexture> texHQ2xLUT;
@property (readonly, nonatomic) id<MTLTexture> texHQ3xLUT;
@property (readonly, nonatomic) id<MTLTexture> texHQ4xLUT;
@property (retain) id<MTLTexture> texCurrentHQnxLUT;
@property (assign) size_t displayFetchNativeBufferSize;
@property (assign) size_t displayFetchCustomBufferSize;
@property (readonly, nonatomic) MTLSize load16To32ThreadsPerGroup;
@property (readonly, nonatomic) MTLSize load16To32ThreadGroupsPerGridNative;
@property (assign) MTLSize load16To32ThreadGroupsPerGridCustom;
@property (readonly, nonatomic) MTLSize deposterizeThreadsPerGroup;
@property (readonly, nonatomic) MTLSize deposterizeThreadGroupsPerGrid;
- (void) setFetchBuffersWithDisplayInfo:(const NDSDisplayInfo &)dispInfo;
- (void) fetchFromBufferIndex:(const u8)index;
- (void) fetchNativeDisplayByID:(const NDSDisplayID)displayID bufferIndex:(const u8)bufferIndex;
- (void) fetchCustomDisplayByID:(const NDSDisplayID)displayID bufferIndex:(const u8)bufferIndex;
- (void) convertFetch16To32UsingEncoder:(id<MTLComputeCommandEncoder>)cce isMainNative:(BOOL)isMainNative isTouchNative:(BOOL)isTouchNative;
@end
@interface DisplayViewMetalLayer : CAMetalLayer <DisplayViewCALayer>
{
MacMetalDisplayView *_cdv;
MetalDisplayViewSharedData *sharedData;
MTLRenderPassDescriptor *_outputRenderPassDesc;
MTLRenderPassColorAttachmentDescriptor *colorAttachment0Desc;
id<MTLComputePipelineState> pixelScalePipeline;
id<MTLRenderPipelineState> displayOutputPipeline;
id<MTLBuffer> _cdvPropertiesBuffer;
id<MTLBuffer> _displayVtxPositionBuffer;
id<MTLBuffer> _displayTexCoordBuffer;
id<MTLBuffer> _hudVtxPositionBuffer;
id<MTLBuffer> _hudTexCoordBuffer;
id<MTLBuffer> bufCPUFilterSrcMain;
id<MTLBuffer> bufCPUFilterSrcTouch;
id<MTLBuffer> bufCPUFilterDstMain;
id<MTLBuffer> bufCPUFilterDstTouch;
id<MTLTexture> _texDisplaySrcDeposterize[2][2];
id<MTLTexture> texDisplayPixelScaleMain;
id<MTLTexture> texDisplayPixelScaleTouch;
id<MTLTexture> _texDisplayOutput[2];
id<MTLTexture> texHUDCharMap;
MTLSize _pixelScalerThreadsPerGroup;
MTLSize _pixelScalerThreadGroupsPerGrid;
BOOL needsViewportUpdate;
BOOL needsRotationScaleUpdate;
BOOL needsScreenVerticesUpdate;
BOOL needsHUDVerticesUpdate;
dispatch_semaphore_t availableResources;
}
@property (assign, nonatomic) MetalDisplayViewSharedData *sharedData;
@property (readonly, nonatomic) MTLRenderPassColorAttachmentDescriptor *colorAttachment0Desc;
@property (retain) id<MTLComputePipelineState> pixelScalePipeline;
@property (retain) id<MTLRenderPipelineState> displayOutputPipeline;
@property (retain) id<MTLBuffer> bufCPUFilterSrcMain;
@property (retain) id<MTLBuffer> bufCPUFilterSrcTouch;
@property (retain) id<MTLBuffer> bufCPUFilterDstMain;
@property (retain) id<MTLBuffer> bufCPUFilterDstTouch;
@property (retain) id<MTLTexture> texDisplayPixelScaleMain;
@property (retain) id<MTLTexture> texDisplayPixelScaleTouch;
@property (retain) id<MTLTexture> texHUDCharMap;
@property (assign) BOOL needsViewportUpdate;
@property (assign) BOOL needsRotationScaleUpdate;
@property (assign) BOOL needsScreenVerticesUpdate;
@property (assign) BOOL needsHUDVerticesUpdate;
@property (assign, nonatomic) VideoFilterTypeID pixelScaler;
@property (assign, nonatomic) OutputFilterTypeID outputFilter;
- (id<MTLCommandBuffer>) newCommandBuffer;
- (void) setupLayer;
- (void) resizeCPUPixelScalerUsingFilterID:(const VideoFilterTypeID)filterID;
- (void) copyHUDFontUsingFace:(const FT_Face &)fontFace size:(const size_t)glyphSize tileSize:(const size_t)glyphTileSize info:(GlyphInfo *)glyphInfo;
- (void) processDisplays;
- (void) renderToDrawable;
@end
#pragma mark -
class MacMetalFetchObject : public GPUClientFetchObject
{
protected:
bool _useCPUFilterPipeline;
uint32_t *_srcNativeCloneMaster;
uint32_t *_srcNativeClone[2][2];
pthread_rwlock_t _srcCloneRWLock[2][2];
virtual void _FetchNativeDisplayByID(const NDSDisplayID displayID, const u8 bufferIndex);
virtual void _FetchCustomDisplayByID(const NDSDisplayID displayID, const u8 bufferIndex);
public:
MacMetalFetchObject();
virtual ~MacMetalFetchObject();
virtual void Init();
virtual void CopyFromSrcClone(uint32_t *dstBufferPtr, const NDSDisplayID displayID, const u8 bufferIndex);
virtual void SetFetchBuffers(const NDSDisplayInfo &currentDisplayInfo);
virtual void FetchFromBufferIndex(const u8 index);
};
#pragma mark -
class MacMetalDisplayView : public ClientDisplay3DView, public DisplayViewCALayerInterface
{
protected:
pthread_mutex_t *_mutexProcessPtr;
virtual void _UpdateNormalSize();
virtual void _UpdateOrder();
virtual void _UpdateRotation();
virtual void _UpdateClientSize();
virtual void _UpdateViewScale();
virtual void _LoadNativeDisplayByID(const NDSDisplayID displayID);
virtual void _ResizeCPUPixelScaler(const VideoFilterTypeID filterID);
public:
MacMetalDisplayView();
virtual ~MacMetalDisplayView();
pthread_mutex_t* GetMutexProcessPtr() const;
virtual void Init();
virtual void CopyHUDFont(const FT_Face &fontFace, const size_t glyphSize, const size_t glyphTileSize, GlyphInfo *glyphInfo);
// NDS screen filters
virtual void SetPixelScaler(const VideoFilterTypeID filterID);
virtual void SetOutputFilter(const OutputFilterTypeID filterID);
virtual void SetFiltersPreferGPU(const bool preferGPU);
// Client view interface
virtual void ProcessDisplays();
virtual void UpdateView();
};
#pragma mark -
void SetupHQnxLUTs_Metal(id<MTLDevice> &device, id<MTLTexture> &texLQ2xLUT, id<MTLTexture> &texHQ2xLUT, id<MTLTexture> &texHQ3xLUT, id<MTLTexture> &texHQ4xLUT);
void DeleteHQnxLUTs_Metal(id<MTLTexture> &texLQ2xLUT, id<MTLTexture> &texHQ2xLUT, id<MTLTexture> &texHQ3xLUT, id<MTLTexture> &texHQ4xLUT);
#endif // _MAC_METALDISPLAYVIEW_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff