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 /docs/user-guide/09-reflection.md | |
| 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 'docs/user-guide/09-reflection.md')
| -rw-r--r-- | docs/user-guide/09-reflection.md | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/docs/user-guide/09-reflection.md b/docs/user-guide/09-reflection.md index 8572dbe08..0c9311212 100644 --- a/docs/user-guide/09-reflection.md +++ b/docs/user-guide/09-reflection.md @@ -19,11 +19,6 @@ Note that just as with output code, the reflection object (and all other objects Unlike the other data, there is no easy way to save the reflection data for later user (we do not currently implement serialization for reflection data). Applications are encouraged to extract whatever information they need before destroying the compilation request. -For convenience (since the reflection API surface area is large), the Slang API provides a C++ wrapper interface around the reflection API, and this document will show code examples using those wrappers: - -```c++ -slang::ShaderReflection* shaderReflection = slang::ShaderReflection::get(request); -``` ## Program Reflection @@ -203,3 +198,30 @@ In the case of a compute shader entry point, you can also query the user-specifi SlangUInt threadGroupSize[3]; entryPoint->getComputeThreadGruopSize(3, &threadGroupSize[0]); ``` + +## Function Reflection + +The `slang::FunctionReflection` type provides methods to query information about a function, such as the return type, parameters and user-defined attributes. You can obtain a `FunctionReflection` object from an `IEntryPoint` with `IEntryPoint::getFunctionReflection`, which will provide more details on the entry point function. + +In addition to entry points, you can also query for ordinary functions with the `ShaderReflection::findFunctionByName` method: + +```c++ +auto funcReflection = program->getLayout()->findFunctionByName("ordinaryFunc"); + +// Get return type. +slang::TypeReflection* returnType = funcReflection->getReturnType(); + +// Get parameter count. +unsigned int paramCount = funcReflection->getParameterCount(); + +// Get Parameter. +slang::VariableReflection* param0 = funcReflection->getParameter(0); +const char* param0Name = param0->getName(); +slang::TypeReflection* param0Type = param0->getType(); + +// Get user defined attributes on the function. +unsigned int attribCount = funcReflection->getUserAttributeCount(); +slang::UserAttribute* attrib = funcReflection->getUserAttributeByIndex(0); +const char* attribName = attrib->getName(); + +```
\ No newline at end of file |
