summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-reflection-api.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-09-26 09:44:08 -0700
committerGitHub <noreply@github.com>2024-09-26 09:44:08 -0700
commit5a0224a0773f6d7f5eae8515424af5fa8faa9c14 (patch)
treeac14b54ad253d4ac5413a3c86254929f332b9e1a /source/slang/slang-reflection-api.cpp
parent7398e1e09312ed4e19195e060de9a2c9a073fcc1 (diff)
Move texture format inference to frontend and add reflection api for it. (#5155)
Diffstat (limited to 'source/slang/slang-reflection-api.cpp')
-rw-r--r--source/slang/slang-reflection-api.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index b6fc05986..fdcac94d7 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -2421,6 +2421,24 @@ SLANG_API SlangReflectionVariable* spReflectionTypeLayout_getBindingRangeLeafVar
return convert(DeclRef<Decl>(bindingRange.leafVariable));
}
+SLANG_API SlangImageFormat spReflectionTypeLayout_getBindingRangeImageFormat(SlangReflectionTypeLayout* typeLayout, SlangInt index)
+{
+ auto typeLayout_ = convert(typeLayout);
+ if (!typeLayout_) return SLANG_IMAGE_FORMAT_unknown;
+
+ auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout_);
+ if (index < 0) return SLANG_IMAGE_FORMAT_unknown;
+ if (index >= extTypeLayout->m_bindingRanges.getCount()) return SLANG_IMAGE_FORMAT_unknown;
+ auto& bindingRange = extTypeLayout->m_bindingRanges[index];
+
+ auto leafVar = bindingRange.leafVariable;
+ if (auto formatAttrib = leafVar->findModifier<FormatAttribute>())
+ {
+ return (SlangImageFormat)formatAttrib->format;
+ }
+ return SLANG_IMAGE_FORMAT_unknown;
+}
+
SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorSetIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
{