Files
rogue/source/render/shader_compiler.hpp
2026-04-17 00:22:27 -03:00

57 lines
1.6 KiB
C++

#ifndef SHADER_COMPILER_HPP
#define SHADER_COMPILER_HPP
#include <filesystem>
#include <string_view>
#include <vector>
#include <slang.h>
namespace rog::render {
class shader_compiler {
public:
explicit shader_compiler(std::filesystem::path root);
[[nodiscard]] std::vector<std::uint32_t>
compile(const std::string_view module_name,
const std::string_view entry_name = "main");
void reload_session();
private:
static void destroy_slang(ISlangUnknown *object);
template <typename T>
using slang_unique_ptr = std::unique_ptr<T, decltype(&destroy_slang)>;
std::filesystem::path root;
slang_unique_ptr<slang::IGlobalSession> global_session = {nullptr,
destroy_slang};
slang_unique_ptr<slang::ISession> session = {nullptr, destroy_slang};
std::vector<std::filesystem::path> search_paths = {"assets/shaders"};
[[nodiscard]] slang::IModule *load_module(const std::string_view module_name);
[[nodiscard]] slang::IEntryPoint *
find_entry_point(slang::IModule *module,
const std::string_view entry_point_name);
[[nodiscard]] slang_unique_ptr<slang::IComponentType>
create_composed_program(slang::IModule *module,
slang::IEntryPoint *entry_point);
[[nodiscard]] slang_unique_ptr<slang::IBlob>
compile_to_spirv(slang::IComponentType *composed_program);
[[noreturn]] void throw_error(const std::string_view context,
slang::IBlob *diagnostic_blob);
[[noreturn]] void throw_error(const std::string_view context);
};
} // namespace rog::render
#endif