diff --git a/modules/upscaling/config/FidelityFX_FSR.cmake b/modules/upscaling/config/FidelityFX_FSR.cmake index 37a6321c16600f1bc811c6cee7fe6d8cfe8085ca..861f76510ec8c7cbb20cd113a6c050695f66cb7e 100644 --- a/modules/upscaling/config/FidelityFX_FSR.cmake +++ b/modules/upscaling/config/FidelityFX_FSR.cmake @@ -2,6 +2,7 @@ if (EXISTS "${vkcv_upscaling_lib_path}/FidelityFX-FSR") include_shader(${vkcv_upscaling_lib_path}/FidelityFX-FSR/ffx-fsr/ffx_a.h ${vkcv_upscaling_include} ${vkcv_upscaling_source}) include_shader(${vkcv_upscaling_lib_path}/FidelityFX-FSR/ffx-fsr/ffx_fsr1.h ${vkcv_upscaling_include} ${vkcv_upscaling_source}) + include_shader(${vkcv_upscaling_lib_path}/FidelityFX-FSR/sample/src/VK/FSR_Pass.glsl ${vkcv_upscaling_include} ${vkcv_upscaling_source}) list(APPEND vkcv_upscaling_includes ${vkcv_upscaling_lib}/FidelityFX-FSR/ffx-fsr) else() diff --git a/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp b/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp index 9434f017a4c94878547a0a2dc48ebb384f5bc9ec..934d550cdf9fb31c90cc7ace41e1d9066f558cd7 100644 --- a/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp +++ b/modules/upscaling/src/vkcv/upscaling/FSRUpscaling.cpp @@ -10,19 +10,53 @@ #include "ffx_a.h.hxx" #include "ffx_fsr1.h.hxx" +#include "FSR_Pass.glsl.hxx" +#include <vkcv/File.hpp> +#include <vkcv/Logger.hpp> #include <vkcv/shader/GLSLCompiler.hpp> namespace vkcv::upscaling { - static void setupTemporaryShaderDirectory() { + static bool writeShaderCode(const std::filesystem::path &shaderPath, const std::string& code) { + std::ofstream file (shaderPath.string(), std::ios::out); + + if (!file.is_open()) { + vkcv_log(LogLevel::ERROR, "The file could not be opened (%s)", shaderPath.string().c_str()); + return false; + } + + file.seekp(0); + file.write(code.c_str(), static_cast<std::streamsize>(code.length())); + file.close(); + + return true; + } + static bool compileFSRShaders(const shader::ShaderCompiledFunction& compiled) { + std::filesystem::path directory = generateTemporaryFilePath(); + + if (!std::filesystem::create_directory(directory)) { + vkcv_log(LogLevel::ERROR, "The directory could not be created (%s)", directory.string().c_str()); + return false; + } + + if (!writeShaderCode(directory / "ffx_a.h", FFX_A_H_SHADER)) { + return false; + } + + if (!writeShaderCode(directory / "ffx_fsr1.h", FFX_FSR1_H_SHADER)) { + return false; + } + + vkcv::shader::GLSLCompiler compiler; + return compiler.compileSource(vkcv::ShaderStage::COMPUTE, + FSR_PASS_GLSL_SHADER.c_str(), + compiled, directory); } FSRUpscaling::FSRUpscaling() { - vkcv::shader::GLSLCompiler compiler; - compiler.compile(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/shader.vert"), - [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { + compileFSRShaders([&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { m_program.addShader(shaderStage, path); }); }