Files
OpenVulkano/openVulkanoCpp/Shader/ShaderCompiler.hpp
2024-07-15 17:31:02 +03:00

45 lines
1.5 KiB
C++

#pragma once
#include "Base/Utils.hpp"
#include "Base/Wrapper.hpp"
#include <spirv_cross/spirv_hlsl.hpp>
#include <spirv_cross/spirv_glsl.hpp>
#include <shaderc/shaderc.hpp>
namespace OpenVulkano
{
class ShaderIncluder : public shaderc::CompileOptions::IncluderInterface
{
public:
ShaderIncluder(const std::string& path);
~ShaderIncluder() override = default;
shaderc_include_result* GetInclude(const char* requested_source, shaderc_include_type type,
const char* requesting_source, uint64_t include_depth) override;
void ReleaseInclude(shaderc_include_result* data) override;
private:
std::string ResolveInclude(const std::string requestedSource);
const char* RecordInclude(const std::string& requestedSource);
const char* GetActualPath(const std::string& requestedSource);
private:
std::vector<std::string> m_includes;
};
class ShaderCompiler
{
public:
/**
* @param absPath - absolute path of the shader that needs to be compiled
* @param incPath - include path that will be used to resolve includes
* @param entryPoint - the name of the void function in the shader
* @param shaderStage - type of the shader that needs to be compiled
* @param bHaveIncludes - if incPath is empty, make it false
*/
static Unique<void*> CompileGLSLToSpirv(const std::string& absPath,
const std::string& incPath, const std::string& entryPoint,
shaderc_shader_kind shaderStage, bool bHaveIncludes);
};
}