michael@0: // michael@0: // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render michael@0: // state objects. michael@0: michael@0: #ifndef LIBGLESV2_RENDERER_RENDERSTATECACHE_H_ michael@0: #define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_ michael@0: michael@0: #include "libGLESv2/angletypes.h" michael@0: #include "common/angleutils.h" michael@0: michael@0: namespace rx michael@0: { michael@0: michael@0: class RenderStateCache michael@0: { michael@0: public: michael@0: RenderStateCache(); michael@0: virtual ~RenderStateCache(); michael@0: michael@0: void initialize(ID3D11Device *device); michael@0: void clear(); michael@0: michael@0: // Increments refcount on the returned blend state, Release() must be called. michael@0: ID3D11BlendState *getBlendState(const gl::BlendState &blendState); michael@0: ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState, michael@0: bool scissorEnabled, unsigned int depthSize); michael@0: ID3D11DepthStencilState *getDepthStencilState(const gl::DepthStencilState &dsState); michael@0: ID3D11SamplerState *getSamplerState(const gl::SamplerState &samplerState); michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(RenderStateCache); michael@0: michael@0: unsigned long long mCounter; michael@0: michael@0: // Blend state cache michael@0: static std::size_t hashBlendState(const gl::BlendState &blendState); michael@0: static bool compareBlendStates(const gl::BlendState &a, const gl::BlendState &b); michael@0: static const unsigned int kMaxBlendStates; michael@0: michael@0: typedef std::size_t (*BlendStateHashFunction)(const gl::BlendState &); michael@0: typedef bool (*BlendStateEqualityFunction)(const gl::BlendState &, const gl::BlendState &); michael@0: typedef std::pair BlendStateCounterPair; michael@0: typedef std::unordered_map BlendStateMap; michael@0: BlendStateMap mBlendStateCache; michael@0: michael@0: // Rasterizer state cache michael@0: struct RasterizerStateKey michael@0: { michael@0: gl::RasterizerState rasterizerState; michael@0: bool scissorEnabled; michael@0: unsigned int depthSize; michael@0: }; michael@0: static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState); michael@0: static bool compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b); michael@0: static const unsigned int kMaxRasterizerStates; michael@0: michael@0: typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &); michael@0: typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &); michael@0: typedef std::pair RasterizerStateCounterPair; michael@0: typedef std::unordered_map RasterizerStateMap; michael@0: RasterizerStateMap mRasterizerStateCache; michael@0: michael@0: // Depth stencil state cache michael@0: static std::size_t hashDepthStencilState(const gl::DepthStencilState &dsState); michael@0: static bool compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b); michael@0: static const unsigned int kMaxDepthStencilStates; michael@0: michael@0: typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &); michael@0: typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &); michael@0: typedef std::pair DepthStencilStateCounterPair; michael@0: typedef std::unordered_map DepthStencilStateMap; michael@0: DepthStencilStateMap mDepthStencilStateCache; michael@0: michael@0: // Sample state cache michael@0: static std::size_t hashSamplerState(const gl::SamplerState &samplerState); michael@0: static bool compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b); michael@0: static const unsigned int kMaxSamplerStates; michael@0: michael@0: typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &); michael@0: typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &); michael@0: typedef std::pair SamplerStateCounterPair; michael@0: typedef std::unordered_map SamplerStateMap; michael@0: SamplerStateMap mSamplerStateCache; michael@0: michael@0: ID3D11Device *mDevice; michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif // LIBGLESV2_RENDERER_RENDERSTATECACHE_H_