MayaFlux 1.0.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 249 of file VKShaderModule.cpp.

255{
256 if (spirv_code.empty()) {
258 "Cannot create shader module from empty SPIR-V code");
259 return false;
260 }
261
262 if (spirv_code[0] != 0x07230203) {
264 "Invalid SPIR-V magic number: 0x{:08X} (expected 0x07230203)",
265 spirv_code[0]);
266 return false;
267 }
268
269 vk::ShaderModuleCreateInfo create_info;
270 create_info.codeSize = spirv_code.size() * sizeof(uint32_t);
271 create_info.pCode = spirv_code.data();
272
273 try {
274 m_module = device.createShaderModule(create_info);
275 } catch (const vk::SystemError& e) {
277 "Failed to create shader module: {}", e.what());
278 return false;
279 }
280
281 m_stage = stage;
282 m_entry_point = entry_point;
283
284 if (m_preserve_spirv) {
285 m_spirv_code = spirv_code;
286 }
287
288 if (enable_reflection) {
289 if (!reflect_spirv(spirv_code)) {
291 "Shader reflection failed - descriptor layouts must be manually specified");
292 }
293 }
294
296 "Shader module created ({} stage, {} bytes SPIR-V, entry='{}')",
297 vk::to_string(stage), spirv_code.size() * 4, entry_point);
298
299 return true;
300}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
vk::PhysicalDevice device
Definition VKDevice.cpp:121
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, device, 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(), create_from_spirv_asm(), and create_from_spirv_file().

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