add metalfx spatial UpScale

This commit is contained in:
connan 2024-12-18 14:20:41 +08:00
parent 69423ceca2
commit 6118e30863
9 changed files with 52 additions and 18 deletions

1
.gitignore vendored
View File

@ -58,3 +58,4 @@ TJURP_BurstDebugInformation_DoNotShip/
UserSettings/ UserSettings/
**/.DS_Store **/.DS_Store
out/

View File

@ -28,7 +28,7 @@ MonoBehaviour:
m_SupportsHDR: 1 m_SupportsHDR: 1
m_HDRColorBufferPrecision: 0 m_HDRColorBufferPrecision: 0
m_MSAA: 1 m_MSAA: 1
m_RenderScale: 0.8333333 m_RenderScale: 0.58823526
m_UpscalingFilter: 0 m_UpscalingFilter: 0
m_FsrOverrideSharpness: 1 m_FsrOverrideSharpness: 1
m_FsrSharpness: 1 m_FsrSharpness: 1
@ -85,7 +85,7 @@ MonoBehaviour:
blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3} blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3}
bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3}
m_PrefilteringModeMainLightShadows: 3 m_PrefilteringModeMainLightShadows: 3
m_PrefilteringModeAdditionalLight: 4 m_PrefilteringModeAdditionalLight: 2
m_PrefilteringModeAdditionalLightShadows: 0 m_PrefilteringModeAdditionalLightShadows: 0
m_PrefilterXRKeywords: 1 m_PrefilterXRKeywords: 1
m_PrefilteringModeForwardPlus: 1 m_PrefilteringModeForwardPlus: 1
@ -96,12 +96,12 @@ MonoBehaviour:
m_PrefilterHDROutput: 1 m_PrefilterHDROutput: 1
m_PrefilterSSAODepthNormals: 1 m_PrefilterSSAODepthNormals: 1
m_PrefilterSSAOSourceDepthLow: 1 m_PrefilterSSAOSourceDepthLow: 1
m_PrefilterSSAOSourceDepthMedium: 0 m_PrefilterSSAOSourceDepthMedium: 1
m_PrefilterSSAOSourceDepthHigh: 1 m_PrefilterSSAOSourceDepthHigh: 1
m_PrefilterSSAOInterleaved: 0 m_PrefilterSSAOInterleaved: 1
m_PrefilterSSAOBlueNoise: 1 m_PrefilterSSAOBlueNoise: 1
m_PrefilterSSAOSampleCountLow: 1 m_PrefilterSSAOSampleCountLow: 1
m_PrefilterSSAOSampleCountMedium: 0 m_PrefilterSSAOSampleCountMedium: 1
m_PrefilterSSAOSampleCountHigh: 1 m_PrefilterSSAOSampleCountHigh: 1
m_PrefilterDBufferMRT1: 1 m_PrefilterDBufferMRT1: 1
m_PrefilterDBufferMRT2: 1 m_PrefilterDBufferMRT2: 1

View File

@ -259,4 +259,4 @@ MonoBehaviour:
m_Name: MetalFxSpatialUpScale m_Name: MetalFxSpatialUpScale
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Active: 1 m_Active: 1
quality: 2 quality: 4

View File

@ -57,7 +57,7 @@ void RenderAPI_Metal::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInt
} }
void RenderAPI_Metal::initSupportFeature() void RenderAPI_Metal::initSupportFeature()
{ {
if (@available(iOS 16.0, macOS 13.0, *)) if (@available(iOS 16, macOS 13, *))
{ {
support_features[GraphicsFeature::METAL_FX_SPATIAL_SR] = true; support_features[GraphicsFeature::METAL_FX_SPATIAL_SR] = true;
support_features[GraphicsFeature::METAL_FX_TEMPORAL_SR] = true; support_features[GraphicsFeature::METAL_FX_TEMPORAL_SR] = true;
@ -66,12 +66,13 @@ void RenderAPI_Metal::initSupportFeature()
void RenderAPI_Metal::spatialUpScale(void* data) void RenderAPI_Metal::spatialUpScale(void* data)
{ {
if (@available(iOS 16.0, macOS 13.0, *)) if (@available(iOS 16, macOS 13, *))
{ {
struct DataPack struct DataPack
{ {
void* src; void* src;
void* dst; void* dst;
bool qulityChange;
}; };
DataPack* data_pack = static_cast<DataPack*>(data); DataPack* data_pack = static_cast<DataPack*>(data);
@ -80,10 +81,10 @@ void RenderAPI_Metal::spatialUpScale(void* data)
id<MTLDevice> _device = metal_graphics->MetalDevice(); id<MTLDevice> _device = metal_graphics->MetalDevice();
id<MTLCommandBuffer> cmd = (id<MTLCommandBuffer>)metal_graphics->CurrentCommandBuffer(); id<MTLCommandBuffer> cmd = (id<MTLCommandBuffer>)metal_graphics->CurrentCommandBuffer();
// metal_graphics->EndCurrentCommandEncoder();
cmd.label = @"Upscale Command Buffer"; cmd.label = @"Upscale Command Buffer";
if (mfx_spatial_scaler == nil) if (mfx_spatial_scaler == nil || data_pack->qulityChange)
{ {
MTLFXSpatialScalerDescriptor* desc = [[MTLFXSpatialScalerDescriptor alloc]init]; MTLFXSpatialScalerDescriptor* desc = [[MTLFXSpatialScalerDescriptor alloc]init];
desc.inputWidth = [srctex width]; desc.inputWidth = [srctex width];
@ -101,11 +102,23 @@ void RenderAPI_Metal::spatialUpScale(void* data)
return; return;
} }
} }
mfx_spatial_scaler.colorTexture = srctex; mfx_spatial_scaler.colorTexture = srctex;
mfx_spatial_scaler.outputTexture = dsttex; mfx_spatial_scaler.outputTexture = dsttex;
[mfx_spatial_scaler encodeToCommandBuffer:cmd]; // if(!cmd)
[cmd commit]; {
id <MTLCommandQueue> _commandQueue = [_device newCommandQueue];
id <MTLCommandBuffer> upscaleCommandBuffer = [_commandQueue commandBuffer];
upscaleCommandBuffer.label = @"Upscale Command Buffer";
[mfx_spatial_scaler encodeToCommandBuffer:upscaleCommandBuffer];
[upscaleCommandBuffer commit];
}
// else
{
// [mfx_spatial_scaler encodeToCommandBuffer:cmd];
// [cmd commit];
}
} }
} }

View File

@ -504,10 +504,10 @@ namespace UnityEngine.Rendering.Universal
ref var colorDescriptor = ref cameraData.cameraTargetDescriptor; ref var colorDescriptor = ref cameraData.cameraTargetDescriptor;
colorDescriptor.width = cameraData.camera.pixelWidth; colorDescriptor.width = cameraData.camera.pixelWidth;
colorDescriptor.height = cameraData.camera.pixelHeight; colorDescriptor.height = cameraData.camera.pixelHeight;
if (asset.SuperResolution == ESuperResolution.XESS13 || asset.SuperResolution == ESuperResolution.GSR2) //if (asset.SuperResolution == ESuperResolution.XESS13 || asset.SuperResolution == ESuperResolution.GSR2)
{ {
colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat; colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat;
colorDescriptor.enableRandomWrite = true; // compute colorDescriptor.enableRandomWrite = true; //
} }
renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear); renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear);

View File

@ -15,10 +15,13 @@ namespace X.Rendering.Feature
SrQuality quality; SrQuality quality;
private ProfilingSampler profiler; private ProfilingSampler profiler;
SrQuality lastQuality;
bool updateSrNextFrame = false;
struct DataPack struct DataPack
{ {
public IntPtr src; public IntPtr src;
public IntPtr dst; public IntPtr dst;
public bool qulityChange;
}; };
IntPtr dataPtr; IntPtr dataPtr;
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
@ -39,11 +42,28 @@ namespace X.Rendering.Feature
public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData) public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData)
{ {
if (source.rt == null || destination.rt == null)
{
return;
}
using var scp = new ProfilingScope(cmd, profiler); using var scp = new ProfilingScope(cmd, profiler);
DataPack * ptr = (DataPack*) dataPtr.ToPointer(); DataPack * ptr = (DataPack*) dataPtr.ToPointer();
ptr->src = source.rt.GetNativeTexturePtr(); ptr->src = source.rt.GetNativeTexturePtr();
ptr->dst = destination.rt.GetNativeTexturePtr(); ptr->dst = destination.rt.GetNativeTexturePtr();
cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.UpdateXESS1Config, dataPtr); ptr->qulityChange = updateSrNextFrame;
if(updateSrNextFrame)
{
updateSrNextFrame = false;
}
if (lastQuality != quality)
{
updateSrNextFrame = true;
UniversalRenderPipeline.asset.renderScale = GetRenderScale();
lastQuality = quality;
}
cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.SpatialUpScale, dataPtr);
} }
public float GetRenderScale() public float GetRenderScale()

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using UnityEditor.VersionControl;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal; using UnityEngine.Rendering.Universal;

View File

@ -266,6 +266,7 @@ PlayerSettings:
- {fileID: 0} - {fileID: 0}
- {fileID: 0} - {fileID: 0}
- {fileID: 0} - {fileID: 0}
- {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}
metroInputSource: 0 metroInputSource: 0
wsaTransparentSwapchain: 0 wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1 m_HolographicPauseOnTrackingLoss: 1