mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
refactor: revert prev 3 commits
This commit is contained in:
parent
41c0083a04
commit
3c7c5a4413
10 changed files with 0 additions and 462 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -32,31 +31,4 @@ namespace VK {
|
|||
VkResult result;
|
||||
};
|
||||
|
||||
/// Simple exception class for stacking errors.
|
||||
class rethrowable_error : public std::runtime_error {
|
||||
public:
|
||||
///
|
||||
/// Construct a new rethrowable_error with a message.
|
||||
///
|
||||
/// @param message The error message.
|
||||
/// @param exe The original exception to rethrow.
|
||||
///
|
||||
explicit rethrowable_error(const std::string& message,
|
||||
const std::exception& exe);
|
||||
|
||||
/// Get the exception as a string.
|
||||
[[nodiscard]] const char* what() const noexcept override {
|
||||
return message.c_str();
|
||||
}
|
||||
|
||||
// Trivially copyable, moveable and destructible
|
||||
rethrowable_error(const rethrowable_error&) = default;
|
||||
rethrowable_error(rethrowable_error&&) = default;
|
||||
rethrowable_error& operator=(const rethrowable_error&) = default;
|
||||
rethrowable_error& operator=(rethrowable_error&&) = default;
|
||||
~rethrowable_error() noexcept override;
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "vk/core/device.hpp"
|
||||
#include "vk/core/image.hpp"
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace VK::Helper {
|
||||
|
||||
///
|
||||
/// Helper class for a list of images with similar properties.
|
||||
///
|
||||
class ImageGroup {
|
||||
public:
|
||||
ImageGroup() noexcept = default;
|
||||
|
||||
///
|
||||
/// Create an image group.
|
||||
///
|
||||
/// @param device Vulkan device.
|
||||
/// @param extent Extent of the base level.
|
||||
/// @param count Number of images (must be at least 1).
|
||||
/// @param format Image format.
|
||||
///
|
||||
/// @throws VK::vulkan_error if object creation fails.
|
||||
///
|
||||
ImageGroup(const Core::Device& device, VkExtent2D extent,
|
||||
size_t count, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM);
|
||||
|
||||
/// Get the number of images
|
||||
[[nodiscard]] auto count() const noexcept { return this->images.size(); }
|
||||
/// Get a specific image.
|
||||
[[nodiscard]] const auto& get(size_t i) const { return this->images.at(i); }
|
||||
/// Get all images.
|
||||
[[nodiscard]] const auto& into() const noexcept { return this->images; }
|
||||
|
||||
/// Get a subgroup of images
|
||||
[[nodiscard]] std::vector<Core::Image> subGroup(size_t start, size_t length) const {
|
||||
if (start + length > this->count())
|
||||
throw std::out_of_range("Sub group range out of bounds");
|
||||
|
||||
std::vector<Core::Image> subgroup(length);
|
||||
std::copy_n(&this->images.at(start), length, subgroup.data());
|
||||
return subgroup;
|
||||
}
|
||||
private:
|
||||
std::vector<Core::Image> images;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "vk/core/device.hpp"
|
||||
#include "vk/core/image.hpp"
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace VK::Helper {
|
||||
|
||||
///
|
||||
/// Helper class for a list of mipmapped images.
|
||||
///
|
||||
class MipmappedImage {
|
||||
public:
|
||||
MipmappedImage() noexcept = default;
|
||||
|
||||
///
|
||||
/// Create a mipmappped image.
|
||||
///
|
||||
/// @param device Vulkan device.
|
||||
/// @param extent Extent of the base level.
|
||||
/// @param levels Number of mip levels (must be at least 1).
|
||||
/// @param format Image format.
|
||||
///
|
||||
/// @throws VK::vulkan_error if object creation fails.
|
||||
///
|
||||
MipmappedImage(const Core::Device& device, VkExtent2D extent,
|
||||
size_t levels, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM);
|
||||
|
||||
/// Get the number of mip levels.
|
||||
[[nodiscard]] auto levels() const noexcept { return this->images.size(); }
|
||||
/// Get a specific mip level image.
|
||||
[[nodiscard]] const auto& get(size_t i) const { return this->images.at(i); }
|
||||
/// Get all mip level images.
|
||||
[[nodiscard]] const auto& into() const noexcept { return this->images; }
|
||||
private:
|
||||
std::vector<Core::Image> images;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "vk/helper/mipmapped_image.hpp"
|
||||
#include "vk/helper/temporal_image.hpp"
|
||||
#include "vk/helper/image_group.hpp"
|
||||
#include "vk/core/descriptorpool.hpp"
|
||||
#include "vk/core/descriptorset.hpp"
|
||||
#include "vk/core/shadermodule.hpp"
|
||||
#include "vk/core/sampler.hpp"
|
||||
#include "vk/core/buffer.hpp"
|
||||
#include "vk/core/image.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace VK::Helper {
|
||||
|
||||
///
|
||||
/// A list of descriptor sets across multiple frames.
|
||||
///
|
||||
class MultiSet {
|
||||
friend class MultiSetBuilder;
|
||||
public:
|
||||
MultiSet() noexcept = default;
|
||||
|
||||
/// Get the amount of descriptor sets.
|
||||
[[nodiscard]] auto size() const noexcept { return this->sets.size(); }
|
||||
/// Get all the descriptor sets.
|
||||
[[nodiscard]] const auto& all() const { return this->sets; }
|
||||
|
||||
/// Get the descriptor set for a specific frame index.
|
||||
[[nodiscard]] const auto& getSetAt(size_t index) const {
|
||||
return this->set(index).sets;
|
||||
}
|
||||
/// Get the sampled images for a specific frame index.
|
||||
[[nodiscard]] const auto& getSampledImagesAt(size_t index) const {
|
||||
return this->set(index).sampled;
|
||||
}
|
||||
/// Get the storage images for a specific frame index.
|
||||
[[nodiscard]] const auto& getStorageImagesAt(size_t index) const {
|
||||
return this->set(index).storage;
|
||||
}
|
||||
private:
|
||||
struct Set {
|
||||
Core::DescriptorSet sets;
|
||||
std::vector<std::optional<Core::Image>> sampled;
|
||||
std::vector<Core::Image> storage;
|
||||
};
|
||||
std::vector<Set> sets;
|
||||
|
||||
/// Get the set at a specific index.
|
||||
[[nodiscard]] const Set& set(size_t index) const {
|
||||
return this->sets.at(index % this->sets.size());
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
/// Builder class for a shader descriptors across multiple frames.
|
||||
///
|
||||
class MultiSetBuilder {
|
||||
public:
|
||||
MultiSetBuilder() noexcept = default;
|
||||
|
||||
///
|
||||
/// Create a new descriptor builder.
|
||||
///
|
||||
/// @param count Amount of sets to create.
|
||||
///
|
||||
MultiSetBuilder(size_t count) noexcept : recipes(count) {}
|
||||
|
||||
/// Add a buffer to the descriptor.
|
||||
MultiSetBuilder& withBuffer(const Core::Buffer& buffer) {
|
||||
this->buffer = buffer;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a sampler to the descriptor.
|
||||
MultiSetBuilder& withSampler(const Core::Sampler& sampler) {
|
||||
this->samplers = { sampler };
|
||||
return *this;
|
||||
}
|
||||
/// Add two samplers to the descriptor.
|
||||
MultiSetBuilder& withSamplers(
|
||||
const Core::Sampler& sampler1, const Core::Sampler& sampler2) {
|
||||
this->samplers = { sampler1, sampler2 };
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a sampled image to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const Core::Image& image) {
|
||||
for (auto& recipe : this->recipes)
|
||||
recipe.sampled.emplace_back(image);
|
||||
return *this;
|
||||
}
|
||||
/// Add an optional sampled image to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const std::optional<Core::Image>& image) {
|
||||
for (auto& recipe : this->recipes)
|
||||
recipe.sampled.emplace_back(image);
|
||||
return *this;
|
||||
}
|
||||
/// Add multiple sampled images to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const std::vector<Core::Image>& images) {
|
||||
for (auto& recipe : this->recipes)
|
||||
for (const auto& img : images)
|
||||
recipe.sampled.emplace_back(img);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a temporal sampled image to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const TemporalImage& temporalImage, size_t offset = 0) {
|
||||
for (auto& recipe : this->recipes)
|
||||
recipe.sampled.emplace_back(temporalImage.at(offset++));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a group of sampled images to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const ImageGroup& imageGroup) {
|
||||
this->addSampledImage(imageGroup.into());
|
||||
return *this;
|
||||
}
|
||||
/// Add a subgroup of sampled images to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const ImageGroup& imageGroup, size_t start, size_t length) {
|
||||
this->addSampledImage(imageGroup.subGroup(start, length));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add all mipmapped images to the descriptor.
|
||||
MultiSetBuilder& addSampledImage(const Helper::MipmappedImage& mipmappedImage) {
|
||||
this->addSampledImage(mipmappedImage.into());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a storage image to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const Core::Image& image) {
|
||||
for (auto& recipe : this->recipes)
|
||||
recipe.storage.push_back(image);
|
||||
return *this;
|
||||
}
|
||||
/// Add multiple storage images to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const std::vector<Core::Image>& images) {
|
||||
for (auto& recipe : this->recipes)
|
||||
for (const auto& img : images)
|
||||
recipe.storage.push_back(img);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a temporal storage image to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const TemporalImage& temporalImage, size_t offset = 0) {
|
||||
for (auto& recipe : this->recipes)
|
||||
recipe.storage.push_back(temporalImage.at(offset++));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add a group of storage images to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const ImageGroup& imageGroup) {
|
||||
this->addStorageImage(imageGroup.into());
|
||||
return *this;
|
||||
}
|
||||
/// Add a subgroup of storage images to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const ImageGroup& imageGroup, size_t start, size_t length) {
|
||||
this->addStorageImage(imageGroup.subGroup(start, length));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Add all mipmapped images to the descriptor.
|
||||
MultiSetBuilder& addStorageImage(const Helper::MipmappedImage& mipmappedImage) {
|
||||
this->addStorageImage(mipmappedImage.into());
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
/// Build the descriptor sets.
|
||||
///
|
||||
/// @param device The Vulkan device.
|
||||
/// @param descriptorPool The descriptor pool to allocate from.
|
||||
/// @param shaderModule The shader module this descriptor is for.
|
||||
/// @return The built descriptor sets.
|
||||
///
|
||||
[[nodiscard]] MultiSet build(
|
||||
const Core::Device& device,
|
||||
const Core::DescriptorPool& descriptorPool,
|
||||
const Core::ShaderModule& shaderModule) const;
|
||||
|
||||
private:
|
||||
std::optional<Core::Buffer> buffer;
|
||||
std::vector<Core::Sampler> samplers;
|
||||
struct SetRecipe {
|
||||
std::vector<std::optional<Core::Image>> sampled;
|
||||
std::vector<Core::Image> storage;
|
||||
};
|
||||
std::vector<SetRecipe> recipes;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "vk/core/device.hpp"
|
||||
#include "vk/core/image.hpp"
|
||||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace VK::Helper {
|
||||
|
||||
///
|
||||
/// Helper class for a list of temporal images.
|
||||
///
|
||||
class TemporalImage {
|
||||
public:
|
||||
TemporalImage() noexcept = default;
|
||||
|
||||
///
|
||||
/// Create a temporal image.
|
||||
///
|
||||
/// @param device Vulkan device.
|
||||
/// @param extent Extent of the images.
|
||||
/// @param count Amount of images (must be at least 1).
|
||||
/// @param format Image format.
|
||||
///
|
||||
/// @throws VK::vulkan_error if object creation fails.
|
||||
///
|
||||
TemporalImage(const Core::Device& device, VkExtent2D extent,
|
||||
size_t count, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM);
|
||||
|
||||
///
|
||||
/// Create a temporal image based on existing images.
|
||||
///
|
||||
/// @param images Vector of existing images.
|
||||
///
|
||||
TemporalImage(std::vector<Core::Image> images)
|
||||
: images(std::move(images)) {}
|
||||
|
||||
/// Get the number of images.
|
||||
[[nodiscard]] auto count() const noexcept { return this->images.size(); }
|
||||
/// Get a specific image.
|
||||
[[nodiscard]] const auto& get(size_t i) const { return this->images.at(i); }
|
||||
/// Get the image based on frame index.
|
||||
[[nodiscard]] const auto& at(size_t f) const { return this->images.at(f % this->count()); }
|
||||
/// Get all images.
|
||||
[[nodiscard]] const auto& into() const noexcept { return this->images; }
|
||||
private:
|
||||
std::vector<Core::Image> images;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
|
|
@ -15,10 +14,3 @@ vulkan_error::vulkan_error(VkResult result, const std::string& message)
|
|||
result(result) {}
|
||||
|
||||
vulkan_error::~vulkan_error() noexcept = default;
|
||||
|
||||
rethrowable_error::rethrowable_error(const std::string& message, const std::exception& exe)
|
||||
: std::runtime_error(message) {
|
||||
this->message = std::format("{}\n- {}", message, exe.what());
|
||||
}
|
||||
|
||||
rethrowable_error::~rethrowable_error() noexcept = default;
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
#include <volk.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include "vk/helper/image_group.hpp"
|
||||
#include "vk/core/device.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
using namespace VK::Helper;
|
||||
|
||||
ImageGroup::ImageGroup(const Core::Device& device, VkExtent2D extent,
|
||||
size_t count, VkFormat format) {
|
||||
this->images.reserve(count);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
this->images.emplace_back(device, extent, format);
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#include <volk.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include "vk/helper/mipmapped_image.hpp"
|
||||
#include "vk/core/device.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
using namespace VK::Helper;
|
||||
|
||||
MipmappedImage::MipmappedImage(const Core::Device& device, VkExtent2D extent,
|
||||
size_t levels, VkFormat format) {
|
||||
this->images.reserve(levels);
|
||||
for (size_t i = 0; i < levels; i++)
|
||||
this->images.emplace_back(
|
||||
device,
|
||||
VkExtent2D { extent.width >> i, extent.height >> i },
|
||||
format
|
||||
);
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#include "vk/helper/multiset.hpp"
|
||||
#include "vk/core/descriptorpool.hpp"
|
||||
#include "vk/core/shadermodule.hpp"
|
||||
#include "vk/core/device.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace VK::Helper;
|
||||
|
||||
MultiSet MultiSetBuilder::build(
|
||||
const Core::Device& device,
|
||||
const Core::DescriptorPool& pool,
|
||||
const Core::ShaderModule& shader) const {
|
||||
MultiSet multiset{};
|
||||
multiset.sets.reserve(this->recipes.size());
|
||||
|
||||
for (const auto& recipe : this->recipes)
|
||||
multiset.sets.push_back({
|
||||
.sets = Core::DescriptorSet(device, pool, shader,
|
||||
recipe.sampled, recipe.storage, this->samplers, this->buffer),
|
||||
.sampled = recipe.sampled,
|
||||
.storage = recipe.storage
|
||||
});
|
||||
|
||||
return multiset;
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#include <volk.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include "vk/helper/temporal_image.hpp"
|
||||
#include "vk/core/device.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
using namespace VK::Helper;
|
||||
|
||||
TemporalImage::TemporalImage(const Core::Device& device, VkExtent2D extent,
|
||||
size_t count, VkFormat format) {
|
||||
this->images.reserve(count);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
this->images.emplace_back(device, extent, format);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue