Unverified Commit f04f1f93 by John Kessenich Committed by GitHub

Merge pull request #1857 from Roy-AMD/automapping-opengl-location

Automapping opengl location
parents 7fc86834 03a93ae1
...@@ -1852,7 +1852,7 @@ const char* TShader::getInfoDebugLog() ...@@ -1852,7 +1852,7 @@ const char* TShader::getInfoDebugLog()
return infoSink->debug.c_str(); return infoSink->debug.c_str();
} }
TProgram::TProgram() : reflection(0), ioMapper(nullptr), linked(false) TProgram::TProgram() : reflection(0), linked(false)
{ {
pool = new TPoolAllocator; pool = new TPoolAllocator;
infoSink = new TInfoSink; infoSink = new TInfoSink;
...@@ -1864,7 +1864,6 @@ TProgram::TProgram() : reflection(0), ioMapper(nullptr), linked(false) ...@@ -1864,7 +1864,6 @@ TProgram::TProgram() : reflection(0), ioMapper(nullptr), linked(false)
TProgram::~TProgram() TProgram::~TProgram()
{ {
delete ioMapper;
delete infoSink; delete infoSink;
delete reflection; delete reflection;
...@@ -2035,21 +2034,24 @@ void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump(); ...@@ -2035,21 +2034,24 @@ void TProgram::dumpReflection() { if (reflection != nullptr) reflection->dump();
// //
// I/O mapping implementation. // I/O mapping implementation.
// //
bool TProgram::mapIO(TIoMapResolver* resolver) bool TProgram::mapIO(TIoMapResolver* pResolver, TIoMapper* pIoMapper)
{ {
if (! linked || ioMapper) if (! linked)
return false; return false;
TIoMapper* ioMapper = nullptr;
ioMapper = new TIoMapper; TIoMapper defaultIOMapper;
if (pIoMapper == nullptr)
ioMapper = &defaultIOMapper;
else
ioMapper = pIoMapper;
for (int s = 0; s < EShLangCount; ++s) { for (int s = 0; s < EShLangCount; ++s) {
if (intermediate[s]) { if (intermediate[s]) {
if (! ioMapper->addStage((EShLanguage)s, *intermediate[s], *infoSink, resolver)) if (! ioMapper->addStage((EShLanguage)s, *intermediate[s], *infoSink, pResolver))
return false; return false;
} }
} }
return true; return ioMapper->doMap(pResolver, *infoSink);
} }
} // end namespace glslang } // end namespace glslang
...@@ -646,8 +646,9 @@ protected: ...@@ -646,8 +646,9 @@ protected:
const TType* type; const TType* type;
}; };
class TReflection; class TReflection;
class TIoMapper; class TIoMapper;
struct TVarEntryInfo;
// Allows to customize the binding layout after linking. // Allows to customize the binding layout after linking.
// All used uniform variables will invoke at least validateBinding. // All used uniform variables will invoke at least validateBinding.
...@@ -668,51 +669,61 @@ class TIoMapper; ...@@ -668,51 +669,61 @@ class TIoMapper;
// notifiy callbacks, this phase ends with a call to endNotifications. // notifiy callbacks, this phase ends with a call to endNotifications.
// Phase two starts directly after the call to endNotifications // Phase two starts directly after the call to endNotifications
// and calls all other callbacks to validate and to get the // and calls all other callbacks to validate and to get the
// bindings, sets, locations, component and color indices. // bindings, sets, locations, component and color indices.
// //
// NOTE: that still limit checks are applied to bindings and sets // NOTE: that still limit checks are applied to bindings and sets
// and may result in an error. // and may result in an error.
class TIoMapResolver class TIoMapResolver
{ {
public: public:
virtual ~TIoMapResolver() {} virtual ~TIoMapResolver() {}
// Should return true if the resulting/current binding would be okay. // Should return true if the resulting/current binding would be okay.
// Basic idea is to do aliasing binding checks with this. // Basic idea is to do aliasing binding checks with this.
virtual bool validateBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current binding should be overridden. // Should return a value >= 0 if the current binding should be overridden.
// Return -1 if the current binding (including no binding) should be kept. // Return -1 if the current binding (including no binding) should be kept.
virtual int resolveBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current set should be overridden. // Should return a value >= 0 if the current set should be overridden.
// Return -1 if the current set (including no set) should be kept. // Return -1 if the current set (including no set) should be kept.
virtual int resolveSet(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current location should be overridden. // Should return a value >= 0 if the current location should be overridden.
// Return -1 if the current location (including no location) should be kept. // Return -1 if the current location (including no location) should be kept.
virtual int resolveUniformLocation(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return true if the resulting/current setup would be okay. // Should return true if the resulting/current setup would be okay.
// Basic idea is to do aliasing checks and reject invalid semantic names. // Basic idea is to do aliasing checks and reject invalid semantic names.
virtual bool validateInOut(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current location should be overridden. // Should return a value >= 0 if the current location should be overridden.
// Return -1 if the current location (including no location) should be kept. // Return -1 if the current location (including no location) should be kept.
virtual int resolveInOutLocation(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current component index should be overridden. // Should return a value >= 0 if the current component index should be overridden.
// Return -1 if the current component index (including no index) should be kept. // Return -1 if the current component index (including no index) should be kept.
virtual int resolveInOutComponent(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Should return a value >= 0 if the current color index should be overridden. // Should return a value >= 0 if the current color index should be overridden.
// Return -1 if the current color index (including no index) should be kept. // Return -1 if the current color index (including no index) should be kept.
virtual int resolveInOutIndex(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Notification of a uniform variable // Notification of a uniform variable
virtual void notifyBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Notification of a in or out variable // Notification of a in or out variable
virtual void notifyInOut(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0; virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
// Called by mapIO when it has finished the notify pass // Called by mapIO when it starts its notify pass for the given stage
virtual void endNotifications(EShLanguage stage) = 0; virtual void beginNotifications(EShLanguage stage) = 0;
// Called by mapIO when it starts its notify pass for the given stage // Called by mapIO when it has finished the notify pass
virtual void beginNotifications(EShLanguage stage) = 0; virtual void endNotifications(EShLanguage stage) = 0;
// Called by mipIO when it starts its resolve pass for the given stage // Called by mipIO when it starts its resolve pass for the given stage
virtual void beginResolve(EShLanguage stage) = 0; virtual void beginResolve(EShLanguage stage) = 0;
// Called by mapIO when it has finished the resolve pass // Called by mapIO when it has finished the resolve pass
virtual void endResolve(EShLanguage stage) = 0; virtual void endResolve(EShLanguage stage) = 0;
// Called by mapIO when it starts its symbol collect for teh given stage
virtual void beginCollect(EShLanguage stage) = 0;
// Called by mapIO when it has finished the symbol collect
virtual void endCollect(EShLanguage stage) = 0;
// Called by TSlotCollector to resolve storage locations or bindings
virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
// Called by TSlotCollector to resolve resource locations or bindings
virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
// Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
virtual void addStage(EShLanguage stage) = 0;
}; };
// 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
...@@ -824,7 +835,7 @@ public: ...@@ -824,7 +835,7 @@ public:
// 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.
bool mapIO(TIoMapResolver* resolver = NULL); bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
protected: protected:
bool linkStage(EShLanguage, EShMessages); bool linkStage(EShLanguage, EShMessages);
...@@ -835,7 +846,6 @@ protected: ...@@ -835,7 +846,6 @@ protected:
bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
TInfoSink* infoSink; TInfoSink* infoSink;
TReflection* reflection; TReflection* reflection;
TIoMapper* ioMapper;
bool linked; bool linked;
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment