• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2012 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 // InputLayoutCache.h: Defines InputLayoutCache, a class that builds and caches
8 // D3D11 input layouts.
9 
10 #ifndef LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
11 #define LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
12 
13 #include <GLES2/gl2.h>
14 
15 #include <cstddef>
16 
17 #include <array>
18 #include <map>
19 
20 #include "common/angleutils.h"
21 #include "libANGLE/Constants.h"
22 #include "libANGLE/Error.h"
23 #include "libANGLE/SizedMRUCache.h"
24 #include "libANGLE/formatutils.h"
25 #include "libANGLE/renderer/d3d/RendererD3D.h"
26 #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
27 
28 namespace rx
29 {
30 struct PackedAttributeLayout
31 {
32     PackedAttributeLayout();
33     PackedAttributeLayout(const PackedAttributeLayout &other);
34 
35     void addAttributeData(GLenum glType,
36                           UINT semanticIndex,
37                           angle::FormatID vertexFormatID,
38                           unsigned int divisor);
39 
40     bool operator==(const PackedAttributeLayout &other) const;
41 
42     enum Flags
43     {
44         FLAG_USES_INSTANCED_SPRITES     = 0x1,
45         FLAG_INSTANCED_SPRITES_ACTIVE   = 0x2,
46         FLAG_INSTANCED_RENDERING_ACTIVE = 0x4,
47     };
48 
49     uint32_t numAttributes;
50     uint32_t flags;
51     gl::AttribArray<uint64_t> attributeData;
52 };
53 }  // namespace rx
54 
55 namespace std
56 {
57 template <>
58 struct hash<rx::PackedAttributeLayout>
59 {
60     size_t operator()(const rx::PackedAttributeLayout &value) const
61     {
62         return angle::ComputeGenericHash(value);
63     }
64 };
65 }  // namespace std
66 
67 namespace gl
68 {
69 class Program;
70 }  // namespace gl
71 
72 namespace rx
73 {
74 class Context11;
75 struct TranslatedAttribute;
76 struct TranslatedIndexData;
77 struct SourceIndexData;
78 class ProgramD3D;
79 class Renderer11;
80 
81 class InputLayoutCache : angle::NonCopyable
82 {
83   public:
84     InputLayoutCache();
85     ~InputLayoutCache();
86 
87     void clear();
88 
89     // Useful for testing
90     void setCacheSize(size_t newCacheSize);
91 
92     angle::Result getInputLayout(Context11 *context,
93                                  const gl::State &state,
94                                  const std::vector<const TranslatedAttribute *> &currentAttributes,
95                                  const AttribIndexArray &sortedSemanticIndices,
96                                  gl::PrimitiveMode mode,
97                                  GLsizei vertexCount,
98                                  GLsizei instances,
99                                  const d3d11::InputLayout **inputLayoutOut);
100 
101   private:
102     angle::Result createInputLayout(
103         Context11 *context11,
104         const AttribIndexArray &sortedSemanticIndices,
105         const std::vector<const TranslatedAttribute *> &currentAttributes,
106         gl::PrimitiveMode mode,
107         GLsizei vertexCount,
108         GLsizei instances,
109         d3d11::InputLayout *inputLayoutOut);
110 
111     // Starting cache size.
112     static constexpr size_t kDefaultCacheSize = 1024;
113 
114     // The cache tries to clean up this many states at once.
115     static constexpr size_t kGCLimit = 128;
116 
117     using LayoutCache = angle::base::HashingMRUCache<PackedAttributeLayout, d3d11::InputLayout>;
118     LayoutCache mLayoutCache;
119 };
120 
121 }  // namespace rx
122 
123 #endif  // LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
124