diff options
Diffstat (limited to 'source')
| -rw-r--r-- | source/core/slang-random-generator.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-capability-defs.h | 17 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.cpp | 57 | ||||
| -rw-r--r-- | source/slang/slang-emit.cpp | 6 |
4 files changed, 60 insertions, 22 deletions
diff --git a/source/core/slang-random-generator.cpp b/source/core/slang-random-generator.cpp index ec06336f1..315678f0a 100644 --- a/source/core/slang-random-generator.cpp +++ b/source/core/slang-random-generator.cpp @@ -8,7 +8,7 @@ namespace Slang { float RandomGenerator::nextUnitFloat32() { int32_t intValue = nextInt32(); - return (intValue & 0x7fffffff) * (1.0f / 0x7fffffff); + return (intValue & 0x7fffffff) * (1.0f / float(0x7fffffff)); } bool RandomGenerator::nextBool() diff --git a/source/slang/slang-capability-defs.h b/source/slang/slang-capability-defs.h index 003fd3125..f66add15b 100644 --- a/source/slang/slang-capability-defs.h +++ b/source/slang/slang-capability-defs.h @@ -56,15 +56,18 @@ SLANG_CAPABILITY_ATOM0(C, c, Concrete,TargetFormat,0) SLANG_CAPABILITY_ATOM0(CPP, cpp, Concrete,TargetFormat,0) SLANG_CAPABILITY_ATOM0(CUDA, cuda, Concrete,TargetFormat,0) -// TODO: We should have multiple capabilities for the various SPIR-V versions, +// We have multiple capabilities for the various SPIR-V versions, // arranged so that they inherit from one another to represent which versions -// provide a super-set of the features of earlier ones (e.g., SPIR-V 1.4 should -// be expressed as inheriting from SPIR-V 1.3). +// provide a super-set of the features of earlier ones (e.g., SPIR-V 1.4 is +// expressed as inheriting from SPIR-V 1.3). // -// For now we are only including the version(s) that are relevant to the -// features controlled by the capability system. -// -SLANG_CAPABILITY_ATOM1(SPIRV_1_4, spirv_1_4, Concrete,None,0, GLSL) +SLANG_CAPABILITY_ATOM1(SPIRV, __spirv, Abstract,None,0, GLSL) +SLANG_CAPABILITY_ATOM1(SPIRV_1_0, spirv_1_0, Concrete,None,0, SPIRV) +SLANG_CAPABILITY_ATOM1(SPIRV_1_1, spirv_1_1, Concrete,None,0, SPIRV_1_0) +SLANG_CAPABILITY_ATOM1(SPIRV_1_2, spirv_1_2, Concrete,None,0, SPIRV_1_1) +SLANG_CAPABILITY_ATOM1(SPIRV_1_3, spirv_1_3, Concrete,None,0, SPIRV_1_2) +SLANG_CAPABILITY_ATOM1(SPIRV_1_4, spirv_1_4, Concrete,None,0, SPIRV_1_3) +SLANG_CAPABILITY_ATOM1(SPIRV_1_5, spirv_1_5, Concrete,None,0, SPIRV_1_4) // The following capabilities all pertain to how ray tracing shaders are translated // to GLSL, where there are two different extensions that can provide the core 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; diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index dc4709d11..c97412cf0 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -696,6 +696,10 @@ Result linkAndOptimizeIR( return SLANG_OK; } +void trackGLSLTargetCaps( + GLSLExtensionTracker* extensionTracker, + CapabilitySet const& caps); + SlangResult emitEntryPointsSourceFromIR( BackEndCompileRequest* compileRequest, const List<Int>& entryPointIndices, @@ -844,6 +848,8 @@ SlangResult emitEntryPointsSourceFromIR( if (auto glslExtensionTracker = as<GLSLExtensionTracker>(extensionTracker)) { + trackGLSLTargetCaps(glslExtensionTracker, targetRequest->getTargetCaps()); + StringBuilder builder; glslExtensionTracker->appendExtensionRequireLines(builder); sourceWriter.emit(builder.getUnownedSlice()); |
