yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4b9a34249
master
1// unit-test-geometry-shader.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 the compilation API for compiling geometry shaders to DXIL. 15 16#if SLANG_WINDOWS_FAMILY 17 18SLANG_UNIT_TEST (geometryShader ) 19{ 20const char * userSourceBody = R"( 21struct GS_INPUT 22{ 23float4 PosSS : TEXTURE0; // [Screen Space] Position 24}; 25 26struct PS_INPUT 27{ 28float4 PosSS : SV_POSITION; // [Screen Space] Position 29}; 30 31[maxvertexcount(3)] 32void main(triangle GS_INPUT input[3], inout TriangleStream<PS_INPUT> outStream) 33{ 34PS_INPUT output; 35 36output.PosSS = input[0].PosSS; 37outStream.Append(output); 3839 output.PosSS = input[1].PosSS; 40outStream.Append(output); 41 42output.PosSS = input[2].PosSS; 43outStream.Append(output); 44 45outStream.RestartStrip(); 46} 47)" ; 48ComPtr < slang::IGlobalSession > globalSession ; 49SlangGlobalSessionDesc globalDesc = {}; 50globalDesc .enableGLSL = true; 51SLANG_CHECK (slang_createGlobalSession2 (& globalDesc ,globalSession .writeRef ())== SLANG_OK ); 52 slang::TargetDesc targetDesc = {}; 53targetDesc .format = SLANG_DXIL ; 54targetDesc .profile = globalSession -> findProfile ("sm_6_0" ); 55 slang::SessionDesc sessionDesc = {}; 56sessionDesc .targetCount = 1 ; 57sessionDesc .targets = & targetDesc ; 58ComPtr < slang::ISession > session ; 59SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 60 61ComPtr < slang::IBlob > diagnosticBlob ; 62auto module = session -> loadModuleFromSourceString ( 63"m" , 64"m.slang" , 65userSourceBody , 66diagnosticBlob .writeRef ()); 67SLANG_CHECK (module != nullptr ); 68 69ComPtr < slang::IEntryPoint > entryPoint ; 70module -> findAndCheckEntryPoint ( 71"main" , 72SLANG_STAGE_GEOMETRY , 73entryPoint .writeRef (), 74diagnosticBlob .writeRef ()); 75 76 slang::IComponentType * componentTypes [2 ]= {module ,entryPoint .get ()}; 77ComPtr < slang::IComponentType > composedProgram ; 78session -> createCompositeComponentType ( 79componentTypes , 802 , 81composedProgram .writeRef (), 82diagnosticBlob .writeRef ()); 83 84ComPtr < slang::IComponentType > linkedProgram ; 85composedProgram -> link (linkedProgram .writeRef (),diagnosticBlob .writeRef ()); 86 87ComPtr < slang::IBlob > code ; 88linkedProgram -> getEntryPointCode (0 ,0 ,code .writeRef (),diagnosticBlob .writeRef ()); 89 90SLANG_CHECK (code != nullptr ); 91} 92 93#endif