Reduce calls to ID3D11DeviceContext::Map() in VertexBuffer11.cpp
This change moves VertexBuffer11::storeVertexAttributes()'s call to
Map() outside a for-loop, eliminating unnecessary calls to Map(). Since
Map() is a relatively expensive operation (even when using NO_OVERWRITE)
this change gives a noticeable performance boost in some scenarios.
Change-Id: I320111b32f2bb9eed92efbd240206e12aaa9964e
Reviewed-on: https://chromium-review.googlesource.com/240181
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Austin Kinross <aukinros@microsoft.com>
diff --git a/src/libANGLE/renderer/d3d/VertexDataManager.cpp b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
index 237c0ad..d0848ce 100644
--- a/src/libANGLE/renderer/d3d/VertexDataManager.cpp
+++ b/src/libANGLE/renderer/d3d/VertexDataManager.cpp
@@ -85,6 +85,35 @@
}
}
+void VertexDataManager::hintUnmapAllResources(const gl::State &state)
+{
+ mStreamingBuffer->getVertexBuffer()->hintUnmapResource();
+
+ for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
+ {
+ const gl::VertexAttribute &attrib = state.getVertexAttribState(i);
+ if (attrib.enabled)
+ {
+ gl::Buffer *buffer = attrib.buffer.get();
+ BufferD3D *storage = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL;
+ StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
+
+ if (staticBuffer)
+ {
+ staticBuffer->getVertexBuffer()->hintUnmapResource();
+ }
+ }
+ }
+
+ for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
+ {
+ if (mCurrentValueBuffer[i] != NULL)
+ {
+ mCurrentValueBuffer[i]->getVertexBuffer()->hintUnmapResource();
+ }
+ }
+}
+
gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint start, GLsizei count,
TranslatedAttribute *translated, GLsizei instances)
{
@@ -132,6 +161,7 @@
if (error.isError())
{
+ hintUnmapAllResources(state);
return error;
}
}
@@ -147,12 +177,16 @@
mCurrentValueBuffer[i]);
if (error.isError())
{
+ hintUnmapAllResources(state);
return error;
}
}
}
}
+ // Hint to unmap all the resources
+ hintUnmapAllResources(state);
+
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i);