yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7b570feed
master
1// unit-test-fcpw-compile.cpp 2 3#include "../../source/core/slang-io.h" 4#include "../../source/core/slang-process.h" 5#include "slang-com-ptr.h" 6#include "slang.h" 7#include "unit-test/slang-unit-test.h" 8 9#include <stdio.h> 10#include <stdlib.h> 11 12using namespace Slang ; 13 14// A test that uses the COM API to load and compile the FCPW library written by 15// Rohan Sawhney, shader code in MIT license. 16// https://github.com/rohan-sawhney/fcpw 17// 18SLANG_UNIT_TEST (fcpwCompile ) 19{ 20ComPtr < slang::IGlobalSession > globalSession ; 21SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 22 slang::TargetDesc targetDesc = {}; 23targetDesc .format = SLANG_SPIRV ; 24targetDesc .profile = globalSession -> findProfile ("spirv_1_5" ); 25 slang::SessionDesc sessionDesc = {}; 26sessionDesc .targetCount = 1 ; 27sessionDesc .targets = & targetDesc ; 28sessionDesc .preprocessorMacroCount = 1 ; 29 slang::PreprocessorMacroDesc macroDesc = {}; 30macroDesc .name = "_BVH_TYPE" ; 31macroDesc .value = "2" ; 32sessionDesc .preprocessorMacros = & macroDesc ; 33ComPtr < slang::ISession > session ; 34SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 35 36ComPtr < slang::IBlob > diagnosticBlob ; 37auto module = 38session -> loadModule ("tests/fcpw/bvh-traversal.cs.slang" ,diagnosticBlob .writeRef ()); 39SLANG_CHECK (module != nullptr ); 40 41ComPtr < slang::IEntryPoint > entryPoint ; 42module -> findEntryPointByName ("rayIntersection" ,entryPoint .writeRef ()); 43SLANG_CHECK (entryPoint != nullptr ); 44 45ComPtr < slang::IComponentType > compositeProgram ; 46 slang::IComponentType * components []= {module ,entryPoint .get ()}; 47session -> createCompositeComponentType ( 48components , 492 , 50compositeProgram .writeRef (), 51diagnosticBlob .writeRef ()); 52SLANG_CHECK (compositeProgram != nullptr ); 53 54ComPtr < slang::IComponentType > linkedProgram ; 55compositeProgram -> link (linkedProgram .writeRef (),diagnosticBlob .writeRef ()); 56SLANG_CHECK (linkedProgram != nullptr ); 57 58ComPtr < slang::IBlob > code ; 59linkedProgram -> getEntryPointCode (0 ,0 ,code .writeRef (),diagnosticBlob .writeRef ()); 60SLANG_CHECK (code != nullptr ); 61SLANG_CHECK (code -> getBufferSize ()!= 0 ); 62}