yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
02706dfc5
master
1#pragma once 2 3#include "core/slang-basic.h" 4#include "slang-gfx.h" 5 6namespace gfx 7{ 8class SlangContext 9{ 10public : 11Slang ::ComPtr < slang ::IGlobalSession > globalSession ; 12Slang ::ComPtr < slang ::ISession > session ; 13SlangCompileTarget compileTarget ; 14Result initialize ( 15const gfx ::IDevice ::SlangDesc & desc , 16uint32_t extendedDescCount , 17void ** extendedDescs , 18SlangCompileTarget compileTarget , 19const char * defaultProfileName , 20Slang ::ConstArrayView < slang ::PreprocessorMacroDesc > additionalMacros ) 21 { 22if (desc .slangGlobalSession ) 23 { 24globalSession = desc .slangGlobalSession ; 25 } 26else 27 { 28SLANG_RETURN_ON_FAIL (slang ::createGlobalSession (globalSession .writeRef ())); 29 } 30 31this -> compileTarget = compileTarget ; 32slang ::SessionDesc slangSessionDesc = {}; 33slangSessionDesc .defaultMatrixLayoutMode = desc .defaultMatrixLayoutMode ; 34slangSessionDesc .searchPathCount = desc .searchPathCount ; 35slangSessionDesc .searchPaths = desc .searchPaths ; 36slangSessionDesc .preprocessorMacroCount = 37desc .preprocessorMacroCount + additionalMacros .getCount (); 38Slang ::List < slang ::PreprocessorMacroDesc > macros ; 39macros .addRange (desc .preprocessorMacros ,desc .preprocessorMacroCount ); 40macros .addRange (additionalMacros .getBuffer (),additionalMacros .getCount ()); 41slangSessionDesc .preprocessorMacros = macros .getBuffer (); 42slang ::TargetDesc targetDesc = {}; 43targetDesc .format = compileTarget ; 44 autotargetProfile = desc. targetProfile ; 45if (targetProfile == nullptr ) 46targetProfile = defaultProfileName; 47targetDesc. profile = globalSession -> findProfile (targetProfile); 48targetDesc. floatingPointMode = desc. floatingPointMode ; 49targetDesc. lineDirectiveMode = desc. lineDirectiveMode ; 50targetDesc. flags = desc. targetFlags ; 51targetDesc. forceGLSLScalarBufferLayout = true; 52 53slangSessionDesc. targets = & targetDesc; 54slangSessionDesc. targetCount = 1 ; 55 56for ( uint32_t i = 0 ; i < extendedDescCount; i ++ ) 57{ 58if (( * ( StructType * )extendedDescs[i]) == StructType::SlangSessionExtendedDesc) 59{ 60auto extDesc = ( SlangSessionExtendedDesc * )extendedDescs[i]; 61slangSessionDesc. compilerOptionEntryCount = extDesc -> compilerOptionEntryCount ; 62slangSessionDesc. compilerOptionEntries = extDesc -> compilerOptionEntries ; 63break ; 64} 65} 66 67SLANG_RETURN_ON_FAIL (globalSession -> createSession (slangSessionDesc, session. writeRef ())); 68return SLANG_OK ; 69} 70}; 71} // namespace gfx