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 | |
| 8 | #ifndef GrRenderTargetProxy_DEFINED |
| 9 | #define GrRenderTargetProxy_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrTypesPriv.h" |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 12 | #include "src/gpu/GrCaps.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrSurfaceProxy.h" |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrSwizzle.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 15 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 16 | class GrResourceProvider; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 17 | class GrRenderTargetProxyPriv; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 18 | |
| 19 | // This class delays the acquisition of RenderTargets until they are actually |
| 20 | // required |
| 21 | // Beware: the uniqueID of the RenderTargetProxy will usually be different than |
| 22 | // the uniqueID of the RenderTarget it represents! |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 23 | class GrRenderTargetProxy : virtual public GrSurfaceProxy { |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 24 | public: |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 25 | GrRenderTargetProxy* asRenderTargetProxy() override { return this; } |
| 26 | const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; } |
| 27 | |
| 28 | // Actually instantiate the backing rendertarget, if necessary. |
Robert Phillips | 10d1721 | 2019-04-24 14:09:10 -0400 | [diff] [blame] | 29 | bool instantiate(GrResourceProvider*) override; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 30 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 31 | bool canUseMixedSamples(const GrCaps& caps) const { |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 32 | return caps.mixedSamplesSupport() && !this->glRTFBOIDIs0() && |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 33 | caps.internalMultisampleCount(this->backendFormat()) > 0 && |
Chris Dalton | 215ff33 | 2019-07-02 09:38:22 -0600 | [diff] [blame] | 34 | this->canChangeStencilAttachment(); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 35 | } |
| 36 | |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 37 | /* |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 38 | * Indicate that a draw to this proxy requires stencil, and how many stencil samples it needs. |
| 39 | * The number of stencil samples on this proxy will be equal to the largest sample count passed |
| 40 | * to this method. |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 41 | */ |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 42 | void setNeedsStencil(int8_t numStencilSamples) { |
| 43 | SkASSERT(numStencilSamples >= fSampleCnt); |
| 44 | fNumStencilSamples = SkTMax(numStencilSamples, fNumStencilSamples); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the number of stencil samples required by this proxy. |
| 49 | * NOTE: Once instantiated, the actual render target may have more samples, but it is guaranteed |
| 50 | * to have at least this many. (After a multisample stencil buffer has been attached to a render |
| 51 | * target, we never "downgrade" it to one with fewer samples.) |
| 52 | */ |
| 53 | int numStencilSamples() const { return fNumStencilSamples; } |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 54 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 55 | /** |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 56 | * Returns the number of samples/pixel in the color buffer (One if non-MSAA). |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 57 | */ |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 58 | int numSamples() const { return fSampleCnt; } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 59 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 60 | int maxWindowRectangles(const GrCaps& caps) const; |
| 61 | |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 62 | const GrSwizzle& outputSwizzle() const { return fOutputSwizzle; } |
| 63 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 64 | bool wrapsVkSecondaryCB() const { return fWrapsVkSecondaryCB == WrapsVkSecondaryCB::kYes; } |
| 65 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 66 | void markMSAADirty() { |
| 67 | SkASSERT(this->requiresManualMSAAResolve()); |
| 68 | fIsMSAADirty = true; |
| 69 | } |
| 70 | void markMSAAResolved() { |
| 71 | SkASSERT(this->requiresManualMSAAResolve()); |
| 72 | fIsMSAADirty = false; |
| 73 | } |
| 74 | bool isMSAADirty() const { |
| 75 | SkASSERT(!fIsMSAADirty || this->requiresManualMSAAResolve()); |
| 76 | return fIsMSAADirty; |
| 77 | } |
| 78 | |
Robert Phillips | e2f7d18 | 2016-12-15 09:23:05 -0500 | [diff] [blame] | 79 | // TODO: move this to a priv class! |
| 80 | bool refsWrappedObjects() const; |
| 81 | |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 82 | // Provides access to special purpose functions. |
| 83 | GrRenderTargetProxyPriv rtPriv(); |
| 84 | const GrRenderTargetProxyPriv rtPriv() const; |
| 85 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 86 | protected: |
Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 87 | friend class GrProxyProvider; // for ctors |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 88 | friend class GrRenderTargetProxyPriv; |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 89 | |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 90 | // Deferred version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 91 | GrRenderTargetProxy(const GrCaps&, |
| 92 | const GrBackendFormat&, |
| 93 | const GrSurfaceDesc&, |
| 94 | int sampleCount, |
| 95 | GrSurfaceOrigin, |
| 96 | const GrSwizzle& textureSwizzle, |
| 97 | const GrSwizzle& outputSwizzle, |
| 98 | SkBackingFit, |
| 99 | SkBudgeted, |
| 100 | GrProtected, |
| 101 | GrInternalSurfaceFlags, |
| 102 | UseAllocator); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 103 | |
Greg Daniel | b085fa9 | 2019-03-05 16:55:12 -0500 | [diff] [blame] | 104 | enum class WrapsVkSecondaryCB : bool { kNo = false, kYes = true }; |
| 105 | |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 106 | // Lazy-callback version |
Greg Daniel | 65fa8ca | 2018-01-10 17:06:31 -0500 | [diff] [blame] | 107 | // There are two main use cases for lazily-instantiated proxies: |
| 108 | // basic knowledge - width, height, config, samples, origin are known |
| 109 | // minimal knowledge - only config is known. |
| 110 | // |
| 111 | // The basic knowledge version is used for DDL where we know the type of proxy we are going to |
| 112 | // use, but we don't have access to the GPU yet to instantiate it. |
| 113 | // |
| 114 | // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not |
| 115 | // know the final size until flush time. |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 116 | GrRenderTargetProxy(LazyInstantiateCallback&&, |
| 117 | const GrBackendFormat&, |
| 118 | const GrSurfaceDesc&, |
| 119 | int sampleCount, |
| 120 | GrSurfaceOrigin, |
| 121 | const GrSwizzle& textureSwizzle, |
| 122 | const GrSwizzle& outputSwizzle, |
| 123 | SkBackingFit, |
| 124 | SkBudgeted, |
| 125 | GrProtected, |
| 126 | GrInternalSurfaceFlags, |
| 127 | UseAllocator, |
| 128 | WrapsVkSecondaryCB); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 129 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 130 | // Wrapped version |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 131 | GrRenderTargetProxy(sk_sp<GrSurface>, |
| 132 | GrSurfaceOrigin, |
| 133 | const GrSwizzle& textureSwizzle, |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 134 | const GrSwizzle& outputSwizzle, |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 135 | UseAllocator, |
| 136 | WrapsVkSecondaryCB = WrapsVkSecondaryCB::kNo); |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 137 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 138 | sk_sp<GrSurface> createSurface(GrResourceProvider*) const override; |
| 139 | |
Robert Phillips | 84a8120 | 2016-11-04 11:59:10 -0400 | [diff] [blame] | 140 | private: |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 141 | void setGLRTFBOIDIs0() { |
| 142 | fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 143 | } |
| 144 | bool glRTFBOIDIs0() const { |
| 145 | return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0; |
| 146 | } |
Chris Dalton | 215ff33 | 2019-07-02 09:38:22 -0600 | [diff] [blame] | 147 | bool canChangeStencilAttachment() const; |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 148 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 149 | size_t onUninstantiatedGpuMemorySize() const override; |
Greg Daniel | 849dce1 | 2018-04-24 14:32:53 -0400 | [diff] [blame] | 150 | SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 151 | |
Brian Osman | 086679b | 2018-09-10 16:26:51 -0400 | [diff] [blame] | 152 | // WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings |
| 153 | // when instantiating GrTextureRenderTargetProxy. The std::function in GrSurfaceProxy makes |
| 154 | // each class in the diamond require 16 byte alignment. Clang appears to layout the fields for |
| 155 | // each class to achieve the necessary alignment. However, ASAN checks the alignment of 'this' |
| 156 | // in the constructors, and always looks for the full 16 byte alignment, even if the fields in |
| 157 | // that particular class don't require it. Changing the size of this object can move the start |
| 158 | // address of other types, leading to this problem. |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 159 | int8_t fSampleCnt; |
| 160 | int8_t fNumStencilSamples = 0; |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 161 | WrapsVkSecondaryCB fWrapsVkSecondaryCB; |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 162 | GrSwizzle fOutputSwizzle; |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 163 | // Indicates whether some sub-rectangle of the render target requires MSAA resolve. We currently |
| 164 | // rely on the GrRenderTarget itself to track the actual dirty rect. |
| 165 | // TODO: In the future, convert the flag to a dirty rect and quit tracking it in GrRenderTarget. |
| 166 | bool fIsMSAADirty = false; |
Greg Daniel | 2c19e7f | 2019-06-18 13:29:21 -0400 | [diff] [blame] | 167 | // This is to fix issue in large comment above. Without the padding we end 6 bytes into a 16 |
| 168 | // byte range, so the GrTextureProxy ends up starting 8 byte aligned by not 16. We add the |
| 169 | // padding here to get us right up to the 16 byte alignment (technically any padding of 3-10 |
| 170 | // bytes would work since it always goes up to 8 byte alignment, but we use 10 to more explicit |
| 171 | // about what we're doing). |
| 172 | char fDummyPadding[10]; |
Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 173 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 174 | typedef GrSurfaceProxy INHERITED; |
| 175 | }; |
| 176 | |
| 177 | #endif |