Commit 2c70e64b by Jamie Madill

Revert "D3D11: Refactor InputLayout cache."

Seems to be failing maps_pixel_test on the bots. BUG=angleproject:959 This reverts commit 53fd1552. Change-Id: I1f2593caca58f701d284993d2ee313846806491b Reviewed-on: https://chromium-review.googlesource.com/283157Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 53fd1552
......@@ -8,15 +8,16 @@
// D3D11 input layouts.
#include "libANGLE/renderer/d3d/d3d11/InputLayoutCache.h"
#include "libANGLE/Program.h"
#include "libANGLE/VertexAttribute.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h"
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h"
#include "libANGLE/renderer/d3d/d3d11/VertexBuffer11.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/Program.h"
#include "libANGLE/VertexAttribute.h"
#include "third_party/murmurhash/MurmurHash3.h"
namespace rx
{
......@@ -44,38 +45,7 @@ void GetInputLayout(const TranslatedAttribute *translatedAttributes[gl::MAX_VERT
const unsigned int InputLayoutCache::kMaxInputLayouts = 1024;
bool InputLayoutCache::PackedAttributeLayout::operator<(const PackedAttributeLayout &other) const
{
if (numAttributes != other.numAttributes)
{
return numAttributes < other.numAttributes;
}
if (flags != other.flags)
{
return flags < other.flags;
}
for (size_t attribIndex = 0; attribIndex < numAttributes; attribIndex++)
{
const auto &attribA = attributeData[attribIndex];
const auto &attribB = other.attributeData[attribIndex];
if (attribA.glType != attribB.glType)
return attribA.glType < attribB.glType;
if (attribA.semanticIndex != attribB.semanticIndex)
return attribA.semanticIndex < attribB.semanticIndex;
if (attribA.dxgiFormat != attribB.dxgiFormat)
return attribA.dxgiFormat < attribB.dxgiFormat;
if (attribA.divisor != attribB.divisor)
return attribA.divisor < attribB.divisor;
}
// Equal
return false;
}
InputLayoutCache::InputLayoutCache()
InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInputLayout, compareInputLayouts)
{
mCounter = 0;
mDevice = NULL;
......@@ -106,11 +76,11 @@ void InputLayoutCache::initialize(ID3D11Device *device, ID3D11DeviceContext *con
void InputLayoutCache::clear()
{
for (auto &layout : mLayoutMap)
for (InputLayoutMap::iterator i = mInputLayoutMap.begin(); i != mInputLayoutMap.end(); i++)
{
SafeRelease(layout.second);
SafeRelease(i->second.inputLayout);
}
mLayoutMap.clear();
mInputLayoutMap.clear();
SafeRelease(mPointSpriteVertexBuffer);
SafeRelease(mPointSpriteIndexBuffer);
markDirty();
......@@ -143,10 +113,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized.");
}
InputLayoutKey ilKey;
ilKey.elementCount = 0;
PackedAttributeLayout layout;
InputLayoutKey ilKey = { 0 };
static const char* semanticName = "TEXCOORD";
......@@ -189,11 +156,6 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
ilKey.elementCount++;
nextAvailableInputSlot = i + 1;
layout.addAttributeData(ilKey.elements[ilKey.elementCount].glslElementType,
sortedSemanticIndices[i],
vertexFormatInfo.nativeFormat,
sortedAttributes[i]->divisor);
}
}
......@@ -251,34 +213,20 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
}
}
if (programUsesInstancedPointSprites)
{
layout.flags |= PackedAttributeLayout::FLAG_USES_INSTANCED_SPRITES;
}
if (moveFirstIndexedIntoSlotZero)
{
layout.flags |= PackedAttributeLayout::FLAG_MOVE_FIRST_INDEXED;
}
if (instancedPointSpritesActive)
{
layout.flags |= PackedAttributeLayout::FLAG_INSTANCED_SPRITES_ACTIVE;
}
ID3D11InputLayout *inputLayout = nullptr;
ID3D11InputLayout *inputLayout = NULL;
auto layoutMapIt = mLayoutMap.find(layout);
if (layoutMapIt != mLayoutMap.end())
InputLayoutMap::iterator keyIter = mInputLayoutMap.find(ilKey);
if (keyIter != mInputLayoutMap.end())
{
inputLayout = layoutMapIt->second;
inputLayout = keyIter->second.inputLayout;
keyIter->second.lastUsedTime = mCounter++;
}
else
{
gl::VertexFormat shaderInputLayout[gl::MAX_VERTEX_ATTRIBS];
GetInputLayout(sortedAttributes, unsortedAttributes.size(), shaderInputLayout);
ShaderExecutableD3D *shader = nullptr;
ShaderExecutableD3D *shader = NULL;
gl::Error error = programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr);
if (error.isError())
{
......@@ -299,19 +247,28 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal input layout, HRESULT: 0x%08x", result);
}
if (mLayoutMap.size() >= kMaxInputLayouts)
if (mInputLayoutMap.size() >= kMaxInputLayouts)
{
TRACE("Overflowed the limit of %u input layouts, purging half the cache.", kMaxInputLayouts);
TRACE("Overflowed the limit of %u input layouts, removing the least recently used "
"to make room.", kMaxInputLayouts);
// Randomly release every second element
for (auto it = mLayoutMap.begin(); it != mLayoutMap.end(); std::advance(it, 2))
InputLayoutMap::iterator leastRecentlyUsed = mInputLayoutMap.begin();
for (InputLayoutMap::iterator i = mInputLayoutMap.begin(); i != mInputLayoutMap.end(); i++)
{
SafeRelease(it->second);
mLayoutMap.erase(it);
if (i->second.lastUsedTime < leastRecentlyUsed->second.lastUsedTime)
{
leastRecentlyUsed = i;
}
}
SafeRelease(leastRecentlyUsed->second.inputLayout);
mInputLayoutMap.erase(leastRecentlyUsed);
}
mLayoutMap[layout] = inputLayout;
InputLayoutCounterPair inputCounterPair;
inputCounterPair.inputLayout = inputLayout;
inputCounterPair.lastUsedTime = mCounter++;
mInputLayoutMap.insert(std::make_pair(ilKey, inputCounterPair));
}
if (inputLayout != mCurrentIL)
......@@ -460,4 +417,23 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
return gl::Error(GL_NO_ERROR);
}
std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout)
{
static const unsigned int seed = 0xDEADBEEF;
std::size_t hash = 0;
MurmurHash3_x86_32(inputLayout.begin(), static_cast<int>(inputLayout.end() - inputLayout.begin()), seed, &hash);
return hash;
}
bool InputLayoutCache::compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b)
{
if (a.elementCount != b.elementCount)
{
return false;
}
return std::equal(a.begin(), a.end(), b.begin());
}
}
......@@ -17,7 +17,6 @@
#include <GLES2/gl2.h>
#include <cstddef>
#include <map>
#include <unordered_map>
namespace gl
......@@ -65,50 +64,12 @@ class InputLayoutCache : angle::NonCopyable
}
};
struct PackedAttributeLayout
struct InputLayoutCounterPair
{
PackedAttributeLayout()
: numAttributes(0),
flags(0)
{
}
void addAttributeData(GLenum glType,
UINT semanticIndex,
DXGI_FORMAT dxgiFormat,
unsigned int divisor)
{
attributeData[numAttributes].glType = glType;
attributeData[numAttributes].semanticIndex = semanticIndex;
attributeData[numAttributes].dxgiFormat = dxgiFormat;
attributeData[numAttributes].divisor = divisor;
++numAttributes;
}
struct PackedAttribute
{
GLenum glType;
UINT semanticIndex;
DXGI_FORMAT dxgiFormat;
unsigned int divisor;
};
enum Flags
{
FLAG_USES_INSTANCED_SPRITES = 0x1,
FLAG_MOVE_FIRST_INDEXED = 0x2,
FLAG_INSTANCED_SPRITES_ACTIVE = 0x4,
};
bool operator<(const PackedAttributeLayout &other) const;
size_t numAttributes;
unsigned int flags;
PackedAttribute attributeData[gl::MAX_VERTEX_ATTRIBS];
ID3D11InputLayout *inputLayout;
unsigned long long lastUsedTime;
};
std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap;
ID3D11InputLayout *mCurrentIL;
ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS];
......@@ -117,6 +78,17 @@ class InputLayoutCache : angle::NonCopyable
ID3D11Buffer *mPointSpriteVertexBuffer;
ID3D11Buffer *mPointSpriteIndexBuffer;
static std::size_t hashInputLayout(const InputLayoutKey &inputLayout);
static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b);
typedef std::size_t (*InputLayoutHashFunction)(const InputLayoutKey &);
typedef bool (*InputLayoutEqualityFunction)(const InputLayoutKey &, const InputLayoutKey &);
typedef std::unordered_map<InputLayoutKey,
InputLayoutCounterPair,
InputLayoutHashFunction,
InputLayoutEqualityFunction> InputLayoutMap;
InputLayoutMap mInputLayoutMap;
static const unsigned int kMaxInputLayouts;
unsigned long long mCounter;
......
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