diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-06-06 17:48:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-06 17:48:39 -0400 |
| commit | fc083a75b94ac4b4e735b4a7ff566191b9123f74 (patch) | |
| tree | ac1168718ac36099374373fdb55b9be178a0a9fa /source/slang/slang-emit.cpp | |
| parent | 0d9071bd1511ee2cb7d6ba6ce9e250d25613ddca (diff) | |
Split out target code generation from CLikeSourceEmitter (#976)
* * Added SourceStyle to CLikeSourceEmitter, to limit cases to actual target types.
* Made Impl methods _ prefixed
* Small tidyup
* * SourceStream -> SourceWriter
* use slang-emit- prefix on SourceWriter file
* * Remove EmitContext -> merge into CLikeSourceEmitter
* slang-c-like-source-emitter -> slang-emit-source.cpp
* ExtensionUsageTracker -> GLSLExtensionTracker
slang-extension-usage-tracker.cpp/.h -> slang-emit-glsl-extension-tracker.cpp/.h
* emit-source.cpp.h -> emit-c-like.cpp/.h
* Small fix to move where some _ prefixed functions are declared in CLikeSourceEmitter.
* * CLikeSourceEmitter::CInfo -> Desc
* Functions to get and find CodeGenTarget by name
* Split out empty language impls
* Create an impl based on SourceStyle
* * CodeGenTarget conversion to and from string
* Move HLSL specific functions to HLSLEmitSource.
* Emitting texture and image types.
* Move move GLSL specific functionality to GLSLSourceEmitter
* Split more out of slang-emit-c-like
* Refactor more out of slang-emit-c-like
* * tryEmitIRInstExprImpl(IRInst* inst, IREmitMode mode, const EmitOpInfo& inOuterPrec)
* Fix bug around output of uintBitsToFloat
* More work refactoring out target specifics from slang-emit-c-like
* Move functions that are only implemented once in GLSL impl into their Impl method.
* Move rate qualification out of slang-emit-c-like
* * Added getEmitOpForOp - allows for table usage so different ops can be dealt with the same way
* Moved vector comparison to slang-emit-glsl
*
* * Use EmitOpInfo to control output in slang-emit-c-like.cpp for unary ops
* Move more functionality from CLikeSourceEmitter to HLSLSourceEmitter
* Make output of parameters implementaion specific.
* Extracted interpolation modifiers.
* Remove IR from methods that don't need them.
* Remove IR from method names.
* Refactor handling of output of types - to make the impls implement the full path without lots of cases for specific impls
* Add variable declaration modifiers and matrix layout to larget specific in slang-emit.
* Make target specific internal functions _ prefixed.
Diffstat (limited to 'source/slang/slang-emit.cpp')
| -rw-r--r-- | source/slang/slang-emit.cpp | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 3cacb2d90..623c57f2b 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -27,6 +27,10 @@ #include "slang-emit-c-like.h" +#include "slang-emit-glsl.h" +#include "slang-emit-hlsl.h" +#include "slang-emit-cpp.h" + #include <assert.h> namespace Slang { @@ -173,30 +177,58 @@ String emitEntryPoint( SourceWriter sourceWriter(compileRequest->getSourceManager(), lineDirectiveMode ); - CLikeSourceEmitter::CInfo cinfo; + CLikeSourceEmitter::Desc desc; - cinfo.compileRequest = compileRequest; - cinfo.target = target; - cinfo.entryPoint = entryPoint; - cinfo.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest); - cinfo.sourceWriter = &sourceWriter; + desc.compileRequest = compileRequest; + desc.target = target; + desc.entryPoint = entryPoint; + desc.effectiveProfile = getEffectiveProfile(entryPoint, targetRequest); + desc.sourceWriter = &sourceWriter; if (entryPoint && programLayout) { - cinfo.entryPointLayout = findEntryPointLayout(programLayout, entryPoint); + desc.entryPointLayout = findEntryPointLayout(programLayout, entryPoint); } - cinfo.programLayout = programLayout; + desc.programLayout = programLayout; // Layout information for the global scope is either an ordinary // `struct` in the common case, or a constant buffer in the case // where there were global-scope uniforms. StructTypeLayout* globalStructLayout = programLayout ? getGlobalStructLayout(programLayout) : nullptr; - cinfo.globalStructLayout = globalStructLayout; + desc.globalStructLayout = globalStructLayout; + + RefPtr<CLikeSourceEmitter> sourceEmitter; - CLikeSourceEmitter sourceEmitter(cinfo); + typedef CLikeSourceEmitter::SourceStyle SourceStyle; + + SourceStyle sourceStyle = CLikeSourceEmitter::getSourceStyle(target); + switch (sourceStyle) + { + case SourceStyle::CPP: + { + sourceEmitter = new CPPSourceEmitter(desc); + break; + } + case SourceStyle::GLSL: + { + sourceEmitter = new GLSLSourceEmitter(desc); + break; + } + case SourceStyle::HLSL: + { + sourceEmitter = new HLSLSourceEmitter(desc); + break; + } + default: break; + } + if (!sourceEmitter) + { + sink->diagnose(SourceLoc(), Diagnostics::unableToGenerateCodeForTarget, getCodeGenTargetName(target)); + return String(); + } { auto session = targetRequest->getSession(); @@ -421,7 +453,7 @@ String emitEntryPoint( irModule, irEntryPoint, compileRequest->getSink(), - sourceEmitter.getGLSLExtensionTracker()); + sourceEmitter->getGLSLExtensionTracker()); #if 0 dumpIRIfEnabled(compileRequest, irModule, "GLSL LEGALIZED"); @@ -456,7 +488,7 @@ String emitEntryPoint( // // TODO: do we want to emit directly from IR, or translate the // IR back into AST for emission? - sourceEmitter.emitIRModule(irModule); + sourceEmitter->emitModule(irModule); } // Deal with cases where a particular stage requires certain GLSL versions @@ -474,8 +506,8 @@ String emitEntryPoint( case Stage::RayGeneration: if( target == CodeGenTarget::GLSL ) { - sourceEmitter.getGLSLExtensionTracker()->requireExtension("GL_NV_ray_tracing"); - sourceEmitter.getGLSLExtensionTracker()->requireVersion(ProfileVersion::GLSL_460); + sourceEmitter->getGLSLExtensionTracker()->requireExtension("GL_NV_ray_tracing"); + sourceEmitter->getGLSLExtensionTracker()->requireVersion(ProfileVersion::GLSL_460); } break; } @@ -487,16 +519,16 @@ String emitEntryPoint( // it is time to stitch together the final output. // There may be global-scope modifiers that we should emit now - sourceEmitter.emitGLSLPreprocessorDirectives(); + sourceEmitter->emitPreprocessorDirectives(); - sourceEmitter.emitLayoutDirectives(targetRequest); + sourceEmitter->emitLayoutDirectives(targetRequest); String prefix = sourceWriter.getContent(); StringBuilder finalResultBuilder; finalResultBuilder << prefix; - finalResultBuilder << sourceEmitter.getGLSLExtensionTracker()->getExtensionRequireLines(); + finalResultBuilder << sourceEmitter->getGLSLExtensionTracker()->getExtensionRequireLines(); finalResultBuilder << code; |
