summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-04-23 11:41:33 -0700
committerGitHub <noreply@github.com>2021-04-23 11:41:33 -0700
commitd1b0d5acb22cf8b6258b40c8690cd0c7e3989d3e (patch)
treecc4e9a6ed28c522c5a3f39bbea4c7110936ec593
parentff1d19079fb789a4d64ee16b3212491fdff9bf9a (diff)
Add `ISession::getParameterBlockLayout()` (#1805)
-rw-r--r--slang.h6
-rwxr-xr-xsource/slang/slang-compiler.h9
-rw-r--r--source/slang/slang.cpp43
3 files changed, 58 insertions, 0 deletions
diff --git a/slang.h b/slang.h
index df0a783be..673d93d1e 100644
--- a/slang.h
+++ b/slang.h
@@ -3933,6 +3933,12 @@ namespace slang
LayoutRules rules = LayoutRules::Default,
ISlangBlob** outDiagnostics = nullptr) = 0;
+ virtual SLANG_NO_THROW TypeLayoutReflection* SLANG_MCALL getParameterBlockLayout(
+ TypeReflection* elementType,
+ SlangInt targetIndex = 0,
+ LayoutRules rules = LayoutRules::Default,
+ ISlangBlob** outDiagnostics = nullptr) = 0;
+
/** Get the mangled name for a type RTTI object.
*/
virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTypeRTTIMangledName(
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index a3eac6fa6..e57c1683a 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1198,10 +1198,14 @@ namespace Slang
// TypeLayouts created on the fly by reflection API
Dictionary<Type*, RefPtr<TypeLayout>> typeLayouts;
+ Dictionary<Type*, ParameterBlockType*> parameterBlockTypes;
+
Dictionary<Type*, RefPtr<TypeLayout>>& getTypeLayouts() { return typeLayouts; }
TypeLayout* getTypeLayout(Type* type);
+ TypeLayout* getParameterBlockLayout(Type* type);
+
private:
Linkage* linkage = nullptr;
CodeGenTarget format = CodeGenTarget::Unknown;
@@ -1274,6 +1278,11 @@ namespace Slang
SlangInt targetIndex = 0,
slang::LayoutRules rules = slang::LayoutRules::Default,
ISlangBlob** outDiagnostics = nullptr) override;
+ SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL getParameterBlockLayout(
+ slang::TypeReflection* elementType,
+ SlangInt targetIndex = 0,
+ slang::LayoutRules rules = slang::LayoutRules::Default,
+ ISlangBlob** outDiagnostics = nullptr) override;
SLANG_NO_THROW SlangResult SLANG_MCALL getTypeRTTIMangledName(
slang::TypeReflection* type,
ISlangBlob** outNameBlob) override;
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