Files
OpenVulkano/openVulkanoCpp/Shader/ShaderCompiler.hpp
Metehan Tuncbilek ac1c5f20ec review fixes
2024-07-16 14:59:09 +03:00

49 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
{
struct IncludeData
{
shaderc_include_result result = {};
std::string m_fullPath;
Array<char> m_content;
};
public:
ShaderIncluder(const std::string& path);
~ShaderIncluder() override = default;
shaderc_include_result* GetInclude(const char* requestedSource, shaderc_include_type type,
const char* requestingSource, uint64_t includeDepth) override;
void ReleaseInclude(shaderc_include_result* data) override;
private:
std::string ResolveInclude(const std::string& requestedSource) const;
private:
std::string m_includePath;
};
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);
};
}