Commit ebf396c1 by Jamie Madill

Lazy creation of the BufferStorage staging buffer.

Only creating the staging buffer on use saves us from allocating a D3D11 staging buffer for pack buffers. This saves some memory and time when we're only using a buffer object for asynchronous readback. BUG=angle:511 Change-Id: I97b37cc27aba4a4526025815b5935b9e74abae2e Reviewed-on: https://chromium-review.googlesource.com/195367Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 0b44a455
......@@ -205,19 +205,22 @@ void *BufferStorage11::getData()
void BufferStorage11::setData(const void* data, unsigned int size, unsigned int offset)
{
NativeBuffer11 *stagingBuffer = getStagingBuffer();
// Explicitly resize the staging buffer, preserving data if the new data will not
// completely fill the buffer
size_t requiredSize = size + offset;
if (stagingBuffer->getSize() < requiredSize)
{
bool preserveData = (offset > 0);
stagingBuffer->resize(requiredSize, preserveData);
}
mWriteUsageCount = 0;
mSize = std::max(mSize, requiredSize);
if (data)
{
NativeBuffer11 *stagingBuffer = getStagingBuffer();
// Explicitly resize the staging buffer, preserving data if the new data will not
// completely fill the buffer
if (stagingBuffer->getSize() < requiredSize)
{
bool preserveData = (offset > 0);
stagingBuffer->resize(requiredSize, preserveData);
}
ID3D11DeviceContext *context = mRenderer->getDeviceContext();
D3D11_MAPPED_SUBRESOURCE mappedResource;
......@@ -231,11 +234,9 @@ void BufferStorage11::setData(const void* data, unsigned int size, unsigned int
memcpy(offsetBufferPointer, data, size);
context->Unmap(stagingBuffer->getNativeBuffer(), 0);
}
stagingBuffer->setDataRevision(stagingBuffer->getDataRevision() + 1);
mWriteUsageCount = 0;
mSize = std::max(mSize, requiredSize);
stagingBuffer->setDataRevision(stagingBuffer->getDataRevision() + 1);
}
}
void BufferStorage11::copyData(BufferStorage* sourceStorage, unsigned int size,
......@@ -379,6 +380,12 @@ BufferStorage11::TypedBufferStorage11 *BufferStorage11::getStorage(BufferUsage u
mTypedBuffers.insert(std::make_pair(usage, directBuffer));
}
// resize buffer
if (directBuffer->getSize() < mSize)
{
directBuffer->resize(mSize, true);
}
TypedBufferStorage11 *latestBuffer = getLatestStorage();
if (latestBuffer && latestBuffer->getDataRevision() > directBuffer->getDataRevision())
{
......
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