Skip to content

Commit

Permalink
Add an interface to get the GLSL IO mapper and resolver
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arcady-lunarg committed Sep 14, 2024
1 parent 8bd9083 commit d081b4d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
10 changes: 10 additions & 0 deletions glslang/MachineIndependent/ShaderLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,10 @@ class TDeferredCompiler : public TCompiler {
virtual bool compile(TIntermNode*, int = 0, EProfile = ENoProfile) { return true; }
};

TIoMapper* GetGlslIoMapper() {
return static_cast<TIoMapper*>(new TGlslIoMapper());
}

TShader::TShader(EShLanguage s)
: stage(s), lengths(nullptr), stringNames(nullptr), preamble(""), overrideVersion(0)
{
Expand Down Expand Up @@ -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<TIoMapResolver*>(new TDefaultGlslIoResolver(*intermediate));
}
//
// I/O mapping implementation.
//
Expand Down
10 changes: 0 additions & 10 deletions glslang/MachineIndependent/iomapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,6 @@ struct TDefaultGlslIoResolver : public TDefaultIoResolverBase {

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
class TGlslIoMapper : public TIoMapper {
public:
Expand Down
18 changes: 18 additions & 0 deletions glslang/Public/ShaderLang.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -838,6 +839,19 @@ class TIoMapResolver
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().
Expand Down Expand Up @@ -945,6 +959,10 @@ class TProgram {
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.
Expand Down

0 comments on commit d081b4d

Please sign in to comment.