gfx/angle/angle-faceforward-emu.patch

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 From: Jeff Gilbert <jgilbert@mozilla.com>
michael@0 2 Bug 771406 - Add emulation for GLSL faceforward() to ANGLE - r=bjacob
michael@0 3
michael@0 4 diff --git a/gfx/angle/src/compiler/BuiltInFunctionEmulator.cpp b/gfx/angle/src/compiler/BuiltInFunctionEmulator.cpp
michael@0 5 --- a/gfx/angle/src/compiler/BuiltInFunctionEmulator.cpp
michael@0 6 +++ b/gfx/angle/src/compiler/BuiltInFunctionEmulator.cpp
michael@0 7 @@ -26,16 +26,22 @@ const char* kFunctionEmulationVertexSour
michael@0 8 "#error no emulation for distance(vec3, vec3)",
michael@0 9 "#error no emulation for distance(vec4, vec4)",
michael@0 10
michael@0 11 "#define webgl_dot_emu(x, y) ((x) * (y))",
michael@0 12 "#error no emulation for dot(vec2, vec2)",
michael@0 13 "#error no emulation for dot(vec3, vec3)",
michael@0 14 "#error no emulation for dot(vec4, vec4)",
michael@0 15
michael@0 16 + // |faceforward(N, I, Nref)| is |dot(NRef, I) < 0 ? N : -N|
michael@0 17 + "#define webgl_faceforward_emu(N, I, Nref) (((Nref) * (I) < 0.0) ? (N) : -(N))",
michael@0 18 + "#error no emulation for faceforward(vec2, vec2, vec2)",
michael@0 19 + "#error no emulation for faceforward(vec3, vec3, vec3)",
michael@0 20 + "#error no emulation for faceforward(vec4, vec4, vec4)",
michael@0 21 +
michael@0 22 "#define webgl_length_emu(x) ((x) >= 0.0 ? (x) : -(x))",
michael@0 23 "#error no emulation for length(vec2)",
michael@0 24 "#error no emulation for length(vec3)",
michael@0 25 "#error no emulation for length(vec4)",
michael@0 26
michael@0 27 "#define webgl_normalize_emu(x) ((x) == 0.0 ? 0.0 : ((x) > 0.0 ? 1.0 : -1.0))",
michael@0 28 "#error no emulation for normalize(vec2)",
michael@0 29 "#error no emulation for normalize(vec3)",
michael@0 30 @@ -58,16 +64,22 @@ const char* kFunctionEmulationFragmentSo
michael@0 31 "#error no emulation for distance(vec3, vec3)",
michael@0 32 "#error no emulation for distance(vec4, vec4)",
michael@0 33
michael@0 34 "#define webgl_dot_emu(x, y) ((x) * (y))",
michael@0 35 "#error no emulation for dot(vec2, vec2)",
michael@0 36 "#error no emulation for dot(vec3, vec3)",
michael@0 37 "#error no emulation for dot(vec4, vec4)",
michael@0 38
michael@0 39 + // |faceforward(N, I, Nref)| is |dot(NRef, I) < 0 ? N : -N|
michael@0 40 + "#define webgl_faceforward_emu(N, I, Nref) (((Nref) * (I) < 0.0) ? (N) : -(N))",
michael@0 41 + "#error no emulation for faceforward(vec2, vec2, vec2)",
michael@0 42 + "#error no emulation for faceforward(vec3, vec3, vec3)",
michael@0 43 + "#error no emulation for faceforward(vec4, vec4, vec4)",
michael@0 44 +
michael@0 45 "#define webgl_length_emu(x) ((x) >= 0.0 ? (x) : -(x))",
michael@0 46 "#error no emulation for length(vec2)",
michael@0 47 "#error no emulation for length(vec3)",
michael@0 48 "#error no emulation for length(vec4)",
michael@0 49
michael@0 50 "#define webgl_normalize_emu(x) ((x) == 0.0 ? 0.0 : ((x) > 0.0 ? 1.0 : -1.0))",
michael@0 51 "#error no emulation for normalize(vec2)",
michael@0 52 "#error no emulation for normalize(vec3)",
michael@0 53 @@ -89,16 +101,20 @@ const bool kFunctionEmulationVertexMask[
michael@0 54 true, // TFunctionDistance1_1
michael@0 55 false, // TFunctionDistance2_2
michael@0 56 false, // TFunctionDistance3_3
michael@0 57 false, // TFunctionDistance4_4
michael@0 58 true, // TFunctionDot1_1
michael@0 59 false, // TFunctionDot2_2
michael@0 60 false, // TFunctionDot3_3
michael@0 61 false, // TFunctionDot4_4
michael@0 62 + true, // TFunctionFaceForward1_1_1
michael@0 63 + false, // TFunctionFaceForward2_2_2
michael@0 64 + false, // TFunctionFaceForward3_3_3
michael@0 65 + false, // TFunctionFaceForward4_4_4
michael@0 66 true, // TFunctionLength1
michael@0 67 false, // TFunctionLength2
michael@0 68 false, // TFunctionLength3
michael@0 69 false, // TFunctionLength4
michael@0 70 true, // TFunctionNormalize1
michael@0 71 false, // TFunctionNormalize2
michael@0 72 false, // TFunctionNormalize3
michael@0 73 false, // TFunctionNormalize4
michael@0 74 @@ -115,16 +131,20 @@ const bool kFunctionEmulationVertexMask[
michael@0 75 false, // TFunctionDistance1_1
michael@0 76 false, // TFunctionDistance2_2
michael@0 77 false, // TFunctionDistance3_3
michael@0 78 false, // TFunctionDistance4_4
michael@0 79 false, // TFunctionDot1_1
michael@0 80 false, // TFunctionDot2_2
michael@0 81 false, // TFunctionDot3_3
michael@0 82 false, // TFunctionDot4_4
michael@0 83 + false, // TFunctionFaceForward1_1_1
michael@0 84 + false, // TFunctionFaceForward2_2_2
michael@0 85 + false, // TFunctionFaceForward3_3_3
michael@0 86 + false, // TFunctionFaceForward4_4_4
michael@0 87 false, // TFunctionLength1
michael@0 88 false, // TFunctionLength2
michael@0 89 false, // TFunctionLength3
michael@0 90 false, // TFunctionLength4
michael@0 91 false, // TFunctionNormalize1
michael@0 92 false, // TFunctionNormalize2
michael@0 93 false, // TFunctionNormalize3
michael@0 94 false, // TFunctionNormalize4
michael@0 95 @@ -146,16 +166,20 @@ const bool kFunctionEmulationFragmentMas
michael@0 96 true, // TFunctionDistance1_1
michael@0 97 false, // TFunctionDistance2_2
michael@0 98 false, // TFunctionDistance3_3
michael@0 99 false, // TFunctionDistance4_4
michael@0 100 true, // TFunctionDot1_1
michael@0 101 false, // TFunctionDot2_2
michael@0 102 false, // TFunctionDot3_3
michael@0 103 false, // TFunctionDot4_4
michael@0 104 + true, // TFunctionFaceForward1_1_1
michael@0 105 + false, // TFunctionFaceForward2_2_2
michael@0 106 + false, // TFunctionFaceForward3_3_3
michael@0 107 + false, // TFunctionFaceForward4_4_4
michael@0 108 true, // TFunctionLength1
michael@0 109 false, // TFunctionLength2
michael@0 110 false, // TFunctionLength3
michael@0 111 false, // TFunctionLength4
michael@0 112 true, // TFunctionNormalize1
michael@0 113 false, // TFunctionNormalize2
michael@0 114 false, // TFunctionNormalize3
michael@0 115 false, // TFunctionNormalize4
michael@0 116 @@ -172,16 +196,20 @@ const bool kFunctionEmulationFragmentMas
michael@0 117 false, // TFunctionDistance1_1
michael@0 118 false, // TFunctionDistance2_2
michael@0 119 false, // TFunctionDistance3_3
michael@0 120 false, // TFunctionDistance4_4
michael@0 121 false, // TFunctionDot1_1
michael@0 122 false, // TFunctionDot2_2
michael@0 123 false, // TFunctionDot3_3
michael@0 124 false, // TFunctionDot4_4
michael@0 125 + false, // TFunctionFaceForward1_1_1
michael@0 126 + false, // TFunctionFaceForward2_2_2
michael@0 127 + false, // TFunctionFaceForward3_3_3
michael@0 128 + false, // TFunctionFaceForward4_4_4
michael@0 129 false, // TFunctionLength1
michael@0 130 false, // TFunctionLength2
michael@0 131 false, // TFunctionLength3
michael@0 132 false, // TFunctionLength4
michael@0 133 false, // TFunctionNormalize1
michael@0 134 false, // TFunctionNormalize2
michael@0 135 false, // TFunctionNormalize3
michael@0 136 false, // TFunctionNormalize4
michael@0 137 @@ -239,25 +267,37 @@ public:
michael@0 138 case EOpReflect:
michael@0 139 case EOpRefract:
michael@0 140 case EOpMul:
michael@0 141 break;
michael@0 142 default:
michael@0 143 return true;
michael@0 144 };
michael@0 145 const TIntermSequence& sequence = node->getSequence();
michael@0 146 - // Right now we only handle built-in functions with two parameters.
michael@0 147 - if (sequence.size() != 2)
michael@0 148 + bool needToEmulate = false;
michael@0 149 +
michael@0 150 + if (sequence.size() == 2) {
michael@0 151 + TIntermTyped* param1 = sequence[0]->getAsTyped();
michael@0 152 + TIntermTyped* param2 = sequence[1]->getAsTyped();
michael@0 153 + if (!param1 || !param2)
michael@0 154 + return true;
michael@0 155 + needToEmulate = mEmulator.SetFunctionCalled(
michael@0 156 + node->getOp(), param1->getType(), param2->getType());
michael@0 157 + } else if (sequence.size() == 3) {
michael@0 158 + TIntermTyped* param1 = sequence[0]->getAsTyped();
michael@0 159 + TIntermTyped* param2 = sequence[1]->getAsTyped();
michael@0 160 + TIntermTyped* param3 = sequence[2]->getAsTyped();
michael@0 161 + if (!param1 || !param2 || !param3)
michael@0 162 + return true;
michael@0 163 + needToEmulate = mEmulator.SetFunctionCalled(
michael@0 164 + node->getOp(), param1->getType(), param2->getType(), param3->getType());
michael@0 165 + } else {
michael@0 166 return true;
michael@0 167 - TIntermTyped* param1 = sequence[0]->getAsTyped();
michael@0 168 - TIntermTyped* param2 = sequence[1]->getAsTyped();
michael@0 169 - if (!param1 || !param2)
michael@0 170 - return true;
michael@0 171 - bool needToEmulate = mEmulator.SetFunctionCalled(
michael@0 172 - node->getOp(), param1->getType(), param2->getType());
michael@0 173 + }
michael@0 174 +
michael@0 175 if (needToEmulate)
michael@0 176 node->setUseEmulatedFunction();
michael@0 177 }
michael@0 178 return true;
michael@0 179 }
michael@0 180
michael@0 181 private:
michael@0 182 BuiltInFunctionEmulator& mEmulator;
michael@0 183 @@ -286,16 +326,23 @@ bool BuiltInFunctionEmulator::SetFunctio
michael@0 184 bool BuiltInFunctionEmulator::SetFunctionCalled(
michael@0 185 TOperator op, const TType& param1, const TType& param2)
michael@0 186 {
michael@0 187 TBuiltInFunction function = IdentifyFunction(op, param1, param2);
michael@0 188 return SetFunctionCalled(function);
michael@0 189 }
michael@0 190
michael@0 191 bool BuiltInFunctionEmulator::SetFunctionCalled(
michael@0 192 + TOperator op, const TType& param1, const TType& param2, const TType& param3)
michael@0 193 +{
michael@0 194 + TBuiltInFunction function = IdentifyFunction(op, param1, param2, param3);
michael@0 195 + return SetFunctionCalled(function);
michael@0 196 +}
michael@0 197 +
michael@0 198 +bool BuiltInFunctionEmulator::SetFunctionCalled(
michael@0 199 BuiltInFunctionEmulator::TBuiltInFunction function) {
michael@0 200 if (function == TFunctionUnknown || mFunctionMask[function] == false)
michael@0 201 return false;
michael@0 202 for (size_t i = 0; i < mFunctions.size(); ++i) {
michael@0 203 if (mFunctions[i] == function)
michael@0 204 return true;
michael@0 205 }
michael@0 206 mFunctions.push_back(function);
michael@0 207 @@ -377,16 +424,44 @@ BuiltInFunctionEmulator::IdentifyFunctio
michael@0 208 }
michael@0 209 if (function == TFunctionUnknown)
michael@0 210 return TFunctionUnknown;
michael@0 211 if (param1.isVector())
michael@0 212 function += param1.getNominalSize() - 1;
michael@0 213 return static_cast<TBuiltInFunction>(function);
michael@0 214 }
michael@0 215
michael@0 216 +BuiltInFunctionEmulator::TBuiltInFunction
michael@0 217 +BuiltInFunctionEmulator::IdentifyFunction(
michael@0 218 + TOperator op, const TType& param1, const TType& param2, const TType& param3)
michael@0 219 +{
michael@0 220 + // Check that all params have the same type, length,
michael@0 221 + // and that they're not too large.
michael@0 222 + if (param1.isVector() != param2.isVector() ||
michael@0 223 + param2.isVector() != param3.isVector() ||
michael@0 224 + param1.getNominalSize() != param2.getNominalSize() ||
michael@0 225 + param2.getNominalSize() != param3.getNominalSize() ||
michael@0 226 + param1.getNominalSize() > 4)
michael@0 227 + return TFunctionUnknown;
michael@0 228 +
michael@0 229 + unsigned int function = TFunctionUnknown;
michael@0 230 + switch (op) {
michael@0 231 + case EOpFaceForward:
michael@0 232 + function = TFunctionFaceForward1_1_1;
michael@0 233 + break;
michael@0 234 + default:
michael@0 235 + break;
michael@0 236 + }
michael@0 237 + if (function == TFunctionUnknown)
michael@0 238 + return TFunctionUnknown;
michael@0 239 + if (param1.isVector())
michael@0 240 + function += param1.getNominalSize() - 1;
michael@0 241 + return static_cast<TBuiltInFunction>(function);
michael@0 242 +}
michael@0 243 +
michael@0 244 void BuiltInFunctionEmulator::MarkBuiltInFunctionsForEmulation(
michael@0 245 TIntermNode* root)
michael@0 246 {
michael@0 247 ASSERT(root);
michael@0 248
michael@0 249 BuiltInFunctionEmulationMarker marker(*this);
michael@0 250 root->traverse(&marker);
michael@0 251 }
michael@0 252 diff --git a/gfx/angle/src/compiler/BuiltInFunctionEmulator.h b/gfx/angle/src/compiler/BuiltInFunctionEmulator.h
michael@0 253 --- a/gfx/angle/src/compiler/BuiltInFunctionEmulator.h
michael@0 254 +++ b/gfx/angle/src/compiler/BuiltInFunctionEmulator.h
michael@0 255 @@ -23,16 +23,18 @@ public:
michael@0 256 // Records that a function is called by the shader and might needs to be
michael@0 257 // emulated. If the function's group is not in mFunctionGroupFilter, this
michael@0 258 // becomes an no-op.
michael@0 259 // Returns true if the function call needs to be replaced with an emulated
michael@0 260 // one.
michael@0 261 bool SetFunctionCalled(TOperator op, const TType& param);
michael@0 262 bool SetFunctionCalled(
michael@0 263 TOperator op, const TType& param1, const TType& param2);
michael@0 264 + bool SetFunctionCalled(
michael@0 265 + TOperator op, const TType& param1, const TType& param2, const TType& param3);
michael@0 266
michael@0 267 // Output function emulation definition. This should be before any other
michael@0 268 // shader source.
michael@0 269 void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
michael@0 270
michael@0 271 void MarkBuiltInFunctionsForEmulation(TIntermNode* root);
michael@0 272
michael@0 273 void Cleanup();
michael@0 274 @@ -55,16 +57,21 @@ private:
michael@0 275 TFunctionDistance3_3, // vec3 distance(vec3, vec3);
michael@0 276 TFunctionDistance4_4, // vec4 distance(vec4, vec4);
michael@0 277
michael@0 278 TFunctionDot1_1, // float dot(float, float);
michael@0 279 TFunctionDot2_2, // vec2 dot(vec2, vec2);
michael@0 280 TFunctionDot3_3, // vec3 dot(vec3, vec3);
michael@0 281 TFunctionDot4_4, // vec4 dot(vec4, vec4);
michael@0 282
michael@0 283 + TFunctionFaceForward1_1_1, // float faceforward(float, float, float);
michael@0 284 + TFunctionFaceForward2_2_2, // vec2 faceforward(vec2, vec2, vec2);
michael@0 285 + TFunctionFaceForward3_3_3, // vec3 faceforward(vec3, vec3, vec3);
michael@0 286 + TFunctionFaceForward4_4_4, // vec4 faceforward(vec4, vec4, vec4);
michael@0 287 +
michael@0 288 TFunctionLength1, // float length(float);
michael@0 289 TFunctionLength2, // float length(vec2);
michael@0 290 TFunctionLength3, // float length(vec3);
michael@0 291 TFunctionLength4, // float length(vec4);
michael@0 292
michael@0 293 TFunctionNormalize1, // float normalize(float);
michael@0 294 TFunctionNormalize2, // vec2 normalize(vec2);
michael@0 295 TFunctionNormalize3, // vec3 normalize(vec3);
michael@0 296 @@ -76,16 +83,18 @@ private:
michael@0 297 TFunctionReflect4_4, // vec4 reflect(vec4, vec4);
michael@0 298
michael@0 299 TFunctionUnknown
michael@0 300 };
michael@0 301
michael@0 302 TBuiltInFunction IdentifyFunction(TOperator op, const TType& param);
michael@0 303 TBuiltInFunction IdentifyFunction(
michael@0 304 TOperator op, const TType& param1, const TType& param2);
michael@0 305 + TBuiltInFunction IdentifyFunction(
michael@0 306 + TOperator op, const TType& param1, const TType& param2, const TType& param3);
michael@0 307
michael@0 308 bool SetFunctionCalled(TBuiltInFunction function);
michael@0 309
michael@0 310 std::vector<TBuiltInFunction> mFunctions;
michael@0 311
michael@0 312 const bool* mFunctionMask; // a boolean flag for each function.
michael@0 313 const char** mFunctionSource;
michael@0 314 };

mercurial