Browse Source

Add an interface to get the GLSL IO mapper and resolver

The TProgram::mapIO method takes a TIoMapResolver and a TIoMapper,
however the only way to obtain instances of these was from methods in
iomapper.h. Rather than try to expose that header as part of the API,
new methods are added to the public ShaderLang.h header to create a
TDefaultGlslIoResolver and a TGlslIoMapper and return them as pointers
to their respective base classes, which are defined in the public
header.
Arcady Goldmints-Orlov 1 năm trước cách đây
mục cha
commit
d081b4d8c6

+ 10 - 0
glslang/MachineIndependent/ShaderLang.cpp

@@ -1716,6 +1716,10 @@ public:
     virtual bool compile(TIntermNode*, int = 0, EProfile = ENoProfile) { return true; }
     virtual bool compile(TIntermNode*, int = 0, EProfile = ENoProfile) { return true; }
 };
 };
 
 
+TIoMapper* GetGlslIoMapper() {
+    return static_cast<TIoMapper*>(new TGlslIoMapper());
+}
+
 TShader::TShader(EShLanguage s)
 TShader::TShader(EShLanguage s)
     : stage(s), lengths(nullptr), stringNames(nullptr), preamble(""), overrideVersion(0)
     : stage(s), lengths(nullptr), stringNames(nullptr), preamble(""), overrideVersion(0)
 {
 {
@@ -2164,6 +2168,12 @@ int TProgram::getNumAtomicCounters() const                            { return r
 const TObjectReflection& TProgram::getAtomicCounter(int index) const  { return reflection->getAtomicCounter(index); }
 const TObjectReflection& TProgram::getAtomicCounter(int index) const  { return reflection->getAtomicCounter(index); }
 void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump(); }
 void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump(); }
 
 
+TIoMapResolver* TProgram::getGlslIoResolver(EShLanguage stage) {
+    auto *intermediate = getIntermediate(stage);
+    if (!intermediate)
+        return NULL;
+    return static_cast<TIoMapResolver*>(new TDefaultGlslIoResolver(*intermediate));
+}
 //
 //
 // I/O mapping implementation.
 // I/O mapping implementation.
 //
 //

+ 0 - 10
glslang/MachineIndependent/iomapper.h

@@ -189,16 +189,6 @@ protected:
 
 
 typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
 typedef std::map<TString, TVarEntryInfo> TVarLiveMap;
 
 
-// I/O mapper
-class TIoMapper {
-public:
-    TIoMapper() {}
-    virtual ~TIoMapper() {}
-    // grow the reflection stage by stage
-    bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
-    bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
-};
-
 // I/O mapper for GLSL
 // I/O mapper for GLSL
 class TGlslIoMapper : public TIoMapper {
 class TGlslIoMapper : public TIoMapper {
 public:
 public:

+ 18 - 0
glslang/Public/ShaderLang.h

@@ -400,6 +400,7 @@ GLSLANG_EXPORT int GetKhronosToolId();
 class TIntermediate;
 class TIntermediate;
 class TProgram;
 class TProgram;
 class TPoolAllocator;
 class TPoolAllocator;
+class TIoMapResolver;
 
 
 // Call this exactly once per process before using anything else
 // Call this exactly once per process before using anything else
 GLSLANG_EXPORT bool InitializeProcess();
 GLSLANG_EXPORT bool InitializeProcess();
@@ -838,6 +839,19 @@ public:
     virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0;
     virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0;
 };
 };
 
 
+// I/O mapper
+class TIoMapper {
+public:
+    TIoMapper() {}
+    virtual ~TIoMapper() {}
+    // grow the reflection stage by stage
+    bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*);
+    bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; }
+};
+
+// Get the default GLSL IO mapper
+GLSLANG_EXPORT TIoMapper* GetGlslIoMapper();
+
 // Make one TProgram per set of shaders that will get linked together.  Add all
 // Make one TProgram per set of shaders that will get linked together.  Add all
 // the shaders that are to be linked together.  After calling shader.parse()
 // the shaders that are to be linked together.  After calling shader.parse()
 // for all shaders, call link().
 // for all shaders, call link().
@@ -945,6 +959,10 @@ public:
     const TType *getAttributeTType(int index) const    { return getPipeInput(index).getType(); }
     const TType *getAttributeTType(int index) const    { return getPipeInput(index).getType(); }
 
 
     GLSLANG_EXPORT void dumpReflection();
     GLSLANG_EXPORT void dumpReflection();
+
+    // Get the IO resolver to use for mapIO
+    GLSLANG_EXPORT TIoMapResolver* getGlslIoResolver(EShLanguage stage);
+
     // I/O mapping: apply base offsets and map live unbound variables
     // I/O mapping: apply base offsets and map live unbound variables
     // If resolver is not provided it uses the previous approach
     // If resolver is not provided it uses the previous approach
     // and respects auto assignment and offsets.
     // and respects auto assignment and offsets.