Split varyings into input and output varyings in compiler
This patch intends to split all vector<Varying> into two vectors
to store input and output varyings separately in the compiler.
This patch is a base of implementing the built-ins, inputs and
outputs of a geometry shader to ANGLE GLSL compiler. Unlike the
vertex shaders (their outputs are varyings) and fragment shaders
(their inputs are varyings), the inputs and outputs of geometry
shaders are all varyings, so we need two vector<Varying> to store
them correctly.
BUG=angleproject:1941
Change-Id: I9e8cc16045d5e29e9a80a09dc31b33a7ae39b345
Reviewed-on: https://chromium-review.googlesource.com/593347
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index 2d6d0d4..04d7b81 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -45,7 +45,20 @@
template <>
const std::vector<Varying> *GetVariableList(const TCompiler *compiler)
{
- return &compiler->getVaryings();
+ switch (compiler->getShaderType())
+ {
+ case GL_VERTEX_SHADER:
+ return &compiler->getOutputVaryings();
+ case GL_FRAGMENT_SHADER:
+ return &compiler->getInputVaryings();
+ case GL_COMPUTE_SHADER:
+ ASSERT(compiler->getOutputVaryings().empty() && compiler->getInputVaryings().empty());
+ return &compiler->getOutputVaryings();
+ // Since geometry shaders have both input and output varyings, we shouldn't call GetVaryings
+ // on a geometry shader.
+ default:
+ return nullptr;
+ }
}
template <>
@@ -66,8 +79,7 @@
return &compiler->getInterfaceBlocks();
}
-template <typename VarT>
-const std::vector<VarT> *GetShaderVariables(const ShHandle handle)
+TCompiler *GetCompilerFromHandle(ShHandle handle)
{
if (!handle)
{
@@ -75,7 +87,13 @@
}
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
- TCompiler *compiler = base->getAsCompiler();
+ return base->getAsCompiler();
+}
+
+template <typename VarT>
+const std::vector<VarT> *GetShaderVariables(const ShHandle handle)
+{
+ TCompiler *compiler = GetCompilerFromHandle(handle);
if (!compiler)
{
return nullptr;
@@ -84,14 +102,6 @@
return GetVariableList<VarT>(compiler);
}
-TCompiler *GetCompilerFromHandle(ShHandle handle)
-{
- if (!handle)
- return nullptr;
- TShHandleBase *base = static_cast<TShHandleBase *>(handle);
- return base->getAsCompiler();
-}
-
#ifdef ANGLE_ENABLE_HLSL
TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
{
@@ -355,6 +365,26 @@
return GetShaderVariables<Uniform>(handle);
}
+const std::vector<sh::Varying> *GetInputVaryings(const ShHandle handle)
+{
+ TCompiler *compiler = GetCompilerFromHandle(handle);
+ if (compiler == nullptr)
+ {
+ return nullptr;
+ }
+ return &compiler->getInputVaryings();
+}
+
+const std::vector<sh::Varying> *GetOutputVaryings(const ShHandle handle)
+{
+ TCompiler *compiler = GetCompilerFromHandle(handle);
+ if (compiler == nullptr)
+ {
+ return nullptr;
+ }
+ return &compiler->getOutputVaryings();
+}
+
const std::vector<Varying> *GetVaryings(const ShHandle handle)
{
return GetShaderVariables<Varying>(handle);