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

◆ create_from_spirv_asm()

bool MayaFlux::Core::VKShaderModule::create_from_spirv_asm ( vk::Device  device,
const std::string &  spirv_asm,
vk::ShaderStageFlagBits  stage,
const std::string &  entry_point = "main",
bool  enable_reflection = true 
)

Create shader module from SPIR-V assembly text.

Assembles human-readable SPIR-V opcodes to binary via spvTextToBinary targeting Vulkan 1.3, then delegates to create_from_spirv(). Does not require shaderc or any GLSL toolchain.

Parameters
deviceLogical device.
spirv_asmSPIR-V assembly text.
stageShader stage.
entry_pointEntry point function name (default: "main").
enable_reflectionExtract descriptor bindings and resources.
Returns
true if assembly and module creation succeeded.

Definition at line 289 of file VKShaderModule.cpp.

295{
296 spv_context ctx = spvContextCreate(SPV_ENV_VULKAN_1_3);
297 spv_binary binary = nullptr;
298 spv_diagnostic diag = nullptr;
299
300 const spv_result_t result = spvTextToBinary(
301 ctx,
302 spirv_asm.c_str(),
303 spirv_asm.size(),
304 &binary,
305 &diag);
306
307 if (result != SPV_SUCCESS) {
309 "SPIR-V assembly failed: {}",
310 (diag && diag->error) ? diag->error : "unknown error");
311 spvDiagnosticDestroy(diag);
312 spvContextDestroy(ctx);
313 return false;
314 }
315
316 std::vector<uint32_t> words(binary->code, binary->code + binary->wordCount);
317
318 spvBinaryDestroy(binary);
319 spvDiagnosticDestroy(diag);
320
321 spv_const_binary_t bin { .code = words.data(), .wordCount = words.size() };
322 spv_diagnostic val_diag = nullptr;
323 const spv_result_t val = spvValidate(ctx, &bin, &val_diag);
324 if (val != SPV_SUCCESS) {
326 "SPIR-V validation failed: {}",
327 (val_diag && val_diag->error) ? val_diag->error : "unknown");
328 spvDiagnosticDestroy(val_diag);
329 spvContextDestroy(ctx);
330 return false;
331 }
332 spvDiagnosticDestroy(val_diag);
333 spvContextDestroy(ctx);
334
336 "Assembled and validated SPIR-V ({} words)", words.size());
337
338 return create_from_spirv(device, words, stage, entry_point, enable_reflection);
339}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
bool 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.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, create_from_spirv(), MayaFlux::Journal::GraphicsBackend, MF_DEBUG, and MF_ERROR.

+ Here is the call graph for this function: