Commit 28b47909 by Geoff Lang

Cache bound vertex and index buffers by ID3D11Buffer instead of serial.

Since a DirectBuffer11 may return different buffers from getBuffer depending on the required buffer type and if the internal buffers are dirty or not, the current serial is not reliable. Use the actual buffer object so that there can be no missmatch. BUG=350581 Change-Id: I23ead63c2f626fc94ccc216201fa8ddc5b652c1b Reviewed-on: https://chromium-review.googlesource.com/189538Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 57f247bd
...@@ -31,7 +31,7 @@ InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInp ...@@ -31,7 +31,7 @@ InputLayoutCache::InputLayoutCache() : mInputLayoutMap(kMaxInputLayouts, hashInp
mCurrentIL = NULL; mCurrentIL = NULL;
for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
mCurrentBuffers[i] = -1; mCurrentBuffers[i] = NULL;
mCurrentVertexStrides[i] = -1; mCurrentVertexStrides[i] = -1;
mCurrentVertexOffsets[i] = -1; mCurrentVertexOffsets[i] = -1;
} }
...@@ -64,7 +64,7 @@ void InputLayoutCache::markDirty() ...@@ -64,7 +64,7 @@ void InputLayoutCache::markDirty()
mCurrentIL = NULL; mCurrentIL = NULL;
for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
mCurrentBuffers[i] = -1; mCurrentBuffers[i] = NULL;
mCurrentVertexStrides[i] = -1; mCurrentVertexStrides[i] = -1;
mCurrentVertexOffsets[i] = -1; mCurrentVertexOffsets[i] = -1;
} }
...@@ -85,7 +85,6 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -85,7 +85,6 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
InputLayoutKey ilKey = { 0 }; InputLayoutKey ilKey = { 0 };
ID3D11Buffer *vertexBuffers[gl::MAX_VERTEX_ATTRIBS] = { NULL }; ID3D11Buffer *vertexBuffers[gl::MAX_VERTEX_ATTRIBS] = { NULL };
unsigned int vertexBufferSerials[gl::MAX_VERTEX_ATTRIBS] = { 0 };
UINT vertexStrides[gl::MAX_VERTEX_ATTRIBS] = { 0 }; UINT vertexStrides[gl::MAX_VERTEX_ATTRIBS] = { 0 };
UINT vertexOffsets[gl::MAX_VERTEX_ATTRIBS] = { 0 }; UINT vertexOffsets[gl::MAX_VERTEX_ATTRIBS] = { 0 };
...@@ -115,7 +114,6 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -115,7 +114,6 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
ilKey.elementCount++; ilKey.elementCount++;
vertexBuffers[i] = bufferStorage ? bufferStorage->getBuffer(BUFFER_USAGE_VERTEX) : vertexBuffer->getBuffer(); vertexBuffers[i] = bufferStorage ? bufferStorage->getBuffer(BUFFER_USAGE_VERTEX) : vertexBuffer->getBuffer();
vertexBufferSerials[i] = bufferStorage ? bufferStorage->getSerial() : vertexBuffer->getSerial();
vertexStrides[i] = attributes[i].stride; vertexStrides[i] = attributes[i].stride;
vertexOffsets[i] = attributes[i].offset; vertexOffsets[i] = attributes[i].offset;
} }
...@@ -178,11 +176,11 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -178,11 +176,11 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
if (vertexBufferSerials[i] != mCurrentBuffers[i] || vertexStrides[i] != mCurrentVertexStrides[i] || if (vertexBuffers[i] != mCurrentBuffers[i] || vertexStrides[i] != mCurrentVertexStrides[i] ||
vertexOffsets[i] != mCurrentVertexOffsets[i]) vertexOffsets[i] != mCurrentVertexOffsets[i])
{ {
mDeviceContext->IASetVertexBuffers(i, 1, &vertexBuffers[i], &vertexStrides[i], &vertexOffsets[i]); mDeviceContext->IASetVertexBuffers(i, 1, &vertexBuffers[i], &vertexStrides[i], &vertexOffsets[i]);
mCurrentBuffers[i] = vertexBufferSerials[i]; mCurrentBuffers[i] = vertexBuffers[i];
mCurrentVertexStrides[i] = vertexStrides[i]; mCurrentVertexStrides[i] = vertexStrides[i];
mCurrentVertexOffsets[i] = vertexOffsets[i]; mCurrentVertexOffsets[i] = vertexOffsets[i];
} }
......
...@@ -67,7 +67,7 @@ class InputLayoutCache ...@@ -67,7 +67,7 @@ class InputLayoutCache
}; };
ID3D11InputLayout *mCurrentIL; ID3D11InputLayout *mCurrentIL;
unsigned int mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS]; ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS];
UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS]; UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS];
UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS]; UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS];
......
...@@ -1092,28 +1092,27 @@ GLenum Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementAr ...@@ -1092,28 +1092,27 @@ GLenum Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementAr
if (err == GL_NO_ERROR) if (err == GL_NO_ERROR)
{ {
if (indexInfo->storage) IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer);
{
if (indexInfo->serial != mAppliedStorageIBSerial || indexInfo->startOffset != mAppliedIBOffset)
{
BufferStorage11 *storage = BufferStorage11::makeBufferStorage11(indexInfo->storage);
IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer);
mDeviceContext->IASetIndexBuffer(storage->getBuffer(BUFFER_USAGE_INDEX), indexBuffer->getIndexFormat(), indexInfo->startOffset); ID3D11Buffer *buffer = NULL;
DXGI_FORMAT bufferFormat = indexBuffer->getIndexFormat();
mAppliedIBSerial = 0; if (indexInfo->storage)
mAppliedStorageIBSerial = storage->getSerial(); {
mAppliedIBOffset = indexInfo->startOffset; BufferStorage11 *storage = BufferStorage11::makeBufferStorage11(indexInfo->storage);
} buffer = storage->getBuffer(BUFFER_USAGE_INDEX);
} }
else if (indexInfo->serial != mAppliedIBSerial || indexInfo->startOffset != mAppliedIBOffset) else
{ {
IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); buffer = indexBuffer->getBuffer();
}
mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startOffset); if (buffer != mAppliedIB || bufferFormat != mAppliedIBFormat || indexInfo->startOffset != mAppliedIBOffset)
{
mDeviceContext->IASetIndexBuffer(buffer, bufferFormat, indexInfo->startOffset);
mAppliedIBSerial = indexInfo->serial; mAppliedIB = buffer;
mAppliedStorageIBSerial = 0; mAppliedIBFormat = bufferFormat;
mAppliedIBOffset = indexInfo->startOffset; mAppliedIBOffset = indexInfo->startOffset;
} }
} }
...@@ -1251,13 +1250,15 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, ...@@ -1251,13 +1250,15 @@ void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices,
return gl::error(GL_OUT_OF_MEMORY); return gl::error(GL_OUT_OF_MEMORY);
} }
if (mAppliedIBSerial != mLineLoopIB->getSerial() || mAppliedIBOffset != indexBufferOffset) IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer());
{ ID3D11Buffer *d3dIndexBuffer = indexBuffer->getBuffer();
IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat();
if (mAppliedIB != d3dIndexBuffer || mAppliedIBFormat != indexFormat || mAppliedIBOffset != indexBufferOffset)
{
mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset);
mAppliedIBSerial = mLineLoopIB->getSerial(); mAppliedIB = d3dIndexBuffer;
mAppliedStorageIBSerial = 0; mAppliedIBFormat = indexFormat;
mAppliedIBOffset = indexBufferOffset; mAppliedIBOffset = indexBufferOffset;
} }
...@@ -1360,13 +1361,15 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic ...@@ -1360,13 +1361,15 @@ void Renderer11::drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indic
return gl::error(GL_OUT_OF_MEMORY); return gl::error(GL_OUT_OF_MEMORY);
} }
if (mAppliedIBSerial != mTriangleFanIB->getSerial() || mAppliedIBOffset != indexBufferOffset) IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer());
{ ID3D11Buffer *d3dIndexBuffer = indexBuffer->getBuffer();
IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mTriangleFanIB->getIndexBuffer()); DXGI_FORMAT indexFormat = indexBuffer->getIndexFormat();
if (mAppliedIB != d3dIndexBuffer || mAppliedIBFormat != indexFormat || mAppliedIBOffset != indexBufferOffset)
{
mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset); mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexBufferOffset);
mAppliedIBSerial = mTriangleFanIB->getSerial(); mAppliedIB = d3dIndexBuffer;
mAppliedStorageIBSerial = 0; mAppliedIBFormat = indexFormat;
mAppliedIBOffset = indexBufferOffset; mAppliedIBOffset = indexBufferOffset;
} }
...@@ -1866,8 +1869,8 @@ void Renderer11::markAllStateDirty() ...@@ -1866,8 +1869,8 @@ void Renderer11::markAllStateDirty()
mForceSetScissor = true; mForceSetScissor = true;
mForceSetViewport = true; mForceSetViewport = true;
mAppliedIBSerial = 0; mAppliedIB = NULL;
mAppliedStorageIBSerial = 0; mAppliedIBFormat = DXGI_FORMAT_UNKNOWN;
mAppliedIBOffset = 0; mAppliedIBOffset = 0;
mAppliedProgramBinarySerial = 0; mAppliedProgramBinarySerial = 0;
......
...@@ -291,8 +291,8 @@ class Renderer11 : public Renderer ...@@ -291,8 +291,8 @@ class Renderer11 : public Renderer
// Currently applied primitive topology // Currently applied primitive topology
D3D11_PRIMITIVE_TOPOLOGY mCurrentPrimitiveTopology; D3D11_PRIMITIVE_TOPOLOGY mCurrentPrimitiveTopology;
unsigned int mAppliedIBSerial; ID3D11Buffer *mAppliedIB;
unsigned int mAppliedStorageIBSerial; DXGI_FORMAT mAppliedIBFormat;
unsigned int mAppliedIBOffset; unsigned int mAppliedIBOffset;
unsigned int mAppliedProgramBinarySerial; unsigned int mAppliedProgramBinarySerial;
......
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