From 5a0224a0773f6d7f5eae8515424af5fa8faa9c14 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 26 Sep 2024 09:44:08 -0700 Subject: Move texture format inference to frontend and add reflection api for it. (#5155) --- source/slang/slang-reflection-api.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (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 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(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()) + { + return (SlangImageFormat)formatAttrib->format; + } + return SLANG_IMAGE_FORMAT_unknown; +} + SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorSetIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index) { -- cgit v1.2.3