diff --git a/spirv_cross_c.cpp b/spirv_cross_c.cpp index e48bfbfb..6a6dee0c 100644 --- a/spirv_cross_c.cpp +++ b/spirv_cross_c.cpp @@ -823,15 +823,15 @@ spvc_result spvc_compiler_require_extension(spvc_compiler compiler, const char * size_t spvc_compiler_get_num_required_extensions(spvc_compiler compiler) { #if SPIRV_CROSS_C_API_GLSL - if (compiler->backend == SPVC_BACKEND_NONE) + if (compiler->backend != SPVC_BACKEND_GLSL) { - compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + compiler->context->report_error("Enabled extensions can only be queried on GLSL backend."); return SPVC_ERROR_INVALID_ARGUMENT; } return static_cast(compiler->compiler.get())->get_required_extensions().size(); #else - compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + compiler->context->report_error("Enabled extensions can only be queried on GLSL backend."); return 0; #endif } @@ -839,20 +839,19 @@ size_t spvc_compiler_get_num_required_extensions(spvc_compiler compiler) const char *spvc_compiler_get_required_extension(spvc_compiler compiler, size_t index) { #if SPIRV_CROSS_C_API_GLSL - if (compiler->backend == SPVC_BACKEND_NONE) + if (compiler->backend != SPVC_BACKEND_GLSL) { - compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + compiler->context->report_error("Enabled extensions can only be queried on GLSL backend."); return nullptr; } - auto& exts = static_cast(compiler->compiler.get())->get_required_extensions(); - if (index < exts.size()) { + auto &exts = static_cast(compiler->compiler.get())->get_required_extensions(); + if (index < exts.size()) return exts[index].c_str(); - } else { + else return nullptr; - } #else - compiler->context->report_error("Cross-compilation related option used on NONE backend which only supports reflection."); + compiler->context->report_error("Enabled extensions can only be queried on GLSL backend."); return nullptr; #endif } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index c01b533f..281d4faa 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -15565,7 +15565,8 @@ void CompilerGLSL::require_extension(const std::string &ext) forced_extensions.push_back(ext); } -const SmallVector &CompilerGLSL::get_required_extensions() const { +const SmallVector &CompilerGLSL::get_required_extensions() const +{ return forced_extensions; } diff --git a/tests-other/c_api_test.c b/tests-other/c_api_test.c index e3fda2ef..81853e44 100644 --- a/tests-other/c_api_test.c +++ b/tests-other/c_api_test.c @@ -176,14 +176,16 @@ int main(int argc, char **argv) SPVC_CHECKED_CALL(spvc_compiler_create_compiler_options(compiler_glsl, &options)); SPVC_CHECKED_CALL(spvc_compiler_install_compiler_options(compiler_glsl, options)); - const int NUM_EXTS = 2; - const char* expected_exts[NUM_EXTS] = { + static const int NUM_EXTS = 2; + const char *expected_exts[NUM_EXTS] = + { "EXT_first", "EXT_second" }; int ext_idx = 0; - while(ext_idx < NUM_EXTS) { + while (ext_idx < NUM_EXTS) + { SPVC_CHECKED_CALL(spvc_compiler_require_extension(compiler_glsl, expected_exts[ext_idx])); ext_idx += 1; } @@ -204,9 +206,11 @@ int main(int argc, char **argv) } ext_idx = 0; - while(ext_idx < num_exts) { - const char* ext = spvc_compiler_get_required_extension(compiler_glsl, ext_idx); - if(strcmp(ext, expected_exts[ext_idx]) != 0) { + while (ext_idx < num_exts) + { + const char *ext = spvc_compiler_get_required_extension(compiler_glsl, ext_idx); + if (strcmp(ext, expected_exts[ext_idx]) != 0) + { fprintf(stderr, "extension mismatch (%s != %s)!\n", ext, expected_exts[ext_idx]); return 1; }