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/core/slang-stream.cpp | 28 ++++++++++++++++++++++++++++ source/core/slang-stream.h | 3 +++ source/core/windows/slang-win-process.cpp | 6 +++--- 3 files changed, 34 insertions(+), 3 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-stream.cpp b/source/core/slang-stream.cpp index 4b5d92228..6507c2e56 100644 --- a/source/core/slang-stream.cpp +++ b/source/core/slang-stream.cpp @@ -2,6 +2,7 @@ #ifdef _WIN32 #include #endif +#include #include "slang-io.h" #include "slang-process.h" @@ -587,6 +588,33 @@ SlangResult BufferedReadStream::readUntilContains(size_t size) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! StreamUtil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +SlangResult StreamUtil::readAndWrite( + Stream* writeStream, + ArrayView bytesToWrite, + Stream* readStream, List& outReadBytes, + Stream* errStream, + List& outErrBytes) +{ + std::thread writeThread([&]() + { + writeStream->write(bytesToWrite.getBuffer(), (size_t)bytesToWrite.getCount()); + writeStream->close(); + }); + SlangResult readResult = SLANG_OK; + std::thread readThread([&]() + { + readResult = readAll(readStream, 1024, outReadBytes); + }); + std::thread readErrThread([&]() + { + readAll(errStream, 1024, outErrBytes); + }); + writeThread.join(); + readThread.join(); + readErrThread.join(); + return readResult; +} + /* static */SlangResult StreamUtil::readAll(Stream* stream, size_t readSize, List& ioBytes) { while (!stream->isEnd()) diff --git a/source/core/slang-stream.h b/source/core/slang-stream.h index 388b178c9..9f405dbb0 100644 --- a/source/core/slang-stream.h +++ b/source/core/slang-stream.h @@ -253,6 +253,9 @@ enum class StreamBufferStyle struct StreamUtil { + // Write inputs to writeStream while simultaneously read from readStream and errStream. + static SlangResult readAndWrite(Stream* writeStream, ArrayView bytesToWrite, Stream* readStream, List& outReadBytes, Stream* errStream, List& outErrBytes); + /// Appends all bytes that can be read from stream into bytes static SlangResult readAll(Stream* stream, size_t readSize, List& ioBytes); diff --git a/source/core/windows/slang-win-process.cpp b/source/core/windows/slang-win-process.cpp index 38f733015..8b41393ae 100644 --- a/source/core/windows/slang-win-process.cpp +++ b/source/core/windows/slang-win-process.cpp @@ -98,10 +98,9 @@ protected: FileAccess m_access = FileAccess::None; WinHandle m_streamHandle; bool m_isOwned; - bool m_isPipe; + bool m_isPipe; }; - class WinProcess : public Process { public: @@ -526,12 +525,13 @@ void WinProcess::kill(int32_t returnCode) } RefPtr streams[Index(StdStreamType::CountOf)]; + if (childStdErrRead) streams[Index(StdStreamType::ErrorOut)] = new WinPipeStream(childStdErrRead.detach(), FileAccess::Read); streams[Index(StdStreamType::Out)] = new WinPipeStream(childStdOutRead.detach(), FileAccess::Read); streams[Index(StdStreamType::In)] = new WinPipeStream(childStdInWrite.detach(), FileAccess::Write); - outProcess = new WinProcess(processHandle.detach(), streams[0].readRef()); + return SLANG_OK; } -- cgit v1.2.3