2 // Copyright (c) 2012-2013 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 "common/angleutils.h"
24 class RenderStateCache
28 virtual ~RenderStateCache();
30 void initialize(ID3D11Device *device);
33 // Increments refcount on the returned blend state, Release() must be called.
34 ID3D11BlendState *getBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState);
35 ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState,
36 bool scissorEnabled, unsigned int depthSize);
37 ID3D11DepthStencilState *getDepthStencilState(const gl::DepthStencilState &dsState);
38 ID3D11SamplerState *getSamplerState(const gl::SamplerState &samplerState);
41 DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
43 unsigned long long mCounter;
48 gl::BlendState blendState;
49 bool rtChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
51 static std::size_t hashBlendState(const BlendStateKey &blendState);
52 static bool compareBlendStates(const BlendStateKey &a, const BlendStateKey &b);
53 static const unsigned int kMaxBlendStates;
55 typedef std::size_t (*BlendStateHashFunction)(const BlendStateKey &);
56 typedef bool (*BlendStateEqualityFunction)(const BlendStateKey &, const BlendStateKey &);
57 typedef std::pair<ID3D11BlendState*, unsigned long long> BlendStateCounterPair;
58 typedef std::unordered_map<BlendStateKey, BlendStateCounterPair, BlendStateHashFunction, BlendStateEqualityFunction> BlendStateMap;
59 BlendStateMap mBlendStateCache;
61 // Rasterizer state cache
62 struct RasterizerStateKey
64 gl::RasterizerState rasterizerState;
66 unsigned int depthSize;
68 static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState);
69 static bool compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
70 static const unsigned int kMaxRasterizerStates;
72 typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
73 typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
74 typedef std::pair<ID3D11RasterizerState*, unsigned long long> RasterizerStateCounterPair;
75 typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
76 RasterizerStateMap mRasterizerStateCache;
78 // Depth stencil state cache
79 static std::size_t hashDepthStencilState(const gl::DepthStencilState &dsState);
80 static bool compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
81 static const unsigned int kMaxDepthStencilStates;
83 typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
84 typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
85 typedef std::pair<ID3D11DepthStencilState*, unsigned long long> DepthStencilStateCounterPair;
86 typedef std::unordered_map<gl::DepthStencilState,
87 DepthStencilStateCounterPair,
88 DepthStencilStateHashFunction,
89 DepthStencilStateEqualityFunction> DepthStencilStateMap;
90 DepthStencilStateMap mDepthStencilStateCache;
93 static std::size_t hashSamplerState(const gl::SamplerState &samplerState);
94 static bool compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
95 static const unsigned int kMaxSamplerStates;
97 typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
98 typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
99 typedef std::pair<ID3D11SamplerState*, unsigned long long> SamplerStateCounterPair;
100 typedef std::unordered_map<gl::SamplerState,
101 SamplerStateCounterPair,
102 SamplerStateHashFunction,
103 SamplerStateEqualityFunction> SamplerStateMap;
104 SamplerStateMap mSamplerStateCache;
106 ID3D11Device *mDevice;
111 #endif // LIBGLESV2_RENDERER_RENDERSTATECACHE_H_