Debian Codegraph @

debian/patches/CVE-2026-15766

raw
1 From ca9aecfbf4e27de60619a4db811575e3fd1e1af6 Mon Sep 17 00:00:00 2001
2 From: Greg Daniel <[email protected]>
3 Date: Mon, 29 Jun 2026 11:45:26 -0400
4 Subject: [PATCH] Check clipped renderpass bounds against cleared stencil area
5
6 * If only a portion of the stencil attachment is cleared, we should not mark the entire attachment as cleared. This CL makes it such that we check which area has most recently been cleared to make an informed decision.
7
8 Bug: https://issues.chromium.org/issues/514010477
9 Change-Id: I3800ca3125f25341dffd818f6c557692020027be
10 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1255256
11 Reviewed-by: Robert Phillips <[email protected]>
12 Commit-Queue: Greg Daniel <[email protected]>
13 ---
14 src/gpu/ganesh/GrAttachment.h | 11 ++++--
15 src/gpu/ganesh/GrCaps.cpp | 7 +++-
16 src/gpu/ganesh/GrCaps.h | 16 ++++++---
17 src/gpu/ganesh/gl/GrGLCaps.cpp | 13 +++++--
18 src/gpu/ganesh/ops/OpsTask.cpp | 66 +++++++++++++++++++++++++---------
19 src/gpu/ganesh/vk/GrVkCaps.cpp | 15 +++++---
20 6 files changed, 96 insertions(+), 32 deletions(-)
21
22 --- a/src/gpu/ganesh/GrAttachment.h
23 +++ b/src/gpu/ganesh/GrAttachment.h
24 @@ -53,8 +53,11 @@
25
26 skgpu::Mipmapped mipmapped() const { return fMipmapped; }
27
28 - bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; }
29 - void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; }
30 + SkIRect clearedArea() const { return fClearedArea; }
31 + bool hasAreaBeenCleared(SkIRect attachmentArea) const {
32 + return fClearedArea.contains(attachmentArea);
33 + }
34 + void markAreaCleared(SkIRect area) { fClearedArea = area; }
35
36 // This unique key is used for attachments of the same dimensions, usage, and sample cnt which
37 // are shared between multiple render targets at the same time. Only one usage flag may be
38 @@ -117,7 +120,9 @@
39 UsageFlags fSupportedUsages;
40 int fSampleCnt;
41 skgpu::Mipmapped fMipmapped;
42 - bool fHasPerformedInitialClear = false;
43 + // Track which area of the attachment has already been cleared to cut down on unnecessary clear
44 + // operations, which can be more expensive on desktop GPUs than loads.
45 + SkIRect fClearedArea = SkIRect::MakeEmpty();
46 GrMemoryless fMemoryless;
47
48 using INHERITED = GrSurface;
49 --- a/src/gpu/ganesh/GrCaps.cpp
50 +++ b/src/gpu/ganesh/GrCaps.cpp
51 @@ -43,6 +43,8 @@
52 fUsePrimitiveRestart = false;
53 fPreferClientSideDynamicBuffers = false;
54 fPreferFullscreenClears = false;
55 + fDiscardStencilValuesAfterRenderPass = false;
56 + fClearsAreFasterThanLoads = false;
57 fTwoSidedStencilRefsAndMasksMustMatch = false;
58 fMustClearUploadedBufferData = false;
59 fShouldInitializeTextures = false;
60 @@ -227,7 +229,10 @@
61 writer->appendBool("MSAA Resolves Automatically", fMSAAResolvesAutomatically);
62 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
63 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
64 - writer->appendBool("Prefer fullscreen clears (and stencil discard)", fPreferFullscreenClears);
65 + writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
66 + writer->appendBool("Discard stencil values after renderpass",
67 + fDiscardStencilValuesAfterRenderPass);
68 + writer->appendBool("Clears are faster than loads", fClearsAreFasterThanLoads);
69 writer->appendBool("Two-sided Stencil Refs And Masks Must Match",
70 fTwoSidedStencilRefsAndMasksMustMatch);
71 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
72 --- a/src/gpu/ganesh/GrCaps.h
73 +++ b/src/gpu/ganesh/GrCaps.h
74 @@ -114,10 +114,11 @@
75
76 bool preferClientSideDynamicBuffers() const { return fPreferClientSideDynamicBuffers; }
77
78 - // On tilers, an initial fullscreen clear is an OPTIMIZATION. It allows the hardware to
79 - // initialize each tile with a constant value rather than loading each pixel from memory.
80 + // The following 3 methods provide information that enables performance optimizations for tiler
81 + // GPUs. Full clear operations (followed by discarding the content when finished) are more
82 + // performant than load operations on these GPUs as they enable the hardware to initialize each
83 + // tile with a constant value as opposed to loading each pixel from memory.
84 bool preferFullscreenClears() const { return fPreferFullscreenClears; }
85 -
86 // Should we discard stencil values after a render pass? (Tilers get better performance if we
87 // always load stencil buffers with a "clear" op, and then discard the content when finished.)
88 bool discardStencilValuesAfterRenderPass() const {
89 @@ -126,10 +127,15 @@
90 #if 0
91 // This method is actually just a duplicate of preferFullscreenClears(), with a descriptive
92 // name for the sake of readability.
93 - return this->preferFullscreenClears();
94 + return fDiscardStencilValuesAfterRenderPass;
95 #endif
96 }
97
98 + // Returns whether clearing an attachment is faster than loading the attachment. This is useful
99 + // when you know the values are already cleared so it doesn't matter if we load or clear at the
100 + // start of a render pass.
101 + bool clearsAreFasterThanLoads() const { return fClearsAreFasterThanLoads; }
102 +
103 // D3D does not allow the refs or masks to differ on a two-sided stencil draw.
104 bool twoSidedStencilRefsAndMasksMustMatch() const {
105 return fTwoSidedStencilRefsAndMasksMustMatch;
106 @@ -605,6 +611,8 @@
107 bool fUsePrimitiveRestart : 1;
108 bool fPreferClientSideDynamicBuffers : 1;
109 bool fPreferFullscreenClears : 1;
110 + bool fDiscardStencilValuesAfterRenderPass : 1;
111 + bool fClearsAreFasterThanLoads : 1;
112 bool fTwoSidedStencilRefsAndMasksMustMatch : 1;
113 bool fMustClearUploadedBufferData : 1;
114 bool fBuffersAreInitiallyZero : 1;
115 --- a/src/gpu/ganesh/gl/GrGLCaps.cpp
116 +++ b/src/gpu/ganesh/gl/GrGLCaps.cpp
117 @@ -118,6 +118,13 @@
118 return backend == GrGLANGLEBackend::kMetal;
119 }
120
121 +namespace {
122 +bool is_tiler_gpu(GrGLVendor vendor) {
123 + return vendor == GrGLVendor::kARM ||
124 + vendor == GrGLVendor::kImagination ||
125 + vendor == GrGLVendor::kQualcomm;
126 +}
127 +} // anonymous namespace
128 void GrGLCaps::init(const GrContextOptions& contextOptions,
129 const GrGLContextInfo& ctxInfo,
130 const GrGLInterface* gli) {
131 @@ -221,10 +228,10 @@
132 }
133 }
134
135 - if (ctxInfo.vendor() == GrGLVendor::kARM ||
136 - ctxInfo.vendor() == GrGLVendor::kImagination ||
137 - ctxInfo.vendor() == GrGLVendor::kQualcomm ) {
138 + if (is_tiler_gpu(ctxInfo.vendor())) {
139 fPreferFullscreenClears = true;
140 + fDiscardStencilValuesAfterRenderPass = true;
141 + fClearsAreFasterThanLoads = true;
142 }
143
144 if (GR_IS_GR_GL(standard)) {
145 --- a/src/gpu/ganesh/ops/OpsTask.cpp
146 +++ b/src/gpu/ganesh/ops/OpsTask.cpp
147 @@ -586,35 +586,67 @@
148 }
149
150 GrLoadOp stencilLoadOp;
151 + // Determine whether the stencil attachment's cleared area should be updated.
152 + bool updateClearedStencilArea = false;
153 + SkIRect boundsRequiredByStencil = fClippedContentBounds;
154 switch (fInitialStencilContent) {
155 case StencilContent::kDontCare:
156 - if (stencil && !caps.performStencilClearsAsDraws()) {
157 - // This OpTask has a stencil, doesn't care about its contents,
158 - // isn't clearing it with draws, and is going to store the result.
159 - // In that case, we proactively clear it so that uninitialized data won't
160 - // creep into the stencil buffer.
161 - stencilLoadOp = GrLoadOp::kClear;
162 - } else {
163 + if (!stencil || caps.performStencilClearsAsDraws()) {
164 // This should only intentionally happen for the AtlasRenderTask which
165 // immediately inserts a clear.
166 stencilLoadOp = GrLoadOp::kDiscard;
167 + break;
168 }
169 break;
170 + // This OpTask has a stencil, doesn't care about its contents, isn't clearing it with
171 + // draws, and is going to store the result. In that case, we fallthrough to clear it so
172 + // that uninitialized data won't creep into the stencil buffer.
173 + [[fallthrough]];
174 case StencilContent::kUserBitsCleared:
175 SkASSERT(!caps.performStencilClearsAsDraws());
176 SkASSERT(stencil);
177 + // Based upon Caps, determine which stencil load operation to use and perform any
178 + // necessary updates to the renderpass's bounds and the stencil's cleared area.
179 +
180 + // If the user bits are meant to be cleared we either do that via an initial clear the
181 + // first time the area of the stencil is used, or we assume previous draws left the
182 + // stencil cleared so we just load the current values. However, on some devices it is
183 + // faster to just clear the stencil each time instead of doing a load.
184 + //
185 + // Since we'll never end up loading the stencil in this case there is no reason for us
186 + // to do the clear rect tracking below, so we just break.
187 + if (caps.clearsAreFasterThanLoads()) {
188 + stencilLoadOp = GrLoadOp::kClear;
189 + break;
190 + }
191 + // If stencil values are discarded after every renderpass, then we do not need to track
192 + // which portion of the stencil attachment has already been cleared.
193 if (caps.discardStencilValuesAfterRenderPass()) {
194 - // Always clear the stencil if it is being discarded after render passes. This is
195 - // also an optimization because we are on a tiler and it avoids loading the values
196 - // from memory.
197 stencilLoadOp = GrLoadOp::kClear;
198 break;
199 }
200 - if (!stencil->hasPerformedInitialClear()) {
201 +
202 + // If the area of the stencil attachment corresponding to this renderpass's
203 + // boundsRequiredByStencil has not already been cleared, calculate new, expanded
204 + // renderpass bounds by joining boundsRequiredByStencil with the cleared stencil area.
205 + // Using this joint area simplifies tracking of cleared areas on the stencil attachment.
206 + if (!stencil->hasAreaBeenCleared(boundsRequiredByStencil)) {
207 stencilLoadOp = GrLoadOp::kClear;
208 - stencil->markHasPerformedInitialClear();
209 + if (!stencil->clearedArea().isEmpty()) {
210 + boundsRequiredByStencil.join(stencil->clearedArea());
211 + // We need to also intersect the bounds with the color attachment's bounds since
212 + // the stencil may be bigger. This could mean that we end up "forgetting" we
213 + // cleared the user bits in the portion of the stencil that doesn't overlap with
214 + // the color attachment - but that shouldn't have a large performance impact if
215 + // we later on need to reclear that area.
216 + boundsRequiredByStencil.intersect(
217 + SkIRect::MakeSize(renderTarget->dimensions()));
218 + }
219 + // We should update the stencil's cleared area if renderpass creation succeeds.
220 + updateClearedStencilArea = true;
221 break;
222 }
223 +
224 // SurfaceDrawContexts are required to leave the user stencil bits in a cleared state
225 // once finished, meaning the stencil values will always remain cleared after the
226 // initial clear. Just fall through to reloading the existing (cleared) stencil values
227 @@ -624,6 +656,8 @@
228 SkASSERT(stencil);
229 stencilLoadOp = GrLoadOp::kLoad;
230 break;
231 + default:
232 + SkUNREACHABLE;
233 }
234
235 // NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split
236 @@ -643,7 +677,7 @@
237 fUsesMSAASurface,
238 stencil,
239 fTargetOrigin,
240 - fClippedContentBounds,
241 + boundsRequiredByStencil,
242 fColorLoadOp,
243 fLoadClearColor,
244 stencilLoadOp,
245 @@ -654,6 +688,9 @@
246 if (!renderPass) {
247 return false;
248 }
249 + if (updateClearedStencilArea) {
250 + stencil->markAreaCleared(boundsRequiredByStencil);
251 + }
252
253 #if defined(SK_DEBUG)
254 if (stencilLoadOp == GrLoadOp::kDiscard) {
255 --- a/src/gpu/ganesh/vk/GrVkCaps.cpp
256 +++ b/src/gpu/ganesh/vk/GrVkCaps.cpp
257 @@ -302,6 +302,13 @@
258
259 }
260
261 +namespace {
262 +bool is_tiler_gpu(uint32_t vendorId) {
263 + return vendorId == skgpu::kARM_VkVendor ||
264 + vendorId == skgpu::kQualcomm_VkVendor ||
265 + vendorId == skgpu::kImagination_VkVendor;
266 +}
267 +} // anonymous namespace
268 void GrVkCaps::init(const GrContextOptions& contextOptions,
269 const skgpu::VulkanInterface* vkInterface,
270 VkPhysicalDevice physDev,
271 @@ -415,12 +422,12 @@
272 this->initGrCaps(vkInterface, physDev, properties, memoryProperties, features, extensions);
273 this->initShaderCaps(properties, features);
274
275 - if (skgpu::kQualcomm_VkVendor == properties.vendorID) {
276 - // A "clear" load for atlases runs faster on QC than a "discard" load followed by a
277 + if (is_tiler_gpu(properties.vendorID)) {
278 + // A "clear" load for atlases runs faster on tiler GPUs than a "discard" load followed by a
279 // scissored clear.
280 - // On NVIDIA and Intel, the discard load followed by clear is faster.
281 - // TODO: Evaluate on ARM, Imagination, and ATI.
282 fPreferFullscreenClears = true;
283 + fDiscardStencilValuesAfterRenderPass = true;
284 + fClearsAreFasterThanLoads = true;
285 }
286
287 if (properties.vendorID == skgpu::kNvidia_VkVendor ||