summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-reflection-api.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-15 23:28:28 -0700
committerGitHub <noreply@github.com>2024-04-15 23:28:28 -0700
commit3192f34f57abd3245995342a0a5971ebbbbd945c (patch)
treedc139be9fe9f4995bac96513571cc9e0526ce547 /source/slang/slang-reflection-api.cpp
parent030d7f45726187b5b23a3cfb9743166aa60fae30 (diff)
[GFX] Fix d3d12 buffer view creation logic for StructuredBuffers. (#3954)
Diffstat (limited to 'source/slang/slang-reflection-api.cpp')
-rw-r--r--source/slang/slang-reflection-api.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index 90103d8d9..ab73ce7f4 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -55,12 +55,12 @@ static inline SpecializationParamLayout* convert(SlangReflectionTypeParameter *
return (SpecializationParamLayout*) typeParam;
}
-static inline VarDeclBase* convert(SlangReflectionVariable* var)
+static inline Decl* convert(SlangReflectionVariable* var)
{
- return (VarDeclBase*) var;
+ return (Decl*) var;
}
-static inline SlangReflectionVariable* convert(VarDeclBase* var)
+static inline SlangReflectionVariable* convert(Decl* var)
{
return (SlangReflectionVariable*) var;
}
@@ -932,7 +932,7 @@ SLANG_API SlangInt spReflectionTypeLayout_findFieldIndexByName(SlangReflectionTy
for(Index f = 0; f < fieldCount; ++f)
{
auto field = structTypeLayout->fields[f];
- if(getReflectionName(field->varDecl.getDecl())->text.getUnownedSlice() == name)
+ if(getReflectionName(field->getVariable())->text.getUnownedSlice() == name)
return f;
}
}
@@ -1059,6 +1059,18 @@ SLANG_API SlangParameterCategory spReflectionTypeLayout_GetParameterCategory(Sla
return getParameterCategory(typeLayout);
}
+SLANG_API uint32_t spReflectionTypeLayout_GetFieldCount(SlangReflectionTypeLayout* inTypeLayout)
+{
+ auto typeLayout = convert(inTypeLayout);
+ if (!typeLayout) return 0;
+
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
+ {
+ return (uint32_t)structTypeLayout->fields.getCount();
+ }
+ return 0;
+}
+
SLANG_API unsigned spReflectionTypeLayout_GetCategoryCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
@@ -2508,6 +2520,9 @@ SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeDescriptorRangeSpaceO
SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* inVar)
{
auto var = convert(inVar);
+ if (as<InheritanceDecl>(var))
+ return "$base";
+
if(!var) return nullptr;
// If the variable is one that has an "external" name that is supposed
@@ -2521,14 +2536,19 @@ SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* inVa
SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVariable* inVar)
{
auto var = convert(inVar);
+
+ if (auto inheritanceDecl = as<InheritanceDecl>(var))
+ return convert(inheritanceDecl->base.type);
+
if(!var) return nullptr;
- return convert(var->getType());
+ return convert(as<VarDeclBase>(var)->getType());
}
SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* inVar, SlangModifierID modifierID)
{
auto var = convert(inVar);
+
if(!var) return nullptr;
Modifier* modifier = nullptr;
@@ -2571,7 +2591,7 @@ SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangR
auto varLayout = convert(inVarLayout);
if(!varLayout) return nullptr;
- return convert(varLayout->varDecl.getDecl());
+ return (SlangReflectionVariable*)(varLayout->varDecl.getDecl());
}
SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(SlangReflectionVariableLayout* inVarLayout)