Commit 9ad2ab33 by Geoff Lang

Improve the TextureStorage11 SRV cache.

* Use a std::map instead of std::vector for logarithmic search time. * Reduce the number of structs and make them private instead of protected since they arn't used outside of the base class. * Fix the SRV cache member name. BUG=angle:520 Change-Id: I5158c1d46523f46158c51cd68044f7c915a3de03 Reviewed-on: https://chromium-review.googlesource.com/217335Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1f8532bd
......@@ -53,40 +53,9 @@ TextureStorage11::SRVKey::SRVKey(int baseLevel, int mipLevels, bool swizzle)
{
}
bool TextureStorage11::SRVKey::operator==(const SRVKey &rhs) const
bool TextureStorage11::SRVKey::operator<(const SRVKey &rhs) const
{
return baseLevel == rhs.baseLevel &&
mipLevels == rhs.mipLevels &&
swizzle == rhs.swizzle;
}
TextureStorage11::SRVCache::~SRVCache()
{
for (size_t i = 0; i < cache.size(); i++)
{
SafeRelease(cache[i].srv);
}
}
ID3D11ShaderResourceView *TextureStorage11::SRVCache::find(const SRVKey &key) const
{
for (size_t i = 0; i < cache.size(); i++)
{
if (cache[i].key == key)
{
return cache[i].srv;
}
}
return NULL;
}
ID3D11ShaderResourceView *TextureStorage11::SRVCache::add(const SRVKey &key, ID3D11ShaderResourceView *srv)
{
SRVPair pair = {key, srv};
cache.push_back(pair);
return srv;
return std::tie(baseLevel, mipLevels, swizzle) < std::tie(rhs.baseLevel, rhs.mipLevels, rhs.swizzle);
}
TextureStorage11::TextureStorage11(Renderer *renderer, UINT bindFlags)
......@@ -115,6 +84,12 @@ TextureStorage11::~TextureStorage11()
{
SafeRelease(mLevelSRVs[level]);
}
for (SRVCache::iterator i = mSrvCache.begin(); i != mSrvCache.end(); i++)
{
SafeRelease(i->second);
}
mSrvCache.clear();
}
TextureStorage11 *TextureStorage11::makeTextureStorage11(TextureStorage *storage)
......@@ -210,21 +185,23 @@ ID3D11ShaderResourceView *TextureStorage11::getSRV(const gl::SamplerState &sampl
{
verifySwizzleExists(samplerState.swizzleRed, samplerState.swizzleGreen, samplerState.swizzleBlue, samplerState.swizzleAlpha);
}
SRVKey key(samplerState.baseLevel, mipLevels, swizzleRequired);
ID3D11ShaderResourceView *srv = srvCache.find(key);
if(srv)
SRVKey key(samplerState.baseLevel, mipLevels, swizzleRequired);
SRVCache::const_iterator iter = mSrvCache.find(key);
if (iter != mSrvCache.end())
{
return srv;
return iter->second;
}
else
{
DXGI_FORMAT format = (swizzleRequired ? mSwizzleShaderResourceFormat : mShaderResourceFormat);
ID3D11Resource *texture = swizzleRequired ? getSwizzleTexture() : getResource();
DXGI_FORMAT format = (swizzleRequired ? mSwizzleShaderResourceFormat : mShaderResourceFormat);
ID3D11Resource *texture = swizzleRequired ? getSwizzleTexture() : getResource();
ID3D11ShaderResourceView *srv = createSRV(samplerState.baseLevel, mipLevels, format, texture);
mSrvCache.insert(std::make_pair(key, srv));
srv = createSRV(samplerState.baseLevel, mipLevels, format, texture);
return srvCache.add(key, srv);
return srv;
}
}
ID3D11ShaderResourceView *TextureStorage11::getSRVLevel(int mipLevel)
......
......@@ -116,39 +116,24 @@ class TextureStorage11 : public TextureStorage
};
SwizzleCacheValue mSwizzleCache[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage11);
const UINT mBindFlags;
struct SRVKey
{
SRVKey(int baseLevel = 0, int mipLevels = 0, bool swizzle = false);
bool operator==(const SRVKey &rhs) const;
bool operator<(const SRVKey &rhs) const;
int baseLevel;
int mipLevels;
bool swizzle;
};
typedef std::map<SRVKey, ID3D11ShaderResourceView *> SRVCache;
struct SRVPair
{
SRVKey key;
ID3D11ShaderResourceView *srv;
};
struct SRVCache
{
~SRVCache();
ID3D11ShaderResourceView *find(const SRVKey &key) const;
ID3D11ShaderResourceView *add(const SRVKey &key, ID3D11ShaderResourceView *srv);
std::vector<SRVPair> cache;
};
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage11);
const UINT mBindFlags;
SRVCache srvCache;
SRVCache mSrvCache;
ID3D11ShaderResourceView *mLevelSRVs[gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS];
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment