gfx/angle/src/compiler/VersionGLSL.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 //
michael@0 2 // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
michael@0 3 // Use of this source code is governed by a BSD-style license that can be
michael@0 4 // found in the LICENSE file.
michael@0 5 //
michael@0 6
michael@0 7 #include "compiler/VersionGLSL.h"
michael@0 8
michael@0 9 static const int GLSL_VERSION_110 = 110;
michael@0 10 static const int GLSL_VERSION_120 = 120;
michael@0 11
michael@0 12 // We need to scan for the following:
michael@0 13 // 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
michael@0 14 // but only at the global scope.
michael@0 15 // 2. "gl_PointCoord" built-in variable: This can only occur in fragment shader
michael@0 16 // but inside any scope.
michael@0 17 // 3. Call to a matrix constructor with another matrix as argument.
michael@0 18 // (These constructors were reserved in GLSL version 1.10.)
michael@0 19 // 4. Arrays as "out" function parameters.
michael@0 20 // GLSL spec section 6.1.1: "When calling a function, expressions that do
michael@0 21 // not evaluate to l-values cannot be passed to parameters declared as
michael@0 22 // out or inout."
michael@0 23 // GLSL 1.1 section 5.8: "Other binary or unary expressions,
michael@0 24 // non-dereferenced arrays, function names, swizzles with repeated fields,
michael@0 25 // and constants cannot be l-values."
michael@0 26 // GLSL 1.2 relaxed the restriction on arrays, section 5.8: "Variables that
michael@0 27 // are built-in types, entire structures or arrays... are all l-values."
michael@0 28 //
michael@0 29 // TODO(alokp): The following two cases of invariant decalaration get lost
michael@0 30 // during parsing - they do not get carried over to the intermediate tree.
michael@0 31 // Handle these cases:
michael@0 32 // 1. When a pragma is used to force all output variables to be invariant:
michael@0 33 // - #pragma STDGL invariant(all)
michael@0 34 // 2. When a previously decalared or built-in variable is marked invariant:
michael@0 35 // - invariant gl_Position;
michael@0 36 // - varying vec3 color; invariant color;
michael@0 37 //
michael@0 38 TVersionGLSL::TVersionGLSL(ShShaderType type)
michael@0 39 : mShaderType(type),
michael@0 40 mVersion(GLSL_VERSION_110)
michael@0 41 {
michael@0 42 }
michael@0 43
michael@0 44 void TVersionGLSL::visitSymbol(TIntermSymbol* node)
michael@0 45 {
michael@0 46 if (node->getSymbol() == "gl_PointCoord")
michael@0 47 updateVersion(GLSL_VERSION_120);
michael@0 48 }
michael@0 49
michael@0 50 void TVersionGLSL::visitConstantUnion(TIntermConstantUnion*)
michael@0 51 {
michael@0 52 }
michael@0 53
michael@0 54 bool TVersionGLSL::visitBinary(Visit, TIntermBinary*)
michael@0 55 {
michael@0 56 return true;
michael@0 57 }
michael@0 58
michael@0 59 bool TVersionGLSL::visitUnary(Visit, TIntermUnary*)
michael@0 60 {
michael@0 61 return true;
michael@0 62 }
michael@0 63
michael@0 64 bool TVersionGLSL::visitSelection(Visit, TIntermSelection*)
michael@0 65 {
michael@0 66 return true;
michael@0 67 }
michael@0 68
michael@0 69 bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node)
michael@0 70 {
michael@0 71 bool visitChildren = true;
michael@0 72
michael@0 73 switch (node->getOp()) {
michael@0 74 case EOpSequence:
michael@0 75 // We need to visit sequence children to get to global or inner scope.
michael@0 76 visitChildren = true;
michael@0 77 break;
michael@0 78 case EOpDeclaration: {
michael@0 79 const TIntermSequence& sequence = node->getSequence();
michael@0 80 TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
michael@0 81 if ((qualifier == EvqInvariantVaryingIn) ||
michael@0 82 (qualifier == EvqInvariantVaryingOut)) {
michael@0 83 updateVersion(GLSL_VERSION_120);
michael@0 84 }
michael@0 85 break;
michael@0 86 }
michael@0 87 case EOpParameters: {
michael@0 88 const TIntermSequence& params = node->getSequence();
michael@0 89 for (TIntermSequence::const_iterator iter = params.begin();
michael@0 90 iter != params.end(); ++iter)
michael@0 91 {
michael@0 92 const TIntermTyped* param = (*iter)->getAsTyped();
michael@0 93 if (param->isArray())
michael@0 94 {
michael@0 95 TQualifier qualifier = param->getQualifier();
michael@0 96 if ((qualifier == EvqOut) || (qualifier == EvqInOut))
michael@0 97 {
michael@0 98 updateVersion(GLSL_VERSION_120);
michael@0 99 break;
michael@0 100 }
michael@0 101 }
michael@0 102 }
michael@0 103 // Fully processed. No need to visit children.
michael@0 104 visitChildren = false;
michael@0 105 break;
michael@0 106 }
michael@0 107 case EOpConstructMat2:
michael@0 108 case EOpConstructMat3:
michael@0 109 case EOpConstructMat4: {
michael@0 110 const TIntermSequence& sequence = node->getSequence();
michael@0 111 if (sequence.size() == 1) {
michael@0 112 TIntermTyped* typed = sequence.front()->getAsTyped();
michael@0 113 if (typed && typed->isMatrix()) {
michael@0 114 updateVersion(GLSL_VERSION_120);
michael@0 115 }
michael@0 116 }
michael@0 117 break;
michael@0 118 }
michael@0 119
michael@0 120 default: break;
michael@0 121 }
michael@0 122
michael@0 123 return visitChildren;
michael@0 124 }
michael@0 125
michael@0 126 bool TVersionGLSL::visitLoop(Visit, TIntermLoop*)
michael@0 127 {
michael@0 128 return true;
michael@0 129 }
michael@0 130
michael@0 131 bool TVersionGLSL::visitBranch(Visit, TIntermBranch*)
michael@0 132 {
michael@0 133 return true;
michael@0 134 }
michael@0 135
michael@0 136 void TVersionGLSL::updateVersion(int version)
michael@0 137 {
michael@0 138 mVersion = std::max(version, mVersion);
michael@0 139 }
michael@0 140

mercurial