MayaFlux 0.1.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 122 of file VKShaderModule.cpp.

128{
129 if (spirv_code.empty()) {
131 "Cannot create shader module from empty SPIR-V code");
132 return false;
133 }
134
135 // if (spirv_code.size() % 4 != 0) {
136 // MF_ERROR(Journal::Component::Core, Journal::Context::GraphicsBackend,
137 // "Invalid SPIR-V code size: {} bytes (must be multiple of 4)",
138 // spirv_code.size());
139 // return false;
140 // }
141
142 if (spirv_code[0] != 0x07230203) {
144 "Invalid SPIR-V magic number: 0x{:08X} (expected 0x07230203)",
145 spirv_code[0]);
146 return false;
147 }
148
149 vk::ShaderModuleCreateInfo create_info;
150 create_info.codeSize = spirv_code.size() * sizeof(uint32_t);
151 create_info.pCode = spirv_code.data();
152
153 try {
154 m_module = device.createShaderModule(create_info);
155 } catch (const vk::SystemError& e) {
157 "Failed to create shader module: {}", e.what());
158 return false;
159 }
160
161 m_stage = stage;
162 m_entry_point = entry_point;
163
164 if (m_preserve_spirv) {
165 m_spirv_code = spirv_code;
166 }
167
168 if (enable_reflection) {
169 if (!reflect_spirv(spirv_code)) {
171 "Shader reflection failed - descriptor layouts must be manually specified");
172 }
173 }
174
176 "Shader module created ({} stage, {} bytes SPIR-V, entry='{}')",
177 vk::to_string(stage), spirv_code.size() * 4, entry_point);
178
179 return true;
180}
#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: