Switch to official SPIRV-Cross C API instead of crossc

This commit is contained in:
Andrei Alexeyev 2019-04-07 04:47:55 +03:00
parent 5f940e31fa
commit 84cba0224c
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
6 changed files with 32 additions and 33 deletions

View file

@ -27,7 +27,7 @@ Dependencies
Optional:
- OpenSSL (for a better SHA-256 implementation; used in shader cache)
- crossc >= 1.5.0 (for OpenGL ES backends)
- SPIRV-Cross >= 2019-03-22 (for OpenGL ES backends)
- libshaderc (for OpenGL ES backends)
Build-only dependencies

View file

@ -14,7 +14,7 @@
#include "util.h"
#include <shaderc/shaderc.h>
#include <crossc.h>
#include <spirv_cross_c.h>
static shaderc_compiler_t spirv_compiler;
@ -201,41 +201,40 @@ bool _spirv_decompile(const ShaderSource *in, ShaderSource *out, const SPIRVDeco
size_t spirv_size = (in->content_size - 1) / sizeof(uint32_t);
const uint32_t *spirv = (uint32_t*)(void*)in->content;
crossc_compiler *cc = crossc_glsl_create(spirv, spirv_size);
spvc_context context = NULL;
spvc_parsed_ir ir = NULL;
spvc_compiler compiler = NULL;
spvc_compiler_options spvc_options = NULL;
const char *code = NULL;
spvc_context_create(&context);
if(cc == NULL) {
log_error("Failed to initialize crossc");
#define SPVCCALL(c) do if((c) != SPVC_SUCCESS) { goto spvc_error; } while(0)
if(context == NULL) {
log_error("Failed to initialize SPIRV-Cross");
return false;
}
if(!crossc_has_valid_program(cc)) {
goto crossc_error;
}
SPVCCALL(spvc_context_parse_spirv(context, spirv, spirv_size, &ir));
SPVCCALL(spvc_context_create_compiler(context, SPVC_BACKEND_GLSL, ir, SPVC_CAPTURE_MODE_TAKE_OWNERSHIP, &compiler));
SPVCCALL(spvc_compiler_create_compiler_options(compiler, &spvc_options));
SPVCCALL(spvc_compiler_options_set_uint(spvc_options, SPVC_COMPILER_OPTION_GLSL_VERSION, options->lang->glsl.version.version));
SPVCCALL(spvc_compiler_options_set_bool(spvc_options, SPVC_COMPILER_OPTION_GLSL_ES, options->lang->glsl.version.profile == GLSL_PROFILE_ES));
SPVCCALL(spvc_compiler_install_compiler_options(compiler, spvc_options));
SPVCCALL(spvc_compiler_compile(compiler, &code));
crossc_glsl_profile profile = (
options->lang->glsl.version.profile == GLSL_PROFILE_ES
? CROSSC_GLSL_PROFILE_ES
: CROSSC_GLSL_PROFILE_CORE
);
crossc_glsl_set_version(cc, options->lang->glsl.version.version, profile);
const char *code = crossc_compile(cc);
if(code == NULL) {
goto crossc_error;
}
assume(code != NULL);
out->content = strdup(code);
out->content_size = strlen(code) + 1;
out->stage = in->stage;
out->lang = *options->lang;
crossc_destroy(cc);
spvc_context_destroy(context);
return true;
crossc_error:
log_error("crossc error: %s", crossc_strerror(cc));
crossc_destroy(cc);
spvc_error:
log_error("SPIRV-Cross error: %s", spvc_context_get_last_error_string(context));
spvc_context_destroy(context);
return false;
}

View file

@ -8,7 +8,7 @@ r_shaderlib_src = files(
r_shaderlib_libdeps = []
if get_option('shader_transpiler')
dep_crossc = dependency('crossc', version : '>=1.5.0', required : true, static : static, fallback : ['crossc', 'crossc_dep'])
dep_spvc = dependency('spirv-cross-c-shared', required : true, static : static, fallback : ['SPIRV-Cross', 'spirv_cross_dep'])
if get_option('wrap_mode') != 'forcefallback'
dep_shaderc = dependency('shaderc', static : static, required : false)
@ -35,7 +35,7 @@ if get_option('shader_transpiler')
'lang_spirv.c'
)
r_shaderlib_libdeps += [dep_shaderc, dep_crossc]
r_shaderlib_libdeps += [dep_shaderc, dep_spvc]
if host_machine.system() == 'windows' and get_option('b_lto') and get_option('static')
error(

View file

@ -1,3 +1,4 @@
SPIRV-Cross
SPIRV-Headers
SPIRV-Tools
crossc

View file

@ -0,0 +1,5 @@
[wrap-git]
directory=SPIRV-Cross
url=https://github.com/taisei-project/SPIRV-Cross.git
push-url=git@github.com:taisei-project/SPIRV-Cross.git
revision=meson

View file

@ -1,6 +0,0 @@
[wrap-git]
directory=crossc
url=https://github.com/taisei-project/crossc.git
push-url=git@github.com:taisei-project/crossc.git
clone-recursive=true
revision=v1.6.0