diff --git a/include/vkcv/Downsampler.hpp b/include/vkcv/Downsampler.hpp index d833f58e6a7bd26d17565e097f40f2c93c732f85..b288f3582b64e4b71374aba052c6dbc8c638555b 100644 --- a/include/vkcv/Downsampler.hpp +++ b/include/vkcv/Downsampler.hpp @@ -19,6 +19,7 @@ namespace vkcv { public: /** * Constructor to create a downsampler instance. + * * @param[in,out] core Reference to a Core instance */ explicit Downsampler(Core& core); @@ -29,8 +30,8 @@ namespace vkcv { * Record the commands of the given downsampler instance to * scale the image down on its own mip levels. * - * @param[in] cmdStream - * @param[in] image + * @param[in] cmdStream Command stream handle + * @param[in] image Image handle */ virtual void recordDownsampling(const CommandStreamHandle& cmdStream, const ImageHandle& image) = 0; diff --git a/modules/algorithm/README.md b/modules/algorithm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b01dbbef7d8f6aa3ff4862d76442c892c6f3ce4f --- /dev/null +++ b/modules/algorithm/README.md @@ -0,0 +1,15 @@ +# Algorithm + +A VkCV module to use different optimized algorithms + +## Build + +### Dependencies (required): + +| Name of dependency | Used as submodule | +|----------------------------------------------------------------------|---| +| [FidelityFX-SPD](https://github.com/GPUOpen-Effects/FidelityFX-SPD/) | ✅ | + +## Docs + +Here is a [link](https://vkcv.de/develop/group__vkcv__algorithm.html) to this module. diff --git a/modules/algorithm/include/vkcv/algorithm/SinglePassDownsampler.hpp b/modules/algorithm/include/vkcv/algorithm/SinglePassDownsampler.hpp index 0b5a71cd27e64acebe6afb08f7d27e40b0a9dcd0..02d2f8d6c02a69cd0c79f822201b5b9ed2fc117b 100644 --- a/modules/algorithm/include/vkcv/algorithm/SinglePassDownsampler.hpp +++ b/modules/algorithm/include/vkcv/algorithm/SinglePassDownsampler.hpp @@ -7,40 +7,67 @@ #include <vkcv/ShaderProgram.hpp> namespace vkcv::algorithm { - -#define SPD_MAX_MIP_LEVELS 12 - - struct SPDConstants { - int mips; - int numWorkGroupsPerSlice; - int workGroupOffset[2]; - }; - struct SPDConstantsSampler { - int mips; - int numWorkGroupsPerSlice; - int workGroupOffset[2]; - float invInputSize[2]; - }; + /** + * @defgroup vkcv_algorithm Algorithm Module + * A module to use different optimized algorithms. + * @{ + */ + /** + * A class to handle downsampling via FidelityFX Single Pass Downsampler. + * https://github.com/GPUOpen-Effects/FidelityFX-SPD + */ class SinglePassDownsampler : public vkcv::Downsampler { private: + /** + * The SPD compute pipeline of the downsampler. + */ ComputePipelineHandle m_pipeline; + /** + * The descriptor set layout of the SPD pipeline. + */ DescriptorSetLayoutHandle m_descriptorSetLayout; + + /** + * The vector of descriptor sets currently in use for downsampling. + */ std::vector<DescriptorSetHandle> m_descriptorSets; + /** + * The buffer template to handle global atomic counters for SPD. + */ Buffer<uint32_t> m_globalCounter; + /** + * The optional sampler handle to use for the downsampling. + */ SamplerHandle m_sampler; public: + /** + * Constructor to create instance for single pass downsampling. + * + * @param[in,out] core Reference to a Core instance + * @param[in] sampler Sampler handle + */ explicit SinglePassDownsampler(Core& core, const SamplerHandle &sampler = SamplerHandle()); + /** + * Record the comands of the downsampling instance to + * generate all mip levels of an input image via a + * command stream. + * + * @param[in] cmdStream Command stream handle + * @param[in] image Image handle + */ void recordDownsampling(const CommandStreamHandle& cmdStream, const ImageHandle& image) override; }; + + /** @} */ } diff --git a/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp b/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp index 6d55bfd7212e350bc4611183010ed12cbd5bde4b..fb078cc9cca080d77932422de9a86a4876de249b 100644 --- a/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp +++ b/modules/algorithm/src/vkcv/algorithm/SinglePassDownsampler.cpp @@ -19,6 +19,21 @@ namespace vkcv::algorithm { + #define SPD_MAX_MIP_LEVELS 12 + + struct SPDConstants { + int mips; + int numWorkGroupsPerSlice; + int workGroupOffset[2]; + }; + + struct SPDConstantsSampler { + int mips; + int numWorkGroupsPerSlice; + int workGroupOffset[2]; + float invInputSize[2]; + }; + static DescriptorBindings getDescriptorBindings(const SamplerHandle &sampler) { DescriptorBindings descriptorBindings = {}; diff --git a/modules/upscaling/include/vkcv/upscaling/BilinearUpscaling.hpp b/modules/upscaling/include/vkcv/upscaling/BilinearUpscaling.hpp index 52569467e07a5155e1cf3619755bd092ecf6979b..4f0bfea8499aaa04ce9d7503b47b08e4cd8cde26 100644 --- a/modules/upscaling/include/vkcv/upscaling/BilinearUpscaling.hpp +++ b/modules/upscaling/include/vkcv/upscaling/BilinearUpscaling.hpp @@ -17,6 +17,7 @@ namespace vkcv::upscaling { public: /** * Constructor to create instance for bilinear upscaling. + * * @param[in,out] core Reference to a Core instance */ explicit BilinearUpscaling(Core& core); @@ -25,6 +26,7 @@ namespace vkcv::upscaling { * Record the comands of the bilinear upscaling instance to * scale the image of the input handle to the resolution of * the output image handle via bilinear interpolation. + * * @param[in] cmdStream Command stream handle to record commands * @param[in] input Input image handle * @param[in] output Output image handle diff --git a/modules/upscaling/include/vkcv/upscaling/FSRUpscaling.hpp b/modules/upscaling/include/vkcv/upscaling/FSRUpscaling.hpp index 04f9ea72ffad7510f62163e045c89140b6fdecf7..fd5bbd3795d62aee7dac6e80a72066556a5ffe07 100644 --- a/modules/upscaling/include/vkcv/upscaling/FSRUpscaling.hpp +++ b/modules/upscaling/include/vkcv/upscaling/FSRUpscaling.hpp @@ -49,6 +49,7 @@ namespace vkcv::upscaling { /** * Calculates the internal resolution for actual rendering if * a specific mode of quality is used for upscaling with FSR. + * * @param[in] mode Mode of quality * @param[in] outputWidth Final resolution width * @param[in] outputHeight Final resolution height @@ -62,6 +63,7 @@ namespace vkcv::upscaling { /** * Returns the matching negative lod bias to reduce artifacts * upscaling with FSR under a given mode of quality. + * * @param mode Mode of quality * @return Lod bias */ @@ -179,6 +181,7 @@ namespace vkcv::upscaling { public: /** * Constructor to create instance for FSR upscaling. + * * @param[in,out] core Reference to a Core instance */ explicit FSRUpscaling(Core& core); @@ -187,6 +190,7 @@ namespace vkcv::upscaling { * Record the comands of the FSR upscaling instance to * scale the image of the input handle to the resolution of * the output image handle via FidelityFX Super Resolution. + * * @param[in] cmdStream Command stream handle to record commands * @param[in] input Input image handle * @param[in] output Output image handle @@ -197,6 +201,7 @@ namespace vkcv::upscaling { /** * Checks if HDR support is enabled and returns the status as boolean. + * * @return true if HDR is supported, otherwise false */ [[nodiscard]] @@ -204,12 +209,14 @@ namespace vkcv::upscaling { /** * Changes the status of HDR support of the FSR upscaling instance. + * * @param[in] enabled New status of HDR support */ void setHdrEnabled(bool enabled); /** * Returns the amount of sharpness the FSR upscaling instance is using. + * * @return The amount of sharpness */ [[nodiscard]] @@ -219,6 +226,7 @@ namespace vkcv::upscaling { * Changes the amount of sharpness of the FSR upscaling instance. * The new sharpness value is restricted by 0.0f as lower and 1.0f * as upper boundary. + * * @param[in] sharpness New sharpness value */ void setSharpness(float sharpness); diff --git a/modules/upscaling/include/vkcv/upscaling/NISUpscaling.hpp b/modules/upscaling/include/vkcv/upscaling/NISUpscaling.hpp index efab311d4fb452285bb3d88262ddbf3fbd04a810..9a35bfd57fd261587eea0d327d2eb3154b1cd38a 100644 --- a/modules/upscaling/include/vkcv/upscaling/NISUpscaling.hpp +++ b/modules/upscaling/include/vkcv/upscaling/NISUpscaling.hpp @@ -6,41 +6,129 @@ namespace vkcv::upscaling { + /** + * @addtogroup vkcv_upscaling + * @{ + */ + + /** + * A class to handle upscaling via NVIDIA Image Scaling. + * https://github.com/NVIDIAGameWorks/NVIDIAImageScaling + */ class NISUpscaling : public Upscaling { private: + /** + * The compute pipeline of the NIS upscaling. + */ ComputePipelineHandle m_scalerPipeline; + /** + * The descriptor set layout of the upscaling pipeline. + */ DescriptorSetLayoutHandle m_scalerDescriptorSetLayout; + + /** + * The descriptor set for the upscaling pipeline. + */ DescriptorSetHandle m_scalerDescriptorSet; + /** + * The buffer template to handle NIS constants for + * the upscaling pipeline. + */ Buffer<uint8_t> m_scalerConstants; + + /** + * The sampler handle to use for accessing the images + * in the NIS upscaling process. + */ SamplerHandle m_sampler; + + /** + * The image handle to store the upscaling coefficients. + */ ImageHandle m_coefScaleImage; + + /** + * The image handle to store the USM coefficients. + */ ImageHandle m_coefUsmImage; + /** + * The amount of pixels per block width. + */ uint32_t m_blockWidth; + + /** + * The amount of pixels per block height. + */ uint32_t m_blockHeight; + /** + * Current state of HDR support. + */ bool m_hdr; + + /** + * The current value of sharpness. + */ float m_sharpness; public: + /** + * Constructor to create instance for NIS upscaling. + * + * @param[in,out] core Reference to a Core instance + */ explicit NISUpscaling(Core &core); + /** + * Record the comands of the NIS upscaling instance to + * scale the image of the input handle to the resolution of + * the output image handle via NVIDIA Image Scaling. + * + * @param[in] cmdStream Command stream handle to record commands + * @param[in] input Input image handle + * @param[in] output Output image handle + */ void recordUpscaling(const CommandStreamHandle &cmdStream, const ImageHandle &input, const ImageHandle &output) override; + /** + * Checks if HDR support is enabled and returns the status as boolean. + * + * @return true if HDR is supported, otherwise false + */ [[nodiscard]] bool isHdrEnabled() const; + /** + * Changes the status of HDR support of the NIS upscaling instance. + * + * @param[in] enabled New status of HDR support + */ void setHdrEnabled(bool enabled); + /** + * Returns the amount of sharpness the NIS upscaling instance is using. + * + * @return The amount of sharpness + */ [[nodiscard]] float getSharpness() const; + /** + * Changes the amount of sharpness of the NIS upscaling instance. + * The new sharpness value is restricted by 0.0f as lower and 1.0f + * as upper boundary. + * + * @param[in] sharpness New sharpness value + */ void setSharpness(float sharpness); }; + /** @} */ + } diff --git a/modules/upscaling/include/vkcv/upscaling/Upscaling.hpp b/modules/upscaling/include/vkcv/upscaling/Upscaling.hpp index 12ba21a8576b3c638510b58341810df7aa039bfa..4d04746f0849615a112d04827c7af41811031116 100644 --- a/modules/upscaling/include/vkcv/upscaling/Upscaling.hpp +++ b/modules/upscaling/include/vkcv/upscaling/Upscaling.hpp @@ -24,6 +24,7 @@ namespace vkcv::upscaling { public: /** * Constructor to create an upscaling instance. + * * @param[in,out] core Reference to a Core instance */ explicit Upscaling(Core& core); @@ -34,6 +35,7 @@ namespace vkcv::upscaling { * Record the comands of the given upscaling instance to * scale the image of the input handle to the resolution of * the output image handle. + * * @param[in] cmdStream Command stream handle to record commands * @param[in] input Input image handle * @param[in] output Output image handle