MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_from_spirv()

bool MayaFlux::Core::VKShaderModule::create_from_spirv ( vk::Device  device,
const std::vector< uint32_t > &  spirv_code,
vk::ShaderStageFlagBits  stage,
const std::string &  entry_point = "main",
bool  enable_reflection = true 
)

Create shader module from SPIR-V binary.

Parameters
deviceLogical device
spirv_codeSPIR-V bytecode (must be aligned to uint32_t)
stageShader stage (compute, vertex, fragment, etc.)
entry_pointEntry point function name (default: "main")
enable_reflectionExtract descriptor bindings and resources
Returns
true if creation succeeded

This is the lowest-level creation method. All other create methods eventually funnel through this one.

Definition at line 215 of file VKShaderModule.cpp.

221{
222 if (spirv_code.empty()) {
224 "Cannot create shader module from empty SPIR-V code");
225 return false;
226 }
227
228 if (spirv_code[0] != 0x07230203) {
230 "Invalid SPIR-V magic number: 0x{:08X} (expected 0x07230203)",
231 spirv_code[0]);
232 return false;
233 }
234
235 vk::ShaderModuleCreateInfo create_info;
236 create_info.codeSize = spirv_code.size() * sizeof(uint32_t);
237 create_info.pCode = spirv_code.data();
238
239 try {
240 m_module = device.createShaderModule(create_info);
241 } catch (const vk::SystemError& e) {
243 "Failed to create shader module: {}", e.what());
244 return false;
245 }
246
247 m_stage = stage;
248 m_entry_point = entry_point;
249
250 if (m_preserve_spirv) {
251 m_spirv_code = spirv_code;
252 }
253
254 if (enable_reflection) {
255 if (!reflect_spirv(spirv_code)) {
257 "Shader reflection failed - descriptor layouts must be manually specified");
258 }
259 }
260
262 "Shader module created ({} stage, {} bytes SPIR-V, entry='{}')",
263 vk::to_string(stage), spirv_code.size() * 4, entry_point);
264
265 return true;
266}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
bool reflect_spirv(const std::vector< uint32_t > &spirv_code)
Perform reflection on SPIR-V bytecode.
vk::ShaderStageFlagBits m_stage
std::vector< uint32_t > m_spirv_code
Preserved SPIR-V (if enabled)
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Journal::GraphicsBackend, m_entry_point, m_module, m_preserve_spirv, m_spirv_code, m_stage, MF_ERROR, MF_INFO, MF_WARN, and reflect_spirv().

Referenced by create_from_glsl(), and create_from_spirv_file().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: