Skip to content

Commit

Permalink
Fix reflection-test issue (shader-slang#4082) (shader-slang#4084)
Browse files Browse the repository at this point in the history
The reflection test doesn't print the user attributes decorating for
the variables, only types. Therefore, add the print for user attributes
of variables.
  • Loading branch information
kaizhangNV authored May 2, 2024
1 parent b490414 commit d53d793
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
13 changes: 11 additions & 2 deletions tests/reflection/attribute.slang
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ struct DefaultValueAttribute
int iParam;
};

[__AttributeUsage(_AttributeTargets.Param)]
struct DefaultFuncParamAttribute
{
int iParam;
};

[MyStruct(0, 1.0)]
struct A
{
Expand All @@ -35,8 +41,11 @@ struct B
ParameterBlock<A> param;
ParameterBlock<B> param2;

[DefaultValue(2)] int globalInt;

[numthreads(1, 1, 1)]
void main(
uint3 dispatchThreadID : SV_DispatchThreadID)
uint3 dispatchThreadID : SV_DispatchThreadID,
[DefaultFuncParam(3)] float a)
{
}
}
63 changes: 61 additions & 2 deletions tests/reflection/attribute.slang.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ standard output = {
"parameters": [
{
"name": "param",
"binding": {"kind": "constantBuffer", "index": 0},
"binding": {"kind": "constantBuffer", "index": 1},
"type": {
"kind": "parameterBlock",
"elementType": {
Expand All @@ -27,6 +27,13 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
},
"userAttribs": [{
"name": "DefaultValue",
"arguments": [
1
]
}
],
"binding": {"kind": "uniform", "offset": 4, "size": 4},
"userAttribs": [{
"name": "DefaultValue",
Expand Down Expand Up @@ -68,6 +75,13 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
},
"userAttribs": [{
"name": "DefaultValue",
"arguments": [
1
]
}
],
"binding": {"kind": "uniform", "offset": 4, "size": 4},
"userAttribs": [{
"name": "DefaultValue",
Expand All @@ -93,7 +107,7 @@ standard output = {
},
{
"name": "param2",
"binding": {"kind": "constantBuffer", "index": 1},
"binding": {"kind": "constantBuffer", "index": 2},
"type": {
"kind": "parameterBlock",
"elementType": {
Expand All @@ -114,6 +128,13 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
},
"userAttribs": [{
"name": "DefaultValue",
"arguments": [
2
]
}
],
"binding": {"kind": "uniform", "offset": 4, "size": 4},
"userAttribs": [{
"name": "DefaultValue",
Expand Down Expand Up @@ -155,6 +176,13 @@ standard output = {
"kind": "scalar",
"scalarType": "float32"
},
"userAttribs": [{
"name": "DefaultValue",
"arguments": [
2
]
}
],
"binding": {"kind": "uniform", "offset": 4, "size": 4},
"userAttribs": [{
"name": "DefaultValue",
Expand All @@ -177,6 +205,21 @@ standard output = {
"binding": {"kind": "uniform", "offset": 0, "size": 8}
}
}
},
{
"name": "globalInt",
"userAttribs": [{
"name": "DefaultValue",
"arguments": [
2
]
}
],
"binding": {"kind": "uniform", "offset": 0, "size": 4},
"type": {
"kind": "scalar",
"scalarType": "int32"
}
}
],
"entryPoints": [
Expand All @@ -195,6 +238,22 @@ standard output = {
"scalarType": "uint32"
}
}
},
{
"name": "a",
"userAttribs": [{
"name": "DefaultFuncParam",
"arguments": [
3
]
}
],
"stage": "compute",
"binding": {"kind": "varyingInput", "index": 0},
"type": {
"kind": "scalar",
"scalarType": "float32"
}
}
],
"threadGroupSize": [1, 1, 1]
Expand Down
4 changes: 4 additions & 0 deletions tools/slang-reflection-test/slang-reflection-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ static void emitReflectionNameInfoJSON(
writer.writeEscapedString(UnownedStringSlice(name));
}

static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* var);

static void emitReflectionModifierInfoJSON(
PrettyWriter& writer,
slang::VariableReflection* var)
Expand All @@ -440,6 +442,8 @@ static void emitReflectionModifierInfoJSON(
writer.maybeComma();
writer << "\"shared\": true";
}

emitUserAttributes(writer, var);
}

static void emitUserAttributeJSON(PrettyWriter& writer, slang::UserAttribute* userAttribute)
Expand Down

0 comments on commit d53d793

Please sign in to comment.