From b2ad8e99a82884bb157e1be76b1ad7eb0e481457 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 26 Aug 2021 10:30:35 -0700 Subject: Add API to control interface specialization. (#1925) --- source/slang/slang.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index ef6872e76..e62d2c9ae 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1043,6 +1043,33 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::getTypeConformanceWitnessSequent return SLANG_OK; } +SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createTypeConformanceComponentType( + slang::TypeReflection* type, + slang::TypeReflection* interfaceType, + slang::ITypeConformance** outConformanceComponentType, + SlangInt conformanceIdOverride, + ISlangBlob** outDiagnostics) +{ + RefPtr result; + DiagnosticSink sink; + try + { + SharedSemanticsContext sharedSemanticsContext(this, nullptr, &sink); + SemanticsVisitor visitor(&sharedSemanticsContext); + auto witness = + visitor.tryGetSubtypeWitness((Slang::Type*)type, (Slang::Type*)interfaceType); + if (auto subtypeWitness = as(witness)) + { + result = new TypeConformance(this, subtypeWitness, conformanceIdOverride, &sink); + } + } + catch (...) + {} + sink.getBlobIfNeeded(outDiagnostics); + *outConformanceComponentType = result.detach(); + return result ? SLANG_OK : SLANG_FAIL; +} + SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompileRequest( SlangCompileRequest** outCompileRequest) { @@ -3041,6 +3068,11 @@ struct EnumerateModulesVisitor : ComponentTypeVisitor { visitChildren(specialized); } + + void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE + { + SLANG_UNUSED(conformance); + } }; @@ -3079,6 +3111,11 @@ struct EnumerateIRModulesVisitor : ComponentTypeVisitor m_callback(specialized->getIRModule(), m_userData); } + + void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE + { + m_callback(conformance->getIRModule(), m_userData); + } }; void ComponentType::enumerateIRModules(EnumerateIRModulesCallback callback, void* userData) @@ -3401,6 +3438,11 @@ struct SpecializationArgModuleCollector : ComponentTypeVisitor { visitChildren(specialized); } + + void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE + { + SLANG_UNUSED(conformance); + } }; SpecializedComponentType::SpecializedComponentType( @@ -3616,7 +3658,10 @@ SpecializedComponentType::SpecializedComponentType( { visitChildren(composite, specializationInfo); } void visitSpecialized(SpecializedComponentType* specialized) SLANG_OVERRIDE { visitChildren(specialized); } - + void visitTypeConformance(TypeConformance* conformance) SLANG_OVERRIDE + { + SLANG_UNUSED(conformance); + } EntryPointMangledNameCollector(ASTBuilder* astBuilder): m_astBuilder(astBuilder) { -- cgit v1.2.3