Commit 8b8f02dc by maxvujovic@gmail.com

[SH_TIMING_RESTRICTIONS] Restrict sampler dependent values from the tex coord…

[SH_TIMING_RESTRICTIONS] Restrict sampler dependent values from the tex coord and bias parameters of all sampling operations, not just texture2D. Issue: 335 Review URL: https://codereview.appspot.com/6305049/ git-svn-id: https://angleproject.googlecode.com/svn/trunk@1167 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 635d6b5d
...@@ -117,6 +117,7 @@ int main(int argc, char* argv[]) ...@@ -117,6 +117,7 @@ int main(int argc, char* argv[])
switch (argv[0][3]) { switch (argv[0][3]) {
case 'i': resources.OES_EGL_image_external = 1; break; case 'i': resources.OES_EGL_image_external = 1; break;
case 'd': resources.OES_standard_derivatives = 1; break; case 'd': resources.OES_standard_derivatives = 1; break;
case 'r': resources.ARB_texture_rectangle = 1; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { } else {
...@@ -220,7 +221,8 @@ void usage() ...@@ -220,7 +221,8 @@ void usage()
" -b=g : output GLSL code\n" " -b=g : output GLSL code\n"
" -b=h : output HLSL code\n" " -b=h : output HLSL code\n"
" -x=i : enable GL_OES_EGL_image_external\n" " -x=i : enable GL_OES_EGL_image_external\n"
" -x=d : enable GL_OES_EGL_standard_derivatives\n"); " -x=d : enable GL_OES_EGL_standard_derivatives\n"
" -x=r : enable ARB_texture_rectangle\n");
} }
// //
......
...@@ -9,6 +9,30 @@ ...@@ -9,6 +9,30 @@
#include "compiler/depgraph/DependencyGraphOutput.h" #include "compiler/depgraph/DependencyGraphOutput.h"
#include "compiler/timing/RestrictFragmentShaderTiming.h" #include "compiler/timing/RestrictFragmentShaderTiming.h"
RestrictFragmentShaderTiming::RestrictFragmentShaderTiming(TInfoSinkBase& sink)
: mSink(sink)
, mNumErrors(0)
{
// Sampling ops found only in fragment shaders.
mSamplingOps.insert("texture2D(s21;vf2;f1;");
mSamplingOps.insert("texture2DProj(s21;vf3;f1;");
mSamplingOps.insert("texture2DProj(s21;vf4;f1;");
mSamplingOps.insert("textureCube(sC1;vf3;f1;");
// Sampling ops found in both vertex and fragment shaders.
mSamplingOps.insert("texture2D(s21;vf2;");
mSamplingOps.insert("texture2DProj(s21;vf3;");
mSamplingOps.insert("texture2DProj(s21;vf4;");
mSamplingOps.insert("textureCube(sC1;vf3;");
// Sampling ops provided by OES_EGL_image_external.
mSamplingOps.insert("texture2D(1;vf2;");
mSamplingOps.insert("texture2DProj(1;vf3;");
mSamplingOps.insert("texture2DProj(1;vf4;");
// Sampling ops provided by ARB_texture_rectangle.
mSamplingOps.insert("texture2DRect(1;vf2;");
mSamplingOps.insert("texture2DRectProj(1;vf3;");
mSamplingOps.insert("texture2DRectProj(1;vf4;");
}
// FIXME(mvujovic): We do not know if the execution time of built-in operations like sin, pow, etc. // FIXME(mvujovic): We do not know if the execution time of built-in operations like sin, pow, etc.
// can vary based on the value of the input arguments. If so, we should restrict those as well. // can vary based on the value of the input arguments. If so, we should restrict those as well.
void RestrictFragmentShaderTiming::enforceRestrictions(const TDependencyGraph& graph) void RestrictFragmentShaderTiming::enforceRestrictions(const TDependencyGraph& graph)
...@@ -50,18 +74,36 @@ void RestrictFragmentShaderTiming::beginError(const TIntermNode* node) ...@@ -50,18 +74,36 @@ void RestrictFragmentShaderTiming::beginError(const TIntermNode* node)
mSink.location(node->getLine()); mSink.location(node->getLine());
} }
void RestrictFragmentShaderTiming::visitArgument(TGraphArgument* parameter) bool RestrictFragmentShaderTiming::isSamplingOp(const TIntermAggregate* intermFunctionCall) const
{ {
// FIXME(mvujovic): We should restrict sampler dependent values from being texture coordinates return !intermFunctionCall->isUserDefined() &&
// in all available sampling operations supported in GLSL ES. mSamplingOps.find(intermFunctionCall->getName()) != mSamplingOps.end();
// This includes overloaded signatures of texture2D, textureCube, and others. }
if (parameter->getIntermFunctionCall()->getName() != "texture2D(s21;vf2;" ||
parameter->getArgumentNumber() != 1)
return;
beginError(parameter->getIntermFunctionCall()); void RestrictFragmentShaderTiming::visitArgument(TGraphArgument* parameter)
mSink << "An expression dependent on a sampler is not permitted to be the second argument" {
<< " of a texture2D call.\n"; // Texture cache access time might leak sensitive information.
// Thus, we restrict sampler dependent values from affecting the coordinate or LOD bias of a
// sampling operation.
if (isSamplingOp(parameter->getIntermFunctionCall())) {
switch (parameter->getArgumentNumber()) {
case 1:
// Second argument (coord)
beginError(parameter->getIntermFunctionCall());
mSink << "An expression dependent on a sampler is not permitted to be the"
<< " coordinate argument of a sampling operation.\n";
break;
case 2:
// Third argument (bias)
beginError(parameter->getIntermFunctionCall());
mSink << "An expression dependent on a sampler is not permitted to be the"
<< " bias argument of a sampling operation.\n";
break;
default:
// First argument (sampler)
break;
}
}
} }
void RestrictFragmentShaderTiming::visitSelection(TGraphSelection* selection) void RestrictFragmentShaderTiming::visitSelection(TGraphSelection* selection)
......
...@@ -16,10 +16,7 @@ class TInfoSinkBase; ...@@ -16,10 +16,7 @@ class TInfoSinkBase;
class RestrictFragmentShaderTiming : TDependencyGraphTraverser { class RestrictFragmentShaderTiming : TDependencyGraphTraverser {
public: public:
RestrictFragmentShaderTiming(TInfoSinkBase& sink) RestrictFragmentShaderTiming(TInfoSinkBase& sink);
: mSink(sink)
, mNumErrors(0) {}
void enforceRestrictions(const TDependencyGraph& graph); void enforceRestrictions(const TDependencyGraph& graph);
int numErrors() const { return mNumErrors; } int numErrors() const { return mNumErrors; }
...@@ -31,9 +28,13 @@ public: ...@@ -31,9 +28,13 @@ public:
private: private:
void beginError(const TIntermNode* node); void beginError(const TIntermNode* node);
void validateUserDefinedFunctionCallUsage(const TDependencyGraph& graph); void validateUserDefinedFunctionCallUsage(const TDependencyGraph& graph);
bool isSamplingOp(const TIntermAggregate* intermFunctionCall) const;
TInfoSinkBase& mSink; TInfoSinkBase& mSink;
int mNumErrors; int mNumErrors;
typedef std::set<TString> StringSet;
StringSet mSamplingOps;
}; };
#endif // COMPILER_TIMING_RESTRICT_FRAGMENT_SHADER_TIMING_H_ #endif // COMPILER_TIMING_RESTRICT_FRAGMENT_SHADER_TIMING_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment