• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 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 LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
11 #define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
12 
13 #include "libGLESv2/Constants.h"
14 #include "common/angleutils.h"
15 
16 namespace gl
17 {
18 class ProgramBinary;
19 }
20 
21 namespace rx
22 {
23 struct TranslatedAttribute;
24 
25 class InputLayoutCache
26 {
27   public:
28     InputLayoutCache();
29     virtual ~InputLayoutCache();
30 
31     void initialize(ID3D11Device *device, ID3D11DeviceContext *context);
32     void clear();
33     void markDirty();
34 
35     GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
36                               gl::ProgramBinary *programBinary);
37 
38   private:
39     DISALLOW_COPY_AND_ASSIGN(InputLayoutCache);
40 
41     struct InputLayoutElement
42     {
43         D3D11_INPUT_ELEMENT_DESC desc;
44         GLenum glslElementType;
45     };
46 
47     struct InputLayoutKey
48     {
49         unsigned int elementCount;
50         InputLayoutElement elements[gl::MAX_VERTEX_ATTRIBS];
51 
beginInputLayoutKey52         const char *begin() const
53         {
54             return reinterpret_cast<const char*>(&elementCount);
55         }
56 
endInputLayoutKey57         const char *end() const
58         {
59             return reinterpret_cast<const char*>(&elements[elementCount]);
60         }
61     };
62 
63     struct InputLayoutCounterPair
64     {
65         ID3D11InputLayout *inputLayout;
66         unsigned long long lastUsedTime;
67     };
68 
69     ID3D11InputLayout *mCurrentIL;
70     unsigned int mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
71     UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS];
72     UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS];
73 
74     static std::size_t hashInputLayout(const InputLayoutKey &inputLayout);
75     static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b);
76 
77     typedef std::size_t (*InputLayoutHashFunction)(const InputLayoutKey &);
78     typedef bool (*InputLayoutEqualityFunction)(const InputLayoutKey &, const InputLayoutKey &);
79     typedef std::unordered_map<InputLayoutKey,
80                                InputLayoutCounterPair,
81                                InputLayoutHashFunction,
82                                InputLayoutEqualityFunction> InputLayoutMap;
83     InputLayoutMap mInputLayoutMap;
84 
85     static const unsigned int kMaxInputLayouts;
86 
87     unsigned long long mCounter;
88 
89     ID3D11Device *mDevice;
90     ID3D11DeviceContext *mDeviceContext;
91 };
92 
93 }
94 
95 #endif // LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
96