yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
49e912a9d
master
1// unit-test-cuda-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// Test that the compilation API can be used to produce CUDA source. 15 16SLANG_UNIT_TEST (CudaCompile ) 17{ 18// Source for a module that contains an undecorated entrypoint. 19const char * userSourceBody = R"( 20[CudaDeviceExport] 21float testExportedFunc(float3 particleRayOrigin) 22{ 23return dot(particleRayOrigin,particleRayOrigin); 24}; 25)" ; 26 27auto moduleName = "moduleG" + String (Process ::getId ()); 28ComPtr < slang::IGlobalSession > globalSession ; 29SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 30 slang::TargetDesc targetDesc = {}; 31targetDesc .format = SLANG_CUDA_SOURCE ; 32 slang::SessionDesc sessionDesc = {}; 33sessionDesc .targetCount = 1 ; 34sessionDesc .targets = & targetDesc ; 35ComPtr < slang::ISession > session ; 36SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 37 38ComPtr < slang::IBlob > diagnosticBlob ; 39auto module = session -> loadModuleFromSourceString ( 40"m" , 41"m.slang" , 42userSourceBody , 43diagnosticBlob .writeRef ()); 44SLANG_CHECK (module != nullptr ); 45 46ComPtr < slang::IComponentType > linkedProgram ; 47module -> link (linkedProgram .writeRef (),diagnosticBlob .writeRef ()); 48SLANG_CHECK (linkedProgram != nullptr ); 49 50ComPtr < slang::IBlob > code ; 51linkedProgram -> getTargetCode (0 ,code .writeRef (),diagnosticBlob .writeRef ()); 52SLANG_CHECK (code != nullptr ); 53SLANG_CHECK (code -> getBufferSize ()!= 0 ); 54String text = String ((char * )code -> getBufferPointer ()); 55SLANG_CHECK (text .indexOf ("testExportedFunc" )> 0 ); 56}