diff options
Diffstat (limited to 'tools/slang-test')
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 58 | ||||
| -rw-r--r-- | tools/slang-test/test-context.cpp | 5 | ||||
| -rw-r--r-- | tools/slang-test/test-context.h | 1 |
3 files changed, 57 insertions, 7 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 59c16c88b..5c6d480d3 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1173,14 +1173,54 @@ String findExpectedPath(const TestInput& input, const char* postFix) return ""; } -static void _initSlangCompiler(TestContext* context, CommandLine& ioCmdLine) +static SlangResult _initSlangCompiler(TestContext* context, CommandLine& ioCmdLine) { ioCmdLine.setExecutableLocation(ExecutableLocation(context->options.binDir, "slangc")); if (context->options.verbosePaths) { - ioCmdLine.addArg("-verbose-paths"); + ioCmdLine.addArgIfNotFound("-verbose-paths"); } + + // Look for definition of a slot + + { + const auto prefix = toSlice("-DNV_SHADER_EXTN_SLOT="); + + bool usesNVAPI = false; + + for (auto& arg : ioCmdLine.m_args) + { + if (arg.startsWith(prefix)) + { + // Has NVAPI prefix, meaning + usesNVAPI = true; + break; + } + } + + // This is necessary because the session can be shared, and the prelude overwritten by the renderer. + if (usesNVAPI) + { + // We want to set the path to NVAPI + String rootPath; + SLANG_RETURN_ON_FAIL(TestToolUtil::getRootPath(context->exePath.getBuffer(), rootPath)); + String includePath; + SLANG_RETURN_ON_FAIL(TestToolUtil::getIncludePath(rootPath, "external/nvapi/nvHLSLExtns.h", includePath)) + + StringBuilder buf; + + // Include the NVAPI header + buf << "#include "; + + StringEscapeUtil::appendQuoted(StringEscapeUtil::getHandler(StringEscapeUtil::Style::Cpp), includePath.getUnownedSlice(), buf); + buf << "\n\n"; + + context->getSession()->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_HLSL, buf.getBuffer()); + } + } + + return SLANG_OK; } TestResult asTestResult(ToolReturnCode code) @@ -1291,7 +1331,7 @@ TestResult runDocTest(TestContext* context, TestInput& input) auto outputStem = input.outputStem; CommandLine cmdLine; - _initSlangCompiler(context, cmdLine); + cmdLine.addArg(input.filePath); @@ -1300,6 +1340,8 @@ TestResult runDocTest(TestContext* context, TestInput& input) cmdLine.addArg(arg); } + _initSlangCompiler(context, cmdLine); + ExecuteResult exeRes; TEST_RETURN_ON_DONE(spawnAndWait(context, outputStem, input.spawnType, cmdLine, exeRes)); @@ -1769,8 +1811,7 @@ TestResult runSimpleTest(TestContext* context, TestInput& input) auto outputStem = input.outputStem; CommandLine cmdLine; - _initSlangCompiler(context, cmdLine); - + if (input.testOptions->command != "SIMPLE_EX") { cmdLine.addArg(input.filePath); @@ -1781,6 +1822,13 @@ TestResult runSimpleTest(TestContext* context, TestInput& input) cmdLine.addArg(arg); } + // If we can't set up for simple compilation, it's because some external resource isn't available + // such as NVAPI headers. In that case we just ignore the test. + if (SLANG_FAILED(_initSlangCompiler(context, cmdLine))) + { + return TestResult::Ignored; + } + ExecuteResult exeRes; TEST_RETURN_ON_DONE(spawnAndWait(context, outputStem, input.spawnType, cmdLine, exeRes)); diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index a5dc2624c..8d8c20adf 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -59,14 +59,15 @@ TestReporter* TestContext::getTestReporter() return m_reporters[slangTestThreadIndex]; } -Result TestContext::init(const char* exePath) +Result TestContext::init(const char* inExePath) { m_session = spCreateSession(nullptr); if (!m_session) { return SLANG_FAIL; } - SLANG_RETURN_ON_FAIL(TestToolUtil::getExeDirectoryPath(exePath, exeDirectoryPath)); + exePath = inExePath; + SLANG_RETURN_ON_FAIL(TestToolUtil::getExeDirectoryPath(inExePath, exeDirectoryPath)); return SLANG_OK; } diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h index 5a48dbcd9..fb391fb42 100644 --- a/tools/slang-test/test-context.h +++ b/tools/slang-test/test-context.h @@ -145,6 +145,7 @@ class TestContext Slang::RefPtr<Slang::DownstreamCompilerSet> compilerSet; Slang::String exeDirectoryPath; + Slang::String exePath; /// Timeout time for communication over connection. /// NOTE! If the timeout is hit, the connection will be destroyed, and then recreated. |
