Commit bc3b5e63 by Corentin Wallez

D3D11: map index buffers only when needed.

Before this patch, index buffers where always mapped in case we needed the index data for the indexed point sprites workaround. This patch makes it so the index buffer is only mapped in this case, when we need to stream index data or when we need to fill the static copies of the index buffers. This make the memory usage of http://alteredqualia.com/xg/examples/mammoth.html go down from 41MB to 28MB. BUG=angleproject:516 Change-Id: I937506d06fd6f074ef2120469dbd235e20245fca Reviewed-on: https://chromium-review.googlesource.com/283626Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 58832204
......@@ -133,9 +133,13 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, GLsizei count, gl::
const gl::Type &srcTypeInfo = gl::GetTypeInfo(srcType);
const gl::Type &dstTypeInfo = gl::GetTypeInfo(dstType);
BufferD3D *buffer = glBuffer ? GetImplAs<BufferD3D>(glBuffer) : nullptr;
translated->indexType = dstType;
if (sourceData)
{
sourceData->srcBuffer = buffer;
sourceData->srcIndices = indices;
sourceData->srcIndexType = srcType;
sourceData->srcCount = count;
}
......@@ -144,16 +148,10 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, GLsizei count, gl::
if (glBuffer == nullptr)
{
translated->storage = nullptr;
if (sourceData)
{
sourceData->srcIndices = indices;
}
return streamIndexData(indices, count, srcType, dstType, translated);
}
// Case 2: the indices are already in a buffer
BufferD3D *buffer = GetImplAs<BufferD3D>(glBuffer);
unsigned int offset = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(indices));
ASSERT(srcTypeInfo.bytes * static_cast<unsigned int>(count) + offset <= buffer->getSize());
......@@ -166,21 +164,6 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, GLsizei count, gl::
default: UNREACHABLE(); offsetAligned = false;
}
// TODO(cwallez) avoid doing this in all cases as it prevents optimizations
// of the sysmem buffer copy
const uint8_t *bufferData = nullptr;
gl::Error error = buffer->getData(&bufferData);
if (error.isError())
{
return error;
}
ASSERT(bufferData != nullptr);
if (sourceData)
{
sourceData->srcIndices = bufferData + offset;
}
// Case 2a: the buffer can be used directly
if (offsetAligned && buffer->supportsDirectBinding() &&
dstType == srcType && !primitiveRestartWorkaround)
......@@ -213,7 +196,15 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, GLsizei count, gl::
if (staticBuffer == nullptr || !offsetAligned)
{
gl::Error error = streamIndexData(bufferData, count, srcType, dstType, translated);
const uint8_t *bufferData = nullptr;
gl::Error error = buffer->getData(&bufferData);
if (error.isError())
{
return error;
}
ASSERT(bufferData != nullptr);
error = streamIndexData(bufferData, count, srcType, dstType, translated);
if (error.isError())
{
return error;
......@@ -223,9 +214,17 @@ gl::Error IndexDataManager::prepareIndexData(GLenum srcType, GLsizei count, gl::
{
if (!staticBufferInitialized)
{
const uint8_t *bufferData = nullptr;
gl::Error error = buffer->getData(&bufferData);
if (error.isError())
{
return error;
}
ASSERT(bufferData != nullptr);
unsigned int convertCount = buffer->getSize() >> srcTypeInfo.bytesShift;
gl::Error error = StreamInIndexBuffer(staticBuffer, bufferData, convertCount,
srcType, dstType, nullptr);
error = StreamInIndexBuffer(staticBuffer, bufferData, convertCount,
srcType, dstType, nullptr);
if (error.isError())
{
return error;
......
......@@ -50,6 +50,7 @@ struct TranslatedIndexData
struct SourceIndexData
{
BufferD3D *srcBuffer;
const GLvoid *srcIndices;
unsigned int srcCount;
GLenum srcIndexType;
......
......@@ -364,6 +364,21 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
}
else if (indexedPointSpriteEmulationActive)
{
if (sourceInfo->srcBuffer != nullptr)
{
const uint8_t *bufferData = nullptr;
gl::Error error = sourceInfo->srcBuffer->getData(&bufferData);
if (error.isError())
{
return error;
}
ASSERT(bufferData != nullptr);
ptrdiff_t offset = reinterpret_cast<ptrdiff_t>(sourceInfo->srcIndices);
sourceInfo->srcBuffer = nullptr;
sourceInfo->srcIndices = bufferData + offset;
}
buffer = bufferStorage->getEmulatedIndexedBuffer(sourceInfo, sortedAttributes[i]);
}
else
......
......@@ -125,7 +125,7 @@ class D3D11EmulatedIndexedBufferTest : public ANGLETest
// into a valid emulated indexed buffer.
TEST_P(D3D11EmulatedIndexedBufferTest, TestNativeToExpandedUsingGLubyteIndices)
{
rx::SourceIndexData srcData = {mubyteIndices.data(), mubyteIndices.size(), GL_UNSIGNED_BYTE, false};
rx::SourceIndexData srcData = {nullptr, mubyteIndices.data(), mubyteIndices.size(), GL_UNSIGNED_BYTE, false};
emulateAndCompare(&srcData);
}
......@@ -133,7 +133,7 @@ TEST_P(D3D11EmulatedIndexedBufferTest, TestNativeToExpandedUsingGLubyteIndices)
// into a valid emulated indexed buffer.
TEST_P(D3D11EmulatedIndexedBufferTest, TestNativeToExpandedUsingGLushortIndices)
{
rx::SourceIndexData srcData = {mushortIndices.data(), mushortIndices.size(), GL_UNSIGNED_SHORT, false};
rx::SourceIndexData srcData = {nullptr, mushortIndices.data(), mushortIndices.size(), GL_UNSIGNED_SHORT, false };
emulateAndCompare(&srcData);
}
......@@ -141,7 +141,7 @@ TEST_P(D3D11EmulatedIndexedBufferTest, TestNativeToExpandedUsingGLushortIndices)
// into a valid emulated indexed buffer.
TEST_P(D3D11EmulatedIndexedBufferTest, TestNativeToExpandedUsingGLuintIndices)
{
rx::SourceIndexData srcData = {muintIndices.data(), muintIndices.size(), GL_UNSIGNED_INT, false};
rx::SourceIndexData srcData = {nullptr, muintIndices.data(), muintIndices.size(), GL_UNSIGNED_INT, false };
emulateAndCompare(&srcData);
}
......@@ -153,7 +153,7 @@ TEST_P(D3D11EmulatedIndexedBufferTest, TestSourceBufferRemainsUntouchedAfterExpa
cleanSourceBuffer->copySubData(mSourceBuffer, 0, 0, mSourceBuffer->getSize());
// Do a basic exanded and compare test.
rx::SourceIndexData srcData = {muintIndices.data(), muintIndices.size(), GL_UNSIGNED_INT, false};
rx::SourceIndexData srcData = {nullptr, muintIndices.data(), muintIndices.size(), GL_UNSIGNED_INT, false };
emulateAndCompare(&srcData);
const uint8_t *sourceBufferMem = nullptr;
......
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