chromium/third_party/angle/src/compiler/translator/StaticType.h

//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Compile-time instances of many common TType values. These are looked up
// (statically or dynamically) through the methods defined in the namespace.
//

#ifndef COMPILER_TRANSLATOR_STATIC_TYPE_H_
#define COMPILER_TRANSLATOR_STATIC_TYPE_H_

#include "compiler/translator/Types.h"

namespace sh
{

namespace StaticType
{

namespace Helpers
{

//
// Generation and static allocation of type mangled name values.
//

// Size of the constexpr-generated mangled name.
// If this value is too small, the compiler will produce errors.
static constexpr size_t kStaticMangledNameLength =;

// Type which holds the mangled names for constexpr-generated TTypes.
// This simple struct is needed so that a char array can be returned by value.
struct StaticMangledName
{};

// Generates a mangled name for a TType given its parameters.
constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType,
                                                   TPrecision precision,
                                                   TQualifier qualifier,
                                                   uint8_t primarySize,
                                                   uint8_t secondarySize)
{}

// Similar mangled name builder but for array types.  Currently, only single-dimension arrays of
// single-digit size are necessary and supported.
static constexpr size_t kStaticArrayMangledNameLength =;
struct StaticArrayMangledName
{};
constexpr StaticArrayMangledName BuildStaticArrayMangledName(TBasicType basicType,
                                                             TPrecision precision,
                                                             TQualifier qualifier,
                                                             uint8_t primarySize,
                                                             uint8_t secondarySize,
                                                             const unsigned int *arraySizes,
                                                             size_t numArraySizes)
{}

// This "variable" contains the mangled names for every constexpr-generated TType.
// If kMangledNameInstance<B, P, Q, PS, SS> is used anywhere (specifally
// in instance, below), this is where the appropriate type will be stored.
kMangledNameInstance;

// Same as kMangledNameInstance, but for array types.
kMangledNameArrayInstance;

//
// Generation and static allocation of TType values.
//

// This "variable" contains every constexpr-generated TType.
// If instance<B, P, Q, PS, SS> is used anywhere (specifally
// in Get, below), this is where the appropriate type will be stored.
//
// TODO(crbug.com/981610): This is constexpr but doesn't follow the kConstant naming convention
// because TType has a mutable member that prevents it from being in .data.rel.ro and makes the
// Android Binary Size builder complain when ANGLE is rolled in Chromium.
instance;

// Same as instance, but for array types.
arrayInstance;

}  // namespace Helpers

//
// Fully-qualified type lookup.
//

template <TBasicType basicType,
          TPrecision precision,
          TQualifier qualifier,
          uint8_t primarySize,
          uint8_t secondarySize>
constexpr const TType *Get()
{}

template <TBasicType basicType,
          TPrecision precision,
          TQualifier qualifier,
          uint8_t primarySize,
          uint8_t secondarySize,
          const unsigned int *arraySizes,
          size_t numArraySizes>
constexpr const TType *GetArray()
{}

//
// Overloads
//

template <TBasicType basicType,
          TPrecision precision,
          uint8_t primarySize   = 1,
          uint8_t secondarySize = 1>
constexpr const TType *GetBasic()
{}

template <TBasicType basicType,
          TPrecision precision,
          uint8_t primarySize   = 1,
          uint8_t secondarySize = 1>
constexpr const TType *GetTemporary()
{}

template <TBasicType basicType,
          TPrecision precision,
          TQualifier qualifier,
          uint8_t primarySize   = 1,
          uint8_t secondarySize = 1>
constexpr const TType *GetQualified()
{}

// Dynamic lookup methods (convert runtime values to template args)

namespace Helpers
{

// Helper which takes secondarySize statically but primarySize dynamically.
template <TBasicType basicType, TPrecision precision, TQualifier qualifier, uint8_t secondarySize>
constexpr const TType *GetForVecMatHelper(uint8_t primarySize)
{}

}  // namespace Helpers

template <TBasicType basicType, TPrecision precision, TQualifier qualifier = EvqGlobal>
constexpr const TType *GetForVecMat(uint8_t primarySize, uint8_t secondarySize = 1)
{}

template <TBasicType basicType, TPrecision precision>
constexpr const TType *GetForVec(TQualifier qualifier, uint8_t size)
{}

}  // namespace StaticType

}  // namespace sh

#endif  // COMPILER_TRANSLATOR_STATIC_TYPE_H_