157 bool create_from_spirv(
159 const
std::vector<uint32_t>& spirv_code,
160 vk::ShaderStageFlagBits stage,
161 const
std::
string& entry_point = "
main",
162 bool enable_reflection = true);
175 bool create_from_spirv_file(
177 const
std::
string& spirv_path,
178 vk::ShaderStageFlagBits stage,
179 const
std::
string& entry_point = "
main",
180 bool enable_reflection = true);
196 bool create_from_glsl(
198 const
std::
string& glsl_source,
199 vk::ShaderStageFlagBits stage,
200 const
std::
string& entry_point = "
main",
201 bool enable_reflection = true,
202 const
std::vector<
std::
string>& include_directories = {},
203 const std::unordered_map<std::string, std::string>& defines = {});
225 bool create_from_glsl_file(
227 const std::string& glsl_path,
228 std::optional<vk::ShaderStageFlagBits> stage = std::nullopt,
229 const std::string& entry_point =
"main",
230 bool enable_reflection =
true,
231 const std::vector<std::string>& include_directories = {},
232 const std::unordered_map<std::string, std::string>& defines = {});
241 void cleanup(vk::Device device);
247 [[nodiscard]]
bool is_valid()
const {
return m_module !=
nullptr; }
253 [[nodiscard]] vk::ShaderModule
get()
const {
return m_module; }
259 [[nodiscard]] vk::ShaderStageFlagBits
get_stage()
const {
return m_stage; }
276 [[nodiscard]] vk::PipelineShaderStageCreateInfo get_stage_create_info()
const;
294 [[nodiscard]]
const std::vector<uint32_t>&
get_spirv()
const {
return m_spirv_code; }
309 void set_specialization_constants(
const std::unordered_map<uint32_t, uint32_t>& constants);
323 [[nodiscard]]
Stage get_stage_type()
const;
331 return m_vertex_input;
339 return !m_vertex_input.attributes.empty();
348 return m_fragment_output;
357 return m_push_constants;
367 return m_reflection.workgroup_size;
375 static std::optional<vk::ShaderStageFlagBits> detect_stage_from_extension(
const std::string& filepath);
378 vk::ShaderModule m_module =
nullptr;
379 vk::ShaderStageFlagBits m_stage = vk::ShaderStageFlagBits::eCompute;
380 std::string m_entry_point =
"main";
385 bool m_preserve_spirv {};
404 bool reflect_spirv(
const std::vector<uint32_t>& spirv_code);
414 std::vector<uint32_t> compile_glsl_to_spirv(
415 const std::string& glsl_source,
416 vk::ShaderStageFlagBits stage,
417 const std::vector<std::string>& include_directories,
418 const std::unordered_map<std::string, std::string>& defines);
425 static std::vector<uint32_t> read_spirv_file(
const std::string& filepath);
432 static std::string read_text_file(
const std::string& filepath);
434#ifndef MAYAFLUX_USE_SHADERC
442 static std::vector<uint32_t> compile_glsl_to_spirv_external(
443 const std::string& glsl_source,
444 vk::ShaderStageFlagBits stage,
445 const std::vector<std::string>& include_directories = {},
446 const std::unordered_map<std::string, std::string>& defines = {});
453 void update_specialization_info();
460 static vk::Format spirv_type_to_vk_format(
const spirv_cross::SPIRType& type);