Skip to content

Commit 7315b33

Browse files
authored
Add userAttribs to entryPoints in reflection JSON (#6366)
1 parent e9a63b2 commit 7315b33

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

source/slang/slang-reflection-json.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection*
328328
writer << "]";
329329
}
330330
}
331+
static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* func)
332+
{
333+
auto attribCount = func->getUserAttributeCount();
334+
if (attribCount)
335+
{
336+
writer << ",\n\"userAttribs\": [";
337+
for (unsigned int i = 0; i < attribCount; i++)
338+
{
339+
if (i > 0)
340+
writer << ",\n";
341+
auto attrib = func->getUserAttributeByIndex(i);
342+
emitUserAttributeJSON(writer, attrib);
343+
}
344+
writer << "]";
345+
}
346+
}
331347

332348
static void emitReflectionVarLayoutJSON(PrettyWriter& writer, slang::VariableLayoutReflection* var)
333349
{
@@ -1091,6 +1107,8 @@ static void emitReflectionEntryPointJSON(
10911107
writer << "\n]";
10921108
}
10931109

1110+
emitUserAttributes(writer, entryPoint->getFunction());
1111+
10941112
writer.dedent();
10951113
writer << "\n}";
10961114
}

tests/reflection/attribute.slang

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//TEST:REFLECTION:-stage compute -entry main -target hlsl -no-codegen
66

77
[__AttributeUsage(_AttributeTargets.Struct)]
8+
[__AttributeUsage(_AttributeTargets.Function)]
89
struct MyStructAttribute
910
{
1011
int iParam;
@@ -58,6 +59,7 @@ D param3;
5859
[StructVarParam(1)] int globalInt2;
5960

6061

62+
[MyStruct(2, 3.0)]
6163
[numthreads(1, 1, 1)]
6264
void main(
6365
uint3 dispatchThreadID : SV_DispatchThreadID,

tests/reflection/attribute.slang.expected

+9-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,15 @@ standard output = {
310310
}
311311
}
312312
],
313-
"threadGroupSize": [1, 1, 1]
313+
"threadGroupSize": [1, 1, 1],
314+
"userAttribs": [{
315+
"name": "MyStruct",
316+
"arguments": [
317+
2,
318+
3.000000
319+
]
320+
}
321+
]
314322
}
315323
]
316324
}

0 commit comments

Comments
 (0)