blob: 9a5607f2445de5084f21b1c0618260875cb309c5 [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:
25
26 static void initialize();
27 static void destroy();
28
29 static const TType *getType(TBasicType basicType,
30 TPrecision precision)
31 {
32 return getType(basicType, precision, EvqTemporary,
33 1, 1);
34 }
35 static const TType *getType(TBasicType basicType,
36 unsigned char primarySize = 1,
37 unsigned char secondarySize = 1)
38 {
39 return getType(basicType, EbpUndefined, EvqGlobal,
40 primarySize, secondarySize);
41 }
42 static const TType *getType(TBasicType basicType,
43 TQualifier qualifier,
44 unsigned char primarySize = 1,
45 unsigned char secondarySize = 1)
46 {
47 return getType(basicType, EbpUndefined, qualifier,
48 primarySize, secondarySize);
49 }
50 static const TType *getType(TBasicType basicType,
51 TPrecision precision,
52 TQualifier qualifier,
53 unsigned char primarySize,
54 unsigned char secondarySize);
55
56 private:
57 TCache()
58 {
59 }
60
61 union TypeKey
62 {
63 TypeKey(TBasicType basicType,
64 TPrecision precision,
65 TQualifier qualifier,
66 unsigned char primarySize,
67 unsigned char secondarySize);
68
69 typedef uint8_t EnumComponentType;
70 struct
71 {
72 EnumComponentType basicType;
73 EnumComponentType precision;
74 EnumComponentType qualifier;
75 unsigned char primarySize;
76 unsigned char secondarySize;
77 } components;
78 uint64_t value;
79
80 bool operator < (const TypeKey &other) const
81 {
82 return value < other.value;
83 }
84 };
85 typedef std::map<TypeKey, const TType*> TypeMap;
86
87 TypeMap mTypes;
88 TPoolAllocator mAllocator;
89
90 static TCache *sCache;
91};
92
Jamie Madill45bcc782016-11-07 13:58:48 -050093} // namespace sh
94
Dmitry Skiba01971112015-07-10 14:54:00 -040095#endif // COMPILER_TRANSLATOR_CACHE_H_