Vulkan: Fix the issue with unused attributes / varyings
When an attribute, a uniform or a varying isn't used, we now remove
their layout and in/out qualifiers so that the shader can still refer
to these var names.
Bug: angleproject:2456
Change-Id: I5f1241d91bd46f663750adfab2562ef87ce69ae5
Reviewed-on: https://chromium-review.googlesource.com/1014009
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index a7534b0..fd1958c 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -214,7 +214,16 @@
out << ") ";
}
-const char *TOutputGLSLBase::mapQualifierToString(TQualifier qualifier, const TSymbol *symbol)
+void TOutputGLSLBase::writeQualifier(TQualifier qualifier, const TSymbol *symbol)
+{
+ const char *result = mapQualifierToString(qualifier);
+ if (result && result[0] != '\0')
+ {
+ objSink() << result << " ";
+ }
+}
+
+const char *TOutputGLSLBase::mapQualifierToString(TQualifier qualifier)
{
if (sh::IsGLSL410OrOlder(mOutput) && mShaderVersion >= 300 &&
(mCompileOptions & SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3) != 0)
@@ -265,11 +274,7 @@
}
if (qualifier != EvqTemporary && qualifier != EvqGlobal)
{
- const char *qualifierString = mapQualifierToString(qualifier, symbol);
- if (qualifierString && qualifierString[0] != '\0')
- {
- out << qualifierString << " ";
- }
+ writeQualifier(qualifier, symbol);
}
const TMemoryQualifier &memoryQualifier = type.getMemoryQualifier();
diff --git a/src/compiler/translator/OutputGLSLBase.h b/src/compiler/translator/OutputGLSLBase.h
index c000b95..272d276 100644
--- a/src/compiler/translator/OutputGLSLBase.h
+++ b/src/compiler/translator/OutputGLSLBase.h
@@ -77,6 +77,7 @@
virtual ImmutableString translateTextureFunction(const ImmutableString &name) { return name; }
void declareStruct(const TStructure *structure);
+ virtual void writeQualifier(TQualifier qualifier, const TSymbol *symbol);
private:
bool structDeclared(const TStructure *structure) const;
@@ -86,7 +87,7 @@
void writeBuiltInFunctionTriplet(Visit visit, TOperator op, bool useEmulatedFunction);
- const char *mapQualifierToString(TQualifier qualifier, const TSymbol *symbol);
+ const char *mapQualifierToString(TQualifier qualifier);
TInfoSinkBase &mObjSink;
bool mDeclaringVariable;
diff --git a/src/compiler/translator/OutputVulkanGLSL.cpp b/src/compiler/translator/OutputVulkanGLSL.cpp
index bd7c4e3..c4b44b1 100644
--- a/src/compiler/translator/OutputVulkanGLSL.cpp
+++ b/src/compiler/translator/OutputVulkanGLSL.cpp
@@ -11,6 +11,7 @@
#include "compiler/translator/OutputVulkanGLSL.h"
+#include "compiler/translator/Symbol.h"
#include "compiler/translator/util.h"
namespace sh
@@ -54,7 +55,6 @@
TInfoSinkBase &out = objSink();
const TLayoutQualifier &layoutQualifier = type.getLayoutQualifier();
- out << "layout(";
// This isn't super clean, but it gets the job done.
// See corresponding code in GlslangWrapper.cpp.
@@ -67,6 +67,10 @@
{
out << "@@ LAYOUT-" << symbol->getName() << " @@";
}
+ else
+ {
+ out << "layout(";
+ }
if (IsImage(type.getBasicType()) && layoutQualifier.imageInternalFormat != EiifUnspecified)
{
@@ -74,7 +78,30 @@
out << getImageInternalFormatString(layoutQualifier.imageInternalFormat);
}
- out << ") ";
+ if (!needsCustomLayout)
+ {
+ out << ") ";
+ }
+}
+
+void TOutputVulkanGLSL::writeQualifier(TQualifier qualifier, const TSymbol *symbol)
+{
+ if (qualifier != EvqUniform && qualifier != EvqVaryingIn && qualifier != EvqVaryingOut &&
+ qualifier != EvqAttribute)
+ {
+ TOutputGLSLBase::writeQualifier(qualifier, symbol);
+ return;
+ }
+
+ if (symbol == nullptr)
+ {
+ return;
+ }
+
+ TInfoSinkBase &out = objSink();
+ out << "@@ QUALIFIER-";
+ out << symbol->name().data();
+ out << " @@ ";
}
void TOutputVulkanGLSL::writeStructType(const TStructure *structure)
diff --git a/src/compiler/translator/OutputVulkanGLSL.h b/src/compiler/translator/OutputVulkanGLSL.h
index 80561e5..d98517b 100644
--- a/src/compiler/translator/OutputVulkanGLSL.h
+++ b/src/compiler/translator/OutputVulkanGLSL.h
@@ -31,6 +31,7 @@
protected:
void writeLayoutQualifier(TIntermTyped *variable) override;
+ void writeQualifier(TQualifier qualifier, const TSymbol *symbol) override;
};
} // namespace sh