robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrRenderTargetProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 9 | |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 10 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkMathPriv.h" |
| 12 | #include "src/gpu/GrCaps.h" |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 13 | #include "src/gpu/GrContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrGpuResourcePriv.h" |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrOpsTask.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrRenderTargetPriv.h" |
| 17 | #include "src/gpu/GrResourceProvider.h" |
| 18 | #include "src/gpu/GrSurfacePriv.h" |
| 19 | #include "src/gpu/GrTextureRenderTargetProxy.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 20 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 21 | // Deferred version |
| 22 | // TODO: we can probably munge the 'desc' in both the wrapped and deferred |
| 23 | // cases to make the sampleConfig/numSamples stuff more rational. |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 24 | GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, |
| 25 | const GrBackendFormat& format, |
| 26 | const GrSurfaceDesc& desc, |
| 27 | int sampleCount, |
| 28 | GrSurfaceOrigin origin, |
| 29 | const GrSwizzle& textureSwizzle, |
| 30 | const GrSwizzle& outputSwizzle, |
| 31 | SkBackingFit fit, |
| 32 | SkBudgeted budgeted, |
| 33 | GrProtected isProtected, |
| 34 | GrInternalSurfaceFlags surfaceFlags, |
| 35 | UseAllocator useAllocator) |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 36 | : INHERITED(format, desc, GrRenderable::kYes, origin, textureSwizzle, fit, budgeted, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 37 | isProtected, surfaceFlags, useAllocator) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 38 | , fSampleCnt(sampleCount) |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 39 | , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo) |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 40 | , fOutputSwizzle(outputSwizzle) {} |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 41 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 42 | // Lazy-callback version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 43 | GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback, |
| 44 | const GrBackendFormat& format, |
| 45 | const GrSurfaceDesc& desc, |
| 46 | int sampleCount, |
| 47 | GrSurfaceOrigin origin, |
| 48 | const GrSwizzle& textureSwizzle, |
| 49 | const GrSwizzle& outputSwizzle, |
| 50 | SkBackingFit fit, |
| 51 | SkBudgeted budgeted, |
| 52 | GrProtected isProtected, |
| 53 | GrInternalSurfaceFlags surfaceFlags, |
| 54 | UseAllocator useAllocator, |
| 55 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
| 56 | : INHERITED(std::move(callback), format, desc, GrRenderable::kYes, origin, textureSwizzle, |
| 57 | fit, budgeted, isProtected, surfaceFlags, useAllocator) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 58 | , fSampleCnt(sampleCount) |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 59 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 60 | , fOutputSwizzle(outputSwizzle) {} |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 61 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 62 | // Wrapped version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 63 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, |
| 64 | GrSurfaceOrigin origin, |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 65 | const GrSwizzle& textureSwizzle, |
| 66 | const GrSwizzle& outputSwizzle, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 67 | UseAllocator useAllocator, |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 68 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 69 | : INHERITED(std::move(surf), origin, textureSwizzle, SkBackingFit::kExact, useAllocator) |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 70 | , fSampleCnt(fTarget->asRenderTarget()->numSamples()) |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 71 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) |
| 72 | , fOutputSwizzle(outputSwizzle) { |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 73 | // The kRequiresManualMSAAResolve flag better not be set if we are not multisampled or if |
| 74 | // MSAA resolve should happen automatically. |
| 75 | // |
| 76 | // From the other side, we don't know enough about the wrapped surface to assert when |
| 77 | // kRequiresManualMSAAResolve *should* be set. e.g., The caller might be wrapping a backend |
| 78 | // texture as a render target at this point but we wouldn't know it. |
| 79 | SkASSERT(!(this->numSamples() <= 1 || |
| 80 | fTarget->getContext()->priv().caps()->msaaResolvesAutomatically()) || |
| 81 | !this->requiresManualMSAAResolve()); |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 82 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 83 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 84 | int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { |
Brian Salomon | 34a2030 | 2018-12-18 12:03:07 -0500 | [diff] [blame] | 85 | return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles(); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 86 | } |
| 87 | |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 88 | bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 89 | if (this->isLazy()) { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 90 | return false; |
| 91 | } |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 92 | if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes, |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 93 | GrMipMapped::kNo, nullptr)) { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 94 | return false; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 95 | } |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 96 | |
| 97 | SkASSERT(this->peekRenderTarget()); |
| 98 | SkASSERT(!this->peekTexture()); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 99 | return true; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Chris Dalton | 215ff33 | 2019-07-02 09:38:22 -0600 | [diff] [blame] | 102 | bool GrRenderTargetProxy::canChangeStencilAttachment() const { |
| 103 | if (!fTarget) { |
| 104 | // If we aren't instantiated, then we definitely are an internal render target. Ganesh is |
| 105 | // free to change stencil attachments on internal render targets. |
| 106 | return true; |
| 107 | } |
| 108 | return fTarget->asRenderTarget()->canAttemptStencilAttachment(); |
| 109 | } |
| 110 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 111 | sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const { |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 112 | sk_sp<GrSurface> surface = this->createSurfaceImpl( |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 113 | resourceProvider, fSampleCnt, fNumStencilSamples, GrRenderable::kYes, GrMipMapped::kNo); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 114 | if (!surface) { |
| 115 | return nullptr; |
| 116 | } |
| 117 | SkASSERT(surface->asRenderTarget()); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 118 | SkASSERT(!surface->asTexture()); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 119 | return surface; |
| 120 | } |
| 121 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 122 | size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 123 | int colorSamplesPerPixel = this->numSamples(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 124 | if (colorSamplesPerPixel > 1) { |
| 125 | // Add one for the resolve buffer. |
| 126 | ++colorSamplesPerPixel; |
| 127 | } |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 128 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 129 | // TODO: do we have enough information to improve this worst case estimate? |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 130 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 131 | colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 134 | bool GrRenderTargetProxy::refsWrappedObjects() const { |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 135 | if (!this->isInstantiated()) { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 139 | GrSurface* surface = this->peekSurface(); |
| 140 | return surface->resourcePriv().refsWrappedObjects(); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 141 | } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 142 | |
| 143 | #ifdef SK_DEBUG |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 144 | void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 145 | // We do not check that surface->asTexture returns null since, when replaying DDLs we |
| 146 | // can fulfill a renderTarget-only proxy w/ a textureRenderTarget. |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 147 | |
| 148 | // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version |
| 149 | SkASSERT(surface->asRenderTarget()); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 150 | SkASSERT(surface->asRenderTarget()->numSamples() == this->numSamples()); |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 151 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 152 | GrInternalSurfaceFlags proxyFlags = fSurfaceFlags; |
| 153 | GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags(); |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 154 | SkASSERT(((int)proxyFlags & kGrInternalRenderTargetFlagsMask) == |
| 155 | ((int)surfaceFlags & kGrInternalRenderTargetFlagsMask)); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 156 | } |
| 157 | #endif |