diff --git a/NativeRenderPlugin/RenderAPI.h b/NativeRenderPlugin/RenderAPI.h index 93472cb..c586430 100644 --- a/NativeRenderPlugin/RenderAPI.h +++ b/NativeRenderPlugin/RenderAPI.h @@ -13,7 +13,8 @@ enum GraphicsFeature VRS_ATTACHMENT, HW_SPATIAL_SR, METAL_VRR, - HW_AISR, + HW_AI_SPATIAL_SR, + HW_AI_TEMPORAL_SR, HW_ADAPTIVE_VRS, HW_FG_INTERPOLATE, HW_FG_EXTRAPOLATION, @@ -90,6 +91,8 @@ public: virtual void spatialUpScale(void* data) {} + virtual void temporalScale(void* data) {} + virtual bool getFeatureSupport(GraphicsFeature feature); virtual void SetVKPSOHook(bool enable) {} diff --git a/NativeRenderPlugin/RenderAPI_Metal.mm b/NativeRenderPlugin/RenderAPI_Metal.mm index 629e250..eb2873b 100644 --- a/NativeRenderPlugin/RenderAPI_Metal.mm +++ b/NativeRenderPlugin/RenderAPI_Metal.mm @@ -29,11 +29,15 @@ public: virtual void spatialUpScale(void*data) override; + virtual void temporalScale(void*data) override; + virtual void enableVRS(void* data) override; virtual void disableVRS() override; private: id mfx_spatial_scaler; + id mfx_temporal_scaler; + bool first_frame_temporal; id commandQueue; id outTexture; IUnityGraphicsMetal* metal_graphics; @@ -78,7 +82,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 { @@ -161,6 +165,79 @@ void RenderAPI_Metal::spatialUpScale(void* data) } } + +void RenderAPI_Metal::temporalScale(void* data) +{ + if (@available(iOS 16, macOS 13, *)) + { + struct DataPack + { + void* src; + void* dst; + void* depth; + void* motion; + float jitter_x; + float jitter_y; + }; + DataPack* data_pack = static_cast(data); + + id srctex = (__bridge id)data_pack->src; + id dsttex = (__bridge id)data_pack->dst; + id depthtex = (__bridge id)data_pack->src; + id motiontex = (__bridge id)data_pack->motion; + + id device = metal_graphics->MetalDevice(); + id cmd = (id)metal_graphics->CurrentCommandBuffer(); + cmd.label = @"Upscale Command Buffer"; + if(mfx_temporal_scaler == null) + { + MTLFXTemporalScalerDescriptor* desc = [[MTLFXTemporalScalerDescriptor alloc]init]; + desc.inputWidth = [srctex width]; + desc.inputHeight = [srctex height]; + desc.outputWidth = [dsttex width]; + desc.outputHeight = [dsttex height]; + desc.colorTextureFormat = [srctex pixelFormat]; + desc.outputTextureFormat = [dsttex pixelFormat]; + desc.depthTextureFormat = [depthtex pixelFormat]; + desc.motionTextureFormat = [motiontex pixelFormat]; + + mfx_temporal_scaler = [desc newTemporalScalerWithDevice:device]; + if(commandQueue == null) + { + commandQueue = [device newCommandQueue]; + } + + mfx_temporal_scaler.motionVectorScaleX = desc.inputWidth; + mfx_temporal_scaler.motionVectorScaleY = desc.inputHeight; + first_frame_temporal = true; + } + + if (mfx_temporal_scaler == nil || commandQueue == nil) + { + return; + } + + if(!(srctex && dsttex)) + { + return; + } + + mfx_temporal_scaler.reset = first_frame_temporal; + mfx_temporal_scaler.colorTexture = srctex; + mfx_temporal_scaler.depthTexture = depthtex; + mfx_temporal_scaler.motionTexture = motiontex; + mfx_temporal_scaler.outputTexture = dsttex; + mfx_temporal_scaler.isDepthReversed = false; + mfx_temporal_scaler.jitterOffsetX = data_pack->jitter_x; + mfx_temporal_scaler.jitterOffsetY = data_pack->jitter_y; + + first_frame_temporal = false; + + [mfx_temporal_scaler encodeToCommandBuffer:cmd]; + + } +} + void RenderAPI_Metal::enableVRS(void* data) { struct DataPack diff --git a/NativeRenderPlugin/RenderAPI_OpenGLCoreES.cpp b/NativeRenderPlugin/RenderAPI_OpenGLCoreES.cpp index a281e69..18367ff 100644 --- a/NativeRenderPlugin/RenderAPI_OpenGLCoreES.cpp +++ b/NativeRenderPlugin/RenderAPI_OpenGLCoreES.cpp @@ -210,7 +210,7 @@ void RenderAPI_OpenGLCoreES::initSupportFeature() if (strstr(extensions, XEG_NEURAL_UPSCALE_EXTENSION_NAME)) { - support_features[GraphicsFeature::HW_AISR] = true; + support_features[GraphicsFeature::HW_AI_SPATIAL_SR] = true; } if (strstr(extensions, XEG_ADAPTIVE_VRS_EXTENSION_NAME)) diff --git a/NativeRenderPlugin/RenderAPI_Vulkan.cpp b/NativeRenderPlugin/RenderAPI_Vulkan.cpp index 040354e..2231373 100644 --- a/NativeRenderPlugin/RenderAPI_Vulkan.cpp +++ b/NativeRenderPlugin/RenderAPI_Vulkan.cpp @@ -578,6 +578,13 @@ void checkXEngine(VkPhysicalDevice physic_device, SupportFeatureList &fl) { fl[GraphicsFeature::HW_ADAPTIVE_VRS] = true; } + + // 查询是否支持时域AI超分 + if (std::find(supported_extensions.begin(), supported_extensions.end(), XEG_TEMPORAL_UPSCALE_EXTENSION_NAME) == + supported_extensions.end()) + { + fl[GraphicsFeature::HW_AI_TEMPORAL_SR] = true; + } } #endif diff --git a/NativeRenderPlugin/RenderingPlugin.cpp b/NativeRenderPlugin/RenderingPlugin.cpp index 693d0b8..31dd356 100644 --- a/NativeRenderPlugin/RenderingPlugin.cpp +++ b/NativeRenderPlugin/RenderingPlugin.cpp @@ -107,6 +107,7 @@ enum NativeRenderingEvent PostFGExtrapolation, DisableFGExtrapolation, SpatialUpScale, + TemporalScale }; static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data) @@ -149,6 +150,11 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void *data) s_current_api->spatialUpScale(data); break; } + case NativeRenderingEvent::TemporalScale: + { + s_current_api->temporalScale(data); + break; + } case NativeRenderingEvent::DoFGExtrapolation: { AFMEParam *param = (AFMEParam *)data;