Browse Source

Reintroduced the clear load counter pass, which does very little in itself but does make the whole CACAO dispatch compatible with async compute.

master
Nico de Poel 2 years ago
parent
commit
1a81392535
  1. 4
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoAssets.cs
  2. 7
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoContext.cs
  3. 24
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoPass.cs
  4. 1
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs
  5. 8
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_clear_load_counter_pass.compute
  6. 7
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_clear_load_counter_pass.compute.meta
  7. 48
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/ffx_cacao_clear_load_counter_pass.hlsl
  8. 7
      com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/ffx_cacao_clear_load_counter_pass.hlsl.meta
  9. 7
      com.unity.render-pipelines.high-definition/Runtime/Settings/HDRenderPipelineRuntimeShaders.cs

4
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoAssets.cs

@ -11,6 +11,7 @@ namespace FidelityFX
{
shaders = new CacaoShaders
{
clearLoadCounter = FindComputeShader("ffx_cacao_clear_load_counter_pass"),
prepareDepths = FindComputeShader("ffx_cacao_prepare_depths_pass"),
prepareNormals = FindComputeShader("ffx_cacao_prepare_normals_pass"),
generateImportanceMap = FindComputeShader("ffx_cacao_generate_importance_map_pass"),
@ -36,6 +37,7 @@ namespace FidelityFX
[System.Serializable]
public class CacaoShaders
{
public ComputeShader clearLoadCounter;
public ComputeShader prepareDepths;
public ComputeShader prepareNormals;
public ComputeShader generateImportanceMap;
@ -53,6 +55,7 @@ namespace FidelityFX
{
return new CacaoShaders
{
clearLoadCounter = Object.Instantiate(clearLoadCounter),
prepareDepths = Object.Instantiate(prepareDepths),
prepareNormals = Object.Instantiate(prepareNormals),
generateImportanceMap = Object.Instantiate(generateImportanceMap),
@ -65,6 +68,7 @@ namespace FidelityFX
public void Dispose()
{
Object.Destroy(clearLoadCounter);
Object.Destroy(prepareDepths);
Object.Destroy(prepareNormals);
Object.Destroy(generateImportanceMap);

7
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoContext.cs

@ -17,6 +17,7 @@ namespace FidelityFX
private readonly CacaoResources _resources = new CacaoResources();
private CacaoClearLoadCounterPass _clearLoadCounterPass;
private CacaoPrepareDepthsPass _prepareDepthsPass;
private CacaoPrepareNormalsPass _prepareNormalsPass;
private CacaoGenerateBaseSsaoPass _generateBaseSsaoPass;
@ -48,6 +49,7 @@ namespace FidelityFX
private void CreatePasses(CacaoShaders shaders)
{
_clearLoadCounterPass = new CacaoClearLoadCounterPass(shaders.clearLoadCounter, _resources);
_prepareDepthsPass = new CacaoPrepareDepthsPass(shaders.prepareDepths, _resources);
_prepareNormalsPass = new CacaoPrepareNormalsPass(shaders.prepareNormals, _resources);
_generateBaseSsaoPass = new CacaoGenerateBaseSsaoPass(shaders.generateSsao, _resources);
@ -60,6 +62,7 @@ namespace FidelityFX
public void Destroy()
{
DestroyPass(ref _clearLoadCounterPass);
DestroyPass(ref _prepareDepthsPass);
DestroyPass(ref _prepareNormalsPass);
DestroyPass(ref _generateBaseSsaoPass);
@ -110,8 +113,8 @@ namespace FidelityFX
commandBuffer.SetBufferData(_constantsBuffer, _constants);
// Clear load counter
commandBuffer.SetRenderTarget(_resources.LoadCounter);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
// The same could be accomplished with a ClearRenderTarget on the LoadCounter texture, but Unity does not allow that with async compute
_clearLoadCounterPass.Execute(commandBuffer, _constantsBuffer);
// Prepare depths, normals and mips
commandBuffer.BeginSample(PrepareMarker);

24
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/CACAO/CacaoPass.cs

@ -22,7 +22,7 @@ namespace FidelityFX
{
if (shader == null)
{
throw new MissingReferenceException($"Shader for FSR3 Upscaler '{passName}' could not be loaded! Please ensure it is included in the project correctly.");
throw new MissingReferenceException($"Shader for CACAO '{passName}' could not be loaded! Please ensure it is included in the project correctly.");
}
ComputeShader = shader;
@ -46,6 +46,28 @@ namespace FidelityFX
}
}
internal class CacaoClearLoadCounterPass : CacaoPass
{
private enum Kernels
{
CS,
}
public CacaoClearLoadCounterPass(ComputeShader shader, CacaoResources resources)
: base(resources)
{
InitComputeShaders<Kernels>("clear_load_counter", shader);
}
public void Execute(CommandBuffer commandBuffer, ComputeBuffer constants)
{
int kernelIndex = KernelIndices[(int)Kernels.CS];
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CacaoShaderIDs.CbSsaoConstantsBuffer, constants, 0, Marshal.SizeOf<Cacao.Constants>());
commandBuffer.SetComputeTextureParam(ComputeShader, kernelIndex, CacaoShaderIDs.UavLoadCounterBuffer, Resources.LoadCounter);
commandBuffer.DispatchCompute(ComputeShader, kernelIndex, 1, 1, 1);
}
}
internal class CacaoPrepareDepthsPass : CacaoPass
{
private enum Kernels

1
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/HDRenderPipeline.FidelityFX.Cacao.cs

@ -41,6 +41,7 @@ namespace UnityEngine.Rendering.HighDefinition
m_CacaoContext = new CacaoContext();
m_CacaoContext.Init(new CacaoShaders
{
clearLoadCounter = runtimeShaders.cacaoClearLoadCounter,
prepareDepths = runtimeShaders.cacaoPrepareDepths,
prepareNormals = runtimeShaders.cacaoPrepareNormals,
generateImportanceMap = runtimeShaders.cacaoGenerateImportanceMap,

8
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_clear_load_counter_pass.compute

@ -0,0 +1,8 @@
#pragma kernel CS
#define FFX_GPU // Compiling for GPU
#define FFX_HLSL // Compile for plain HLSL
#include "ffx_cacao_common_hdrp.cginc"
#include "shaders/ffx_cacao_clear_load_counter_pass.hlsl"

7
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/ffx_cacao_clear_load_counter_pass.compute.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c094ed852dad311478628ff78e8e1a42
ComputeShaderImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

48
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/ffx_cacao_clear_load_counter_pass.hlsl

@ -0,0 +1,48 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#define CACAO_BIND_UAV_LOAD_COUNTER 0
#define CACAO_BIND_CB_CACAO 0
#include "cacao/ffx_cacao_callbacks_hlsl.h"
#ifndef FFX_CACAO_THREAD_GROUP_WIDTH
#define FFX_CACAO_THREAD_GROUP_WIDTH 1
#endif // #ifndef FFX_CACAO_THREAD_GROUP_WIDTH
#ifndef FFX_CACAO_THREAD_GROUP_HEIGHT
#define FFX_CACAO_THREAD_GROUP_HEIGHT 1
#endif // FFX_CACAO_THREAD_GROUP_HEIGHT
#ifndef FFX_CACAO_THREAD_GROUP_DEPTH
#define FFX_CACAO_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_CACAO_THREAD_GROUP_DEPTH
#ifndef FFX_CACAO_NUM_THREADS
#define FFX_CACAO_NUM_THREADS [numthreads(FFX_CACAO_THREAD_GROUP_WIDTH, FFX_CACAO_THREAD_GROUP_HEIGHT, FFX_CACAO_THREAD_GROUP_DEPTH)]
#endif // #ifndef FFX_CACAO_NUM_THREADS
FFX_PREFER_WAVE64
FFX_CACAO_NUM_THREADS
FFX_CACAO_EMBED_ROOTSIG_CONTENT
void CS()
{
FFX_CACAO_ClearLoadCounter_SetLoadCounter(0);
}

7
com.unity.render-pipelines.high-definition/Runtime/FidelityFX/shaders/ffx_cacao_clear_load_counter_pass.hlsl.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 32c3c0650f00bf948b435ceed9f0ceda
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
com.unity.render-pipelines.high-definition/Runtime/Settings/HDRenderPipelineRuntimeShaders.cs

@ -1085,6 +1085,13 @@ namespace UnityEngine.Rendering.HighDefinition
// FidelityFX CACAO
[SerializeField, ResourcePath("Runtime/FidelityFX/ffx_cacao_clear_load_counter_pass.compute")]
private ComputeShader m_cacaoClearLoadCounter;
public ComputeShader cacaoClearLoadCounter
{
get => m_cacaoClearLoadCounter;
set => this.SetValueAndNotify(ref m_cacaoClearLoadCounter, value);
}
[SerializeField, ResourcePath("Runtime/FidelityFX/ffx_cacao_prepare_depths_pass.compute")]
private ComputeShader m_cacaoPrepareDepths;
public ComputeShader cacaoPrepareDepths

Loading…
Cancel
Save