|
|
|
@ -32,9 +32,9 @@ namespace FidelityFX |
|
|
|
{ |
|
|
|
_contextDescription = contextDescription; |
|
|
|
|
|
|
|
_fsr2ConstantsBuffer = new ComputeBuffer(1, Marshal.SizeOf<Fsr2Constants>(), ComputeBufferType.Constant); |
|
|
|
_spdConstantsBuffer = new ComputeBuffer(1, Marshal.SizeOf<SpdConstants>(), ComputeBufferType.Constant); |
|
|
|
_rcasConstantsBuffer = new ComputeBuffer(1, Marshal.SizeOf<RcasConstants>(), ComputeBufferType.Constant); |
|
|
|
_fsr2ConstantsBuffer = CreateConstantBuffer<Fsr2Constants>(); |
|
|
|
_spdConstantsBuffer = CreateConstantBuffer<SpdConstants>(); |
|
|
|
_rcasConstantsBuffer = CreateConstantBuffer<RcasConstants>(); |
|
|
|
|
|
|
|
// Set defaults
|
|
|
|
_fsr2ConstantsArray[0].displaySize = _contextDescription.DisplaySize; |
|
|
|
@ -71,12 +71,6 @@ namespace FidelityFX |
|
|
|
LoadComputeShader("FSR2/ffx_fsr2_tcr_autogen_pass", ref _tcrAutogenShader); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadComputeShader(string name, ref ComputeShader shaderRef) |
|
|
|
{ |
|
|
|
if (shaderRef == null) |
|
|
|
shaderRef = _contextDescription.Callbacks.LoadComputeShader(name); |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispatch(Fsr2.DispatchDescription dispatchDescription) |
|
|
|
{ |
|
|
|
_fsr2ConstantsArray[0].preExposure = dispatchDescription.PreExposure; |
|
|
|
@ -110,23 +104,19 @@ namespace FidelityFX |
|
|
|
|
|
|
|
public void Destroy() |
|
|
|
{ |
|
|
|
if (_rcasConstantsBuffer != null) |
|
|
|
{ |
|
|
|
_rcasConstantsBuffer.Release(); |
|
|
|
_rcasConstantsBuffer = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (_spdConstantsBuffer != null) |
|
|
|
{ |
|
|
|
_spdConstantsBuffer.Release(); |
|
|
|
_spdConstantsBuffer = null; |
|
|
|
} |
|
|
|
|
|
|
|
if (_fsr2ConstantsBuffer != null) |
|
|
|
{ |
|
|
|
_fsr2ConstantsBuffer.Release(); |
|
|
|
_fsr2ConstantsBuffer = null; |
|
|
|
} |
|
|
|
DestroyConstantBuffer(ref _rcasConstantsBuffer); |
|
|
|
DestroyConstantBuffer(ref _spdConstantsBuffer); |
|
|
|
DestroyConstantBuffer(ref _fsr2ConstantsBuffer); |
|
|
|
|
|
|
|
DestroyComputeShader(ref _tcrAutogenShader); |
|
|
|
DestroyComputeShader(ref _generateReactiveShader); |
|
|
|
DestroyComputeShader(ref _accumulateShader); |
|
|
|
DestroyComputeShader(ref _lockShader); |
|
|
|
DestroyComputeShader(ref _reconstructPreviousDepthShader); |
|
|
|
DestroyComputeShader(ref _depthClipShader); |
|
|
|
DestroyComputeShader(ref _prepareInputColorShader); |
|
|
|
DestroyComputeShader(ref _rcasShader); |
|
|
|
DestroyComputeShader(ref _computeLuminancePyramidShader); |
|
|
|
} |
|
|
|
|
|
|
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
|
|
|
@ -203,5 +193,34 @@ namespace FidelityFX |
|
|
|
new(1064229695u, 997604214u), |
|
|
|
new(1065353216u, 1006648320), |
|
|
|
}; |
|
|
|
|
|
|
|
private static ComputeBuffer CreateConstantBuffer<TConstants>() where TConstants: struct |
|
|
|
{ |
|
|
|
return new ComputeBuffer(1, Marshal.SizeOf<TConstants>(), ComputeBufferType.Constant); |
|
|
|
} |
|
|
|
|
|
|
|
private void LoadComputeShader(string name, ref ComputeShader shaderRef) |
|
|
|
{ |
|
|
|
if (shaderRef == null) |
|
|
|
shaderRef = _contextDescription.Callbacks.LoadComputeShader(name); |
|
|
|
} |
|
|
|
|
|
|
|
private static void DestroyConstantBuffer(ref ComputeBuffer bufferRef) |
|
|
|
{ |
|
|
|
if (bufferRef == null) |
|
|
|
return; |
|
|
|
|
|
|
|
bufferRef.Release(); |
|
|
|
bufferRef = null; |
|
|
|
} |
|
|
|
|
|
|
|
private void DestroyComputeShader(ref ComputeShader shaderRef) |
|
|
|
{ |
|
|
|
if (shaderRef == null) |
|
|
|
return; |
|
|
|
|
|
|
|
_contextDescription.Callbacks.UnloadComputeShader(shaderRef); |
|
|
|
shaderRef = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |