diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-05-17 17:27:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-17 17:27:12 -0400 |
| commit | 05c4c2679ae979cfcb61e4c2acdb432c34384ddb (patch) | |
| tree | da146d2f90a28319a32bcb27ea33acec21537265 /source/slang/slang-emit-glsl.cpp | |
| parent | 39fb45484996f9d71b6551239dbf55eaaaf8db1f (diff) | |
Refactor prelude emit (#2236)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Refactor how prelude output works in emit.
* Small improvement to emit output.
* Move around comment on target specific language directives based on review.
Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-emit-glsl.cpp')
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 7578a2dd5..d9c81f14b 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -12,6 +12,10 @@ namespace Slang { +void trackGLSLTargetCaps( + GLSLExtensionTracker* extensionTracker, + CapabilitySet const& caps); + GLSLSourceEmitter::GLSLSourceEmitter(const Desc& desc) : Super(desc) { @@ -1740,7 +1744,33 @@ void GLSLSourceEmitter::handleRequiredCapabilitiesImpl(IRInst* inst) } } -void GLSLSourceEmitter::emitPreprocessorDirectivesImpl() +static Index _getGLSLVersion(ProfileVersion profile) +{ + switch (profile) + { +#define CASE(TAG, VALUE) case ProfileVersion::TAG: return VALUE; + CASE(GLSL_110, 110); + CASE(GLSL_120, 120); + CASE(GLSL_130, 130); + CASE(GLSL_140, 140); + CASE(GLSL_150, 150); + CASE(GLSL_330, 330); + CASE(GLSL_400, 400); + CASE(GLSL_410, 410); + CASE(GLSL_420, 420); + CASE(GLSL_430, 430); + CASE(GLSL_440, 440); + CASE(GLSL_450, 450); + CASE(GLSL_460, 460); +#undef CASE + + default: + break; + } + return -1; +} + +void GLSLSourceEmitter::emitFrontMatterImpl(TargetRequest* targetReq) { auto effectiveProfile = m_effectiveProfile; if (effectiveProfile.getFamily() == ProfileFamily::GLSL) @@ -1759,44 +1789,34 @@ void GLSLSourceEmitter::emitPreprocessorDirectivesImpl() // the user to specify a version as part of the target. m_glslExtensionTracker->requireVersion(ProfileVersion::GLSL_450); - auto requiredProfileVersion = m_glslExtensionTracker->getRequiredProfileVersion(); - switch (requiredProfileVersion) + Index glslVersion = _getGLSLVersion(m_glslExtensionTracker->getRequiredProfileVersion()); + if (glslVersion < 0) { -#define CASE(TAG, VALUE) \ -case ProfileVersion::TAG: m_writer->emit("#version " #VALUE "\n"); return - - CASE(GLSL_110, 110); - CASE(GLSL_120, 120); - CASE(GLSL_130, 130); - CASE(GLSL_140, 140); - CASE(GLSL_150, 150); - CASE(GLSL_330, 330); - CASE(GLSL_400, 400); - CASE(GLSL_410, 410); - CASE(GLSL_420, 420); - CASE(GLSL_430, 430); - CASE(GLSL_440, 440); - CASE(GLSL_450, 450); - CASE(GLSL_460, 460); -#undef CASE + // No information is available for us to guess a profile, + // so it seems like we need to pick one out of thin air. + // + // Ideally we should infer a minimum required version based + // on the constructs we have seen used in the user's code + // + // For now we just fall back to a reasonably recent version. - default: - break; + glslVersion = 420; } - // No information is available for us to guess a profile, - // so it seems like we need to pick one out of thin air. - // - // Ideally we should infer a minimum required version based - // on the constructs we have seen used in the user's code - // - // For now we just fall back to a reasonably recent version. + m_writer->emit("#version "); + m_writer->emit(glslVersion); + m_writer->emit("\n"); - m_writer->emit("#version 420\n"); -} + // Output the extensions + if (m_glslExtensionTracker) + { + trackGLSLTargetCaps(m_glslExtensionTracker, targetReq->getTargetCaps()); + + StringBuilder builder; + m_glslExtensionTracker->appendExtensionRequireLines(builder); + m_writer->emit(builder.getUnownedSlice()); + } -void GLSLSourceEmitter::emitLayoutDirectivesImpl(TargetRequest* targetReq) -{ // Reminder: the meaning of row/column major layout // in our semantics is the *opposite* of what GLSL // calls them, because what they call "columns" @@ -1804,16 +1824,16 @@ void GLSLSourceEmitter::emitLayoutDirectivesImpl(TargetRequest* targetReq) // switch (targetReq->getDefaultMatrixLayoutMode()) { - case kMatrixLayoutMode_RowMajor: - default: - m_writer->emit("layout(column_major) uniform;\n"); - m_writer->emit("layout(column_major) buffer;\n"); - break; + case kMatrixLayoutMode_RowMajor: + default: + m_writer->emit("layout(column_major) uniform;\n"); + m_writer->emit("layout(column_major) buffer;\n"); + break; - case kMatrixLayoutMode_ColumnMajor: - m_writer->emit("layout(row_major) uniform;\n"); - m_writer->emit("layout(row_major) buffer;\n"); - break; + case kMatrixLayoutMode_ColumnMajor: + m_writer->emit("layout(row_major) uniform;\n"); + m_writer->emit("layout(row_major) buffer;\n"); + break; } } |
