159 bool create_from_spirv(
161 const
std::vector<uint32_t>& spirv_code,
162 vk::ShaderStageFlagBits stage,
163 const
std::
string& entry_point = "
main",
164 bool enable_reflection = true);
177 bool create_from_spirv_file(
179 const
std::
string& spirv_path,
180 vk::ShaderStageFlagBits stage,
181 const
std::
string& entry_point = "
main",
182 bool enable_reflection = true);
198 bool create_from_glsl(
200 const
std::
string& glsl_source,
201 vk::ShaderStageFlagBits stage,
202 const
std::
string& entry_point = "
main",
203 bool enable_reflection = true,
204 const
std::vector<
std::
string>& include_directories = {},
205 const std::unordered_map<std::string, std::string>& defines = {});
227 bool create_from_glsl_file(
229 const std::string& glsl_path,
230 std::optional<vk::ShaderStageFlagBits> stage = std::nullopt,
231 const std::string& entry_point =
"main",
232 bool enable_reflection =
true,
233 const std::vector<std::string>& include_directories = {},
234 const std::unordered_map<std::string, std::string>& defines = {});
243 void cleanup(vk::Device device);
249 [[nodiscard]]
bool is_valid()
const {
return m_module !=
nullptr; }
255 [[nodiscard]] vk::ShaderModule
get()
const {
return m_module; }
261 [[nodiscard]] vk::ShaderStageFlagBits
get_stage()
const {
return m_stage; }
278 [[nodiscard]] vk::PipelineShaderStageCreateInfo get_stage_create_info()
const;
296 [[nodiscard]]
const std::vector<uint32_t>&
get_spirv()
const {
return m_spirv_code; }
311 void set_specialization_constants(
const std::unordered_map<uint32_t, uint32_t>& constants);
325 [[nodiscard]]
Stage get_stage_type()
const;
333 return m_vertex_input;
341 return !m_vertex_input.attributes.empty();
350 return m_fragment_output;
359 return m_push_constants;
369 return m_reflection.workgroup_size;
377 static std::optional<vk::ShaderStageFlagBits> detect_stage_from_extension(
const std::string& filepath);
380 vk::ShaderModule m_module =
nullptr;
381 vk::ShaderStageFlagBits m_stage = vk::ShaderStageFlagBits::eCompute;
382 std::string m_entry_point =
"main";
387 bool m_preserve_spirv {};
406 bool reflect_spirv(
const std::vector<uint32_t>& spirv_code);
416 std::vector<uint32_t> compile_glsl_to_spirv(
417 const std::string& glsl_source,
418 vk::ShaderStageFlagBits stage,
419 const std::vector<std::string>& include_directories,
420 const std::unordered_map<std::string, std::string>& defines);
427 static std::vector<uint32_t> read_spirv_file(
const std::string& filepath);
434 static std::string read_text_file(
const std::string& filepath);
436#ifndef MAYAFLUX_USE_SHADERC
444 static std::vector<uint32_t> compile_glsl_to_spirv_external(
445 const std::string& glsl_source,
446 vk::ShaderStageFlagBits stage,
447 const std::vector<std::string>& include_directories = {},
448 const std::unordered_map<std::string, std::string>& defines = {});
455 void update_specialization_info();
462 static vk::Format spirv_type_to_vk_format(
const spirv_cross::SPIRType& type);