summaryrefslogtreecommitdiffstats
path: root/source/slang/reflection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/reflection.cpp')
-rw-r--r--source/slang/reflection.cpp64
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);