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, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 26 | SkISize dimensions, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 27 | int sampleCount, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 28 | SkBackingFit fit, |
| 29 | SkBudgeted budgeted, |
| 30 | GrProtected isProtected, |
| 31 | GrInternalSurfaceFlags surfaceFlags, |
| 32 | UseAllocator useAllocator) |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 33 | : INHERITED(format, dimensions, fit, budgeted, isProtected, surfaceFlags, useAllocator) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 34 | , fSampleCnt(sampleCount) |
Greg Daniel | baf8d99 | 2019-10-29 14:14:32 -0400 | [diff] [blame] | 35 | , fWrapsVkSecondaryCB(WrapsVkSecondaryCB::kNo) {} |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 36 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 37 | // Lazy-callback version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 38 | GrRenderTargetProxy::GrRenderTargetProxy(LazyInstantiateCallback&& callback, |
| 39 | const GrBackendFormat& format, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 40 | SkISize dimensions, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 41 | int sampleCount, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 42 | SkBackingFit fit, |
| 43 | SkBudgeted budgeted, |
| 44 | GrProtected isProtected, |
| 45 | GrInternalSurfaceFlags surfaceFlags, |
| 46 | UseAllocator useAllocator, |
| 47 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 48 | : INHERITED(std::move(callback), format, dimensions, fit, budgeted, isProtected, |
| 49 | surfaceFlags, useAllocator) |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 50 | , fSampleCnt(sampleCount) |
Greg Daniel | baf8d99 | 2019-10-29 14:14:32 -0400 | [diff] [blame] | 51 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) {} |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 52 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 53 | // Wrapped version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 54 | GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 55 | UseAllocator useAllocator, |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 56 | WrapsVkSecondaryCB wrapsVkSecondaryCB) |
Brian Salomon | df1bd6d | 2020-03-26 20:37:01 -0400 | [diff] [blame] | 57 | : INHERITED(std::move(surf), SkBackingFit::kExact, useAllocator) |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 58 | , fSampleCnt(fTarget->asRenderTarget()->numSamples()) |
Greg Daniel | baf8d99 | 2019-10-29 14:14:32 -0400 | [diff] [blame] | 59 | , fWrapsVkSecondaryCB(wrapsVkSecondaryCB) { |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 60 | // The kRequiresManualMSAAResolve flag better not be set if we are not multisampled or if |
| 61 | // MSAA resolve should happen automatically. |
| 62 | // |
| 63 | // From the other side, we don't know enough about the wrapped surface to assert when |
| 64 | // kRequiresManualMSAAResolve *should* be set. e.g., The caller might be wrapping a backend |
| 65 | // texture as a render target at this point but we wouldn't know it. |
| 66 | SkASSERT(!(this->numSamples() <= 1 || |
| 67 | fTarget->getContext()->priv().caps()->msaaResolvesAutomatically()) || |
| 68 | !this->requiresManualMSAAResolve()); |
Robert Phillips | c4f0a82 | 2017-06-13 08:11:36 -0400 | [diff] [blame] | 69 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 70 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 71 | int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { |
Jim Van Verth | 5fab909 | 2019-11-25 21:23:53 +0000 | [diff] [blame] | 72 | return this->glRTFBOIDIs0() ? 0 : caps.maxWindowRectangles(); |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 73 | } |
| 74 | |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 75 | bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 76 | if (this->isLazy()) { |
Greg Daniel | 0a375db | 2018-02-01 12:21:39 -0500 | [diff] [blame] | 77 | return false; |
| 78 | } |
Chris Dalton | 0b68dda | 2019-11-07 21:08:03 -0700 | [diff] [blame] | 79 | if (!this->instantiateImpl(resourceProvider, fSampleCnt, GrRenderable::kYes, GrMipMapped::kNo, |
| 80 | nullptr)) { |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 81 | return false; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 82 | } |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 83 | |
| 84 | SkASSERT(this->peekRenderTarget()); |
| 85 | SkASSERT(!this->peekTexture()); |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 86 | return true; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Chris Dalton | 215ff33 | 2019-07-02 09:38:22 -0600 | [diff] [blame] | 89 | bool GrRenderTargetProxy::canChangeStencilAttachment() const { |
| 90 | if (!fTarget) { |
| 91 | // If we aren't instantiated, then we definitely are an internal render target. Ganesh is |
| 92 | // free to change stencil attachments on internal render targets. |
| 93 | return true; |
| 94 | } |
| 95 | return fTarget->asRenderTarget()->canAttemptStencilAttachment(); |
| 96 | } |
| 97 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 98 | sk_sp<GrSurface> GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const { |
Chris Dalton | 0b68dda | 2019-11-07 21:08:03 -0700 | [diff] [blame] | 99 | sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, |
| 100 | GrRenderable::kYes, GrMipMapped::kNo); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 101 | if (!surface) { |
| 102 | return nullptr; |
| 103 | } |
| 104 | SkASSERT(surface->asRenderTarget()); |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 105 | SkASSERT(!surface->asTexture()); |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 106 | return surface; |
| 107 | } |
| 108 | |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 109 | size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 110 | int colorSamplesPerPixel = this->numSamples(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 111 | if (colorSamplesPerPixel > 1) { |
| 112 | // Add one for the resolve buffer. |
| 113 | ++colorSamplesPerPixel; |
| 114 | } |
Greg Daniel | e252f08 | 2017-10-23 16:05:23 -0400 | [diff] [blame] | 115 | |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 116 | // TODO: do we have enough information to improve this worst case estimate? |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 117 | return GrSurface::ComputeSize(caps, this->backendFormat(), this->dimensions(), |
Greg Daniel | a00bcad | 2019-10-11 13:21:48 -0400 | [diff] [blame] | 118 | colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact()); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 119 | } |
| 120 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 121 | bool GrRenderTargetProxy::refsWrappedObjects() const { |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 122 | if (!this->isInstantiated()) { |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 123 | return false; |
| 124 | } |
| 125 | |
Robert Phillips | b520476 | 2019-06-19 14:12:13 -0400 | [diff] [blame] | 126 | GrSurface* surface = this->peekSurface(); |
| 127 | return surface->resourcePriv().refsWrappedObjects(); |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 128 | } |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 129 | |
Brian Salomon | 63410e9 | 2020-03-23 18:32:50 -0400 | [diff] [blame] | 130 | GrSurfaceProxy::LazySurfaceDesc GrRenderTargetProxy::callbackDesc() const { |
| 131 | // We only expect exactly sized lazy RT proxies. |
| 132 | SkASSERT(!this->isFullyLazy()); |
| 133 | SkASSERT(this->isFunctionallyExact()); |
| 134 | return { |
| 135 | this->dimensions(), |
| 136 | SkBackingFit::kExact, |
| 137 | GrRenderable::kYes, |
| 138 | GrMipMapped::kNo, |
| 139 | this->numSamples(), |
| 140 | this->backendFormat(), |
| 141 | this->isProtected(), |
| 142 | this->isBudgeted(), |
| 143 | }; |
| 144 | } |
| 145 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 146 | #ifdef SK_DEBUG |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 147 | void GrRenderTargetProxy::onValidateSurface(const GrSurface* surface) { |
Robert Phillips | b45f47d | 2019-02-03 17:17:54 -0500 | [diff] [blame] | 148 | // We do not check that surface->asTexture returns null since, when replaying DDLs we |
| 149 | // can fulfill a renderTarget-only proxy w/ a textureRenderTarget. |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 150 | |
| 151 | // Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version |
| 152 | SkASSERT(surface->asRenderTarget()); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 153 | SkASSERT(surface->asRenderTarget()->numSamples() == this->numSamples()); |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 154 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 155 | GrInternalSurfaceFlags proxyFlags = fSurfaceFlags; |
| 156 | GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags(); |
Robert Phillips | 350db7c | 2020-03-06 13:39:41 -0500 | [diff] [blame] | 157 | if (proxyFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0 && this->numSamples() == 1) { |
| 158 | // Ganesh never internally creates FBO0 proxies or surfaces so this must be a wrapped |
| 159 | // proxy. In this case, with no MSAA, rendering to FBO0 is strictly more limited than |
| 160 | // rendering to an arbitrary surface so we allow a non-FBO0 surface to be matched with |
| 161 | // the proxy. |
| 162 | surfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 163 | } |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 164 | SkASSERT(((int)proxyFlags & kGrInternalRenderTargetFlagsMask) == |
| 165 | ((int)surfaceFlags & kGrInternalRenderTargetFlagsMask)); |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 166 | } |
| 167 | #endif |