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

330{
331 spv_context ctx = spvContextCreate(SPV_ENV_VULKAN_1_3);
332 spv_binary binary = nullptr;
333 spv_diagnostic diag = nullptr;
334
335 const spv_result_t result = spvTextToBinary(
336 ctx,
337 spirv_asm.c_str(),
338 spirv_asm.size(),
339 &binary,
340 &diag);
341
342 if (result != SPV_SUCCESS) {
344 "SPIR-V assembly failed: {}",
345 (diag && diag->error) ? diag->error : "unknown error");
346 spvDiagnosticDestroy(diag);
347 spvContextDestroy(ctx);
348 return false;
349 }
350
351 std::vector<uint32_t> words(binary->code, binary->code + binary->wordCount);
352
353 spvBinaryDestroy(binary);
354 spvDiagnosticDestroy(diag);
355
356 spv_const_binary_t bin { .code = words.data(), .wordCount = words.size() };
357 spv_diagnostic val_diag = nullptr;
358 const spv_result_t val = spvValidate(ctx, &bin, &val_diag);
359 if (val != SPV_SUCCESS) {
361 "SPIR-V validation failed: {}",
362 (val_diag && val_diag->error) ? val_diag->error : "unknown");
363 spvDiagnosticDestroy(val_diag);
364 spvContextDestroy(ctx);
365 return false;
366 }
367 spvDiagnosticDestroy(val_diag);
368 spvContextDestroy(ctx);
369
371 "Assembled and validated SPIR-V ({} words)", words.size());
372
373 return create_from_spirv(device, words, stage, entry_point, enable_reflection);
374}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
vk::PhysicalDevice device
Definition VKDevice.cpp:121
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(), device, MayaFlux::Journal::GraphicsBackend, MF_DEBUG, and MF_ERROR.

+ Here is the call graph for this function: