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.
7 // InputLayoutCache.h: Defines InputLayoutCache, a class that builds and caches
8 // D3D11 input layouts.
10 #ifndef LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
11 #define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
13 #include "libGLESv2/Constants.h"
14 #include "common/angleutils.h"
23 struct TranslatedAttribute;
25 class InputLayoutCache
29 virtual ~InputLayoutCache();
31 void initialize(ID3D11Device *device, ID3D11DeviceContext *context);
35 GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
36 gl::ProgramBinary *programBinary);
39 DISALLOW_COPY_AND_ASSIGN(InputLayoutCache);
41 struct InputLayoutElement
43 D3D11_INPUT_ELEMENT_DESC desc;
44 GLenum glslElementType;
49 unsigned int elementCount;
50 InputLayoutElement elements[gl::MAX_VERTEX_ATTRIBS];
52 const char *begin() const
54 return reinterpret_cast<const char*>(&elementCount);
57 const char *end() const
59 return reinterpret_cast<const char*>(&elements[elementCount]);
63 struct InputLayoutCounterPair
65 ID3D11InputLayout *inputLayout;
66 unsigned long long lastUsedTime;
69 ID3D11InputLayout *mCurrentIL;
70 ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
71 UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS];
72 UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS];
74 static std::size_t hashInputLayout(const InputLayoutKey &inputLayout);
75 static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b);
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;
85 static const unsigned int kMaxInputLayouts;
87 unsigned long long mCounter;
89 ID3D11Device *mDevice;
90 ID3D11DeviceContext *mDeviceContext;
95 #endif // LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_