From 115920406ebd747e02e1e6a8e4595f7d88eef0d9 Mon Sep 17 00:00:00 2001 From: Dietrich Geisler Date: Mon, 20 Jul 2020 14:53:23 -0400 Subject: Multiple Entry Point Backend (#1437) * Multiple Entry Point Backend This PR introduces changes to the IR linking, emitting, and options for multiple entry points. Specifically, this PR updates several locations to support a (potentially empty) list of entry points, adding list infrastructure and looping over entry points as appropriate. * Formatting change * Updated unknown target case to not require an entry point * Formatting and list consts updates Co-authored-by: Tim Foley --- source/slang/slang-emit.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 63bf8f054..72b2e07c5 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -165,7 +165,6 @@ struct LinkingAndOptimizationOptions CLikeSourceEmitter* sourceEmitter = nullptr; }; -// TODO(DG): A bit tricky; this needs to be generalized to multiple entry points Result linkAndOptimizeIR( BackEndCompileRequest* compileRequest, const List& entryPointIndices, @@ -194,7 +193,7 @@ Result linkAndOptimizeIR( target, targetProgram); auto irModule = outLinkedIR.module; - auto irEntryPoint = outLinkedIR.entryPoint; + auto irEntryPoints = outLinkedIR.entryPoints; #if 0 dumpIRIfEnabled(compileRequest, irModule, "LINKED"); @@ -341,8 +340,7 @@ Result linkAndOptimizeIR( } // TODO(DG): There are multiple DCE steps here, which need to be changed - // CHECK: how to these modules work? - // so that they don't just throw out any non-entry point code + // so that they don't just throw out any non-entry point code // Debugging code for IR transformations... #if 0 dumpIRIfEnabled(compileRequest, irModule, "SPECIALIZED"); @@ -611,10 +609,10 @@ Result linkAndOptimizeIR( { auto glslExtensionTracker = as(options.sourceEmitter->getExtensionTracker()); - legalizeEntryPointForGLSL( + legalizeEntryPointsForGLSL( session, irModule, - irEntryPoint, + irEntryPoints, compileRequest->getSink(), glslExtensionTracker); @@ -692,8 +690,7 @@ Result linkAndOptimizeIR( return SLANG_OK; } -// TODO(DG): This probably needs to be generalized to a list -SlangResult emitEntryPointSourceFromIR( +SlangResult emitEntryPointsSourceFromIR( BackEndCompileRequest* compileRequest, const List& entryPointIndices, CodeGenTarget target, @@ -705,10 +702,6 @@ SlangResult emitEntryPointSourceFromIR( auto sink = compileRequest->getSink(); auto program = compileRequest->getProgram(); - // Temporary assertion for checkpoint - SLANG_ASSERT(entryPointIndices.getCount() == 1); - auto entryPoint = program->getEntryPoint(entryPointIndices[0]); - auto lineDirectiveMode = compileRequest->getLineDirectiveMode(); // To try to make the default behavior reasonable, we will // always use C-style line directives (to give the user @@ -728,8 +721,12 @@ SlangResult emitEntryPointSourceFromIR( desc.compileRequest = compileRequest; desc.target = target; // TODO(DG): Can't assume a single entry point stage for multiple entry points - desc.entryPointStage = entryPoint->getStage(); - desc.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest); + if (entryPointIndices.getCount() == 1) + { + auto entryPoint = program->getEntryPoint(entryPointIndices[0]); + desc.entryPointStage = entryPoint->getStage(); + desc.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest); + } desc.sourceWriter = &sourceWriter; // Define here, because must be in scope longer than the sourceEmitter, as sourceEmitter might reference @@ -857,7 +854,7 @@ SlangResult emitEntryPointSourceFromIR( SlangResult emitSPIRVFromIR( BackEndCompileRequest* compileRequest, IRModule* irModule, - IRFunc* irEntryPoint, + const List& irEntryPoints, List& spirvOut); SlangResult emitSPIRVForEntryPointsDirectly( @@ -866,8 +863,6 @@ SlangResult emitSPIRVForEntryPointsDirectly( TargetRequest* targetRequest, List& spirvOut) { - // TODO(DG): Temporary assertion for checkpoint - SLANG_ASSERT(entryPointIndices.getCount() == 1); auto sink = compileRequest->getSink(); auto program = compileRequest->getProgram(); auto targetProgram = program->getTargetProgram(targetRequest); @@ -887,12 +882,12 @@ SlangResult emitSPIRVForEntryPointsDirectly( linkedIR); auto irModule = linkedIR.module; - auto irEntryPoint = linkedIR.entryPoint; + auto irEntryPoints = linkedIR.entryPoints; emitSPIRVFromIR( compileRequest, irModule, - irEntryPoint, + irEntryPoints, spirvOut); return SLANG_OK; -- cgit v1.2.3