yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
71e90a7ba
master
1// unit-test-ptr-layout.cpp 2 3#include "slang-com-ptr.h" 4#include "slang.h" 5#include "unit-test/slang-unit-test.h" 6 7#include <stdio.h> 8#include <stdlib.h> 9 10using namespace Slang ; 11 12SLANG_UNIT_TEST (pointerTypeLayout ) 13{ 14const char * testSource = "struct TestStruct {" 15" int3 member0;" 16" float member1;" 17"};" ; 18 19ComPtr < slang::IGlobalSession > globalSession ; 20SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 21 slang::TargetDesc targetDesc = {}; 22targetDesc .format = SLANG_SPIRV ; 23targetDesc .profile = globalSession -> findProfile ("spirv_1_5" ); 24 slang::SessionDesc sessionDesc = {}; 25sessionDesc .targetCount = 1 ; 26sessionDesc .targets = & targetDesc ; 27sessionDesc .compilerOptionEntryCount = 1 ; 28 slang::CompilerOptionEntry compilerOptionEntry = {}; 29compilerOptionEntry .name = slang::CompilerOptionName ::EmitSpirvViaGLSL ; 30compilerOptionEntry .value .kind = slang::CompilerOptionValueKind ::Int ; 31compilerOptionEntry .value .intValue0 = 1 ; 32sessionDesc .compilerOptionEntries = & compilerOptionEntry ; 33 34ComPtr < slang::ISession > session ; 35SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 36 37ComPtr < slang::IBlob > diagnosticBlob ; 38auto module = 39session -> loadModuleFromSourceString ("m" ,"m.slang" ,testSource ,diagnosticBlob .writeRef ()); 40SLANG_CHECK (module != nullptr ); 41 42 43auto testBody = [& ]() 44 { 45auto reflection = module -> getLayout (); 46auto testStruct = reflection -> findTypeByName ("Ptr<TestStruct>" ); 47auto ptrLayout = reflection -> getTypeLayout (testStruct ); 48auto valueLayout = ptrLayout -> getElementTypeLayout (); 49SLANG_CHECK_ABORT (valueLayout -> getFieldCount ()== 2 ); 50SLANG_CHECK_ABORT (valueLayout -> getFieldByIndex (1 )-> getOffset ()== 12 ); 51 }; 52 53testBody (); 54}