summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/lower.cpp2
-rw-r--r--source/slang/parameter-binding.cpp21
-rw-r--r--source/slang/reflection.cpp22
-rw-r--r--source/slang/type-layout.h8
4 files changed, 53 insertions, 0 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index 5708bab64..94738307b 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -3183,6 +3183,8 @@ struct LoweringVisitor
newFieldLayout->varDecl = fieldLayout->varDecl;
newFieldLayout->systemValueSemantic = fieldLayout->systemValueSemantic;
newFieldLayout->systemValueSemanticIndex = fieldLayout->systemValueSemanticIndex;
+ newFieldLayout->semanticName = fieldLayout->semanticName;
+ newFieldLayout->semanticIndex = fieldLayout->semanticIndex;
for (auto resInfo : fieldLayout->resourceInfos)
{
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 4fbec5652..fed838e6b 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -1190,6 +1190,27 @@ static RefPtr<TypeLayout> processEntryPointParameter(
EntryPointParameterState const& state,
RefPtr<VarLayout> varLayout)
{
+ // If there is an available semantic name and index,
+ // then we should apply it to this parameter unconditionally
+ // (that is, not just if it is a leaf parameter).
+ auto optSemanticName = state.optSemanticName;
+ if (optSemanticName && varLayout)
+ {
+ // Always store semantics in upper-case for
+ // reflection information, since they are
+ // supposed to be case-insensitive and
+ // upper-case is the dominant convention.
+ String semanticName = *optSemanticName;
+ String sn = semanticName.ToUpper();
+
+ auto semanticIndex = *state.ioSemanticIndex;
+
+ varLayout->semanticName = sn;
+ varLayout->semanticIndex = semanticIndex;
+ varLayout->flags |= VarLayoutFlag::HasSemantic;
+ }
+
+
// Scalar and vector types are treated as outputs directly
if(auto basicType = type->As<BasicExpressionType>())
{
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index 435b4db3f..d7e8820c0 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -623,6 +623,28 @@ SLANG_API size_t spReflectionVariableLayout_GetSpace(SlangReflectionVariableLayo
return info->space;
}
+SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflectionVariableLayout* inVarLayout)
+{
+ auto varLayout = convert(inVarLayout);
+ if(!varLayout) return 0;
+
+ if (!(varLayout->flags & Slang::VarLayoutFlag::HasSemantic))
+ return 0;
+
+ return varLayout->semanticName.Buffer();
+}
+
+SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* inVarLayout)
+{
+ auto varLayout = convert(inVarLayout);
+ if(!varLayout) return 0;
+
+ if (!(varLayout->flags & Slang::VarLayoutFlag::HasSemantic))
+ return 0;
+
+ return varLayout->semanticIndex;
+}
+
// Shader Parameter Reflection
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h
index 971088aac..d078d9554 100644
--- a/source/slang/type-layout.h
+++ b/source/slang/type-layout.h
@@ -218,6 +218,7 @@ typedef unsigned int VarLayoutFlags;
enum VarLayoutFlag : VarLayoutFlags
{
IsRedeclaration = 1 << 0, ///< This is a redeclaration of some shader parameter
+ HasSemantic = 1 << 1,
};
// A reified layout for a particular variable, field, etc.
@@ -241,6 +242,13 @@ public:
String systemValueSemantic;
int systemValueSemanticIndex;
+ // General cse semantic name and index
+ // TODO: this and the system-value field are redundant
+ // TODO: the `VarLayout` type is getting bloated; we need to not store this
+ // information unless actually required.
+ String semanticName;
+ int semanticIndex;
+
// The start register(s) for any resources
struct ResourceInfo
{