LCOV - code coverage report
Current view: top level - gfx/angle/include/GLSLANG - ShaderVars.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 5 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
       3             : // Use of this source code is governed by a BSD-style license that can be
       4             : // found in the LICENSE file.
       5             : //
       6             : // ShaderVars.h:
       7             : //  Types to represent GL variables (varyings, uniforms, etc)
       8             : //
       9             : 
      10             : #ifndef GLSLANG_SHADERVARS_H_
      11             : #define GLSLANG_SHADERVARS_H_
      12             : 
      13             : #include <algorithm>
      14             : #include <string>
      15             : #include <vector>
      16             : 
      17             : // This type is defined here to simplify ANGLE's integration with glslang for SPIRv.
      18             : using ShCompileOptions = uint64_t;
      19             : 
      20             : namespace sh
      21             : {
      22             : // GLenum alias
      23             : typedef unsigned int GLenum;
      24             : 
      25             : // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec
      26             : enum InterpolationType
      27             : {
      28             :     INTERPOLATION_SMOOTH,
      29             :     INTERPOLATION_CENTROID,
      30             :     INTERPOLATION_FLAT
      31             : };
      32             : 
      33             : // Validate link & SSO consistency of interpolation qualifiers
      34             : bool InterpolationTypesMatch(InterpolationType a, InterpolationType b);
      35             : 
      36             : // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec
      37             : enum BlockLayoutType
      38             : {
      39             :     BLOCKLAYOUT_STANDARD,
      40             :     BLOCKLAYOUT_PACKED,
      41             :     BLOCKLAYOUT_SHARED
      42             : };
      43             : 
      44             : // Base class for all variables defined in shaders, including Varyings, Uniforms, etc
      45             : // Note: we must override the copy constructor and assignment operator so we can
      46             : // work around excessive GCC binary bloating:
      47             : // See https://code.google.com/p/angleproject/issues/detail?id=697
      48             : struct ShaderVariable
      49             : {
      50             :     ShaderVariable();
      51             :     ShaderVariable(GLenum typeIn, unsigned int arraySizeIn);
      52             :     ~ShaderVariable();
      53             :     ShaderVariable(const ShaderVariable &other);
      54             :     ShaderVariable &operator=(const ShaderVariable &other);
      55             : 
      56           0 :     bool isArray() const { return arraySize > 0; }
      57           0 :     unsigned int elementCount() const { return std::max(1u, arraySize); }
      58           0 :     bool isStruct() const { return !fields.empty(); }
      59             : 
      60             :     // All of the shader's variables are described using nested data
      61             :     // structures. This is needed in order to disambiguate similar looking
      62             :     // types, such as two structs containing the same fields, but in
      63             :     // different orders. "findInfoByMappedName" provides an easy query for
      64             :     // users to dive into the data structure and fetch the unique variable
      65             :     // instance corresponding to a dereferencing chain of the top-level
      66             :     // variable.
      67             :     // Given a mapped name like 'a[0].b.c[0]', return the ShaderVariable
      68             :     // that defines 'c' in |leafVar|, and the original name 'A[0].B.C[0]'
      69             :     // in |originalName|, based on the assumption that |this| defines 'a'.
      70             :     // If no match is found, return false.
      71             :     bool findInfoByMappedName(const std::string &mappedFullName,
      72             :                               const ShaderVariable **leafVar,
      73             :                               std::string* originalFullName) const;
      74             : 
      75             :     bool isBuiltIn() const { return name.compare(0, 3, "gl_") == 0; }
      76             : 
      77             :     GLenum type;
      78             :     GLenum precision;
      79             :     std::string name;
      80             :     std::string mappedName;
      81             :     unsigned int arraySize;
      82             :     bool staticUse;
      83             :     std::vector<ShaderVariable> fields;
      84             :     std::string structName;
      85             : 
      86             :   protected:
      87             :     bool isSameVariableAtLinkTime(const ShaderVariable &other,
      88             :                                   bool matchPrecision) const;
      89             : 
      90             :     bool operator==(const ShaderVariable &other) const;
      91           0 :     bool operator!=(const ShaderVariable &other) const
      92             :     {
      93           0 :         return !operator==(other);
      94             :     }
      95             : };
      96             : 
      97             : struct Uniform : public ShaderVariable
      98             : {
      99             :     Uniform();
     100             :     ~Uniform();
     101             :     Uniform(const Uniform &other);
     102             :     Uniform &operator=(const Uniform &other);
     103             :     bool operator==(const Uniform &other) const;
     104             :     bool operator!=(const Uniform &other) const
     105             :     {
     106             :         return !operator==(other);
     107             :     }
     108             : 
     109             :     // Decide whether two uniforms are the same at shader link time,
     110             :     // assuming one from vertex shader and the other from fragment shader.
     111             :     // See GLSL ES Spec 3.00.3, sec 4.3.5.
     112             :     bool isSameUniformAtLinkTime(const Uniform &other) const;
     113             : };
     114             : 
     115             : // An interface variable is a variable which passes data between the GL data structures and the
     116             : // shader execution: either vertex shader inputs or fragment shader outputs. These variables can
     117             : // have integer locations to pass back to the GL API.
     118             : struct InterfaceVariable : public ShaderVariable
     119             : {
     120             :     InterfaceVariable();
     121             :     ~InterfaceVariable();
     122             :     InterfaceVariable(const InterfaceVariable &other);
     123             :     InterfaceVariable &operator=(const InterfaceVariable &other);
     124             :     bool operator==(const InterfaceVariable &other) const;
     125             :     bool operator!=(const InterfaceVariable &other) const { return !operator==(other); }
     126             : 
     127             :     int location;
     128             : };
     129             : 
     130             : struct Attribute : public InterfaceVariable
     131             : {
     132             :     Attribute();
     133             :     ~Attribute();
     134             :     Attribute(const Attribute &other);
     135             :     Attribute &operator=(const Attribute &other);
     136             :     bool operator==(const Attribute &other) const;
     137             :     bool operator!=(const Attribute &other) const { return !operator==(other); }
     138             : };
     139             : 
     140             : struct OutputVariable : public InterfaceVariable
     141             : {
     142             :     OutputVariable();
     143             :     ~OutputVariable();
     144             :     OutputVariable(const OutputVariable &other);
     145             :     OutputVariable &operator=(const OutputVariable &other);
     146             :     bool operator==(const OutputVariable &other) const;
     147             :     bool operator!=(const OutputVariable &other) const { return !operator==(other); }
     148             : };
     149             : 
     150             : struct InterfaceBlockField : public ShaderVariable
     151             : {
     152             :     InterfaceBlockField();
     153             :     ~InterfaceBlockField();
     154             :     InterfaceBlockField(const InterfaceBlockField &other);
     155             :     InterfaceBlockField &operator=(const InterfaceBlockField &other);
     156             :     bool operator==(const InterfaceBlockField &other) const;
     157             :     bool operator!=(const InterfaceBlockField &other) const
     158             :     {
     159             :         return !operator==(other);
     160             :     }
     161             : 
     162             :     // Decide whether two InterfaceBlock fields are the same at shader
     163             :     // link time, assuming one from vertex shader and the other from
     164             :     // fragment shader.
     165             :     // See GLSL ES Spec 3.00.3, sec 4.3.7.
     166             :     bool isSameInterfaceBlockFieldAtLinkTime(
     167             :         const InterfaceBlockField &other) const;
     168             : 
     169             :     bool isRowMajorLayout;
     170             : };
     171             : 
     172             : struct Varying : public ShaderVariable
     173             : {
     174             :     Varying();
     175             :     ~Varying();
     176             :     Varying(const Varying &otherg);
     177             :     Varying &operator=(const Varying &other);
     178             :     bool operator==(const Varying &other) const;
     179             :     bool operator!=(const Varying &other) const
     180             :     {
     181             :         return !operator==(other);
     182             :     }
     183             : 
     184             :     // Decide whether two varyings are the same at shader link time,
     185             :     // assuming one from vertex shader and the other from fragment shader.
     186             :     // Invariance needs to match only in ESSL1. Relevant spec sections:
     187             :     // GLSL ES 3.00.4, sections 4.6.1 and 4.3.9.
     188             :     // GLSL ES 1.00.17, section 4.6.4.
     189             :     bool isSameVaryingAtLinkTime(const Varying &other, int shaderVersion) const;
     190             : 
     191             :     // Deprecated version of isSameVaryingAtLinkTime, which assumes ESSL1.
     192             :     bool isSameVaryingAtLinkTime(const Varying &other) const;
     193             : 
     194             :     InterpolationType interpolation;
     195             :     bool isInvariant;
     196             : };
     197             : 
     198             : struct InterfaceBlock
     199             : {
     200             :     InterfaceBlock();
     201             :     ~InterfaceBlock();
     202             :     InterfaceBlock(const InterfaceBlock &other);
     203             :     InterfaceBlock &operator=(const InterfaceBlock &other);
     204             : 
     205             :     // Fields from blocks with non-empty instance names are prefixed with the block name.
     206             :     std::string fieldPrefix() const;
     207             : 
     208             :     // Decide whether two interface blocks are the same at shader link time.
     209             :     bool isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const;
     210             : 
     211             :     std::string name;
     212             :     std::string mappedName;
     213             :     std::string instanceName;
     214             :     unsigned int arraySize;
     215             :     BlockLayoutType layout;
     216             :     bool isRowMajorLayout;
     217             :     bool staticUse;
     218             :     std::vector<InterfaceBlockField> fields;
     219             : };
     220             : 
     221             : struct WorkGroupSize
     222             : {
     223             :     void fill(int fillValue);
     224             :     void setLocalSize(int localSizeX, int localSizeY, int localSizeZ);
     225             : 
     226             :     int &operator[](size_t index);
     227             :     int operator[](size_t index) const;
     228             :     size_t size() const;
     229             : 
     230             :     // Checks whether two work group size declarations match.
     231             :     // Two work group size declarations are the same if the explicitly specified elements are the
     232             :     // same or if one of them is specified as one and the other one is not specified
     233             :     bool isWorkGroupSizeMatching(const WorkGroupSize &right) const;
     234             : 
     235             :     // Checks whether any of the values are set.
     236             :     bool isAnyValueSet() const;
     237             : 
     238             :     // Checks whether all of the values are set.
     239             :     bool isDeclared() const;
     240             : 
     241             :     // Checks whether either all of the values are set, or none of them are.
     242             :     bool isLocalSizeValid() const;
     243             : 
     244             :     int localSizeQualifiers[3];
     245             : };
     246             : 
     247             : }  // namespace sh
     248             : 
     249             : #endif // GLSLANG_SHADERVARS_H_

Generated by: LCOV version 1.13