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