diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2021-03-02 12:52:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-02 12:52:34 -0800 |
| commit | b81e8d4c8b718e97c6d6fc65b09850f19fb80502 (patch) | |
| tree | bc8d7100a53633abab5b659686ba597a56f0a680 /source/slang/slang-compiler.cpp | |
| parent | 837a155b3d33035ee0739858f4ab25c65048ad6c (diff) | |
Add command-line control over SPIR-V version (#1730)
* Add command-line control over SPIR-V version
By default the Slang compiler policy is usually to produce output with the fewest dependencies possible. If input code can be encoded as SPIR-V 1.0, that is what we will use by default. The catch here is that in some cases later SPIR-V versions introduced improvements to the encoding that can affect performance (e.g., around large global arrays of constants), so that a user might explicitly want to require a newer SPIR-V version (restricting the driver versions their code can work on) in the hopes of seeing better performance.
This change uses the system of capabilities that was previously introduced so that an option like `-profile glsl_450+spirv_1_5` can be used to explicitly request a specific SPIR-V version. Consistent with the existing implementation, the requested version will be taken as a minimum, and the final version might be higher based on other requirements (e.g., use of intrinsic functions that require a higher version).
The test case included here is a little iffy in terms of long-term maintanenace. It relies on having both a `.slang` file and a `.glsl` file that we compile with the same options and then compare the SPIR-V, but that means there is no direct testing that the output SPIR-V actually uses the necessary version. If we break the inference of SPIR-V versions for both the regular and pass-through paths at once, this test won't flag the problem. A better test is probably needed soon.
This change *only* adds support for controlling the SPIR-V version via capabilities specified via the command line or API. It would be nice to a future change to allow something like `[require(spirv_1_5)]` to be added to an entry point function to allow the user to embed their expectation/requirement into the source code.
* fixup: clang warning
Diffstat (limited to 'source/slang/slang-compiler.cpp')
| -rwxr-xr-x | source/slang/slang-compiler.cpp | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 993a4966e..2d0287613 100755 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -577,6 +577,45 @@ namespace Slang outCodeBuilder << fileContent << "\n"; } + static void _maybeCreatePassThroughExtensionTracker( + CodeGenTarget target, + EndToEndCompileRequest* endToEndReq, + SourceResult& outSource) + { + if(!isPassThroughEnabled(endToEndReq)) + return; + + if(target != CodeGenTarget::GLSL) + return; + + if(outSource.extensionTracker) + return; + + RefPtr<GLSLExtensionTracker> extensionTracker = new GLSLExtensionTracker(); + outSource.extensionTracker = extensionTracker; + } + + void trackGLSLTargetCaps( + GLSLExtensionTracker* extensionTracker, + CapabilitySet const& caps) + { + for( auto atom : caps.getExpandedAtoms() ) + { + switch( atom ) + { + default: + break; + + case CapabilityAtom::SPIRV_1_0: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 0)); break; + case CapabilityAtom::SPIRV_1_1: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 1)); break; + case CapabilityAtom::SPIRV_1_2: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 2)); break; + case CapabilityAtom::SPIRV_1_3: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 3)); break; + case CapabilityAtom::SPIRV_1_4: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 4)); break; + case CapabilityAtom::SPIRV_1_5: extensionTracker->requireSPIRVVersion(SemanticVersion(1, 5)); break; + } + } + } + SlangResult emitEntryPointsSource( BackEndCompileRequest* compileRequest, const List<Int>& entryPointIndices, @@ -602,6 +641,10 @@ namespace Slang StringBuilder codeBuilder; if (target == CodeGenTarget::GLSL) { + _maybeCreatePassThroughExtensionTracker(target, endToEndReq, outSource); + if(auto extensionTracker = as<GLSLExtensionTracker>(outSource.extensionTracker)) + trackGLSLTargetCaps(extensionTracker, targetReq->getTargetCaps()); + // Special case GLSL int translationUnitCounter = 0; for (auto sourceFile : translationUnit->getSourceFiles()) @@ -1633,20 +1676,6 @@ SlangResult dissassembleDXILUsingDXC( request.spirvVersion.minor = spirvLanguageVersion.m_minor; request.spirvVersion.patch = spirvLanguageVersion.m_patch; } - else - { - // HACK: look at the requested capabilities of the target, - // and see if they specify a SPIR-V version that we should - // pass down. - // - auto targetCaps = targetReq->getTargetCaps(); - if(targetCaps.implies(CapabilityAtom::SPIRV_1_4)) - { - request.spirvVersion.major = 1; - request.spirvVersion.minor = 4; - request.spirvVersion.patch = 0; - } - } request.outputFunc = outputFunc; request.outputUserData = &spirvOut; |
