Apply suggestions from code review
This commit is contained in:
parent
c4fdb3f371
commit
2ace2714ed
@ -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)
|
size_t spvc_compiler_get_num_required_extensions(spvc_compiler compiler)
|
||||||
{
|
{
|
||||||
#if SPIRV_CROSS_C_API_GLSL
|
#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 SPVC_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<CompilerGLSL *>(compiler->compiler.get())->get_required_extensions().size();
|
return static_cast<CompilerGLSL *>(compiler->compiler.get())->get_required_extensions().size();
|
||||||
#else
|
#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;
|
return 0;
|
||||||
#endif
|
#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)
|
const char *spvc_compiler_get_required_extension(spvc_compiler compiler, size_t index)
|
||||||
{
|
{
|
||||||
#if SPIRV_CROSS_C_API_GLSL
|
#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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& exts = static_cast<CompilerGLSL *>(compiler->compiler.get())->get_required_extensions();
|
auto &exts = static_cast<CompilerGLSL *>(compiler->compiler.get())->get_required_extensions();
|
||||||
if (index < exts.size()) {
|
if (index < exts.size())
|
||||||
return exts[index].c_str();
|
return exts[index].c_str();
|
||||||
} else {
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
#else
|
#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;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -15565,7 +15565,8 @@ void CompilerGLSL::require_extension(const std::string &ext)
|
|||||||
forced_extensions.push_back(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;
|
return forced_extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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_create_compiler_options(compiler_glsl, &options));
|
||||||
SPVC_CHECKED_CALL(spvc_compiler_install_compiler_options(compiler_glsl, options));
|
SPVC_CHECKED_CALL(spvc_compiler_install_compiler_options(compiler_glsl, options));
|
||||||
|
|
||||||
const int NUM_EXTS = 2;
|
static const int NUM_EXTS = 2;
|
||||||
const char* expected_exts[NUM_EXTS] = {
|
const char *expected_exts[NUM_EXTS] =
|
||||||
|
{
|
||||||
"EXT_first",
|
"EXT_first",
|
||||||
"EXT_second"
|
"EXT_second"
|
||||||
};
|
};
|
||||||
|
|
||||||
int ext_idx = 0;
|
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]));
|
SPVC_CHECKED_CALL(spvc_compiler_require_extension(compiler_glsl, expected_exts[ext_idx]));
|
||||||
ext_idx += 1;
|
ext_idx += 1;
|
||||||
}
|
}
|
||||||
@ -204,9 +206,11 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext_idx = 0;
|
ext_idx = 0;
|
||||||
while(ext_idx < num_exts) {
|
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) {
|
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]);
|
fprintf(stderr, "extension mismatch (%s != %s)!\n", ext, expected_exts[ext_idx]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user