Browse Source
Moved all create/destroy methods for various types of resources to a new common base class
framework
Moved all create/destroy methods for various types of resources to a new common base class
framework
4 changed files with 93 additions and 82 deletions
-
80Runtime/Common/FfxResourcesBase.cs
-
11Runtime/Common/FfxResourcesBase.cs.meta
-
42Runtime/FSR2/Fsr2Resources.cs
-
42Runtime/FSR3/Fsr3UpscalerResources.cs
@ -0,0 +1,80 @@ |
|||
using System; |
|||
using System.Runtime.InteropServices; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace FidelityFX |
|||
{ |
|||
internal abstract class FfxResourcesBase |
|||
{ |
|||
protected static ComputeBuffer CreateBuffer<TElem>(string name, int count) |
|||
{ |
|||
return new ComputeBuffer(count, Marshal.SizeOf<TElem>()); |
|||
} |
|||
|
|||
protected static RenderTexture CreateResource(string name, in Vector2Int size, GraphicsFormat format) |
|||
{ |
|||
var rt = new RenderTexture(size.x, size.y, 0, format) { name = name, enableRandomWrite = true }; |
|||
rt.Create(); |
|||
return rt; |
|||
} |
|||
|
|||
protected static RenderTexture CreateResourceMips(string name, in Vector2Int size, GraphicsFormat format) |
|||
{ |
|||
int mipCount = 1 + Mathf.FloorToInt(Mathf.Log(Math.Max(size.x, size.y), 2.0f)); |
|||
var rt = new RenderTexture(size.x, size.y, 0, format, mipCount) { name = name, enableRandomWrite = true, useMipMap = true, autoGenerateMips = false }; |
|||
rt.Create(); |
|||
return rt; |
|||
} |
|||
|
|||
protected static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, in Vector2Int size, GraphicsFormat format, int numElements = 2) |
|||
{ |
|||
numElements = Math.Min(resource.Length, numElements); |
|||
for (int i = 0; i < numElements; ++i) |
|||
{ |
|||
resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true }; |
|||
resource[i].Create(); |
|||
} |
|||
} |
|||
|
|||
protected static void DestroyResource(ref Texture2D resource) |
|||
{ |
|||
if (resource == null) |
|||
return; |
|||
|
|||
#if UNITY_EDITOR
|
|||
if (Application.isPlaying && !UnityEditor.EditorApplication.isPaused) |
|||
UnityEngine.Object.Destroy(resource); |
|||
else |
|||
UnityEngine.Object.DestroyImmediate(resource); |
|||
#else
|
|||
UnityEngine.Object.Destroy(resource); |
|||
#endif
|
|||
resource = null; |
|||
} |
|||
|
|||
protected static void DestroyResource(ref RenderTexture resource) |
|||
{ |
|||
if (resource == null) |
|||
return; |
|||
|
|||
resource.Release(); |
|||
resource = null; |
|||
} |
|||
|
|||
protected static void DestroyResource(ref ComputeBuffer resource) |
|||
{ |
|||
if (resource == null) |
|||
return; |
|||
|
|||
resource.Release(); |
|||
resource = null; |
|||
} |
|||
|
|||
protected static void DestroyResource(RenderTexture[] resource) |
|||
{ |
|||
for (int i = 0; i < resource.Length; ++i) |
|||
DestroyResource(ref resource[i]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 2a46b97ac72c45545a80a896462e1112 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue