diff options
| author | Yong He <yonghe@outlook.com> | 2023-09-13 09:48:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-13 09:48:32 -0700 |
| commit | d2466a602774fcaec063e2f8cdbf86fd5e160a21 (patch) | |
| tree | 13d453cbf79c51ddba4131453da89055fe9740af | |
| parent | c0a77c360436c4f1ec4d284e331063c35bdf95ad (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>
| -rw-r--r-- | .github/workflows/windows-selfhosted.yml | 6 | ||||
| -rw-r--r-- | premake5.lua | 27 | ||||
| -rw-r--r-- | source/compiler-core/slang-spirv-dis-compiler.cpp | 61 | ||||
| -rw-r--r-- | source/core/slang-stream.cpp | 28 | ||||
| -rw-r--r-- | source/core/slang-stream.h | 3 | ||||
| -rw-r--r-- | source/core/windows/slang-win-process.cpp | 6 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 398 | ||||
| -rw-r--r-- | source/slang/slang-artifact-output-util.cpp | 1 | ||||
| -rw-r--r-- | source/slang/slang-ir-spirv-legalize.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-language-server.cpp | 3 | ||||
| -rw-r--r-- | source/slang/slang-lookup.cpp | 4 | ||||
| -rw-r--r-- | tests/vkray/anyhit.slang | 10 | ||||
| -rw-r--r-- | tests/vkray/callable.slang | 11 | ||||
| -rw-r--r-- | tests/vkray/callable.slang.glsl | 24 | ||||
| -rw-r--r-- | tests/vkray/closesthit.slang | 17 | ||||
| -rw-r--r-- | tests/vkray/closesthit.slang.glsl | 71 | ||||
| -rw-r--r-- | tests/vkray/entry-point-params.slang | 10 | ||||
| -rw-r--r-- | tests/vkray/entry-point-params.slang.glsl | 38 | ||||
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 1 |
19 files changed, 348 insertions, 375 deletions
diff --git a/.github/workflows/windows-selfhosted.yml b/.github/workflows/windows-selfhosted.yml index bc059ad0a..6daab9673 100644 --- a/.github/workflows/windows-selfhosted.yml +++ b/.github/workflows/windows-selfhosted.yml @@ -40,12 +40,12 @@ jobs: - name: test-spirv-direct run: | $ErrorActionPreference = "SilentlyContinue" - $env:Path += ';.\external\slang-binaries\spirv-tools\windows-${{matrix.testPlatform}}\bin\' - .\bin\windows-${{matrix.testPlatform}}\${{matrix.configuration}}\slang-test.exe tests/ -use-test-server -server-count 8 -emit-spirv-directly -expected-failure-list tests/expected-failure.txt -api vk + where.exe spirv-dis + spirv-dis --version + .\bin\windows-${{matrix.testPlatform}}\${{matrix.configuration}}\slang-test.exe tests/ -use-test-server -server-count 8 -emit-spirv-directly -expected-failure-list tests/expected-failure.txt -api vk 2>&1 - name: test run: | $ErrorActionPreference = "SilentlyContinue" - $env:Path += ';.\external\slang-binaries\spirv-tools\windows-${{matrix.testPlatform}}\bin\' .\bin\windows-${{matrix.testPlatform}}\${{matrix.configuration}}\slang-test.exe -use-test-server -server-count 8 -api all-cpu diff --git a/premake5.lua b/premake5.lua index d946ec22f..3e4ac1100 100644 --- a/premake5.lua +++ b/premake5.lua @@ -698,6 +698,10 @@ function tool(name) -- default. -- kind "ConsoleApp" + + if not targetInfo.isWindows then + links { "pthread" } + end end -- "Standard" projects will be those that go to make the binary @@ -725,6 +729,10 @@ function toolSharedLibrary(name) defines { "SLANG_SHARED_LIBRARY_TOOL" } kind "SharedLib" + + if not targetInfo.isWindows then + links { "pthread" } + end end function exampleLibrary(name) @@ -771,6 +779,10 @@ function example(name) -- rather than in each example. links { "example-base", "slang", "gfx", "gfx-util", "platform", "core" } + if not targetInfo.isWindows then + links { "pthread" } + end + if targetInfo.isWindows then else if enableXlib then @@ -809,6 +821,10 @@ function generatorProject(name, sourcePath, projectKind) else kind (projectKind) end + + if not targetInfo.isWindows then + links { "pthread" } + end end -- @@ -944,6 +960,7 @@ standardProject("slang-rt", "source/slang-rt") addSourceDir "source/core/windows" else addSourceDir "source/core/unix" + links { "pthread" } end -- @@ -1241,6 +1258,9 @@ standardProject("slangc", "source/slangc") uuid "D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7" kind "ConsoleApp" links { "core", "slang" } + if not targetInfo.isWindows then + links { "pthread" } + end function getBuildDir(isArm64) return "%{cfg.targetdir}" @@ -1519,6 +1539,9 @@ if enableEmbedStdLib then "prelude/slang-cpp-host-prelude.h.cpp", "prelude/slang-torch-prelude.h.cpp" } + if not targetInfo.isWindows then + links { "pthread" } + end end if enableEmbedStdLib then @@ -1675,6 +1698,10 @@ standardProject("slang", "source/slang") defines { "SLANG_ENABLE_IR_BREAK_ALLOC=1" } filter {} + if not targetInfo.isWindows then + links { "pthread" } + end + toolSharedLibrary "gfx-unit-test" uuid "092DAB9F-1DA5-4538-ADD7-1A8D1DBFD519" includedirs { "." } 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; } 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 <share.h> #endif +#include <thread> #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<Byte> bytesToWrite, + Stream* readStream, List<Byte>& outReadBytes, + Stream* errStream, + List<Byte>& 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<Byte>& 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<Byte> bytesToWrite, Stream* readStream, List<Byte>& outReadBytes, Stream* errStream, List<Byte>& outErrBytes); + /// Appends all bytes that can be read from stream into bytes static SlangResult readAll(Stream* stream, size_t readSize, List<Byte>& 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<Stream> 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; } diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index dce44c9cc..c04a88923 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -7874,6 +7874,36 @@ struct RayQuery <let rayFlagsGeneric : RAY_FLAG = RAY_FLAG_NONE> } } + // Commit the current non-opaque triangle hit. + __glsl_extension(GL_EXT_ray_query) + __glsl_version(460) + [__NoSideEffect] + [mutating] + void CommitNonOpaqueTriangleHit() + { + __target_switch + { + case hlsl: __intrinsic_asm ".CommitNonOpaqueTriangleHit"; + case glsl: __intrinsic_asm "rayQueryConfirmIntersectionEXT"; + case spirv: spirv_asm { OpRayQueryConfirmIntersectionKHR &this }; + } + } + + // Commit the current procedural primitive hit, with hit time `t`. + __glsl_extension(GL_EXT_ray_query) + __glsl_version(460) + [__NoSideEffect] + [mutating] + void CommitProceduralPrimitiveHit(float t) + { + __target_switch + { + case hlsl: __intrinsic_asm ".CommitProceduralPrimitiveHit"; + case glsl: __intrinsic_asm "rayQueryGenerateIntersectionEXT"; + case spirv: spirv_asm { OpRayQueryGenerateIntersectionKHR &this $t }; + } + } + // Get the type of candidate hit being considered. // // The ray query coroutine will suspend when it encounters @@ -7885,7 +7915,7 @@ struct RayQuery <let rayFlagsGeneric : RAY_FLAG = RAY_FLAG_NONE> // __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] + [__NoSideEffect] CANDIDATE_TYPE CandidateType() { __target_switch @@ -7900,125 +7930,10 @@ struct RayQuery <let rayFlagsGeneric : RAY_FLAG = RAY_FLAG_NONE> } } - // Access properties of a candidate hit. - - __target_intrinsic(glsl, "transpose(rayQueryGetIntersectionObjectToWorldEXT($0, false))") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float3x4 CandidateObjectToWorld3x4(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectToWorldEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float4x3 CandidateObjectToWorld4x3(); - - __target_intrinsic(glsl, "transpose(rayQueryGetIntersectionWorldToObjectEXT($0, false))") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float3x4 CandidateWorldToObject3x4(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionWorldToObjectEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float4x3 CandidateWorldToObject4x3(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceIdEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CandidateInstanceIndex(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceCustomIndexEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CandidateInstanceID(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionGeometryIndexEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CandidateGeometryIndex(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionPrimitiveIndexEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CandidatePrimitiveIndex(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CandidateInstanceContributionToHitGroupIndex(); - - // Access properties of the ray being traced - // in the object space of a candidate hit. - - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectRayOriginEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float3 CandidateObjectRayOrigin(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectRayDirectionEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float3 CandidateObjectRayDirection(); - - // Access properties of a candidate procedural primitive hit. - - __target_intrinsic(glsl, "rayQueryGetIntersectionCandidateAABBOpaqueEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - bool CandidateProceduralPrimitiveNonOpaque(); - - // Access properties of a candidate non-opaque triangle hit. - - __target_intrinsic(glsl, "rayQueryGetIntersectionFrontFaceEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - bool CandidateTriangleFrontFace(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionBarycentricsEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float2 CandidateTriangleBarycentrics(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionTEXT($0, false)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float CandidateTriangleRayT(); - - // Commit the current non-opaque triangle hit. - __target_intrinsic(glsl, rayQueryConfirmIntersectionEXT) - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__NoSideEffect] - [mutating] - void CommitNonOpaqueTriangleHit(); - - // Commit the current procedural primitive hit, with hit time `t`. - __target_intrinsic(glsl, rayQueryGenerateIntersectionEXT) - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__NoSideEffect] - [mutating] - void CommitProceduralPrimitiveHit(float t); - // Get the status of the committed (closest) hit, if any. __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] + [__NoSideEffect] COMMITTED_STATUS CommittedStatus() { __target_switch @@ -8034,134 +7949,221 @@ struct RayQuery <let rayFlagsGeneric : RAY_FLAG = RAY_FLAG_NONE> } } - // Access properties of the committed hit. - // - __target_intrinsic(glsl, "transpose(rayQueryGetIntersectionObjectToWorldEXT($0, true))") __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float3x4 CommittedObjectToWorld3x4(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectToWorldEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float4x3 CommittedObjectToWorld4x3(); - - __target_intrinsic(glsl, "transpose(rayQueryGetIntersectionWorldToObjectEXT($0, true))") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - float3x4 CommittedWorldToObject3x4(); + [__NoSideEffect] + bool CandidateProceduralPrimitiveNonOpaque() + { + __target_switch + { + case hlsl: __intrinsic_asm ".CandidateProceduralPrimitiveNonOpaque"; + case glsl: __intrinsic_asm "(!rayQueryGetIntersectionCandidateAABBOpaqueEXT($0, false))"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + %rr:$$bool = OpRayQueryGetIntersectionCandidateAABBOpaqueKHR &this $iCandidateOrCommitted; + result:$$bool = OpLogicalNot %rr; + }; + } + } - __target_intrinsic(glsl, "rayQueryGetIntersectionWorldToObjectEXT($0, true)") __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float4x3 CommittedWorldToObject4x3(); - + [__NoSideEffect] + float CandidateTriangleRayT() + { + __target_switch + { + case hlsl: __intrinsic_asm ".CandidateTriangleRayT"; + case glsl: __intrinsic_asm "rayQueryGetIntersectionTEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float = OpRayQueryGetIntersectionTKHR &this $iCandidateOrCommitted; + }; + } + } __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] + [__NoSideEffect] float CommittedRayT() { __target_switch { - case glsl: __intrinsic_asm "rayQueryGetIntersectionTEXT($0, true)"; case hlsl: __intrinsic_asm ".CommittedRayT"; + case glsl: __intrinsic_asm "rayQueryGetIntersectionTEXT($0, true)"; case spirv: - uint RayQueryCommittedIntersectionKHR = 1; + uint iCandidateOrCommitted = 1; return spirv_asm { - result:$$float = OpRayQueryGetIntersectionTKHR &this $RayQueryCommittedIntersectionKHR + result:$$float = OpRayQueryGetIntersectionTKHR &this $iCandidateOrCommitted; }; } } - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceIdEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CommittedInstanceIndex(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceCustomIndexEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CommittedInstanceID(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionGeometryIndexEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CommittedGeometryIndex(); - - __target_intrinsic(glsl, "rayQueryGetIntersectionPrimitiveIndexEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CommittedPrimitiveIndex(); +${{{{ + const char* kCandidateCommitted[] = {"Candidate", "Committed"}; - __target_intrinsic(glsl, "rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - uint CommittedInstanceContributionToHitGroupIndex(); + // Access Candidate and Committed Matrices. + for (uint32_t candidateOrCommitted = 0; candidateOrCommitted < 2; candidateOrCommitted++) + { + auto ccName = kCandidateCommitted[candidateOrCommitted]; + auto ccTF = candidateOrCommitted == 0 ? "false" : "true"; +}}}} - // Access properties of the ray being traced - // in the object space of a committed hit. + // CandidateObjectToWorld3x4, CandidateWorldToObject4x3 + // CommittedObjectToWorld3x4, CommittedObjectToWorld4x3 + ${{{{ + const char* kRayQueryMatrixNames[] = {"ObjectToWorld", "WorldToObject"}; + for (auto matName : kRayQueryMatrixNames) { + }}}} - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectRayOriginEXT($0, true)") __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float3 CommittedObjectRayOrigin(); + [__NoSideEffect] + float3x4 $(ccName)$(matName)3x4() + { + __target_switch + { + case glsl: __intrinsic_asm "transpose(rayQueryGetIntersection$(matName)EXT($0, $(ccTF)))"; + case hlsl: __intrinsic_asm ".$(ccName)$(matName)3x4"; + case spirv: + uint iCandidateOrCommitted = $(candidateOrCommitted); + return spirv_asm { + %m:$$float4x3 = OpRayQueryGetIntersection$(matName)KHR &this $iCandidateOrCommitted; + result:$$float3x4 = OpTranspose %m; + }; + } + } - __target_intrinsic(glsl, "rayQueryGetIntersectionObjectRayDirectionEXT($0, true)") __glsl_extension(GL_EXT_ray_query) __glsl_version(460) [__readNone] - float3 CommittedObjectRayDirection(); + float4x3 $(ccName)$(matName)4x3() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersection$(matName)EXT($0, $(ccTF))"; + case hlsl: __intrinsic_asm ".$(ccName)$(matName)4x3"; + case spirv: + uint iCandidateOrCommitted = $(candidateOrCommitted); + return spirv_asm { + result:$$float4x3 = OpRayQueryGetIntersection$(matName)KHR &this $iCandidateOrCommitted; + }; + } + } - // Access properties of a committed triangle hit. +${{{{ + } // ObjectToWorld/WorldToObject. - __target_intrinsic(glsl, "rayQueryGetIntersectionFrontFaceEXT($0, true)") - __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) - [__readNone] - bool CommittedTriangleFrontFace(); + // Access Candidate and Committed properties. + struct RayQueryMethodEntry + { + const char* type; + const char* hlslName; + const char* glslName; + }; + const RayQueryMethodEntry rayQueryMethods[] = { + {"uint", "InstanceIndex", "InstanceId"}, + {"uint", "InstanceID", "InstanceCustomIndex"}, + {"uint", "PrimitiveIndex", "PrimitiveIndex"}, + {"uint", "InstanceContributionToHitGroupIndex", "InstanceShaderBindingTableRecordOffset"}, + {"float3", "ObjectRayOrigin", "ObjectRayOrigin"}, + {"float3", "ObjectRayDirection", "ObjectRayDirection"}, + {"bool", "TriangleFrontFace", "FrontFace"}, + {"float2", "TriangleBarycentrics", "Barycentrics"}, + }; + for (auto method : rayQueryMethods) { +}}}} - __target_intrinsic(glsl, "rayQueryGetIntersectionBarycentricsEXT($0, true)") __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float2 CommittedTriangleBarycentrics(); + [__NoSideEffect] + $(method.type) $(ccName)$(method.hlslName)() + { + __target_switch + { + case hlsl: __intrinsic_asm ".$(ccName)$(method.hlslName)"; + case glsl: __intrinsic_asm "rayQueryGetIntersection$(method.glslName)EXT($0, $(ccTF))"; + case spirv: + uint iCandidateOrCommitted = $(candidateOrCommitted); + return spirv_asm { + result:$$$(method.type) = OpRayQueryGetIntersection$(method.glslName)KHR &this $iCandidateOrCommitted; + }; + } + } +${{{{ + } // Candidate/Committed properties. + } // for ("Candidate", "Committed") +}}}} // Access properties of the ray being traced. - __target_intrinsic(glsl, rayQueryGetRayFlagsEXT) __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - uint RayFlags(); + [__NoSideEffect] + uint RayFlags() + { + __target_switch + { + case hlsl: __intrinsic_asm ".RayFlags"; + case glsl: __intrinsic_asm "rayQueryGetRayFlagsEXT"; + case spirv: + return spirv_asm { + result:$$uint = OpRayQueryGetRayFlagsKHR &this; + }; + } + } - __target_intrinsic(glsl, rayQueryGetWorldRayOriginEXT) __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float3 WorldRayOrigin(); + [__NoSideEffect] + float3 WorldRayOrigin() + { + __target_switch + { + case hlsl: __intrinsic_asm ".WorldRayOrigin"; + case glsl: __intrinsic_asm "rayQueryGetWorldRayOriginEXT"; + case spirv: + return spirv_asm { + result:$$float3 = OpRayQueryGetWorldRayOriginKHR &this; + }; + } + } - __target_intrinsic(glsl, rayQueryGetWorldRayDirectionEXT) __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float3 WorldRayDirection(); + [__NoSideEffect] + float3 WorldRayDirection() + { + __target_switch + { + case hlsl: __intrinsic_asm ".WorldRayDirection"; + case glsl: __intrinsic_asm "rayQueryGetWorldRayDirectionEXT"; + case spirv: + return spirv_asm { + result:$$float3 = OpRayQueryGetWorldRayDirectionKHR &this; + }; + } + } - __target_intrinsic(glsl, rayQueryGetRayTMinEXT) __glsl_extension(GL_EXT_ray_query) __glsl_version(460) - [__readNone] - float RayTMin(); + [__NoSideEffect] + float RayTMin() + { + __target_switch + { + case hlsl: __intrinsic_asm ".RayTMin"; + case glsl: __intrinsic_asm "rayQueryGetRayTMinEXT"; + case spirv: + return spirv_asm { + result:$$float = OpRayQueryGetRayTMinKHR &this; + }; + } + }; } // diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp index 32aff9f43..2c560e236 100644 --- a/source/slang/slang-artifact-output-util.cpp +++ b/source/slang/slang-artifact-output-util.cpp @@ -75,7 +75,6 @@ SlangResult ArtifactOutputUtil::maybeDisassemble(Session* session, IArtifact* ar auto toDesc = desc; toDesc.kind = ArtifactKind::Assembly; - // If this likes a playsible disassebly conversion if (ArtifactDescUtil::isDisassembly(desc, toDesc)) { diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index 8d785bceb..54cacf4a6 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -202,6 +202,8 @@ struct SPIRVLegalizationContext : public SourceEmitterBase i->removeAndDeallocate(); } + // Returns true if the given type that should be decorated as in `UniformConstant` address space. + // These are typically opaque resource handles that can't be marked as `Uniform`. bool isSpirvUniformConstantType(IRType* type) { if (as<IRTextureTypeBase>(type)) @@ -250,7 +252,7 @@ struct SPIRVLegalizationContext : public SourceEmitterBase } } - // Textures and Samplers can't be in Uniform for Vulkan, if they are + // Opaque resource handles can't be in Uniform for Vulkan, if they are // placed here then put them in UniformConstant instead if (storageClass == SpvStorageClassUniform && isSpirvUniformConstantType(inst->getDataType())) diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp index 54da4120c..ad88ab5ac 100644 --- a/source/slang/slang-language-server.cpp +++ b/source/slang/slang-language-server.cpp @@ -910,6 +910,8 @@ SlangResult LanguageServer::completion( // Always create a new workspace version for the completion request since we // will use a modified source. auto version = m_workspace->createVersionForCompletion(); + SLANG_AST_BUILDER_RAII(version->linkage->getASTBuilder()); + auto moduleName = getMangledNameFromNameString(canonicalPath.getUnownedSlice()); version->linkage->contentAssistInfo.cursorLine = utf8Line; version->linkage->contentAssistInfo.cursorCol = utf8Col; @@ -1007,6 +1009,7 @@ SlangResult LanguageServer::completionResolve( m_connection->sendResult(&resolvedItem, responseId); return SLANG_OK; } + SLANG_AST_BUILDER_RAII(version->linkage->getASTBuilder()); auto& candidateItems = version->linkage->contentAssistInfo.completionSuggestions.candidateItems; if (itemId >= 0 && itemId < candidateItems.getCount()) { diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp index 89d3380e4..b32236019 100644 --- a/source/slang/slang-lookup.cpp +++ b/source/slang/slang-lookup.cpp @@ -372,7 +372,7 @@ static void _lookUpMembersInSuperTypeDeclImpl( BreadcrumbInfo* inBreadcrumbs) { auto semantics = request.semantics; - if (!as<InterfaceDecl>(declRef.getDecl()) && name->text == "This") + if (!as<InterfaceDecl>(declRef.getDecl()) && getText(name) == "This") { // If we are looking for `This` in anything other than an InterfaceDecl, // we just need to return the declRef itself. @@ -471,7 +471,7 @@ static void _lookUpMembersInSuperTypeDeclImpl( parentDeclRef = _maybeSpecializeSuperTypeDeclRef( astBuilder, containerDeclRef, facet->getType(), facet->subtypeWitness) .as<ContainerDecl>(); - if (as<ThisTypeDecl>(parentDeclRef.getDecl()) && name->text == "This") + if (as<ThisTypeDecl>(parentDeclRef.getDecl()) && getText(name) == "This") { // If we are going looking for `This` in a `ThisType`, we just need to return the declRef itself. AddToLookupResult(ioResult, CreateLookupResultItem(parentDeclRef, inBreadcrumbs)); diff --git a/tests/vkray/anyhit.slang b/tests/vkray/anyhit.slang index 515c66f14..baafb00a0 100644 --- a/tests/vkray/anyhit.slang +++ b/tests/vkray/anyhit.slang @@ -5,7 +5,7 @@ // where we cannot infer the required SPIR-V version from the code // (and glslang doesn't include any such inference ability). -//TEST:CROSS_COMPILE: -profile glsl_460+spirv_1_4 -stage anyhit -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage anyhit -entry main -target spirv-assembly struct SphereHitAttributes { @@ -45,3 +45,11 @@ void main( } } } + +// CHECK: OpCapability RayTracing +// CHECK: OpEntryPoint AnyHitNV %main "main" +// CHECK: %_ptr_HitAttributeNV_SphereHitAttributes_0 = OpTypePointer HitAttributeNV %SphereHitAttributes_0 +// CHECK: %_S{{.*}} = OpVariable %_ptr_HitAttributeNV_SphereHitAttributes_0 HitAttributeNV +// CHECK: %{{.*}} = OpAccessChain %_ptr_HitAttributeNV_v3float %_S{{.*}} %int_0 +// CHECK: OpTerminateRayKHR +// CHECK: OpIgnoreIntersectionKHR diff --git a/tests/vkray/callable.slang b/tests/vkray/callable.slang index 5fdbd0eb5..0f96266f6 100644 --- a/tests/vkray/callable.slang +++ b/tests/vkray/callable.slang @@ -1,6 +1,6 @@ // callable.slang -//TEST:CROSS_COMPILE: -profile glsl_460+spirv_1_4 -stage callable -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage callable -entry main -target spirv-assembly import callable_shared; @@ -14,3 +14,12 @@ void main(in out MaterialPayload ioPayload) ioPayload.uv, 0); } + +// CHECK: OpCapability RayTracingKHR +// CHECK: OpExtension "SPV_KHR_ray_tracing" +// CHECK: OpEntryPoint CallableNV %main +// CHECK: %_ptr_IncomingCallableDataNV_MaterialPayload_0 = OpTypePointer IncomingCallableDataNV %MaterialPayload_0 +// CHECK: %_ptr_IncomingCallableDataNV_v2float = OpTypePointer IncomingCallableDataNV %v2float +// CHECK: %_ptr_IncomingCallableDataNV_v4float = OpTypePointer IncomingCallableDataNV %v4float +// CHECK: %{{.*}} = OpAccessChain %_ptr_IncomingCallableDataNV_v2float %_S1 %int_1 +// CHECK: %{{.*}} = OpAccessChain %_ptr_IncomingCallableDataNV_v4float %_S1 %int_0 diff --git a/tests/vkray/callable.slang.glsl b/tests/vkray/callable.slang.glsl deleted file mode 100644 index 871ffcbb7..000000000 --- a/tests/vkray/callable.slang.glsl +++ /dev/null @@ -1,24 +0,0 @@ -#version 460 -#extension GL_EXT_ray_tracing : require -layout(row_major) uniform; -layout(row_major) buffer; -layout(binding = 0) -uniform texture2D gAlbedoMap_0; - -layout(binding = 1) -uniform sampler gSampler_0; - -struct MaterialPayload_0 -{ - vec4 albedo_0; - vec2 uv_0; -}; - -callableDataInEXT MaterialPayload_0 _S1; - -void main() -{ - _S1.albedo_0 = (textureLod(sampler2D(gAlbedoMap_0,gSampler_0), (_S1.uv_0), (0.0))); - return; -} - diff --git a/tests/vkray/closesthit.slang b/tests/vkray/closesthit.slang index b1b73c94e..b2af4501c 100644 --- a/tests/vkray/closesthit.slang +++ b/tests/vkray/closesthit.slang @@ -1,5 +1,5 @@ // closesthit.slang -//TEST:CROSS_COMPILE: -profile glsl_460+GL_NV_ray_tracing -stage closesthit -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+GL_NV_ray_tracing -stage closesthit -entry main -target spirv-assembly struct ReflectionRay { @@ -30,3 +30,18 @@ void main( ioPayload.color = color; } + +// CHECK: OpCapability RayTracing +// CHECK: OpEntryPoint ClosestHitNV %main "main" +// CHECK: OpDecorate %gl_InstanceID BuiltIn InstanceId +// CHECK: OpDecorate %gl_InstanceCustomIndexNV BuiltIn InstanceCustomIndexNV +// CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId +// CHECK: OpDecorate %gl_HitKindNV BuiltIn HitKindNV +// CHECK: OpDecorate %gl_RayTmaxNV BuiltIn RayTmaxNV +// CHECK: OpDecorate %gl_RayTminNV BuiltIn RayTminNV +// CHECK: %ShaderRecord_0 = OpVariable %_ptr_ShaderRecordBufferNV__S{{.*}} ShaderRecordBufferNV +// CHECK: %{{.*}} = OpVariable %_ptr_IncomingRayPayloadNV_ReflectionRay_0 IncomingRayPayloadNV +// CHECK: %{{.*}} = OpLoad %int %gl_InstanceID +// CHECK: %{{.*}} = OpLoad %int %gl_InstanceCustomIndexNV +// CHECK: %{{.*}} = OpAccessChain %_ptr_ShaderRecordBufferNV_uint %ShaderRecord_0 %int_0 +// CHECK: %{{.*}} = OpAccessChain %_ptr_IncomingRayPayloadNV_v4float %_S{{.*}} %int_0 diff --git a/tests/vkray/closesthit.slang.glsl b/tests/vkray/closesthit.slang.glsl deleted file mode 100644 index bb3e81f87..000000000 --- a/tests/vkray/closesthit.slang.glsl +++ /dev/null @@ -1,71 +0,0 @@ -// closesthit.slang.glsl -#version 460 -#extension GL_NV_ray_tracing : require - -#define tmp_shaderrecord _S1 -#define tmp_colors StructuredBuffer_float4_t_0 -#define tmp_hitattrs _S2 -#define tmp_payload _S3 -#define tmp_customidx _S4 -#define tmp_instanceid _S5 -#define tmp_add_0 _S6 -#define tmp_primid _S7 -#define tmp_add_1 _S8 -#define tmp_hitkind _S9 -#define tmp_hitt _S10 -#define tmp_tmin _S11 - -struct SLANG_ParameterGroup_ShaderRecord_0 -{ - uint shaderRecordID_0; -}; - -layout(shaderRecordNV) -buffer tmp_shaderrecord -{ - uint shaderRecordID_0; -} ShaderRecord_0; - -layout(std430, binding = 0) readonly buffer tmp_colors -{ - vec4 _data[]; -} colors_0; - -struct BuiltInTriangleIntersectionAttributes_0 -{ - vec2 barycentrics_0; -}; - - -hitAttributeNV BuiltInTriangleIntersectionAttributes_0 tmp_hitattrs; - -struct ReflectionRay_0 -{ - vec4 color_0; -}; - -rayPayloadInNV ReflectionRay_0 tmp_payload; - -void main() -{ - uint tmp_instanceid = gl_InstanceID; - uint tmp_shift_0 = tmp_instanceid << 1; - - uint tmp_customidx = gl_InstanceCustomIndexNV; - - uint tmp_add_0 = tmp_shift_0 + tmp_customidx; - uint tmp_primid = gl_PrimitiveID; - - uint tmp_add_1 = tmp_add_0 + tmp_primid; - uint tmp_hitkind = gl_HitKindNV; - - vec4 color_1 = colors_0._data[tmp_add_1 + tmp_hitkind + ShaderRecord_0.shaderRecordID_0]; - - float tmp_hitt = gl_RayTmaxNV; - float tmp_tmin = gl_RayTminNV; - - tmp_payload.color_0 = color_1 * (tmp_hitt - tmp_tmin); - - return; -} - diff --git a/tests/vkray/entry-point-params.slang b/tests/vkray/entry-point-params.slang index 25ee29d0d..075692b19 100644 --- a/tests/vkray/entry-point-params.slang +++ b/tests/vkray/entry-point-params.slang @@ -3,7 +3,7 @@ // Test that entry-point `uniform` parameters on ray-tracing // shaders properly map to the "shader record" in SPIR-V output. -//TEST:CROSS_COMPILE: -profile glsl_460+spirv_1_4 -stage raygeneration -entry main -target spirv-assembly +//TEST:SIMPLE(filecheck=CHECK): -profile glsl_460+spirv_1_4 -stage raygeneration -entry main -target spirv-assembly RWStructuredBuffer<float> buffer; @@ -12,3 +12,11 @@ void main( { buffer[DispatchRaysIndex().x] = value; } + +// CHECK: OpCapability RayTracingKHR +// CHECK: OpExtension "SPV_KHR_ray_tracing" +// CHECK: OpEntryPoint RayGenerationNV %main +// CHECK: OpDecorate %gl_LaunchIDEXT BuiltIn LaunchIdNV +// CHECK: %gl_LaunchIDEXT = OpVariable %_ptr_Input_v3uint Input +// CHECK: %{{.*}} = OpLoad %v3uint %gl_LaunchIDEXT +// CHECK: %{{.*}} = OpAccessChain %_ptr_ShaderRecordBufferNV_float %_S2 %int_0 diff --git a/tests/vkray/entry-point-params.slang.glsl b/tests/vkray/entry-point-params.slang.glsl deleted file mode 100644 index a505b337e..000000000 --- a/tests/vkray/entry-point-params.slang.glsl +++ /dev/null @@ -1,38 +0,0 @@ -//TEST_IGNORE_FILE: -#version 460 - -#if USE_NV_RT -#extension GL_NV_ray_tracing : require -#define callableDataInEXT callableDataInNV -#define gl_LaunchIDEXT gl_LaunchIDNV -#define hitAttributeEXT hitAttributeNV -#define ignoreIntersectionEXT ignoreIntersectionNV -#define rayPayloadInEXT rayPayloadInNV -#define shaderRecordEXT shaderRecordNV -#define terminateRayEXT terminateRayNV -#else -#extension GL_EXT_ray_tracing : require -#endif - -layout(std430, binding = 0) -buffer StructuredBuffer_float_t_0 { - float _data[]; -} buffer_0; - -struct EntryPointParams_0 -{ - float value_0; -}; - -layout(shaderRecordEXT) -buffer _S1 -{ - float value_0; -} _S2; - -void main() -{ - uvec3 _S3 = gl_LaunchIDEXT; - buffer_0._data[_S3.x] = _S2.value_0; - return; -} diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index b726caea3..2395aad16 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -642,6 +642,7 @@ static TestResult _fileCheckTest( } const bool coloredOutput = true; + testReporter.message(TestMessageType::Info, outputToCheck.getBuffer()); return fc->performTest( "slang-test", fileCheckRules.begin(), |
