1 // 2 // Copyright 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 LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ 11 #define LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ 12 13 #include <GLES2/gl2.h> 14 15 #include <cstddef> 16 17 #include <array> 18 #include <map> 19 20 #include "common/angleutils.h" 21 #include "libANGLE/Constants.h" 22 #include "libANGLE/Error.h" 23 #include "libANGLE/SizedMRUCache.h" 24 #include "libANGLE/formatutils.h" 25 #include "libANGLE/renderer/d3d/RendererD3D.h" 26 #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h" 27 28 namespace rx 29 { 30 struct PackedAttributeLayout 31 { 32 PackedAttributeLayout(); 33 PackedAttributeLayout(const PackedAttributeLayout &other); 34 35 void addAttributeData(GLenum glType, 36 UINT semanticIndex, 37 angle::FormatID vertexFormatID, 38 unsigned int divisor); 39 40 bool operator==(const PackedAttributeLayout &other) const; 41 42 uint32_t numAttributes; 43 gl::AttribArray<uint64_t> attributeData; 44 }; 45 } // namespace rx 46 47 namespace std 48 { 49 template <> 50 struct hash<rx::PackedAttributeLayout> 51 { 52 size_t operator()(const rx::PackedAttributeLayout &value) const 53 { 54 return angle::ComputeGenericHash(value); 55 } 56 }; 57 } // namespace std 58 59 namespace gl 60 { 61 class Program; 62 } // namespace gl 63 64 namespace rx 65 { 66 class Context11; 67 struct TranslatedAttribute; 68 struct TranslatedIndexData; 69 struct SourceIndexData; 70 class ProgramD3D; 71 class Renderer11; 72 73 class InputLayoutCache : angle::NonCopyable 74 { 75 public: 76 InputLayoutCache(); 77 ~InputLayoutCache(); 78 79 void clear(); 80 81 // Useful for testing 82 void setCacheSize(size_t newCacheSize); 83 84 angle::Result getInputLayout(Context11 *context, 85 const gl::State &state, 86 const std::vector<const TranslatedAttribute *> ¤tAttributes, 87 const AttribIndexArray &sortedSemanticIndices, 88 gl::PrimitiveMode mode, 89 GLsizei vertexCount, 90 GLsizei instances, 91 const d3d11::InputLayout **inputLayoutOut); 92 93 private: 94 angle::Result createInputLayout( 95 Context11 *context11, 96 const AttribIndexArray &sortedSemanticIndices, 97 const std::vector<const TranslatedAttribute *> ¤tAttributes, 98 gl::PrimitiveMode mode, 99 GLsizei vertexCount, 100 GLsizei instances, 101 d3d11::InputLayout *inputLayoutOut); 102 103 // Starting cache size. 104 static constexpr size_t kDefaultCacheSize = 1024; 105 106 // The cache tries to clean up this many states at once. 107 static constexpr size_t kGCLimit = 128; 108 109 using LayoutCache = angle::base::HashingMRUCache<PackedAttributeLayout, d3d11::InputLayout>; 110 LayoutCache mLayoutCache; 111 }; 112 113 } // namespace rx 114 115 #endif // LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ 116