MayaFlux 0.5.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 214 of file VKShaderModule.cpp.

220{
221 if (spirv_code.empty()) {
223 "Cannot create shader module from empty SPIR-V code");
224 return false;
225 }
226
227 if (spirv_code[0] != 0x07230203) {
229 "Invalid SPIR-V magic number: 0x{:08X} (expected 0x07230203)",
230 spirv_code[0]);
231 return false;
232 }
233
234 vk::ShaderModuleCreateInfo create_info;
235 create_info.codeSize = spirv_code.size() * sizeof(uint32_t);
236 create_info.pCode = spirv_code.data();
237
238 try {
239 m_module = device.createShaderModule(create_info);
240 } catch (const vk::SystemError& e) {
242 "Failed to create shader module: {}", e.what());
243 return false;
244 }
245
246 m_stage = stage;
247 m_entry_point = entry_point;
248
249 if (m_preserve_spirv) {
250 m_spirv_code = spirv_code;
251 }
252
253 if (enable_reflection) {
254 if (!reflect_spirv(spirv_code)) {
256 "Shader reflection failed - descriptor layouts must be manually specified");
257 }
258 }
259
261 "Shader module created ({} stage, {} bytes SPIR-V, entry='{}')",
262 vk::to_string(stage), spirv_code.size() * 4, entry_point);
263
264 return true;
265}
#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(), 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: