Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refine. #2227

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions glslang/MachineIndependent/iomapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,7 @@ TDefaultGlslIoResolver::TDefaultGlslIoResolver(const TIntermediate& intermediate

int TDefaultGlslIoResolver::resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = IsAnonymous(ent.symbol->getName()) ?
ent.symbol->getType().getTypeName()
:
ent.symbol->getName();
TString& name = getAccessName(ent.symbol);
if (currentStage != stage) {
preStage = currentStage;
currentStage = stage;
Expand Down Expand Up @@ -666,10 +663,7 @@ int TDefaultGlslIoResolver::resolveInOutLocation(EShLanguage stage, TVarEntryInf

int TDefaultGlslIoResolver::resolveUniformLocation(EShLanguage /*stage*/, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = IsAnonymous(ent.symbol->getName()) ?
ent.symbol->getType().getTypeName()
:
ent.symbol->getName();
TString& name = getAccessName(ent.symbol);
// kick out of not doing this
if (! doAutoLocationMapping()) {
return ent.newLocation = -1;
Expand Down Expand Up @@ -740,10 +734,7 @@ int TDefaultGlslIoResolver::resolveUniformLocation(EShLanguage /*stage*/, TVarEn

int TDefaultGlslIoResolver::resolveBinding(EShLanguage /*stage*/, TVarEntryInfo& ent) {
const TType& type = ent.symbol->getType();
const TString& name = IsAnonymous(ent.symbol->getName()) ?
ent.symbol->getType().getTypeName()
:
ent.symbol->getName();
TString& name = getAccessName(ent.symbol);
// On OpenGL arrays of opaque types take a seperate binding for each element
int numBindings = intermediate.getSpv().openGl != 0 && type.isSizedArray() ? type.getCumulativeArraySize() : 1;
TResourceType resource = getResourceType(type);
Expand Down Expand Up @@ -818,10 +809,7 @@ void TDefaultGlslIoResolver::endCollect(EShLanguage /*stage*/) {

void TDefaultGlslIoResolver::reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) {
const TType& type = ent.symbol->getType();
const TString& name = IsAnonymous(ent.symbol->getName()) ?
ent.symbol->getType().getTypeName()
:
ent.symbol->getName();
TString& name = getAccessName(ent.symbol);
TStorageQualifier storage = type.getQualifier().storage;
EShLanguage stage(EShLangCount);
switch (storage) {
Expand Down Expand Up @@ -881,10 +869,7 @@ void TDefaultGlslIoResolver::reserverStorageSlot(TVarEntryInfo& ent, TInfoSink&

void TDefaultGlslIoResolver::reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) {
const TType& type = ent.symbol->getType();
const TString& name = IsAnonymous(ent.symbol->getName()) ?
ent.symbol->getType().getTypeName()
:
ent.symbol->getName();
TString& name = getAccessName(ent.symbol);
int resource = getResourceType(type);
if (type.getQualifier().hasBinding()) {
TVarSlotMap& varSlotMap = resourceSlotMap[resource];
Expand All @@ -907,6 +892,17 @@ void TDefaultGlslIoResolver::reserverResourceSlot(TVarEntryInfo& ent, TInfoSink&
}
}

TString& TDefaultGlslIoResolver::getAccessName(const TIntermSymbol* symbol)
{
TString name;
if (symbol->getBasicType() == EbtBlock) {
johnkslang marked this conversation as resolved.
Show resolved Hide resolved
name = symbol->getType().getTypeName();
} else {
name = symbol->getName();
}
return name;
}

//TDefaultGlslIoResolver end

/*
Expand Down
1 change: 1 addition & 0 deletions glslang/MachineIndependent/iomapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ struct TDefaultGlslIoResolver : public TDefaultIoResolverBase {
void endCollect(EShLanguage) override;
void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) override;
TString& getAccessName(const TIntermSymbol*);
// in/out symbol and uniform symbol are stored in the same resourceSlotMap, the storage key is used to identify each type of symbol.
// We use stage and storage qualifier to construct a storage key. it can help us identify the same storage resource used in different stage.
// if a resource is a program resource and we don't need know it usage stage, we can use same stage to build storage key.
Expand Down