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 InputLayoutKey 42 { 43 unsigned int elementCount; 44 D3D11_INPUT_ELEMENT_DESC elements[gl::MAX_VERTEX_ATTRIBS]; 45 GLenum glslElementType[gl::MAX_VERTEX_ATTRIBS]; 46 }; 47 48 struct InputLayoutCounterPair 49 { 50 ID3D11InputLayout *inputLayout; 51 unsigned long long lastUsedTime; 52 }; 53 54 ID3D11InputLayout *mCurrentIL; 55 unsigned int mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS]; 56 UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS]; 57 UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS]; 58 59 static std::size_t hashInputLayout(const InputLayoutKey &inputLayout); 60 static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b); 61 62 typedef std::size_t (*InputLayoutHashFunction)(const InputLayoutKey &); 63 typedef bool (*InputLayoutEqualityFunction)(const InputLayoutKey &, const InputLayoutKey &); 64 typedef std::unordered_map<InputLayoutKey, 65 InputLayoutCounterPair, 66 InputLayoutHashFunction, 67 InputLayoutEqualityFunction> InputLayoutMap; 68 InputLayoutMap mInputLayoutMap; 69 70 static const unsigned int kMaxInputLayouts; 71 72 unsigned long long mCounter; 73 74 ID3D11Device *mDevice; 75 ID3D11DeviceContext *mDeviceContext; 76 }; 77 78 } 79 80 #endif // LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_ 81