yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
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 ( 11StdWriters * stdWriters , 12 slang::IGlobalSession * sharedSession , 13int argc , 14const char * const * argv ) 15{ 16StdWriters ::setSingleton (stdWriters ); 17 18// Assume we will used the shared session 19ComPtr < 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. 25if (TestToolUtil ::hasDeferredCoreModule (Index (argc - 1 ),argv + 1 )) 26 { 27SLANG_RETURN_ON_FAIL ( 28slang_createGlobalSessionWithoutCoreModule (SLANG_API_VERSION ,session .writeRef ())); 29 } 30 31ComPtr < slang::ICompileRequest > compileRequest ; 32SLANG_ALLOW_DEPRECATED_BEGIN 33SLANG_RETURN_ON_FAIL (session -> createCompileRequest (compileRequest .writeRef ())); 34SLANG_ALLOW_DEPRECATED_END 35 36auto compilerExecutablePath = Path ::getParentDirectory (Path ::getExecutablePath ()); 37compileRequest -> addSearchPath (compilerExecutablePath .getBuffer ()); 38 39// Do any app specific configuration 40for (int i = 0 ;i < SLANG_WRITER_CHANNEL_COUNT_OF ;++ i ) 41 { 42const auto channel = SlangWriterChannel (i ); 43compileRequest -> setWriter (channel ,stdWriters -> getWriter (channel )); 44 } 45 46compileRequest -> setCommandLineCompilerMode (); 47 48SLANG_RETURN_ON_FAIL (compileRequest -> processCommandLineArguments (& argv [1 ],argc - 1 )); 49 50SlangResult compileRes = SLANG_OK ; 51 52#ifndef _DEBUG 53try 54#endif 55 { 56// Run the compiler (this will produce any diagnostics through 57// SLANG_WRITER_TARGET_TYPE_DIAGNOSTIC). 58compileRes = 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 63compileRes = SLANG_FAILED (compileRes ) ?SLANG_E_INTERNAL_FAIL :compileRes ; 64 } 65#ifndef _DEBUG 66catch (const Exception & e ) 67 { 68StdWriters ::getOut ()."internal compiler error: %S\n" ,e .Message .toWString ().begin ()); 69compileRes = SLANG_FAIL ; 70 } 71#endif 72 73return compileRes ; 74}