gfx/angle/src/compiler/BuiltInFunctionEmulator.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/compiler/BuiltInFunctionEmulator.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +//
     1.5 +// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +#ifndef COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
    1.11 +#define COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_
    1.12 +
    1.13 +#include "GLSLANG/ShaderLang.h"
    1.14 +
    1.15 +#include "compiler/InfoSink.h"
    1.16 +#include "compiler/intermediate.h"
    1.17 +
    1.18 +//
    1.19 +// This class decides which built-in functions need to be replaced with the
    1.20 +// emulated ones.
    1.21 +// It's only a workaround for OpenGL driver bugs, and isn't needed in general.
    1.22 +//
    1.23 +class BuiltInFunctionEmulator {
    1.24 +public:
    1.25 +    BuiltInFunctionEmulator(ShShaderType shaderType);
    1.26 +    // Records that a function is called by the shader and might needs to be
    1.27 +    // emulated.  If the function's group is not in mFunctionGroupFilter, this
    1.28 +    // becomes an no-op.
    1.29 +    // Returns true if the function call needs to be replaced with an emulated
    1.30 +    // one.
    1.31 +    bool SetFunctionCalled(TOperator op, const TType& param);
    1.32 +    bool SetFunctionCalled(
    1.33 +        TOperator op, const TType& param1, const TType& param2);
    1.34 +    bool SetFunctionCalled(
    1.35 +        TOperator op, const TType& param1, const TType& param2, const TType& param3);
    1.36 +
    1.37 +    // Output function emulation definition.  This should be before any other
    1.38 +    // shader source.
    1.39 +    void OutputEmulatedFunctionDefinition(TInfoSinkBase& out, bool withPrecision) const;
    1.40 +
    1.41 +    void MarkBuiltInFunctionsForEmulation(TIntermNode* root);
    1.42 +
    1.43 +    void Cleanup();
    1.44 +
    1.45 +    // "name(" becomes "webgl_name_emu(".
    1.46 +    static TString GetEmulatedFunctionName(const TString& name);
    1.47 +
    1.48 +private:
    1.49 +    //
    1.50 +    // Built-in functions.
    1.51 +    //
    1.52 +    enum TBuiltInFunction {
    1.53 +        TFunctionCos1 = 0,  // float cos(float);
    1.54 +        TFunctionCos2,  // vec2 cos(vec2);
    1.55 +        TFunctionCos3,  // vec3 cos(vec3);
    1.56 +        TFunctionCos4,  // vec4 cos(vec4);
    1.57 +
    1.58 +        TFunctionDistance1_1,  // float distance(float, float);
    1.59 +        TFunctionDistance2_2,  // vec2 distance(vec2, vec2);
    1.60 +        TFunctionDistance3_3,  // vec3 distance(vec3, vec3);
    1.61 +        TFunctionDistance4_4,  // vec4 distance(vec4, vec4);
    1.62 +
    1.63 +        TFunctionDot1_1,  // float dot(float, float);
    1.64 +        TFunctionDot2_2,  // vec2 dot(vec2, vec2);
    1.65 +        TFunctionDot3_3,  // vec3 dot(vec3, vec3);
    1.66 +        TFunctionDot4_4,  // vec4 dot(vec4, vec4);
    1.67 +
    1.68 +        TFunctionFaceForward1_1_1,  // float faceforward(float, float, float);
    1.69 +        TFunctionFaceForward2_2_2,  // vec2 faceforward(vec2, vec2, vec2);
    1.70 +        TFunctionFaceForward3_3_3,  // vec3 faceforward(vec3, vec3, vec3);
    1.71 +        TFunctionFaceForward4_4_4,  // vec4 faceforward(vec4, vec4, vec4);
    1.72 +
    1.73 +        TFunctionLength1,  // float length(float);
    1.74 +        TFunctionLength2,  // float length(vec2);
    1.75 +        TFunctionLength3,  // float length(vec3);
    1.76 +        TFunctionLength4,  // float length(vec4);
    1.77 +
    1.78 +        TFunctionNormalize1,  // float normalize(float);
    1.79 +        TFunctionNormalize2,  // vec2 normalize(vec2);
    1.80 +        TFunctionNormalize3,  // vec3 normalize(vec3);
    1.81 +        TFunctionNormalize4,  // vec4 normalize(vec4);
    1.82 +
    1.83 +        TFunctionReflect1_1,  // float reflect(float, float);
    1.84 +        TFunctionReflect2_2,  // vec2 reflect(vec2, vec2);
    1.85 +        TFunctionReflect3_3,  // vec3 reflect(vec3, vec3);
    1.86 +        TFunctionReflect4_4,  // vec4 reflect(vec4, vec4);
    1.87 +
    1.88 +        TFunctionUnknown
    1.89 +    };
    1.90 +
    1.91 +    TBuiltInFunction IdentifyFunction(TOperator op, const TType& param);
    1.92 +    TBuiltInFunction IdentifyFunction(
    1.93 +        TOperator op, const TType& param1, const TType& param2);
    1.94 +    TBuiltInFunction IdentifyFunction(
    1.95 +        TOperator op, const TType& param1, const TType& param2, const TType& param3);
    1.96 +
    1.97 +    bool SetFunctionCalled(TBuiltInFunction function);
    1.98 +
    1.99 +    std::vector<TBuiltInFunction> mFunctions;
   1.100 +
   1.101 +    const bool* mFunctionMask;  // a boolean flag for each function.
   1.102 +    const char** mFunctionSource;
   1.103 +};
   1.104 +
   1.105 +#endif  // COMPILIER_BUILT_IN_FUNCTION_EMULATOR_H_

mercurial