Rework how auto push_constant upgrading works a bit.

Ensure we traverse the entire tree and upgrade all references to the
given symbol so it can be upgraded to push_constant. Without this change
only one instance was upgraded, and others were left as uniform buffers.
This commit is contained in:
Malcolm Bechard 2023-06-16 20:19:35 -04:00 committed by arcady-lunarg
parent 8a6a311d22
commit 6defcb2478
2 changed files with 21 additions and 14 deletions

View File

@ -145,6 +145,8 @@ public:
base->getWritableType().getQualifier().layoutComponent = at->second.newComponent; base->getWritableType().getQualifier().layoutComponent = at->second.newComponent;
if (at->second.newIndex != -1) if (at->second.newIndex != -1)
base->getWritableType().getQualifier().layoutIndex = at->second.newIndex; base->getWritableType().getQualifier().layoutIndex = at->second.newIndex;
if (at->second.upgradedToPushConstant)
base->getWritableType().getQualifier().layoutPushConstant = true;
} }
private: private:
@ -1670,31 +1672,34 @@ bool TGlslIoMapper::doMap(TIoMapResolver* resolver, TInfoSink& infoSink) {
} }
} }
} }
// If it's been upgraded to push_constant, then remove it from the uniformVector // If it's been upgraded to push_constant, then set the flag so when its traversed
// in the next for loop, all references to this symbol will get their flag changed.
// so it doesn't get a set/binding assigned to it. // so it doesn't get a set/binding assigned to it.
if (upgraded) { if (upgraded) {
while (1) { std::for_each(uniformVector.begin(), uniformVector.end(),
auto at = std::find_if(uniformVector.begin(), uniformVector.end(), [this](TVarLivePair& p) {
[this](const TVarLivePair& p) { return p.first == autoPushConstantBlockName; }); if (p.first == autoPushConstantBlockName) {
if (at != uniformVector.end()) p.second.upgradedToPushConstant = true;
uniformVector.erase(at); }
else });
break;
}
} }
} }
for (size_t stage = 0; stage < EShLangCount; stage++) { for (size_t stage = 0; stage < EShLangCount; stage++) {
if (intermediates[stage] != nullptr) { if (intermediates[stage] != nullptr) {
// traverse each stage, set new location to each input/output and unifom symbol, set new binding to // traverse each stage, set new location to each input/output and unifom symbol, set new binding to
// ubo, ssbo and opaque symbols // ubo, ssbo and opaque symbols. Assign push_constant upgrades as well.
TVarLiveMap** pUniformVarMap = uniformResolve.uniformVarMap; TVarLiveMap** pUniformVarMap = uniformResolve.uniformVarMap;
std::for_each(uniformVector.begin(), uniformVector.end(), [pUniformVarMap, stage](TVarLivePair p) { std::for_each(uniformVector.begin(), uniformVector.end(), [pUniformVarMap, stage](TVarLivePair p) {
auto at = pUniformVarMap[stage]->find(p.second.symbol->getAccessName()); auto at = pUniformVarMap[stage]->find(p.second.symbol->getAccessName());
if (at != pUniformVarMap[stage]->end() && at->second.id == p.second.id){ if (at != pUniformVarMap[stage]->end() && at->second.id == p.second.id){
int resolvedBinding = at->second.newBinding; if (p.second.upgradedToPushConstant) {
at->second = p.second; at->second.upgradedToPushConstant = true;
if (resolvedBinding > 0) } else {
at->second.newBinding = resolvedBinding; int resolvedBinding = at->second.newBinding;
at->second = p.second;
if (resolvedBinding > 0)
at->second.newBinding = resolvedBinding;
}
} }
}); });
TVarSetTraverser iter_iomap(*intermediates[stage], *inVarMaps[stage], *outVarMaps[stage], TVarSetTraverser iter_iomap(*intermediates[stage], *inVarMaps[stage], *outVarMaps[stage],

View File

@ -55,6 +55,7 @@ struct TVarEntryInfo {
long long id; long long id;
TIntermSymbol* symbol; TIntermSymbol* symbol;
bool live; bool live;
bool upgradedToPushConstant;
int newBinding; int newBinding;
int newSet; int newSet;
int newLocation; int newLocation;
@ -63,6 +64,7 @@ struct TVarEntryInfo {
EShLanguage stage; EShLanguage stage;
void clearNewAssignments() { void clearNewAssignments() {
upgradedToPushConstant = false;
newBinding = -1; newBinding = -1;
newSet = -1; newSet = -1;
newLocation = -1; newLocation = -1;