Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add userAttribs to entryPoints in reflection JSON #6366

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/slang/slang-reflection-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection*
writer << "]";
}
}
static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* func)
{
auto attribCount = func->getUserAttributeCount();
if (attribCount)
{
writer << ",\n\"userAttribs\": [";
for (unsigned int i = 0; i < attribCount; i++)
{
if (i > 0)
writer << ",\n";
auto attrib = func->getUserAttributeByIndex(i);
emitUserAttributeJSON(writer, attrib);
}
writer << "]";
}
}

static void emitReflectionVarLayoutJSON(PrettyWriter& writer, slang::VariableLayoutReflection* var)
{
Expand Down Expand Up @@ -1091,6 +1107,8 @@ static void emitReflectionEntryPointJSON(
writer << "\n]";
}

emitUserAttributes(writer, entryPoint->getFunction());

writer.dedent();
writer << "\n}";
}
Expand Down
2 changes: 2 additions & 0 deletions tests/reflection/attribute.slang
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//TEST:REFLECTION:-stage compute -entry main -target hlsl -no-codegen

[__AttributeUsage(_AttributeTargets.Struct)]
[__AttributeUsage(_AttributeTargets.Function)]
struct MyStructAttribute
{
int iParam;
Expand Down Expand Up @@ -58,6 +59,7 @@ D param3;
[StructVarParam(1)] int globalInt2;


[MyStruct(2, 3.0)]
[numthreads(1, 1, 1)]
void main(
uint3 dispatchThreadID : SV_DispatchThreadID,
Expand Down
10 changes: 9 additions & 1 deletion tests/reflection/attribute.slang.expected
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,15 @@ standard output = {
}
}
],
"threadGroupSize": [1, 1, 1]
"threadGroupSize": [1, 1, 1],
"userAttribs": [{
"name": "MyStruct",
"arguments": [
2,
3.000000
]
}
]
}
]
}
Expand Down
Loading