Title: [279468] branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE
- Revision
- 279468
- Author
- rubent...@apple.com
- Date
- 2021-07-01 10:09:00 -0700 (Thu, 01 Jul 2021)
Log Message
Cherry-pick r279373. rdar://problem/80030448
ANGLE Metal primitive restart range computation could index with size_t
https://bugs.webkit.org/show_bug.cgi?id=227449
Patch by Kimmo Kinnunen <kkinnu...@apple.com> 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):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279373 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/ChangeLog (279467 => 279468)
--- branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/ChangeLog 2021-07-01 17:08:26 UTC (rev 279467)
+++ branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/ChangeLog 2021-07-01 17:09:00 UTC (rev 279468)
@@ -1,3 +1,70 @@
+2021-07-01 Ruben Turcios <rubent...@apple.com>
+
+ Cherry-pick r279373. rdar://problem/80030448
+
+ ANGLE Metal primitive restart range computation could index with size_t
+ https://bugs.webkit.org/show_bug.cgi?id=227449
+
+ Patch by Kimmo Kinnunen <kkinnu...@apple.com> 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):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@279373 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-06-29 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ 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-28 Kimmo Kinnunen <kkinnu...@apple.com>
iPhone 6S - iOS 15.0 - unable to retrieve WebGL2 context
Modified: branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h (279467 => 279468)
--- branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h 2021-07-01 17:08:26 UTC (rev 279467)
+++ branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.h 2021-07-01 17:09:00 UTC (rev 279468)
@@ -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: branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm (279467 => 279468)
--- branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm 2021-07-01 17:08:26 UTC (rev 279467)
+++ branches/safari-612.1.21-branch/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/BufferMtl.mm 2021-07-01 17:09:00 UTC (rev 279468)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes