You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

903 lines
30 KiB

// 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.
#include "ffx_cacao_resources.h"
#if defined(FFX_GPU)
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic push
#pragma dxc diagnostic ignored "-Wambig-lit-shift"
#endif //__hlsl_dx_compiler
#include "../common/ffx_core.h"
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic pop
#endif //__hlsl_dx_compiler
#endif // #if defined(FFX_GPU)
#if defined(FFX_GPU)
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // #if defined(FFX_GPU)
#if defined(FFX_GPU)
#pragma warning(disable: 3205) // conversion from larger type to smaller
#endif // #if defined(FFX_GPU)
#define DECLARE_SRV_REGISTER(regIndex) t##regIndex
#define DECLARE_UAV_REGISTER(regIndex) u##regIndex
#define DECLARE_CB_REGISTER(regIndex) b##regIndex
#define FFX_CACAO_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))
#define FFX_CACAO_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))
#define FFX_CACAO_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))
#if defined(CACAO_BIND_CB_CACAO)
cbuffer SSAOConstantsBuffer : register(b0)
{
FfxFloat32x2 g_FFX_CACAO_DepthUnpackConsts;
FfxFloat32x2 g_FFX_CACAO_CameraTanHalfFOV;
FfxFloat32x2 g_FFX_CACAO_NDCToViewMul;
FfxFloat32x2 g_FFX_CACAO_NDCToViewAdd;
FfxFloat32x2 g_FFX_CACAO_DepthBufferUVToViewMul;
FfxFloat32x2 g_FFX_CACAO_DepthBufferUVToViewAdd;
FfxFloat32 g_FFX_CACAO_EffectRadius; // world (viewspace) maximum size of the shadow
FfxFloat32 g_FFX_CACAO_EffectShadowStrength; // global strength of the effect (0 - 5)
FfxFloat32 g_FFX_CACAO_EffectShadowPow;
FfxFloat32 g_FFX_CACAO_EffectShadowClamp;
FfxFloat32 g_FFX_CACAO_EffectFadeOutMul; // effect fade out from distance (ex. 25)
FfxFloat32 g_FFX_CACAO_EffectFadeOutAdd; // effect fade out to distance (ex. 100)
FfxFloat32 g_FFX_CACAO_EffectHorizonAngleThreshold; // limit errors on slopes and caused by insufficient geometry tessellation (0.05 to 0.5)
FfxFloat32 g_FFX_CACAO_EffectSamplingRadiusNearLimitRec; // if viewspace pixel closer than this, don't enlarge shadow sampling radius anymore (makes no sense to grow beyond some distance, not enough samples to cover everything, so just limit the shadow growth; could be SSAOSettingsFadeOutFrom * 0.1 or less)
FfxFloat32 g_FFX_CACAO_DepthPrecisionOffsetMod;
FfxFloat32 g_FFX_CACAO_NegRecEffectRadius; // -1.0 / EffectRadius
FfxFloat32 g_FFX_CACAO_LoadCounterAvgDiv; // 1.0 / ( halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeX * halfDepthMip[SSAO_DEPTH_MIP_LEVELS-1].sizeY )
FfxFloat32 g_FFX_CACAO_AdaptiveSampleCountLimit;
FfxFloat32 g_FFX_CACAO_InvSharpness;
FfxInt32 g_FFX_CACAO_BlurNumPasses;
FfxFloat32 g_FFX_CACAO_BilateralSigmaSquared;
FfxFloat32 g_FFX_CACAO_BilateralSimilarityDistanceSigma;
FfxFloat32x4 g_FFX_CACAO_PatternRotScaleMatrices[4][5];
FfxFloat32 g_FFX_CACAO_NormalsUnpackMul;
FfxFloat32 g_FFX_CACAO_NormalsUnpackAdd;
FfxFloat32 g_FFX_CACAO_DetailAOStrength;
FfxInt32 g_FFX_CACAO_Dummy0;
FfxFloat32x2 g_FFX_CACAO_SSAOBufferDimensions;
FfxFloat32x2 g_FFX_CACAO_SSAOBufferInverseDimensions;
FfxFloat32x2 g_FFX_CACAO_DepthBufferDimensions;
FfxFloat32x2 g_FFX_CACAO_DepthBufferInverseDimensions;
FfxInt32x2 g_FFX_CACAO_DepthBufferOffset;
FfxInt32x2 g_FFX_CACAO_Pad;
FfxFloat32x4 g_FFX_CACAO_PerPassFullResUVOffset[4];
FfxFloat32x2 g_FFX_CACAO_OutputBufferDimensions;
FfxFloat32x2 g_FFX_CACAO_OutputBufferInverseDimensions;
FfxFloat32x2 g_FFX_CACAO_ImportanceMapDimensions;
FfxFloat32x2 g_FFX_CACAO_ImportanceMapInverseDimensions;
FfxFloat32x2 g_FFX_CACAO_DeinterleavedDepthBufferDimensions;
FfxFloat32x2 g_FFX_CACAO_DeinterleavedDepthBufferInverseDimensions;
FfxFloat32x2 g_FFX_CACAO_DeinterleavedDepthBufferOffset;
FfxFloat32x2 g_FFX_CACAO_DeinterleavedDepthBufferNormalisedOffset;
float4x4 g_FFX_CACAO_NormalsWorldToViewspaceMatrix;
FfxFloat32x4 g_FFX_CACAO_RTHandleScale;
};
#define FFX_CACAO_CONSTANT_BUFFER_1_SIZE 172 // Number of 32-bit values. This must be kept in sync with max( cbRCAS , cbSPD) size.
#endif
FfxFloat32x2 DepthUnpackConsts(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthUnpackConsts;
#else
return 0;
#endif
}
FfxFloat32x2 CameraTanHalfFOV(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_CameraTanHalfFOV;
#else
return 0;
#endif
}
FfxFloat32x2 NDCToViewMul(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NDCToViewMul;
#else
return 0;
#endif
}
FfxFloat32x2 NDCToViewAdd(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NDCToViewAdd;
#else
return 0;
#endif
}
FfxFloat32x2 DepthBufferUVToViewMul(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthBufferUVToViewMul;
#else
return 0;
#endif
}
FfxFloat32x2 DepthBufferUVToViewAdd(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthBufferUVToViewAdd;
#else
return 0;
#endif
}
FfxFloat32 EffectRadius(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectRadius;
#else
return 0;
#endif
}
FfxFloat32 EffectShadowStrength(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectShadowStrength;
#else
return 0;
#endif
}
FfxFloat32 EffectShadowPow(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectShadowPow;
#else
return 0;
#endif
}
FfxFloat32 EffectShadowClamp(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectShadowClamp;
#else
return 0;
#endif
}
FfxFloat32 EffectFadeOutMul(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectFadeOutMul;
#else
return 0;
#endif
}
FfxFloat32 EffectFadeOutAdd(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectFadeOutAdd;
#else
return 0;
#endif
}
FfxFloat32 EffectHorizonAngleThreshold(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectHorizonAngleThreshold;
#else
return 0;
#endif
}
FfxFloat32 EffectSamplingRadiusNearLimitRec(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_EffectSamplingRadiusNearLimitRec;
#else
return 0;
#endif
}
FfxFloat32 DepthPrecisionOffsetMod(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthPrecisionOffsetMod;
#else
return 0;
#endif
}
FfxFloat32 NegRecEffectRadius(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NegRecEffectRadius;
#else
return 0;
#endif
}
FfxFloat32 LoadCounterAvgDiv(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_LoadCounterAvgDiv;
#else
return 0;
#endif
}
FfxFloat32 AdaptiveSampleCountLimit(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_AdaptiveSampleCountLimit;
#else
return 0;
#endif
}
FfxFloat32 InvSharpness(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_InvSharpness;
#else
return 0;
#endif
}
FfxInt32 BlurNumPasses(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_BlurNumPasses;
#else
return 0;
#endif
}
FfxFloat32 BilateralSigmaSquared(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_BilateralSigmaSquared;
#else
return 0;
#endif
}
FfxFloat32 BilateralSimilarityDistanceSigma(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_BilateralSimilarityDistanceSigma;
#else
return 0;
#endif
}
FfxFloat32x4 PatternRotScaleMatrices(uint i, uint j){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_PatternRotScaleMatrices[i][j];
#else
return 0;
#endif
}
FfxFloat32 NormalsUnpackMul(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NormalsUnpackMul;
#else
return 0;
#endif
}
FfxFloat32 NormalsUnpackAdd(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NormalsUnpackAdd;
#else
return 0;
#endif
}
FfxFloat32 DetailAOStrength(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DetailAOStrength;
#else
return 0;
#endif
}
FfxFloat32 Dummy0(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_Dummy0;
#else
return 0;
#endif
}
FfxFloat32x2 SSAOBufferDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_SSAOBufferDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 SSAOBufferInverseDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_SSAOBufferInverseDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 DepthBufferDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthBufferDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 DepthBufferInverseDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthBufferInverseDimensions;
#else
return 0;
#endif
}
FfxInt32x2 DepthBufferOffset(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DepthBufferOffset;
#else
return 0;
#endif
}
FfxFloat32x4 PerPassFullResUVOffset(uint i){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_PerPassFullResUVOffset[i];
#else
return 0;
#endif
}
FfxFloat32x2 OutputBufferDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_OutputBufferDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 OutputBufferInverseDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_OutputBufferInverseDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 ImportanceMapDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_ImportanceMapDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 ImportanceMapInverseDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_ImportanceMapInverseDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 DeinterleavedDepthBufferDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DeinterleavedDepthBufferDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 DeinterleavedDepthBufferInverseDimensions(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DeinterleavedDepthBufferInverseDimensions;
#else
return 0;
#endif
}
FfxFloat32x2 DeinterleavedDepthBufferOffset(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DeinterleavedDepthBufferOffset;
#else
return 0;
#endif
}
FfxFloat32x2 DeinterleavedDepthBufferNormalisedOffset(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_DeinterleavedDepthBufferNormalisedOffset;
#else
return 0;
#endif
}
float4x4 NormalsWorldToViewspaceMatrix(){
#if defined(CACAO_BIND_CB_CACAO)
return g_FFX_CACAO_NormalsWorldToViewspaceMatrix;
#else
return 0;
#endif
}
FfxFloat32x2 ClampAndScaleUV_HDRP(FfxFloat32x2 UV)
{
#if defined(CACAO_BIND_CB_CACAO)
return min(UV, 1.0f) * g_FFX_CACAO_RTHandleScale.xy;
#else
return UV;
#endif
}
#if defined(FFX_GPU)
#define FFX_CACAO_ROOTSIG_STRINGIFY(p) FFX_CACAO_ROOTSIG_STR(p)
#define FFX_CACAO_ROOTSIG_STR(p) #p
#define FFX_CACAO_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"RootConstants(num32BitConstants=" FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_CONSTANT_BUFFER_1_SIZE) ", b0) ")] \
#define FFX_CACAO_CB2_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"RootConstants(num32BitConstants=" FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_CONSTANT_BUFFER_1_SIZE) ", b0), " \
#define FFX_CACAO_CB_GENERATE_REACTIVE_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_RESOURCE_IDENTIFIER_COUNT) ")), " \
"RootConstants(num32BitConstants=" FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_CONSTANT_BUFFER_1_SIZE) ", b0), " \
"RootConstants(num32BitConstants=" FFX_CACAO_ROOTSIG_STRINGIFY(FFX_CACAO_CONSTANT_BUFFER_GENERATE_REACTIVE_SIZE) ", b1), ")] \
#if defined(FFX_CACAO_EMBED_ROOTSIG)
#define FFX_CACAO_EMBED_ROOTSIG_CONTENT FFX_CACAO_ROOTSIG
#define FFX_CACAO_EMBED_CB2_ROOTSIG_CONTENT FFX_CACAO_CB2_ROOTSIG
#define FFX_CACAO_EMBED_CB_GENERATE_REACTIVE_ROOTSIG_CONTENT FFX_CACAO_CB_GENERATE_REACTIVE_ROOTSIG
#else
#define FFX_CACAO_EMBED_ROOTSIG_CONTENT
#define FFX_CACAO_EMBED_CB2_ROOTSIG_CONTENT
#define FFX_CACAO_EMBED_CB_GENERATE_REACTIVE_ROOTSIG_CONTENT
#endif // #if FFX_CACAO_EMBED_ROOTSIG
#endif // #if defined(FFX_GPU)
SamplerState g_PointClampSampler : register(s0);
SamplerState g_PointMirrorSampler : register(s1);
SamplerState g_LinearClampSampler : register(s2);
SamplerState g_ViewPointClampSampler : register(s3);
SamplerState g_RealPointClampSampler : register(s4);
#if defined CACAO_BIND_SRV_DEPTH_IN
Texture2D<FfxFloat32> g_DepthIn : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_DEPTH_IN);
#endif
#if defined CACAO_BIND_SRV_NORMAL_IN
Texture2D<FfxFloat32x4> g_NormalIn : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_NORMAL_IN);
#endif
#if defined CACAO_BIND_SRV_LOAD_COUNTER
Texture1D<FfxUInt32> g_LoadCounter : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_LOAD_COUNTER);
#endif
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
Texture2DArray<FfxFloat32> g_DeinterleavedDepth : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS);
#endif
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
Texture2DArray<FfxFloat32x4> g_DeinterleavedNormals : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_DEINTERLEAVED_NORMALS);
#endif
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
Texture2DArray<FfxFloat32x2> g_SsaoBufferPing : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_SSAO_BUFFER_PING);
#endif
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
Texture2DArray<FfxFloat32x2> g_SsaoBufferPong : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_SSAO_BUFFER_PONG);
#endif
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
Texture2D<FfxFloat32> g_ImportanceMap : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_IMPORTANCE_MAP);
#endif
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
Texture2D<FfxFloat32> g_ImportanceMapPong : FFX_CACAO_DECLARE_SRV(CACAO_BIND_SRV_IMPORTANCE_MAP_PONG);
#endif
#if defined CACAO_BIND_UAV_LOAD_COUNTER
RWTexture1D<FfxUInt32> g_RwLoadCounter : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_LOAD_COUNTER);
#endif
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
RWTexture2DArray<FfxFloat32> g_RwDeinterleavedDepth : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS);
#endif
#if defined CACAO_BIND_UAV_DEINTERLEAVED_NORMALS
RWTexture2DArray<FfxFloat32x4> g_RwDeinterleavedNormals : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_DEINTERLEAVED_NORMALS);
#endif
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
RWTexture2DArray<FfxFloat32x2> g_RwSsaoBufferPing : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_SSAO_BUFFER_PING);
#endif
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
RWTexture2DArray<FfxFloat32x2> g_RwSsaoBufferPong : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_SSAO_BUFFER_PONG);
#endif
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
RWTexture2D<FfxFloat32> g_RwImportanceMap : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_IMPORTANCE_MAP);
#endif
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
RWTexture2D<FfxFloat32> g_RwImportanceMapPong : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_IMPORTANCE_MAP_PONG);
#endif
#if defined CACAO_BIND_UAV_OUTPUT
RWTexture2D<FfxFloat32> g_RwOutput : FFX_CACAO_DECLARE_UAV(CACAO_BIND_UAV_OUTPUT);
#endif
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
RWTexture2DArray<FfxFloat32> g_RwDepthMips0 : FFX_CACAO_DECLARE_UAV(0);
RWTexture2DArray<FfxFloat32> g_RwDepthMips1 : FFX_CACAO_DECLARE_UAV(1);
RWTexture2DArray<FfxFloat32> g_RwDepthMips2 : FFX_CACAO_DECLARE_UAV(2);
RWTexture2DArray<FfxFloat32> g_RwDepthMips3 : FFX_CACAO_DECLARE_UAV(3);
#endif
// =============================================================================
// Clear Load Counter
void FFX_CACAO_ClearLoadCounter_SetLoadCounter(FfxUInt32 val)
{
#if defined CACAO_BIND_UAV_LOAD_COUNTER
g_RwLoadCounter[0] = val;
#endif
}
// =============================================================================
// Edge Sensitive Blur
FfxFloat32x2 FFX_CACAO_EdgeSensitiveBlur_SampleInputOffset(FfxFloat32x2 uv, FfxInt32x2 offset, FfxUInt32 layerId)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.SampleLevel(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), 0.0f, offset);
#else
return FfxFloat32x2(0, 0);
#endif
}
FfxFloat32x2 FFX_CACAO_EdgeSensitiveBlur_SampleInput(FfxFloat32x2 uv, FfxUInt32 layerId)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.SampleLevel(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), 0.0f);
#else
return FfxFloat32x2(0, 0);
#endif
}
void FFX_CACAO_EdgeSensitiveBlur_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 value, FfxUInt32 layerId)
{
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PONG
g_RwSsaoBufferPong[FfxInt32x3(coord, layerId)] = value;
#endif
}
// =============================================================================
// SSAO Generation
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleViewspaceDepthMip(FfxFloat32x2 uv, FfxFloat32 mip, FfxUInt32 layerId)
{
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
return g_DeinterleavedDepth.SampleLevel(g_ViewPointClampSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), mip);
#else
return 0;
#endif
}
FfxFloat32x4 FFX_CACAO_SSAOGeneration_GatherViewspaceDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset, FfxUInt32 layerId)
{
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
return g_DeinterleavedDepth.GatherRed(g_PointMirrorSampler, FfxFloat32x3(uv, FfxFloat32(layerId)), offset);
#else
return FfxFloat32x4(0, 0, 0, 0);
#endif
}
FfxUInt32 FFX_CACAO_SSAOGeneration_GetLoadCounter()
{
#if defined CACAO_BIND_SRV_LOAD_COUNTER
return g_LoadCounter[0];
#else
return 0;
#endif
}
FfxFloat32 FFX_CACAO_SSAOGeneration_SampleImportance(FfxFloat32x2 uv)
{
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
return g_ImportanceMap.SampleLevel(g_LinearClampSampler, uv, 0.0f);
#else
return 0;
#endif
}
FfxFloat32x2 FFX_CACAO_SSAOGeneration_LoadBasePassSSAOPass(FfxUInt32x2 coord, FfxUInt32 passnum)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
return g_SsaoBufferPong.Load(FfxInt32x4(coord, passnum, 0)).xy;
#else
return FfxFloat32x2(0, 0);
#endif
}
FfxFloat32x3 FFX_CACAO_SSAOGeneration_GetNormalPass(FfxUInt32x2 coord, FfxUInt32 passnum)
{
#if defined CACAO_BIND_SRV_DEINTERLEAVED_NORMALS
return g_DeinterleavedNormals[FfxInt32x3(coord, passnum)].xyz;
#else
return FfxFloat32x3(0, 0, 0);
#endif
}
void FFX_CACAO_SSAOGeneration_StoreOutput(FfxUInt32x2 coord, FfxFloat32x2 val, FfxUInt32 layerId)
{
#if defined CACAO_BIND_UAV_SSAO_BUFFER_PING
g_RwSsaoBufferPing[FfxInt32x3(coord, layerId)] = val;
#endif
}
// ============================================================================
// Apply
// This resource can be ssao ping or pong, handled by schedule Dispatch
FfxFloat32 FFX_CACAO_Apply_SampleSSAOUVPass(FfxFloat32x2 uv, FfxUInt32 passnum)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.SampleLevel(g_LinearClampSampler, FfxFloat32x3(uv, passnum), 0.0f).x;
#else
return 0;
#endif
}
FfxFloat32x2 FFX_CACAO_Apply_LoadSSAOPass(FfxUInt32x2 coord, FfxUInt32 passnum)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.Load(FfxInt32x4(coord, passnum, 0));
#else
return FfxFloat32x2(0, 0);
#endif
}
void FFX_CACAO_Apply_StoreOutput(FfxUInt32x2 coord, FfxFloat32 val)
{
FFX_CACAO_Apply_StoreOutput_Unity(coord, val);
// #if defined CACAO_BIND_UAV_OUTPUT
// g_RwOutput[coord] = val;
// #endif
}
// =============================================================================
// Prepare
FfxFloat32x4 FFX_CACAO_Prepare_SampleDepthOffsets(FfxFloat32x2 uv)
{
return FFX_CACAO_Prepare_SampleDepthOffsets_Unity(ClampAndScaleUV_HDRP(uv));
// #if defined CACAO_BIND_SRV_DEPTH_IN
// FfxFloat32x4 samples;
// samples.x = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(0, 2));
// samples.y = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(2, 2));
// samples.z = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(2, 0));
// samples.w = g_DepthIn.SampleLevel(g_PointClampSampler, uv, 0.0f, FfxInt32x2(0, 0));
// return samples;
// #else
// return FfxFloat32x4(0, 0, 0, 0);
// #endif
}
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepth(FfxFloat32x2 uv)
{
return FFX_CACAO_Prepare_GatherDepth_Unity(ClampAndScaleUV_HDRP(uv));
// #if defined CACAO_BIND_SRV_DEPTH_IN
// return g_DepthIn.GatherRed(g_PointClampSampler, uv);
// #else
// return FfxFloat32x4(0, 0, 0, 0);
// #endif
}
FfxFloat32 FFX_CACAO_Prepare_LoadDepth(FfxUInt32x2 coord)
{
return FFX_CACAO_Prepare_LoadDepth_Unity(coord);
// #if defined CACAO_BIND_SRV_DEPTH_IN
// return g_DepthIn.Load(FfxInt32x3(coord, 0));
// #else
// return 0;
// #endif
}
FfxFloat32 FFX_CACAO_Prepare_LoadDepthOffset(FfxUInt32x2 coord, FfxInt32x2 offset)
{
return FFX_CACAO_Prepare_LoadDepthOffset_Unity(coord, offset);
// #if defined CACAO_BIND_SRV_DEPTH_IN
// return g_DepthIn.Load(FfxInt32x3(coord, 0), offset);
// #else
// return 0;
// #endif
}
FfxFloat32x4 FFX_CACAO_Prepare_GatherDepthOffset(FfxFloat32x2 uv, FfxInt32x2 offset)
{
return FFX_CACAO_Prepare_GatherDepthOffset_Unity(ClampAndScaleUV_HDRP(uv), offset);
// #if defined CACAO_BIND_SRV_DEPTH_IN
// return g_DepthIn.GatherRed(g_PointClampSampler, uv, offset);
// #else
// return FfxFloat32x4(0, 0, 0, 0);
// #endif
}
FfxFloat32x3 FFX_CACAO_Prepare_LoadNormal(FfxUInt32x2 coord)
{
#if defined CACAO_BIND_SRV_NORMAL_IN
//FfxFloat32x3 normal = g_NormalIn.Load(FfxInt32x3(coord, 0)).xyz;
FfxFloat32x3 normal = LoadSceneNormals_Unity(coord);
//normal = normal * NormalsUnpackMul().xxx + NormalsUnpackAdd().xxx;
normal = mul(normal, (float3x3)NormalsWorldToViewspaceMatrix()).xyz;
// normal = normalize(normal);
return normal;
#else
return FfxFloat32x3(0, 0, 0);
#endif
}
void FFX_CACAO_Prepare_StoreDepthMip0(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
g_RwDepthMips0[FfxInt32x3(coord, index)] = val;
#endif
}
void FFX_CACAO_Prepare_StoreDepthMip1(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
g_RwDepthMips1[FfxInt32x3(coord, index)] = val;
#endif
}
void FFX_CACAO_Prepare_StoreDepthMip2(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
g_RwDepthMips2[FfxInt32x3(coord, index)] = val;
#endif
}
void FFX_CACAO_Prepare_StoreDepthMip3(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_DEPTH_DOWNSAMPLED_MIPS
g_RwDepthMips3[FfxInt32x3(coord, index)] = val;
#endif
}
void FFX_CACAO_Prepare_StoreDepth(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_DEINTERLEAVED_DEPTHS
g_RwDeinterleavedDepth[FfxInt32x3(coord, index)] = val;
#endif
}
void FFX_CACAO_Prepare_StoreNormal(FfxUInt32x2 coord, FfxUInt32 index, FfxFloat32x3 normal)
{
#if defined CACAO_BIND_UAV_DEINTERLEAVED_NORMALS
g_RwDeinterleavedNormals[FfxInt32x3(coord, index)] = FfxFloat32x4(normal, 1.0f);
#endif
}
// =============================================================================
// Importance Map
FfxFloat32x4 FFX_CACAO_Importance_GatherSSAO(FfxFloat32x2 uv, FfxUInt32 index)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PONG
return g_SsaoBufferPong.GatherRed(g_PointClampSampler, FfxFloat32x3(uv, index));
#else
return FfxFloat32x4(0, 0, 0, 0);
#endif
}
void FFX_CACAO_Importance_StoreImportance(FfxUInt32x2 coord, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
g_RwImportanceMap[coord] = val;
#endif
}
FfxFloat32 FFX_CACAO_Importance_SampleImportanceA(FfxFloat32x2 uv)
{
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP
return g_ImportanceMap.SampleLevel(g_LinearClampSampler, uv, 0.0f);
#else
return 0;
#endif
}
void FFX_CACAO_Importance_StoreImportanceA(FfxUInt32x2 coord, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP_PONG
g_RwImportanceMapPong[coord] = val;
#endif
}
FfxFloat32 FFX_CACAO_Importance_SampleImportanceB(FfxFloat32x2 uv)
{
#if defined CACAO_BIND_SRV_IMPORTANCE_MAP_PONG
return g_ImportanceMapPong.SampleLevel(g_LinearClampSampler, uv, 0.0f);
#else
return 0;
#endif
}
void FFX_CACAO_Importance_StoreImportanceB(FfxUInt32x2 coord, FfxFloat32 val)
{
#if defined CACAO_BIND_UAV_IMPORTANCE_MAP
g_RwImportanceMap[coord] = val;
#endif
}
void FFX_CACAO_Importance_LoadCounterInterlockedAdd(FfxUInt32 val)
{
#if defined CACAO_BIND_UAV_LOAD_COUNTER
InterlockedAdd(g_RwLoadCounter[0], val);
#endif
}
// =============================================================================
// Bilateral Upscale
// These resources ping/pong which is handled by schedule dispatch
void FFX_CACAO_BilateralUpscale_StoreOutput(FfxUInt32x2 coord, FfxInt32x2 offset, FfxFloat32 val)
{
FFX_CACAO_BilateralUpscale_StoreOutput_Unity(coord, offset, val);
// #if defined CACAO_BIND_UAV_OUTPUT
// g_RwOutput[coord + offset] = val;
// #endif
}
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOLinear(FfxFloat32x2 uv, FfxUInt32 index)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.SampleLevel(g_LinearClampSampler, FfxFloat32x3(uv, index), 0).x;
#else
return 0;
#endif
}
FfxFloat32 FFX_CACAO_BilateralUpscale_SampleSSAOPoint(FfxFloat32x2 uv, FfxUInt32 index)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.SampleLevel(g_PointClampSampler, FfxFloat32x3(uv, index), 0).x;
#else
return 0;
#endif
}
FfxFloat32x2 FFX_CACAO_BilateralUpscale_LoadSSAO(FfxUInt32x2 coord, FfxUInt32 index)
{
#if defined CACAO_BIND_SRV_SSAO_BUFFER_PING
return g_SsaoBufferPing.Load(FfxInt32x4(coord, index, 0));
#else
return 0;
#endif
}
FfxFloat32x4 FFX_CACAO_BilateralUpscale_LoadDepths(FfxUInt32x2 coord)
{
return FFX_CACAO_BilateralUpscale_LoadDepths_Unity(coord);
// FfxFloat32x4 depths;
// #if defined CACAO_BIND_SRV_DEPTH_IN
// depths.x = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 0));
// depths.y = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 0));
// depths.z = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(0, 1));
// depths.w = g_DepthIn.Load(FfxInt32x3(coord, 0), FfxInt32x2(1, 1));
// return depths;
// #else
// return FfxFloat32x4(0, 0, 0, 0);
// #endif
}
FfxFloat32 FFX_CACAO_BilateralUpscale_LoadDownscaledDepth(FfxUInt32x2 coord, FfxUInt32 index)
{
#if defined CACAO_BIND_SRV_DEINTERLEAVED_DEPTHS
return g_DeinterleavedDepth.Load(FfxInt32x4(coord, index, 0));
#else
return 0;
#endif
}
#endif // #if defined(FFX_GPU)