mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
91 lines
3 KiB
C++
91 lines
3 KiB
C++
#pragma once
|
|
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
#include <functional>
|
|
#include <stdexcept>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace LSFG {
|
|
|
|
///
|
|
/// Initialize the LSFG library.
|
|
///
|
|
/// @param deviceUUID The UUID of the Vulkan device to use.
|
|
/// @param isHdr Whether the images are in HDR format.
|
|
/// @param flowScale Internal flow scale factor.
|
|
/// @param generationCount Number of frames to generate.
|
|
/// @param loader Function to load shader source code by name.
|
|
///
|
|
/// @throws LSFG::vulkan_error if Vulkan objects fail to initialize.
|
|
///
|
|
void initialize(uint64_t deviceUUID,
|
|
bool isHdr, float flowScale, uint64_t generationCount,
|
|
const std::function<std::vector<uint8_t>(const std::string&)>& loader);
|
|
|
|
///
|
|
/// Create a new LSFG context on a swapchain.
|
|
///
|
|
/// @param in0 File descriptor for the first input image.
|
|
/// @param in1 File descriptor for the second input image.
|
|
/// @param outN File descriptor for each output image. This defines the LSFG level.
|
|
/// @param extent The size of the images
|
|
/// @param format The format of the images.
|
|
/// @return A unique identifier for the created context.
|
|
///
|
|
/// @throws LSFG::vulkan_error if the context cannot be created.
|
|
///
|
|
int32_t createContext(
|
|
int in0, int in1, const std::vector<int>& outN,
|
|
VkExtent2D extent, VkFormat format);
|
|
|
|
///
|
|
/// Present a context.
|
|
///
|
|
/// @param id Unique identifier of the context to present.
|
|
/// @param inSem Semaphore to wait on before starting the generation.
|
|
/// @param outSem Semaphores to signal once each output image is ready.
|
|
///
|
|
/// @throws LSFG::vulkan_error if the context cannot be presented.
|
|
///
|
|
void presentContext(int32_t id, int inSem, const std::vector<int>& outSem);
|
|
|
|
///
|
|
/// Delete an LSFG context.
|
|
///
|
|
/// @param id Unique identifier of the context to delete.
|
|
///
|
|
void deleteContext(int32_t id);
|
|
|
|
///
|
|
/// Deinitialize the LSFG library.
|
|
///
|
|
void finalize();
|
|
|
|
/// Simple exception class for Vulkan errors.
|
|
class vulkan_error : public std::runtime_error {
|
|
public:
|
|
///
|
|
/// Construct a vulkan_error with a message and a Vulkan result code.
|
|
///
|
|
/// @param result The Vulkan result code associated with the error.
|
|
/// @param message The error message.
|
|
///
|
|
explicit vulkan_error(VkResult result, const std::string& message);
|
|
|
|
/// Get the Vulkan result code associated with this error.
|
|
[[nodiscard]] VkResult error() const { return this->result; }
|
|
|
|
// Trivially copyable, moveable and destructible
|
|
vulkan_error(const vulkan_error&) = default;
|
|
vulkan_error(vulkan_error&&) = default;
|
|
vulkan_error& operator=(const vulkan_error&) = default;
|
|
vulkan_error& operator=(vulkan_error&&) = default;
|
|
~vulkan_error() noexcept override;
|
|
private:
|
|
VkResult result;
|
|
};
|
|
|
|
}
|