Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / d3d11 / RenderStateCache.h
1 //
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.
5 //
6
7 // RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render
8 // state objects.
9
10 #ifndef LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
11 #define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
12
13 #include "libGLESv2/angletypes.h"
14 #include "common/angleutils.h"
15
16 namespace gl
17 {
18 class Framebuffer;
19 }
20
21 namespace rx
22 {
23
24 class RenderStateCache
25 {
26   public:
27     RenderStateCache();
28     virtual ~RenderStateCache();
29
30     void initialize(ID3D11Device *device);
31     void clear();
32
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);
39
40   private:
41     DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
42
43     unsigned long long mCounter;
44
45     // Blend state cache
46     struct BlendStateKey
47     {
48         gl::BlendState blendState;
49         bool rtChannels[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT][4];
50     };
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;
54
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;
60
61     // Rasterizer state cache
62     struct RasterizerStateKey
63     {
64         gl::RasterizerState rasterizerState;
65         bool scissorEnabled;
66         unsigned int depthSize;
67     };
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;
71
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;
77
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;
82
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;
91
92     // Sample state cache
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;
96
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;
105
106     ID3D11Device *mDevice;
107 };
108
109 }
110
111 #endif // LIBGLESV2_RENDERER_RENDERSTATECACHE_H_