summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slang.h25
-rw-r--r--source/slang/reflection.cpp125
-rw-r--r--tests/reflection/arrays.hlsl.expected6
-rw-r--r--tests/reflection/gh-55.glsl.expected6
-rw-r--r--tests/reflection/global-uniforms.hlsl.expected6
-rw-r--r--tests/reflection/image-types.glsl.expected6
-rw-r--r--tests/reflection/multi-file.hlsl.expected10
-rw-r--r--tests/reflection/reflect-imported-code.hlsl.expected6
-rw-r--r--tests/reflection/reflection0.hlsl.expected6
-rw-r--r--tests/reflection/resource-in-cbuffer.hlsl.expected6
-rw-r--r--tests/reflection/std430-layout.glsl.expected6
11 files changed, 208 insertions, 0 deletions
diff --git a/slang.h b/slang.h
index f5da206ce..28940fd03 100644
--- a/slang.h
+++ b/slang.h
@@ -514,6 +514,16 @@ extern "C"
// Entry Point Reflection
+ SLANG_API char const* spReflectionEntryPoint_getName(
+ SlangReflectionEntryPoint* entryPoint);
+
+ SLANG_API unsigned spReflectionEntryPoint_getParameterCount(
+ SlangReflectionEntryPoint* entryPoint);
+
+ SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getParameterByIndex(
+ SlangReflectionEntryPoint* entryPoint,
+ unsigned index);
+
SLANG_API SlangStage spReflectionEntryPoint_getStage(SlangReflectionEntryPoint* entryPoint);
SLANG_API void spReflectionEntryPoint_getComputeThreadGroupSize(
@@ -857,6 +867,21 @@ namespace slang
struct EntryPointReflection
{
+ char const* getName()
+ {
+ return spReflectionEntryPoint_getName((SlangReflectionEntryPoint*) this);
+ }
+
+ unsigned getParameterCount()
+ {
+ return spReflectionEntryPoint_getParameterCount((SlangReflectionEntryPoint*) this);
+ }
+
+ VariableLayoutReflection* getParameterByIndex(unsigned index)
+ {
+ return (VariableLayoutReflection*) spReflectionEntryPoint_getParameterByIndex((SlangReflectionEntryPoint*) this, index);
+ }
+
SlangStage getStage()
{
return spReflectionEntryPoint_getStage((SlangReflectionEntryPoint*) this);
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index 08621d9a3..8e5044d13 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -651,8 +651,71 @@ SLANG_API unsigned spReflectionParameter_GetBindingSpace(SlangReflectionParamete
return 0;
}
+// Helpers for getting parameter count
+
+namespace Slang
+{
+ static unsigned getParameterCount(RefPtr<TypeLayout> typeLayout)
+ {
+ if(auto parameterBlockLayout = typeLayout.As<ParameterBlockTypeLayout>())
+ {
+ typeLayout = parameterBlockLayout->elementTypeLayout;
+ }
+
+ if(auto structLayout = typeLayout.As<StructTypeLayout>())
+ {
+ return (unsigned) structLayout->fields.Count();
+ }
+
+ return 0;
+ }
+
+ static VarLayout* getParameterByIndex(RefPtr<TypeLayout> typeLayout, unsigned index)
+ {
+ if(auto parameterBlockLayout = typeLayout.As<ParameterBlockTypeLayout>())
+ {
+ typeLayout = parameterBlockLayout->elementTypeLayout;
+ }
+
+ if(auto structLayout = typeLayout.As<StructTypeLayout>())
+ {
+ return structLayout->fields[index];
+ }
+
+ return 0;
+ }
+}
+
// Entry Point Reflection
+SLANG_API char const* spReflectionEntryPoint_getName(
+ SlangReflectionEntryPoint* inEntryPoint)
+{
+ auto entryPointLayout = convert(inEntryPoint);
+ if(!entryPointLayout) return 0;
+
+ return entryPointLayout->entryPoint->getName().begin();
+}
+
+SLANG_API unsigned spReflectionEntryPoint_getParameterCount(
+ SlangReflectionEntryPoint* inEntryPoint)
+{
+ auto entryPointLayout = convert(inEntryPoint);
+ if(!entryPointLayout) return 0;
+
+ return getParameterCount(entryPointLayout);
+}
+
+SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getParameterByIndex(
+ SlangReflectionEntryPoint* inEntryPoint,
+ unsigned index)
+{
+ auto entryPointLayout = convert(inEntryPoint);
+ if(!entryPointLayout) return 0;
+
+ return convert(getParameterByIndex(entryPointLayout, index));
+}
+
SLANG_API SlangStage spReflectionEntryPoint_getStage(SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
@@ -1395,6 +1458,49 @@ Range<T> range(T end)
return Range<T>(T(0), end);
}
+static void emitReflectionEntryPointJSON(
+ PrettyWriter& writer,
+ slang::EntryPointReflection* entryPoint)
+{
+ write(writer, "{\n");
+ indent(writer);
+
+ emitReflectionNameInfoJSON(writer, entryPoint->getName());
+
+ switch (entryPoint->getStage())
+ {
+ case SLANG_STAGE_VERTEX: write(writer, ",\n\"stage:\": \"vertex\""); break;
+ case SLANG_STAGE_HULL: write(writer, ",\n\"stage:\": \"hull\""); break;
+ case SLANG_STAGE_DOMAIN: write(writer, ",\n\"stage:\": \"domain\""); break;
+ case SLANG_STAGE_GEOMETRY: write(writer, ",\n\"stage:\": \"geometry\""); break;
+ case SLANG_STAGE_FRAGMENT: write(writer, ",\n\"stage:\": \"fragment\""); break;
+ case SLANG_STAGE_COMPUTE: write(writer, ",\n\"stage:\": \"compute\""); break;
+ default:
+ break;
+ }
+
+ auto parameterCount = entryPoint->getParameterCount();
+ if (parameterCount)
+ {
+ write(writer, ",\n\"parameters\": [\n");
+ indent(writer);
+
+ for( auto pp : range(parameterCount) )
+ {
+ if(pp != 0) write(writer, ",\n");
+
+ auto parameter = entryPoint->getParameterByIndex(pp);
+ emitReflectionParamJSON(writer, parameter);
+ }
+
+ dedent(writer);
+ write(writer, "\n]");
+ }
+
+ dedent(writer);
+ write(writer, "\n}");
+}
+
static void emitReflectionJSON(
PrettyWriter& writer,
slang::ShaderReflection* programReflection)
@@ -1415,6 +1521,25 @@ static void emitReflectionJSON(
dedent(writer);
write(writer, "\n]");
+
+ auto entryPointCount = programReflection->getEntryPointCount();
+ if (entryPointCount)
+ {
+ write(writer, ",\n\"entryPoints\": [\n");
+ indent(writer);
+
+ for (auto ee : range(entryPointCount))
+ {
+ if (ee != 0) write(writer, ",\n");
+
+ auto entryPoint = programReflection->getEntryPointByIndex(ee);
+ emitReflectionEntryPointJSON(writer, entryPoint);
+ }
+
+ dedent(writer);
+ write(writer, "\n]");
+ }
+
dedent(writer);
write(writer, "\n}\n");
}
diff --git a/tests/reflection/arrays.hlsl.expected b/tests/reflection/arrays.hlsl.expected
index 052bd3927..b586e362a 100644
--- a/tests/reflection/arrays.hlsl.expected
+++ b/tests/reflection/arrays.hlsl.expected
@@ -98,6 +98,12 @@ standard output = {
"kind": "samplerState"
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/gh-55.glsl.expected b/tests/reflection/gh-55.glsl.expected
index 8cdebdcd8..993984d93 100644
--- a/tests/reflection/gh-55.glsl.expected
+++ b/tests/reflection/gh-55.glsl.expected
@@ -40,6 +40,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/global-uniforms.hlsl.expected b/tests/reflection/global-uniforms.hlsl.expected
index b40b2d69c..e36665673 100644
--- a/tests/reflection/global-uniforms.hlsl.expected
+++ b/tests/reflection/global-uniforms.hlsl.expected
@@ -67,6 +67,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/image-types.glsl.expected b/tests/reflection/image-types.glsl.expected
index 19d28f329..dfe477287 100644
--- a/tests/reflection/image-types.glsl.expected
+++ b/tests/reflection/image-types.glsl.expected
@@ -22,6 +22,12 @@ standard output = {
"access": "readWrite"
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/multi-file.hlsl.expected b/tests/reflection/multi-file.hlsl.expected
index 38d028ffe..3dc23c11c 100644
--- a/tests/reflection/multi-file.hlsl.expected
+++ b/tests/reflection/multi-file.hlsl.expected
@@ -233,6 +233,16 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ },
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/reflect-imported-code.hlsl.expected b/tests/reflection/reflect-imported-code.hlsl.expected
index 1190ab550..78e7ce195 100644
--- a/tests/reflection/reflect-imported-code.hlsl.expected
+++ b/tests/reflection/reflect-imported-code.hlsl.expected
@@ -74,6 +74,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/reflection0.hlsl.expected b/tests/reflection/reflection0.hlsl.expected
index 3b74988b2..e4d6070ca 100644
--- a/tests/reflection/reflection0.hlsl.expected
+++ b/tests/reflection/reflection0.hlsl.expected
@@ -39,6 +39,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/resource-in-cbuffer.hlsl.expected b/tests/reflection/resource-in-cbuffer.hlsl.expected
index faae1c8b7..261fe2587 100644
--- a/tests/reflection/resource-in-cbuffer.hlsl.expected
+++ b/tests/reflection/resource-in-cbuffer.hlsl.expected
@@ -55,6 +55,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}
diff --git a/tests/reflection/std430-layout.glsl.expected b/tests/reflection/std430-layout.glsl.expected
index 701a36909..bd04c417f 100644
--- a/tests/reflection/std430-layout.glsl.expected
+++ b/tests/reflection/std430-layout.glsl.expected
@@ -102,6 +102,12 @@ standard output = {
}
}
}
+ ],
+ "entryPoints": [
+ {
+ "name": "main",
+ "stage:": "fragment"
+ }
]
}
}