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