gfx/angle/src/libGLESv2/renderer/RenderStateCache.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/renderer/RenderStateCache.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +//
     1.5 +// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +// RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render
    1.11 +// state objects.
    1.12 +
    1.13 +#ifndef LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
    1.14 +#define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
    1.15 +
    1.16 +#include "libGLESv2/angletypes.h"
    1.17 +#include "common/angleutils.h"
    1.18 +
    1.19 +namespace rx
    1.20 +{
    1.21 +
    1.22 +class RenderStateCache
    1.23 +{
    1.24 +  public:
    1.25 +    RenderStateCache();
    1.26 +    virtual ~RenderStateCache();
    1.27 +
    1.28 +    void initialize(ID3D11Device *device);
    1.29 +    void clear();
    1.30 +
    1.31 +    // Increments refcount on the returned blend state, Release() must be called.
    1.32 +    ID3D11BlendState *getBlendState(const gl::BlendState &blendState);
    1.33 +    ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState,
    1.34 +                                              bool scissorEnabled, unsigned int depthSize);
    1.35 +    ID3D11DepthStencilState *getDepthStencilState(const gl::DepthStencilState &dsState);
    1.36 +    ID3D11SamplerState *getSamplerState(const gl::SamplerState &samplerState);
    1.37 +
    1.38 +  private:
    1.39 +    DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
    1.40 +
    1.41 +    unsigned long long mCounter;
    1.42 +
    1.43 +    // Blend state cache
    1.44 +    static std::size_t hashBlendState(const gl::BlendState &blendState);
    1.45 +    static bool compareBlendStates(const gl::BlendState &a, const gl::BlendState &b);
    1.46 +    static const unsigned int kMaxBlendStates;
    1.47 +
    1.48 +    typedef std::size_t (*BlendStateHashFunction)(const gl::BlendState &);
    1.49 +    typedef bool (*BlendStateEqualityFunction)(const gl::BlendState &, const gl::BlendState &);
    1.50 +    typedef std::pair<ID3D11BlendState*, unsigned long long> BlendStateCounterPair;
    1.51 +    typedef std::unordered_map<gl::BlendState, BlendStateCounterPair, BlendStateHashFunction, BlendStateEqualityFunction> BlendStateMap;
    1.52 +    BlendStateMap mBlendStateCache;
    1.53 +
    1.54 +    // Rasterizer state cache
    1.55 +    struct RasterizerStateKey
    1.56 +    {
    1.57 +        gl::RasterizerState rasterizerState;
    1.58 +        bool scissorEnabled;
    1.59 +        unsigned int depthSize;
    1.60 +    };
    1.61 +    static std::size_t hashRasterizerState(const RasterizerStateKey &rasterState);
    1.62 +    static bool compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
    1.63 +    static const unsigned int kMaxRasterizerStates;
    1.64 +
    1.65 +    typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
    1.66 +    typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
    1.67 +    typedef std::pair<ID3D11RasterizerState*, unsigned long long> RasterizerStateCounterPair;
    1.68 +    typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
    1.69 +    RasterizerStateMap mRasterizerStateCache;
    1.70 +
    1.71 +    // Depth stencil state cache
    1.72 +    static std::size_t hashDepthStencilState(const gl::DepthStencilState &dsState);
    1.73 +    static bool compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
    1.74 +    static const unsigned int kMaxDepthStencilStates;
    1.75 +
    1.76 +    typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
    1.77 +    typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
    1.78 +    typedef std::pair<ID3D11DepthStencilState*, unsigned long long> DepthStencilStateCounterPair;
    1.79 +    typedef std::unordered_map<gl::DepthStencilState,
    1.80 +                               DepthStencilStateCounterPair,
    1.81 +                               DepthStencilStateHashFunction,
    1.82 +                               DepthStencilStateEqualityFunction> DepthStencilStateMap;
    1.83 +    DepthStencilStateMap mDepthStencilStateCache;
    1.84 +
    1.85 +    // Sample state cache
    1.86 +    static std::size_t hashSamplerState(const gl::SamplerState &samplerState);
    1.87 +    static bool compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
    1.88 +    static const unsigned int kMaxSamplerStates;
    1.89 +
    1.90 +    typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
    1.91 +    typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
    1.92 +    typedef std::pair<ID3D11SamplerState*, unsigned long long> SamplerStateCounterPair;
    1.93 +    typedef std::unordered_map<gl::SamplerState,
    1.94 +                               SamplerStateCounterPair,
    1.95 +                               SamplerStateHashFunction,
    1.96 +                               SamplerStateEqualityFunction> SamplerStateMap;
    1.97 +    SamplerStateMap mSamplerStateCache;
    1.98 +
    1.99 +    ID3D11Device *mDevice;
   1.100 +};
   1.101 +
   1.102 +}
   1.103 +
   1.104 +#endif // LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
   1.105 \ No newline at end of file

mercurial