yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7b570feed
master
1// unit-test-default-matrix-layout.cpp 2 3#include "../../source/core/slang-list.h" 4#include "slang-com-helper.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 12namespace 13{ 14 15using namespace Slang ; 16 17struct DefaultMatrixLayoutTestContext 18{ 19DefaultMatrixLayoutTestContext (UnitTestContext * context ) 20 :m_unitTestContext (context ) 21 { 22 slang::IGlobalSession * slangSession = m_unitTestContext -> slangGlobalSession ; 23 } 24 25SlangResult runTests () 26 { 27 slang::IGlobalSession * slangSession = m_unitTestContext -> slangGlobalSession ; 28ComPtr < slang::ISession > session ; 29 slang::SessionDesc sessionDesc {}; 30sessionDesc .targetCount = 1 ; 31 slang::TargetDesc targetDesc {}; 32targetDesc .format = SLANG_GLSL ; 33targetDesc .profile = slangSession -> findProfile ("glsl_460" ); 34sessionDesc .targets = & targetDesc ; 35sessionDesc .defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR ; 36SLANG_RETURN_ON_FAIL (slangSession -> createSession (sessionDesc ,session .writeRef ())); 37 38auto module = session -> loadModuleFromSourceString ( 39"mymodule" , 40"mymodule.slang" , 41R"( 42RWStructuredBuffer<float> output; 43[numthreads(1,1,1)] [shader("compute")] 44void main(uniform float3x4 m) 45{ 46output[0] = m[0][0]; 47})" ); 48if (!module ) 49return SLANG_FAIL ; 50 51ComPtr < slang::IEntryPoint > entryPoint ; 52SLANG_RETURN_ON_FAIL (module -> findEntryPointByName ("main" ,entryPoint .writeRef ())); 53 54if (!entryPoint ) 55return SLANG_FAIL ; 56 57 slang::IComponentType * components []= {module ,entryPoint .get ()}; 58ComPtr < slang::IComponentType > composedProgram ; 59SLANG_RETURN_ON_FAIL ( 60session -> createCompositeComponentType (components ,2 ,composedProgram .writeRef ())); 61 62ComPtr < slang::IComponentType > linkedProgram ; 63SLANG_RETURN_ON_FAIL (composedProgram -> link (linkedProgram .writeRef ())); 64 65ComPtr < slang::IBlob > outCode ; 66SLANG_RETURN_ON_FAIL (linkedProgram -> getEntryPointCode (0 ,0 ,outCode .writeRef ())); 67 68const char * code = (const char * )outCode -> getBufferPointer (); 69if (strstr (code ,"row_major" )!= nullptr ) 70return SLANG_OK ; 71return SLANG_FAIL ; 72 } 73 74UnitTestContext * m_unitTestContext ; 75}; 76 77}// namespace 78 79SLANG_UNIT_TEST (defaultMatrixLayout ) 80{ 81DefaultMatrixLayoutTestContext context (unitTestContext ); 82 83const auto result = context .runTests (); 84 85SLANG_CHECK (SLANG_SUCCEEDED (result )); 86}