summaryrefslogtreecommitdiff
path: root/source/slang/slang-spirv-opt.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-10-09 14:03:43 -0700
committerGitHub <noreply@github.com>2023-10-09 14:03:43 -0700
commit67e186f0169591c48d24bd8ff7e4e4e715e8fa45 (patch)
tree9b46dc35145d18d5b25d9b3b16759c9b7343615c /source/slang/slang-spirv-opt.cpp
parent17c7163c2ae8fc290e70b43d8700b68ef18b1ee1 (diff)
Run curated spirv-opt passes through slang-glslang. (#3266)
* Run curated spirv-opt passes through slang-glslang. * Cleanup. * Replace spirv-dis downstream compiler with glslang. * delete slang-spirv-opt.cpp. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-spirv-opt.cpp')
-rw-r--r--source/slang/slang-spirv-opt.cpp66
1 files changed, 0 insertions, 66 deletions
diff --git a/source/slang/slang-spirv-opt.cpp b/source/slang/slang-spirv-opt.cpp
deleted file mode 100644
index 786358324..000000000
--- a/source/slang/slang-spirv-opt.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-#include "slang-spirv-opt.h"
-#include "slang-spirv-val.h"
-
-namespace Slang
-{
-
-struct RemoveFileRAII
-{
- String fileName;
-
- RemoveFileRAII(String inFileName)
- :fileName(inFileName)
- {}
-
- ~RemoveFileRAII()
- {
- File::remove(fileName);
- }
-};
-
-SlangResult optimizeSPIRV(const List<uint8_t>& spirv, String& outErr, List<uint8_t>& outSpv)
-{
- // Set up our process
- CommandLine commandLine;
- commandLine.m_executableLocation.setName("spirv-opt");
- commandLine.addArg("--eliminate-dead-functions");
- commandLine.addArg("--eliminate-local-single-block");
- commandLine.addArg("--eliminate-local-single-store");
- commandLine.addArg("--eliminate-dead-code-aggressive");
-
- commandLine.addArg("-o");
- String outFileName;
- File::generateTemporary(UnownedStringSlice("out_spv"), outFileName);
- RemoveFileRAII removeFile(outFileName);
-
- commandLine.addArg(outFileName);
-
- RefPtr<Process> p;
-
- // If we failed to even start the process, then spirv-opt isn't available
- SLANG_RETURN_ON_FAIL(Process::create(commandLine, 0, p));
- const auto in = p->getStream(StdStreamType::In);
- const auto out = p->getStream(StdStreamType::Out);
- const auto err = p->getStream(StdStreamType::ErrorOut);
-
- List<Byte> outErrData;
- SLANG_RETURN_ON_FAIL(StreamUtil::readAndWrite(in, spirv.getArrayView(), out, outSpv, err, outErrData));
-
- outSpv.clear();
- File::readAllBytes(outFileName, outSpv);
-
- SLANG_RETURN_ON_FAIL(p->waitForTermination(3600000));
-
- outErr = String(
- reinterpret_cast<const char*>(outErrData.begin()),
- reinterpret_cast<const char*>(outErrData.end())
- );
-
- const auto ret = p->getReturnValue();
- if (ret != 0)
- return SLANG_FAIL;
-
- return debugValidateSPIRV(outSpv);
-}
-
-}