2 // Copyright (c) 2012-2014 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 // RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render
10 #ifndef LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
11 #define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
13 #include "libGLESv2/angletypes.h"
14 #include "libGLESv2/Error.h"
15 #include "common/angleutils.h"
17 #include <unordered_map>
28 class RenderStateCache
32 virtual ~RenderStateCache();
34 void initialize(ID3D11Device *device);
37 gl::Error getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, ID3D11BlendState **outBlendState);
38 gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState);
39 gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, ID3D11DepthStencilState **outDSState);
40 gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState);
43 DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
45 unsigned long long mCounter;
50 gl::BlendState blendState;
51 bool rtChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
53 static std::size_t hashBlendState(const BlendStateKey &blendState);
54 static bool compareBlendStates(const BlendStateKey &a, const BlendStateKey &b);
55 static const unsigned int kMaxBlendStates;
57 typedef std::size_t (*BlendStateHashFunction)(const BlendStateKey &);
58 typedef bool (*BlendStateEqualityFunction)(const BlendStateKey &, const BlendStateKey &);
59 typedef std::pair<ID3D11BlendState*, unsigned long long> BlendStateCounterPair;
60 typedef std::unordered_map<BlendStateKey, BlendStateCounterPair, BlendStateHashFunction, BlendStateEqualityFunction> BlendStateMap;
61 BlendStateMap mBlendStateCache;
63 // Rasterizer state cache
64 struct RasterizerStateKey
66 gl::RasterizerState rasterizerState;
69 static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState);
70 static bool compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
71 static const unsigned int kMaxRasterizerStates;
73 typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
74 typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
75 typedef std::pair<ID3D11RasterizerState*, unsigned long long> RasterizerStateCounterPair;
76 typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
77 RasterizerStateMap mRasterizerStateCache;
79 // Depth stencil state cache
80 static std::size_t hashDepthStencilState(const gl::DepthStencilState &dsState);
81 static bool compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
82 static const unsigned int kMaxDepthStencilStates;
84 typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
85 typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
86 typedef std::pair<ID3D11DepthStencilState*, unsigned long long> DepthStencilStateCounterPair;
87 typedef std::unordered_map<gl::DepthStencilState,
88 DepthStencilStateCounterPair,
89 DepthStencilStateHashFunction,
90 DepthStencilStateEqualityFunction> DepthStencilStateMap;
91 DepthStencilStateMap mDepthStencilStateCache;
94 static std::size_t hashSamplerState(const gl::SamplerState &samplerState);
95 static bool compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
96 static const unsigned int kMaxSamplerStates;
98 typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
99 typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
100 typedef std::pair<ID3D11SamplerState*, unsigned long long> SamplerStateCounterPair;
101 typedef std::unordered_map<gl::SamplerState,
102 SamplerStateCounterPair,
103 SamplerStateHashFunction,
104 SamplerStateEqualityFunction> SamplerStateMap;
105 SamplerStateMap mSamplerStateCache;
107 ID3D11Device *mDevice;
112 #endif // LIBGLESV2_RENDERER_RENDERSTATECACHE_H_