From 3192f34f57abd3245995342a0a5971ebbbbd945c Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 15 Apr 2024 23:28:28 -0700 Subject: [GFX] Fix d3d12 buffer view creation logic for StructuredBuffers. (#3954) --- source/slang/slang-reflection-api.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'source/slang/slang-reflection-api.cpp') 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(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(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(var)) + return convert(inheritanceDecl->base.type); + if(!var) return nullptr; - return convert(var->getType()); + return convert(as(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) -- cgit v1.2.3