summaryrefslogtreecommitdiff
path: root/source/slang-glslang/slang-glslang.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-01-07 01:35:47 -0800
committerGitHub <noreply@github.com>2025-01-07 01:35:47 -0800
commit5621ace93b7665051f7e7c8a2fa68ceaf285ff8d (patch)
tree0aec6cedaeb888da9bd1cff617359a2775c63921 /source/slang-glslang/slang-glslang.cpp
parenta448b7ecd880c4cbe1c0504af3df4ec708f42d48 (diff)
Use disassemble API from SPIRV-Tools (#6001)
* Use disassemble API from SPIRV-Tools This commit uses C API version of SPIRV disassemble function rather than calling spirv-dis.exe. This allows us to use a correct version of SPIRV disassble function that Slangc.exe is using. The implementation is mostly copied from external/spirv-tools/tools/dis/dis.cpp, which is a source file for building spirv-dis.exe. This commit also includes a fix for a bug in RPC communication to `test-server`. When an RPC connection to `test-server.exe` is reused and the second test abruptly fails due to a compile error or SPIRV validation error, the output from the first test run was incorrectly reused as the output for the second test. This commit resets the RPC result before waiting for the response so that even when the RPC connection is erratically disconnected, the result from the previous run will not be reused incorrectly. Some of the tests appear to be relying on this type of behavior. By using an option, `-skip-spirv-validation`, the RPC connection will continue without an interruption.
Diffstat (limited to 'source/slang-glslang/slang-glslang.cpp')
-rw-r--r--source/slang-glslang/slang-glslang.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp
index 4abcada62..ca45be05b 100644
--- a/source/slang-glslang/slang-glslang.cpp
+++ b/source/slang-glslang/slang-glslang.cpp
@@ -182,6 +182,37 @@ extern "C"
return tools.Validate(contents, contentsSize, options);
}
+// Disassemble the given SPIRV-ASM instructions.
+extern "C"
+#ifdef _MSC_VER
+ _declspec(dllexport)
+#else
+ __attribute__((__visibility__("default")))
+#endif
+ bool glslang_disassembleSPIRV(const uint32_t* contents, int contentsSize)
+{
+ static const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_5;
+
+ uint32_t options = SPV_BINARY_TO_TEXT_OPTION_NONE;
+ options |= SPV_BINARY_TO_TEXT_OPTION_COMMENT;
+ options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
+ options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
+
+ spv_diagnostic diagnostic = nullptr;
+ spv_context context = spvContextCreate(kDefaultEnvironment);
+ spv_result_t error =
+ spvBinaryToText(context, contents, contentsSize, options, nullptr, &diagnostic);
+ spvContextDestroy(context);
+ if (error)
+ {
+ spvDiagnosticPrint(diagnostic);
+ spvDiagnosticDestroy(diagnostic);
+ return false;
+ }
+
+ return true;
+}
+
// Apply the SPIRV-Tools optimizer to generated SPIR-V based on the desired optimization level
// TODO: add flag for optimizing SPIR-V size as well
static void glslang_optimizeSPIRV(