diff --git a/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib b/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib index 5c1cd01..7d52015 100755 Binary files a/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib and b/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib differ diff --git a/Assets/Plugins/iOS/IUnityGraphics.h b/Assets/Plugins/iOS/IUnityGraphics.h new file mode 100644 index 0000000..eb47f84 --- /dev/null +++ b/Assets/Plugins/iOS/IUnityGraphics.h @@ -0,0 +1,62 @@ +// Unity Native Plugin API copyright © 2015 Unity Technologies ApS +// +// Licensed under the Unity Companion License for Unity - dependent projects--see[Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). +// +// Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.Please review the license for details on these and other terms and conditions. + +#pragma once +#include "IUnityInterface.h" + +// Has to match the GfxDeviceRenderer enum +typedef enum UnityGfxRenderer +{ + //kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed + //kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed + kUnityGfxRendererD3D11 = 2, // Direct3D 11 + kUnityGfxRendererNull = 4, // "null" device (used in batch mode) + //kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0, removed + kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 + //kUnityGfxRendererGXM = 12, // PlayStation Vita, removed + kUnityGfxRendererPS4 = 13, // PlayStation 4 + kUnityGfxRendererXboxOne = 14, // Xbox One + kUnityGfxRendererMetal = 16, // iOS Metal + kUnityGfxRendererOpenGLCore = 17, // OpenGL core + kUnityGfxRendererD3D12 = 18, // Direct3D 12 + kUnityGfxRendererVulkan = 21, // Vulkan + kUnityGfxRendererNvn = 22, // Nintendo Switch NVN API + kUnityGfxRendererXboxOneD3D12 = 23, // MS XboxOne Direct3D 12 + kUnityGfxRendererGameCoreXboxOne = 24, // GameCore Xbox One + kUnityGfxRendererGameCoreXboxSeries = 25, // GameCore XboxSeries + kUnityGfxRendererPS5 = 26, // PS5 + kUnityGfxRendererPS5NGGC = 27 // PS5 NGGC +} UnityGfxRenderer; + +typedef enum UnityGfxDeviceEventType +{ + kUnityGfxDeviceEventInitialize = 0, + kUnityGfxDeviceEventShutdown = 1, + kUnityGfxDeviceEventBeforeReset = 2, + kUnityGfxDeviceEventAfterReset = 3, +} UnityGfxDeviceEventType; + +typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); + +// Should only be used on the rendering thread unless noted otherwise. +UNITY_DECLARE_INTERFACE(IUnityGraphics) +{ + UnityGfxRenderer(UNITY_INTERFACE_API * GetRenderer)(); // Thread safe + + // This callback will be called when graphics device is created, destroyed, reset, etc. + // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, + // when the graphics device is already created. + void(UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); + void(UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); + int(UNITY_INTERFACE_API * ReserveEventIDRange)(int count); // reserves 'count' event IDs. Plugins should use the result as a base index when issuing events back and forth to avoid event id clashes. +}; +UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL, 0x8C5AD4926EB17B11ULL, IUnityGraphics) + + +// Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. +// Provide them with an address to a function of this signature. +typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); +typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data); diff --git a/Assets/Plugins/iOS/IUnityGraphics.h.meta b/Assets/Plugins/iOS/IUnityGraphics.h.meta new file mode 100644 index 0000000..bb78456 --- /dev/null +++ b/Assets/Plugins/iOS/IUnityGraphics.h.meta @@ -0,0 +1,33 @@ +fileFormatVersion: 2 +guid: DnxM43+uBi5PTN+VjLUhJiqWT35vZ3X/qYGSh1s9ygOCPHX7gp770Po= +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/RegisterPlugin.mm b/Assets/Plugins/iOS/RegisterPlugin.mm new file mode 100644 index 0000000..d96880c --- /dev/null +++ b/Assets/Plugins/iOS/RegisterPlugin.mm @@ -0,0 +1,21 @@ +#import "UnityAppController.h" +#include "IUnityGraphics.h" + +extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); +extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload(); + +@interface MyAppController : UnityAppController +{ +} +- (void)shouldAttachRenderDelegate; +@end +@implementation MyAppController +- (void)shouldAttachRenderDelegate +{ + // unlike desktops where plugin dynamic library is automatically loaded and registered + // we need to do that manually on iOS + UnityRegisterRenderingPluginV5(&UnityPluginLoad, &UnityPluginUnload); +} + +@end +IMPL_APP_CONTROLLER_SUBCLASS(MyAppController); diff --git a/Assets/Plugins/iOS/RegisterPlugin.mm.meta b/Assets/Plugins/iOS/RegisterPlugin.mm.meta new file mode 100644 index 0000000..e60ce08 --- /dev/null +++ b/Assets/Plugins/iOS/RegisterPlugin.mm.meta @@ -0,0 +1,73 @@ +fileFormatVersion: 2 +guid: BykYsCOpBX+d2b+9FYpH4sRtQQWfzWt//qzo8usCE85bX6WDY31ZgjI= +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 1 + Exclude Win64: 1 + Exclude iOS: 0 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + CPU: AnyCPU + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/libGfxPluginNativeRender.a.meta b/Assets/Plugins/iOS/libGfxPluginNativeRender.a.meta index 546715d..65b987b 100644 --- a/Assets/Plugins/iOS/libGfxPluginNativeRender.a.meta +++ b/Assets/Plugins/iOS/libGfxPluginNativeRender.a.meta @@ -67,7 +67,7 @@ PluginImporter: AddToEmbeddedBinaries: false CPU: ARM64 CompileFlags: - FrameworkDependencies: + FrameworkDependencies: Metal;MetalKit; userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Settings/Mobile/Mobile_High_Renderer.asset b/Assets/Settings/Mobile/Mobile_High_Renderer.asset index 15b1a71..dd7473b 100644 --- a/Assets/Settings/Mobile/Mobile_High_Renderer.asset +++ b/Assets/Settings/Mobile/Mobile_High_Renderer.asset @@ -83,7 +83,7 @@ MonoBehaviour: - {fileID: 1342351342872651138} - {fileID: 6446168921458335383} m_RendererFeatureMap: bc3f630842f2e70dd6a559c442a94bfd4529d15534f2d3de228858dca8d12222f0f17d10860a28157820480586dae7578265b12b6ffda01297deaf157b647559 - m_UseNativeRenderPass: 0 + m_UseNativeRenderPass: 1 postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} shaders: blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3} diff --git a/NativeRenderPlugin/RenderAPI_Metal.mm b/NativeRenderPlugin/RenderAPI_Metal.mm index 9bc1dfa..e8d4acf 100644 --- a/NativeRenderPlugin/RenderAPI_Metal.mm +++ b/NativeRenderPlugin/RenderAPI_Metal.mm @@ -78,7 +78,7 @@ void RenderAPI_Metal::initSupportFeature() void RenderAPI_Metal::spatialUpScale(void* data) { - if (@available(iOS 16, macOS 13, *)) + // if (@available(iOS 16, macOS 13, *)) { struct DataPack { @@ -93,9 +93,8 @@ void RenderAPI_Metal::spatialUpScale(void* data) id device = metal_graphics->MetalDevice(); id cmd = (id)metal_graphics->CurrentCommandBuffer(); - metal_graphics->EndCurrentCommandEncoder(); + // metal_graphics->EndCurrentCommandEncoder(); cmd.label = @"Upscale Command Buffer"; - if (mfx_spatial_scaler == nil ) { MTLFXSpatialScalerDescriptor* desc = [[MTLFXSpatialScalerDescriptor alloc]init]; @@ -128,34 +127,34 @@ void RenderAPI_Metal::spatialUpScale(void* data) return; } mfx_spatial_scaler.colorTexture = srctex; - mfx_spatial_scaler.outputTexture = outTexture; + mfx_spatial_scaler.outputTexture = dsttex; - mfx_spatial_scaler.inputContentWidth = [srctex width]; - mfx_spatial_scaler.inputContentHeight = [srctex height]; + // mfx_spatial_scaler.inputContentWidth = [srctex width]; + // mfx_spatial_scaler.inputContentHeight = [srctex height]; // if(!cmd) // { - // id upscaleCommandBuffer = [commandQueue commandBuffer]; - // upscaleCommandBuffer.label = @"Upscale Command Buffer"; - // [mfx_spatial_scaler encodeToCommandBuffer:upscaleCommandBuffer]; - // [upscaleCommandBuffer commit]; + id upscaleCommandBuffer = [commandQueue commandBuffer]; + upscaleCommandBuffer.label = @"Upscale Command Buffer"; + [mfx_spatial_scaler encodeToCommandBuffer:upscaleCommandBuffer]; + [upscaleCommandBuffer commit]; - // id textureCommandBuffer = [commandQueue commandBuffer]; - // id _mfxSpatialEncoder =[textureCommandBuffer blitCommandEncoder]; + // id textureCommandBuffer = [commandQueue commandBuffer]; + // id _mfxSpatialEncoder =[textureCommandBuffer blitCommandEncoder]; - // [_mfxSpatialEncoder copyFromTexture: outTexture toTexture: dsttex]; - // [_mfxSpatialEncoder endEncoding]; - // [textureCommandBuffer commit]; + // [_mfxSpatialEncoder copyFromTexture: outTexture toTexture: dsttex]; + // [_mfxSpatialEncoder endEncoding]; + // [textureCommandBuffer commit]; // } // else { - [mfx_spatial_scaler encodeToCommandBuffer:cmd]; + // [mfx_spatial_scaler encodeToCommandBuffer:cmd]; // [cmd commit]; // id textureCommandBuffer = [commandQueue commandBuffer]; - id _mfxSpatialEncoder =[textureCommandBuffer blitCommandEncoder]; + // id _mfxSpatialEncoder =[textureCommandBuffer blitCommandEncoder]; - [_mfxSpatialEncoder copyFromTexture: outTexture toTexture: dsttex]; - [_mfxSpatialEncoder endEncoding]; + // [_mfxSpatialEncoder copyFromTexture: outTexture toTexture: dsttex]; + // [_mfxSpatialEncoder endEncoding]; // [textureCommandBuffer commit]; } diff --git a/NativeRenderPlugin/RenderingPlugin.cpp b/NativeRenderPlugin/RenderingPlugin.cpp index d6c5ead..a42d5a2 100644 --- a/NativeRenderPlugin/RenderingPlugin.cpp +++ b/NativeRenderPlugin/RenderingPlugin.cpp @@ -71,6 +71,7 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev if (eventType == kUnityGfxDeviceEventInitialize) { assert(s_current_api == NULL); + unityLog("kUnityGfxDeviceEventInitialize"); s_device_type = s_graphics->GetRenderer(); s_current_api = createRenderAPI(s_device_type); } @@ -114,10 +115,10 @@ enum NativeRenderingEvent static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data) { + // unityLog("OnRenderEventAndData0"); // Unknown / unsupported graphics device type? Do nothing if (s_current_api == NULL) return; - switch ((NativeRenderingEvent)eventID) { case NativeRenderingEvent::EnableVRS: diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs index 96e37c3..d9e9d35 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs @@ -69,18 +69,17 @@ namespace X.Rendering.Feature lastQuality = quality; } ptr->dst = destination.rt.GetNativeTexturePtr(); - [DllImport("__Internal", EntryPoint = "callMetalFX_SpatialScaling")] - static extern void CallNativeMethod(IntPtr srcTexture, IntPtr dstTexture); - // cmd.SetRenderTarget(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare); - CallNativeMethod(source.rt.GetNativeTexturePtr(), destination.rt.GetNativeTexturePtr()); - //cmd.Blit(dstRT, destination); - //cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.SpatialUpScale, dataPtr); + //[DllImport("__Internal", EntryPoint = "callMetalFX_SpatialScaling")] + //static extern void CallNativeMethod(IntPtr srcTexture, IntPtr dstTexture); + //CallNativeMethod(source.rt.GetNativeTexturePtr(), destination.rt.GetNativeTexturePtr()); + cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.SpatialUpScale, dataPtr); //cmd.Blit(dstRT, destination); } //cmd.SetRenderTarget(destination, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store); //cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.SpatialUpScale, dataPtr); - //SuperResolutionParamSets.Instance.RenderContext.ExecuteCommandBuffer(cmd); + SuperResolutionParamSets.Instance.RenderContext.ExecuteCommandBuffer(cmd); + cmd.Clear(); //CommandBufferPool.Release(cmd); } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 3a895e1..5f1f572 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -10,7 +10,7 @@ PlayerSettings: AndroidFilterTouchesWhenObscured: 0 AndroidEnableSustainedPerformanceMode: 0 defaultScreenOrientation: 3 - targetDevice: 2 + targetDevice: 0 useOnDemandResources: 0 accelerometerFrequency: 60 companyName: DefaultCompany @@ -1088,7 +1088,8 @@ PlayerSettings: Standalone: 0 il2cppCompilerConfiguration: {} il2cppCodeGeneration: {} - managedStrippingLevel: {} + managedStrippingLevel: + iPhone: 1 incrementalIl2cppBuild: {} suppressCommonWarnings: 1 allowUnsafeCode: 1 diff --git a/UserSettings/Layouts/default-2022.dwlt b/UserSettings/Layouts/default-2022.dwlt index 616fda4..c66d75e 100644 --- a/UserSettings/Layouts/default-2022.dwlt +++ b/UserSettings/Layouts/default-2022.dwlt @@ -43,7 +43,7 @@ MonoBehaviour: width: 1920 height: 954 m_ShowMode: 4 - m_Title: Console + m_Title: Game m_RootView: {fileID: 13} m_MinSize: {x: 875, y: 321} m_MaxSize: {x: 10000, y: 10000} @@ -97,7 +97,7 @@ MonoBehaviour: m_MinSize: {x: 640, y: 601} m_MaxSize: {x: 4000, y: 4021} vertical: 0 - controlID: 2099 + controlID: 14 draggingID: 0 --- !u!114 &5 MonoBehaviour: @@ -150,7 +150,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 50} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 18 + controlID: 123 draggingID: 0 --- !u!114 &7 MonoBehaviour: @@ -202,7 +202,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 50} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 120 + controlID: 226 draggingID: 0 --- !u!114 &9 MonoBehaviour: @@ -228,7 +228,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 100} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 16 + controlID: 121 draggingID: 0 --- !u!114 &10 MonoBehaviour: @@ -403,7 +403,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 17 + controlID: 122 draggingID: 0 --- !u!114 &17 MonoBehaviour: @@ -958,9 +958,9 @@ MonoBehaviour: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 37} - m_SelectedIDs: 76ba0000 - m_LastClickedID: 47734 - m_ExpandedIDs: 0000000074b7000076b7000078b7000000ca9a3bffffff7f + m_SelectedIDs: 4ebb0000 + m_LastClickedID: 47950 + m_ExpandedIDs: 000000004cb800004eb8000050b8000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -988,7 +988,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 0000000074b7000076b7000078b70000 + m_ExpandedIDs: 000000004cb800004eb8000050b80000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -1015,7 +1015,7 @@ MonoBehaviour: m_ListAreaState: m_SelectedInstanceIDs: m_LastClickedInstanceID: 0 - m_HadKeyboardFocusLastEvent: 1 + m_HadKeyboardFocusLastEvent: 0 m_ExpandedInstanceIDs: c6230000000000005aca0000 m_RenameOverlay: m_UserAcceptedRename: 0 @@ -1130,7 +1130,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: f263feff9264feff72d6feffb6ecfeff56edfeff365fffff4cfaffff + m_ExpandedIDs: 4cfaffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: