Hash :
05b6b7fc
Author :
Date :
2015-03-02T17:08:09
Add an SH_GLSL_CORE_OUTPUT profile. So we could generate shaders for Apple using core GL profile. By switching to core profile, we still pass most WebGL conformance tests 1.0.2 on Linux, but not all, so apparently more work is needed. However, I think it's OK to check this CL in because this output profile will be only used behind a chromium switch. BUG=angleproject:933 TEST=webgl conformance tests Change-Id: Iad70e1aebf82349d3fc5f4116c1d6bc4448193fd Reviewed-on: https://chromium-review.googlesource.com/255282 Tested-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/translator/VersionGLSL.h"
static const int GLSL_VERSION_110 = 110;
static const int GLSL_VERSION_120 = 120;
static const int GLSL_VERSION_150 = 150;
// We need to scan for the following:
// 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
// but only at the global scope.
// 2. "gl_PointCoord" built-in variable: This can only occur in fragment shader
// but inside any scope.
// 3. Call to a matrix constructor with another matrix as argument.
// (These constructors were reserved in GLSL version 1.10.)
// 4. Arrays as "out" function parameters.
// GLSL spec section 6.1.1: "When calling a function, expressions that do
// not evaluate to l-values cannot be passed to parameters declared as
// out or inout."
// GLSL 1.1 section 5.8: "Other binary or unary expressions,
// non-dereferenced arrays, function names, swizzles with repeated fields,
// and constants cannot be l-values."
// GLSL 1.2 relaxed the restriction on arrays, section 5.8: "Variables that
// are built-in types, entire structures or arrays... are all l-values."
//
TVersionGLSL::TVersionGLSL(sh::GLenum type,
const TPragma &pragma,
ShShaderOutput output)
{
if (output == SH_GLSL_CORE_OUTPUT)
{
mVersion = GLSL_VERSION_150;
}
else
{
ASSERT(output == SH_GLSL_COMPATIBILITY_OUTPUT);
if (pragma.stdgl.invariantAll)
mVersion = GLSL_VERSION_120;
else
mVersion = GLSL_VERSION_110;
}
}
void TVersionGLSL::visitSymbol(TIntermSymbol *node)
{
if (node->getSymbol() == "gl_PointCoord")
updateVersion(GLSL_VERSION_120);
}
bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
{
bool visitChildren = true;
switch (node->getOp())
{
case EOpSequence:
// We need to visit sequence children to get to global or inner scope.
visitChildren = true;
break;
case EOpDeclaration:
{
const TIntermSequence &sequence = *(node->getSequence());
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if ((qualifier == EvqInvariantVaryingIn) ||
(qualifier == EvqInvariantVaryingOut))
{
updateVersion(GLSL_VERSION_120);
}
break;
}
case EOpInvariantDeclaration:
updateVersion(GLSL_VERSION_120);
break;
case EOpParameters:
{
const TIntermSequence ¶ms = *(node->getSequence());
for (TIntermSequence::const_iterator iter = params.begin();
iter != params.end(); ++iter)
{
const TIntermTyped *param = (*iter)->getAsTyped();
if (param->isArray())
{
TQualifier qualifier = param->getQualifier();
if ((qualifier == EvqOut) || (qualifier == EvqInOut))
{
updateVersion(GLSL_VERSION_120);
break;
}
}
}
// Fully processed. No need to visit children.
visitChildren = false;
break;
}
case EOpConstructMat2:
case EOpConstructMat3:
case EOpConstructMat4:
{
const TIntermSequence &sequence = *(node->getSequence());
if (sequence.size() == 1)
{
TIntermTyped *typed = sequence.front()->getAsTyped();
if (typed && typed->isMatrix())
{
updateVersion(GLSL_VERSION_120);
}
}
break;
}
default:
break;
}
return visitChildren;
}
void TVersionGLSL::updateVersion(int version)
{
mVersion = std::max(version, mVersion);
}