Hash :
95f6cedd
Author :
Date :
2017-03-13T17:40:31
RenderstateCache and Clear11 Optimizations - Unify DepthStencilState and BlendState caches in RenderStateCache with those in Clear11. This will increase cache hit rate and reduce memory usage. - Apply DepthStencilState and BlendState only when required to reduce state sets. BUG=angleproject:1632 Change-Id: I244e3ba189f82814638fa90e2617aa5441024d0f Reviewed-on: https://chromium-review.googlesource.com/453888 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
//
// Copyright (c) 2012-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RenderStateCache.h: Defines rx::RenderStateCache, a cache of Direct3D render
// state objects.
#ifndef LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_
#define LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_
#include "libANGLE/angletypes.h"
#include "libANGLE/Error.h"
#include "common/angleutils.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include <unordered_map>
namespace gl
{
class Framebuffer;
}
namespace rx
{
class Renderer11;
class RenderStateCache : angle::NonCopyable
{
public:
RenderStateCache(Renderer11 *renderer);
virtual ~RenderStateCache();
void initialize(ID3D11Device *device);
void clear();
static d3d11::BlendStateKey GetBlendStateKey(const gl::Framebuffer *framebuffer,
const gl::BlendState &blendState);
gl::Error getBlendState(const d3d11::BlendStateKey &key, ID3D11BlendState **outBlendState);
gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState);
gl::Error getDepthStencilState(const gl::DepthStencilState &dsState,
ID3D11DepthStencilState **outDSState);
gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState);
private:
Renderer11 *mRenderer;
unsigned long long mCounter;
// Blend state cache
static std::size_t HashBlendState(const d3d11::BlendStateKey &blendState);
static bool CompareBlendStates(const d3d11::BlendStateKey &a, const d3d11::BlendStateKey &b);
static const unsigned int kMaxBlendStates;
typedef std::size_t (*BlendStateHashFunction)(const d3d11::BlendStateKey &);
typedef bool (*BlendStateEqualityFunction)(const d3d11::BlendStateKey &,
const d3d11::BlendStateKey &);
typedef std::pair<ID3D11BlendState*, unsigned long long> BlendStateCounterPair;
typedef std::unordered_map<d3d11::BlendStateKey,
BlendStateCounterPair,
BlendStateHashFunction,
BlendStateEqualityFunction>
BlendStateMap;
BlendStateMap mBlendStateCache;
// Rasterizer state cache
struct RasterizerStateKey
{
gl::RasterizerState rasterizerState;
bool scissorEnabled;
};
static std::size_t HashRasterizerState(const RasterizerStateKey &rasterState);
static bool CompareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b);
static const unsigned int kMaxRasterizerStates;
typedef std::size_t (*RasterizerStateHashFunction)(const RasterizerStateKey &);
typedef bool (*RasterizerStateEqualityFunction)(const RasterizerStateKey &, const RasterizerStateKey &);
typedef std::pair<ID3D11RasterizerState*, unsigned long long> RasterizerStateCounterPair;
typedef std::unordered_map<RasterizerStateKey, RasterizerStateCounterPair, RasterizerStateHashFunction, RasterizerStateEqualityFunction> RasterizerStateMap;
RasterizerStateMap mRasterizerStateCache;
// Depth stencil state cache
static std::size_t HashDepthStencilState(const gl::DepthStencilState &dsState);
static bool CompareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b);
static const unsigned int kMaxDepthStencilStates;
typedef std::size_t (*DepthStencilStateHashFunction)(const gl::DepthStencilState &);
typedef bool (*DepthStencilStateEqualityFunction)(const gl::DepthStencilState &, const gl::DepthStencilState &);
typedef std::pair<ID3D11DepthStencilState*, unsigned long long> DepthStencilStateCounterPair;
typedef std::unordered_map<gl::DepthStencilState,
DepthStencilStateCounterPair,
DepthStencilStateHashFunction,
DepthStencilStateEqualityFunction> DepthStencilStateMap;
DepthStencilStateMap mDepthStencilStateCache;
// Sample state cache
static std::size_t HashSamplerState(const gl::SamplerState &samplerState);
static bool CompareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b);
static const unsigned int kMaxSamplerStates;
typedef std::size_t (*SamplerStateHashFunction)(const gl::SamplerState &);
typedef bool (*SamplerStateEqualityFunction)(const gl::SamplerState &, const gl::SamplerState &);
typedef std::pair<ID3D11SamplerState*, unsigned long long> SamplerStateCounterPair;
typedef std::unordered_map<gl::SamplerState,
SamplerStateCounterPair,
SamplerStateHashFunction,
SamplerStateEqualityFunction> SamplerStateMap;
SamplerStateMap mSamplerStateCache;
ID3D11Device *mDevice;
};
}
#endif // LIBANGLE_RENDERER_D3D_D3D11_RENDERSTATECACHE_H_