diff --git a/SPIRV/CInterface/spirv_c_interface.cpp b/SPIRV/CInterface/spirv_c_interface.cpp index a0790f48..d9312bbb 100644 --- a/SPIRV/CInterface/spirv_c_interface.cpp +++ b/SPIRV/CInterface/spirv_c_interface.cpp @@ -36,6 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SPIRV/Logger.h" #include "SPIRV/SpvTools.h" +static_assert(sizeof(glslang_spv_options_t) == sizeof(glslang::SpvOptions), ""); + typedef struct glslang_program_s { glslang::TProgram* program; std::vector spirv; @@ -81,13 +83,23 @@ static EShLanguage c_shader_stage(glslang_stage_t stage) GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage) { + glslang_spv_options_t spv_options; + spv_options.generate_debug_info = false; + spv_options.strip_debug_info = false; + spv_options.disable_optimizer = true; + spv_options.optimize_size = false; + spv_options.disassemble = false; + spv_options.validate = true; + + glslang_program_SPIRV_generate_with_options(program, stage, &spv_options); +} + +GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options) { spv::SpvBuildLogger logger; - glslang::SpvOptions spvOptions; - spvOptions.validate = true; const glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage)); - glslang::GlslangToSpv(*intermediate, program->spirv, &logger, &spvOptions); + glslang::GlslangToSpv(*intermediate, program->spirv, &logger, reinterpret_cast(spv_options)); program->loggerMessages = logger.getAllMessages(); } diff --git a/glslang/CInterface/glslang_c_interface.cpp b/glslang/CInterface/glslang_c_interface.cpp index 53892bc5..0e691a1f 100644 --- a/glslang/CInterface/glslang_c_interface.cpp +++ b/glslang/CInterface/glslang_c_interface.cpp @@ -38,6 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "glslang/Include/ResourceLimits.h" #include "glslang/MachineIndependent/Versions.h" +#include "glslang/MachineIndependent/localintermediate.h" static_assert(int(GLSLANG_STAGE_COUNT) == EShLangCount, ""); static_assert(int(GLSLANG_STAGE_MASK_COUNT) == EShLanguageMaskCount, ""); @@ -455,6 +456,16 @@ GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages return (int)program->program->link((EShMessages)messages); } +GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len) { + glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage)); + intermediate->addSourceText(text, len); +} + +GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file) { + glslang::TIntermediate* intermediate = program->program->getIntermediate(c_shader_stage(stage)); + intermediate->setSourceFile(file); +} + GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program) { return (int)program->program->mapIO(); diff --git a/glslang/Include/glslang_c_interface.h b/glslang/Include/glslang_c_interface.h index a98a7e17..9e5909ce 100644 --- a/glslang/Include/glslang_c_interface.h +++ b/glslang/Include/glslang_c_interface.h @@ -199,6 +199,16 @@ typedef struct glsl_include_callbacks_s { glsl_free_include_result_func free_include_result; } glsl_include_callbacks_t; +/* SpvOptions counterpart */ +typedef struct glslang_spv_options_s { + bool generate_debug_info; + bool strip_debug_info; + bool disable_optimizer; + bool optimize_size; + bool disassemble; + bool validate; +} glslang_spv_options_t; + #ifdef __cplusplus extern "C" { #endif @@ -238,8 +248,11 @@ GLSLANG_EXPORT glslang_program_t* glslang_program_create(); GLSLANG_EXPORT void glslang_program_delete(glslang_program_t* program); GLSLANG_EXPORT void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader); GLSLANG_EXPORT int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t +GLSLANG_EXPORT void glslang_program_add_source_text(glslang_program_t* program, glslang_stage_t stage, const char* text, size_t len); +GLSLANG_EXPORT void glslang_program_set_source_file(glslang_program_t* program, glslang_stage_t stage, const char* file); GLSLANG_EXPORT int glslang_program_map_io(glslang_program_t* program); GLSLANG_EXPORT void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage); +GLSLANG_EXPORT void glslang_program_SPIRV_generate_with_options(glslang_program_t* program, glslang_stage_t stage, glslang_spv_options_t* spv_options); GLSLANG_EXPORT size_t glslang_program_SPIRV_get_size(glslang_program_t* program); GLSLANG_EXPORT void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*); GLSLANG_EXPORT unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);