diff options
| author | Yong He <yonghe@outlook.com> | 2018-01-02 22:04:50 -0800 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-01-02 22:04:50 -0800 |
| commit | 1e0aabf4b28f48bfbfee7b1a9c08031892c004d0 (patch) | |
| tree | 2ad25a371def11f89cfd77e61116002d6d028bdd /source/slang/reflection.cpp | |
| parent | 66f9a7cefe351d7e0a27fa77fbfe5ca93f2d8133 (diff) | |
no-codegen compile flag and global generics reflection (#347)
* no-codegen compile flag and global generics reflection
1. Add SLANG_COMPILE_FLAG_NO_CODEGEN (-no-codegen) compiler flag to skip code generation stage, so that a shader that uses global generic type parmameters can be parsed, checked and introspected without knowing the final specialization.
2. Add reflection API to query for global generic type parameters, global parameters of generic type, and the generic type parameter index related to a global generic parameter.
3. Add a reflection test case for global generic type parameters.
* add expected result for global-type-params test case.
* fix reflection json output.
* fix branch condition errors
* fix expected result for global-type-params.slang
* fix expected test case output
Diffstat (limited to 'source/slang/reflection.cpp')
| -rw-r--r-- | source/slang/reflection.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index bd95f48fa..5270df8b4 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -39,6 +39,11 @@ static inline SlangReflectionTypeLayout* convert(TypeLayout* type) return (SlangReflectionTypeLayout*) type; } +static inline GenericParamLayout* convert(SlangReflectionTypeParameter * typeParam) +{ + return (GenericParamLayout*)typeParam; +} + static inline VarDeclBase* convert(SlangReflectionVariable* var) { return (VarDeclBase*) var; @@ -126,7 +131,6 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) { return SLANG_TYPE_KIND_RESOURCE; } - // TODO: need a better way to handle this stuff... #define CASE(TYPE) \ else if(type->As<TYPE>()) do { \ @@ -153,6 +157,14 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType) { return SLANG_TYPE_KIND_STRUCT; } + else if (auto genericParamType = declRef.As<GlobalGenericParamDecl>()) + { + return SLANG_TYPE_KIND_GENERIC_TYPE_PARAMETER; + } + else if (auto interfaceType = declRef.As<InterfaceDecl>()) + { + return SLANG_TYPE_KIND_INTERFACE; + } } else if (auto errorType = type->As<ErrorType>()) { @@ -848,7 +860,7 @@ namespace Slang return 0; } - + static VarLayout* getParameterByIndex(RefPtr<TypeLayout> typeLayout, unsigned index) { if(auto parameterGroupLayout = typeLayout.As<ParameterGroupTypeLayout>()) @@ -974,6 +986,33 @@ SLANG_API int spReflectionEntryPoint_usesAnySampleRateInput( return (entryPointLayout->flags & EntryPointLayout::Flag::usesAnySampleRateInput) != 0; } +// SlangReflectionTypeParameter +SLANG_API char const* spReflectionTypeParameter_GetName(SlangReflectionTypeParameter * inTypeParam) +{ + auto typeParam = convert(inTypeParam); + return typeParam->decl->getName()->text.Buffer(); +} + +SLANG_API unsigned spReflectionTypeParameter_GetIndex(SlangReflectionTypeParameter * inTypeParam) +{ + auto typeParam = convert(inTypeParam); + return (unsigned)(typeParam->index); +} + +SLANG_API unsigned int spReflectionTypeParameter_GetConstraintCount(SlangReflectionTypeParameter* inTypeParam) +{ + auto typeParam = convert(inTypeParam); + auto constraints = typeParam->decl->getMembersOfType<GenericTypeConstraintDecl>(); + return (unsigned int)constraints.Count(); +} + +SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex(SlangReflectionTypeParameter * inTypeParam, unsigned index) +{ + auto typeParam = convert(inTypeParam); + auto constraints = typeParam->decl->getMembersOfType<GenericTypeConstraintDecl>(); + return (SlangReflectionType*)constraints.ToArray()[index]->sup.Ptr(); +} + // Shader Reflection namespace Slang @@ -1006,6 +1045,27 @@ SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(SlangReflec return convert(globalStructLayout->fields[index].Ptr()); } +SLANG_API unsigned int spReflection_GetTypeParameterCount(SlangReflection * reflection) +{ + auto program = convert(reflection); + return (unsigned int)program->globalGenericParams.Count(); +} + +SLANG_API SlangReflectionTypeParameter* spReflection_GetTypeParameterByIndex(SlangReflection * reflection, unsigned int index) +{ + auto program = convert(reflection); + return (SlangReflectionTypeParameter*)program->globalGenericParams[index].Ptr(); +} + +SLANG_API SlangReflectionTypeParameter * spReflection_FindTypeParameter(SlangReflection * inProgram, char const * name) +{ + auto program = convert(inProgram); + if (!program) return nullptr; + GenericParamLayout * result = nullptr; + program->globalGenericParamsMap.TryGetValue(name, result); + return (SlangReflectionTypeParameter*)result; +} + SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* inProgram) { auto program = convert(inProgram); |
