diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2021-01-05 09:00:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-05 09:00:00 -0800 |
| commit | b4f94629f225b837e7102acc337610c5d4d8a7c1 (patch) | |
| tree | cb75cc2059d517fa41dfe2954f2893e04fa6af3b /source/slang/slang.cpp | |
| parent | f5fffa90e936ab462b3842f9b2cfa996ae870fe4 (diff) | |
Use "capability" system to select VKRT extension (#1647)
* Use "capability" system to select VKRT extension
Slang currently supports translation of ray tracing shader code to Vulkan GLSL code that uses the `GL_NV_ray_tracing` extension. A multi-vendor equivalent of that extension has been released as `GL_EXT_ray_tracing` and we want Slang to support that extension as well.
At the simplest, making the change from one extension to the other is just a matter of changing a few strings, since it does not appear that anything of significance was changed at the GLSL level (or even in SPIR-V). Where this gets trickier is when we have users who want us to support *both* extensions, and to be able to switch between them.
The solution we've implemented here more or less amounts to:
* If you don't tell the compiler which extension to use, it will default to `GL_EXT_ray_tracing` (the newer multi-vendor one).
* If you explicitly want the older extension, you can opt into it using the `-profile` option or via a new API for explicitly adding capabilities to your target.
Making that work required a few different kinds of changes:
* The options parsing and public API needed ways to add optional capabilities to a target.
* During GLSL code emit, we can check the capabilities that were added to the target to see if the `GL_NV_ray_tracing` extension was explicitly enabled and, if not, default to using the `GL_EXT_ray_tracing` names for things. This step is needed because some of the modifiers/attributes involved in the extension have to be handled explicitly in the code generator rather than implicitly as part of mapping intrinsic functions.
* We add two different translations to the relevant operatiosn in the stdlib, one marked with each of the extensions. If profile/capability-based overload resolution can be relied on to pick the right one, this should Just Work.
* Next, a bunch of work had to go into making capability-based overloading Just Work for the purposes of this change. There's been a nearly complete reworking of the implementation of `CapabilitySet` here to make it more suitable for our needs.
* The tests that were using ray tracing translation for Vulkan needed to be updated. For some of them I updated their baselines to use `GL_EXT_ray_tracing` so that they can test the new path. For others, I updated the command line for the test case so that it explicitly opts into using `GL_NV_ray_tracing`. The result is that we have some coverage of each extension. I would have liked to have each test run in both modes, but our pass-through glslang support doesn't support `-D` options, so I couldn't take that step easily.
This change does *not* add support for `GL_EXT_ray_query`, the extension that supports "DXR 1.1" style queries under Vulkan. Adding support for that extension should hopefully be a smaller step because it doesn't have the same multiple-extensions issue.
This change does *not* address a lot of possible avenues for improvement or cleanup around the capability system. It focuses only on those changes that are necessary to make the ray tracing feature work and leaves the rest for future work.
* fixup: infinite loop
* Comment-only change to retrigger TC build
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index ef838b871..fbcc97c51 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -474,6 +474,12 @@ SLANG_NO_THROW SlangProfileID SLANG_MCALL Session::findProfile( return Slang::Profile::lookUp(name).raw; } +SLANG_NO_THROW SlangCapabilityID SLANG_MCALL Session::findCapability( + char const* name) +{ + return SlangCapabilityID(Slang::findCapabilityAtom(UnownedTerminatedStringSlice(name))); +} + SLANG_NO_THROW void SLANG_MCALL Session::setDownstreamCompilerPath( SlangPassThrough inPassThrough, char const* path) @@ -571,7 +577,7 @@ DownstreamCompiler* Session::getDefaultDownstreamCompiler(SourceLanguage sourceL Profile getEffectiveProfile(EntryPoint* entryPoint, TargetRequest* target) { auto entryPointProfile = entryPoint->getProfile(); - auto targetProfile = target->targetProfile; + auto targetProfile = target->getTargetProfile(); // Depending on the target *format* we might have to restrict the // profile family to one that makes sense. @@ -579,7 +585,7 @@ Profile getEffectiveProfile(EntryPoint* entryPoint, TargetRequest* target) // TODO: Some of this should really be handled as validation at // the front-end. People shouldn't be allowed to ask for SPIR-V // output with Shader Model 5.0... - switch(target->target) + switch(target->getTarget()) { default: break; @@ -747,9 +753,9 @@ void Linkage::addTarget( auto targetIndex = addTarget(CodeGenTarget(desc.format)); auto target = targets[targetIndex]; - target->floatingPointMode = FloatingPointMode(desc.floatingPointMode); - target->targetFlags = desc.flags; - target->targetProfile = Profile(desc.profile); + target->setFloatingPointMode(FloatingPointMode(desc.floatingPointMode)); + target->addTargetFlags(desc.flags); + target->setTargetProfile(Profile(desc.profile)); } #if 0 @@ -961,6 +967,12 @@ SlangResult Linkage::setMatrixLayoutMode( // TargetRequest // +TargetRequest::TargetRequest(Linkage* linkage, CodeGenTarget format) + : linkage(linkage) + , format(format) +{} + + Session* TargetRequest::getSession() { return linkage->getSessionImpl(); @@ -971,10 +983,17 @@ MatrixLayoutMode TargetRequest::getDefaultMatrixLayoutMode() return linkage->getDefaultMatrixLayoutMode(); } +void TargetRequest::addCapability(CapabilityAtom capability) +{ + rawCapabilities.add(capability); + cookedCapabilities = CapabilitySet::makeEmpty(); +} + + CapabilitySet TargetRequest::getTargetCaps() { - if(!targetCaps.isInvalid()) - return targetCaps; + if(!cookedCapabilities.isEmpty()) + return cookedCapabilities; // The full `CapabilitySet` for the target will be computed // from the combination of the code generation format, and @@ -996,7 +1015,7 @@ CapabilitySet TargetRequest::getTargetCaps() // are available where can be directly encoded on the declarations. List<CapabilityAtom> atoms; - switch(target) + switch(format) { case CodeGenTarget::GLSL: case CodeGenTarget::GLSL_Vulkan: @@ -1033,9 +1052,11 @@ CapabilitySet TargetRequest::getTargetCaps() default: break; } + for(auto atom : rawCapabilities) + atoms.add(atom); - targetCaps = CapabilitySet(atoms); - return targetCaps; + cookedCapabilities = CapabilitySet(atoms); + return cookedCapabilities; } @@ -2136,9 +2157,7 @@ int EndToEndCompileRequest::addEntryPoint( UInt Linkage::addTarget( CodeGenTarget target) { - RefPtr<TargetRequest> targetReq = new TargetRequest(); - targetReq->linkage = this; - targetReq->target = target; + RefPtr<TargetRequest> targetReq = new TargetRequest(this, target); Index result = targets.getCount(); targets.add(targetReq); @@ -3681,17 +3700,17 @@ int EndToEndCompileRequest::addCodeGenTarget(SlangCompileTarget target) void EndToEndCompileRequest::setTargetProfile(int targetIndex, SlangProfileID profile) { - getLinkage()->targets[targetIndex]->targetProfile = Profile(profile); + getLinkage()->targets[targetIndex]->setTargetProfile(Profile(profile)); } void EndToEndCompileRequest::setTargetFlags(int targetIndex, SlangTargetFlags flags) { - getLinkage()->targets[targetIndex]->targetFlags = flags; + getLinkage()->targets[targetIndex]->addTargetFlags(flags); } void EndToEndCompileRequest::setTargetFloatingPointMode(int targetIndex, SlangFloatingPointMode mode) { - getLinkage()->targets[targetIndex]->floatingPointMode = FloatingPointMode(mode); + getLinkage()->targets[targetIndex]->setFloatingPointMode(FloatingPointMode(mode)); } void EndToEndCompileRequest::setMatrixLayoutMode(SlangMatrixLayoutMode mode) @@ -3705,6 +3724,15 @@ void EndToEndCompileRequest::setTargetMatrixLayoutMode(int targetIndex, SlangMat setMatrixLayoutMode(mode); } +SlangResult EndToEndCompileRequest::addTargetCapability(SlangInt targetIndex, SlangCapabilityID capability) +{ + auto& targets = getLinkage()->targets; + if(targetIndex < 0 || targetIndex >= targets.getCount()) + return SLANG_E_INVALID_ARG; + targets[targetIndex]->addCapability(CapabilityAtom(capability)); + return SLANG_OK; +} + void EndToEndCompileRequest::setDebugInfoLevel(SlangDebugInfoLevel level) { getLinkage()->debugInfoLevel = DebugInfoLevel(level); |
