@@ -258,7 +258,9 @@ Anvil::GLSLShaderToSPIRVGenerator::GLSLShaderToSPIRVGenerator(const Anvil::BaseD
258258 m_glsl_source_code_dirty(true ),
259259 m_mode (in_mode),
260260 m_shader_stage (in_shader_stage),
261- m_spirv_version (in_spirv_version)
261+ m_spirv_version (in_spirv_version),
262+ m_glsl_file_path{},
263+ m_with_debug_info{false }
262264{
263265 #ifdef ANVIL_LINK_WITH_GLSLANG
264266 {
@@ -612,7 +614,7 @@ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob() const
612614 if (m_spirv_blob.size () == 0 )
613615 {
614616 /* Need to bake a brand new SPIR-V blob */
615- result = bake_spirv_blob_by_calling_glslang (m_glsl_source_code.c_str () );
617+ result = bake_spirv_blob_by_calling_glslang (m_glsl_source_code.c_str (), m_glsl_file_path, m_with_debug_info );
616618 }
617619 }
618620
@@ -639,7 +641,7 @@ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob() const
639641 *
640642 * @return true if successful, false otherwise.
641643 **/
642- bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob_by_calling_glslang (const char * in_body) const
644+ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob_by_calling_glslang (const char * in_body, const std::optional<std::string> &glslFilePath, bool withDebugInfo ) const
643645 {
644646 const EShLanguage glslang_shader_stage = get_glslang_shader_stage ();
645647 glslang::TIntermediate* intermediate_ptr = nullptr ;
@@ -669,8 +671,14 @@ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob() const
669671 glslang::EShTargetLanguageVersion spirv_version;
670672
671673 /* Try to compile the shader */
672- new_shader_ptr->setStrings (&in_body,
673- 1 );
674+ const char *path = nullptr ;
675+ int numNames = 0 ;
676+ if (glslFilePath) {
677+ path = glslFilePath->c_str ();
678+ numNames = 1 ;
679+ }
680+ int length = strlen (in_body);
681+ new_shader_ptr->setStringsWithLengthsAndNames (&in_body, &length, &path, numNames);
674682
675683 switch (m_spirv_version)
676684 {
@@ -723,7 +731,7 @@ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob() const
723731 result = new_shader_ptr->parse (m_limits_ptr->get_resource_ptr (),
724732 110 , /* defaultVersion */
725733 false , /* forwardCompatible */
726- (EShMessages) (EShMsgDefault | EShMsgSpvRules | EShMsgVulkanRules) );
734+ (EShMessages) (EShMsgDefault | EShMsgSpvRules | EShMsgVulkanRules | EShMsgDebugInfo ) );
727735
728736 m_debug_info_log = new_shader_ptr->getInfoDebugLog ();
729737 m_shader_info_log = new_shader_ptr->getInfoLog ();
@@ -765,8 +773,13 @@ bool Anvil::GLSLShaderToSPIRVGenerator::bake_spirv_blob() const
765773 goto end;
766774 }
767775
776+ glslang::SpvOptions options {};
777+ if (withDebugInfo) {
778+ options.generateDebugInfo = true ;
779+ options.stripDebugInfo = false ;
780+ }
768781 glslang::GlslangToSpv (*intermediate_ptr,
769- spirv_blob);
782+ spirv_blob, &options );
770783
771784 if (spirv_blob.size () == 0 )
772785 {
0 commit comments