diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-01-08 14:45:06 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-08 14:45:06 -0800 |
| commit | 0a856f458ff9f17d76bc646d008602713c6c66d1 (patch) | |
| tree | 8b4642a374fb5b4d06411f2a9c383a6079a7426e /source | |
| parent | cae5ddd4a2c9343ec7367c9049c5cc0c8628a9c4 (diff) | |
Cover a few corner cases in reflection API (#1163)
This change adds some new entry points to the reflection API to cover corner cases that a majority of applications won't care about.
These are most likely to come up for users who want to make a complete copy of the Slang reflection information into a data format of their own design.
All of the information is stuff that we already computed as part of layout, and just hadn't exposed:
* Alignment information for type layouts. This is only useful for ordinary/uniform data; in all other cases alignment is always one. Even for uniform/ordinary data, it is unlikely that any application would actually make use of it.
* Layout information for the result of an entry point function. This would be useful for applications that need to enumerate the varying outputs (user- or system-defined) of a shader. Having information available for `out` parameters but not the function result was inconsistent.
* The "element type" of a parameter block type (e.g., going from `ParameterBlock<X>` to `X`). This seems to have been an oversight since `ConstantBuffer<X>` appears to have been implemented, and the case for a type *layout* was handled.
* The "container" variable layout for a parameter block or constant buffer. It took a while for us to arrive at the current representation of layout for parameter groups, and most client code continues to use the original API that requires us to generated kludged "do what I mean" data. However, if we don't expose the more useful new representation fully, there is no way for users to take advantage of it!
The reflection test tool has been updated to print the new information where it makes sense, which provides us some level of coverage for the new code.
Unfortunately, this led to some cascading changes:
* First, a bunch of the tests had their output changed since they include new information. That's the easy bit.
* Next, the "container" and "element" var layouts don't actually have names (because there is no actual variable underlying them), which means that the code to emit variable names in the JSON dump needed to be condition.
* Making the `"name"` output conditional messed up a lot of the delicate logic that had been dealing with when to emit commas for the output JSON (JSON uses commas as separators, and doesn't allow trailing commas). I added a bit of new infrastructure to make it simple(-ish) to track when a comma actually needs to be output.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-reflection.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index 8901f6bdd..c0c5bd72f 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -357,9 +357,9 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy { return (SlangReflectionType*) arrayType->baseType.Ptr(); } - else if( auto constantBufferType = as<ConstantBufferType>(type)) + else if( auto parameterGroupType = as<ParameterGroupType>(type)) { - return convert(constantBufferType->elementType.Ptr()); + return convert(parameterGroupType->elementType.Ptr()); } else if( auto vectorType = as<VectorExpressionType>(type)) { @@ -680,6 +680,21 @@ SLANG_API size_t spReflectionTypeLayout_GetSize(SlangReflectionTypeLayout* inTyp return getReflectionSize(info->count); } +SLANG_API int32_t spReflectionTypeLayout_getAlignment(SlangReflectionTypeLayout* inTypeLayout, SlangParameterCategory category) +{ + auto typeLayout = convert(inTypeLayout); + if(!typeLayout) return 0; + + if( category == SLANG_PARAMETER_CATEGORY_UNIFORM ) + { + return int32_t(typeLayout->uniformAlignment); + } + else + { + return 1; + } +} + SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetFieldByIndex(SlangReflectionTypeLayout* inTypeLayout, unsigned index) { auto typeLayout = convert(inTypeLayout); @@ -758,9 +773,22 @@ SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetElementVarLay auto typeLayout = convert(inTypeLayout); if(!typeLayout) return nullptr; - if( auto constantBufferTypeLayout = as<ParameterGroupTypeLayout>(typeLayout)) + if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout)) { - return convert(constantBufferTypeLayout->elementVarLayout.Ptr()); + return convert(parameterGroupTypeLayout->elementVarLayout.Ptr()); + } + + return nullptr; +} + +SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getContainerVarLayout(SlangReflectionTypeLayout* inTypeLayout) +{ + auto typeLayout = convert(inTypeLayout); + if(!typeLayout) return nullptr; + + if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout)) + { + return convert(parameterGroupTypeLayout->containerVarLayout.Ptr()); } return nullptr; @@ -1300,6 +1328,17 @@ SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getVarLayout( return convert(entryPointLayout->parametersLayout); } +SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getResultVarLayout( + SlangReflectionEntryPoint* inEntryPoint) +{ + auto entryPointLayout = convert(inEntryPoint); + if(!entryPointLayout) + return nullptr; + + return convert(entryPointLayout->resultLayout); +} + + static bool hasDefaultConstantBuffer(ScopeLayout* layout) { auto typeLayout = layout->parametersLayout->getTypeLayout(); |
