| 1 |
/* |
| 2 |
* Copyright 2019 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
#include "src/gpu/ganesh/ops/OpsTask.h" |
| 8 |
|
| 9 |
#include "include/core/SkSize.h" |
| 10 |
#include "include/core/SkString.h" |
| 11 |
#include "include/gpu/GpuTypes.h" |
| 12 |
#include "include/gpu/ganesh/GrRecordingContext.h" |
| 13 |
#include "include/private/base/SkPoint_impl.h" |
| 14 |
#include "src/base/SkArenaAlloc.h" |
| 15 |
#include "src/base/SkScopeExit.h" |
| 16 |
#include "src/core/SkRectPriv.h" |
| 17 |
#include "src/core/SkStringUtils.h" |
| 18 |
#include "src/core/SkTraceEvent.h" |
| 19 |
#include "src/gpu/ganesh/GrAppliedClip.h" |
| 20 |
#include "src/gpu/ganesh/GrAttachment.h" |
| 21 |
#include "src/gpu/ganesh/GrAuditTrail.h" |
| 22 |
#include "src/gpu/ganesh/GrCaps.h" |
| 23 |
#include "src/gpu/ganesh/GrGpu.h" |
| 24 |
#include "src/gpu/ganesh/GrNativeRect.h" |
| 25 |
#include "src/gpu/ganesh/GrOpFlushState.h" |
| 26 |
#include "src/gpu/ganesh/GrOpsRenderPass.h" |
| 27 |
#include "src/gpu/ganesh/GrRecordingContextPriv.h" |
| 28 |
#include "src/gpu/ganesh/GrRenderTarget.h" |
| 29 |
#include "src/gpu/ganesh/GrRenderTargetProxy.h" |
| 30 |
#include "src/gpu/ganesh/GrResourceAllocator.h" |
| 31 |
#include "src/gpu/ganesh/GrResourceProvider.h" |
| 32 |
#include "src/gpu/ganesh/GrSurfaceProxyView.h" |
| 33 |
#include "src/gpu/ganesh/GrTextureProxy.h" |
| 34 |
#include "src/gpu/ganesh/GrTextureResolveManager.h" |
| 35 |
#include "src/gpu/ganesh/geometry/GrRect.h" |
| 36 |
|
| 37 |
#include <algorithm> |
| 38 |
#include <cstddef> |
| 39 |
#include <cstdint> |
| 40 |
#include <functional> |
| 41 |
#include <memory> |
| 42 |
#include <utility> |
| 43 |
|
| 44 |
class GrDrawingManager; |
| 45 |
enum GrSurfaceOrigin : int; |
| 46 |
|
| 47 |
using namespace skia_private; |
| 48 |
|
| 49 |
//////////////////////////////////////////////////////////////////////////////// |
| 50 |
|
| 51 |
namespace { |
| 52 |
|
| 53 |
// Experimentally we have found that most combining occurs within the first 10 comparisons. |
| 54 |
static const int kMaxOpMergeDistance = 10; |
| 55 |
static const int kMaxOpChainDistance = 10; |
| 56 |
|
| 57 |
//////////////////////////////////////////////////////////////////////////////// |
| 58 |
|
| 59 |
inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
| 60 |
|
| 61 |
GrOpsRenderPass* create_render_pass(GrGpu* gpu, |
| 62 |
GrRenderTarget* rt, |
| 63 |
bool useMSAASurface, |
| 64 |
GrAttachment* stencil, |
| 65 |
GrSurfaceOrigin origin, |
| 66 |
const SkIRect& bounds, |
| 67 |
GrLoadOp colorLoadOp, |
| 68 |
const std::array<float, 4>& loadClearColor, |
| 69 |
GrLoadOp stencilLoadOp, |
| 70 |
GrStoreOp stencilStoreOp, |
| 71 |
const TArray<GrSurfaceProxy*, true>& sampledProxies, |
| 72 |
GrXferBarrierFlags renderPassXferBarriers) { |
| 73 |
const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo { |
| 74 |
colorLoadOp, |
| 75 |
GrStoreOp::kStore, |
| 76 |
loadClearColor |
| 77 |
}; |
| 78 |
|
| 79 |
// TODO: |
| 80 |
// We would like to (at this level) only ever clear & discard. We would need |
| 81 |
// to stop splitting up higher level OpsTasks for copyOps to achieve that. |
| 82 |
// Note: we would still need SB loads and stores but they would happen at a |
| 83 |
// lower level (inside the VK command buffer). |
| 84 |
const GrOpsRenderPass::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
| 85 |
stencilLoadOp, |
| 86 |
stencilStoreOp, |
| 87 |
}; |
| 88 |
|
| 89 |
return gpu->getOpsRenderPass(rt, useMSAASurface, stencil, origin, bounds, kColorLoadStoreInfo, |
| 90 |
stencilLoadAndStoreInfo, sampledProxies, renderPassXferBarriers); |
| 91 |
} |
| 92 |
|
| 93 |
} // anonymous namespace |
| 94 |
|
| 95 |
//////////////////////////////////////////////////////////////////////////////// |
| 96 |
|
| 97 |
namespace skgpu::ganesh { |
| 98 |
|
| 99 |
inline OpsTask::OpChain::List::List(GrOp::Owner op) |
| 100 |
: fHead(std::move(op)), fTail(fHead.get()) { |
| 101 |
this->validate(); |
| 102 |
} |
| 103 |
|
| 104 |
inline OpsTask::OpChain::List::List(List&& that) { *this = std::move(that); } |
| 105 |
|
| 106 |
inline OpsTask::OpChain::List& OpsTask::OpChain::List::operator=(List&& that) { |
| 107 |
fHead = std::move(that.fHead); |
| 108 |
fTail = that.fTail; |
| 109 |
that.fTail = nullptr; |
| 110 |
this->validate(); |
| 111 |
return *this; |
| 112 |
} |
| 113 |
|
| 114 |
inline GrOp::Owner OpsTask::OpChain::List::popHead() { |
| 115 |
SkASSERT(fHead); |
| 116 |
auto temp = fHead->cutChain(); |
| 117 |
std::swap(temp, fHead); |
| 118 |
if (!fHead) { |
| 119 |
SkASSERT(fTail == temp.get()); |
| 120 |
fTail = nullptr; |
| 121 |
} |
| 122 |
return temp; |
| 123 |
} |
| 124 |
|
| 125 |
inline GrOp::Owner OpsTask::OpChain::List::removeOp(GrOp* op) { |
| 126 |
#ifdef SK_DEBUG |
| 127 |
auto head = op; |
| 128 |
while (head->prevInChain()) { head = head->prevInChain(); } |
| 129 |
SkASSERT(head == fHead.get()); |
| 130 |
#endif |
| 131 |
auto prev = op->prevInChain(); |
| 132 |
if (!prev) { |
| 133 |
SkASSERT(op == fHead.get()); |
| 134 |
return this->popHead(); |
| 135 |
} |
| 136 |
auto temp = prev->cutChain(); |
| 137 |
if (auto next = temp->cutChain()) { |
| 138 |
prev->chainConcat(std::move(next)); |
| 139 |
} else { |
| 140 |
SkASSERT(fTail == op); |
| 141 |
fTail = prev; |
| 142 |
} |
| 143 |
this->validate(); |
| 144 |
return temp; |
| 145 |
} |
| 146 |
|
| 147 |
inline void OpsTask::OpChain::List::pushHead(GrOp::Owner op) { |
| 148 |
SkASSERT(op); |
| 149 |
SkASSERT(op->isChainHead()); |
| 150 |
SkASSERT(op->isChainTail()); |
| 151 |
if (fHead) { |
| 152 |
op->chainConcat(std::move(fHead)); |
| 153 |
fHead = std::move(op); |
| 154 |
} else { |
| 155 |
fHead = std::move(op); |
| 156 |
fTail = fHead.get(); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
inline void OpsTask::OpChain::List::pushTail(GrOp::Owner op) { |
| 161 |
SkASSERT(op->isChainTail()); |
| 162 |
fTail->chainConcat(std::move(op)); |
| 163 |
fTail = fTail->nextInChain(); |
| 164 |
} |
| 165 |
|
| 166 |
inline void OpsTask::OpChain::List::validate() const { |
| 167 |
#ifdef SK_DEBUG |
| 168 |
if (fHead) { |
| 169 |
SkASSERT(fTail); |
| 170 |
fHead->validateChain(fTail); |
| 171 |
} |
| 172 |
#endif |
| 173 |
} |
| 174 |
|
| 175 |
//////////////////////////////////////////////////////////////////////////////// |
| 176 |
|
| 177 |
OpsTask::OpChain::OpChain(GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, |
| 178 |
GrAppliedClip* appliedClip, const GrDstProxyView* dstProxyView) |
| 179 |
: fList{std::move(op)} |
| 180 |
, fProcessorAnalysis(processorAnalysis) |
| 181 |
, fAppliedClip(appliedClip) { |
| 182 |
if (fProcessorAnalysis.requiresDstTexture()) { |
| 183 |
SkASSERT(dstProxyView && dstProxyView->proxy()); |
| 184 |
fDstProxyView = *dstProxyView; |
| 185 |
} |
| 186 |
fBounds = fList.head()->bounds(); |
| 187 |
} |
| 188 |
|
| 189 |
void OpsTask::OpChain::visitProxies(const GrVisitProxyFunc& func) const { |
| 190 |
if (fList.empty()) { |
| 191 |
return; |
| 192 |
} |
| 193 |
for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 194 |
op.visitProxies(func); |
| 195 |
} |
| 196 |
if (fDstProxyView.proxy()) { |
| 197 |
func(fDstProxyView.proxy(), skgpu::Mipmapped::kNo); |
| 198 |
} |
| 199 |
if (fAppliedClip) { |
| 200 |
fAppliedClip->visitProxies(func); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
void OpsTask::OpChain::deleteOps() { |
| 205 |
while (!fList.empty()) { |
| 206 |
// Since the value goes out of scope immediately, the GrOp::Owner deletes the op. |
| 207 |
fList.popHead(); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
// Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that |
| 212 |
// the two chains are chainable. Returns the new chain. |
| 213 |
OpsTask::OpChain::List OpsTask::OpChain::DoConcat(List chainA, List chainB, const GrCaps& caps, |
| 214 |
SkArenaAlloc* opsTaskArena, |
| 215 |
GrAuditTrail* auditTrail) { |
| 216 |
// We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting |
| 217 |
// at chain a's tail and working toward the head. We produce one of the following outcomes: |
| 218 |
// 1) b's head is merged into an op in a. |
| 219 |
// 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.) |
| 220 |
// 3) b's head is popped from chain a and added at the tail of a. |
| 221 |
// After result 3 we don't want to attempt to merge the next head of b with the new tail of a, |
| 222 |
// as we assume merges were already attempted when chain b was created. So we keep track of the |
| 223 |
// original tail of a and start our iteration of a there. We also track the bounds of the nodes |
| 224 |
// appended to chain a that will be skipped for bounds testing. If the original tail of a is |
| 225 |
// merged into an op in b (case 2) then we advance the "original tail" towards the head of a. |
| 226 |
GrOp* origATail = chainA.tail(); |
| 227 |
SkRect skipBounds = SkRectPriv::MakeLargestInverted(); |
| 228 |
do { |
| 229 |
int numMergeChecks = 0; |
| 230 |
bool merged = false; |
| 231 |
bool noSkip = (origATail == chainA.tail()); |
| 232 |
SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted())); |
| 233 |
bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds); |
| 234 |
SkRect forwardMergeBounds = skipBounds; |
| 235 |
GrOp* a = origATail; |
| 236 |
while (a) { |
| 237 |
bool canForwardMerge = |
| 238 |
(a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds); |
| 239 |
if (canForwardMerge || canBackwardMerge) { |
| 240 |
auto result = a->combineIfPossible(chainB.head(), opsTaskArena, caps); |
| 241 |
SkASSERT(result != GrOp::CombineResult::kCannotCombine); |
| 242 |
merged = (result == GrOp::CombineResult::kMerged); |
| 243 |
GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
| 244 |
chainB.head()->name(), chainB.head()->uniqueID(), a->name(), |
| 245 |
a->uniqueID()); |
| 246 |
} |
| 247 |
if (merged) { |
| 248 |
GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head()); |
| 249 |
if (canBackwardMerge) { |
| 250 |
// The GrOp::Owner releases the op. |
| 251 |
chainB.popHead(); |
| 252 |
} else { |
| 253 |
// We merged the contents of b's head into a. We will replace b's head with a in |
| 254 |
// chain b. |
| 255 |
SkASSERT(canForwardMerge); |
| 256 |
if (a == origATail) { |
| 257 |
origATail = a->prevInChain(); |
| 258 |
} |
| 259 |
GrOp::Owner detachedA = chainA.removeOp(a); |
| 260 |
// The GrOp::Owner releases the op. |
| 261 |
chainB.popHead(); |
| 262 |
chainB.pushHead(std::move(detachedA)); |
| 263 |
if (chainA.empty()) { |
| 264 |
// We merged all the nodes in chain a to chain b. |
| 265 |
return chainB; |
| 266 |
} |
| 267 |
} |
| 268 |
break; |
| 269 |
} else { |
| 270 |
if (++numMergeChecks == kMaxOpMergeDistance) { |
| 271 |
break; |
| 272 |
} |
| 273 |
forwardMergeBounds.joinNonEmptyArg(a->bounds()); |
| 274 |
canBackwardMerge = |
| 275 |
canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds()); |
| 276 |
a = a->prevInChain(); |
| 277 |
} |
| 278 |
} |
| 279 |
// If we weren't able to merge b's head then pop b's head from chain b and make it the new |
| 280 |
// tail of a. |
| 281 |
if (!merged) { |
| 282 |
chainA.pushTail(chainB.popHead()); |
| 283 |
skipBounds.joinNonEmptyArg(chainA.tail()->bounds()); |
| 284 |
} |
| 285 |
} while (!chainB.empty()); |
| 286 |
return chainA; |
| 287 |
} |
| 288 |
|
| 289 |
// Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns |
| 290 |
// whether the operation succeeded. On success, the provided list will be returned empty. |
| 291 |
bool OpsTask::OpChain::tryConcat( |
| 292 |
List* list, GrProcessorSet::Analysis processorAnalysis, const GrDstProxyView& dstProxyView, |
| 293 |
const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps, |
| 294 |
SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) { |
| 295 |
SkASSERT(!fList.empty()); |
| 296 |
SkASSERT(!list->empty()); |
| 297 |
SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxyView.proxy())); |
| 298 |
SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxyView.proxy())); |
| 299 |
// All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug. |
| 300 |
if (fList.head()->classID() != list->head()->classID() || |
| 301 |
SkToBool(fAppliedClip) != SkToBool(appliedClip) || |
| 302 |
(fAppliedClip && *fAppliedClip != *appliedClip) || |
| 303 |
(fProcessorAnalysis.requiresNonOverlappingDraws() != |
| 304 |
processorAnalysis.requiresNonOverlappingDraws()) || |
| 305 |
(fProcessorAnalysis.requiresNonOverlappingDraws() && |
| 306 |
// Non-overlaping draws are only required when Ganesh will either insert a barrier, |
| 307 |
// or read back a new dst texture between draws. In either case, we can neither |
| 308 |
// chain nor combine overlapping Ops. |
| 309 |
GrRectsTouchOrOverlap(fBounds, bounds)) || |
| 310 |
(fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) || |
| 311 |
(fProcessorAnalysis.requiresDstTexture() && fDstProxyView != dstProxyView)) { |
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
SkDEBUGCODE(bool first = true;) |
| 316 |
do { |
| 317 |
switch (fList.tail()->combineIfPossible(list->head(), opsTaskArena, caps)) |
| 318 |
{ |
| 319 |
case GrOp::CombineResult::kCannotCombine: |
| 320 |
// If an op supports chaining then it is required that chaining is transitive and |
| 321 |
// that if any two ops in two different chains can merge then the two chains |
| 322 |
// may also be chained together. Thus, we should only hit this on the first |
| 323 |
// iteration. |
| 324 |
SkASSERT(first); |
| 325 |
return false; |
| 326 |
case GrOp::CombineResult::kMayChain: |
| 327 |
fList = DoConcat(std::move(fList), std::exchange(*list, List()), caps, opsTaskArena, |
| 328 |
auditTrail); |
| 329 |
// The above exchange cleared out 'list'. The list needs to be empty now for the |
| 330 |
// loop to terminate. |
| 331 |
SkASSERT(list->empty()); |
| 332 |
break; |
| 333 |
case GrOp::CombineResult::kMerged: { |
| 334 |
GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
| 335 |
list->tail()->name(), list->tail()->uniqueID(), list->head()->name(), |
| 336 |
list->head()->uniqueID()); |
| 337 |
GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head()); |
| 338 |
// The GrOp::Owner releases the op. |
| 339 |
list->popHead(); |
| 340 |
break; |
| 341 |
} |
| 342 |
} |
| 343 |
SkDEBUGCODE(first = false); |
| 344 |
} while (!list->empty()); |
| 345 |
|
| 346 |
// The new ops were successfully merged and/or chained onto our own. |
| 347 |
fBounds.joinPossiblyEmptyRect(bounds); |
| 348 |
return true; |
| 349 |
} |
| 350 |
|
| 351 |
bool OpsTask::OpChain::prependChain(OpChain* that, const GrCaps& caps, SkArenaAlloc* opsTaskArena, |
| 352 |
GrAuditTrail* auditTrail) { |
| 353 |
if (!that->tryConcat(&fList, fProcessorAnalysis, fDstProxyView, fAppliedClip, fBounds, caps, |
| 354 |
opsTaskArena, auditTrail)) { |
| 355 |
this->validate(); |
| 356 |
// append failed |
| 357 |
return false; |
| 358 |
} |
| 359 |
|
| 360 |
// 'that' owns the combined chain. Move it into 'this'. |
| 361 |
SkASSERT(fList.empty()); |
| 362 |
fList = std::move(that->fList); |
| 363 |
fBounds = that->fBounds; |
| 364 |
|
| 365 |
that->fDstProxyView.setProxyView({}); |
| 366 |
if (that->fAppliedClip && that->fAppliedClip->hasCoverageFragmentProcessor()) { |
| 367 |
// Obliterates the processor. |
| 368 |
that->fAppliedClip->detachCoverageFragmentProcessor(); |
| 369 |
} |
| 370 |
this->validate(); |
| 371 |
return true; |
| 372 |
} |
| 373 |
|
| 374 |
GrOp::Owner OpsTask::OpChain::appendOp( |
| 375 |
GrOp::Owner op, GrProcessorSet::Analysis processorAnalysis, |
| 376 |
const GrDstProxyView* dstProxyView, const GrAppliedClip* appliedClip, const GrCaps& caps, |
| 377 |
SkArenaAlloc* opsTaskArena, GrAuditTrail* auditTrail) { |
| 378 |
const GrDstProxyView noDstProxyView; |
| 379 |
if (!dstProxyView) { |
| 380 |
dstProxyView = &noDstProxyView; |
| 381 |
} |
| 382 |
SkASSERT(op->isChainHead() && op->isChainTail()); |
| 383 |
SkRect opBounds = op->bounds(); |
| 384 |
List chain(std::move(op)); |
| 385 |
if (!this->tryConcat(&chain, processorAnalysis, *dstProxyView, appliedClip, opBounds, caps, |
| 386 |
opsTaskArena, auditTrail)) { |
| 387 |
// append failed, give the op back to the caller. |
| 388 |
this->validate(); |
| 389 |
return chain.popHead(); |
| 390 |
} |
| 391 |
|
| 392 |
SkASSERT(chain.empty()); |
| 393 |
this->validate(); |
| 394 |
return nullptr; |
| 395 |
} |
| 396 |
|
| 397 |
inline void OpsTask::OpChain::validate() const { |
| 398 |
#ifdef SK_DEBUG |
| 399 |
fList.validate(); |
| 400 |
for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 401 |
// Not using SkRect::contains because we allow empty rects. |
| 402 |
SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop && |
| 403 |
fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom); |
| 404 |
} |
| 405 |
#endif |
| 406 |
} |
| 407 |
|
| 408 |
//////////////////////////////////////////////////////////////////////////////// |
| 409 |
|
| 410 |
OpsTask::OpsTask(GrDrawingManager* drawingMgr, |
| 411 |
GrSurfaceProxyView view, |
| 412 |
GrAuditTrail* auditTrail, |
| 413 |
sk_sp<GrArenas> arenas) |
| 414 |
: GrRenderTask() |
| 415 |
, fAuditTrail(auditTrail) |
| 416 |
, fUsesMSAASurface(view.asRenderTargetProxy()->numSamples() > 1) |
| 417 |
, fTargetSwizzle(view.swizzle()) |
| 418 |
, fTargetOrigin(view.origin()) |
| 419 |
, fArenas{std::move(arenas)} |
| 420 |
SkDEBUGCODE(, fNumClips(0)) { |
| 421 |
this->addTarget(drawingMgr, view.detachProxy()); |
| 422 |
} |
| 423 |
|
| 424 |
void OpsTask::deleteOps() { |
| 425 |
for (auto& chain : fOpChains) { |
| 426 |
chain.deleteOps(); |
| 427 |
} |
| 428 |
fOpChains.clear(); |
| 429 |
} |
| 430 |
|
| 431 |
OpsTask::~OpsTask() { |
| 432 |
this->deleteOps(); |
| 433 |
} |
| 434 |
|
| 435 |
void OpsTask::addOp(GrDrawingManager* drawingMgr, GrOp::Owner op, |
| 436 |
GrTextureResolveManager textureResolveManager, const GrCaps& caps) { |
| 437 |
auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) { |
| 438 |
this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps); |
| 439 |
}; |
| 440 |
|
| 441 |
op->visitProxies(addDependency); |
| 442 |
|
| 443 |
this->recordOp(std::move(op), false/*usesMSAA*/, GrProcessorSet::EmptySetAnalysis(), nullptr, |
| 444 |
nullptr, caps); |
| 445 |
} |
| 446 |
|
| 447 |
void OpsTask::addDrawOp(GrDrawingManager* drawingMgr, GrOp::Owner op, bool usesMSAA, |
| 448 |
const GrProcessorSet::Analysis& processorAnalysis, GrAppliedClip&& clip, |
| 449 |
const GrDstProxyView& dstProxyView, |
| 450 |
GrTextureResolveManager textureResolveManager, const GrCaps& caps) { |
| 451 |
auto addDependency = [&](GrSurfaceProxy* p, skgpu::Mipmapped mipmapped) { |
| 452 |
this->addSampledTexture(p); |
| 453 |
this->addDependency(drawingMgr, p, mipmapped, textureResolveManager, caps); |
| 454 |
}; |
| 455 |
|
| 456 |
op->visitProxies(addDependency); |
| 457 |
clip.visitProxies(addDependency); |
| 458 |
if (dstProxyView.proxy()) { |
| 459 |
if (!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment)) { |
| 460 |
this->addSampledTexture(dstProxyView.proxy()); |
| 461 |
} |
| 462 |
if (dstProxyView.dstSampleFlags() & GrDstSampleFlags::kRequiresTextureBarrier) { |
| 463 |
fRenderPassXferBarriers |= GrXferBarrierFlags::kTexture; |
| 464 |
} |
| 465 |
addDependency(dstProxyView.proxy(), skgpu::Mipmapped::kNo); |
| 466 |
SkASSERT(!(dstProxyView.dstSampleFlags() & GrDstSampleFlags::kAsInputAttachment) || |
| 467 |
dstProxyView.offset().isZero()); |
| 468 |
} |
| 469 |
|
| 470 |
if (processorAnalysis.usesNonCoherentHWBlending()) { |
| 471 |
fRenderPassXferBarriers |= GrXferBarrierFlags::kBlend; |
| 472 |
} |
| 473 |
|
| 474 |
this->recordOp(std::move(op), usesMSAA, processorAnalysis, clip.doesClip() ? &clip : nullptr, |
| 475 |
&dstProxyView, caps); |
| 476 |
} |
| 477 |
|
| 478 |
void OpsTask::endFlush(GrDrawingManager* drawingMgr) { |
| 479 |
fLastClipStackGenID = SK_InvalidUniqueID; |
| 480 |
this->deleteOps(); |
| 481 |
|
| 482 |
fDeferredProxies.clear(); |
| 483 |
fSampledProxies.clear(); |
| 484 |
fAuditTrail = nullptr; |
| 485 |
|
| 486 |
GrRenderTask::endFlush(drawingMgr); |
| 487 |
} |
| 488 |
|
| 489 |
void OpsTask::onPrePrepare(GrRecordingContext* context) { |
| 490 |
SkASSERT(this->isClosed()); |
| 491 |
// TODO: remove the check for discard here once reduced op splitting is turned on. Currently we |
| 492 |
// can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation |
| 493 |
// we need to keep that discard and not drop it. Once we have reduce op list splitting enabled |
| 494 |
// we shouldn't end up with OpsTasks with only discard. |
| 495 |
if (this->isColorNoOp() || |
| 496 |
(fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) { |
| 497 |
return; |
| 498 |
} |
| 499 |
TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 500 |
|
| 501 |
GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle); |
| 502 |
for (const auto& chain : fOpChains) { |
| 503 |
if (chain.shouldExecute()) { |
| 504 |
chain.head()->prePrepare(context, |
| 505 |
dstView, |
| 506 |
chain.appliedClip(), |
| 507 |
chain.dstProxyView(), |
| 508 |
fRenderPassXferBarriers, |
| 509 |
fColorLoadOp); |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
void OpsTask::onPrepare(GrOpFlushState* flushState) { |
| 515 |
SkASSERT(this->target(0)->peekRenderTarget()); |
| 516 |
SkASSERT(this->isClosed()); |
| 517 |
// TODO: remove the check for discard here once reduced op splitting is turned on. Currently we |
| 518 |
// can end up with OpsTasks that only have a discard load op and no ops. For vulkan validation |
| 519 |
// we need to keep that discard and not drop it. Once we have reduce op list splitting enabled |
| 520 |
// we shouldn't end up with OpsTasks with only discard. |
| 521 |
if (this->isColorNoOp() || |
| 522 |
(fClippedContentBounds.isEmpty() && fColorLoadOp != GrLoadOp::kDiscard)) { |
| 523 |
return; |
| 524 |
} |
| 525 |
TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC); |
| 526 |
|
| 527 |
flushState->setSampledProxyArray(&fSampledProxies); |
| 528 |
GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle); |
| 529 |
// Loop over the ops that haven't yet been prepared. |
| 530 |
for (const auto& chain : fOpChains) { |
| 531 |
if (chain.shouldExecute()) { |
| 532 |
GrOpFlushState::OpArgs opArgs(chain.head(), |
| 533 |
dstView, |
| 534 |
fUsesMSAASurface, |
| 535 |
chain.appliedClip(), |
| 536 |
chain.dstProxyView(), |
| 537 |
fRenderPassXferBarriers, |
| 538 |
fColorLoadOp); |
| 539 |
|
| 540 |
flushState->setOpArgs(&opArgs); |
| 541 |
|
| 542 |
// Temporary debugging helper: for debugging prePrepare w/o going through DDLs |
| 543 |
// Delete once most of the GrOps have an onPrePrepare. |
| 544 |
// chain.head()->prePrepare(flushState->gpu()->getContext(), &this->target(0), |
| 545 |
// chain.appliedClip()); |
| 546 |
|
| 547 |
// GrOp::prePrepare may or may not have been called at this point |
| 548 |
chain.head()->prepare(flushState); |
| 549 |
flushState->setOpArgs(nullptr); |
| 550 |
} |
| 551 |
} |
| 552 |
flushState->setSampledProxyArray(nullptr); |
| 553 |
} |
| 554 |
|
| 555 |
// TODO: this is where GrOp::renderTarget is used (which is fine since it |
| 556 |
// is at flush time). However, we need to store the RenderTargetProxy in the |
| 557 |
// Ops and instantiate them here. |
| 558 |
bool OpsTask::onExecute(GrOpFlushState* flushState) { |
| 559 |
SkASSERT(this->numTargets() == 1); |
| 560 |
GrRenderTargetProxy* proxy = this->target(0)->asRenderTargetProxy(); |
| 561 |
SkASSERT(proxy); |
| 562 |
SK_AT_SCOPE_EXIT(proxy->clearArenas()); |
| 563 |
|
| 564 |
if (this->isColorNoOp() || fClippedContentBounds.isEmpty()) { |
| 565 |
return false; |
| 566 |
} |
| 567 |
TRACE_EVENT0_ALWAYS("skia.gpu", TRACE_FUNC); |
| 568 |
|
| 569 |
// Make sure load ops are not kClear if the GPU needs to use draws for clears |
| 570 |
SkASSERT(fColorLoadOp != GrLoadOp::kClear || |
| 571 |
!flushState->gpu()->caps()->performColorClearsAsDraws()); |
| 572 |
|
| 573 |
const GrCaps& caps = *flushState->gpu()->caps(); |
| 574 |
GrRenderTarget* renderTarget = proxy->peekRenderTarget(); |
| 575 |
SkASSERT(renderTarget); |
| 576 |
|
| 577 |
GrAttachment* stencil = nullptr; |
| 578 |
if (proxy->needsStencil()) { |
| 579 |
SkASSERT(proxy->canUseStencil(caps)); |
| 580 |
if (!flushState->resourceProvider()->attachStencilAttachment(renderTarget, |
| 581 |
fUsesMSAASurface)) { |
| 582 |
SkDebugf("WARNING: failed to attach a stencil buffer. Rendering will be skipped.\n"); |
| 583 |
return false; |
| 584 |
} |
| 585 |
stencil = renderTarget->getStencilAttachment(fUsesMSAASurface); |
| 586 |
} |
| 587 |
|
| 588 |
GrLoadOp stencilLoadOp; |
| 589 |
switch (fInitialStencilContent) { |
| 590 |
case StencilContent::kDontCare: |
| 591 |
stencilLoadOp = GrLoadOp::kDiscard; |
| 592 |
break; |
| 593 |
case StencilContent::kUserBitsCleared: |
| 594 |
SkASSERT(!caps.performStencilClearsAsDraws()); |
| 595 |
SkASSERT(stencil); |
| 596 |
if (caps.discardStencilValuesAfterRenderPass()) { |
| 597 |
// Always clear the stencil if it is being discarded after render passes. This is |
| 598 |
// also an optimization because we are on a tiler and it avoids loading the values |
| 599 |
// from memory. |
| 600 |
stencilLoadOp = GrLoadOp::kClear; |
| 601 |
break; |
| 602 |
} |
| 603 |
if (!stencil->hasPerformedInitialClear()) { |
| 604 |
stencilLoadOp = GrLoadOp::kClear; |
| 605 |
stencil->markHasPerformedInitialClear(); |
| 606 |
break; |
| 607 |
} |
| 608 |
// SurfaceDrawContexts are required to leave the user stencil bits in a cleared state |
| 609 |
// once finished, meaning the stencil values will always remain cleared after the |
| 610 |
// initial clear. Just fall through to reloading the existing (cleared) stencil values |
| 611 |
// from memory. |
| 612 |
[[fallthrough]]; |
| 613 |
case StencilContent::kPreserved: |
| 614 |
SkASSERT(stencil); |
| 615 |
stencilLoadOp = GrLoadOp::kLoad; |
| 616 |
break; |
| 617 |
} |
| 618 |
|
| 619 |
// NOTE: If fMustPreserveStencil is set, then we are executing a surfaceDrawContext that split |
| 620 |
// its opsTask. |
| 621 |
// |
| 622 |
// FIXME: We don't currently flag render passes that don't use stencil at all. In that case |
| 623 |
// their store op might be "discard", and we currently make the assumption that a discard will |
| 624 |
// not invalidate what's already in main memory. This is probably ok for now, but certainly |
| 625 |
// something we want to address soon. |
| 626 |
GrStoreOp stencilStoreOp = (caps.discardStencilValuesAfterRenderPass() && !fMustPreserveStencil) |
| 627 |
? GrStoreOp::kDiscard |
| 628 |
: GrStoreOp::kStore; |
| 629 |
|
| 630 |
GrOpsRenderPass* renderPass = create_render_pass(flushState->gpu(), |
| 631 |
proxy->peekRenderTarget(), |
| 632 |
fUsesMSAASurface, |
| 633 |
stencil, |
| 634 |
fTargetOrigin, |
| 635 |
fClippedContentBounds, |
| 636 |
fColorLoadOp, |
| 637 |
fLoadClearColor, |
| 638 |
stencilLoadOp, |
| 639 |
stencilStoreOp, |
| 640 |
fSampledProxies, |
| 641 |
fRenderPassXferBarriers); |
| 642 |
|
| 643 |
if (!renderPass) { |
| 644 |
return false; |
| 645 |
} |
| 646 |
flushState->setOpsRenderPass(renderPass); |
| 647 |
renderPass->begin(); |
| 648 |
|
| 649 |
GrSurfaceProxyView dstView(sk_ref_sp(this->target(0)), fTargetOrigin, fTargetSwizzle); |
| 650 |
|
| 651 |
// Draw all the generated geometry. |
| 652 |
for (const auto& chain : fOpChains) { |
| 653 |
if (!chain.shouldExecute()) { |
| 654 |
continue; |
| 655 |
} |
| 656 |
|
| 657 |
GrOpFlushState::OpArgs opArgs(chain.head(), |
| 658 |
dstView, |
| 659 |
fUsesMSAASurface, |
| 660 |
chain.appliedClip(), |
| 661 |
chain.dstProxyView(), |
| 662 |
fRenderPassXferBarriers, |
| 663 |
fColorLoadOp); |
| 664 |
|
| 665 |
flushState->setOpArgs(&opArgs); |
| 666 |
chain.head()->execute(flushState, chain.bounds()); |
| 667 |
flushState->setOpArgs(nullptr); |
| 668 |
} |
| 669 |
|
| 670 |
renderPass->end(); |
| 671 |
flushState->gpu()->submit(renderPass); |
| 672 |
flushState->setOpsRenderPass(nullptr); |
| 673 |
|
| 674 |
return true; |
| 675 |
} |
| 676 |
|
| 677 |
void OpsTask::setColorLoadOp(GrLoadOp op, std::array<float, 4> color) { |
| 678 |
fColorLoadOp = op; |
| 679 |
fLoadClearColor = color; |
| 680 |
if (GrLoadOp::kClear == fColorLoadOp) { |
| 681 |
GrSurfaceProxy* proxy = this->target(0); |
| 682 |
SkASSERT(proxy); |
| 683 |
fTotalBounds = proxy->backingStoreBoundsRect(); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
void OpsTask::reset() { |
| 688 |
fDeferredProxies.clear(); |
| 689 |
fSampledProxies.clear(); |
| 690 |
fClippedContentBounds = SkIRect::MakeEmpty(); |
| 691 |
fTotalBounds = SkRect::MakeEmpty(); |
| 692 |
this->deleteOps(); |
| 693 |
fRenderPassXferBarriers = GrXferBarrierFlags::kNone; |
| 694 |
} |
| 695 |
|
| 696 |
bool OpsTask::canMerge(const OpsTask* opsTask) const { |
| 697 |
return this->target(0) == opsTask->target(0) && |
| 698 |
fArenas == opsTask->fArenas && |
| 699 |
!opsTask->fCannotMergeBackward; |
| 700 |
} |
| 701 |
|
| 702 |
int OpsTask::mergeFrom(SkSpan<const sk_sp<GrRenderTask>> tasks) { |
| 703 |
int mergedCount = 0; |
| 704 |
for (const sk_sp<GrRenderTask>& task : tasks) { |
| 705 |
auto opsTask = task->asOpsTask(); |
| 706 |
if (!opsTask || !this->canMerge(opsTask)) { |
| 707 |
break; |
| 708 |
} |
| 709 |
SkASSERT(fTargetSwizzle == opsTask->fTargetSwizzle); |
| 710 |
SkASSERT(fTargetOrigin == opsTask->fTargetOrigin); |
| 711 |
if (GrLoadOp::kClear == opsTask->fColorLoadOp) { |
| 712 |
// TODO(11903): Go back to actually dropping ops tasks when we are merged with |
| 713 |
// color clear. |
| 714 |
return 0; |
| 715 |
} |
| 716 |
mergedCount += 1; |
| 717 |
} |
| 718 |
if (0 == mergedCount) { |
| 719 |
return 0; |
| 720 |
} |
| 721 |
|
| 722 |
SkSpan<const sk_sp<OpsTask>> mergingNodes( |
| 723 |
reinterpret_cast<const sk_sp<OpsTask>*>(tasks.data()), SkToSizeT(mergedCount)); |
| 724 |
int addlDeferredProxyCount = 0; |
| 725 |
int addlProxyCount = 0; |
| 726 |
int addlOpChainCount = 0; |
| 727 |
for (const auto& toMerge : mergingNodes) { |
| 728 |
addlDeferredProxyCount += toMerge->fDeferredProxies.size(); |
| 729 |
addlProxyCount += toMerge->fSampledProxies.size(); |
| 730 |
addlOpChainCount += toMerge->fOpChains.size(); |
| 731 |
fClippedContentBounds.join(toMerge->fClippedContentBounds); |
| 732 |
fTotalBounds.join(toMerge->fTotalBounds); |
| 733 |
fRenderPassXferBarriers |= toMerge->fRenderPassXferBarriers; |
| 734 |
if (fInitialStencilContent == StencilContent::kDontCare) { |
| 735 |
// Propogate the first stencil content that isn't kDontCare. |
| 736 |
// |
| 737 |
// Once the stencil has any kind of initial content that isn't kDontCare, then the |
| 738 |
// inital contents of subsequent opsTasks that get merged in don't matter. |
| 739 |
// |
| 740 |
// (This works because the opsTask all target the same render target and are in |
| 741 |
// painter's order. kPreserved obviously happens automatically with a merge, and kClear |
| 742 |
// is also automatic because the contract is for ops to leave the stencil buffer in a |
| 743 |
// cleared state when finished.) |
| 744 |
fInitialStencilContent = toMerge->fInitialStencilContent; |
| 745 |
} |
| 746 |
fUsesMSAASurface |= toMerge->fUsesMSAASurface; |
| 747 |
SkDEBUGCODE(fNumClips += toMerge->fNumClips); |
| 748 |
} |
| 749 |
|
| 750 |
fLastClipStackGenID = SK_InvalidUniqueID; |
| 751 |
fDeferredProxies.reserve_exact(fDeferredProxies.size() + addlDeferredProxyCount); |
| 752 |
fSampledProxies.reserve_exact(fSampledProxies.size() + addlProxyCount); |
| 753 |
fOpChains.reserve_exact(fOpChains.size() + addlOpChainCount); |
| 754 |
for (const auto& toMerge : mergingNodes) { |
| 755 |
for (GrRenderTask* renderTask : toMerge->dependents()) { |
| 756 |
renderTask->replaceDependency(toMerge.get(), this); |
| 757 |
} |
| 758 |
for (GrRenderTask* renderTask : toMerge->dependencies()) { |
| 759 |
renderTask->replaceDependent(toMerge.get(), this); |
| 760 |
} |
| 761 |
fDeferredProxies.move_back_n(toMerge->fDeferredProxies.size(), |
| 762 |
toMerge->fDeferredProxies.data()); |
| 763 |
fSampledProxies.move_back_n(toMerge->fSampledProxies.size(), |
| 764 |
toMerge->fSampledProxies.data()); |
| 765 |
fOpChains.move_back_n(toMerge->fOpChains.size(), |
| 766 |
toMerge->fOpChains.data()); |
| 767 |
toMerge->fDeferredProxies.clear(); |
| 768 |
toMerge->fSampledProxies.clear(); |
| 769 |
toMerge->fOpChains.clear(); |
| 770 |
} |
| 771 |
fMustPreserveStencil = mergingNodes.back()->fMustPreserveStencil; |
| 772 |
return mergedCount; |
| 773 |
} |
| 774 |
|
| 775 |
bool OpsTask::resetForFullscreenClear(CanDiscardPreviousOps canDiscardPreviousOps) { |
| 776 |
if (CanDiscardPreviousOps::kYes == canDiscardPreviousOps || this->isEmpty()) { |
| 777 |
this->deleteOps(); |
| 778 |
fDeferredProxies.clear(); |
| 779 |
fSampledProxies.clear(); |
| 780 |
|
| 781 |
// If the opsTask is using a render target which wraps a vulkan command buffer, we can't do |
| 782 |
// a clear load since we cannot change the render pass that we are using. Thus we fall back |
| 783 |
// to making a clear op in this case. |
| 784 |
return !this->target(0)->asRenderTargetProxy()->wrapsVkSecondaryCB(); |
| 785 |
} |
| 786 |
|
| 787 |
// Could not empty the task, so an op must be added to handle the clear |
| 788 |
return false; |
| 789 |
} |
| 790 |
|
| 791 |
void OpsTask::discard() { |
| 792 |
// Discard calls to in-progress opsTasks are ignored. Calls at the start update the |
| 793 |
// opsTasks' color & stencil load ops. |
| 794 |
if (this->isEmpty()) { |
| 795 |
fColorLoadOp = GrLoadOp::kDiscard; |
| 796 |
fInitialStencilContent = StencilContent::kDontCare; |
| 797 |
fTotalBounds.setEmpty(); |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
//////////////////////////////////////////////////////////////////////////////// |
| 802 |
|
| 803 |
#if defined(GPU_TEST_UTILS) |
| 804 |
void OpsTask::dump(const SkString& label, |
| 805 |
SkString indent, |
| 806 |
bool printDependencies, |
| 807 |
bool close) const { |
| 808 |
GrRenderTask::dump(label, indent, printDependencies, false); |
| 809 |
|
| 810 |
SkDebugf("%sfColorLoadOp: ", indent.c_str()); |
| 811 |
switch (fColorLoadOp) { |
| 812 |
case GrLoadOp::kLoad: |
| 813 |
SkDebugf("kLoad\n"); |
| 814 |
break; |
| 815 |
case GrLoadOp::kClear: |
| 816 |
SkDebugf("kClear {%g, %g, %g, %g}\n", |
| 817 |
fLoadClearColor[0], |
| 818 |
fLoadClearColor[1], |
| 819 |
fLoadClearColor[2], |
| 820 |
fLoadClearColor[3]); |
| 821 |
break; |
| 822 |
case GrLoadOp::kDiscard: |
| 823 |
SkDebugf("kDiscard\n"); |
| 824 |
break; |
| 825 |
} |
| 826 |
|
| 827 |
SkDebugf("%sfInitialStencilContent: ", indent.c_str()); |
| 828 |
switch (fInitialStencilContent) { |
| 829 |
case StencilContent::kDontCare: |
| 830 |
SkDebugf("kDontCare\n"); |
| 831 |
break; |
| 832 |
case StencilContent::kUserBitsCleared: |
| 833 |
SkDebugf("kUserBitsCleared\n"); |
| 834 |
break; |
| 835 |
case StencilContent::kPreserved: |
| 836 |
SkDebugf("kPreserved\n"); |
| 837 |
break; |
| 838 |
} |
| 839 |
|
| 840 |
SkDebugf("%s%d ops:\n", indent.c_str(), fOpChains.size()); |
| 841 |
for (int i = 0; i < fOpChains.size(); ++i) { |
| 842 |
SkDebugf("%s*******************************\n", indent.c_str()); |
| 843 |
if (!fOpChains[i].head()) { |
| 844 |
SkDebugf("%s%d: <combined forward or failed instantiation>\n", indent.c_str(), i); |
| 845 |
} else { |
| 846 |
SkDebugf("%s%d: %s\n", indent.c_str(), i, fOpChains[i].head()->name()); |
| 847 |
SkRect bounds = fOpChains[i].bounds(); |
| 848 |
SkDebugf("%sClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 849 |
indent.c_str(), |
| 850 |
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 851 |
for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) { |
| 852 |
SkString info = SkTabString(op.dumpInfo(), 1); |
| 853 |
SkDebugf("%s%s\n", indent.c_str(), info.c_str()); |
| 854 |
bounds = op.bounds(); |
| 855 |
SkDebugf("%s\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 856 |
indent.c_str(), |
| 857 |
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 858 |
} |
| 859 |
} |
| 860 |
} |
| 861 |
|
| 862 |
if (close) { |
| 863 |
SkDebugf("%s--------------------------------------------------------------\n\n", |
| 864 |
indent.c_str()); |
| 865 |
} |
| 866 |
} |
| 867 |
#endif |
| 868 |
|
| 869 |
#ifdef SK_DEBUG |
| 870 |
void OpsTask::visitProxies_debugOnly(const GrVisitProxyFunc& func) const { |
| 871 |
auto textureFunc = [func](GrSurfaceProxy* tex, skgpu::Mipmapped mipmapped) { |
| 872 |
func(tex, mipmapped); |
| 873 |
}; |
| 874 |
|
| 875 |
for (const OpChain& chain : fOpChains) { |
| 876 |
chain.visitProxies(textureFunc); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
#endif |
| 881 |
|
| 882 |
//////////////////////////////////////////////////////////////////////////////// |
| 883 |
|
| 884 |
void OpsTask::onMakeSkippable() { |
| 885 |
this->deleteOps(); |
| 886 |
fDeferredProxies.clear(); |
| 887 |
fColorLoadOp = GrLoadOp::kLoad; |
| 888 |
SkASSERT(this->isColorNoOp()); |
| 889 |
} |
| 890 |
|
| 891 |
bool OpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const { |
| 892 |
bool used = false; |
| 893 |
for (GrSurfaceProxy* proxy : fSampledProxies) { |
| 894 |
if (proxy == proxyToCheck) { |
| 895 |
used = true; |
| 896 |
break; |
| 897 |
} |
| 898 |
} |
| 899 |
#ifdef SK_DEBUG |
| 900 |
bool usedSlow = false; |
| 901 |
auto visit = [proxyToCheck, &usedSlow](GrSurfaceProxy* p, skgpu::Mipmapped) { |
| 902 |
if (p == proxyToCheck) { |
| 903 |
usedSlow = true; |
| 904 |
} |
| 905 |
}; |
| 906 |
this->visitProxies_debugOnly(visit); |
| 907 |
SkASSERT(used == usedSlow); |
| 908 |
#endif |
| 909 |
|
| 910 |
return used; |
| 911 |
} |
| 912 |
|
| 913 |
void OpsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 914 |
SkASSERT(this->isClosed()); |
| 915 |
if (this->isColorNoOp()) { |
| 916 |
return; |
| 917 |
} |
| 918 |
|
| 919 |
for (int i = 0; i < fDeferredProxies.size(); ++i) { |
| 920 |
SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
| 921 |
// We give all the deferred proxies a write usage at the very start of flushing. This |
| 922 |
// locks them out of being reused for the entire flush until they are read - and then |
| 923 |
// they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 924 |
// with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 925 |
// the sub-flush in which they appear. |
| 926 |
alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo, |
| 927 |
GrResourceAllocator::AllowRecycling::kYes); |
| 928 |
} |
| 929 |
|
| 930 |
GrSurfaceProxy* targetSurface = this->target(0); |
| 931 |
SkASSERT(targetSurface); |
| 932 |
GrRenderTargetProxy* targetProxy = targetSurface->asRenderTargetProxy(); |
| 933 |
|
| 934 |
// Add the interval for all the writes to this OpsTasks's target |
| 935 |
if (!fOpChains.empty()) { |
| 936 |
unsigned int cur = alloc->curOp(); |
| 937 |
|
| 938 |
alloc->addInterval(targetProxy, cur, cur + fOpChains.size() - 1, |
| 939 |
GrResourceAllocator::ActualUse::kYes, |
| 940 |
GrResourceAllocator::AllowRecycling::kYes); |
| 941 |
} else { |
| 942 |
// This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 943 |
// still need to add an interval for the destination so we create a fake op# for |
| 944 |
// the missing clear op. |
| 945 |
alloc->addInterval(targetProxy, alloc->curOp(), alloc->curOp(), |
| 946 |
GrResourceAllocator::ActualUse::kYes, |
| 947 |
GrResourceAllocator::AllowRecycling::kYes); |
| 948 |
alloc->incOps(); |
| 949 |
} |
| 950 |
|
| 951 |
GrResourceAllocator::AllowRecycling allowRecycling = |
| 952 |
targetProxy->wrapsVkSecondaryCB() ? GrResourceAllocator::AllowRecycling::kNo |
| 953 |
: GrResourceAllocator::AllowRecycling::kYes; |
| 954 |
|
| 955 |
auto gather = [alloc, allowRecycling SkDEBUGCODE(, this)](GrSurfaceProxy* p, skgpu::Mipmapped) { |
| 956 |
alloc->addInterval(p, |
| 957 |
alloc->curOp(), |
| 958 |
alloc->curOp(), |
| 959 |
GrResourceAllocator::ActualUse::kYes, |
| 960 |
allowRecycling |
| 961 |
SkDEBUGCODE(, this->target(0) == p)); |
| 962 |
}; |
| 963 |
// TODO: visitProxies is expensive. Can we do this with fSampledProxies instead? |
| 964 |
for (const OpChain& recordedOp : fOpChains) { |
| 965 |
recordedOp.visitProxies(gather); |
| 966 |
|
| 967 |
// Even though the op may have been (re)moved we still need to increment the op count to |
| 968 |
// keep all the math consistent. |
| 969 |
alloc->incOps(); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
void OpsTask::recordOp( |
| 974 |
GrOp::Owner op, bool usesMSAA, GrProcessorSet::Analysis processorAnalysis, |
| 975 |
GrAppliedClip* clip, const GrDstProxyView* dstProxyView, const GrCaps& caps) { |
| 976 |
GrSurfaceProxy* proxy = this->target(0); |
| 977 |
#ifdef SK_DEBUG |
| 978 |
op->validate(); |
| 979 |
SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxyView && dstProxyView->proxy())); |
| 980 |
SkASSERT(proxy); |
| 981 |
// A closed OpsTask should never receive new/more ops |
| 982 |
SkASSERT(!this->isClosed()); |
| 983 |
// Ensure we can support dynamic msaa if the caller is trying to trigger it. |
| 984 |
if (proxy->asRenderTargetProxy()->numSamples() == 1 && usesMSAA) { |
| 985 |
SkASSERT(caps.supportsDynamicMSAA(proxy->asRenderTargetProxy())); |
| 986 |
} |
| 987 |
#endif |
| 988 |
|
| 989 |
if (!op->bounds().isFinite()) { |
| 990 |
return; |
| 991 |
} |
| 992 |
|
| 993 |
fUsesMSAASurface |= usesMSAA; |
| 994 |
|
| 995 |
// Account for this op's bounds before we attempt to combine. |
| 996 |
// NOTE: The caller should have already called "op->setClippedBounds()" by now, if applicable. |
| 997 |
fTotalBounds.join(op->bounds()); |
| 998 |
|
| 999 |
// Check if there is an op we can combine with by linearly searching back until we either |
| 1000 |
// 1) check every op |
| 1001 |
// 2) intersect with something |
| 1002 |
// 3) find a 'blocker' |
| 1003 |
GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), proxy->uniqueID()); |
| 1004 |
GrOP_INFO("opsTask: %d Recording (%s, opID: %u)\n" |
| 1005 |
"\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 1006 |
this->uniqueID(), |
| 1007 |
op->name(), |
| 1008 |
op->uniqueID(), |
| 1009 |
op->bounds().fLeft, op->bounds().fTop, |
| 1010 |
op->bounds().fRight, op->bounds().fBottom); |
| 1011 |
GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
| 1012 |
GrOP_INFO("\tOutcome:\n"); |
| 1013 |
int maxCandidates = std::min(kMaxOpChainDistance, fOpChains.size()); |
| 1014 |
if (maxCandidates) { |
| 1015 |
int i = 0; |
| 1016 |
while (true) { |
| 1017 |
OpChain& candidate = fOpChains.fromBack(i); |
| 1018 |
op = candidate.appendOp(std::move(op), processorAnalysis, dstProxyView, clip, caps, |
| 1019 |
fArenas->arenaAlloc(), fAuditTrail); |
| 1020 |
if (!op) { |
| 1021 |
return; |
| 1022 |
} |
| 1023 |
// Stop going backwards if we would cause a painter's order violation. |
| 1024 |
if (!can_reorder(candidate.bounds(), op->bounds())) { |
| 1025 |
GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n", |
| 1026 |
candidate.head()->name(), candidate.head()->uniqueID()); |
| 1027 |
break; |
| 1028 |
} |
| 1029 |
if (++i == maxCandidates) { |
| 1030 |
GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i); |
| 1031 |
break; |
| 1032 |
} |
| 1033 |
} |
| 1034 |
} else { |
| 1035 |
GrOP_INFO("\t\tBackward: FirstOp\n"); |
| 1036 |
} |
| 1037 |
if (clip) { |
| 1038 |
clip = fArenas->arenaAlloc()->make<GrAppliedClip>(std::move(*clip)); |
| 1039 |
SkDEBUGCODE(fNumClips++;) |
| 1040 |
} |
| 1041 |
fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxyView); |
| 1042 |
} |
| 1043 |
|
| 1044 |
void OpsTask::forwardCombine(const GrCaps& caps) { |
| 1045 |
SkASSERT(!this->isClosed()); |
| 1046 |
GrOP_INFO("opsTask: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.size()); |
| 1047 |
|
| 1048 |
for (int i = 0; i < fOpChains.size() - 1; ++i) { |
| 1049 |
OpChain& chain = fOpChains[i]; |
| 1050 |
int maxCandidateIdx = std::min(i + kMaxOpChainDistance, fOpChains.size() - 1); |
| 1051 |
int j = i + 1; |
| 1052 |
while (true) { |
| 1053 |
OpChain& candidate = fOpChains[j]; |
| 1054 |
if (candidate.prependChain(&chain, caps, fArenas->arenaAlloc(), fAuditTrail)) { |
| 1055 |
break; |
| 1056 |
} |
| 1057 |
// Stop traversing if we would cause a painter's order violation. |
| 1058 |
if (!can_reorder(chain.bounds(), candidate.bounds())) { |
| 1059 |
GrOP_INFO( |
| 1060 |
"\t\t%d: chain (%s head opID: %u) -> " |
| 1061 |
"Intersects with chain (%s, head opID: %u)\n", |
| 1062 |
i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(), |
| 1063 |
candidate.head()->uniqueID()); |
| 1064 |
break; |
| 1065 |
} |
| 1066 |
if (++j > maxCandidateIdx) { |
| 1067 |
GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n", |
| 1068 |
i, chain.head()->name(), chain.head()->uniqueID()); |
| 1069 |
break; |
| 1070 |
} |
| 1071 |
} |
| 1072 |
} |
| 1073 |
} |
| 1074 |
|
| 1075 |
GrRenderTask::ExpectedOutcome OpsTask::onMakeClosed(GrRecordingContext* rContext, |
| 1076 |
SkIRect* targetUpdateBounds) { |
| 1077 |
this->forwardCombine(*rContext->priv().caps()); |
| 1078 |
if (!this->isColorNoOp()) { |
| 1079 |
GrSurfaceProxy* proxy = this->target(0); |
| 1080 |
// Use the entire backing store bounds since the GPU doesn't clip automatically to the |
| 1081 |
// logical dimensions. |
| 1082 |
SkRect clippedContentBounds = proxy->backingStoreBoundsRect(); |
| 1083 |
// TODO: If we can fix up GLPrograms test to always intersect the target proxy bounds |
| 1084 |
// then we can simply assert here that the bounds intersect. |
| 1085 |
if (clippedContentBounds.intersect(fTotalBounds)) { |
| 1086 |
clippedContentBounds.roundOut(&fClippedContentBounds); |
| 1087 |
*targetUpdateBounds = GrNativeRect::MakeIRectRelativeTo( |
| 1088 |
fTargetOrigin, |
| 1089 |
this->target(0)->backingStoreDimensions().height(), |
| 1090 |
fClippedContentBounds); |
| 1091 |
return ExpectedOutcome::kTargetDirty; |
| 1092 |
} |
| 1093 |
} |
| 1094 |
return ExpectedOutcome::kTargetUnchanged; |
| 1095 |
} |
| 1096 |
|
| 1097 |
} // namespace skgpu::ganesh |