summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDevon <devonrutledge03@gmail.com>2025-03-20 00:38:52 -0600
committerGitHub <noreply@github.com>2025-03-20 06:38:52 +0000
commit30068d75fb97fecc163253fb331daddbb09234e6 (patch)
tree6e1a5b757db538a58c2397de4980618d280783d4 /source
parent404e95cdd02830ba0fb215081e826025609c4d14 (diff)
Make image format reflection easier (#6550)
* image format json reflection * format code * use direct include --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-reflection-api.cpp17
-rw-r--r--source/slang/slang-reflection-json.cpp10
2 files changed, 27 insertions, 0 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index 9295bfdf6..5dfa9d55a 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -3305,6 +3305,23 @@ SLANG_API size_t spReflectionVariableLayout_GetSpace(
return space;
}
+SLANG_API SlangImageFormat
+spReflectionVariableLayout_GetImageFormat(SlangReflectionVariableLayout* inVarLayout)
+{
+ auto varLayout = convert(inVarLayout);
+ if (!varLayout)
+ return SLANG_IMAGE_FORMAT_unknown;
+
+ if (auto leafVar = varLayout->getVariable())
+ {
+ if (auto formatAttrib = leafVar->findModifier<FormatAttribute>())
+ {
+ return (SlangImageFormat)formatAttrib->format;
+ }
+ }
+ return SLANG_IMAGE_FORMAT_unknown;
+}
+
SLANG_API char const* spReflectionVariableLayout_GetSemanticName(
SlangReflectionVariableLayout* inVarLayout)
{
diff --git a/source/slang/slang-reflection-json.cpp b/source/slang/slang-reflection-json.cpp
index 4e8b6b2a4..82e8e1e3f 100644
--- a/source/slang/slang-reflection-json.cpp
+++ b/source/slang/slang-reflection-json.cpp
@@ -2,6 +2,7 @@
#include "slang-reflection-json.h"
#include "../core/slang-blob.h"
+#include "slang-ast-support-types.h"
template<typename T>
struct Range
@@ -237,6 +238,15 @@ static void emitReflectionVarBindingInfoJSON(
writer << "\"semanticIndex\": " << int(semanticIndex);
}
}
+
+ if (auto format = var->getImageFormat())
+ {
+ writer.maybeComma();
+ auto formatName = getImageFormatInfo((Slang::ImageFormat)format).name;
+ writer << "\"format\": \"";
+ writer << formatName;
+ writer << "\"";
+ }
}
static void emitReflectionNameInfoJSON(PrettyWriter& writer, char const* name)