diff options
| author | Yong He <yonghe@outlook.com> | 2021-04-23 11:41:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-23 11:41:33 -0700 |
| commit | d1b0d5acb22cf8b6258b40c8690cd0c7e3989d3e (patch) | |
| tree | cc4e9a6ed28c522c5a3f39bbea4c7110936ec593 /source/slang/slang.cpp | |
| parent | ff1d19079fb789a4d64ee16b3212491fdff9bf9a (diff) | |
Add `ISession::getParameterBlockLayout()` (#1805)
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index c48701575..d315570f5 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -897,6 +897,37 @@ SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL Linkage::getTypeLayout( return asExternal(typeLayout); } +SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL Linkage::getParameterBlockLayout( + slang::TypeReflection* inType, + SlangInt targetIndex, + slang::LayoutRules rules, + ISlangBlob** outDiagnostics) +{ + auto type = asInternal(inType); + + if (targetIndex < 0 || targetIndex >= targets.getCount()) + return nullptr; + + auto target = targets[targetIndex]; + + // TODO: We need a way to pass through the layout rules + // that the user requested (e.g., constant buffers vs. + // structured buffer rules). Right now the API only + // exposes a single case, so this isn't a big deal. + // + SLANG_UNUSED(rules); + + auto typeLayout = target->getParameterBlockLayout(type); + + // TODO: We currently don't have a path for capturing + // errors that occur during layout (e.g., types that + // are invalid because of target-specific layout constraints). + // + SLANG_UNUSED(outDiagnostics); + + return asExternal(typeLayout); +} + SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::getTypeRTTIMangledName( slang::TypeReflection* type, ISlangBlob** outNameBlob) { @@ -1102,6 +1133,18 @@ TypeLayout* TargetRequest::getTypeLayout(Type* type) return result.Ptr(); } +TypeLayout* TargetRequest::getParameterBlockLayout(Type* type) +{ + ParameterBlockType* parameterBlockType = nullptr; + if (!parameterBlockTypes.TryGetValue(type, parameterBlockType)) + { + parameterBlockType = getLinkage()->getASTBuilder()->create<ParameterBlockType>(); + parameterBlockType->elementType = type; + parameterBlockTypes.Add(type, parameterBlockType); + } + return getTypeLayout(parameterBlockType); +} + // // TranslationUnitRequest |
