summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slang.h11
-rw-r--r--source/slang/reflection.cpp21
-rw-r--r--tests/reflection/std430-layout.glsl.expected1
-rw-r--r--tests/reflection/vertex-input-semantics.hlsl.expected4
-rw-r--r--tools/slang-reflection-test/main.cpp8
5 files changed, 44 insertions, 1 deletions
diff --git a/slang.h b/slang.h
index 6ccf04d83..67d364898 100644
--- a/slang.h
+++ b/slang.h
@@ -601,6 +601,8 @@ extern "C"
SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflectionType* type);
SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* type);
+ SLANG_API char const* spReflectionType_GetName(SlangReflectionType* type);
+
// Type Layout Reflection
SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(SlangReflectionTypeLayout* type);
@@ -801,6 +803,11 @@ namespace slang
{
return spReflectionType_GetResourceAccess((SlangReflectionType*) this);
}
+
+ char const* getName()
+ {
+ return spReflectionType_GetName((SlangReflectionType*) this);
+ }
};
enum ParameterCategory : SlangParameterCategory
@@ -924,6 +931,10 @@ namespace slang
return getType()->getResourceAccess();
}
+ char const* getName()
+ {
+ return getType()->getName();
+ }
};
struct VariableReflection
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index 3ed182750..9fc032c76 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -392,6 +392,27 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection
return SLANG_RESOURCE_ACCESS_NONE;
}
+SLANG_API char const* spReflectionType_GetName(SlangReflectionType* inType)
+{
+ auto type = convert(inType);
+
+ if( auto declRefType = type->As<DeclRefType>() )
+ {
+ auto declRef = declRefType->declRef;
+
+ // Don't return a name for auto-generated anonymous types
+ // that represent `cbuffer` members, etc.
+ auto decl = declRef.getDecl();
+ if(decl->HasModifier<ImplicitParameterGroupElementTypeModifier>())
+ return nullptr;
+
+ return getText(declRef.GetName()).begin();
+ }
+
+ return nullptr;
+}
+
+
SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* inType)
{
auto type = convert(inType);
diff --git a/tests/reflection/std430-layout.glsl.expected b/tests/reflection/std430-layout.glsl.expected
index bd04c417f..7c9c514d6 100644
--- a/tests/reflection/std430-layout.glsl.expected
+++ b/tests/reflection/std430-layout.glsl.expected
@@ -61,6 +61,7 @@ standard output = {
"name": "e",
"type": {
"kind": "struct",
+ "name": "Foo",
"fields": [
{
"name": "f",
diff --git a/tests/reflection/vertex-input-semantics.hlsl.expected b/tests/reflection/vertex-input-semantics.hlsl.expected
index 014533fdb..a3747a86a 100644
--- a/tests/reflection/vertex-input-semantics.hlsl.expected
+++ b/tests/reflection/vertex-input-semantics.hlsl.expected
@@ -30,6 +30,7 @@ standard output = {
"semanticName": "B",
"type": {
"kind": "struct",
+ "name": "B",
"fields": [
{
"name": "b0",
@@ -48,6 +49,7 @@ standard output = {
"name": "b1",
"type": {
"kind": "struct",
+ "name": "X",
"fields": [
{
"name": "x0",
@@ -91,11 +93,13 @@ standard output = {
"binding": {"kind": "vertexInput", "index": 4, "count": 3},
"type": {
"kind": "struct",
+ "name": "C",
"fields": [
{
"name": "c0",
"type": {
"kind": "struct",
+ "name": "X",
"fields": [
{
"name": "x0",
diff --git a/tools/slang-reflection-test/main.cpp b/tools/slang-reflection-test/main.cpp
index f604ca1aa..b0d970ba3 100644
--- a/tools/slang-reflection-test/main.cpp
+++ b/tools/slang-reflection-test/main.cpp
@@ -460,11 +460,17 @@ static void emitReflectionTypeLayoutInfoJSON(
case slang::TypeReflection::Kind::Struct:
{
+ auto structTypeLayout = typeLayout;
+
write(writer, "\"kind\": \"struct\",\n");
+ if( auto name = structTypeLayout->getName() )
+ {
+ emitReflectionNameInfoJSON(writer, structTypeLayout->getName());
+ write(writer, ",\n");
+ }
write(writer, "\"fields\": [\n");
indent(writer);
- auto structTypeLayout = typeLayout;
auto fieldCount = structTypeLayout->getFieldCount();
for( uint32_t ff = 0; ff < fieldCount; ++ff )
{