gfx/angle/src/compiler/timing/RestrictFragmentShaderTiming.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 //
michael@0 2 // Copyright (c) 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/InfoSink.h"
michael@0 8 #include "compiler/ParseHelper.h"
michael@0 9 #include "compiler/depgraph/DependencyGraphOutput.h"
michael@0 10 #include "compiler/timing/RestrictFragmentShaderTiming.h"
michael@0 11
michael@0 12 RestrictFragmentShaderTiming::RestrictFragmentShaderTiming(TInfoSinkBase& sink)
michael@0 13 : mSink(sink)
michael@0 14 , mNumErrors(0)
michael@0 15 {
michael@0 16 // Sampling ops found only in fragment shaders.
michael@0 17 mSamplingOps.insert("texture2D(s21;vf2;f1;");
michael@0 18 mSamplingOps.insert("texture2DProj(s21;vf3;f1;");
michael@0 19 mSamplingOps.insert("texture2DProj(s21;vf4;f1;");
michael@0 20 mSamplingOps.insert("textureCube(sC1;vf3;f1;");
michael@0 21 // Sampling ops found in both vertex and fragment shaders.
michael@0 22 mSamplingOps.insert("texture2D(s21;vf2;");
michael@0 23 mSamplingOps.insert("texture2DProj(s21;vf3;");
michael@0 24 mSamplingOps.insert("texture2DProj(s21;vf4;");
michael@0 25 mSamplingOps.insert("textureCube(sC1;vf3;");
michael@0 26 // Sampling ops provided by OES_EGL_image_external.
michael@0 27 mSamplingOps.insert("texture2D(1;vf2;");
michael@0 28 mSamplingOps.insert("texture2DProj(1;vf3;");
michael@0 29 mSamplingOps.insert("texture2DProj(1;vf4;");
michael@0 30 // Sampling ops provided by ARB_texture_rectangle.
michael@0 31 mSamplingOps.insert("texture2DRect(1;vf2;");
michael@0 32 mSamplingOps.insert("texture2DRectProj(1;vf3;");
michael@0 33 mSamplingOps.insert("texture2DRectProj(1;vf4;");
michael@0 34 }
michael@0 35
michael@0 36 // FIXME(mvujovic): We do not know if the execution time of built-in operations like sin, pow, etc.
michael@0 37 // can vary based on the value of the input arguments. If so, we should restrict those as well.
michael@0 38 void RestrictFragmentShaderTiming::enforceRestrictions(const TDependencyGraph& graph)
michael@0 39 {
michael@0 40 mNumErrors = 0;
michael@0 41
michael@0 42 // FIXME(mvujovic): The dependency graph does not support user defined function calls right now,
michael@0 43 // so we generate errors for them.
michael@0 44 validateUserDefinedFunctionCallUsage(graph);
michael@0 45
michael@0 46 // Starting from each sampler, traverse the dependency graph and generate an error each time we
michael@0 47 // hit a node where sampler dependent values are not allowed.
michael@0 48 for (TGraphSymbolVector::const_iterator iter = graph.beginSamplerSymbols();
michael@0 49 iter != graph.endSamplerSymbols();
michael@0 50 ++iter)
michael@0 51 {
michael@0 52 TGraphSymbol* samplerSymbol = *iter;
michael@0 53 clearVisited();
michael@0 54 samplerSymbol->traverse(this);
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 void RestrictFragmentShaderTiming::validateUserDefinedFunctionCallUsage(const TDependencyGraph& graph)
michael@0 59 {
michael@0 60 for (TFunctionCallVector::const_iterator iter = graph.beginUserDefinedFunctionCalls();
michael@0 61 iter != graph.endUserDefinedFunctionCalls();
michael@0 62 ++iter)
michael@0 63 {
michael@0 64 TGraphFunctionCall* functionCall = *iter;
michael@0 65 beginError(functionCall->getIntermFunctionCall());
michael@0 66 mSink << "A call to a user defined function is not permitted.\n";
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 void RestrictFragmentShaderTiming::beginError(const TIntermNode* node)
michael@0 71 {
michael@0 72 ++mNumErrors;
michael@0 73 mSink.prefix(EPrefixError);
michael@0 74 mSink.location(node->getLine());
michael@0 75 }
michael@0 76
michael@0 77 bool RestrictFragmentShaderTiming::isSamplingOp(const TIntermAggregate* intermFunctionCall) const
michael@0 78 {
michael@0 79 return !intermFunctionCall->isUserDefined() &&
michael@0 80 mSamplingOps.find(intermFunctionCall->getName()) != mSamplingOps.end();
michael@0 81 }
michael@0 82
michael@0 83 void RestrictFragmentShaderTiming::visitArgument(TGraphArgument* parameter)
michael@0 84 {
michael@0 85 // Texture cache access time might leak sensitive information.
michael@0 86 // Thus, we restrict sampler dependent values from affecting the coordinate or LOD bias of a
michael@0 87 // sampling operation.
michael@0 88 if (isSamplingOp(parameter->getIntermFunctionCall())) {
michael@0 89 switch (parameter->getArgumentNumber()) {
michael@0 90 case 1:
michael@0 91 // Second argument (coord)
michael@0 92 beginError(parameter->getIntermFunctionCall());
michael@0 93 mSink << "An expression dependent on a sampler is not permitted to be the"
michael@0 94 << " coordinate argument of a sampling operation.\n";
michael@0 95 break;
michael@0 96 case 2:
michael@0 97 // Third argument (bias)
michael@0 98 beginError(parameter->getIntermFunctionCall());
michael@0 99 mSink << "An expression dependent on a sampler is not permitted to be the"
michael@0 100 << " bias argument of a sampling operation.\n";
michael@0 101 break;
michael@0 102 default:
michael@0 103 // First argument (sampler)
michael@0 104 break;
michael@0 105 }
michael@0 106 }
michael@0 107 }
michael@0 108
michael@0 109 void RestrictFragmentShaderTiming::visitSelection(TGraphSelection* selection)
michael@0 110 {
michael@0 111 beginError(selection->getIntermSelection());
michael@0 112 mSink << "An expression dependent on a sampler is not permitted in a conditional statement.\n";
michael@0 113 }
michael@0 114
michael@0 115 void RestrictFragmentShaderTiming::visitLoop(TGraphLoop* loop)
michael@0 116 {
michael@0 117 beginError(loop->getIntermLoop());
michael@0 118 mSink << "An expression dependent on a sampler is not permitted in a loop condition.\n";
michael@0 119 }
michael@0 120
michael@0 121 void RestrictFragmentShaderTiming::visitLogicalOp(TGraphLogicalOp* logicalOp)
michael@0 122 {
michael@0 123 beginError(logicalOp->getIntermLogicalOp());
michael@0 124 mSink << "An expression dependent on a sampler is not permitted on the left hand side of a logical "
michael@0 125 << logicalOp->getOpString()
michael@0 126 << " operator.\n";
michael@0 127 }

mercurial