diff options
| author | Yong He <yonghe@outlook.com> | 2024-07-10 14:09:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-10 14:09:18 -0700 |
| commit | b89421cb3b803165455020f5b70d582b6aec6e76 (patch) | |
| tree | 461327ffbb55e7cea0ca73ae11cfa18425c904a8 /slang.h | |
| parent | 45ef0ce906c93c16495755fec2e597573e8631c4 (diff) | |
Add reflection API for functions. (#4587)
* Add reflection API for functions.
This change adds `SlangFunctionReflection` type in the reflection API that provides methods for querying function result type, parameters and user-defined attributes.
`ProgramLayout::findFunctionByName` can now find a function with the given name and returns a `FunctionReflection`.
`IEntryPoint` now has a `getFunctionReflection` method that returns an `FunctionReflection` for the entrypoint.
* More modifiers; make reflection API consistent.
Diffstat (limited to 'slang.h')
| -rw-r--r-- | slang.h | 97 |
1 files changed, 94 insertions, 3 deletions
@@ -2111,6 +2111,7 @@ extern "C" typedef struct SlangReflectionVariableLayout SlangReflectionVariableLayout; typedef struct SlangReflectionTypeParameter SlangReflectionTypeParameter; typedef struct SlangReflectionUserAttribute SlangReflectionUserAttribute; + typedef struct SlangReflectionFunction SlangReflectionFunction; /* Type aliases to maintain backward compatibility. @@ -2384,6 +2385,12 @@ extern "C" enum SlangModifierID : SlangModifierIDIntegral { SLANG_MODIFIER_SHARED, + SLANG_MODIFIER_NO_DIFF, + SLANG_MODIFIER_STATIC, + SLANG_MODIFIER_CONST, + SLANG_MODIFIER_EXPORT, + SLANG_MODIFIER_EXTERN, + SLANG_MODIFIER_DIFFERENTIABLE, }; // User Attribute @@ -2434,6 +2441,7 @@ extern "C" SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* type); SLANG_API char const* spReflectionType_GetName(SlangReflectionType* type); + SLANG_API SlangResult spReflectionType_GetFullName(SlangReflectionType* type, ISlangBlob** outNameBlob); // Type Layout Reflection @@ -2516,7 +2524,7 @@ extern "C" SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* var, SlangModifierID modifierID); SLANG_API unsigned int spReflectionVariable_GetUserAttributeCount(SlangReflectionVariable* var); SLANG_API SlangReflectionUserAttribute* spReflectionVariable_GetUserAttribute(SlangReflectionVariable* var, unsigned int index); - SLANG_API SlangReflectionUserAttribute* spReflectionVariable_FindUserAttributeByName(SlangReflectionVariable* var, SlangSession * session, char const* name); + SLANG_API SlangReflectionUserAttribute* spReflectionVariable_FindUserAttributeByName(SlangReflectionVariable* var, SlangSession * globalSession, char const* name); // Variable Layout Reflection @@ -2530,6 +2538,17 @@ extern "C" SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflectionVariableLayout* var); SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* var); + + // Function Reflection + + SLANG_API char const* spReflectionFunction_GetName(SlangReflectionFunction* func); + SLANG_API unsigned int spReflectionFunction_GetUserAttributeCount(SlangReflectionFunction* func); + SLANG_API SlangReflectionUserAttribute* spReflectionFunction_GetUserAttribute(SlangReflectionFunction* func, unsigned int index); + SLANG_API SlangReflectionUserAttribute* spReflectionFunction_FindUserAttributeByName(SlangReflectionFunction* func, SlangSession* globalSession, char const* name); + SLANG_API unsigned int spReflectionFunction_GetParameterCount(SlangReflectionFunction* func); + SLANG_API SlangReflectionVariable* spReflectionFunction_GetParameter(SlangReflectionFunction* func, unsigned index); + SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectionFunction* func); + /** Get the stage that a variable belongs to (if any). A variable "belongs" to a specific stage when it is a varying input/output @@ -2567,6 +2586,9 @@ extern "C" SLANG_API char const* spReflectionEntryPoint_getNameOverride( SlangReflectionEntryPoint* entryPoint); + SLANG_API SlangReflectionFunction* spReflectionEntryPoint_getFunction( + SlangReflectionEntryPoint* entryPoint); + SLANG_API unsigned spReflectionEntryPoint_getParameterCount( SlangReflectionEntryPoint* entryPoint); @@ -2615,6 +2637,8 @@ extern "C" SLANG_API SlangReflectionType* spReflection_FindTypeByName(SlangReflection* reflection, char const* name); SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout(SlangReflection* reflection, SlangReflectionType* reflectionType, SlangLayoutRules rules); + SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(SlangReflection* reflection, char const* name); + SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* reflection); SLANG_API SlangReflectionEntryPoint* spReflection_getEntryPointByIndex(SlangReflection* reflection, SlangUInt index); SLANG_API SlangReflectionEntryPoint* spReflection_findEntryPointByName(SlangReflection* reflection, char const* name); @@ -2830,6 +2854,11 @@ namespace slang return spReflectionType_GetName((SlangReflectionType*) this); } + SlangResult getFullName(ISlangBlob** outNameBlob) + { + return spReflectionType_GetFullName((SlangReflectionType*)this, outNameBlob); + } + unsigned int getUserAttributeCount() { return spReflectionType_GetUserAttributeCount((SlangReflectionType*)this); @@ -3255,6 +3284,12 @@ namespace slang enum ID : SlangModifierIDIntegral { Shared = SLANG_MODIFIER_SHARED, + NoDiff = SLANG_MODIFIER_NO_DIFF, + Static = SLANG_MODIFIER_STATIC, + Const = SLANG_MODIFIER_CONST, + Export = SLANG_MODIFIER_EXPORT, + Extern = SLANG_MODIFIER_EXTERN, + Differentiable = SLANG_MODIFIER_DIFFERENTIABLE, }; }; @@ -3283,9 +3318,9 @@ namespace slang { return (UserAttribute*)spReflectionVariable_GetUserAttribute((SlangReflectionVariable*)this, index); } - UserAttribute* findUserAttributeByName(SlangSession* session, char const* name) + UserAttribute* findUserAttributeByName(SlangSession* globalSession, char const* name) { - return (UserAttribute*)spReflectionVariable_FindUserAttributeByName((SlangReflectionVariable*)this, session, name); + return (UserAttribute*)spReflectionVariable_FindUserAttributeByName((SlangReflectionVariable*)this, globalSession, name); } }; @@ -3373,6 +3408,47 @@ namespace slang } }; + struct FunctionReflection + { + char const* getName() + { + return spReflectionFunction_GetName((SlangReflectionFunction*)this); + } + + TypeReflection* getReturnType() + { + return (TypeReflection*)spReflectionFunction_GetResultType((SlangReflectionFunction*)this); + } + + unsigned int getParameterCount() + { + return spReflectionFunction_GetParameterCount((SlangReflectionFunction*)this); + } + + VariableReflection* getParameterByIndex(unsigned int index) + { + return (VariableReflection*)spReflectionFunction_GetParameter((SlangReflectionFunction*)this, index); + } + + unsigned int getUserAttributeCount() + { + return spReflectionVariable_GetUserAttributeCount((SlangReflectionVariable*)this); + } + UserAttribute* getUserAttributeByIndex(unsigned int index) + { + return (UserAttribute*)spReflectionVariable_GetUserAttribute((SlangReflectionVariable*)this, index); + } + UserAttribute* findUserAttributeByName(SlangSession* globalSession, char const* name) + { + return (UserAttribute*)spReflectionVariable_FindUserAttributeByName((SlangReflectionVariable*)this, globalSession, name); + } + + Modifier* findModifier(Modifier::ID id) + { + return (Modifier*)spReflectionVariable_FindModifier((SlangReflectionVariable*)this, (SlangModifierID)id); + } + }; + struct EntryPointReflection { char const* getName() @@ -3390,6 +3466,11 @@ namespace slang return spReflectionEntryPoint_getParameterCount((SlangReflectionEntryPoint*) this); } + FunctionReflection* getFunction() + { + return (FunctionReflection*)spReflectionEntryPoint_getFunction((SlangReflectionEntryPoint*) this); + } + VariableLayoutReflection* getParameterByIndex(unsigned index) { return (VariableLayoutReflection*) spReflectionEntryPoint_getParameterByIndex((SlangReflectionEntryPoint*) this, index); @@ -3438,6 +3519,7 @@ namespace slang return spReflectionEntryPoint_hasDefaultConstantBuffer((SlangReflectionEntryPoint*) this) != 0; } }; + typedef EntryPointReflection EntryPointLayout; struct TypeParameterReflection @@ -3531,6 +3613,13 @@ namespace slang name); } + FunctionReflection* findFunctionByName(const char* name) + { + return (FunctionReflection*)spReflection_FindFunctionByName( + (SlangReflection*) this, + name); + } + TypeLayoutReflection* getTypeLayout( TypeReflection* type, LayoutRules rules = LayoutRules::Default) @@ -4966,6 +5055,8 @@ namespace slang struct IEntryPoint : public IComponentType { SLANG_COM_INTERFACE(0x8f241361, 0xf5bd, 0x4ca0, { 0xa3, 0xac, 0x2, 0xf7, 0xfa, 0x24, 0x2, 0xb8 }) + + virtual SLANG_NO_THROW FunctionReflection* SLANG_MCALL getFunctionReflection() = 0; }; #define SLANG_UUID_IEntryPoint IEntryPoint::getTypeGuid() |
