yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7b570feed
master
1// unit-test-image-format-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 that the getBindingRangeImageFormat API works. 15 16SLANG_UNIT_TEST (imageFormatReflection ) 17{ 18// Source for a module that contains an undecorated entrypoint. 19const char * userSourceBody = R"( 20Texture2D<uint4> g_tex : register(t0); 21float4 fragMain(float4 pos:SV_Position) : SV_Position 22{ 23return pos; 24} 25)" ; 26 27auto moduleName = "moduleG" + String (Process ::getId ()); 28String userSource = "import " + moduleName + ";\n" + userSourceBody ; 29ComPtr < slang::IGlobalSession > globalSession ; 30SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 31 slang::TargetDesc targetDesc = {}; 32targetDesc .format = SLANG_HLSL ; 33targetDesc .profile = globalSession -> findProfile ("sm_5_0" ); 34 slang::SessionDesc sessionDesc = {}; 35sessionDesc .targetCount = 1 ; 36sessionDesc .targets = & targetDesc ; 37ComPtr < slang::ISession > session ; 38SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 39 40ComPtr < slang::IBlob > diagnosticBlob ; 41auto module = session -> loadModuleFromSourceString ( 42"m" , 43"m.slang" , 44userSourceBody , 45diagnosticBlob .writeRef ()); 46SLANG_CHECK (module != nullptr ); 47 48ComPtr < slang::IEntryPoint > entryPoint ; 49module -> findAndCheckEntryPoint ( 50"fragMain" , 51SLANG_STAGE_FRAGMENT , 52entryPoint .writeRef (), 53diagnosticBlob .writeRef ()); 54SLANG_CHECK (entryPoint != nullptr ); 55 56ComPtr < slang::IComponentType > compositeProgram ; 57 slang::IComponentType * components []= {module ,entryPoint .get ()}; 58session -> createCompositeComponentType ( 59components , 602 , 61compositeProgram .writeRef (), 62diagnosticBlob .writeRef ()); 63SLANG_CHECK (compositeProgram != nullptr ); 64 65auto layout = compositeProgram -> getLayout (0 ); 66auto format = layout -> getGlobalParamsTypeLayout ()-> getBindingRangeImageFormat (0 ); 67SLANG_CHECK (format == SLANG_IMAGE_FORMAT_rgba32ui ); 68}