yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
a5efbb1b7
master
1// unit-test-translation-unit-import.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 14static String getTypeFullName (slang::TypeReflection * type ) 15{ 16ComPtr < ISlangBlob > blob ; 17type -> getFullName (blob .writeRef ()); 18return String ((const char * )blob -> getBufferPointer ()); 19} 20 21static void printRefl (slang::DeclReflection * refl ,unsigned int level = 0 ) 22{ 23// Mapping of kind ids to names 24 std::string names []= {"Unsupported" ,"Struct" ,"Function" ,"Module" ,"Generic" ,"Variable" }; 25for (unsigned int i = 0 ;i < level ;i ++ ) 26 { 27 std::cout <<" " ; 28 } 29 std::cout <<"[" <<names [(unsigned int )refl -> getKind ()] <<"] (" <<refl -> getChildrenCount () 30 <<")" << std::endl ; 31 32for (auto * child :refl -> getChildren ()) 33 { 34printRefl (child ,level + 1 ); 35 } 36} 37 38// Test that the reflection API provides correct info about entry point and ordinary functions. 39 40SLANG_UNIT_TEST (declTreeReflection ) 41{ 42// Source for a module that contains an undecorated entrypoint. 43const char * userSourceBody = R"( 44[__AttributeUsage(_AttributeTargets.Function)] 45struct MyFuncPropertyAttribute {int v;} 46 47[MyFuncProperty(1024)] 48[Differentiable] 49float ordinaryFunc(no_diff float x, int y) { return x + y; } 50 51float4 fragMain(float4 pos:SV_Position) : SV_Position 52{ 53return pos; 54} 55 56uint f(uint y) { return y; } 57 58struct MyType 59{ 60int x; 61float f(float x) { return x; } 62} 63 64struct MyGenericType<T : IArithmetic & IFloat> 65{ 66T z; 67 68__init(T _z) { z = _z; } 6970 T g() { return z; } 71U h<U>(U x, out T y) { y = z; return x; } 72 73T j<let N : int>(T x, out int o) { o = N; return x; } 74 75U q<U>(U x, T y) { return x; } 76} 77 78namespace MyNamespace 79{ 80struct MyStruct 81{ 82int x; 83} 84} 85 86T foo<T, U>(T t, U u) { return t; } 87 88)" ; 89 90auto moduleName = "moduleG" + String (Process ::getId ()); 91String userSource = "import " + moduleName + ";\n" + userSourceBody ; 92ComPtr < slang::IGlobalSession > globalSession ; 93SLANG_CHECK (slang_createGlobalSession (SLANG_API_VERSION ,globalSession .writeRef ())== SLANG_OK ); 94 slang::TargetDesc targetDesc = {}; 95targetDesc .format = SLANG_HLSL ; 96targetDesc .profile = globalSession -> findProfile ("sm_5_0" ); 97 slang::SessionDesc sessionDesc = {}; 98sessionDesc .targetCount = 1 ; 99sessionDesc .targets = & targetDesc ; 100ComPtr < slang::ISession > session ; 101SLANG_CHECK (globalSession -> createSession (sessionDesc ,session .writeRef ())== SLANG_OK ); 102 103ComPtr < slang::IBlob > diagnosticBlob ; 104auto module = session -> loadModuleFromSourceString ( 105"m" , 106"m.slang" , 107userSourceBody , 108diagnosticBlob .writeRef ()); 109SLANG_CHECK (module != nullptr ); 110 111ComPtr < slang::IEntryPoint > entryPoint ; 112module -> findAndCheckEntryPoint ( 113"fragMain" , 114SLANG_STAGE_FRAGMENT , 115entryPoint .writeRef (), 116diagnosticBlob .writeRef ()); 117SLANG_CHECK (entryPoint != nullptr ); 118 119ComPtr < slang::IComponentType > compositeProgram ; 120 slang::IComponentType * components []= {module ,entryPoint .get ()}; 121session -> createCompositeComponentType ( 122components , 1232 , 124compositeProgram .writeRef (), 125diagnosticBlob .writeRef ()); 126SLANG_CHECK (compositeProgram != nullptr ); 127 128auto moduleDeclReflection = module -> getModuleReflection (); 129SLANG_CHECK (moduleDeclReflection != nullptr ); 130SLANG_CHECK (moduleDeclReflection -> getKind ()== slang::DeclReflection ::Kind ::Module ); 131SLANG_CHECK (moduleDeclReflection -> getChildrenCount ()== 9 ); 132 133// First declaration should be a struct with 1 variable and a synthesized constructor 134auto firstDecl = moduleDeclReflection -> getChild (0 ); 135SLANG_CHECK (firstDecl -> getKind ()== slang::DeclReflection ::Kind ::Struct ); 136SLANG_CHECK (firstDecl -> getChildrenCount ()== 2 ); 137 138 { 139 slang::TypeReflection * type = firstDecl -> getType (); 140SLANG_CHECK (getTypeFullName (type )== "MyFuncPropertyAttribute" ); 141 142// Check the field of the struct. 143SLANG_CHECK (type -> getFieldCount ()== 1 ); 144auto field = type -> getFieldByIndex (0 ); 145SLANG_CHECK (UnownedStringSlice (field -> getName ())== "v" ); 146SLANG_CHECK (getTypeFullName (field -> getType ())== "int" ); 147 } 148 149// Second declaration should be a function 150auto secondDecl = moduleDeclReflection -> getChild (1 ); 151SLANG_CHECK (secondDecl -> getKind ()== slang::DeclReflection ::Kind ::Func ); 152SLANG_CHECK ( 153secondDecl -> getChildrenCount ()== 1542 );// Parameter declarations are children (return type is not) 155 156 { 157auto funcReflection = secondDecl -> asFunction (); 158SLANG_CHECK (funcReflection -> findModifier (slang::Modifier ::Differentiable )!= nullptr ); 159SLANG_CHECK (getTypeFullName (funcReflection -> getReturnType ())== "float" ); 160SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "ordinaryFunc" ); 161SLANG_CHECK (funcReflection -> getParameterCount ()== 2 ); 162SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (0 )-> getName ())== "x" ); 163SLANG_CHECK (getTypeFullName (funcReflection -> getParameterByIndex (0 )-> getType ())== "float" ); 164SLANG_CHECK ( 165funcReflection -> getParameterByIndex (0 )-> findModifier (slang::Modifier ::NoDiff )!= 166nullptr ); 167 168SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (1 )-> getName ())== "y" ); 169SLANG_CHECK (getTypeFullName (funcReflection -> getParameterByIndex (1 )-> getType ())== "int" ); 170 171SLANG_CHECK (funcReflection -> getUserAttributeCount ()== 1 ); 172auto userAttribute = funcReflection -> getUserAttributeByIndex (0 ); 173SLANG_CHECK (UnownedStringSlice (userAttribute -> getName ())== "MyFuncProperty" ); 174SLANG_CHECK (userAttribute -> getArgumentCount ()== 1 ); 175SLANG_CHECK (getTypeFullName (userAttribute -> getArgumentType (0 ))== "int" ); 176int val = 0 ; 177auto result = userAttribute -> getArgumentValueInt (0 ,& val ); 178SLANG_CHECK (result == SLANG_OK ); 179SLANG_CHECK (val == 1024 ); 180SLANG_CHECK ( 181funcReflection -> findAttributeByName (globalSession .get (),"MyFuncProperty" )== 182userAttribute ); 183 } 184 185// Third declaration should also be a function 186auto thirdDecl = moduleDeclReflection -> getChild (2 ); 187SLANG_CHECK (thirdDecl -> getKind ()== slang::DeclReflection ::Kind ::Func ); 188SLANG_CHECK (thirdDecl -> getChildrenCount ()== 1 ); 189 190 { 191auto funcReflection = thirdDecl -> asFunction (); 192SLANG_CHECK (getTypeFullName (funcReflection -> getReturnType ())== "vector<float,4>" ); 193SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "fragMain" ); 194SLANG_CHECK (funcReflection -> getParameterCount ()== 1 ); 195SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (0 )-> getName ())== "pos" ); 196SLANG_CHECK ( 197getTypeFullName (funcReflection -> getParameterByIndex (0 )-> getType ())== 198"vector<float,4>" ); 199 } 200 201// Sixth declaration should be a generic struct 202auto sixthDecl = moduleDeclReflection -> getChild (5 ); 203SLANG_CHECK (sixthDecl -> getKind ()== slang::DeclReflection ::Kind ::Generic ); 204auto genericReflection = sixthDecl -> asGeneric (); 205SLANG_CHECK (genericReflection -> getTypeParameterCount ()== 1 ); 206auto typeParamT = genericReflection -> getTypeParameter (0 ); 207SLANG_CHECK (UnownedStringSlice (typeParamT -> getName ())== "T" ); 208auto typeParamTConstraintCount = genericReflection -> getTypeParameterConstraintCount (typeParamT ); 209SLANG_CHECK (typeParamTConstraintCount == 2 ); 210auto typeParamTConstraintType1 = 211genericReflection -> getTypeParameterConstraintType (typeParamT ,0 ); 212SLANG_CHECK (getTypeFullName (typeParamTConstraintType1 )== "IFloat" ); 213auto typeParamTConstraintType2 = 214genericReflection -> getTypeParameterConstraintType (typeParamT ,1 ); 215SLANG_CHECK (getTypeFullName (typeParamTConstraintType2 )== "IArithmetic" ); 216 217auto innerStruct = genericReflection -> getInnerDecl (); 218SLANG_CHECK (innerStruct -> getKind ()== slang::DeclReflection ::Kind ::Struct ); 219 220// Check that the seventh declaration is a namespace 221auto seventhDecl = moduleDeclReflection -> getChild (6 ); 222SLANG_CHECK (seventhDecl -> getKind ()== slang::DeclReflection ::Kind ::Namespace ); 223SLANG_CHECK (UnownedStringSlice (seventhDecl -> getName ())== "MyNamespace" ); 224 225 226// Check type-lookup-by-name 227 { 228auto type = compositeProgram -> getLayout ()-> findTypeByName ("MyType" ); 229SLANG_CHECK (type != nullptr ); 230// SLANG_CHECK(type->getKind() == slang::DeclReflection::Kind::Struct); 231SLANG_CHECK (UnownedStringSlice (type -> getName ())== "MyType" ); 232auto funcReflection = compositeProgram -> getLayout ()-> findFunctionByNameInType (type ,"f" ); 233SLANG_CHECK (funcReflection != nullptr ); 234SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "f" ); 235SLANG_CHECK (getTypeFullName (funcReflection -> getReturnType ())== "float" ); 236SLANG_CHECK (funcReflection -> getParameterCount ()== 1 ); 237SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (0 )-> getName ())== "x" ); 238SLANG_CHECK (getTypeFullName (funcReflection -> getParameterByIndex (0 )-> getType ())== "float" ); 239 } 240 241// Check type-lookup-by-name for generic type 242 { 243auto type = compositeProgram -> getLayout ()-> findTypeByName ("MyGenericType<half>" ); 244SLANG_CHECK (type != nullptr ); 245SLANG_CHECK (getTypeFullName (type )== "MyGenericType<half>" ); 246auto funcReflection = compositeProgram -> getLayout ()-> findFunctionByNameInType (type ,"g" ); 247SLANG_CHECK (funcReflection != nullptr ); 248SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "g" ); 249SLANG_CHECK (getTypeFullName (funcReflection -> getReturnType ())== "half" ); 250SLANG_CHECK (funcReflection -> getParameterCount ()== 0 ); 251 252auto varReflection = compositeProgram -> getLayout ()-> findVarByNameInType (type ,"z" ); 253SLANG_CHECK (varReflection != nullptr ); 254SLANG_CHECK (UnownedStringSlice (varReflection -> getName ())== "z" ); 255SLANG_CHECK (getTypeFullName (varReflection -> getType ())== "half" ); 256 257funcReflection = compositeProgram -> getLayout ()-> findFunctionByNameInType (type ,"h<float>" ); 258SLANG_CHECK (funcReflection != nullptr ); 259SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "h" ); 260SLANG_CHECK (getTypeFullName (funcReflection -> getReturnType ())== "float" ); 261SLANG_CHECK (funcReflection -> getParameterCount ()== 2 ); 262SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (0 )-> getName ())== "x" ); 263SLANG_CHECK (getTypeFullName (funcReflection -> getParameterByIndex (0 )-> getType ())== "float" ); 264SLANG_CHECK (UnownedStringSlice (funcReflection -> getParameterByIndex (1 )-> getName ())== "y" ); 265SLANG_CHECK (getTypeFullName (funcReflection -> getParameterByIndex (1 )-> getType ())== "half" ); 266 267// Access parent generic container from a specialized method. 268auto specializationInfo = funcReflection -> getGenericContainer (); 269SLANG_CHECK (specializationInfo != nullptr ); 270SLANG_CHECK (UnownedStringSlice (specializationInfo -> getName ())== "h" ); 271SLANG_CHECK ( 272specializationInfo -> asDecl ()-> getKind ()== slang::DeclReflection ::Kind ::Generic ); 273// Check type parameters 274SLANG_CHECK (specializationInfo -> getTypeParameterCount ()== 1 ); 275auto typeParam = specializationInfo -> getTypeParameter (0 ); 276SLANG_CHECK (UnownedStringSlice (typeParam -> getName ())== "U" );// generic name 277SLANG_CHECK ( 278getTypeFullName (specializationInfo -> getConcreteType (typeParam ))== 279"float" );// specialized type name under the context in which the generic is obtained 280SLANG_CHECK (specializationInfo -> getTypeParameterConstraintCount (typeParam )== 0 ); 281 282// Go up another level to the generic struct 283specializationInfo = specializationInfo -> getOuterGenericContainer (); 284SLANG_CHECK (specializationInfo != nullptr ); 285SLANG_CHECK (UnownedStringSlice (specializationInfo -> getName ())== "MyGenericType" ); 286SLANG_CHECK ( 287specializationInfo -> asDecl ()-> getKind ()== slang::DeclReflection ::Kind ::Generic ); 288// Check type parameters 289SLANG_CHECK (specializationInfo -> getTypeParameterCount ()== 1 ); 290typeParam = specializationInfo -> getTypeParameter (0 ); 291SLANG_CHECK (UnownedStringSlice (typeParam -> getName ())== "T" );// generic name 292SLANG_CHECK ( 293getTypeFullName (specializationInfo -> getConcreteType (typeParam ))== 294"half" );// specialized type name under the context in which the generic is obtained 295SLANG_CHECK (specializationInfo -> getTypeParameterConstraintCount (typeParam )== 2 ); 296 297// Query 'j' on the type 'half' 298funcReflection = compositeProgram -> getLayout ()-> findFunctionByNameInType (type ,"j<10>" ); 299SLANG_CHECK (funcReflection != nullptr ); 300SLANG_CHECK (UnownedStringSlice (funcReflection -> getName ())== "j" ); 301 302// Check the generic parameters 303specializationInfo = funcReflection -> getGenericContainer (); 304SLANG_CHECK (specializationInfo != nullptr ); 305SLANG_CHECK (UnownedStringSlice (specializationInfo -> getName ())== "j" ); 306SLANG_CHECK ( 307specializationInfo -> asDecl ()-> getKind ()== slang::DeclReflection ::Kind ::Generic ); 308SLANG_CHECK (specializationInfo -> getValueParameterCount ()== 1 ); 309auto valueParam = specializationInfo -> getValueParameter (0 ); 310SLANG_CHECK (UnownedStringSlice (valueParam -> getName ())== "N" );// generic name 311SLANG_CHECK (specializationInfo -> getConcreteIntVal (valueParam )== 10 ); 312 } 313 314// Check specializeGeneric() and applySpecializations() 315 { 316auto unspecializedType = compositeProgram -> getLayout ()-> findTypeByName ("MyGenericType" ); 317SLANG_CHECK (unspecializedType != nullptr ); 318auto halfType = compositeProgram -> getLayout ()-> findTypeByName ("half" ); 319SLANG_CHECK (halfType != nullptr ); 320 321 slang::GenericReflection * genericContainer = unspecializedType -> getGenericContainer (); 322SLANG_CHECK (genericContainer != nullptr ); 323// auto typeParamT = genericContainer->getTypeParameter(0); 324 325List < slang::GenericArgType > argTypes ; 326List < slang::GenericArgReflection > args ; 327argTypes .add (slang::GenericArgType ::SLANG_GENERIC_ARG_TYPE ); 328args .add ({halfType }); 329auto specializedContainer = compositeProgram -> getLayout ()-> specializeGeneric ( 330genericContainer , 331argTypes .getCount (), 332argTypes .getBuffer (), 333args .getBuffer (), 334nullptr ); 335 336SLANG_CHECK (specializedContainer != nullptr ); 337 338auto specializedType = unspecializedType -> applySpecializations (specializedContainer ); 339SLANG_CHECK (specializedType != nullptr ); 340SLANG_CHECK (getTypeFullName (specializedType )== "MyGenericType<half>" ); 341 } 342 343// Check specializeGeneric() and applySpecializations() on multiple levels (generic function 344// nested in a generic struct) 345 { 346auto unspecializedType = compositeProgram -> getLayout ()-> findTypeByName ("MyGenericType" ); 347auto unspecializedFunc = 348compositeProgram -> getLayout ()-> findFunctionByNameInType (unspecializedType ,"j" ); 349 350SLANG_CHECK (unspecializedFunc != nullptr ); 351auto halfType = compositeProgram -> getLayout ()-> findTypeByName ("half" ); 352SLANG_CHECK (halfType != nullptr ); 353 354 slang::GenericReflection * genericFuncContainer = unspecializedFunc -> getGenericContainer (); 355SLANG_CHECK (genericFuncContainer != nullptr ); 356 slang::GenericReflection * genericStructContainer = 357genericFuncContainer -> getOuterGenericContainer (); 358SLANG_CHECK (genericStructContainer != nullptr ); 359 360// Specialize the outer container with half 361List < slang::GenericArgType > argTypes ; 362List < slang::GenericArgReflection > args ; 363argTypes .add (slang::GenericArgType ::SLANG_GENERIC_ARG_TYPE ); 364args .add ({halfType }); 365auto specializedStructContainer = compositeProgram -> getLayout ()-> specializeGeneric ( 366genericStructContainer , 367argTypes .getCount (), 368argTypes .getBuffer (), 369args .getBuffer (), 370nullptr ); 371SLANG_CHECK (specializedStructContainer != nullptr ); 372 373// apply T=half. N is still left unspecialized. 374genericFuncContainer = 375genericFuncContainer -> applySpecializations (specializedStructContainer ); 376 377// Specialize the inner container with 10 separately.. 378argTypes .clear (); 379args .clear (); 380 381 slang::GenericArgReflection argN ; 382argN .intVal = 10 ; 383argTypes .add (slang::GenericArgType ::SLANG_GENERIC_ARG_INT ); 384args .add (argN ); 385 386auto specializedFuncContainer = compositeProgram -> getLayout ()-> specializeGeneric ( 387genericFuncContainer , 388argTypes .getCount (), 389argTypes .getBuffer (), 390args .getBuffer (), 391nullptr ); 392 393auto specializedFunc = unspecializedFunc -> applySpecializations (specializedFuncContainer ); 394SLANG_CHECK (specializedFunc != nullptr ); 395 396// ------ check the specialized function 397auto specializationInfo = specializedFunc -> getGenericContainer (); 398SLANG_CHECK (specializationInfo != nullptr ); 399SLANG_CHECK (UnownedStringSlice (specializationInfo -> getName ())== "j" ); 400SLANG_CHECK ( 401specializationInfo -> asDecl ()-> getKind ()== slang::DeclReflection ::Kind ::Generic ); 402SLANG_CHECK (specializationInfo -> getValueParameterCount ()== 1 ); 403auto valueParam = specializationInfo -> getValueParameter (0 ); 404SLANG_CHECK (UnownedStringSlice (valueParam -> getName ())== "N" );// generic name 405SLANG_CHECK (specializationInfo -> getConcreteIntVal (valueParam )== 10 ); 406 407// check outer container 408specializationInfo = specializationInfo -> getOuterGenericContainer (); 409SLANG_CHECK (specializationInfo != nullptr ); 410SLANG_CHECK (UnownedStringSlice (specializationInfo -> getName ())== "MyGenericType" ); 411SLANG_CHECK ( 412specializationInfo -> asDecl ()-> getKind ()== slang::DeclReflection ::Kind ::Generic ); 413// Check type parameters 414SLANG_CHECK (specializationInfo -> getTypeParameterCount ()== 1 ); 415auto typeParam = specializationInfo -> getTypeParameter (0 ); 416SLANG_CHECK (UnownedStringSlice (typeParam -> getName ())== "T" );// generic name 417SLANG_CHECK (getTypeFullName (specializationInfo -> getConcreteType (typeParam ))== "half" ); 418 } 419 420// Check sub-type relations 421 { 422auto floatType = compositeProgram -> getLayout ()-> findTypeByName ("float" ); 423SLANG_CHECK (floatType != nullptr ); 424auto diffType = compositeProgram -> getLayout ()-> findTypeByName ("IDifferentiable" ); 425SLANG_CHECK (diffType != nullptr ); 426 427SLANG_CHECK (compositeProgram -> getLayout ()-> isSubType (floatType ,diffType )== true); 428 429auto uintType = compositeProgram -> getLayout ()-> findTypeByName ("uint" ); 430SLANG_CHECK (compositeProgram -> getLayout ()-> isSubType (uintType ,diffType )== false); 431 } 432 433// Check specializeWithArgTypes() 434 { 435auto unspecializedFoo = compositeProgram -> getLayout ()-> findFunctionByName ("foo" ); 436SLANG_CHECK (unspecializedFoo != nullptr ); 437 438auto floatType = compositeProgram -> getLayout ()-> findTypeByName ("float" ); 439SLANG_CHECK (floatType != nullptr ); 440auto uintType = compositeProgram -> getLayout ()-> findTypeByName ("uint" ); 441SLANG_CHECK (uintType != nullptr ); 442 443List < slang::TypeReflection *> argTypes ; 444argTypes .add (floatType ); 445argTypes .add (uintType ); 446 447 slang::FunctionReflection * specializedFoo = 448unspecializedFoo -> specializeWithArgTypes (argTypes .getCount (),argTypes .getBuffer ()); 449SLANG_CHECK (specializedFoo != nullptr ); 450 451SLANG_CHECK (getTypeFullName (specializedFoo -> getReturnType ())== "float" ); 452SLANG_CHECK (specializedFoo -> getParameterCount ()== 2 ); 453 454SLANG_CHECK (UnownedStringSlice (specializedFoo -> getParameterByIndex (0 )-> getName ())== "t" ); 455SLANG_CHECK (getTypeFullName (specializedFoo -> getParameterByIndex (0 )-> getType ())== "float" ); 456 457SLANG_CHECK (UnownedStringSlice (specializedFoo -> getParameterByIndex (1 )-> getName ())== "u" ); 458SLANG_CHECK (getTypeFullName (specializedFoo -> getParameterByIndex (1 )-> getType ())== "uint" ); 459 } 460 461// Check specializeArgTypes on member method looked up through a specialized type 462 { 463auto specializedType = compositeProgram -> getLayout ()-> findTypeByName ("MyGenericType<half>" ); 464SLANG_CHECK (specializedType != nullptr ); 465 466auto unspecializedMethod = 467compositeProgram -> getLayout ()-> findFunctionByNameInType (specializedType ,"h" ); 468SLANG_CHECK (unspecializedMethod != nullptr ); 469 470// Specialize the method with float 471auto floatType = compositeProgram -> getLayout ()-> findTypeByName ("float" ); 472SLANG_CHECK (floatType != nullptr ); 473 474auto halfType = compositeProgram -> getLayout ()-> findTypeByName ("half" ); 475SLANG_CHECK (halfType != nullptr ); 476 477List < slang::TypeReflection *> argTypes ; 478argTypes .add (floatType ); 479argTypes .add (halfType ); 480 481auto specializedMethodWithFloat = 482unspecializedMethod -> specializeWithArgTypes (argTypes .getCount (),argTypes .getBuffer ()); 483SLANG_CHECK (specializedMethodWithFloat != nullptr ); 484SLANG_CHECK (getTypeFullName (specializedMethodWithFloat -> getReturnType ())== "float" ); 485 } 486 487// Check getTypeFullName() on nested objects. 488 { 489auto structType = compositeProgram -> getLayout ()-> findTypeByName ("MyNamespace::MyStruct" ); 490SLANG_CHECK (getTypeFullName (structType )== "MyNamespace.MyStruct" ); 491 } 492 493// Check iterators 494 { 495unsigned int count = 0 ; 496for (auto * child :moduleDeclReflection -> getChildren ()) 497 { 498count ++ ; 499 } 500SLANG_CHECK (count == 9 ); 501 502count = 0 ; 503for (auto * child : 504moduleDeclReflection -> getChildrenOfKind < slang::DeclReflection ::Kind ::Func > ()) 505 { 506count ++ ; 507 } 508SLANG_CHECK (count == 3 ); 509 510count = 0 ; 511for (auto * child : 512moduleDeclReflection -> getChildrenOfKind < slang::DeclReflection ::Kind ::Struct > ()) 513 { 514count ++ ; 515 } 516SLANG_CHECK (count == 2 ); 517 518count = 0 ; 519for (auto * child : 520moduleDeclReflection -> getChildrenOfKind < slang::DeclReflection ::Kind ::Generic > ()) 521 { 522count ++ ; 523 } 524SLANG_CHECK (count == 2 ); 525 526count = 0 ; 527for (auto * child : 528moduleDeclReflection -> getChildrenOfKind < slang::DeclReflection ::Kind ::Namespace > ()) 529 { 530count ++ ; 531 } 532SLANG_CHECK (count == 1 ); 533 } 534}