blob: a45ada4878d6f1169a603b3657413043f20b4c59 [file] [log] [blame]
Dmitry Skiba01971112015-07-10 14:54:00 -04001//
2// Copyright (c) 2015 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
7// Cache.h: Implements a cache for various commonly created objects.
8
9#ifndef COMPILER_TRANSLATOR_CACHE_H_
10#define COMPILER_TRANSLATOR_CACHE_H_
11
12#include <stdint.h>
13#include <string.h>
14#include <map>
15
16#include "compiler/translator/Types.h"
17#include "compiler/translator/PoolAlloc.h"
18
Jamie Madill45bcc782016-11-07 13:58:48 -050019namespace sh
20{
21
Dmitry Skiba01971112015-07-10 14:54:00 -040022class TCache
23{
24 public:
Dmitry Skiba01971112015-07-10 14:54:00 -040025 static void initialize();
26 static void destroy();
27
Jamie Madilld7b1ab52016-12-12 14:42:19 -050028 static const TType *getType(TBasicType basicType, TPrecision precision)
Dmitry Skiba01971112015-07-10 14:54:00 -040029 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050030 return getType(basicType, precision, EvqTemporary, 1, 1);
Dmitry Skiba01971112015-07-10 14:54:00 -040031 }
32 static const TType *getType(TBasicType basicType,
Jamie Madilld7b1ab52016-12-12 14:42:19 -050033 unsigned char primarySize = 1,
Dmitry Skiba01971112015-07-10 14:54:00 -040034 unsigned char secondarySize = 1)
35 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050036 return getType(basicType, EbpUndefined, EvqGlobal, primarySize, secondarySize);
Dmitry Skiba01971112015-07-10 14:54:00 -040037 }
38 static const TType *getType(TBasicType basicType,
39 TQualifier qualifier,
Jamie Madilld7b1ab52016-12-12 14:42:19 -050040 unsigned char primarySize = 1,
Dmitry Skiba01971112015-07-10 14:54:00 -040041 unsigned char secondarySize = 1)
42 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050043 return getType(basicType, EbpUndefined, qualifier, primarySize, secondarySize);
Dmitry Skiba01971112015-07-10 14:54:00 -040044 }
45 static const TType *getType(TBasicType basicType,
46 TPrecision precision,
47 TQualifier qualifier,
48 unsigned char primarySize,
49 unsigned char secondarySize);
50
51 private:
Jamie Madilld7b1ab52016-12-12 14:42:19 -050052 TCache() {}
Dmitry Skiba01971112015-07-10 14:54:00 -040053
Jamie Madilld7b1ab52016-12-12 14:42:19 -050054 union TypeKey {
Dmitry Skiba01971112015-07-10 14:54:00 -040055 TypeKey(TBasicType basicType,
56 TPrecision precision,
57 TQualifier qualifier,
58 unsigned char primarySize,
59 unsigned char secondarySize);
60
61 typedef uint8_t EnumComponentType;
62 struct
63 {
64 EnumComponentType basicType;
65 EnumComponentType precision;
66 EnumComponentType qualifier;
67 unsigned char primarySize;
68 unsigned char secondarySize;
69 } components;
70 uint64_t value;
71
Jamie Madilld7b1ab52016-12-12 14:42:19 -050072 bool operator<(const TypeKey &other) const { return value < other.value; }
Dmitry Skiba01971112015-07-10 14:54:00 -040073 };
Jamie Madilld7b1ab52016-12-12 14:42:19 -050074 typedef std::map<TypeKey, const TType *> TypeMap;
Dmitry Skiba01971112015-07-10 14:54:00 -040075
76 TypeMap mTypes;
77 TPoolAllocator mAllocator;
78
79 static TCache *sCache;
80};
81
Jamie Madill45bcc782016-11-07 13:58:48 -050082} // namespace sh
83
Dmitry Skiba01971112015-07-10 14:54:00 -040084#endif // COMPILER_TRANSLATOR_CACHE_H_