deduplicate spirv disassembly code

This commit is contained in:
Mathias Agopian
2023-02-01 17:07:52 -08:00
committed by Mathias Agopian
parent 8afb11128d
commit f71e90fae0
2 changed files with 6 additions and 13 deletions

View File

@@ -70,20 +70,13 @@ static const std::string_view kErrorHeader =
"Connection: close\r\n\r\n";
static void spirvToAsm(struct mg_connection *conn, const uint32_t* spirv, size_t size) {
auto context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
spv_text text = nullptr;
const uint32_t options = SPV_BINARY_TO_TEXT_OPTION_INDENT |
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
spvBinaryToText(context, spirv, size / 4, options, &text, nullptr);
auto spirvDisassembly = ShaderExtractor::spirvToText(spirv, size / 4);
mg_printf(conn, kSuccessHeader.data(), "application/txt");
mg_write(conn, text->str, text->length);
spvTextDestroy(text);
spvContextDestroy(context);
mg_write(conn, spirvDisassembly.c_str(), spirvDisassembly.size());
}
static void spirvToGlsl(ShaderModel shaderModel, struct mg_connection *conn, const uint32_t* spirv,
size_t size) {
static void spirvToGlsl(ShaderModel shaderModel, struct mg_connection *conn,
const uint32_t* spirv, size_t size) {
auto glsl = ShaderExtractor::spirvToGLSL(shaderModel, spirv, size / 4);
mg_printf(conn, kSuccessHeader.data(), "application/txt");
mg_printf(conn, glsl.c_str(), glsl.size());

View File

@@ -101,7 +101,6 @@ CString ShaderExtractor::spirvToGLSL(ShaderModel shaderModel, const uint32_t* da
emitOptions.version = 450;
}
emitOptions.vulkan_semantics = true;
//emitOptions.emit_line_directives = true;
std::vector<uint32_t> spirv(data, data + wordCount);
CompilerGLSL glslCompiler(std::move(spirv));
@@ -115,7 +114,8 @@ CString ShaderExtractor::spirvToGLSL(ShaderModel shaderModel, const uint32_t* da
// uses, which lets us easily generate test cases for the spirv-cross project.
CString ShaderExtractor::spirvToText(const uint32_t* begin, size_t wordCount) {
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
if (SPV_SUCCESS != spvValidateBinary(context, begin, wordCount, nullptr)) {
if (spvValidateBinary(context, begin, wordCount, nullptr) != SPV_SUCCESS) {
spvContextDestroy(context);
return CString("Validation failure.");
}