16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 17:29:18 +02:00

Some renaming

This commit is contained in:
2025-04-15 01:32:56 +02:00
parent 12d6a1578d
commit a39d972126
864 changed files with 29 additions and 34 deletions

View File

@@ -0,0 +1,49 @@
# This file is part of the FidelityFX SDK.
#
# Copyright (C) 2024 Advanced Micro Devices, Inc.
#
# 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.
set(SSSR_BASE_ARGS
-reflection -deps=gcc -DFFX_GPU=1)
set(SSSR_PERMUTATION_ARGS
-DFFX_SSSR_OPTION_INVERTED_DEPTH={0,1})
set(SSSR_INCLUDE_ARGS
"${FFX_GPU_PATH}"
"${FFX_GPU_PATH}/sssr")
if (NOT SSSR_SHADER_EXT)
set(SSSR_SHADER_EXT *)
endif()
file(GLOB SSSR_SHADERS
"shaders/sssr/ffx_sssr_classify_tiles_pass.${SSSR_SHADER_EXT}"
"shaders/sssr/ffx_sssr_depth_downsample_pass.${SSSR_SHADER_EXT}"
"shaders/sssr/ffx_sssr_intersect_pass.${SSSR_SHADER_EXT}"
"shaders/sssr/ffx_sssr_prepare_blue_noise_texture_pass.${SSSR_SHADER_EXT}"
"shaders/sssr/ffx_sssr_prepare_indirect_args_pass.${SSSR_SHADER_EXT}")
compile_shaders_with_depfile(
"${FFX_SC_EXECUTABLE}"
"${SSSR_BASE_ARGS}" "${SSSR_API_BASE_ARGS}" "${SSSR_PERMUTATION_ARGS}" "${SSSR_INCLUDE_ARGS}"
"${SSSR_SHADERS}" "${FFX_PASS_SHADER_OUTPUT_PATH}" SSSR_PERMUTATION_OUTPUTS)
add_shader_output("${SSSR_PERMUTATION_OUTPUTS}")

View File

@@ -0,0 +1,644 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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_sssr_resources.h"
#if defined(FFX_GPU)
#include "ffx_core.h"
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // #ifndef FFX_PREFER_WAVE64
#if defined(SSSR_BIND_CB_SSSR)
layout (set = 0, binding = SSSR_BIND_CB_SSSR, std140) uniform cbSSSR_t
{
FfxFloat32Mat4 invViewProjection;
FfxFloat32Mat4 projection;
FfxFloat32Mat4 invProjection;
FfxFloat32Mat4 viewMatrix;
FfxFloat32Mat4 invView;
FfxFloat32Mat4 prevViewProjection;
FfxUInt32x2 renderSize;
FfxFloat32x2 inverseRenderSize;
FfxFloat32 normalsUnpackMul;
FfxFloat32 normalsUnpackAdd;
FfxUInt32 roughnessChannel;
FfxBoolean isRoughnessPerceptual;
FfxFloat32 iblFactor;
FfxFloat32 temporalStabilityFactor;
FfxFloat32 depthBufferThickness;
FfxFloat32 roughnessThreshold;
FfxFloat32 varianceThreshold;
FfxUInt32 frameIndex;
FfxUInt32 maxTraversalIntersections;
FfxUInt32 minTraversalOccupancy;
FfxUInt32 mostDetailedMip;
FfxUInt32 samplesPerQuad;
FfxUInt32 temporalVarianceGuidedTracingEnabled;
} cbSSSR;
FfxFloat32Mat4 InvViewProjection()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.invViewProjection;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32Mat4 Projection()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.projection;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32Mat4 InvProjection()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.invProjection;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32Mat4 ViewMatrix()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.viewMatrix;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32Mat4 InvView()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.invView;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32Mat4 PrevViewProjection()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.prevViewProjection;
#else
return FfxFloat32Mat4(0.0f);
#endif
}
FfxFloat32 NormalsUnpackMul()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.normalsUnpackMul;
#else
return 0.0f;
#endif
}
FfxFloat32 NormalsUnpackAdd()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.normalsUnpackAdd;
#else
return 0.0f;
#endif
}
FfxUInt32 RoughnessChannel()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.roughnessChannel;
#else
return 0;
#endif
}
FfxBoolean IsRoughnessPerceptual()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.isRoughnessPerceptual;
#else
return false;
#endif
}
FfxUInt32x2 RenderSize()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.renderSize;
#else
return FfxUInt32x2(0);
#endif
}
FfxFloat32x2 InverseRenderSize()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.inverseRenderSize;
#else
return FfxFloat32x2(0.0f);
#endif
}
FfxFloat32 IBLFactor()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.iblFactor;
#else
return 0.0f;
#endif
}
FfxFloat32 TemporalStabilityFactor()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.temporalStabilityFactor;
#else
return 0.0f;
#endif
}
FfxFloat32 DepthBufferThickness()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.depthBufferThickness;
#else
return 0.0f;
#endif
}
FfxFloat32 RoughnessThreshold()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.roughnessThreshold;
#else
return 0.0f;
#endif
}
FfxFloat32 VarianceThreshold()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.varianceThreshold;
#else
return 0.0f;
#endif
}
FfxUInt32 FrameIndex()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.frameIndex;
#else
return 0;
#endif
}
FfxUInt32 MaxTraversalIntersections()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.maxTraversalIntersections;
#else
return 0;
#endif
}
FfxUInt32 MinTraversalOccupancy()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.minTraversalOccupancy;
#else
return 0;
#endif
}
FfxUInt32 MostDetailedMip()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.mostDetailedMip;
#else
return 0;
#endif
}
FfxUInt32 SamplesPerQuad()
{
#if defined SSSR_BIND_CB_SSSR
return cbSSSR.samplesPerQuad;
#else
return 0;
#endif
}
FfxBoolean TemporalVarianceGuidedTracingEnabled()
{
#if defined SSSR_BIND_CB_SSSR
return FfxBoolean(cbSSSR.temporalVarianceGuidedTracingEnabled);
#else
return false;
#endif
}
#endif // #if defined(SSSR_BIND_CB_SSSR)
layout (set = 0, binding = 1000) uniform sampler s_EnvironmentMapSampler;
layout (set = 0, binding = 1001) uniform sampler s_LinearSampler;
// SRVs
#if defined SSSR_BIND_SRV_INPUT_COLOR
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_COLOR) uniform texture2D r_input_color;
#endif
#if defined SSSR_BIND_SRV_INPUT_DEPTH
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_DEPTH) uniform texture2D r_input_depth;
#endif
#if defined SSSR_BIND_SRV_DEPTH_HIERARCHY
layout (set = 0, binding = SSSR_BIND_SRV_DEPTH_HIERARCHY) uniform texture2D r_depth_hierarchy;
#endif
#if defined SSSR_BIND_SRV_INPUT_NORMAL
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_NORMAL) uniform texture2D r_input_normal;
#endif
#if defined SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS) uniform texture2D r_input_material_parameters;
#endif
#if defined SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP) uniform textureCube r_input_environment_map;
#endif
#if defined SSSR_BIND_SRV_RADIANCE
layout (set = 0, binding = SSSR_BIND_SRV_RADIANCE) uniform texture2D r_radiance;
#endif
#if defined SSSR_BIND_SRV_RADIANCE_HISTORY
layout (set = 0, binding = SSSR_BIND_SRV_RADIANCE_HISTORY) uniform texture2D r_radiance_history;
#endif
#if defined SSSR_BIND_SRV_VARIANCE
layout (set = 0, binding = SSSR_BIND_SRV_VARIANCE) uniform texture2D r_variance;
#endif
#if defined SSSR_BIND_SRV_EXTRACTED_ROUGHNESS
layout (set = 0, binding = SSSR_BIND_SRV_EXTRACTED_ROUGHNESS) uniform texture2D r_extracted_roughness;
#endif
#if defined SSSR_BIND_SRV_SOBOL_BUFFER
layout (set = 0, binding = SSSR_BIND_SRV_SOBOL_BUFFER) uniform utexture2D r_sobol_buffer;
#endif
#if defined SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER
layout (set = 0, binding = SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER) uniform utexture2D r_scrambling_tile_buffer;
#endif
#if defined SSSR_BIND_SRV_BLUE_NOISE_TEXTURE
layout (set = 0, binding = SSSR_BIND_SRV_BLUE_NOISE_TEXTURE) uniform texture2D r_blue_noise_texture;
#endif
#if defined SSSR_BIND_SRV_INPUT_BRDF_TEXTURE
layout (set = 0, binding = SSSR_BIND_SRV_INPUT_BRDF_TEXTURE) uniform texture2D r_input_brdf_texture;
#endif
// UAVs
#if defined SSSR_BIND_UAV_OUTPUT
layout (set = 0, binding = SSSR_BIND_UAV_OUTPUT, rgba32f) uniform image2D rw_output;
#endif
#if defined SSSR_BIND_UAV_RADIANCE
layout (set = 0, binding = SSSR_BIND_UAV_RADIANCE, rgba32f) uniform image2D rw_radiance;
#endif
#if defined SSSR_BIND_UAV_VARIANCE
layout (set = 0, binding = SSSR_BIND_UAV_VARIANCE, r32f) uniform image2D rw_variance;
#endif
#if defined SSSR_BIND_UAV_RAY_LIST
layout (set = 0, binding = SSSR_BIND_UAV_RAY_LIST, std430) buffer rw_ray_list_t
{
FfxUInt32 data[];
} rw_ray_list;
#endif
#if defined SSSR_BIND_UAV_DENOISER_TILE_LIST
layout (set = 0, binding = SSSR_BIND_UAV_DENOISER_TILE_LIST, std430) buffer rw_denoiser_tile_list_t
{
FfxUInt32 data[];
} rw_denoiser_tile_list;
#endif
#if defined SSSR_BIND_UAV_RAY_COUNTER
layout (set = 0, binding = SSSR_BIND_UAV_RAY_COUNTER, std430) buffer rw_ray_counter_t
{
FfxUInt32 data[];
} rw_ray_counter;
#endif
#if defined SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS
layout (set = 0, binding = SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS, std430) buffer rw_intersection_pass_indirect_args_t
{
FfxUInt32 data[];
} rw_intersection_pass_indirect_args;
#endif
#if defined SSSR_BIND_UAV_EXTRACTED_ROUGHNESS
layout (set = 0, binding = SSSR_BIND_UAV_EXTRACTED_ROUGHNESS, r32f) uniform image2D rw_extracted_roughness;
#endif
#if defined SSSR_BIND_UAV_BLUE_NOISE_TEXTURE
layout (set = 0, binding = SSSR_BIND_UAV_BLUE_NOISE_TEXTURE, rg32f) uniform image2D rw_blue_noise_texture;
#endif
#if defined SSSR_BIND_UAV_DEPTH_HIERARCHY
layout (set = 0, binding = SSSR_BIND_UAV_DEPTH_HIERARCHY, r32f) uniform image2D rw_depth_hierarchy[13];
#endif
// SPD UAV
#if defined SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC
layout (set = 0, binding = SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC, std430) buffer rw_spd_global_atomic_t
{
FfxUInt32 data[];
} rw_spd_global_atomic;
#endif
#if FFX_HALF
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
FfxFloat16x4 SpdLoadH(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return FfxFloat16x4(imageLoad(rw_depth_hierarchy[6], coordinate).x); // 5 -> 6 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
FfxFloat16x4 SpdLoadSourceImageH(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return FfxFloat16x4(texelFetch(r_input_depth, coordinate, 0).x);
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void SpdStoreH(FfxInt32x2 pix, FfxFloat16x4 outValue, FfxUInt32 coordinate, FfxUInt32 slice)
{
imageStore(rw_depth_hierarchy[coordinate + 1], pix, FfxFloat16x4(outValue.x)); // + 1 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#endif // #if defined(FFX_HALF)
#if defined(SSSR_BIND_SRV_INPUT_NORMAL)
FfxFloat32x3 FFX_SSSR_LoadWorldSpaceNormal(FfxInt32x2 pixel_coordinate)
{
// Normals are
return normalize(NormalsUnpackMul() * texelFetch(r_input_normal, pixel_coordinate, 0).xyz + NormalsUnpackAdd());
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_NORMAL)
#if defined(SSSR_BIND_SRV_DEPTH_HIERARCHY)
FfxFloat32 FFX_SSSR_LoadDepth(FfxInt32x2 pixel_coordinate, FfxInt32 mip)
{
return texelFetch(r_depth_hierarchy, pixel_coordinate, mip).x;
}
#endif // #if defined(SSSR_BIND_SRV_DEPTH_HIERARCHY)
#if defined(SSSR_BIND_SRV_BLUE_NOISE_TEXTURE)
FfxFloat32x2 FFX_SSSR_SampleRandomVector2D(FfxUInt32x2 pixel)
{
return texelFetch(r_blue_noise_texture, FfxInt32x2(pixel.xy % 128), 0).xy;
}
#endif // #if defined(SSSR_BIND_SRV_BLUE_NOISE_TEXTURE)
#if defined(SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP)
FfxFloat32x3 FFX_SSSR_SampleEnvironmentMap(FfxFloat32x3 direction, FfxFloat32 preceptualRoughness)
{
FfxInt32x2 cubeSize = textureSize(r_input_environment_map, 0);
FfxInt32 maxMipLevel = FfxInt32(log2(FfxFloat32(cubeSize.x > 0 ? cubeSize.x : 1)));
FfxFloat32 lod = clamp(preceptualRoughness * FfxFloat32(maxMipLevel), 0.0, FfxFloat32(maxMipLevel));
return textureLod(samplerCube(r_input_environment_map, s_EnvironmentMapSampler), direction, lod).xyz * IBLFactor();
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void IncrementRayCounter(FfxUInt32 value, FFX_PARAMETER_OUT FfxUInt32 original_value)
{
original_value = atomicAdd(rw_ray_counter.data[0], value);
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void IncrementDenoiserTileCounter(FFX_PARAMETER_OUT FfxUInt32 original_value)
{
original_value = atomicAdd(rw_ray_counter.data[2], 1);
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxUInt32 PackRayCoords(FfxUInt32x2 ray_coord, FfxBoolean copy_horizontal, FfxBoolean copy_vertical, FfxBoolean copy_diagonal)
{
FfxUInt32 ray_x_15bit = ray_coord.x & 32767; // 0b111111111111111
FfxUInt32 ray_y_14bit = ray_coord.y & 16383; // 0b11111111111111;
FfxUInt32 copy_horizontal_1bit = copy_horizontal ? 1 : 0;
FfxUInt32 copy_vertical_1bit = copy_vertical ? 1 : 0;
FfxUInt32 copy_diagonal_1bit = copy_diagonal ? 1 : 0;
FfxUInt32 packed = (copy_diagonal_1bit << 31) | (copy_vertical_1bit << 30) | (copy_horizontal_1bit << 29) | (ray_y_14bit << 15) | (ray_x_15bit << 0);
return packed;
}
#if defined (SSSR_BIND_UAV_RAY_LIST)
void StoreRay(FfxInt32 index, FfxUInt32x2 ray_coord, FfxBoolean copy_horizontal, FfxBoolean copy_vertical, FfxBoolean copy_diagonal)
{
FfxUInt32 packedRayCoords = PackRayCoords(ray_coord, copy_horizontal, copy_vertical, copy_diagonal); // Store out pixel to trace
rw_ray_list.data[index] = packedRayCoords;
}
#endif // #if defined (SSSR_BIND_UAV_RAY_LIST)
#if defined (SSSR_BIND_UAV_DENOISER_TILE_LIST)
void StoreDenoiserTile(FfxInt32 index, FfxUInt32x2 tile_coord)
{
rw_denoiser_tile_list.data[index] = ((tile_coord.y & 0xffffu) << 16) | ((tile_coord.x & 0xffffu) << 0); // Store out pixel to trace
}
#endif // #if defined (SSSR_BIND_UAV_DENOISER_TILE_LIST)
#if defined (SSSR_BIND_SRV_DEPTH_HIERARCHY)
FfxBoolean IsReflectiveSurface(FfxUInt32x2 pixel_coordinate, FfxFloat32 roughness)
{
#if FFX_SSSR_OPTION_INVERTED_DEPTH
const FfxFloat32 far_plane = 0.0f;
return texelFetch(r_depth_hierarchy, FfxInt32x2(pixel_coordinate), 0).r > far_plane;
#else // FFX_SSSR_OPTION_INVERTED_DEPTH
const FfxFloat32 far_plane = 1.0f;
return texelFetch(r_depth_hierarchy, FfxInt32x2(pixel_coordinate), 0).r < far_plane;
#endif // FFX_SSSR_OPTION_INVERTED_DEPTH
}
#endif // #if defined (SSSR_BIND_SRV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_EXTRACTED_ROUGHNESS)
void StoreExtractedRoughness(FfxUInt32x2 coordinate, FfxFloat32 roughness)
{
imageStore(rw_extracted_roughness, FfxInt32x2(coordinate), FfxFloat32x4(roughness));
}
#endif // #if defined (SSSR_BIND_UAV_EXTRACTED_ROUGHNESS)
#if defined (SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS)
FfxFloat32 LoadRoughnessFromMaterialParametersInput(FfxUInt32x3 coordinate)
{
FfxFloat32 rawRoughness = texelFetch(r_input_material_parameters, FfxInt32x2(coordinate.xy), FfxInt32(coordinate.z))[RoughnessChannel()];
if (IsRoughnessPerceptual())
{
rawRoughness *= rawRoughness;
}
return rawRoughness;
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxBoolean IsRayIndexValid(FfxUInt32 ray_index)
{
return ray_index < rw_ray_counter.data[1];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_LIST)
FfxUInt32 GetRaylist(FfxUInt32 ray_index)
{
return rw_ray_list.data[ray_index];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_LIST)
#if defined (SSSR_BIND_UAV_BLUE_NOISE_TEXTURE)
void FFX_SSSR_StoreBlueNoiseSample(FfxUInt32x2 coordinate, FfxFloat32x2 blue_noise_sample)
{
imageStore(rw_blue_noise_texture, FfxInt32x2(coordinate), FfxFloat32x4(blue_noise_sample, 0.0f, 0.0f));
}
#endif // #if defined (SSSR_BIND_UAV_BLUE_NOISE_TEXTURE)
#if defined (SSSR_BIND_SRV_VARIANCE)
FfxFloat32 FFX_SSSR_LoadVarianceHistory(FfxInt32x3 coordinate)
{
return texelFetch(r_variance, coordinate.xy, coordinate.z).x;
}
#endif // #if defined (SSSR_BIND_SRV_VARIANCE)
#if defined (SSSR_BIND_UAV_RADIANCE)
void FFX_SSSR_StoreRadiance(FfxUInt32x2 coordinate, FfxFloat32x4 radiance)
{
imageStore(rw_radiance, FfxInt32x2(coordinate), radiance);
}
#endif // #if defined (SSSR_BIND_UAV_RADIANCE)
#if defined (SSSR_BIND_SRV_SOBOL_BUFFER)
FfxUInt32 FFX_SSSR_GetSobolSample(FfxUInt32x3 coordinate)
{
return FfxUInt32(texelFetch(r_sobol_buffer, FfxInt32x2(coordinate.xy), FfxInt32(coordinate.z)).r);
}
#endif // #if defined (SSSR_BIND_SRV_SOBOL_BUFFER)
#if defined (SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER)
FfxUInt32 FFX_SSSR_GetScramblingTile(FfxUInt32x3 coordinate)
{
return FfxUInt32(texelFetch(r_scrambling_tile_buffer, FfxInt32x2(coordinate.xy), FfxInt32(coordinate.z)).r);
}
#endif // #if defined (SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER)
#if defined (SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS)
void FFX_SSSR_WriteIntersectIndirectArgs(FfxUInt32 index, FfxUInt32 data)
{
rw_intersection_pass_indirect_args.data[index] = data;
}
#endif // #if defined (SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void FFX_SSSR_WriteRayCounter(FfxUInt32 index, FfxUInt32 data)
{
rw_ray_counter.data[index] = data;
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxUInt32 FFX_SSSR_GetRayCounter(FfxUInt32 index)
{
return rw_ray_counter.data[index];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
void FFX_SSSR_GetInputDepthDimensions(FFX_PARAMETER_OUT FfxFloat32x2 image_size)
{
image_size = textureSize(r_input_depth, 0);
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void FFX_SSSR_GetDepthHierarchyMipDimensions(FfxUInt32 mip, FFX_PARAMETER_OUT FfxFloat32x2 image_size)
{
image_size = imageSize(rw_depth_hierarchy[mip]);
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
FfxFloat32 FFX_SSSR_GetInputDepth(FfxUInt32x2 coordinate)
{
return texelFetch(r_input_depth, FfxInt32x2(coordinate), 0).r;
}
FfxFloat32x4 SpdLoadSourceImage(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return FFX_SSSR_GetInputDepth(coordinate).xxxx;
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void FFX_SSSR_WriteDepthHierarchy(FfxUInt32 index, FfxUInt32x2 coordinate, FfxFloat32 data)
{
imageStore(rw_depth_hierarchy[index], FfxInt32x2(coordinate), FfxFloat32x4(data));
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
FfxFloat32x4 SpdLoad(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return FfxFloat32x4(imageLoad(rw_depth_hierarchy[6], coordinate).x); // 5 -> 6 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void SpdStore(FfxInt32x2 pix, FfxFloat32x4 outValue, FfxUInt32 coordinate, FfxUInt32 slice)
{
imageStore(rw_depth_hierarchy[coordinate + 1], pix, FfxFloat32x4(outValue.x)); // + 1 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
void SpdResetAtomicCounter(FfxUInt32 slice)
{
rw_spd_global_atomic.data[0] = 0;
}
#endif // #if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
#if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
void FFX_SSSR_SPDIncreaseAtomicCounter(FFX_PARAMETER_INOUT FfxUInt32 spdCounter)
{
spdCounter = atomicAdd(rw_spd_global_atomic.data[0], 1);
}
#endif // #if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
#if defined(SSSR_BIND_SRV_INPUT_COLOR)
FfxFloat32x3 FFX_SSSR_LoadInputColor(FfxInt32x3 coordinate)
{
return texelFetch(r_input_color, coordinate.xy, coordinate.z).xyz;
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_COLOR)
#if defined(SSSR_BIND_SRV_EXTRACTED_ROUGHNESS)
FfxFloat32 FFX_SSSR_LoadExtractedRoughness(FfxInt32x3 coordinate)
{
return texelFetch(r_extracted_roughness, coordinate.xy, coordinate.z).x;
}
#endif // #if defined(SSSR_BIND_SRV_EXTRACTED_ROUGHNESS)
#endif // #if defined(FFX_GPU)

View File

@@ -0,0 +1,602 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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_sssr_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 "ffx_core.h"
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic pop
#endif //__hlsl_dx_compiler
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // #ifndef FFX_PREFER_WAVE64
#pragma warning(disable: 3205) // conversion from larger type to smaller
#define DECLARE_SRV_REGISTER(regIndex) t##regIndex
#define DECLARE_UAV_REGISTER(regIndex) u##regIndex
#define DECLARE_CB_REGISTER(regIndex) b##regIndex
#define FFX_SSSR_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))
#define FFX_SSSR_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))
#define FFX_SSSR_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))
#if defined(SSSR_BIND_CB_SSSR)
cbuffer cbSSSR : FFX_SSSR_DECLARE_CB(SSSR_BIND_CB_SSSR)
{
FfxFloat32Mat4 invViewProjection;
FfxFloat32Mat4 projection;
FfxFloat32Mat4 invProjection;
FfxFloat32Mat4 viewMatrix;
FfxFloat32Mat4 invView;
FfxFloat32Mat4 prevViewProjection;
FfxUInt32x2 renderSize;
FfxFloat32x2 inverseRenderSize;
FfxFloat32 normalsUnpackMul;
FfxFloat32 normalsUnpackAdd;
FfxUInt32 roughnessChannel;
FfxBoolean isRoughnessPerceptual;
FfxFloat32 iblFactor;
FfxFloat32 temporalStabilityFactor;
FfxFloat32 depthBufferThickness;
FfxFloat32 roughnessThreshold;
FfxFloat32 varianceThreshold;
FfxUInt32 frameIndex;
FfxUInt32 maxTraversalIntersections;
FfxUInt32 minTraversalOccupancy;
FfxUInt32 mostDetailedMip;
FfxUInt32 samplesPerQuad;
FfxUInt32 temporalVarianceGuidedTracingEnabled;
#define FFX_SSSR_CONSTANT_BUFFER_1_SIZE 110 // Number of 32-bit values. This must be kept in sync with the cbSSSR size.
};
#else
#define invViewProjection 0
#define projection 0
#define invProjection 0
#define viewMatrix 0
#define invView 0
#define prevViewProjection 0
#define normalsUnpackMul 0
#define normalsUnpackAdd 0
#define roughnessChannel 0
#define isRoughnessPerceptual 0
#define renderSize 0
#define inverseRenderSize 0
#define iblFactor 0
#define temporalStabilityFactor 0
#define depthBufferThickness 0
#define roughnessThreshold 0
#define varianceThreshold 0
#define frameIndex 0
#define maxTraversalIntersections 0
#define minTraversalOccupancy 0
#define mostDetailedMip 0
#define samplesPerQuad 0
#define temporalVarianceGuidedTracingEnabled 0
#define FFX_SSSR_CONSTANT_BUFFER_1_SIZE 0
#endif
#if defined(FFX_GPU)
#define FFX_SSSR_ROOTSIG_STRINGIFY(p) FFX_SSSR_ROOTSIG_STR(p)
#define FFX_SSSR_ROOTSIG_STR(p) #p
#define FFX_SSSR_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_SSSR_ROOTSIG_STRINGIFY(FFX_SSSR_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_SSSR_ROOTSIG_STRINGIFY(FFX_SSSR_RESOURCE_IDENTIFIER_COUNT) ")), " \
"CBV(b0), " \
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_LINEAR, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_WRAP, " \
"comparisonFunc = COMPARISON_ALWAYS, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK, " \
"maxAnisotropy = 1, " \
"visibility = SHADER_VISIBILITY_ALL) " )]
#if defined(FFX_SSSR_EMBED_ROOTSIG)
#define FFX_SSSR_EMBED_ROOTSIG_CONTENT FFX_SSSR_ROOTSIG
#else
#define FFX_SSSR_EMBED_ROOTSIG_CONTENT
#endif // #if FFX_SSSR_EMBED_ROOTSIG
#endif // #if defined(FFX_GPU)
SamplerState s_EnvironmentMapSampler : register(s0);
FfxFloat32Mat4 InvViewProjection()
{
return invViewProjection;
}
FfxFloat32Mat4 Projection()
{
return projection;
}
FfxFloat32Mat4 InvProjection()
{
return invProjection;
}
FfxFloat32Mat4 ViewMatrix()
{
return viewMatrix;
}
FfxFloat32Mat4 InvView()
{
return invView;
}
FfxFloat32Mat4 PrevViewProjection()
{
return prevViewProjection;
}
FfxFloat32 NormalsUnpackMul()
{
return normalsUnpackMul;
}
FfxFloat32 NormalsUnpackAdd()
{
return normalsUnpackAdd;
}
FfxUInt32 RoughnessChannel()
{
return roughnessChannel;
}
FfxBoolean IsRoughnessPerceptual()
{
return isRoughnessPerceptual;
}
FfxUInt32x2 RenderSize()
{
return renderSize;
}
FfxFloat32x2 InverseRenderSize()
{
return inverseRenderSize;
}
FfxFloat32 IBLFactor()
{
return iblFactor;
}
FfxFloat32 TemporalStabilityFactor()
{
return temporalStabilityFactor;
}
FfxFloat32 DepthBufferThickness()
{
return depthBufferThickness;
}
FfxFloat32 RoughnessThreshold()
{
return roughnessThreshold;
}
FfxFloat32 VarianceThreshold()
{
return varianceThreshold;
}
FfxUInt32 FrameIndex()
{
return frameIndex;
}
FfxUInt32 MaxTraversalIntersections()
{
return maxTraversalIntersections;
}
FfxUInt32 MinTraversalOccupancy()
{
return minTraversalOccupancy;
}
FfxUInt32 MostDetailedMip()
{
return mostDetailedMip;
}
FfxUInt32 SamplesPerQuad()
{
return samplesPerQuad;
}
FfxBoolean TemporalVarianceGuidedTracingEnabled()
{
return FfxBoolean(temporalVarianceGuidedTracingEnabled);
}
// SRVs
#if defined SSSR_BIND_SRV_INPUT_COLOR
Texture2D<FfxFloat32x4> r_input_color : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_COLOR);
#endif
#if defined SSSR_BIND_SRV_INPUT_DEPTH
Texture2D<FfxFloat32> r_input_depth : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_DEPTH);
#endif
#if defined SSSR_BIND_SRV_DEPTH_HIERARCHY
Texture2D<FfxFloat32> r_depth_hierarchy : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_DEPTH_HIERARCHY);
#endif
#if defined SSSR_BIND_SRV_INPUT_NORMAL
Texture2D<FfxFloat32x3> r_input_normal : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_NORMAL);
#endif
#if defined SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS
Texture2D<FfxFloat32x4> r_input_material_parameters : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS);
#endif
#if defined SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP
TextureCube r_input_environment_map : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP);
#endif
#if defined SSSR_BIND_SRV_RADIANCE
Texture2D<FfxFloat32x4> r_radiance : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_RADIANCE);
#endif
#if defined SSSR_BIND_SRV_RADIANCE_HISTORY
Texture2D<FfxFloat32x4> r_radiance_history : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_RADIANCE_HISTORY);
#endif
#if defined SSSR_BIND_SRV_VARIANCE
Texture2D<FfxFloat32> r_variance : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_VARIANCE);
#endif
#if defined SSSR_BIND_SRV_EXTRACTED_ROUGHNESS
Texture2D<FfxFloat32> r_extracted_roughness : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_EXTRACTED_ROUGHNESS);
#endif
#if defined SSSR_BIND_SRV_SOBOL_BUFFER
Texture2D<FfxUInt32> r_sobol_buffer : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_SOBOL_BUFFER);
#endif
#if defined SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER
Texture2D<FfxUInt32> r_scrambling_tile_buffer : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER);
#endif
#if defined SSSR_BIND_SRV_BLUE_NOISE_TEXTURE
Texture2D<FfxFloat32x2> r_blue_noise_texture : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_BLUE_NOISE_TEXTURE);
#endif
#if defined SSSR_BIND_SRV_INPUT_BRDF_TEXTURE
Texture2D<FfxFloat32x4> r_input_brdf_texture : FFX_SSSR_DECLARE_SRV(SSSR_BIND_SRV_INPUT_BRDF_TEXTURE);
#endif
// UAVs
#if defined SSSR_BIND_UAV_OUTPUT
RWTexture2D<FfxFloat32x4> rw_output : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_OUTPUT);
#endif
#if defined SSSR_BIND_UAV_RADIANCE
RWTexture2D<FfxFloat32x4> rw_radiance : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_RADIANCE);
#endif
#if defined SSSR_BIND_UAV_VARIANCE
RWTexture2D<FfxFloat32> rw_variance : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_VARIANCE);
#endif
#if defined SSSR_BIND_UAV_RAY_LIST
RWStructuredBuffer<FfxUInt32> rw_ray_list : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_RAY_LIST);
#endif
#if defined SSSR_BIND_UAV_DENOISER_TILE_LIST
RWStructuredBuffer<FfxUInt32> rw_denoiser_tile_list : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_DENOISER_TILE_LIST);
#endif
#if defined SSSR_BIND_UAV_RAY_COUNTER
globallycoherent RWStructuredBuffer<FfxUInt32> rw_ray_counter : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_RAY_COUNTER);
#endif
#if defined SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS
RWStructuredBuffer<FfxUInt32> rw_intersection_pass_indirect_args : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS);
#endif
#if defined SSSR_BIND_UAV_EXTRACTED_ROUGHNESS
RWTexture2D<FfxFloat32> rw_extracted_roughness : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_EXTRACTED_ROUGHNESS);
#endif
#if defined SSSR_BIND_UAV_BLUE_NOISE_TEXTURE
RWTexture2D<FfxFloat32x2> rw_blue_noise_texture : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_BLUE_NOISE_TEXTURE);
#endif
#if defined SSSR_BIND_UAV_DEPTH_HIERARCHY
RWTexture2D<FfxFloat32> rw_depth_hierarchy[13] : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_DEPTH_HIERARCHY);
#endif
// SPD UAV
#if defined SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC
globallycoherent RWStructuredBuffer<FfxUInt32> rw_spd_global_atomic : FFX_SSSR_DECLARE_UAV(SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC);
#endif
#if FFX_HALF
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
FfxFloat16x4 SpdLoadH(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return (FfxFloat16x4)rw_depth_hierarchy[6][coordinate].xxxx; // 5 -> 6 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
FfxFloat16x4 SpdLoadSourceImageH(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return (FfxFloat16x4)r_input_depth[coordinate].xxxx;
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void SpdStoreH(FfxInt32x2 pix, FfxFloat16x4 outValue, FfxUInt32 coordinate, FfxUInt32 slice)
{
rw_depth_hierarchy[coordinate + 1][pix] = outValue.x; // + 1 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#endif // #if defined(FFX_HALF)
#if defined(SSSR_BIND_SRV_INPUT_NORMAL)
FfxFloat32x3 FFX_SSSR_LoadWorldSpaceNormal(FfxInt32x2 pixel_coordinate)
{
return normalize(NormalsUnpackMul() * r_input_normal.Load(FfxInt32x3(pixel_coordinate, 0)).xyz + NormalsUnpackAdd());
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_NORMAL)
#if defined(SSSR_BIND_SRV_DEPTH_HIERARCHY)
FfxFloat32 FFX_SSSR_LoadDepth(FfxInt32x2 pixel_coordinate, FfxInt32 mip)
{
return r_depth_hierarchy.Load(FfxInt32x3(pixel_coordinate, mip));
}
#endif // #if defined(SSSR_BIND_SRV_DEPTH_HIERARCHY)
#if defined(SSSR_BIND_SRV_BLUE_NOISE_TEXTURE)
FfxFloat32x2 FFX_SSSR_SampleRandomVector2D(FfxUInt32x2 pixel)
{
return r_blue_noise_texture.Load(FfxInt32x3(pixel.xy % 128, 0));
}
#endif // #if defined(SSSR_BIND_SRV_BLUE_NOISE_TEXTURE)
#if defined(SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP)
FfxFloat32x3 FFX_SSSR_SampleEnvironmentMap(FfxFloat32x3 direction, FfxFloat32 preceptualRoughness)
{
FfxFloat32 Width; FfxFloat32 Height;
r_input_environment_map.GetDimensions(Width, Height);
FfxInt32 maxMipLevel = FfxInt32(log2(FfxFloat32(Width > 0 ? Width : 1)));
FfxFloat32 mip = clamp(preceptualRoughness * FfxFloat32(maxMipLevel), 0.0, FfxFloat32(maxMipLevel));
return r_input_environment_map.SampleLevel(s_EnvironmentMapSampler, direction, mip).xyz * IBLFactor();
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_ENVIRONMENT_MAP)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void IncrementRayCounter(FfxUInt32 value, FFX_PARAMETER_OUT FfxUInt32 original_value)
{
InterlockedAdd(rw_ray_counter[0], value, original_value);
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void IncrementDenoiserTileCounter(FFX_PARAMETER_OUT FfxUInt32 original_value)
{
InterlockedAdd(rw_ray_counter[2], 1, original_value);
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxUInt32 PackRayCoords(FfxUInt32x2 ray_coord, FfxBoolean copy_horizontal, FfxBoolean copy_vertical, FfxBoolean copy_diagonal)
{
FfxUInt32 ray_x_15bit = ray_coord.x & 0b111111111111111;
FfxUInt32 ray_y_14bit = ray_coord.y & 0b11111111111111;
FfxUInt32 copy_horizontal_1bit = copy_horizontal ? 1 : 0;
FfxUInt32 copy_vertical_1bit = copy_vertical ? 1 : 0;
FfxUInt32 copy_diagonal_1bit = copy_diagonal ? 1 : 0;
FfxUInt32 packed = (copy_diagonal_1bit << 31) | (copy_vertical_1bit << 30) | (copy_horizontal_1bit << 29) | (ray_y_14bit << 15) | (ray_x_15bit << 0);
return packed;
}
#if defined (SSSR_BIND_UAV_RAY_LIST)
void StoreRay(FfxInt32 index, FfxUInt32x2 ray_coord, FfxBoolean copy_horizontal, FfxBoolean copy_vertical, FfxBoolean copy_diagonal)
{
FfxUInt32 packedRayCoords = PackRayCoords(ray_coord, copy_horizontal, copy_vertical, copy_diagonal); // Store out pixel to trace
rw_ray_list[index] = packedRayCoords;
}
#endif // #if defined (SSSR_BIND_UAV_RAY_LIST)
#if defined (SSSR_BIND_UAV_DENOISER_TILE_LIST)
void StoreDenoiserTile(FfxInt32 index, FfxUInt32x2 tile_coord)
{
rw_denoiser_tile_list[index] = ((tile_coord.y & 0xffffu) << 16) | ((tile_coord.x & 0xffffu) << 0); // Store out pixel to trace
}
#endif // #if defined (SSSR_BIND_UAV_DENOISER_TILE_LIST)
#if defined (SSSR_BIND_SRV_DEPTH_HIERARCHY)
FfxBoolean IsReflectiveSurface(FfxInt32x2 pixel_coordinate, FfxFloat32 roughness)
{
#if FFX_SSSR_OPTION_INVERTED_DEPTH
const FfxFloat32 far_plane = 0.0f;
return r_depth_hierarchy[pixel_coordinate] > far_plane;
#else // FFX_SSSR_OPTION_INVERTED_DEPTH
const FfxFloat32 far_plane = 1.0f;
return r_depth_hierarchy[pixel_coordinate] < far_plane;
#endif // FFX_SSSR_OPTION_INVERTED_DEPTH
}
#endif // #if defined (SSSR_BIND_SRV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_EXTRACTED_ROUGHNESS)
void StoreExtractedRoughness(FfxUInt32x2 coordinate, FfxFloat32 roughness)
{
rw_extracted_roughness[coordinate] = roughness;
}
#endif // #if defined (SSSR_BIND_UAV_EXTRACTED_ROUGHNESS)
#if defined (SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS)
FfxFloat32 LoadRoughnessFromMaterialParametersInput(FfxUInt32x3 coordinate)
{
FfxFloat32 rawRoughness = r_input_material_parameters.Load(coordinate)[RoughnessChannel()];
if (IsRoughnessPerceptual())
{
rawRoughness *= rawRoughness;
}
return rawRoughness;
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_MATERIAL_PARAMETERS)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxBoolean IsRayIndexValid(FfxUInt32 ray_index)
{
return ray_index < rw_ray_counter[1];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_LIST)
FfxUInt32 GetRaylist(FfxUInt32 ray_index)
{
return rw_ray_list[ray_index];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_LIST)
#if defined (SSSR_BIND_UAV_BLUE_NOISE_TEXTURE)
void FFX_SSSR_StoreBlueNoiseSample(FfxUInt32x2 coordinate, FfxFloat32x2 blue_noise_sample)
{
rw_blue_noise_texture[coordinate] = blue_noise_sample;
}
#endif // #if defined (SSSR_BIND_UAV_BLUE_NOISE_TEXTURE)
#if defined (SSSR_BIND_SRV_VARIANCE)
FfxFloat32 FFX_SSSR_LoadVarianceHistory(FfxInt32x3 coordinate)
{
return r_variance.Load(coordinate).x;
}
#endif // #if defined (SSSR_BIND_SRV_VARIANCE)
#if defined (SSSR_BIND_UAV_RADIANCE)
void FFX_SSSR_StoreRadiance(FfxUInt32x2 coordinate, FfxFloat32x4 radiance)
{
rw_radiance[coordinate] = radiance;
}
#endif // #if defined (SSSR_BIND_UAV_RADIANCE)
#if defined (SSSR_BIND_SRV_SOBOL_BUFFER)
FfxUInt32 FFX_SSSR_GetSobolSample(FfxUInt32x3 coordinate)
{
return r_sobol_buffer.Load(coordinate);
}
#endif // #if defined (SSSR_BIND_SRV_SOBOL_BUFFER)
#if defined (SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER)
FfxUInt32 FFX_SSSR_GetScramblingTile(FfxUInt32x3 coordinate)
{
return r_scrambling_tile_buffer.Load(coordinate);
}
#endif // #if defined (SSSR_BIND_SRV_SCRAMBLING_TILE_BUFFER)
#if defined (SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS)
void FFX_SSSR_WriteIntersectIndirectArgs(FfxUInt32 index, FfxUInt32 data)
{
rw_intersection_pass_indirect_args[index] = data;
}
#endif // #if defined (SSSR_BIND_UAV_INTERSECTION_PASS_INDIRECT_ARGS)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
void FFX_SSSR_WriteRayCounter(FfxUInt32 index, FfxUInt32 data)
{
rw_ray_counter[index] = data;
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_UAV_RAY_COUNTER)
FfxUInt32 FFX_SSSR_GetRayCounter(FfxUInt32 index)
{
return rw_ray_counter[index];
}
#endif // #if defined (SSSR_BIND_UAV_RAY_COUNTER)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
void FFX_SSSR_GetInputDepthDimensions(FFX_PARAMETER_OUT FfxFloat32x2 image_size)
{
r_input_depth.GetDimensions(image_size.x, image_size.y);
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void FFX_SSSR_GetDepthHierarchyMipDimensions(FfxUInt32 mip, FFX_PARAMETER_OUT FfxFloat32x2 image_size)
{
rw_depth_hierarchy[mip].GetDimensions(image_size.x, image_size.y);
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_SRV_INPUT_DEPTH)
FfxFloat32 FFX_SSSR_GetInputDepth(FfxUInt32x2 coordinate)
{
return r_input_depth[coordinate];
}
FfxFloat32x4 SpdLoadSourceImage(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return FFX_SSSR_GetInputDepth(coordinate).xxxx;
}
#endif // #if defined (SSSR_BIND_SRV_INPUT_DEPTH)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void FFX_SSSR_WriteDepthHierarchy(FfxUInt32 index, FfxUInt32x2 coordinate, FfxFloat32 data)
{
rw_depth_hierarchy[index][coordinate] = data;
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
FfxFloat32x4 SpdLoad(FfxInt32x2 coordinate, FfxUInt32 slice)
{
return rw_depth_hierarchy[6][coordinate].xxxx; // 5 -> 6 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
void SpdStore(FfxInt32x2 pix, FfxFloat32x4 outValue, FfxUInt32 coordinate, FfxUInt32 slice)
{
rw_depth_hierarchy[coordinate + 1][pix] = outValue.x; // + 1 as we store a copy of the depth buffer at index 0
}
#endif // #if defined (SSSR_BIND_UAV_DEPTH_HIERARCHY)
#if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
void SpdResetAtomicCounter(FfxUInt32 slice)
{
rw_spd_global_atomic[0] = 0;
}
#endif // #if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
#if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
void FFX_SSSR_SPDIncreaseAtomicCounter(FFX_PARAMETER_INOUT FfxUInt32 spdCounter)
{
InterlockedAdd(rw_spd_global_atomic[0], 1, spdCounter);
}
#endif // #if defined (SSSR_BIND_UAV_SPD_GLOBAL_ATOMIC)
#if defined(SSSR_BIND_SRV_INPUT_COLOR)
FfxFloat32x3 FFX_SSSR_LoadInputColor(FfxInt32x3 coordinate)
{
return r_input_color.Load(coordinate).xyz;
}
#endif // #if defined(SSSR_BIND_SRV_INPUT_COLOR)
#if defined(SSSR_BIND_SRV_EXTRACTED_ROUGHNESS)
FfxFloat32 FFX_SSSR_LoadExtractedRoughness(FfxInt32x3 coordinate)
{
return r_extracted_roughness.Load(coordinate).x;
}
#endif // #if defined(SSSR_BIND_SRV_EXTRACTED_ROUGHNESS)
#endif // #if defined(FFX_GPU)

View File

@@ -0,0 +1,121 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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_sssr_common.h"
FfxBoolean IsBaseRay(FfxUInt32x2 dispatch_thread_id, FfxUInt32 samples_per_quad) {
switch (samples_per_quad) {
case 1:
return ((dispatch_thread_id.x & 1) | (dispatch_thread_id.y & 1)) == 0; // Deactivates 3 out of 4 rays
case 2:
return (dispatch_thread_id.x & 1) == (dispatch_thread_id.y & 1); // Deactivates 2 out of 4 rays. Keeps diagonal.
default: // case 4:
return true;
}
}
FFX_GROUPSHARED FfxUInt32 g_TileCount;
void ClassifyTiles(FfxUInt32x2 dispatch_thread_id, FfxUInt32x2 group_thread_id, FfxFloat32 roughness)
{
g_TileCount = 0;
FfxBoolean is_first_lane_of_wave = ffxWaveIsFirstLane();
// First we figure out on a per thread basis if we need to shoot a reflection ray.
// Disable offscreen pixels
FfxBoolean needs_ray = !(dispatch_thread_id.x >= RenderSize().x || dispatch_thread_id.y >= RenderSize().y);
// Dont shoot a ray on very rough surfaces.
FfxBoolean is_reflective_surface = IsReflectiveSurface(dispatch_thread_id, roughness);
FfxBoolean is_glossy_reflection = IsGlossyReflection(roughness);
needs_ray = needs_ray && is_glossy_reflection && is_reflective_surface;
// Also we dont need to run the denoiser on mirror reflections.
FfxBoolean needs_denoiser = needs_ray && !IsMirrorReflection(roughness);
// Decide which ray to keep
FfxBoolean is_base_ray = IsBaseRay(dispatch_thread_id, SamplesPerQuad());
needs_ray = needs_ray && (!needs_denoiser || is_base_ray); // Make sure to not deactivate mirror reflection rays.
if (TemporalVarianceGuidedTracingEnabled() && needs_denoiser && !needs_ray) {
FfxBoolean has_temporal_variance = FFX_SSSR_LoadVarianceHistory(FfxInt32x3(dispatch_thread_id, 0)) > VarianceThreshold();
needs_ray = needs_ray || has_temporal_variance;
}
FFX_GROUP_MEMORY_BARRIER; // Wait until g_TileCount is cleared - allow some computations before and after
// Now we know for each thread if it needs to shoot a ray and wether or not a denoiser pass has to run on this pixel.
if (is_glossy_reflection && is_reflective_surface)
{
FFX_ATOMIC_ADD(g_TileCount, 1);
}
// Next we have to figure out for which pixels that ray is creating the values for. Thus, if we have to copy its value horizontal, vertical or across.
FfxBoolean require_copy = !needs_ray && needs_denoiser; // Our pixel only requires a copy if we want to run a denoiser on it but don't want to shoot a ray for it.
FfxBoolean copy_horizontal = ffxWaveReadAtLaneIndexB1(require_copy, ffxWaveLaneIndex() ^ 1) && (SamplesPerQuad() != 4) && is_base_ray; // QuadReadAcrossX
FfxBoolean copy_vertical = ffxWaveReadAtLaneIndexB1(require_copy, ffxWaveLaneIndex() ^ 2) && (SamplesPerQuad() == 1) && is_base_ray; // QuadReadAcrossY
FfxBoolean copy_diagonal = ffxWaveReadAtLaneIndexB1(require_copy, ffxWaveLaneIndex() ^ 3) && (SamplesPerQuad() == 1) && is_base_ray; // QuadReadAcrossDiagonal
// Thus, we need to compact the rays and append them all at once to the ray list.
FfxUInt32 local_ray_index_in_wave = ffxWavePrefixCountBits(needs_ray);
FfxUInt32 wave_ray_count = ffxWaveActiveCountBits(needs_ray);
FfxUInt32 base_ray_index;
if (is_first_lane_of_wave) {
IncrementRayCounter(wave_ray_count, base_ray_index);
}
base_ray_index = ffxWaveReadLaneFirstU1(base_ray_index);
if (needs_ray) {
FfxInt32 ray_index = FfxInt32(base_ray_index + local_ray_index_in_wave);
StoreRay(ray_index, dispatch_thread_id, copy_horizontal, copy_vertical, copy_diagonal);
}
FfxFloat32x4 intersection_output = FfxFloat32x4(0.0f, 0.0f, 0.0f, 0.0f);
if (is_reflective_surface && !is_glossy_reflection)
{
// Fall back to environment map without preparing a ray
FfxFloat32x2 uv = (dispatch_thread_id + 0.5) * InverseRenderSize();
FfxFloat32x3 world_space_normal = FFX_SSSR_LoadWorldSpaceNormal(FfxInt32x2(dispatch_thread_id));
FfxFloat32 z = FFX_SSSR_LoadDepth(FfxInt32x2(dispatch_thread_id), 0);
FfxFloat32x3 screen_uv_space_ray_origin = FfxFloat32x3(uv, z);
FfxFloat32x3 view_space_ray = ScreenSpaceToViewSpace(screen_uv_space_ray_origin);
FfxFloat32x3 view_space_ray_direction = normalize(view_space_ray);
FfxFloat32x3 view_space_surface_normal = FFX_MATRIX_MULTIPLY(ViewMatrix(), FfxFloat32x4(world_space_normal, 0)).xyz;
FfxFloat32x3 view_space_reflected_direction = reflect(view_space_ray_direction, view_space_surface_normal);
FfxFloat32x3 world_space_reflected_direction = FFX_MATRIX_MULTIPLY(InvView(), FfxFloat32x4(view_space_reflected_direction, 0)).xyz;
intersection_output.xyz = FFX_SSSR_SampleEnvironmentMap(world_space_reflected_direction, sqrt(roughness));
}
FFX_SSSR_StoreRadiance(dispatch_thread_id, intersection_output);
FFX_GROUP_MEMORY_BARRIER; // Wait until g_TileCount
if ((group_thread_id.x == 0) && (group_thread_id.y == 0) && g_TileCount > 0)
{
FfxUInt32 tile_offset;
IncrementDenoiserTileCounter(tile_offset);
StoreDenoiserTile(FfxInt32(tile_offset), FfxInt32x2(dispatch_thread_id.xy));
}
}

View File

@@ -0,0 +1,68 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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.
//=== Common functions of the SssrSample ===
void UnpackRayCoords(FfxUInt32 packed, FFX_PARAMETER_OUT FfxUInt32x2 ray_coord, FFX_PARAMETER_OUT FfxBoolean copy_horizontal, FFX_PARAMETER_OUT FfxBoolean copy_vertical, FFX_PARAMETER_OUT FfxBoolean copy_diagonal) {
ray_coord.x = (packed >> 0) & 32767; // 0b111111111111111;
ray_coord.y = (packed >> 15) & 16383; // 0b11111111111111;
copy_horizontal = FfxBoolean((packed >> 29) & 1u);
copy_vertical = FfxBoolean((packed >> 30) & 1u);
copy_diagonal = FfxBoolean((packed >> 31) & 1u);
}
// Transforms origin to uv space
// Mat must be able to transform origin from its current space into clip space.
FfxFloat32x3 ProjectPosition(FfxFloat32x3 origin, FfxFloat32Mat4 mat) {
FfxFloat32x4 projected = FFX_MATRIX_MULTIPLY(mat, FfxFloat32x4(origin, 1));
projected.xyz /= projected.w;
projected.xy = 0.5 * projected.xy + 0.5;
projected.y = (1 - projected.y);
return projected.xyz;
}
// Mat must be able to transform origin from texture space to a linear space.
FfxFloat32x3 InvProjectPosition(FfxFloat32x3 coord, FfxFloat32Mat4 mat) {
coord.y = (1 - coord.y);
coord.xy = 2 * coord.xy - 1;
FfxFloat32x4 projected = FFX_MATRIX_MULTIPLY(mat, FfxFloat32x4(coord, 1));
projected.xyz /= projected.w;
return projected.xyz;
}
// Origin and direction must be in the same space and mat must be able to transform from that space into clip space.
FfxFloat32x3 ProjectDirection(FfxFloat32x3 origin, FfxFloat32x3 direction, FfxFloat32x3 screen_space_origin, FfxFloat32Mat4 mat) {
FfxFloat32x3 offsetted = ProjectPosition(origin + direction, mat);
return offsetted - screen_space_origin;
}
FfxBoolean IsGlossyReflection(FfxFloat32 roughness) {
return roughness < RoughnessThreshold();
}
FfxBoolean IsMirrorReflection(FfxFloat32 roughness) {
return roughness < 0.0001;
}
FfxFloat32x3 ScreenSpaceToViewSpace(FfxFloat32x3 screen_uv_coord) {
return InvProjectPosition(screen_uv_coord, InvProjection());
}

View File

@@ -0,0 +1,115 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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.
FFX_GROUPSHARED FfxUInt32 spdCounter;
FFX_GROUPSHARED FfxFloat32 spdIntermediate[16][16];
// Define fetch and store functions
FfxUInt32 SpdGetAtomicCounter() {
return spdCounter;
}
#if FFX_HALF
FfxFloat16x4 SpdReduce4H(FfxFloat16x4 v0, FfxFloat16x4 v1, FfxFloat16x4 v2, FfxFloat16x4 v3) {
#if FFX_SSSR_OPTION_INVERTED_DEPTH
return max(max(v0, v1), max(v2, v3));
#else
return min(min(v0, v1), min(v2, v3));
#endif
}
FfxFloat16x4 SpdLoadIntermediateH(FfxUInt32 x, FfxUInt32 y) {
FfxFloat16 f = FfxFloat16(spdIntermediate[x][y]);
return FfxFloat16x4(f.x, f.x, f.x, f.x);
}
void SpdStoreIntermediateH(FfxUInt32 x, FfxUInt32 y, FfxFloat16x4 value) {
spdIntermediate[x][y] = value.x;
}
#endif // FFX_HALF
void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value) {
spdIntermediate[x][y] = value.x;
}
FfxFloat32x4 SpdLoadIntermediate(FfxUInt32 x, FfxUInt32 y) {
FfxFloat32 f = spdIntermediate[x][y];
return FfxFloat32x4(f.x, f.x, f.x, f.x);
}
FfxFloat32x4 SpdReduce4(FfxFloat32x4 v0, FfxFloat32x4 v1, FfxFloat32x4 v2, FfxFloat32x4 v3) {
#if FFX_SSSR_OPTION_INVERTED_DEPTH
return max(max(v0, v1), max(v2, v3));
#else
return min(min(v0, v1), min(v2, v3));
#endif
}
void SpdIncreaseAtomicCounter(FfxUInt32 slice)
{
FFX_SSSR_SPDIncreaseAtomicCounter(spdCounter);
}
#include "../spd/ffx_spd.h"
FfxUInt32 GetThreadgroupCount(FfxUInt32x2 image_size){
// Each threadgroup works on 64x64 texels
return ((image_size.x + 63) / 64) * ((image_size.y + 63) / 64);
}
// Returns mips count of a texture with specified size
FfxFloat32 GetMipsCount(FfxFloat32x2 texture_size){
FfxFloat32 max_dim = max(texture_size.x, texture_size.y);
return 1.0 + floor(log2(max_dim));
}
void DepthDownsample(FfxUInt32 group_index, FfxUInt32x3 group_id, FfxUInt32x3 dispatch_thread_id){
FfxFloat32x2 depth_image_size = FfxFloat32x2(0.0f, 0.0f);
FFX_SSSR_GetInputDepthDimensions(depth_image_size);
// Copy most detailed level into the hierarchy and transform it.
FfxUInt32x2 u_depth_image_size = FfxUInt32x2(depth_image_size);
for (FfxInt32 i = 0; i < 2; ++i)
{
for (FfxInt32 j = 0; j < 8; ++j)
{
FfxUInt32x2 idx = FfxUInt32x2(2 * dispatch_thread_id.x + i, 8 * dispatch_thread_id.y + j);
if (idx.x < u_depth_image_size.x && idx.y < u_depth_image_size.y)
{
FFX_SSSR_WriteDepthHierarchy(0, idx, FFX_SSSR_GetInputDepth(idx));
}
}
}
FfxFloat32x2 image_size = FfxFloat32x2(0.0f, 0.0f);
FFX_SSSR_GetDepthHierarchyMipDimensions(0, image_size);
FfxFloat32 mips_count = GetMipsCount(image_size);
FfxUInt32 threadgroup_count = GetThreadgroupCount(FfxInt32x2(image_size));
SpdDownsample(
FfxUInt32x2(group_id.xy),
FfxUInt32(group_index),
FfxUInt32(mips_count),
FfxUInt32(threadgroup_count),
0);
}

View File

@@ -0,0 +1,341 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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_sssr_common.h"
#define M_PI 3.14159265358979f
#define FFX_SSSR_FLOAT_MAX 3.402823466e+38
#define FFX_SSSR_DEPTH_HIERARCHY_MAX_MIP 6
FfxFloat32x3 FFX_SSSR_ScreenSpaceToViewSpace(FfxFloat32x3 screen_space_position) {
return InvProjectPosition(screen_space_position, InvProjection());
}
FfxFloat32x3 ScreenSpaceToWorldSpace(FfxFloat32x3 screen_space_position) {
return InvProjectPosition(screen_space_position, InvViewProjection());
}
// http://jcgt.org/published/0007/04/01/paper.pdf by Eric Heitz
// Input Ve: view direction
// Input alpha_x, alpha_y: roughness parameters
// Input U1, U2: uniform random numbers
// Output Ne: normal sampled with PDF D_Ve(Ne) = G1(Ve) * max(0, dot(Ve, Ne)) * D(Ne) / Ve.z
FfxFloat32x3 SampleGGXVNDF(FfxFloat32x3 Ve, FfxFloat32 alpha_x, FfxFloat32 alpha_y, FfxFloat32 U1, FfxFloat32 U2) {
// Section 3.2: transforming the view direction to the hemisphere configuration
FfxFloat32x3 Vh = normalize(FfxFloat32x3(alpha_x * Ve.x, alpha_y * Ve.y, Ve.z));
// Section 4.1: orthonormal basis (with special case if cross product is zero)
FfxFloat32 lensq = Vh.x * Vh.x + Vh.y * Vh.y;
FfxFloat32x3 T1 = lensq > 0 ? FfxFloat32x3(-Vh.y, Vh.x, 0) * ffxRsqrt(lensq) : FfxFloat32x3(1, 0, 0);
FfxFloat32x3 T2 = cross(Vh, T1);
// Section 4.2: parameterization of the projected area
FfxFloat32 r = sqrt(U1);
FfxFloat32 phi = 2.0 * M_PI * U2;
FfxFloat32 t1 = r * cos(phi);
FfxFloat32 t2 = r * sin(phi);
FfxFloat32 s = 0.5 * (1.0 + Vh.z);
t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;
// Section 4.3: reprojection onto hemisphere
FfxFloat32x3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * Vh;
// Section 3.4: transforming the normal back to the ellipsoid configuration
FfxFloat32x3 Ne = normalize(FfxFloat32x3(alpha_x * Nh.x, alpha_y * Nh.y, max(0.0, Nh.z)));
return Ne;
}
FfxFloat32x3 Sample_GGX_VNDF_Ellipsoid(FfxFloat32x3 Ve, FfxFloat32 alpha_x, FfxFloat32 alpha_y, FfxFloat32 U1, FfxFloat32 U2) {
return SampleGGXVNDF(Ve, alpha_x, alpha_y, U1, U2);
}
FfxFloat32x3 Sample_GGX_VNDF_Hemisphere(FfxFloat32x3 Ve, FfxFloat32 alpha, FfxFloat32 U1, FfxFloat32 U2) {
return Sample_GGX_VNDF_Ellipsoid(Ve, alpha, alpha, U1, U2);
}
FfxFloat32x3 SampleReflectionVector(FfxFloat32x3 view_direction, FfxFloat32x3 normal, FfxFloat32 roughness, FfxInt32x2 dispatch_thread_id) {
FfxFloat32x3 U;
FfxFloat32x3 N = normal;
if (abs(N.z) > 0.0) {
FfxFloat32 k = sqrt(N.y * N.y + N.z * N.z);
U.x = 0.0; U.y = -N.z / k; U.z = N.y / k;
}
else {
FfxFloat32 k = sqrt(N.x * N.x + N.y * N.y);
U.x = N.y / k; U.y = -N.x / k; U.z = 0.0;
}
// TBN 3x3 matrix
FfxFloat32x3 TBN_row0 = U;
FfxFloat32x3 TBN_row1 = cross(N, U);
FfxFloat32x3 TBN_row2 = N;
// TBN * -view_direction
FfxFloat32x3 view_direction_tbn = FfxFloat32x3(dot(TBN_row0, -view_direction), dot(TBN_row1, -view_direction), dot(TBN_row2, -view_direction));
FfxFloat32x2 u = FFX_SSSR_SampleRandomVector2D(dispatch_thread_id);
FfxFloat32x3 sampled_normal_tbn = Sample_GGX_VNDF_Hemisphere(view_direction_tbn, roughness, u.x, u.y);
#ifdef PERFECT_REFLECTIONS
sampled_normal_tbn = FfxFloat32x3(0, 0, 1); // Overwrite normal sample to produce perfect reflection.
#endif
FfxFloat32x3 reflected_direction_tbn = reflect(-view_direction_tbn, sampled_normal_tbn);
// Transpose of TBN
FfxFloat32x3 TBN_col0 = FfxFloat32x3(TBN_row0[0], TBN_row1[0], TBN_row2[0]);
FfxFloat32x3 TBN_col1 = FfxFloat32x3(TBN_row0[1], TBN_row1[1], TBN_row2[1]);
FfxFloat32x3 TBN_col2 = FfxFloat32x3(TBN_row0[2], TBN_row1[2], TBN_row2[2]);
// transpose(TBN) * reflected_direction_tbn
return FfxFloat32x3(dot(TBN_col0, reflected_direction_tbn), dot(TBN_col1, reflected_direction_tbn), dot(TBN_col2, reflected_direction_tbn));
}
void FFX_SSSR_InitialAdvanceRay(FfxFloat32x3 origin, FfxFloat32x3 direction, FfxFloat32x3 inv_direction, FfxFloat32x2 current_mip_resolution, FfxFloat32x2 current_mip_resolution_inv, FfxFloat32x2 floor_offset, FfxFloat32x2 uv_offset, FFX_PARAMETER_OUT FfxFloat32x3 position, FFX_PARAMETER_OUT FfxFloat32 current_t) {
FfxFloat32x2 current_mip_position = current_mip_resolution * origin.xy;
// Intersect ray with the half box that is pointing away from the ray origin.
FfxFloat32x2 xy_plane = floor(current_mip_position) + floor_offset;
xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
// o + d * t = p' => t = (p' - o) / d
FfxFloat32x2 t = xy_plane * inv_direction.xy - origin.xy * inv_direction.xy;
current_t = min(t.x, t.y);
position = origin + current_t * direction;
}
FfxBoolean FFX_SSSR_AdvanceRay(FfxFloat32x3 origin, FfxFloat32x3 direction, FfxFloat32x3 inv_direction, FfxFloat32x2 current_mip_position, FfxFloat32x2 current_mip_resolution_inv, FfxFloat32x2 floor_offset, FfxFloat32x2 uv_offset, FfxFloat32 surface_z, FFX_PARAMETER_INOUT FfxFloat32x3 position, FFX_PARAMETER_INOUT FfxFloat32 current_t) {
// Create boundary planes
FfxFloat32x2 xy_plane = floor(current_mip_position) + floor_offset;
xy_plane = xy_plane * current_mip_resolution_inv + uv_offset;
FfxFloat32x3 boundary_planes = FfxFloat32x3(xy_plane, surface_z);
// Intersect ray with the half box that is pointing away from the ray origin.
// o + d * t = p' => t = (p' - o) / d
FfxFloat32x3 t = boundary_planes * inv_direction - origin * inv_direction;
// Prevent using z plane when shooting out of the depth buffer.
#if FFX_SSSR_OPTION_INVERTED_DEPTH
t.z = direction.z < 0 ? t.z : FFX_SSSR_FLOAT_MAX;
#else
t.z = direction.z > 0 ? t.z : FFX_SSSR_FLOAT_MAX;
#endif
// Choose nearest intersection with a boundary.
FfxFloat32 t_min = min(min(t.x, t.y), t.z);
#if FFX_SSSR_OPTION_INVERTED_DEPTH
// Larger z means closer to the camera.
FfxBoolean above_surface = surface_z < position.z;
#else
// Smaller z means closer to the camera.
FfxBoolean above_surface = surface_z > position.z;
#endif
// Decide whether we are able to advance the ray until we hit the xy boundaries or if we had to clamp it at the surface.
// We use the asuint comparison to avoid NaN / Inf logic, also we actually care about bitwise equality here to see if t_min is the t.z we fed into the min3 above.
FfxBoolean skipped_tile = ffxAsUInt32(t_min) != ffxAsUInt32(t.z) && above_surface;
// Make sure to only advance the ray if we're still above the surface.
current_t = above_surface ? t_min : current_t;
// Advance ray
position = origin + current_t * direction;
return skipped_tile;
}
FfxFloat32x2 FFX_SSSR_GetMipResolution(FfxFloat32x2 screen_dimensions, FfxInt32 mip_level) {
return screen_dimensions * pow(0.5, mip_level);
}
// Requires origin and direction of the ray to be in screen space [0, 1] x [0, 1]
FfxFloat32x3 FFX_SSSR_HierarchicalRaymarch(FfxFloat32x3 origin, FfxFloat32x3 direction, FfxBoolean is_mirror, FfxFloat32x2 screen_size, FfxInt32 most_detailed_mip, FfxUInt32 min_traversal_occupancy, FfxUInt32 max_traversal_intersections, FFX_PARAMETER_OUT FfxBoolean valid_hit)
{
const FfxFloat32x3 inv_direction = direction != FFX_SELECT(FfxFloat32x3(0.0f, 0.0f, 0.0f), FfxFloat32x3(1.0f, 1.0f, 1.0f) / direction, FfxFloat32x3(FFX_SSSR_FLOAT_MAX, FFX_SSSR_FLOAT_MAX, FFX_SSSR_FLOAT_MAX));
// Start on mip with highest detail.
FfxInt32 current_mip = most_detailed_mip;
// Could recompute these every iteration, but it's faster to hoist them out and update them.
FfxFloat32x2 current_mip_resolution = FFX_SSSR_GetMipResolution(screen_size, current_mip);
FfxFloat32x2 current_mip_resolution_inv = ffxReciprocal(current_mip_resolution);
// Offset to the bounding boxes uv space to intersect the ray with the center of the next pixel.
// This means we ever so slightly over shoot into the next region.
FfxFloat32x2 uv_offset = 0.005 * exp2(most_detailed_mip) / screen_size;
uv_offset.x = direction.x < 0.0f ? -uv_offset.x : uv_offset.x;
uv_offset.y = direction.y < 0.0f ? -uv_offset.y : uv_offset.y;
// Offset applied depending on current mip resolution to move the boundary to the left/right upper/lower border depending on ray direction.
FfxFloat32x2 floor_offset;
floor_offset.x = direction.x < 0.0f ? 0.0f : 1.0f;
floor_offset.y = direction.y < 0.0f ? 0.0f : 1.0f;
// Initially advance ray to avoid immediate self intersections.
FfxFloat32 current_t;
FfxFloat32x3 position;
FFX_SSSR_InitialAdvanceRay(origin, direction, inv_direction, current_mip_resolution, current_mip_resolution_inv, floor_offset, uv_offset, position, current_t);
FfxBoolean exit_due_to_low_occupancy = false;
FfxInt32 i = 0;
while (i < max_traversal_intersections && current_mip >= most_detailed_mip && !exit_due_to_low_occupancy) {
FfxFloat32x2 current_mip_position = current_mip_resolution * position.xy;
FfxFloat32 surface_z = FFX_SSSR_LoadDepth(FfxInt32x2(current_mip_position), current_mip);
exit_due_to_low_occupancy = !is_mirror && ffxWaveActiveCountBits(true) <= min_traversal_occupancy;
FfxBoolean skipped_tile = FFX_SSSR_AdvanceRay(origin, direction, inv_direction, current_mip_position, current_mip_resolution_inv, floor_offset, uv_offset, surface_z, position, current_t);
// Don't increase mip further than this because we did not generate it
FfxBoolean nextMipIsOutOfRange = skipped_tile && (current_mip >= FFX_SSSR_DEPTH_HIERARCHY_MAX_MIP);
if (!nextMipIsOutOfRange)
{
current_mip += skipped_tile ? 1 : -1;
current_mip_resolution *= skipped_tile ? 0.5 : 2;
current_mip_resolution_inv *= skipped_tile ? 2 : 0.5;;
}
++i;
}
valid_hit = (i <= max_traversal_intersections);
return position;
}
FfxFloat32 FFX_SSSR_ValidateHit(FfxFloat32x3 hit, FfxFloat32x2 uv, FfxFloat32x3 world_space_ray_direction, FfxFloat32x2 screen_size, FfxFloat32 depth_buffer_thickness) {
// Reject hits outside the view frustum
if ((hit.x < 0.0f) || (hit.y < 0.0f) || (hit.x > 1.0f) || (hit.y > 1.0f)) {
return 0.0f;
}
// Reject the hit if we didnt advance the ray significantly to avoid immediate self reflection
FfxFloat32x2 manhattan_dist = abs(hit.xy - uv);
if((manhattan_dist.x < (2.0f / screen_size.x)) && (manhattan_dist.y < (2.0f / screen_size.y)) ) {
return 0.0;
}
// Don't lookup radiance from the background.
FfxInt32x2 texel_coords = FfxInt32x2(screen_size * hit.xy);
FfxFloat32 surface_z = FFX_SSSR_LoadDepth(texel_coords / 2, 1);
#if FFX_SSSR_OPTION_INVERTED_DEPTH
if (surface_z == 0.0) {
#else
if (surface_z == 1.0) {
#endif
return 0;
}
// We check if we hit the surface from the back, these should be rejected.
FfxFloat32x3 hit_normal = FFX_SSSR_LoadWorldSpaceNormal(texel_coords);
if (dot(hit_normal, world_space_ray_direction) > 0) {
return 0;
}
FfxFloat32x3 view_space_surface = FFX_SSSR_ScreenSpaceToViewSpace(FfxFloat32x3(hit.xy, surface_z));
FfxFloat32x3 view_space_hit = FFX_SSSR_ScreenSpaceToViewSpace(hit);
FfxFloat32 distance = length(view_space_surface - view_space_hit);
// Fade out hits near the screen borders
FfxFloat32x2 fov = 0.05 * FfxFloat32x2(screen_size.y / screen_size.x, 1);
FfxFloat32x2 border = smoothstep(FfxFloat32x2(0.0f, 0.0f), fov, hit.xy) * (1 - smoothstep(FfxFloat32x2(1.0f, 1.0f) - fov, FfxFloat32x2(1.0f, 1.0f), hit.xy));
FfxFloat32 vignette = border.x * border.y;
// We accept all hits that are within a reasonable minimum distance below the surface.
// Add constant in linear space to avoid growing of the reflections toward the reflected objects.
FfxFloat32 confidence = 1.0f - smoothstep(0.0f, depth_buffer_thickness, distance);
confidence *= confidence;
return vignette * confidence;
}
void Intersect(FfxUInt32 group_index, FfxUInt32 group_id)
{
FfxUInt32 ray_index = group_id * 64 + group_index;
if(!IsRayIndexValid(ray_index))
{
return;
}
FfxUInt32 packed_coords = GetRaylist(ray_index);
FfxUInt32x2 coords;
FfxBoolean copy_horizontal;
FfxBoolean copy_vertical;
FfxBoolean copy_diagonal;
UnpackRayCoords(packed_coords, coords, copy_horizontal, copy_vertical, copy_diagonal);
const FfxUInt32x2 screen_size = RenderSize();
FfxFloat32x2 uv = (coords + 0.5) * InverseRenderSize();
FfxFloat32x3 world_space_normal = FFX_SSSR_LoadWorldSpaceNormal(FfxInt32x2(coords));
FfxFloat32 roughness = FFX_SSSR_LoadExtractedRoughness(FfxInt32x3(coords, 0));
FfxBoolean is_mirror = IsMirrorReflection(roughness);
FfxInt32 most_detailed_mip = is_mirror ? 0 : FfxInt32(MostDetailedMip());
FfxFloat32x2 mip_resolution = FFX_SSSR_GetMipResolution(screen_size, most_detailed_mip);
FfxFloat32 z = FFX_SSSR_LoadDepth(FfxInt32x2(uv * mip_resolution), most_detailed_mip);
FfxFloat32x3 screen_uv_space_ray_origin = FfxFloat32x3(uv, z);
FfxFloat32x3 view_space_ray = ScreenSpaceToViewSpace(screen_uv_space_ray_origin);
FfxFloat32x3 view_space_ray_direction = normalize(view_space_ray);
FfxFloat32x3 view_space_surface_normal = FFX_MATRIX_MULTIPLY(ViewMatrix(), FfxFloat32x4(world_space_normal, 0)).xyz;
FfxFloat32x3 view_space_reflected_direction = SampleReflectionVector(view_space_ray_direction, view_space_surface_normal, roughness, FfxInt32x2(coords));
FfxFloat32x3 screen_space_ray_direction = ProjectDirection(view_space_ray, view_space_reflected_direction, screen_uv_space_ray_origin, Projection());
//====SSSR====
FfxBoolean valid_hit = false;
FfxFloat32x3 hit = FFX_SSSR_HierarchicalRaymarch(screen_uv_space_ray_origin, screen_space_ray_direction, is_mirror, screen_size, most_detailed_mip, MinTraversalOccupancy(), MaxTraversalIntersections(), valid_hit);
FfxFloat32x3 world_space_origin = ScreenSpaceToWorldSpace(screen_uv_space_ray_origin);
FfxFloat32x3 world_space_hit = ScreenSpaceToWorldSpace(hit);
FfxFloat32x3 world_space_ray = world_space_hit - world_space_origin.xyz;
FfxFloat32 confidence = valid_hit ? FFX_SSSR_ValidateHit(hit, uv, world_space_ray, screen_size, DepthBufferThickness()) : 0;
FfxFloat32 world_ray_length = max(0, length(world_space_ray));
FfxFloat32x3 reflection_radiance = FfxFloat32x3(0.0f, 0.0f, 0.0f);
if (confidence > 0.0f) {
// Found an intersection with the depth buffer -> We can lookup the color from lit scene.
reflection_radiance = FFX_SSSR_LoadInputColor(FfxInt32x3(screen_size * hit.xy, 0));
}
// Sample environment map.
FfxFloat32x3 world_space_reflected_direction = FFX_MATRIX_MULTIPLY(InvView(), FfxFloat32x4(view_space_reflected_direction, 0)).xyz;
FfxFloat32x3 environment_lookup = FFX_SSSR_SampleEnvironmentMap(world_space_reflected_direction, 0.0f);
reflection_radiance = ffxLerp(environment_lookup, reflection_radiance, confidence);
FfxFloat32x4 new_sample = FfxFloat32x4(reflection_radiance, world_ray_length);
FFX_SSSR_StoreRadiance(coords, new_sample);
FfxUInt32x2 copy_target = coords ^ 1; // Flip last bit to find the mirrored coords along the x and y axis within a quad.
if (copy_horizontal) {
FfxUInt32x2 copy_coords = FfxUInt32x2(copy_target.x, coords.y);
FFX_SSSR_StoreRadiance(copy_coords, new_sample);
}
if (copy_vertical) {
FfxUInt32x2 copy_coords = FfxUInt32x2(coords.x, copy_target.y);
FFX_SSSR_StoreRadiance(copy_coords, new_sample);
}
if (copy_diagonal) {
FfxUInt32x2 copy_coords = copy_target;
FFX_SSSR_StoreRadiance(copy_coords, new_sample);
}
}

View File

@@ -0,0 +1,59 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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_sssr_common.h"
#define GOLDEN_RATIO 1.61803398875f
// Blue Noise Sampler by Eric Heitz. Returns a value in the range [0, 1].
FfxFloat32 SampleRandomNumber(FfxUInt32 pixel_i, FfxUInt32 pixel_j, FfxUInt32 sample_index, FfxUInt32 sample_dimension) {
// Wrap arguments
pixel_i = pixel_i & 127u;
pixel_j = pixel_j & 127u;
sample_index = sample_index & 255u;
sample_dimension = sample_dimension & 255u;
// xor index based on optimized ranking
const FfxUInt32 ranked_sample_index = sample_index;
// Fetch value in sequence
FfxUInt32 value = FFX_SSSR_GetSobolSample(FfxUInt32x3(sample_dimension, ranked_sample_index * 256u, 0));
// If the dimension is optimized, xor sequence value based on optimized scrambling
FfxUInt32 originalIndex = (sample_dimension % 8u) + (pixel_i + pixel_j * 128u) * 8u;
value = value ^ FFX_SSSR_GetScramblingTile(FfxUInt32x3(originalIndex % 512u, originalIndex / 512u, 0));
// Convert to FfxFloat32 and return
return (value + 0.5f) / 256.0f;
}
FfxFloat32x2 SampleRandomVector2D(FfxUInt32x2 pixel) {
FfxFloat32x2 u = FfxFloat32x2(
FFX_MODULO(SampleRandomNumber(pixel.x, pixel.y, 0, 0u) + (FrameIndex() & 0xFFu) * GOLDEN_RATIO, 1.0f),
FFX_MODULO(SampleRandomNumber(pixel.x, pixel.y, 0, 1u) + (FrameIndex() & 0xFFu) * GOLDEN_RATIO, 1.0f));
return u;
}
void PrepareBlueNoiseTexture(FfxUInt32x2 dispatch_thread_id) {
FFX_SSSR_StoreBlueNoiseSample(dispatch_thread_id, SampleRandomVector2D(dispatch_thread_id));
}

View File

@@ -0,0 +1,44 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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.
void PrepareIndirectArgs() {
{ // Prepare intersection args
FfxUInt32 ray_count = FFX_SSSR_GetRayCounter(0);
FFX_SSSR_WriteIntersectIndirectArgs(0, (ray_count + 63) / 64);
FFX_SSSR_WriteIntersectIndirectArgs(1, 1);
FFX_SSSR_WriteIntersectIndirectArgs(2, 1);
FFX_SSSR_WriteRayCounter(0, 0);
FFX_SSSR_WriteRayCounter(1, ray_count);
}
{ // Prepare denoiser args
FfxUInt32 tile_count = FFX_SSSR_GetRayCounter(2);
FFX_SSSR_WriteIntersectIndirectArgs(3, tile_count);
FFX_SSSR_WriteIntersectIndirectArgs(4, 1);
FFX_SSSR_WriteIntersectIndirectArgs(5, 1);
FFX_SSSR_WriteRayCounter(2, 0);
FFX_SSSR_WriteRayCounter(3, tile_count);
}
}

View File

@@ -0,0 +1,61 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
//
// 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.
#ifndef FFX_SSSR2_RESOURCES_H
#define FFX_SSSR2_RESOURCES_H
#if defined(FFX_CPU) || defined(FFX_GPU)
#define FFX_SSSR_RESOURCE_IDENTIFIER_NULL 0
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_COLOR 1
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_DEPTH 2
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS 3
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_NORMAL 4
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_MATERIAL_PARAMETERS 5
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_ENVIRONMENT_MAP 6
#define FFX_SSSR_RESOURCE_IDENTIFIER_INPUT_BRDF_TEXTURE 7
#define FFX_SSSR_RESOURCE_IDENTIFIER_OUTPUT 8
#define FFX_SSSR_RESOURCE_IDENTIFIER_DEPTH_HIERARCHY 9
#define FFX_SSSR_RESOURCE_IDENTIFIER_RADIANCE 10
#define FFX_SSSR_RESOURCE_IDENTIFIER_RADIANCE_HISTORY 11
#define FFX_SSSR_RESOURCE_IDENTIFIER_VARIANCE 12
#define FFX_SSSR_RESOURCE_IDENTIFIER_RAY_LIST 13
#define FFX_SSSR_RESOURCE_IDENTIFIER_DENOISER_TILE_LIST 14
#define FFX_SSSR_RESOURCE_IDENTIFIER_RAY_COUNTER 15
#define FFX_SSSR_RESOURCE_IDENTIFIER_INTERSECTION_PASS_INDIRECT_ARGS 16
#define FFX_SSSR_RESOURCE_IDENTIFIER_EXTRACTED_ROUGHNESS 17
#define FFX_SSSR_RESOURCE_IDENTIFIER_RADIANCE_0 18
#define FFX_SSSR_RESOURCE_IDENTIFIER_RADIANCE_1 19
#define FFX_SSSR_RESOURCE_IDENTIFIER_VARIANCE_0 20
#define FFX_SSSR_RESOURCE_IDENTIFIER_VARIANCE_1 21
#define FFX_SSSR_RESOURCE_IDENTIFIER_SOBOL_BUFFER 22
#define FFX_SSSR_RESOURCE_IDENTIFIER_RANKING_TILE_BUFFER 23
#define FFX_SSSR_RESOURCE_IDENTIFIER_SCRAMBLING_TILE_BUFFER 24
#define FFX_SSSR_RESOURCE_IDENTIFIER_BLUE_NOISE_TEXTURE 25
#define FFX_SSSR_RESOURCE_IDENTIFIER_SPD_GLOBAL_ATOMIC 26
#define FFX_SSSR_RESOURCE_IDENTIFIER_COUNT 27
#define FFX_SSSR_CONSTANTBUFFER_IDENTIFIER_SSSR 0
#define FFX_SSSR_CONSTANTBUFFER_IDENTIFIER_COUNT 1
#endif // #if defined(FFX_CPU) || defined(FFX_GPU)
#endif //!defined( FFX_SSSR_RESOURCES_H )