diff options
Diffstat (limited to 'source/slang/slang-reflection-api.cpp')
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index b0d88e954..56a82e17e 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -4,6 +4,7 @@ #include "slang-check-impl.h" #include "slang-check.h" #include "slang-compiler.h" +#include "slang-deprecated.h" #include "slang-syntax.h" #include "slang-type-layout.h" #include "slang.h" @@ -568,20 +569,45 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex( SLANG_API size_t spReflectionType_GetElementCount(SlangReflectionType* inType) { + return spReflectionType_GetSpecializedElementCount(inType, nullptr); +} + +SLANG_API size_t spReflectionType_GetSpecializedElementCount( + SlangReflectionType* inType, + SlangReflection* reflection) +{ auto type = convert(inType); if (!type) return 0; + IntVal* elementCount; + bool isUnsized; if (auto arrayType = as<ArrayExpressionType>(type)) { - return !arrayType->isUnsized() ? (size_t)getIntVal(arrayType->getElementCount()) : 0; + elementCount = arrayType->getElementCount(); + isUnsized = arrayType->isUnsized(); } else if (auto vectorType = as<VectorExpressionType>(type)) { - return (size_t)getIntVal(vectorType->getElementCount()); + elementCount = vectorType->getElementCount(); + isUnsized = false; + } + else + { + return 0; } - return 0; + if (const auto program = convert(reflection)) + { + if (const auto componentType = program->getProgram()) + { + if (const auto c = componentType->tryFoldIntVal(elementCount)) + return c->getValue(); + } + } + + const auto isWithoutSize = isUnsized || elementCount->isLinkTimeVal(); + return isWithoutSize ? 0 : (size_t)getIntVal(elementCount); } SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionType* inType) @@ -1945,7 +1971,9 @@ struct ExtendedTypeLayoutContext LayoutSize elementCount = LayoutSize::infinite(); if (auto arrayType = as<ArrayExpressionType>(arrayTypeLayout->type)) { - if (!arrayType->isUnsized()) + const auto isWithoutSize = + arrayType->isUnsized() || arrayType->getElementCount()->isLinkTimeVal(); + if (!isWithoutSize) { elementCount = LayoutSize::RawValue(getIntVal(arrayType->getElementCount())); } |
