mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-07 11:13:15 +00:00
FidelityFX FSR implementation (#2624)
* host_shaders: support for includes * video_core: add a simpler vulkan asserts * video_core: refactored post processing pipeline to another file * renderer_vulkan: add define param to compile shader utility * video_core: fsr implementation * devtools: show resolution & fsr state
This commit is contained in:
parent
ba1eb298de
commit
f663176a5d
26 changed files with 4984 additions and 324 deletions
|
@ -12,6 +12,7 @@ set(SHADER_FILES
|
|||
detilers/micro_64bpp.comp
|
||||
detilers/micro_8bpp.comp
|
||||
fs_tri.vert
|
||||
fsr.comp
|
||||
post_process.frag
|
||||
)
|
||||
|
||||
|
|
|
@ -9,28 +9,31 @@ get_filename_component(CONTENTS_NAME ${SOURCE_FILE} NAME)
|
|||
string(REPLACE "." "_" CONTENTS_NAME ${CONTENTS_NAME})
|
||||
string(TOUPPER ${CONTENTS_NAME} CONTENTS_NAME)
|
||||
|
||||
FILE(READ ${SOURCE_FILE} line_contents)
|
||||
# Function to recursively parse #include directives and replace them with file contents
|
||||
function(parse_includes file_path output_content)
|
||||
file(READ ${file_path} file_content)
|
||||
# This regex includes \n at the begin to (hackish) avoid including comments
|
||||
string(REGEX MATCHALL "\n#include +\"[^\"]+\"" includes "${file_content}")
|
||||
|
||||
# Replace double quotes with single quotes,
|
||||
# as double quotes will be used to wrap the lines
|
||||
STRING(REGEX REPLACE "\"" "'" line_contents "${line_contents}")
|
||||
set(parsed_content "${file_content}")
|
||||
foreach (include_match ${includes})
|
||||
string(REGEX MATCH "\"([^\"]+)\"" _ "${include_match}")
|
||||
set(include_file ${CMAKE_MATCH_1})
|
||||
get_filename_component(include_full_path "${file_path}" DIRECTORY)
|
||||
set(include_full_path "${include_full_path}/${include_file}")
|
||||
|
||||
# CMake separates list elements with semicolons, but semicolons
|
||||
# are used extensively in the shader code.
|
||||
# Replace with a temporary marker, to be reverted later.
|
||||
STRING(REGEX REPLACE ";" "{{SEMICOLON}}" line_contents "${line_contents}")
|
||||
if (NOT EXISTS "${include_full_path}")
|
||||
message(FATAL_ERROR "Included file not found: ${include_full_path} from ${file_path}")
|
||||
endif ()
|
||||
|
||||
# Make every line an individual element in the CMake list.
|
||||
STRING(REGEX REPLACE "\n" ";" line_contents "${line_contents}")
|
||||
parse_includes("${include_full_path}" sub_content)
|
||||
string(REPLACE "${include_match}" "\n${sub_content}" parsed_content "${parsed_content}")
|
||||
endforeach ()
|
||||
set(${output_content} "${parsed_content}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Build the shader string, wrapping each line in double quotes.
|
||||
foreach(line IN LISTS line_contents)
|
||||
string(CONCAT CONTENTS "${CONTENTS}" \"${line}\\n\"\n)
|
||||
endforeach()
|
||||
|
||||
# Revert the original semicolons in the source.
|
||||
STRING(REGEX REPLACE "{{SEMICOLON}}" ";" CONTENTS "${CONTENTS}")
|
||||
parse_includes("${SOURCE_FILE}" CONTENTS)
|
||||
|
||||
get_filename_component(OUTPUT_DIR ${HEADER_FILE} DIRECTORY)
|
||||
make_directory(${OUTPUT_DIR})
|
||||
file(MAKE_DIRECTORY ${OUTPUT_DIR})
|
||||
configure_file(${INPUT_FILE} ${HEADER_FILE} @ONLY)
|
||||
|
|
91
src/video_core/host_shaders/fsr.comp
Normal file
91
src/video_core/host_shaders/fsr.comp
Normal file
|
@ -0,0 +1,91 @@
|
|||
// SPDX-FileCopyrightText: Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects: enable
|
||||
#extension GL_ARB_shading_language_420pack: enable
|
||||
|
||||
// FidelityFX Super Resolution Sample
|
||||
//
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
layout (push_constant) uniform const_buffer
|
||||
{
|
||||
uvec4 Const0;
|
||||
uvec4 Const1;
|
||||
uvec4 Const2;
|
||||
uvec4 Const3;
|
||||
uvec4 Sample;
|
||||
};
|
||||
|
||||
#define A_GPU 1
|
||||
#define A_GLSL 1
|
||||
|
||||
#define A_HALF
|
||||
#include "fsr/ffx_a.h"
|
||||
|
||||
layout (set = 0, binding = 0) uniform texture2D InputTexture;
|
||||
layout (set = 0, binding = 1, rgba16f) uniform image2D OutputTexture;
|
||||
layout (set = 0, binding = 2) uniform sampler InputSampler;
|
||||
|
||||
#if SAMPLE_EASU
|
||||
#define FSR_EASU_H 1
|
||||
AH4 FsrEasuRH(AF2 p) { AH4 res = AH4(textureGather(sampler2D(InputTexture, InputSampler), p, 0)); return res; }
|
||||
AH4 FsrEasuGH(AF2 p) { AH4 res = AH4(textureGather(sampler2D(InputTexture, InputSampler), p, 1)); return res; }
|
||||
AH4 FsrEasuBH(AF2 p) { AH4 res = AH4(textureGather(sampler2D(InputTexture, InputSampler), p, 2)); return res; }
|
||||
#endif// SAMPLE_EASU
|
||||
|
||||
#if SAMPLE_RCAS
|
||||
#define FSR_RCAS_H
|
||||
AH4 FsrRcasLoadH(ASW2 p) { return AH4(texelFetch(sampler2D(InputTexture, InputSampler), ASU2(p), 0)); }
|
||||
void FsrRcasInputH(inout AH1 r, inout AH1 g, inout AH1 b) { }
|
||||
#endif// SAMPLE_RCAS
|
||||
|
||||
#include "fsr/ffx_fsr1.h"
|
||||
|
||||
void CurrFilter(AU2 pos)
|
||||
{
|
||||
#if SAMPLE_EASU
|
||||
AH3 c;
|
||||
FsrEasuH(c, pos, Const0, Const1, Const2, Const3);
|
||||
if (Sample.x == 1)
|
||||
c *= c;
|
||||
imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
|
||||
#endif// SAMPLE_EASU
|
||||
#if SAMPLE_RCAS
|
||||
AH3 c;
|
||||
FsrRcasH(c.r, c.g, c.b, pos, Const0);
|
||||
if (Sample.x == 1)
|
||||
c *= c;
|
||||
imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
|
||||
#endif// SAMPLE_RCAS
|
||||
}
|
||||
|
||||
layout (local_size_x = 64) in;
|
||||
void main()
|
||||
{
|
||||
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
|
||||
AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
|
||||
CurrFilter(gxy);
|
||||
gxy.x += 8u;
|
||||
CurrFilter(gxy);
|
||||
gxy.y += 8u;
|
||||
CurrFilter(gxy);
|
||||
gxy.x -= 8u;
|
||||
CurrFilter(gxy);
|
||||
}
|
2657
src/video_core/host_shaders/fsr/ffx_a.h
Normal file
2657
src/video_core/host_shaders/fsr/ffx_a.h
Normal file
File diff suppressed because it is too large
Load diff
1200
src/video_core/host_shaders/fsr/ffx_fsr1.h
Normal file
1200
src/video_core/host_shaders/fsr/ffx_fsr1.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ layout (location = 0) out vec4 color;
|
|||
|
||||
layout (binding = 0) uniform sampler2D texSampler;
|
||||
|
||||
layout(push_constant) uniform settings {
|
||||
layout (push_constant) uniform settings {
|
||||
float gamma;
|
||||
bool hdr;
|
||||
} pp;
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
namespace HostShaders {
|
||||
|
||||
constexpr std::string_view @CONTENTS_NAME@ = {
|
||||
constexpr std::string_view @CONTENTS_NAME@ = R"shader_src(
|
||||
@CONTENTS@
|
||||
};
|
||||
)shader_src";
|
||||
|
||||
} // namespace HostShaders
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue