From 33e11eef3e51dfcc4a3baf1e1ccd79a4bf56d32d Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Mon, 30 Jun 2025 04:57:55 +0200 Subject: [PATCH] shaderchain draft headers --- include/shaderchains/alpha.hpp | 18 +++--- include/shaderchains/beta.hpp | 72 +++++++++++++++++++++++ include/shaderchains/delta.hpp | 72 +++++++++++++++++++++++ include/shaderchains/downsample.hpp | 12 ++-- include/shaderchains/epsilon.hpp | 75 ++++++++++++++++++++++++ include/shaderchains/extract.hpp | 74 ++++++++++++++++++++++++ include/shaderchains/gamma.hpp | 89 +++++++++++++++++++++++++++++ include/shaderchains/magic.hpp | 84 +++++++++++++++++++++++++++ include/shaderchains/merge.hpp | 78 +++++++++++++++++++++++++ include/shaderchains/zeta.hpp | 75 ++++++++++++++++++++++++ 10 files changed, 634 insertions(+), 15 deletions(-) create mode 100644 include/shaderchains/beta.hpp create mode 100644 include/shaderchains/delta.hpp create mode 100644 include/shaderchains/epsilon.hpp create mode 100644 include/shaderchains/extract.hpp create mode 100644 include/shaderchains/gamma.hpp create mode 100644 include/shaderchains/magic.hpp create mode 100644 include/shaderchains/merge.hpp create mode 100644 include/shaderchains/zeta.hpp diff --git a/include/shaderchains/alpha.hpp b/include/shaderchains/alpha.hpp index 84a1b7a..1f0cbb1 100644 --- a/include/shaderchains/alpha.hpp +++ b/include/shaderchains/alpha.hpp @@ -14,7 +14,7 @@ namespace Vulkan::Shaderchains { /// /// Shader chain alpha. /// - /// Takes an 8-bit R texture creates four quarter-sized 8-bit RGBA textures. + /// Takes an 8-bit R image creates four quarter-sized 8-bit RGBA images. /// class Alpha { public: @@ -23,12 +23,12 @@ namespace Vulkan::Shaderchains { /// /// @param device The Vulkan device to create the resources on. /// @param pool The descriptor pool to allocate in. - /// @param inImage The input texture to process + /// @param inImg The input image to process /// /// @throws ls::vulkan_error if resource creation fails. /// Alpha(const Device& device, const Core::DescriptorPool& pool, - const Core::Image& inImage); + const Core::Image& inImg); /// /// Dispatch the shaderchain. @@ -40,7 +40,7 @@ namespace Vulkan::Shaderchains { void Dispatch(const Core::CommandBuffer& buf); /// Get the output images. - [[nodiscard]] const auto& getOutImages() const { return this->outImages; } + [[nodiscard]] const auto& getOutImages() const { return this->outImgs; } /// Trivially copyable, moveable and destructible Alpha(const Alpha&) noexcept = default; @@ -53,13 +53,13 @@ namespace Vulkan::Shaderchains { std::vector pipelines{4}; std::vector descriptorSets{4}; - Core::Image inImage; + Core::Image inImg; - std::vector tempTex1{2}; // half-size - std::vector tempTex2{2}; // half-size - std::vector tempTex3{4}; // quarter-size + std::vector tempImgs1{2}; // half-size + std::vector tempImgs2{2}; // half-size + std::vector tempImgs3{4}; // quarter-size - std::vector outImages{4}; // quarter-size + std::vector outImgs{4}; // quarter-size }; } diff --git a/include/shaderchains/beta.hpp b/include/shaderchains/beta.hpp new file mode 100644 index 0000000..e9efe7d --- /dev/null +++ b/include/shaderchains/beta.hpp @@ -0,0 +1,72 @@ +#ifndef BETA_HPP +#define BETA_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain beta. + /// + /// Takes eight temporal 8-bit RGBA images, as well as the four output images from alpha, + /// and creates six 8-bit R images, halving in resolution each step. + /// + class Beta { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to allocate in. + /// @param temporalImgs The temporal images to use for processing. + /// @param inImgs The input images to process + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Beta(const Device& device, const Core::DescriptorPool& pool, + const std::vector& temporalImgs, + const std::vector& inImgs); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output images. + [[nodiscard]] const auto& getOutImages() const { return this->outImgs; } + + /// Trivially copyable, moveable and destructible + Beta(const Beta&) noexcept = default; + Beta& operator=(const Beta&) noexcept = default; + Beta(Beta&&) noexcept = default; + Beta& operator=(Beta&&) noexcept = default; + ~Beta() = default; + private: + std::vector shaderModules{5}; + std::vector pipelines{5}; + std::vector descriptorSets{5}; + Core::Buffer buffer; + + std::vector temporalImgs{8}; + std::vector inImgs{4}; + + std::vector tempImgs1{2}; + std::vector tempImgs2{2}; + + std::vector outImgs{6}; + }; + +} + +#endif // BETA_HPP diff --git a/include/shaderchains/delta.hpp b/include/shaderchains/delta.hpp new file mode 100644 index 0000000..4a5d7e1 --- /dev/null +++ b/include/shaderchains/delta.hpp @@ -0,0 +1,72 @@ +#ifndef DELTA_HPP +#define DELTA_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain delta. + /// + /// Takes two 8-bit RGBA images and an optional third 16-bit half-res RGBA image, + /// producing a full-res 16-bit RGBA image. + /// + class Delta { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to allocate in. + /// @param inImgs The input images to process. + /// @param optImg An optional additional input from the previous pass. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Delta(const Device& device, const Core::DescriptorPool& pool, + const std::vector& inImgs, + const std::optional& optImg); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output image. + [[nodiscard]] const auto& getOutImage() const { return this->outImg; } + + /// Trivially copyable, moveable and destructible + Delta(const Delta&) noexcept = default; + Delta& operator=(const Delta&) noexcept = default; + Delta(Delta&&) noexcept = default; + Delta& operator=(Delta&&) noexcept = default; + ~Delta() = default; + private: + std::vector shaderModules{4}; + std::vector pipelines{4}; + std::vector descriptorSets{4}; + Core::Buffer buffer; + + std::vector inImg{2}; + std::optional optImg; + + std::vector tempImgs1{2}; + std::vector tempImgs2{2}; + + Core::Image outImg; + }; + +} + +#endif // DELTA_HPP diff --git a/include/shaderchains/downsample.hpp b/include/shaderchains/downsample.hpp index 21cc8c3..0f9c523 100644 --- a/include/shaderchains/downsample.hpp +++ b/include/shaderchains/downsample.hpp @@ -15,7 +15,7 @@ namespace Vulkan::Shaderchains { /// /// Downsample shader. /// - /// Takes an 8-bit RGBA texture and downsamples it into 7x 8-bit R textures. + /// Takes an 8-bit RGBA image and downsamples it into 7x 8-bit R images. /// class Downsample { public: @@ -24,12 +24,12 @@ namespace Vulkan::Shaderchains { /// /// @param device The Vulkan device to create the resources on. /// @param pool The descriptor pool to allocate in. - /// @param inImage The input image to downsample. + /// @param inImg The input image to downsample. /// /// @throws ls::vulkan_error if resource creation fails. /// Downsample(const Device& device, const Core::DescriptorPool& pool, - const Core::Image& inImage); + const Core::Image& inImg); /// /// Dispatch the shaderchain. @@ -41,7 +41,7 @@ namespace Vulkan::Shaderchains { void Dispatch(const Core::CommandBuffer& buf); /// Get the output images. - [[nodiscard]] const auto& getOutImages() const { return this->outImages; } + [[nodiscard]] const auto& getOutImages() const { return this->outImgs; } /// Trivially copyable, moveable and destructible Downsample(const Downsample&) noexcept = default; @@ -55,9 +55,9 @@ namespace Vulkan::Shaderchains { Core::DescriptorSet descriptorSet; Core::Buffer buffer; - Core::Image inImage; + Core::Image inImg; - std::vector outImages{7}; + std::vector outImgs{7}; }; } diff --git a/include/shaderchains/epsilon.hpp b/include/shaderchains/epsilon.hpp new file mode 100644 index 0000000..b875a26 --- /dev/null +++ b/include/shaderchains/epsilon.hpp @@ -0,0 +1,75 @@ +#ifndef EPSILON_HPP +#define EPSILON_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain epsilon. + /// + /// Takes three 8-bit RGBA textures, a fourth 8-bit R texture, an optional fifth + /// half-res 16-bit RGBA texture and produces a full-res 16-bit RGBA texture. + /// + class Epsilon { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to use for descriptor sets. + /// @param inImgs1 The first set of input images to process. + /// @param inImg2 The second type image to process. + /// @param optImg An optional additional input from the previous pass. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Epsilon(const Device& device, const Core::DescriptorPool& pool, + const std::vector& inImgs1, + const Core::Image& inImg2, + const std::optional& optImg); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output image. + [[nodiscard]] const auto& getOutImage() const { return this->outImg; } + + /// Trivially copyable, moveable and destructible + Epsilon(const Epsilon&) noexcept = default; + Epsilon& operator=(const Epsilon&) noexcept = default; + Epsilon(Epsilon&&) noexcept = default; + Epsilon& operator=(Epsilon&&) noexcept = default; + ~Epsilon() = default; + private: + std::vector shaderModules{4}; + std::vector pipelines{4}; + std::vector descriptorSets{4}; + Core::Buffer buffer; + + std::vector inImgs1{3}; + Core::Image inImg2; + std::optional optImg; + + std::vector tempImgs1{4}; + std::vector tempImgs2{4}; + + Core::Image outImg; + }; + +} + +#endif // EPSILON_HPP diff --git a/include/shaderchains/extract.hpp b/include/shaderchains/extract.hpp new file mode 100644 index 0000000..b8677de --- /dev/null +++ b/include/shaderchains/extract.hpp @@ -0,0 +1,74 @@ +#ifndef EXTRACT_HPP +#define EXTRACT_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" +#include + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain extract. + /// + /// Takes two half-res 16-bit RGBA textures, producing + /// an full-res 8-bit RGBA texture. + /// + class Extract { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to use for descriptor sets. + /// @param inImg1 The first set of input images to process. + /// @param inImg2 The second type image to process. + /// @param outExtent The extent of the output image. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Extract(const Device& device, const Core::DescriptorPool& pool, + const Core::Image& inImg1, + const Core::Image& inImg2, + VkExtent2D outExtent); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output image. + [[nodiscard]] const auto& getOutImage() const { return this->outImg; } + + /// Trivially copyable, moveable and destructible + Extract(const Extract&) noexcept = default; + Extract& operator=(const Extract&) noexcept = default; + Extract(Extract&&) noexcept = default; + Extract& operator=(Extract&&) noexcept = default; + ~Extract() = default; + private: + Core::ShaderModule shaderModule; + Core::Pipeline pipeline; + Core::DescriptorSet descriptorSet; + Core::Buffer buffer; + + Core::Image inImg1; + Core::Image inImg2; + + Core::Image whiteImg; + + Core::Image outImg; + }; + +} + +#endif // EXTRACT_HPP diff --git a/include/shaderchains/gamma.hpp b/include/shaderchains/gamma.hpp new file mode 100644 index 0000000..693a16d --- /dev/null +++ b/include/shaderchains/gamma.hpp @@ -0,0 +1,89 @@ +#ifndef GAMMA_HPP +#define GAMMA_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain gamma. + /// + /// Takes four temporal 8-bit RGBA images, as well as four output images from a given alpha stage. + /// Also takes the corresponding (smallest if oob) output image from the beta pass. + /// On non-first passes optionally takes 2 output images from previous gamma pass. + /// Creates two images, one at twice the resolution of input images and the other with R16G16B16A16_FLOAT. + /// + class Gamma { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to allocate in. + /// @param temporalImgs The temporal images to use for processing. + /// @param inImgs1 The input images to process. + /// @param inImg2 The second input image to process, next step up the resolution. + /// @param optImg1 An optional additional input from the previous pass. + /// @param optImg2 An optional additional input image for processing non-first passes. + /// @param outExtent The extent of the output image. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Gamma(const Device& device, const Core::DescriptorPool& pool, + const std::vector& temporalImgs, + const std::vector& inImgs1, + const Core::Image& inImg2, + const std::optional& optImg1, + const std::optional& optImg2, + VkExtent2D outExtent); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the first output image. + [[nodiscard]] const auto& getOutImage1() const { return this->outImg1; } + /// Get the second output image. + [[nodiscard]] const auto& getOutImage2() const { return this->outImg2; } + + /// Trivially copyable, moveable and destructible + Gamma(const Gamma&) noexcept = default; + Gamma& operator=(const Gamma&) noexcept = default; + Gamma(Gamma&&) noexcept = default; + Gamma& operator=(Gamma&&) noexcept = default; + ~Gamma() = default; + private: + std::vector shaderModules{6}; + std::vector pipelines{6}; + std::vector descriptorSets{6}; + Core::Buffer buffer; + + std::vector temporalImgs{4}; + std::vector inImgs1{4}; + Core::Image inImg2; + Core::Image optImg1; // specified or created black + std::optional optImg2; + + std::vector tempImgs1{4}; + std::vector tempImgs2{4}; + Core::Image whiteImg; + + Core::Image outImg1; + Core::Image outImg2; + }; + +} + +#endif // GAMMA_HPP diff --git a/include/shaderchains/magic.hpp b/include/shaderchains/magic.hpp new file mode 100644 index 0000000..188df72 --- /dev/null +++ b/include/shaderchains/magic.hpp @@ -0,0 +1,84 @@ +#ifndef MAGIC_HPP +#define MAGIC_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain magic. + /// + /// Takes textures similar to gamma shader chain, produces intermediary + /// results in groups of 3, 2, 2. + /// + class Magic { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to use for descriptor sets. + /// @param temporalImgs The temporal images to use for processing. + /// @param inImgs1 The first set of input images to process. + /// @param inImg2 The second input image to process. + /// @param inImg3 The third input image to process, next step up the resolution. + /// @param optImg An optional additional input from the previous pass. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Magic(const Device& device, const Core::DescriptorPool& pool, + const std::array& temporalImgs, + const std::array& inImgs1, + const Core::Image& inImg2, + const Core::Image& inImg3, + const std::optional& optImg); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the first set of output images + [[nodiscard]] const auto& getOutImages1() const { return this->outImgs1; } + /// Get the second set of output images + [[nodiscard]] const auto& getOutImages2() const { return this->outImgs2; } + /// Get the third set of output images + [[nodiscard]] const auto& getOutImages3() const { return this->outImgs3; } + + /// Trivially copyable, moveable and destructible + Magic(const Magic&) noexcept = default; + Magic& operator=(const Magic&) noexcept = default; + Magic(Magic&&) noexcept = default; + Magic& operator=(Magic&&) noexcept = default; + ~Magic() = default; + private: + Core::ShaderModule shaderModule; + Core::Pipeline pipeline; + Core::DescriptorSet descriptorSet; + Core::Buffer buffer; + + std::vector temporalImgs{4}; + std::vector inImgs1{4}; + Core::Image inImg2; + Core::Image inImg3; + std::optional optImg; + + std::vector outImgs1{3}; + std::vector outImgs2{3}; + std::vector outImgs3{3}; + }; + +} + +#endif // MAGIC_HPP diff --git a/include/shaderchains/merge.hpp b/include/shaderchains/merge.hpp new file mode 100644 index 0000000..520cd47 --- /dev/null +++ b/include/shaderchains/merge.hpp @@ -0,0 +1,78 @@ +#ifndef MERGE_HPP +#define MERGE_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain merge. + /// + /// Takes the two previous frames as well as related resources + /// and merges them into a new frame. + /// + class Merge { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to use for descriptor sets. + /// @param inImg1 The first frame texture + /// @param inImg2 The second frame texture + /// @param inImg3 The first related input texture + /// @param inImg4 The second related input texture + /// @param inImg5 The third related input texture + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Merge(const Device& device, const Core::DescriptorPool& pool, + const Core::Image& inImg1, + const Core::Image& inImg2, + const Core::Image& inImg3, + const Core::Image& inImg4, + const Core::Image& inImg5); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output image + [[nodiscard]] const auto& getOutImage() const { return this->outImg; } + + /// Trivially copyable, moveable and destructible + Merge(const Merge&) noexcept = default; + Merge& operator=(const Merge&) noexcept = default; + Merge(Merge&&) noexcept = default; + Merge& operator=(Merge&&) noexcept = default; + ~Merge() = default; + private: + Core::ShaderModule shaderModule; + Core::Pipeline pipeline; + Core::DescriptorSet descriptorSet; + Core::Buffer buffer; + + Core::Image inImg1; + Core::Image inImg2; + Core::Image inImg3; + Core::Image inImg4; + Core::Image inImg5; + + Core::Image outImg; + }; + +} + +#endif // MERGE_HPP diff --git a/include/shaderchains/zeta.hpp b/include/shaderchains/zeta.hpp new file mode 100644 index 0000000..e0847d1 --- /dev/null +++ b/include/shaderchains/zeta.hpp @@ -0,0 +1,75 @@ +#ifndef ZETA_HPP +#define ZETA_HPP + +#include "core/buffer.hpp" +#include "core/commandbuffer.hpp" +#include "core/descriptorpool.hpp" +#include "core/descriptorset.hpp" +#include "core/image.hpp" +#include "core/pipeline.hpp" +#include "core/shadermodule.hpp" +#include "device.hpp" + +namespace Vulkan::Shaderchains { + + /// + /// Shader chain zeta. + /// + /// Takes three 8-bit RGBA textures, a fourth 8-bit R texture, a fifth + /// half-res 16-bit RGBA texture and produces a full-res 16-bit RGBA texture. + /// + class Zeta { + public: + /// + /// Initialize the shaderchain. + /// + /// @param device The Vulkan device to create the resources on. + /// @param pool The descriptor pool to use for descriptor sets. + /// @param inImgs1 The first set of input images to process. + /// @param inImg2 The second type image to process. + /// @param inImg3 The third type image to process. + /// + /// @throws ls::vulkan_error if resource creation fails. + /// + Zeta(const Device& device, const Core::DescriptorPool& pool, + const std::vector& inImgs1, + const Core::Image& inImg2, + const Core::Image& inImg3); + + /// + /// Dispatch the shaderchain. + /// + /// @param buf The command buffer to use for dispatching. + /// + /// @throws std::logic_error if the command buffer is not recording. + /// + void Dispatch(const Core::CommandBuffer& buf); + + /// Get the output image. + [[nodiscard]] const auto& getOutImage() const { return this->outImg; } + + /// Trivially copyable, moveable and destructible + Zeta(const Zeta&) noexcept = default; + Zeta& operator=(const Zeta&) noexcept = default; + Zeta(Zeta&&) noexcept = default; + Zeta& operator=(Zeta&&) noexcept = default; + ~Zeta() = default; + private: + std::vector shaderModules{4}; + std::vector pipelines{4}; + std::vector descriptorSets{4}; + Core::Buffer buffer; + + std::vector inImgs1{3}; + Core::Image inImg2; + Core::Image inImg3; + + std::vector tempImgs1{4}; + std::vector tempImgs2{4}; + + Core::Image outImg; + }; + +} + +#endif // ZETA_HPP