yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7e51180ed
master
1// slang-reflection-test-main.cpp 2 3#include "../../source/compiler-core/slang-pretty-writer.h" 4#include "../../source/core/slang-char-util.h" 5#include "../../source/core/slang-string-escape-util.h" 6#include "../../source/core/slang-string-util.h" 7#include "../../source/core/slang-test-tool-util.h" 8#include "slang-com-helper.h" 9#include "slang.h" 10 11#include <assert.h> 12#include <stdio.h> 13#include <stdlib.h> 14#include <string.h> 15 16using namespace Slang ; 17 18void emitReflectionJSON (SlangCompileRequest * request ,SlangReflection * reflection ) 19{ 20ComPtr < ISlangBlob > b ; 21 22spReflection_ToJson (reflection ,request ,b .writeRef ()); 23 24// Output the writer content to out stream 25StdWriters ::getOut ().write ((const char * )b -> getBufferPointer (),b -> getBufferSize ()); 26} 27 28static SlangResult maybeDumpDiagnostic (SlangResult res ,SlangCompileRequest * request ) 29{ 30const char * diagnostic ; 31if (SLANG_FAILED (res )&& (diagnostic = spGetDiagnosticOutput (request ))) 32 { 33StdWriters ::getError ().put (diagnostic ); 34 } 35return res ; 36} 37 38SlangResult performCompilationAndReflection ( 39SlangCompileRequest * request , 40int argc , 41const char * const * argv ) 42{ 43SLANG_RETURN_ON_FAIL ( 44maybeDumpDiagnostic (spProcessCommandLineArguments (request ,& argv [1 ],argc - 1 ),request )); 45SLANG_RETURN_ON_FAIL (maybeDumpDiagnostic (spCompile (request ),request )); 46 47// Okay, let's go through and emit reflection info on whatever 48// we have. 49 50SlangReflection * reflection = spGetReflection (request ); 51emitReflectionJSON (request ,reflection ); 52 53return SLANG_OK ; 54} 55 56SLANG_TEST_TOOL_API SlangResult 57innerMain (Slang ::StdWriters * stdWriters ,SlangSession * session ,int argc ,const char * const * argv ) 58{ 59Slang ::StdWriters ::setSingleton (stdWriters ); 60 61SlangCompileRequest * request = spCreateCompileRequest (session ); 62for (int i = 0 ;i < SLANG_WRITER_CHANNEL_COUNT_OF ;++ i ) 63 { 64const auto channel = SlangWriterChannel (i ); 65spSetWriter (request ,channel ,stdWriters -> getWriter (channel )); 66 } 67 68char const * appName = "slang-reflection-test" ; 69if (argc > 0 ) 70appName = argv [0 ]; 71 72SlangResult res = performCompilationAndReflection (request ,argc ,argv ); 73 74spDestroyCompileRequest (request ); 75 76return res ; 77} 78 79int main (int argc ,char ** argv ) 80{ 81using namespace Slang ; 82 83SlangSession * session = spCreateSession (nullptr ); 84 85auto stdWriters = StdWriters ::initDefaultSingleton (); 86 87SlangResult res = innerMain (stdWriters ,session ,argc ,argv ); 88spDestroySession (session ); 89 slang::shutdown (); 90return SLANG_FAILED (res ) ?1 :0 ; 91}