From d2466a602774fcaec063e2f8cdbf86fd5e160a21 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 13 Sep 2023 09:48:32 -0700 Subject: Add all RayQuery SPIRV Intrinsics. (#3204) * Add all RayQuery SPIRV Intrinsics. * Fix * Fix. * fix. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He --- source/compiler-core/slang-spirv-dis-compiler.cpp | 61 ++++++++++++----------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'source/compiler-core') 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 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 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 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 outBytes; const auto err = p->getStream(StdStreamType::ErrorOut); + List errData; + + SLANG_RETURN_ON_FAIL(StreamUtil::readAndWrite( + inputStream, + ArrayView((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 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 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; } -- cgit v1.2.3