blob: 209241a1314c1f955e76fecd684d2fa72a3320da [file] [log] [blame]
daniel@transgaming.comcd9458d2012-12-20 21:10:09 +00001//
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/Context.h"
14
15#include "libGLESv2/renderer/VertexDataManager.h"
16
17#include <D3D11.h>
18#include <unordered_map>
19
20namespace rx
21{
22
23class InputLayoutCache
24{
25 public:
26 InputLayoutCache();
27 virtual ~InputLayoutCache();
28
29 void initialize(ID3D11Device *device, ID3D11DeviceContext *context);
30 void clear();
31
32 GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
33 gl::ProgramBinary *programBinary);
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(InputLayoutCache);
37
38 struct InputLayoutKey
39 {
40 unsigned int elementCount;
41 D3D11_INPUT_ELEMENT_DESC elements[gl::MAX_VERTEX_ATTRIBS];
42 };
43
44 struct InputLayoutCounterPair
45 {
46 ID3D11InputLayout *inputLayout;
47 unsigned long long lastUsedTime;
48 };
49
50 static std::size_t hashInputLayout(const InputLayoutKey &inputLayout);
51 static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b);
52
53 typedef std::size_t (*InputLayoutHashFunction)(const InputLayoutKey &);
54 typedef bool (*InputLayoutEqualityFunction)(const InputLayoutKey &, const InputLayoutKey &);
55 typedef std::unordered_map<InputLayoutKey,
56 InputLayoutCounterPair,
57 InputLayoutHashFunction,
58 InputLayoutEqualityFunction> InputLayoutMap;
59 InputLayoutMap mInputLayoutMap;
60
61 static const unsigned int kMaxInputLayouts;
62
63 unsigned long long mCounter;
64
65 ID3D11Device *mDevice;
66 ID3D11DeviceContext *mDeviceContext;
67};
68
69}
70
71#endif // LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_