summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-13 09:48:32 -0700
committerGitHub <noreply@github.com>2023-09-13 09:48:32 -0700
commitd2466a602774fcaec063e2f8cdbf86fd5e160a21 (patch)
tree13d453cbf79c51ddba4131453da89055fe9740af /source/compiler-core
parentc0a77c360436c4f1ec4d284e331063c35bdf95ad (diff)
Add all RayQuery SPIRV Intrinsics. (#3204)
* Add all RayQuery SPIRV Intrinsics. * Fix * Fix. * fix. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-spirv-dis-compiler.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/source/compiler-core/slang-spirv-dis-compiler.cpp b/source/compiler-core/slang-spirv-dis-compiler.cpp
index 0e484c7c5..9b40254ce 100644
--- a/source/compiler-core/slang-spirv-dis-compiler.cpp
+++ b/source/compiler-core/slang-spirv-dis-compiler.cpp
@@ -1,5 +1,4 @@
#include "slang-spirv-dis-compiler.h"
-
#include "../core/slang-common.h"
#include "../core/slang-string-util.h"
#include "../core/slang-string.h"
@@ -7,7 +6,6 @@
#include "slang-artifact-representation.h"
#include "slang-artifact-util.h"
#include "slang-artifact-representation-impl.h"
-
namespace Slang
{
@@ -18,7 +16,6 @@ SlangResult SPIRVDisDownstreamCompilerUtil::locateCompilers(
{
// TODO: We could check that the compiler is actually present in PATH (or
// explicitly given)
-
ComPtr<IDownstreamCompiler> com(
new SPIRVDisDownstreamCompiler(DownstreamCompilerDesc(SLANG_PASS_THROUGH_SPIRV_DIS)));
set->addCompiler(com);
@@ -43,54 +40,58 @@ SlangResult SLANG_MCALL SPIRVDisDownstreamCompiler::convert(
ISlangBlob* fromBlob;
SLANG_RETURN_ON_FAIL(from->loadBlob(ArtifactKeep::No, &fromBlob));
- ComPtr<IOSFileArtifactRepresentation> fromFile;
- SLANG_RETURN_ON_FAIL(from->requireFile(ArtifactKeep::No, fromFile.writeRef()));
-
- String toFile;
- File::generateTemporary(UnownedStringSlice("spv-asm"), toFile);
-
// Set up our process
CommandLine commandLine;
commandLine.m_executableLocation.setName("spirv-dis");
commandLine.addArg("--comment");
- commandLine.addArg(fromFile->getPath());
- commandLine.addArg("-o");
- commandLine.addArg(toFile);
+
RefPtr<Process> p;
SLANG_RETURN_ON_FAIL(Process::create(commandLine, 0, p));
+
+ auto inputStream = p->getStream(StdStreamType::In);
+ if (!inputStream)
+ return SLANG_FAIL;
+
+ auto outputStream = p->getStream(StdStreamType::Out);
+ List<uint8_t> outBytes;
const auto err = p->getStream(StdStreamType::ErrorOut);
+ List<Byte> errData;
+
+ SLANG_RETURN_ON_FAIL(StreamUtil::readAndWrite(
+ inputStream,
+ ArrayView<Byte>((Byte*)fromBlob->getBufferPointer(), (Index)fromBlob->getBufferSize()),
+ outputStream,
+ outBytes,
+ err,
+ errData));
// Wait for it to finish
if(!p->waitForTermination(1000))
return SLANG_FAIL;
- // TODO: allow inheriting stderr in Process
- List<Byte> errData;
- SLANG_RETURN_ON_FAIL(StreamUtil::readAll(err, 0, errData));
- fwrite(errData.getBuffer(), errData.getCount(), 1, stderr);
+ if (errData.getCount())
+ fwrite(errData.getBuffer(), 1, (size_t)errData.getCount(), stderr);
+ StringBuilder sbOutput;
+ List<UnownedStringSlice> lines;
+ StringUtil::calcLines(StringUtil::trimEndOfLine(UnownedStringSlice((const char*)outBytes.getBuffer())), lines);
+ for (auto line : lines)
+ {
+ sbOutput << StringUtil::trimEndOfLine(line) << "\n";
+ }
// If spirv-dis failed, we fail
const auto ret = p->getReturnValue();
if(ret != 0)
return SLANG_FAIL;
- // Normalize line endings
- String outContents;
- SLANG_RETURN_ON_FAIL(File::readAllText(toFile, outContents));
- StringBuilder outBuilder;
- StringUtil::appendStandardLines(outContents.getUnownedSlice(), outBuilder);
- SLANG_RETURN_ON_FAIL(File::writeAllBytes(toFile, outBuilder.getBuffer(), outBuilder.getLength()));
-
// Return as a file artifact
- auto fileRep = OSFileArtifactRepresentation::create(
- IOSFileArtifactRepresentation::Kind::Owned,
- toFile.getUnownedSlice(),
- nullptr
- );
+
+ auto disassemblyBlob = StringBlob::moveCreate(sbOutput);
+
auto artifact = ArtifactUtil::createArtifact(to);
- artifact->addRepresentation(fileRep.detach());
- *outArtifact = artifact.detach();
+ artifact->addRepresentationUnknown(disassemblyBlob);
+ *outArtifact = artifact.detach();
return SLANG_OK;
}