Bug 1328762 - Cherry-pick ANGLE a4aaa2de57dc51243da35ea147d289a21a9f0c49. a=dveditz FIREFOX_54_0b5_BUILD1 FIREFOX_54_0b5_RELEASE
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 04 May 2017 13:15:48 -0400
changeset 574135 06bf49fb579575e4813aa54127f67c22964c822b
parent 574134 6d7583b30b408ea75bba3bb1ef7912f0343eda68
child 574136 c097727dc38532dfac5370dc7a1023ca1ba1ef40
push id57592
push userbmo:cpearce@mozilla.com
push dateMon, 08 May 2017 10:55:22 +0000
reviewersdveditz
bugs1328762
milestone54.0
Bug 1328762 - Cherry-pick ANGLE a4aaa2de57dc51243da35ea147d289a21a9f0c49. a=dveditz MozReview-Commit-ID: WVK0smAfAW
gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h
--- a/gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
+++ b/gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.cpp
@@ -566,26 +566,29 @@ bool Buffer11::canDeallocateSystemMemory
     {
         return false;
     }
 
     return (!mBufferStorages[BUFFER_USAGE_UNIFORM] ||
             mSize <= mRenderer->getNativeCaps().maxUniformBlockSize);
 }
 
-gl::Error Buffer11::markBufferUsage(BufferUsage usage)
+void Buffer11::markBufferUsage(BufferUsage usage)
 {
     mIdleness[usage] = 0;
+}
 
-    if (usage != BUFFER_USAGE_SYSTEM_MEMORY && canDeallocateSystemMemory())
+gl::Error Buffer11::garbageCollection(BufferUsage currentUsage)
+{
+    if (currentUsage != BUFFER_USAGE_SYSTEM_MEMORY && canDeallocateSystemMemory())
     {
         ANGLE_TRY(checkForDeallocation(BUFFER_USAGE_SYSTEM_MEMORY));
     }
 
-    if (usage != BUFFER_USAGE_STAGING)
+    if (currentUsage != BUFFER_USAGE_STAGING)
     {
         ANGLE_TRY(checkForDeallocation(BUFFER_USAGE_STAGING));
     }
 
     return gl::NoError();
 }
 
 gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getBuffer(BufferUsage usage)
@@ -681,25 +684,28 @@ gl::ErrorOrResult<Buffer11::BufferStorag
     ASSERT(0 <= usage && usage < BUFFER_USAGE_COUNT);
     BufferStorage *&newStorage = mBufferStorages[usage];
 
     if (!newStorage)
     {
         newStorage = allocateStorage(usage);
     }
 
+    markBufferUsage(usage);
+
     // resize buffer
     if (newStorage->getSize() < mSize)
     {
         ANGLE_TRY(newStorage->resize(mSize, true));
     }
 
-    mIdleness[usage] = 0;
+    ASSERT(newStorage);
+
     ANGLE_TRY(updateBufferStorage(newStorage, 0, mSize));
-    ANGLE_TRY(markBufferUsage(usage));
+    ANGLE_TRY(garbageCollection(usage));
 
     return newStorage;
 }
 
 Buffer11::BufferStorage *Buffer11::allocateStorage(BufferUsage usage)
 {
     updateDeallocThreshold(usage);
     switch (usage)
@@ -733,16 +739,18 @@ gl::ErrorOrResult<Buffer11::BufferStorag
             cacheEntry->storage  = allocateStorage(BUFFER_USAGE_UNIFORM);
             cacheEntry->lruCount = ++mMaxConstantBufferLruCount;
         }
 
         cacheEntry->lruCount = ++mMaxConstantBufferLruCount;
         newStorage           = cacheEntry->storage;
     }
 
+    markBufferUsage(BUFFER_USAGE_UNIFORM);
+
     if (newStorage->getSize() < static_cast<size_t>(size))
     {
         size_t maximumAllowedAdditionalSize = 2 * getSize();
 
         size_t sizeDelta = size - newStorage->getSize();
 
         while (mConstantBufferStorageAdditionalSize + sizeDelta > maximumAllowedAdditionalSize)
         {
@@ -767,27 +775,29 @@ gl::ErrorOrResult<Buffer11::BufferStorag
 
         // We don't copy the old data when resizing the constant buffer because the data may be
         // out-of-date therefore we reset the data revision and let updateBufferStorage() handle the
         // copy.
         newStorage->setDataRevision(0);
     }
 
     ANGLE_TRY(updateBufferStorage(newStorage, offset, size));
-    ANGLE_TRY(markBufferUsage(BUFFER_USAGE_UNIFORM));
+    ANGLE_TRY(garbageCollection(BUFFER_USAGE_UNIFORM));
     return newStorage;
 }
 
 gl::Error Buffer11::updateBufferStorage(BufferStorage *storage,
                                         size_t sourceOffset,
                                         size_t storageSize)
 {
     BufferStorage *latestBuffer = nullptr;
     ANGLE_TRY_RESULT(getLatestBufferStorage(), latestBuffer);
 
+    ASSERT(storage);
+
     if (latestBuffer && latestBuffer->getDataRevision() > storage->getDataRevision())
     {
         // Copy through a staging buffer if we're copying from or to a non-staging, mappable
         // buffer storage. This is because we can't map a GPU buffer, and copy CPU
         // data directly. If we're already using a staging buffer we're fine.
         if (latestBuffer->getUsage() != BUFFER_USAGE_STAGING &&
             storage->getUsage() != BUFFER_USAGE_STAGING &&
             (!latestBuffer->isMappable(GL_MAP_READ_BIT) || !storage->isMappable(GL_MAP_WRITE_BIT)))
--- a/gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h
+++ b/gfx/angle/src/libANGLE/renderer/d3d/d3d11/Buffer11.h
@@ -101,17 +101,18 @@ class Buffer11 : public BufferD3D
     struct ConstantBufferCacheEntry
     {
         ConstantBufferCacheEntry() : storage(nullptr), lruCount(0) { }
 
         BufferStorage *storage;
         unsigned int lruCount;
     };
 
-    gl::Error markBufferUsage(BufferUsage usage);
+    void markBufferUsage(BufferUsage usage);
+    gl::Error garbageCollection(BufferUsage currentUsage);
     gl::ErrorOrResult<NativeStorage *> getStagingStorage();
     gl::ErrorOrResult<PackStorage *> getPackStorage();
     gl::ErrorOrResult<SystemMemoryStorage *> getSystemMemoryStorage();
 
     gl::Error updateBufferStorage(BufferStorage *storage, size_t sourceOffset, size_t storageSize);
     gl::ErrorOrResult<BufferStorage *> getBufferStorage(BufferUsage usage);
     gl::ErrorOrResult<BufferStorage *> getLatestBufferStorage() const;