diff options
| -rw-r--r-- | slang.h | 27 | ||||
| -rw-r--r-- | source/slang/reflection.cpp | 20 | ||||
| -rw-r--r-- | tests/reflection/shared-modifier.hlsl | 12 | ||||
| -rw-r--r-- | tests/reflection/shared-modifier.hlsl.expected | 47 | ||||
| -rw-r--r-- | tools/slang-reflection-test/main.cpp | 18 |
5 files changed, 123 insertions, 1 deletions
@@ -497,6 +497,7 @@ extern "C" typedef struct SlangReflection SlangReflection; typedef struct SlangReflectionEntryPoint SlangReflectionEntryPoint; + typedef struct SlangReflectionModifier SlangReflectionModifier; typedef struct SlangReflectionType SlangReflectionType; typedef struct SlangReflectionTypeLayout SlangReflectionTypeLayout; typedef struct SlangReflectionVariable SlangReflectionVariable; @@ -643,6 +644,12 @@ extern "C" SLANG_LAYOUT_RULES_DEFAULT, }; + typedef SlangUInt32 SlangModifierID; + enum + { + SLANG_MODIFIER_SHARED, + }; + // Type Reflection SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* type); @@ -683,6 +690,8 @@ extern "C" SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* var); SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVariable* var); + SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* var, SlangModifierID modifierID); + // Variable Layout Reflection SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangReflectionVariableLayout* var); @@ -1034,6 +1043,14 @@ namespace slang } }; + struct Modifier + { + enum ID : SlangModifierID + { + Shared = SLANG_MODIFIER_SHARED, + }; + }; + struct VariableReflection { char const* getName() @@ -1045,6 +1062,11 @@ namespace slang { return (TypeReflection*) spReflectionVariable_GetType((SlangReflectionVariable*) this); } + + Modifier* findModifier(Modifier::ID id) + { + return (Modifier*) spReflectionVariable_FindModifier((SlangReflectionVariable*) this, (SlangModifierID) id); + } }; struct VariableLayoutReflection @@ -1059,6 +1081,11 @@ namespace slang return getVariable()->getName(); } + Modifier* findModifier(Modifier::ID id) + { + return getVariable()->findModifier(id); + } + TypeLayoutReflection* getTypeLayout() { return (TypeLayoutReflection*) spReflectionVariableLayout_GetTypeLayout((SlangReflectionVariableLayout*) this); diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index 65901d6af..20cd188de 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -681,6 +681,26 @@ SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVaria return convert(var->getType()); } +SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* inVar, SlangModifierID modifierID) +{ + auto var = convert(inVar); + if(!var) return nullptr; + + Modifier* modifier = nullptr; + switch( modifierID ) + { + case SLANG_MODIFIER_SHARED: + modifier = var->FindModifier<HLSLEffectSharedModifier>(); + break; + + default: + return nullptr; + } + + return (SlangReflectionModifier*) modifier; +} + + // Variable Layout Reflection SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangReflectionVariableLayout* inVarLayout) diff --git a/tests/reflection/shared-modifier.hlsl b/tests/reflection/shared-modifier.hlsl new file mode 100644 index 000000000..45a1dfac8 --- /dev/null +++ b/tests/reflection/shared-modifier.hlsl @@ -0,0 +1,12 @@ +// shared-modifier.hlsl +//TEST:REFLECTION:-profile ps_5_0 -target hlsl + +// Confirm that we expose the `shared` modifier in reflection data. + +Texture2D t; +shared SamplerState s; + +float4 main(float2 uv : UV) : SV_Target +{ + return t.Sample(s, uv); +}
\ No newline at end of file diff --git a/tests/reflection/shared-modifier.hlsl.expected b/tests/reflection/shared-modifier.hlsl.expected new file mode 100644 index 000000000..ddb982177 --- /dev/null +++ b/tests/reflection/shared-modifier.hlsl.expected @@ -0,0 +1,47 @@ +result code = 0 +standard error = { +} +standard output = { +{ + "parameters": [ + { + "name": "t", + "binding": {"kind": "shaderResource", "index": 0}, + "type": { + "kind": "resource", + "baseShape": "texture2D" + } + }, + { + "name": "s", + "shared": true, + "binding": {"kind": "samplerState", "index": 0}, + "type": { + "kind": "samplerState" + } + } + ], + "entryPoints": [ + { + "name": "main", + "stage:": "fragment", + "parameters": [ + { + "name": "uv", + "stage": "fragment", + "binding": {"kind": "varyingInput", "index": 0}, + "semanticName": "UV", + "type": { + "kind": "vector", + "elementCount": 2, + "elementType": { + "kind": "scalar", + "scalarType": "float32" + } + } + } + ] + } + ] +} +} diff --git a/tools/slang-reflection-test/main.cpp b/tools/slang-reflection-test/main.cpp index 90be8f5c7..b900f3f62 100644 --- a/tools/slang-reflection-test/main.cpp +++ b/tools/slang-reflection-test/main.cpp @@ -239,6 +239,16 @@ static void emitReflectionNameInfoJSON( write(writer, "\""); } +static void emitReflectionModifierInfoJSON( + PrettyWriter& writer, + slang::VariableReflection* var) +{ + if( var->findModifier(slang::Modifier::Shared) ) + { + write(writer, ",\n\"shared\": true"); + } +} + static void emitReflectionVarLayoutJSON( PrettyWriter& writer, slang::VariableLayoutReflection* var) @@ -252,6 +262,8 @@ static void emitReflectionVarLayoutJSON( write(writer, "\"type\": "); emitReflectionTypeLayoutJSON(writer, var->getTypeLayout()); + emitReflectionModifierInfoJSON(writer, var->getVariable()); + emitReflectionVarBindingInfoJSON(writer, var); dedent(writer); @@ -607,8 +619,10 @@ static void emitReflectionVarInfoJSON( slang::VariableReflection* var) { emitReflectionNameInfoJSON(writer, var->getName()); - write(writer, ",\n"); + emitReflectionModifierInfoJSON(writer, var); + + write(writer, ",\n"); write(writer, "\"type\": "); emitReflectionTypeJSON(writer, var->getType()); } @@ -622,6 +636,8 @@ static void emitReflectionParamJSON( emitReflectionNameInfoJSON(writer, param->getName()); + emitReflectionModifierInfoJSON(writer, param->getVariable()); + emitReflectionVarBindingInfoJSON(writer, param); write(writer, ",\n"); |
