diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-08-21 16:04:42 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-21 13:04:42 -0700 |
| commit | fcac02e405661de311b5ceebbd6d3e2c78bf8aea (patch) | |
| tree | 6e79865b39f0739d2ac9c3f91cc4129c244b6977 /source | |
| parent | 49067fd2e97b40649df3fa2ce096f78c2e45da5a (diff) | |
Vulkan update/NVAPI support (#1511)
* First pass at incorporating nvapi into test harness.
* D3d12 Atomic Float Add via NVAPI working
* Dx12 atomic float appears to work.
* Atomic float add on Dx12.
* Added atomic64 feature addition to vk.
Fix correct output for atomic-float-byte-address.slang
* Disable atomic float failing tests.
* Upgraded VK headers.
* Detect atomic float availability on VK.
* Try to get test working for in64 atomic.
* Made HLSL prelude controlled via the render-test requirements.
* Added -enable-nvapi to premake.
* Fix D3D12Renderer when NVAPI is not available.
* Small improvements to VKRenderer.
* Improve atomic documentation in target-compatibility.md.
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/slang-test-tool-util.cpp | 86 | ||||
| -rw-r--r-- | source/core/slang-test-tool-util.h | 22 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 11 | ||||
| -rw-r--r-- | source/slangc/main.cpp | 2 |
4 files changed, 66 insertions, 55 deletions
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp index 7c972d099..f06095ada 100644 --- a/source/core/slang-test-tool-util.cpp +++ b/source/core/slang-test-tool-util.cpp @@ -37,7 +37,7 @@ namespace Slang } } -static SlangResult _calcIncludePath(const String& parentPath, const char* path, String& outIncludePath) +/* static */SlangResult TestToolUtil::getIncludePath(const String& parentPath, const char* path, String& outIncludePath) { String includePath; SLANG_RETURN_ON_FAIL(Path::getCanonical(Path::combine(parentPath, path), includePath)); @@ -55,73 +55,73 @@ static SlangResult _calcIncludePath(const String& parentPath, const char* path, return SLANG_OK; } -static SlangResult _addCPPPrelude(const String& parentPath, slang::IGlobalSession* session) +static SlangResult _addCPPPrelude(const String& rootPath, slang::IGlobalSession* session) { String includePath; - SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cpp-prelude.h", includePath)); + SLANG_RETURN_ON_FAIL(TestToolUtil::getIncludePath(rootPath, "prelude/slang-cpp-prelude.h", includePath)); StringBuilder prelude; prelude << "#include \"" << includePath << "\"\n\n"; session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CPP, prelude.getBuffer()); return SLANG_OK; } -static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSession* session) +static SlangResult _addCUDAPrelude(const String& rootPath, slang::IGlobalSession* session) { String includePath; - SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cuda-prelude.h", includePath)); + SLANG_RETURN_ON_FAIL(TestToolUtil::getIncludePath(rootPath, "prelude/slang-cuda-prelude.h", includePath)); StringBuilder prelude; prelude << "#include \"" << includePath << "\"\n\n"; session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CUDA, prelude.getBuffer()); return SLANG_OK; } -/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const PreludeInfo& info, slang::IGlobalSession* session) +/* static */SlangResult TestToolUtil::getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath) { - // Set the prelude to a path - if (info.exePath) - { - String exePath(info.exePath); + String canonicalPath; + SLANG_RETURN_ON_FAIL(Path::getCanonical(exePath, canonicalPath)); + // Get the directory + outExeDirectoryPath = Path::getParentDirectory(canonicalPath); + return SLANG_OK; +} - String canonicalPath; - if (SLANG_SUCCEEDED(Path::getCanonical(exePath, canonicalPath))) - { - // Get the directory - String parentPath = Path::getParentDirectory(canonicalPath); - - if (SLANG_FAILED(_addCPPPrelude(parentPath, session))) - { - SLANG_ASSERT(!"Couldn't find the C++ prelude relative to the executable"); - } - - if (SLANG_FAILED(_addCUDAPrelude(parentPath, session))) - { - SLANG_ASSERT(!"Couldn't find the CUDA prelude relative to the executable"); - } - } - } - // If the nvAPI path is set, and we find nvHLSLExtns.h, put that in the HLSL prelude - if (info.nvapiPath) - { - String includePath; - if (SLANG_SUCCEEDED(_calcIncludePath(info.nvapiPath, "nvHLSLExtns.h", includePath))) - { - StringBuilder buf; +/* static */SlangResult TestToolUtil::getRootPath(const char* inExePath, String& outExePath) +{ + // Get the directory holding the exe + String parentPath; + SLANG_RETURN_ON_FAIL(getExeDirectoryPath(inExePath, parentPath)); - buf << "#include \"" << includePath << "\"\n"; + // From directory to the root is ../../.. + // Work out the relative path to the root + String rootRelPath = Path::combine(parentPath, "../../../"); - session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_HLSL, buf.getBuffer()); - return SLANG_OK; - } - } + // We want the absolute path to the root + SLANG_RETURN_ON_FAIL(Path::getCanonical(rootRelPath, outExePath)); + return SLANG_OK; +} +/* static */SlangResult TestToolUtil::setSessionDefaultPreludeFromExePath(const char* inExePath, slang::IGlobalSession* session) +{ + String rootPath; + SLANG_RETURN_ON_FAIL(getRootPath(inExePath, rootPath)); + SLANG_RETURN_ON_FAIL(setSessionDefaultPreludeFromRootPath(rootPath, session)); return SLANG_OK; } -/* static */SlangResult TestToolUtil::setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session) +/* static */SlangResult TestToolUtil::setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session) { - PreludeInfo info; - info.exePath = exePath; - return setSessionDefaultPrelude(info, session); + // Set the prelude to a path + + if (SLANG_FAILED(_addCPPPrelude(rootPath, session))) + { + SLANG_ASSERT(!"Couldn't find the C++ prelude relative to the executable"); + } + + if (SLANG_FAILED(_addCUDAPrelude(rootPath, session))) + { + SLANG_ASSERT(!"Couldn't find the CUDA prelude relative to the executable"); + } + + return SLANG_OK; } } diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h index 9aa34bd0e..07532682b 100644 --- a/source/core/slang-test-tool-util.h +++ b/source/core/slang-test-tool-util.h @@ -36,12 +36,6 @@ enum class ToolReturnCodeSpan /* Utility functions for 'test tools' */ struct TestToolUtil { - struct PreludeInfo - { - const char* exePath = nullptr; - const char* nvapiPath = nullptr; - }; - typedef SlangResult(*InnerMainFunc)(Slang::StdWriters* stdWriters, SlangSession* session, int argc, const char*const* argv); /// If the test failed to run or was ignored then we are done @@ -53,10 +47,22 @@ struct TestToolUtil /// Given a slang result, returns a return code that can be returned from an executable static ToolReturnCode getReturnCode(SlangResult res); + /// Given the executable path (as located in Slang directory hierarchy), works out the absolute path to the root + static SlangResult getRootPath(const char* exePath, String& outRootPath); + + /// Given the exePath, give return the absolute path to the directory the exe is in + static SlangResult getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath); + /// Sets the default preludes on the session based on the executable path - static SlangResult setSessionDefaultPrelude(const PreludeInfo& preludeInfo, slang::IGlobalSession* session); + static SlangResult setSessionDefaultPreludeFromRootPath(const String& rootPath, slang::IGlobalSession* session); - static SlangResult setSessionDefaultPrelude(const char* exePath, slang::IGlobalSession* session); + /// Calculates the path that is the combination of parentPath, and relPath + /// And converts such that can be used as an include path (handling slashes) + static SlangResult getIncludePath(const String& parentPath, const char* relPath, String& outIncludePath); + + + /// Sets the default preludes on the session based on the executable path + static SlangResult setSessionDefaultPreludeFromExePath(const char* exePath, slang::IGlobalSession* session); }; } // namespace Slang diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index dc87eb6fd..8ec5c2c67 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -196,16 +196,20 @@ ${{{{ // float32 and int64 atomic support. This is a Slang specific extension, it uses // GL_EXT_shader_atomic_float on vk - // NVAPI support on DX - // NOTE! To use this feature on HLSL, the shader needs to include 'nvHLSLExtns.h' from the NVAPI SDK - // + // NvAPI support on DX + // NOTE! To use this feature on HLSL, the shader needs to include 'nvHLSLExtns.h' from the NvAPI SDK + // + // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VK_EXT_shader_atomic_float + // https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/EXT/SPV_EXT_shader_atomic_float_add.html // Fp32 __target_intrinsic(hlsl, "($3 = NvInterlockedAddFp32($0, $1, $2))") + __cuda_sm_version(2.0) __target_intrinsic(cuda, "(*$3 = atomicAdd((float*)$0._getPtrAt($1), $2))") void InterlockedAddFp32(uint byteAddress, float valueToAdd, out float originalValue); + __specialized_for_target(glsl) void InterlockedAddFp32(uint byteAddress, float valueToAdd, out float originalValue) { @@ -216,6 +220,7 @@ ${{{{ // Without returning original value __target_intrinsic(hlsl, "(NvInterlockedAddFp32($0, $1, $2))") + __cuda_sm_version(2.0) __target_intrinsic(cuda, "atomicAdd((float*)$0._getPtrAt($1), $2)") void InterlockedAddFp32(uint byteAddress, float valueToAdd); diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index 931737a41..9f4ffcaff 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -83,7 +83,7 @@ int MAIN(int argc, char** argv) SlangResult res; { SlangSession* session = spCreateSession(nullptr); - TestToolUtil::setSessionDefaultPrelude(argv[0], session); + TestToolUtil::setSessionDefaultPreludeFromExePath(argv[0], session); auto stdWriters = StdWriters::initDefaultSingleton(); |
