yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
edf5e9f97
master
1// unit-test-argument-buffer-tier-2-reflection.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 metal argument buffer tier2 layout rules. 15 16SLANG_UNIT_TEST (metalArgumentBufferTier2Reflection ) 17{ 18const char * userSourceBody = R"( 19struct A 20{ 21float3 one; 22float3 two; 23float three; 24} 25 26struct Args{ 27ParameterBlock<A> a; 28} 29ParameterBlock<Args> argument_buffer; 30RWStructuredBuffer<float> outputBuffer; 31 32[numthreads(1,1,1)] 33void computeMain() 34{ 35outputBuffer[0] = argument_buffer.a.two.x; 36} 37)" ; 38 39auto moduleName = "moduleG" + String (Process ::getId ()); 40String userSource = "import " + moduleName + ";\n" + userSourceBody ; 41ComPtr < slang::IGlobalSession > globalSession ; 42SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 43 slang::TargetDesc targetDesc = {}; 44targetDesc .format = SLANG_SPIRV ; 45targetDesc .profile = globalSession -> findProfile ("spirv_1_5" ); 46 slang::SessionDesc sessionDesc = {}; 47sessionDesc .targetCount = 1 ; 48sessionDesc .targets = & targetDesc ; 49ComPtr < slang::ISession > session ; 50SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 51 52ComPtr < slang::IBlob > diagnosticBlob ; 53auto module = session -> loadModuleFromSourceString ( 54"m" , 55"m.slang" , 56userSourceBody , 57diagnosticBlob .writeRef ()); 58SLANG_CHECK (module != nullptr ); 59 60auto layout = module -> getLayout (); 61 62auto type = layout -> findTypeByName ("A" ); 63auto typeLayout = layout -> getTypeLayout (type , slang::LayoutRules ::MetalArgumentBufferTier2 ); 64SLANG_CHECK (typeLayout -> getFieldByIndex (0 )-> getOffset ()== 0 ); 65SLANG_CHECK (typeLayout -> getFieldByIndex (0 )-> getTypeLayout ()-> getSize ()== 16 ); 66SLANG_CHECK (typeLayout -> getFieldByIndex (1 )-> getOffset ()== 16 ); 67SLANG_CHECK (typeLayout -> getFieldByIndex (1 )-> getTypeLayout ()-> getSize ()== 16 ); 68SLANG_CHECK (typeLayout -> getFieldByIndex (2 )-> getOffset ()== 32 ); 69SLANG_CHECK (typeLayout -> getFieldByIndex (2 )-> getTypeLayout ()-> getSize ()== 4 ); 70}