From d081b4d8c6df2febac924f33cd44c8755006148b Mon Sep 17 00:00:00 2001 From: Arcady Goldmints-Orlov Date: Fri, 13 Sep 2024 08:44:40 -0700 Subject: [PATCH] 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. --- glslang/MachineIndependent/ShaderLang.cpp | 10 ++++++++++ glslang/MachineIndependent/iomapper.h | 10 ---------- glslang/Public/ShaderLang.h | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 28519e98..40aeaa7c 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -1716,6 +1716,10 @@ public: virtual bool compile(TIntermNode*, int = 0, EProfile = ENoProfile) { return true; } }; +TIoMapper* GetGlslIoMapper() { + return static_cast(new TGlslIoMapper()); +} + TShader::TShader(EShLanguage s) : 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); } void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump(); } +TIoMapResolver* TProgram::getGlslIoResolver(EShLanguage stage) { + auto *intermediate = getIntermediate(stage); + if (!intermediate) + return NULL; + return static_cast(new TDefaultGlslIoResolver(*intermediate)); +} // // I/O mapping implementation. // diff --git a/glslang/MachineIndependent/iomapper.h b/glslang/MachineIndependent/iomapper.h index ef73c273..86c9e87b 100644 --- a/glslang/MachineIndependent/iomapper.h +++ b/glslang/MachineIndependent/iomapper.h @@ -189,16 +189,6 @@ protected: typedef std::map 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 class TGlslIoMapper : public TIoMapper { public: diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index d7880307..5e3ab581 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -400,6 +400,7 @@ GLSLANG_EXPORT int GetKhronosToolId(); class TIntermediate; class TProgram; class TPoolAllocator; +class TIoMapResolver; // Call this exactly once per process before using anything else GLSLANG_EXPORT bool InitializeProcess(); @@ -838,6 +839,19 @@ public: 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 // the shaders that are to be linked together. After calling shader.parse() // for all shaders, call link(). @@ -945,6 +959,10 @@ public: const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); } 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 // If resolver is not provided it uses the previous approach // and respects auto assignment and offsets.