Skip to content

Commit 7fddbf2

Browse files
MikhailGorobetsTheMostDiligent
authored andcommitted
Integrate FSR spatial upscaler
1 parent a920b28 commit 7fddbf2

20 files changed

+12022
-5
lines changed

BuildTools/FormatValidation/validate_format_linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ validate_format ../../Common ../../Graphics ../../Platforms ../../Primitives ../
66
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
77
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
88
--exclude ../../Graphics/GraphicsEngineVulkan/shaders \
9+
--exclude ../../Graphics/SuperResolution/shaders \
910
--exclude ../../Graphics/GraphicsEngine.NET \
1011
--exclude ../../Tests/DiligentCoreAPITest/assets
1112

BuildTools/FormatValidation/validate_format_mac.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ python3 clang-format-validate.py --clang-format-executable ./clang-format_mac_10
44
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h \
55
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h \
66
--exclude ../../Graphics/GraphicsEngineVulkan/shaders \
7+
--exclude ../../Graphics/SuperResolution/shaders \
78
--exclude ../../Graphics/GraphicsEngine.NET \
89
--exclude ../../Tests/DiligentCoreAPITest/assets

BuildTools/FormatValidation/validate_format_win.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ python clang-format-validate.py --color never --clang-format-executable clang-fo
33
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h ^
44
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h ^
55
--exclude ../../Graphics/GraphicsEngineVulkan/shaders ^
6+
--exclude ../../Graphics/SuperResolution/shaders ^
67
--exclude ../../Graphics/GraphicsEngine.NET ^
78
--exclude ../../Tests/DiligentCoreAPITest/assets

Graphics/SuperResolution/CMakeLists.txt

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project(Diligent-SuperResolution CXX)
66

77
set(DILIGENT_DLSS_SUPPORTED FALSE CACHE INTERNAL "DLSS is not supported")
88
set(DILIGENT_DSR_SUPPORTED FALSE CACHE INTERNAL "DirectSR is not supported")
9+
set(DILIGENT_FSR_SUPPORTED TRUE CACHE INTERNAL "FSR is not supported")
910

1011
if(PLATFORM_WIN32 AND NOT MINGW_BUILD AND CMAKE_SIZEOF_VOID_P EQUAL 8)
1112
if (D3D11_SUPPORTED OR D3D12_SUPPORTED OR VULKAN_SUPPORTED)
@@ -22,6 +23,9 @@ endif()
2223
if(${DILIGENT_NO_DSR})
2324
set(DILIGENT_DSR_SUPPORTED FALSE CACHE INTERNAL "DirectSR is forcibly disabled")
2425
endif()
26+
if(${DILIGENT_NO_FSR})
27+
set(DILIGENT_FSR_SUPPORTED FALSE CACHE INTERNAL "FSR is forcibly disabled")
28+
endif()
2529

2630
if(DILIGENT_DSR_SUPPORTED)
2731
# Fetch DirectSR headers
@@ -61,6 +65,35 @@ set(SOURCE
6165
src/SuperResolutionFactory.cpp
6266
)
6367

68+
if(DILIGENT_FSR_SUPPORTED)
69+
set(FSR_SHADERS
70+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/FSR_FullQuad.fx
71+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/FSRStructures.fxh
72+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/FSR_EdgeAdaptiveUpsampling.fx
73+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/FSR_ContrastAdaptiveSharpening.fx
74+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_common_types.h
75+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core.h
76+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core_glsl.h
77+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core_gpu_common.h
78+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core_gpu_common_half.h
79+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core_hlsl.h
80+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_core_portability.h
81+
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fsr1/ffx_fsr1.h
82+
)
83+
set_source_files_properties(${FSR_SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None")
84+
85+
# Convert shaders to headers and generate master header with the list of all files
86+
set(FSR_SHADER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/shaders_inc/FSR)
87+
file(MAKE_DIRECTORY ${FSR_SHADER_OUTPUT_DIR})
88+
set(FSR_SHADERS_LIST_FILE ${FSR_SHADER_OUTPUT_DIR}/FSRShaderList.h)
89+
convert_shaders_to_headers("${FSR_SHADERS}" ${FSR_SHADER_OUTPUT_DIR} ${FSR_SHADERS_LIST_FILE} FSR_SHADERS_INC_LIST)
90+
91+
list(APPEND SOURCE src/FSRProvider.cpp)
92+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
93+
set_source_files_properties(src/FSRProvider.cpp PROPERTIES COMPILE_OPTIONS "-Wno-unused-function")
94+
endif()
95+
endif()
96+
6497
if(DILIGENT_DLSS_SUPPORTED)
6598
list(APPEND INCLUDE include/SuperResolutionDLSS.hpp)
6699
list(APPEND SOURCE src/SuperResolutionDLSS.cpp)
@@ -92,9 +125,17 @@ target_include_directories(Diligent-SuperResolutionInterface INTERFACE interface
92125
target_compile_definitions(Diligent-SuperResolutionInterface INTERFACE SUPER_RESOLUTION_SUPPORTED=1)
93126

94127
add_library(Diligent-SuperResolution-static STATIC
95-
${SOURCE} ${INTERFACE} ${INCLUDE}
128+
${SOURCE}
129+
${INTERFACE}
130+
${INCLUDE}
131+
${FSR_SHADERS}
132+
${FSR_SHADERS_INC_LIST}
133+
${FSR_SHADERS_LIST_FILE}
96134
readme.md
97135
)
136+
source_group("shaders/FSR" FILES ${FSR_SHADERS})
137+
source_group("generated/FSR" FILES ${FSR_SHADERS_INC_LIST} ${FSR_SHADERS_LIST_FILE})
138+
98139
add_library(Diligent-SuperResolution-shared SHARED
99140
readme.md
100141
)
@@ -129,6 +170,11 @@ if(DILIGENT_DSR_SUPPORTED)
129170
endif()
130171
endif()
131172

173+
if(DILIGENT_FSR_SUPPORTED)
174+
target_compile_definitions(Diligent-SuperResolution-static PRIVATE DILIGENT_FSR_SUPPORTED=1)
175+
target_include_directories(Diligent-SuperResolution-static PRIVATE ${FSR_SHADER_OUTPUT_DIR})
176+
endif()
177+
132178
target_compile_definitions(Diligent-SuperResolution-shared PUBLIC DILIGENT_SUPER_RESOLUTION_SHARED=1)
133179

134180
target_link_libraries(Diligent-SuperResolution-static
@@ -139,6 +185,7 @@ PRIVATE
139185
Diligent-Common
140186
Diligent-GraphicsAccessories
141187
Diligent-ShaderTools
188+
Diligent-GraphicsTools
142189
)
143190

144191
if(DILIGENT_DSR_SUPPORTED)

Graphics/SuperResolution/include/SuperResolutionVariants.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ static constexpr INTERFACE_ID VariantId_MetalFXSpatial =
4646
static constexpr INTERFACE_ID VariantId_MetalFXTemporal =
4747
{0xc4d70002, 0xa1b2, 0x4c3d, {0x8e, 0x9f, 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f}};
4848

49+
// {F5A10001-B2C3-4D5E-9F01-2A3B4C5D6E7F}
50+
static constexpr INTERFACE_ID VariantId_FSRSpatial =
51+
{0xf5a10001, 0xb2c3, 0x4d5e, {0x9f, 0x01, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f}};
52+
4953
} // namespace Diligent
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef _FSR_STRUCTURES_FXH_
2+
#define _FSR_STRUCTURES_FXH_
3+
4+
#ifndef __cplusplus
5+
# ifndef DEFAULT_VALUE
6+
# define DEFAULT_VALUE(x)
7+
# endif
8+
#elif !defined(DEFAULT_VALUE)
9+
# define DEFAULT_VALUE(x) = x
10+
#endif
11+
12+
#ifndef __cplusplus
13+
# ifndef CHECK_STRUCT_ALIGNMENT
14+
# define CHECK_STRUCT_ALIGNMENT(s)
15+
# endif
16+
#endif
17+
18+
struct FSRAttribs
19+
{
20+
uint4 EASUConstants0;
21+
uint4 EASUConstants1;
22+
uint4 EASUConstants2;
23+
uint4 EASUConstants3;
24+
uint4 RCASConstants;
25+
float4 SourceSize;
26+
};
27+
28+
#ifdef CHECK_STRUCT_ALIGNMENT
29+
CHECK_STRUCT_ALIGNMENT(FSRAttribs);
30+
#endif
31+
32+
33+
#endif //_FSR_STRUCTURES_FXH_
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "FSRStructures.fxh"
2+
3+
cbuffer cbFSRAttribs
4+
{
5+
FSRAttribs g_FSRAttribs;
6+
}
7+
8+
Texture2D<float4> g_TextureSource;
9+
10+
#define FFX_GPU
11+
#define FFX_HLSL
12+
#define FFX_HALF 0
13+
#define FFX_HLSL_SM 50
14+
#include "ffx_core.h"
15+
16+
#define FSR_RCAS_F 1
17+
#define FSR_RCAS_DENOISE 1
18+
19+
FfxFloat32x4 FsrRcasLoadF(FfxInt32x2 Position)
20+
{
21+
return g_TextureSource.Load(FfxInt32x3(Position, 0));
22+
}
23+
24+
void FsrRcasInputF(FFX_PARAMETER_INOUT FfxFloat32 R, FFX_PARAMETER_INOUT FfxFloat32 G, FFX_PARAMETER_INOUT FfxFloat32 B)
25+
{
26+
27+
}
28+
29+
#include "ffx_fsr1.h"
30+
31+
FfxFloat32x4 ComputeContrastAdaptiveSharpeningPS(in float4 Position : SV_Position) : SV_Target0
32+
{
33+
FfxFloat32x3 ResultColor = FfxFloat32x3(0.0, 0.0, 0.0);
34+
FsrRcasF(ResultColor.r, ResultColor.g, ResultColor.b, FfxUInt32x2(Position.xy), g_FSRAttribs.RCASConstants);
35+
return FfxFloat32x4(ResultColor, 1.0);
36+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "FSRStructures.fxh"
2+
3+
cbuffer cbFSRAttribs
4+
{
5+
FSRAttribs g_FSRAttribs;
6+
}
7+
8+
Texture2D<float4> g_TextureSource;
9+
SamplerState g_TextureSource_sampler;
10+
11+
#define FFX_GPU
12+
#define FFX_HLSL
13+
#define FFX_HALF 0
14+
#define FFX_HLSL_SM 50
15+
#include "ffx_core.h"
16+
17+
#define FFX_FSR_EASU_FLOAT 1
18+
19+
FfxFloat32x4 FsrEasuRF(FfxFloat32x2 Texcoord)
20+
{
21+
#ifdef FSR_FEATURE_TEXTURE_GATHER
22+
return g_TextureSource.GatherRed(g_TextureSource_sampler, Texcoord);
23+
#else
24+
float2 Position = g_FSRAttribs.SourceSize.xy * Texcoord - float2(0.5, 0.5);
25+
FfxFloat32x4 Gather;
26+
Gather.x = g_TextureSource.Load(int3(int2(Position) + int2(0, 1), 0)).r;
27+
Gather.y = g_TextureSource.Load(int3(int2(Position) + int2(1, 1), 0)).r;
28+
Gather.z = g_TextureSource.Load(int3(int2(Position) + int2(1, 0), 0)).r;
29+
Gather.w = g_TextureSource.Load(int3(int2(Position) + int2(0, 0), 0)).r;
30+
return Gather;
31+
#endif
32+
}
33+
34+
FfxFloat32x4 FsrEasuGF(FfxFloat32x2 Texcoord)
35+
{
36+
#ifdef FSR_FEATURE_TEXTURE_GATHER
37+
return g_TextureSource.GatherGreen(g_TextureSource_sampler, Texcoord);
38+
#else
39+
float2 Position = g_FSRAttribs.SourceSize.xy * Texcoord - float2(0.5, 0.5);
40+
FfxFloat32x4 Gather;
41+
Gather.x = g_TextureSource.Load(int3(int2(Position) + int2(0, 1), 0)).g;
42+
Gather.y = g_TextureSource.Load(int3(int2(Position) + int2(1, 1), 0)).g;
43+
Gather.z = g_TextureSource.Load(int3(int2(Position) + int2(1, 0), 0)).g;
44+
Gather.w = g_TextureSource.Load(int3(int2(Position) + int2(0, 0), 0)).g;
45+
return Gather;
46+
#endif
47+
}
48+
49+
FfxFloat32x4 FsrEasuBF(FfxFloat32x2 Texcoord)
50+
{
51+
#ifdef FSR_FEATURE_TEXTURE_GATHER
52+
return g_TextureSource.GatherBlue(g_TextureSource_sampler, Texcoord);
53+
#else
54+
float2 Position = g_FSRAttribs.SourceSize.xy * Texcoord - float2(0.5, 0.5);
55+
FfxFloat32x4 Gather;
56+
Gather.x = g_TextureSource.Load(int3(int2(Position) + int2(0, 1), 0)).b;
57+
Gather.y = g_TextureSource.Load(int3(int2(Position) + int2(1, 1), 0)).b;
58+
Gather.z = g_TextureSource.Load(int3(int2(Position) + int2(1, 0), 0)).b;
59+
Gather.w = g_TextureSource.Load(int3(int2(Position) + int2(0, 0), 0)).b;
60+
return Gather;
61+
#endif
62+
}
63+
64+
#include "ffx_fsr1.h"
65+
66+
FfxFloat32x4 ComputeEdgeAdaptiveUpsamplingPS(in float4 Position : SV_Position) : SV_Target0
67+
{
68+
FfxFloat32x3 ResultColor = FfxFloat32x3(0.0, 0.0, 0.0);
69+
ffxFsrEasuFloat(ResultColor, FfxUInt32x2(Position.xy),
70+
g_FSRAttribs.EASUConstants0, g_FSRAttribs.EASUConstants1,
71+
g_FSRAttribs.EASUConstants2, g_FSRAttribs.EASUConstants3);
72+
return FfxFloat32x4(ResultColor, 1.0);
73+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct FSR_VSOutput
2+
{
3+
float4 Position : SV_Position;
4+
};
5+
6+
void FSR_FullQuadVS(in uint VertexId : SV_VertexID, out FSR_VSOutput VSOut)
7+
{
8+
float2 PosXY[3];
9+
PosXY[0] = float2(-1.0, -1.0);
10+
PosXY[1] = float2(-1.0, +3.0);
11+
PosXY[2] = float2(+3.0, -1.0);
12+
13+
VSOut.Position = float4(PosXY[VertexId % 3u], 0.0, 1.0);
14+
}

0 commit comments

Comments
 (0)