MayaFlux 0.2.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 142 of file VKShaderModule.cpp.

148{
149 if (spirv_code.empty()) {
151 "Cannot create shader module from empty SPIR-V code");
152 return false;
153 }
154
155 if (spirv_code[0] != 0x07230203) {
157 "Invalid SPIR-V magic number: 0x{:08X} (expected 0x07230203)",
158 spirv_code[0]);
159 return false;
160 }
161
162 vk::ShaderModuleCreateInfo create_info;
163 create_info.codeSize = spirv_code.size() * sizeof(uint32_t);
164 create_info.pCode = spirv_code.data();
165
166 try {
167 m_module = device.createShaderModule(create_info);
168 } catch (const vk::SystemError& e) {
170 "Failed to create shader module: {}", e.what());
171 return false;
172 }
173
174 m_stage = stage;
175 m_entry_point = entry_point;
176
177 if (m_preserve_spirv) {
178 m_spirv_code = spirv_code;
179 }
180
181 if (enable_reflection) {
182 if (!reflect_spirv(spirv_code)) {
184 "Shader reflection failed - descriptor layouts must be manually specified");
185 }
186 }
187
189 "Shader module created ({} stage, {} bytes SPIR-V, entry='{}')",
190 vk::to_string(stage), spirv_code.size() * 4, entry_point);
191
192 return true;
193}
#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: