Title: [279373] trunk/Source/ThirdParty/ANGLE
Revision
279373
Author
[email protected]
Date
2021-06-29 06:53:43 -0700 (Tue, 29 Jun 2021)

Log Message

ANGLE Metal primitive restart range computation could index with size_t
https://bugs.webkit.org/show_bug.cgi?id=227449

Patch by Kimmo Kinnunen <[email protected]> on 2021-06-29
Reviewed by Kenneth Russell.

Make the `calculateRestartRanges()` a bit simpler in order
for it to be easier to understand.

* src/libANGLE/renderer/metal/BufferMtl.h:
(rx::IndexRange::IndexRange):
Add documentation what the mtl::IndexRange is.
Add constructor so that `std::vector::emplace_back()` works.

* src/libANGLE/renderer/metal/BufferMtl.mm:
(rx::calculateRestartRanges):
Index with size_t to make it simpler to understand if the index
overflows or not.
Use reinterpret_cast in order to not accidentally cast away
const from `mtl::BufferRef::mapReadOnly()`.
Skip the non-marker elements with `continue` to avoid deep nesting.
Give a name to the restart range marker value.
Remove intermediate variable `value = bufferData[i]` as it is never
used more than once. This simplifies the code as the do-while loop
does not need to check the if condition as the loop ending condition
already checks.
Make the array a returned result instead of out variable.

(rx::BufferMtl::getRestartIndices):

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ANGLE/ChangeLog (279372 => 279373)


--- trunk/Source/ThirdParty/ANGLE/ChangeLog	2021-06-29 13:52:16 UTC (rev 279372)
+++ trunk/Source/ThirdParty/ANGLE/ChangeLog	2021-06-29 13:53:43 UTC (rev 279373)
@@ -1,5 +1,36 @@
 2021-06-29  Kimmo Kinnunen  <[email protected]>
 
+        ANGLE Metal primitive restart range computation could index with size_t
+        https://bugs.webkit.org/show_bug.cgi?id=227449
+
+        Reviewed by Kenneth Russell.
+
+        Make the `calculateRestartRanges()` a bit simpler in order
+        for it to be easier to understand.
+
+        * src/libANGLE/renderer/metal/BufferMtl.h:
+        (rx::IndexRange::IndexRange):
+        Add documentation what the mtl::IndexRange is.
+        Add constructor so that `std::vector::emplace_back()` works.
+
+        * src/libANGLE/renderer/metal/BufferMtl.mm:
+        (rx::calculateRestartRanges):
+        Index with size_t to make it simpler to understand if the index
+        overflows or not.
+        Use reinterpret_cast in order to not accidentally cast away
+        const from `mtl::BufferRef::mapReadOnly()`.
+        Skip the non-marker elements with `continue` to avoid deep nesting.
+        Give a name to the restart range marker value.
+        Remove intermediate variable `value = bufferData[i]` as it is never
+        used more than once. This simplifies the code as the do-while loop
+        does not need to check the if condition as the loop ending condition
+        already checks.
+        Make the array a returned result instead of out variable.
+
+        (rx::BufferMtl::getRestartIndices):
+
+2021-06-29  Kimmo Kinnunen  <[email protected]>
+
         ANGLE Metal primitive restart range computation should not be done unless primitive restart is enabled
         https://bugs.webkit.org/show_bug.cgi?id=227452
 

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h (279372 => 279373)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h	2021-06-29 13:52:16 UTC (rev 279372)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h	2021-06-29 13:53:43 UTC (rev 279373)
@@ -30,8 +30,11 @@
     uint32_t count;
     size_t offset;
 };
+
+// Inclusive range of consecutive primitive restart value indexes.
 struct IndexRange
 {
+    IndexRange(size_t begin, size_t end) : restartBegin(begin), restartEnd(end) {}
     size_t restartBegin;
     size_t restartEnd;
 };

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm (279372 => 279373)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm	2021-06-29 13:52:16 UTC (rev 279372)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm	2021-06-29 13:53:43 UTC (rev 279373)
@@ -412,30 +412,27 @@
 }
 
 template<typename T>
-static void calculateRestartRanges(ContextMtl* ctx, mtl::BufferRef idxBuffer, std::vector<IndexRange> * ranges)
+static std::vector<IndexRange> calculateRestartRanges(ContextMtl *ctx, mtl::BufferRef idxBuffer)
 {
-    ranges->clear();
-    T *bufferData = (T*)(idxBuffer->mapReadOnly(ctx));
-    const size_t numIndices = idxBuffer->size()/sizeof(T);
-    for(int i = 0; i < numIndices; i++)
+    std::vector<IndexRange> result;
+    const T *bufferData = reinterpret_cast<const T *>(idxBuffer->mapReadOnly(ctx));
+    const size_t numIndices = idxBuffer->size() / sizeof(T);
+    constexpr T restartMarker = std::numeric_limits<T>::max();
+    for (size_t i = 0; i < numIndices; ++i)
     {
-        T value = bufferData[i];
-        if(value == std::numeric_limits<T>::max())
+        // Find the start of the restart range, i.e. first index with value of restart marker.
+        if (bufferData[i] != restartMarker)
+            continue;
+        size_t restartBegin = i;
+        // Find the end of the restart range, i.e. last index with value of restart marker.
+        do
         {
-            IndexRange newRange;
-            newRange.restartBegin = i;
-            //Find the end of the restart range.
-            do
-            {
-                ++i;
-                if(i < numIndices)
-                    value = bufferData[i];
-            }while (i < numIndices && value == std::numeric_limits<T>::max());
-            newRange.restartEnd = i-1;
-            ranges->push_back(newRange);
-        }
+            ++i;
+        } while (i < numIndices && bufferData[i] == restartMarker);
+        result.emplace_back(restartBegin, i - 1);
     }
     idxBuffer->unmap(ctx);
+    return result;
 }
 
 const std::vector<IndexRange> & BufferMtl::getRestartIndices(ContextMtl * ctx, gl::DrawElementsType indexType)
@@ -442,20 +439,20 @@
 {
     if(mRestartIndicesDirty)
     {
+        std::vector<IndexRange>().swap(mRestartIndices);
         switch(indexType)
         {
             case gl::DrawElementsType::UnsignedByte:
-                calculateRestartRanges<uint8_t>(ctx, getCurrentBuffer(),&mRestartIndices);
+                mRestartIndices = calculateRestartRanges<uint8_t>(ctx, getCurrentBuffer());
                 break;
             case gl::DrawElementsType::UnsignedShort:
-                calculateRestartRanges<uint16_t>(ctx, getCurrentBuffer(),&mRestartIndices);
+                mRestartIndices = calculateRestartRanges<uint16_t>(ctx, getCurrentBuffer());
                 break;
             case gl::DrawElementsType::UnsignedInt:
-                calculateRestartRanges<uint32_t>(ctx, getCurrentBuffer(),&mRestartIndices);
+                mRestartIndices = calculateRestartRanges<uint32_t>(ctx, getCurrentBuffer());
                 break;
             default:
                 ASSERT(false);
-                
         }
         mRestartIndicesDirty = false;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to