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