summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Lang <geofflang@google.com>2013-07-22 12:18:39 -0400
committerGeoff Lang <geofflang@google.com>2013-07-26 17:05:51 -0400
commitb312b1c6bf47b6741878f4f54acb6db9eb0f9938 (patch)
tree0d8da49ae82f2ca8f9926c3ea80e24168045bc2f
parent5b3f92177fd5cefb4833d48d47f0f4dcea3955b5 (diff)
downloadangle_dx11-b312b1c6bf47b6741878f4f54acb6db9eb0f9938.tar.gz
Cache applied vertex buffers and input layout.
Issue #451 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang
-rw-r--r--src/libGLESv2/renderer/InputLayoutCache.cpp40
-rw-r--r--src/libGLESv2/renderer/InputLayoutCache.h6
-rw-r--r--src/libGLESv2/renderer/Renderer11.cpp2
3 files changed, 46 insertions, 2 deletions
diff --git a/src/libGLESv2/renderer/InputLayoutCache.cpp b/src/libGLESv2/renderer/InputLayoutCache.cpp
index 0402bb35..fcc6f7ce 100644
--- a/src/libGLESv2/renderer/InputLayoutCache.cpp
+++ b/src/libGLESv2/renderer/InputLayoutCache.cpp
@@ -28,6 +28,13 @@ InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInp
mCounter = 0;
mDevice = NULL;
mDeviceContext = NULL;
+ mCurrentIL = NULL;
+ for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
+ {
+ mCurrentBuffers[i] = -1;
+ mCurrentVertexStrides[i] = -1;
+ mCurrentVertexOffsets[i] = -1;
+ }
}
InputLayoutCache::~InputLayoutCache()
@@ -49,6 +56,18 @@ void InputLayoutCache::clear()
i->second.inputLayout->Release();
}
mInputLayoutMap.clear();
+ markDirty();
+}
+
+void InputLayoutCache::markDirty()
+{
+ mCurrentIL = NULL;
+ for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
+ {
+ mCurrentBuffers[i] = -1;
+ mCurrentVertexStrides[i] = -1;
+ mCurrentVertexOffsets[i] = -1;
+ }
}
GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
@@ -66,6 +85,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
InputLayoutKey ilKey = { 0 };
ID3D11Buffer *vertexBuffers[gl::MAX_VERTEX_ATTRIBS] = { NULL };
+ unsigned int vertexBufferSerials[gl::MAX_VERTEX_ATTRIBS] = { 0 };
UINT vertexStrides[gl::MAX_VERTEX_ATTRIBS] = { 0 };
UINT vertexOffsets[gl::MAX_VERTEX_ATTRIBS] = { 0 };
@@ -95,6 +115,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
ilKey.elementCount++;
vertexBuffers[i] = bufferStorage ? bufferStorage->getBuffer() : vertexBuffer->getBuffer();
+ vertexBufferSerials[i] = bufferStorage ? bufferStorage->getSerial() : vertexBuffer->getSerial();
vertexStrides[i] = attributes[i].stride;
vertexOffsets[i] = attributes[i].offset;
}
@@ -143,8 +164,23 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
mInputLayoutMap.insert(std::make_pair(ilKey, inputCounterPair));
}
- mDeviceContext->IASetInputLayout(inputLayout);
- mDeviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, vertexBuffers, vertexStrides, vertexOffsets);
+ if (inputLayout != mCurrentIL)
+ {
+ mDeviceContext->IASetInputLayout(inputLayout);
+ mCurrentIL = inputLayout;
+ }
+
+ for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
+ {
+ if (vertexBufferSerials[i] != mCurrentBuffers[i] || vertexStrides[i] != mCurrentVertexStrides[i] ||
+ vertexOffsets[i] != mCurrentVertexOffsets[i])
+ {
+ mDeviceContext->IASetVertexBuffers(i, 1, &vertexBuffers[i], &vertexStrides[i], &vertexOffsets[i]);
+ mCurrentBuffers[i] = vertexBufferSerials[i];
+ mCurrentVertexStrides[i] = vertexStrides[i];
+ mCurrentVertexOffsets[i] = vertexOffsets[i];
+ }
+ }
return GL_NO_ERROR;
}
diff --git a/src/libGLESv2/renderer/InputLayoutCache.h b/src/libGLESv2/renderer/InputLayoutCache.h
index d95f39fa..797853de 100644
--- a/src/libGLESv2/renderer/InputLayoutCache.h
+++ b/src/libGLESv2/renderer/InputLayoutCache.h
@@ -30,6 +30,7 @@ class InputLayoutCache
void initialize(ID3D11Device *device, ID3D11DeviceContext *context);
void clear();
+ void markDirty();
GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
gl::ProgramBinary *programBinary);
@@ -50,6 +51,11 @@ class InputLayoutCache
unsigned long long lastUsedTime;
};
+ ID3D11InputLayout *mCurrentIL;
+ unsigned int mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
+ UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS];
+ UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS];
+
static std::size_t hashInputLayout(const InputLayoutKey &inputLayout);
static bool compareInputLayouts(const InputLayoutKey &a, const InputLayoutKey &b);
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index e544b40c..c0066d0f 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -1797,6 +1797,8 @@ void Renderer11::markAllStateDirty()
mAppliedProgramBinarySerial = 0;
memset(&mAppliedVertexConstants, 0, sizeof(dx_VertexConstants));
memset(&mAppliedPixelConstants, 0, sizeof(dx_PixelConstants));
+
+ mInputLayoutCache.markDirty();
}
void Renderer11::releaseDeviceResources()