yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.4 KiB74 linesraw
1// test-context.cpp
2#include "slangc-tool.h"
3
4#include "../../source/core/slang-exception.h"
5#include "../../source/core/slang-io.h"
6#include "../../source/core/slang-test-tool-util.h"
7
8using namespace Slang;
9
10SlangResult SlangCTool::innerMain(
11    StdWriters* stdWriters,
12    slang::IGlobalSession* sharedSession,
13    int argc,
14    const char* const* argv)
15{
16    StdWriters::setSingleton(stdWriters);
17
18    // Assume we will used the shared session
19    ComPtr<slang::IGlobalSession> session(sharedSession);
20
21    // The sharedSession always has a pre-loaded core module.
22    // This differed test checks if the command line has an option to setup the core module.
23    // If so we *don't* use the sharedSession, and create a new session without the core module just
24    // for this compilation.
25    if (TestToolUtil::hasDeferredCoreModule(Index(argc - 1), argv + 1))
26    {
27        SLANG_RETURN_ON_FAIL(
28            slang_createGlobalSessionWithoutCoreModule(SLANG_API_VERSION, session.writeRef()));
29    }
30
31    ComPtr<slang::ICompileRequest> compileRequest;
32    SLANG_ALLOW_DEPRECATED_BEGIN
33    SLANG_RETURN_ON_FAIL(session->createCompileRequest(compileRequest.writeRef()));
34    SLANG_ALLOW_DEPRECATED_END
35
36    auto compilerExecutablePath = Path::getParentDirectory(Path::getExecutablePath());
37    compileRequest->addSearchPath(compilerExecutablePath.getBuffer());
38
39    // Do any app specific configuration
40    for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
41    {
42        const auto channel = SlangWriterChannel(i);
43        compileRequest->setWriter(channel, stdWriters->getWriter(channel));
44    }
45
46    compileRequest->setCommandLineCompilerMode();
47
48    SLANG_RETURN_ON_FAIL(compileRequest->processCommandLineArguments(&argv[1], argc - 1));
49
50    SlangResult compileRes = SLANG_OK;
51
52#ifndef _DEBUG
53    try
54#endif
55    {
56        // Run the compiler (this will produce any diagnostics through
57        // SLANG_WRITER_TARGET_TYPE_DIAGNOSTIC).
58        compileRes = compileRequest->compile();
59
60        // If the compilation failed, then get out of here...
61        // Turn into an internal Result -> such that return code can be used to vary result to match
62        // previous behavior
63        compileRes = SLANG_FAILED(compileRes) ? SLANG_E_INTERNAL_FAIL : compileRes;
64    }
65#ifndef _DEBUG
66    catch (const Exception& e)
67    {
68        StdWriters::getOut().print("internal compiler error: %S\n", e.Message.toWString().begin());
69        compileRes = SLANG_FAIL;
70    }
71#endif
72
73    return compileRes;
74}