| 1 |
From b6c7a5bc832b785a445ab89b3365ed80ab2e9d47 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Robert Phillips <[email protected]> |
| 3 |
Date: Wed, 17 Jun 2026 15:01:07 -0400 |
| 4 |
Subject: [PATCH] Reland "[Ganesh] TextureOp quad illegal memory access" |
| 5 |
|
| 6 |
This reverts commit 5e976cb2f034067e006ec8db2889791f0d4eb443. |
| 7 |
|
| 8 |
Reason for revert: The unit test was exceeding maxTextureSize on some devices |
| 9 |
|
| 10 |
Original change's description: |
| 11 |
> Revert "[Ganesh] TextureOp quad illegal memory access" |
| 12 |
> |
| 13 |
> This reverts commit 148b2b1948019f8f89435b4df7d598224a2ab0e1. |
| 14 |
> |
| 15 |
> Reason for revert: Crashing on some Android devices |
| 16 |
> |
| 17 |
> Failure Link: <LINK TO FAILURE> |
| 18 |
> |
| 19 |
> Original change's description: |
| 20 |
> > [Ganesh] TextureOp quad illegal memory access |
| 21 |
> > |
| 22 |
> > This CL fixes an overflow in the number of allowed quads in a TextureOp. It works on two fronts: |
| 23 |
> > It conservatively tracks the number of quads (incl. perspective) |
| 24 |
> > It prevents a fast path when there possibly might be an overflow. |
| 25 |
> > |
| 26 |
> > Bug: b/500172224 |
| 27 |
> > Change-Id: Icd92ed5c80d81cdbfea8d2463407cc48a0a32843 |
| 28 |
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1262376 |
| 29 |
> > Commit-Queue: Robert Phillips <[email protected]> |
| 30 |
> > Reviewed-by: Michael Ludwig <[email protected]> |
| 31 |
> |
| 32 |
> Bug: b/500172224 |
| 33 |
> No-Presubmit: true |
| 34 |
> No-Tree-Checks: true |
| 35 |
> No-Try: true |
| 36 |
> Change-Id: Ic4ea8537eb642131fbbcb14a485b11ce3ed4a636 |
| 37 |
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1268256 |
| 38 |
> Bot-Commit: [email protected] <[email protected]> |
| 39 |
> Auto-Submit: Robert Phillips <[email protected]> |
| 40 |
> Commit-Queue: [email protected] <[email protected]> |
| 41 |
|
| 42 |
Bug: https://issues.chromium.org/issues/500172224 |
| 43 |
Change-Id: If745b11a8e4b0dda535f114018009085ee2c0ce8 |
| 44 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1269156 |
| 45 |
Commit-Queue: Robert Phillips <[email protected]> |
| 46 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 47 |
--- |
| 48 |
gn/tests.gni | 1 + |
| 49 |
src/gpu/ganesh/Device_drawTexture.cpp | 22 +++-- |
| 50 |
src/gpu/ganesh/SurfaceDrawContext.cpp | 5 +- |
| 51 |
src/gpu/ganesh/SurfaceDrawContext.h | 3 +- |
| 52 |
src/gpu/ganesh/ops/TextureOp.cpp | 55 ++++++++--- |
| 53 |
src/gpu/ganesh/ops/TextureOp.h | 3 +- |
| 54 |
tests/BulkRectTest.cpp | 3 +- |
| 55 |
tests/crbug_500172224.cpp | 137 ++++++++++++++++++++++++++ |
| 56 |
8 files changed, 205 insertions(+), 24 deletions(-) |
| 57 |
create mode 100644 tests/crbug_500172224.cpp |
| 58 |
|
| 59 |
diff --git a/gn/tests.gni b/gn/tests.gni |
| 60 |
index da779fdd37..430705565a 100644 |
| 61 |
--- a/gn/tests.gni |
| 62 |
+++ b/gn/tests.gni |
| 63 |
@@ -523,6 +523,7 @@ ganesh_tests_sources = [ |
| 64 |
"$_tests/VkBackendSurfaceTest.cpp", |
| 65 |
"$_tests/VkWrapTests.cpp", |
| 66 |
"$_tests/WrappedSurfaceCopyOnWriteTest.cpp", |
| 67 |
+ "$_tests/crbug_500172224.cpp", |
| 68 |
] |
| 69 |
|
| 70 |
ganesh_gl_tests_sources = [ |
| 71 |
diff --git a/src/gpu/ganesh/Device_drawTexture.cpp b/src/gpu/ganesh/Device_drawTexture.cpp |
| 72 |
index 3864216932..103e684953 100644 |
| 73 |
--- a/src/gpu/ganesh/Device_drawTexture.cpp |
| 74 |
+++ b/src/gpu/ganesh/Device_drawTexture.cpp |
| 75 |
@@ -608,11 +608,11 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 76 |
SkBlendMode mode = paint.getBlendMode_or(SkBlendMode::kSrcOver); |
| 77 |
|
| 78 |
AutoTArray<GrTextureSetEntry> textures(count); |
| 79 |
- // We accumulate compatible proxies until we find an an incompatible one or reach the end and |
| 80 |
+ // We accumulate compatible proxies until we find an incompatible one or reach the end and |
| 81 |
// issue the accumulated 'n' draws starting at 'base'. 'p' represents the number of proxy |
| 82 |
// switches that occur within the 'n' entries. |
| 83 |
int base = 0, n = 0, p = 0; |
| 84 |
- auto draw = [&](int nextBase) { |
| 85 |
+ auto draw = [&](int nextBase, bool setMayHavePersp) { |
| 86 |
if (n > 0) { |
| 87 |
auto textureXform = GrColorSpaceXform::Make(set[base].fImage->imageInfo().colorInfo(), |
| 88 |
fSurfaceDrawContext->colorInfo()); |
| 89 |
@@ -625,12 +625,16 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 90 |
mode, |
| 91 |
constraint, |
| 92 |
this->localToDevice(), |
| 93 |
- std::move(textureXform)); |
| 94 |
+ std::move(textureXform), |
| 95 |
+ setMayHavePersp); |
| 96 |
} |
| 97 |
base = nextBase; |
| 98 |
n = 0; |
| 99 |
p = 0; |
| 100 |
}; |
| 101 |
+ // This is a conservatively computed property of the image set that disables a fast path |
| 102 |
+ // in TextureOp::AddTextureSetOps. |
| 103 |
+ bool setMayHavePersp = this->localToDevice().hasPerspective(); |
| 104 |
int dstClipIndex = 0; |
| 105 |
for (int i = 0; i < count; ++i) { |
| 106 |
SkASSERT(!set[i].fHasClip || dstClips); |
| 107 |
@@ -644,7 +648,7 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 108 |
// The default SkDevice implementation is based on drawImageRect which does not allow |
| 109 |
// non-sorted src rects. TODO: Decide this is OK or make sure we handle it. |
| 110 |
if (!set[i].fSrcRect.isSorted()) { |
| 111 |
- draw(i + 1); |
| 112 |
+ draw(i + 1, setMayHavePersp); |
| 113 |
continue; |
| 114 |
} |
| 115 |
|
| 116 |
@@ -668,7 +672,7 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 117 |
if (!view) { |
| 118 |
// This image can't go through the texture op, send through general image pipeline |
| 119 |
// after flushing current batch. |
| 120 |
- draw(i + 1); |
| 121 |
+ draw(i + 1, setMayHavePersp); |
| 122 |
SkTCopyOnFirstWrite<SkPaint> entryPaint(paint); |
| 123 |
if (set[i].fAlpha != 1.f) { |
| 124 |
auto paintAlpha = paint.getAlphaf(); |
| 125 |
@@ -689,6 +693,10 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 126 |
textures[i].fDstClipQuad = clip; |
| 127 |
textures[i].fPreViewMatrix = |
| 128 |
set[i].fMatrixIndex < 0 ? nullptr : preViewMatrices + set[i].fMatrixIndex; |
| 129 |
+ if (textures[i].fPreViewMatrix && textures[i].fPreViewMatrix->hasPerspective()) { |
| 130 |
+ // Once set, this flag stays on for the rest of the image set |
| 131 |
+ setMayHavePersp = true; |
| 132 |
+ } |
| 133 |
textures[i].fColor = texture_color(paint.getColor4f(), set[i].fAlpha, |
| 134 |
SkColorTypeToGrColorType(image->colorType()), |
| 135 |
fSurfaceDrawContext->colorInfo()); |
| 136 |
@@ -701,7 +709,7 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 137 |
textures[i].fProxyView.swizzle() != textures[base].fProxyView.swizzle() || |
| 138 |
set[i].fImage->alphaType() != set[base].fImage->alphaType() || |
| 139 |
!SkColorSpace::Equals(set[i].fImage->colorSpace(), set[base].fImage->colorSpace()))) { |
| 140 |
- draw(i); |
| 141 |
+ draw(i, setMayHavePersp); |
| 142 |
} |
| 143 |
// Whether or not we submitted a draw in the above if(), this ith entry is in the current |
| 144 |
// set being accumulated so increment n, and increment p if proxies are different. |
| 145 |
@@ -712,7 +720,7 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 146 |
++p; |
| 147 |
} |
| 148 |
} |
| 149 |
- draw(count); |
| 150 |
+ draw(count, setMayHavePersp); |
| 151 |
} |
| 152 |
|
| 153 |
bool Device::drawBlurredRRect(const SkRRect& rrect, const SkPaint& paint, float deviceSigma) { |
| 154 |
diff --git a/src/gpu/ganesh/SurfaceDrawContext.cpp b/src/gpu/ganesh/SurfaceDrawContext.cpp |
| 155 |
index 2ec011d254..a8339d276c 100644 |
| 156 |
--- a/src/gpu/ganesh/SurfaceDrawContext.cpp |
| 157 |
+++ b/src/gpu/ganesh/SurfaceDrawContext.cpp |
| 158 |
@@ -910,7 +910,8 @@ void SurfaceDrawContext::drawTextureSet(const GrClip* clip, |
| 159 |
SkBlendMode mode, |
| 160 |
SkCanvas::SrcRectConstraint constraint, |
| 161 |
const SkMatrix& viewMatrix, |
| 162 |
- sk_sp<GrColorSpaceXform> texXform) { |
| 163 |
+ sk_sp<GrColorSpaceXform> texXform, |
| 164 |
+ bool setMayHavePersp) { |
| 165 |
ASSERT_SINGLE_OWNER |
| 166 |
RETURN_IF_ABANDONED |
| 167 |
SkDEBUGCODE(this->validate();) |
| 168 |
@@ -924,7 +925,7 @@ void SurfaceDrawContext::drawTextureSet(const GrClip* clip, |
| 169 |
: ganesh::TextureOp::Saturate::kNo; |
| 170 |
ganesh::TextureOp::AddTextureSetOps(this, clip, fContext, set, cnt, proxyRunCnt, filter, mm, |
| 171 |
saturate, mode, aaType, constraint, viewMatrix, |
| 172 |
- std::move(texXform)); |
| 173 |
+ std::move(texXform), setMayHavePersp); |
| 174 |
} |
| 175 |
|
| 176 |
void SurfaceDrawContext::drawVertices(const GrClip* clip, |
| 177 |
diff --git a/src/gpu/ganesh/SurfaceDrawContext.h b/src/gpu/ganesh/SurfaceDrawContext.h |
| 178 |
index 16846874da..24e3838064 100644 |
| 179 |
--- a/src/gpu/ganesh/SurfaceDrawContext.h |
| 180 |
+++ b/src/gpu/ganesh/SurfaceDrawContext.h |
| 181 |
@@ -323,7 +323,8 @@ public: |
| 182 |
SkBlendMode mode, |
| 183 |
SkCanvas::SrcRectConstraint, |
| 184 |
const SkMatrix& viewMatrix, |
| 185 |
- sk_sp<GrColorSpaceXform> texXform); |
| 186 |
+ sk_sp<GrColorSpaceXform> texXform, |
| 187 |
+ bool setMayHavePersp); |
| 188 |
|
| 189 |
/** |
| 190 |
* Draw a roundrect using a paint. |
| 191 |
diff --git a/src/gpu/ganesh/ops/TextureOp.cpp b/src/gpu/ganesh/ops/TextureOp.cpp |
| 192 |
index 0c04a671e2..cf2287e345 100644 |
| 193 |
--- a/src/gpu/ganesh/ops/TextureOp.cpp |
| 194 |
+++ b/src/gpu/ganesh/ops/TextureOp.cpp |
| 195 |
@@ -1262,6 +1262,28 @@ public: |
| 196 |
, fTextureColorSpaceXform(textureColorSpaceXform) |
| 197 |
, fNumLeft(numEntries) {} |
| 198 |
|
| 199 |
+ int determineClumpSize(const GrTextureSetEntry set[], int quadLimit) const { |
| 200 |
+ bool hasPersp = fViewMatrix.hasPerspective(); |
| 201 |
+ |
| 202 |
+ int conservativeNumQuads = 0; |
| 203 |
+ for (int i = 0; i < fNumLeft; ++i) { |
| 204 |
+ int absIndex = this->baseIndex() + i; |
| 205 |
+ |
| 206 |
+ bool hasPrePersp = false; |
| 207 |
+ if (set[absIndex].fPreViewMatrix) { |
| 208 |
+ hasPrePersp = set[absIndex].fPreViewMatrix->hasPerspective(); |
| 209 |
+ } |
| 210 |
+ |
| 211 |
+ // A perspective quad could split into two quads |
| 212 |
+ conservativeNumQuads += hasPersp || hasPrePersp ? 2 : 1; |
| 213 |
+ if (conservativeNumQuads > quadLimit) { |
| 214 |
+ return i; |
| 215 |
+ } |
| 216 |
+ } |
| 217 |
+ |
| 218 |
+ return fNumLeft; |
| 219 |
+ } |
| 220 |
+ |
| 221 |
void createOp(GrTextureSetEntry set[], int clumpSize, GrAAType aaType) { |
| 222 |
|
| 223 |
int clumpProxyCount = proxy_run_count(&set[fNumClumped], clumpSize); |
| 224 |
@@ -1314,7 +1336,8 @@ void TextureOp::AddTextureSetOps(ganesh::SurfaceDrawContext* sdc, |
| 225 |
GrAAType aaType, |
| 226 |
SkCanvas::SrcRectConstraint constraint, |
| 227 |
const SkMatrix& viewMatrix, |
| 228 |
- sk_sp<GrColorSpaceXform> textureColorSpaceXform) { |
| 229 |
+ sk_sp<GrColorSpaceXform> textureColorSpaceXform, |
| 230 |
+ bool setMayHavePersp) { |
| 231 |
// Ensure that the index buffer limits are lower than the proxy and quad count limits of |
| 232 |
// the op's metadata so we don't need to worry about overflow. |
| 233 |
SkDEBUGCODE(TextureOpImpl::ValidateResourceLimits();) |
| 234 |
@@ -1358,8 +1381,8 @@ void TextureOp::AddTextureSetOps(ganesh::SurfaceDrawContext* sdc, |
| 235 |
|
| 236 |
// Second check if we can always just make a single op and avoid the extra iteration |
| 237 |
// needed to clump things together. |
| 238 |
- if (cnt <= std::min(GrResourceProvider::MaxNumNonAAQuads(), |
| 239 |
- GrResourceProvider::MaxNumAAQuads())) { |
| 240 |
+ if (!setMayHavePersp && cnt <= std::min(GrResourceProvider::MaxNumNonAAQuads(), |
| 241 |
+ GrResourceProvider::MaxNumAAQuads())) { |
| 242 |
auto op = TextureOpImpl::Make(context, set, cnt, proxyRunCnt, filter, mm, saturate, aaType, |
| 243 |
constraint, viewMatrix, std::move(textureColorSpaceXform)); |
| 244 |
sdc->addDrawOp(clip, std::move(op)); |
| 245 |
@@ -1373,7 +1396,7 @@ void TextureOp::AddTextureSetOps(ganesh::SurfaceDrawContext* sdc, |
| 246 |
if (aaType == GrAAType::kNone || aaType == GrAAType::kMSAA) { |
| 247 |
// Clump these into series of MaxNumNonAAQuads-sized GrTextureOps |
| 248 |
while (state.numLeft() > 0) { |
| 249 |
- int clumpSize = std::min(state.numLeft(), GrResourceProvider::MaxNumNonAAQuads()); |
| 250 |
+ int clumpSize = state.determineClumpSize(set, GrResourceProvider::MaxNumNonAAQuads()); |
| 251 |
|
| 252 |
state.createOp(set, clumpSize, aaType); |
| 253 |
} |
| 254 |
@@ -1383,25 +1406,34 @@ void TextureOp::AddTextureSetOps(ganesh::SurfaceDrawContext* sdc, |
| 255 |
// axis-aligned. |
| 256 |
SkASSERT(aaType == GrAAType::kCoverage); |
| 257 |
|
| 258 |
+ bool hasPersp = viewMatrix.hasPerspective(); |
| 259 |
+ |
| 260 |
while (state.numLeft() > 0) { |
| 261 |
GrAAType runningAA = GrAAType::kNone; |
| 262 |
bool clumped = false; |
| 263 |
|
| 264 |
+ int conservativeNumQuads = 0; |
| 265 |
+ |
| 266 |
for (int i = 0; i < state.numLeft(); ++i) { |
| 267 |
int absIndex = state.baseIndex() + i; |
| 268 |
|
| 269 |
+ bool hasPrePersp = false; |
| 270 |
+ if (set[absIndex].fPreViewMatrix) { |
| 271 |
+ hasPrePersp = set[absIndex].fPreViewMatrix->hasPerspective(); |
| 272 |
+ } |
| 273 |
+ |
| 274 |
+ // A perspective quad could split into two quads |
| 275 |
+ conservativeNumQuads += hasPersp || hasPrePersp ? 2 : 1; |
| 276 |
+ |
| 277 |
if (set[absIndex].fAAFlags != GrQuadAAFlags::kNone || |
| 278 |
runningAA == GrAAType::kCoverage) { |
| 279 |
|
| 280 |
- if (i >= GrResourceProvider::MaxNumAAQuads()) { |
| 281 |
+ if (conservativeNumQuads > GrResourceProvider::MaxNumAAQuads()) { |
| 282 |
// Here we either need to boost the AA type to kCoverage, but doing so with |
| 283 |
// all the accumulated quads would overflow, or we have a set of AA quads |
| 284 |
// that has just gotten too large. In either case, calve off the existing |
| 285 |
// quads as their own TextureOp. |
| 286 |
- state.createOp( |
| 287 |
- set, |
| 288 |
- runningAA == GrAAType::kNone ? i : GrResourceProvider::MaxNumAAQuads(), |
| 289 |
- runningAA); // maybe downgrading AA here |
| 290 |
+ state.createOp(set, i, runningAA); // maybe downgrading AA here |
| 291 |
clumped = true; |
| 292 |
break; |
| 293 |
} |
| 294 |
@@ -1409,11 +1441,10 @@ void TextureOp::AddTextureSetOps(ganesh::SurfaceDrawContext* sdc, |
| 295 |
runningAA = GrAAType::kCoverage; |
| 296 |
} else if (runningAA == GrAAType::kNone) { |
| 297 |
|
| 298 |
- if (i >= GrResourceProvider::MaxNumNonAAQuads()) { |
| 299 |
+ if (conservativeNumQuads > GrResourceProvider::MaxNumNonAAQuads()) { |
| 300 |
// Here we've found a consistent batch of non-AA quads that has gotten too |
| 301 |
// large. Calve it off as its own TextureOp. |
| 302 |
- state.createOp(set, GrResourceProvider::MaxNumNonAAQuads(), |
| 303 |
- GrAAType::kNone); // definitely downgrading AA here |
| 304 |
+ state.createOp(set, i, GrAAType::kNone); // definitely downgrading AA here |
| 305 |
clumped = true; |
| 306 |
break; |
| 307 |
} |
| 308 |
diff --git a/src/gpu/ganesh/ops/TextureOp.h b/src/gpu/ganesh/ops/TextureOp.h |
| 309 |
index d6629c2838..e8e148a4e2 100644 |
| 310 |
--- a/src/gpu/ganesh/ops/TextureOp.h |
| 311 |
+++ b/src/gpu/ganesh/ops/TextureOp.h |
| 312 |
@@ -87,7 +87,8 @@ public: |
| 313 |
GrAAType, |
| 314 |
SkCanvas::SrcRectConstraint, |
| 315 |
const SkMatrix& viewMatrix, |
| 316 |
- sk_sp<GrColorSpaceXform> textureXform); |
| 317 |
+ sk_sp<GrColorSpaceXform> textureXform, |
| 318 |
+ bool setMayHavePersp); |
| 319 |
|
| 320 |
#if defined(GPU_TEST_UTILS) |
| 321 |
static uint32_t ClassID(); |
| 322 |
-- |
| 323 |
2.53.0 |
| 324 |
|