Apply suggestions from code review

This commit is contained in:
Hans-Kristian Arntzen 2023-06-06 12:41:59 +02:00 committed by GitHub
parent c4fdb3f371
commit 2ace2714ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View File

@ -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<CompilerGLSL *>(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<CompilerGLSL *>(compiler->compiler.get())->get_required_extensions();
if (index < exts.size()) {
auto &exts = static_cast<CompilerGLSL *>(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
}

View File

@ -15565,7 +15565,8 @@ void CompilerGLSL::require_extension(const std::string &ext)
forced_extensions.push_back(ext);
}
const SmallVector<std::string> &CompilerGLSL::get_required_extensions() const {
const SmallVector<std::string> &CompilerGLSL::get_required_extensions() const
{
return forced_extensions;
}

View File

@ -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;
}