michael@0: // michael@0: // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // InputLayoutCache.h: Defines InputLayoutCache, a class that builds and caches michael@0: // D3D11 input layouts. michael@0: michael@0: #ifndef LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_ michael@0: #define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_ michael@0: michael@0: #include "libGLESv2/Constants.h" michael@0: #include "common/angleutils.h" michael@0: michael@0: namespace gl michael@0: { michael@0: class ProgramBinary; michael@0: } michael@0: michael@0: namespace rx michael@0: { michael@0: struct TranslatedAttribute; michael@0: michael@0: class InputLayoutCache michael@0: { michael@0: public: michael@0: InputLayoutCache(); michael@0: virtual ~InputLayoutCache(); michael@0: michael@0: void initialize(ID3D11Device *device, ID3D11DeviceContext *context); michael@0: void clear(); michael@0: void markDirty(); michael@0: michael@0: GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], michael@0: gl::ProgramBinary *programBinary); michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(InputLayoutCache); michael@0: michael@0: struct InputLayoutKey michael@0: { michael@0: unsigned int elementCount; michael@0: D3D11_INPUT_ELEMENT_DESC elements[gl::MAX_VERTEX_ATTRIBS]; michael@0: GLenum glslElementType[gl::MAX_VERTEX_ATTRIBS]; michael@0: }; michael@0: michael@0: struct InputLayoutCounterPair michael@0: { michael@0: ID3D11InputLayout *inputLayout; michael@0: unsigned long long lastUsedTime; michael@0: }; michael@0: michael@0: ID3D11InputLayout *mCurrentIL; michael@0: unsigned int mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS]; michael@0: UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS]; michael@0: UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS]; michael@0: michael@0: static std::size_t hashInputLayout(const InputLayoutKey &inputLayout); michael@0: static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b); michael@0: michael@0: typedef std::size_t (*InputLayoutHashFunction)(const InputLayoutKey &); michael@0: typedef bool (*InputLayoutEqualityFunction)(const InputLayoutKey &, const InputLayoutKey &); michael@0: typedef std::unordered_map InputLayoutMap; michael@0: InputLayoutMap mInputLayoutMap; michael@0: michael@0: static const unsigned int kMaxInputLayouts; michael@0: michael@0: unsigned long long mCounter; michael@0: michael@0: ID3D11Device *mDevice; michael@0: ID3D11DeviceContext *mDeviceContext; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif // LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_