bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 8 | #ifndef GrOpFlushState_DEFINED |
| 9 | #define GrOpFlushState_DEFINED |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 10 | |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 11 | #include <utility> |
Ben Wagner | 729a23f | 2019-05-17 16:29:34 -0400 | [diff] [blame] | 12 | #include "src/core/SkArenaAlloc.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/core/SkArenaAllocList.h" |
| 14 | #include "src/gpu/GrAppliedClip.h" |
| 15 | #include "src/gpu/GrBufferAllocPool.h" |
| 16 | #include "src/gpu/GrDeferredUpload.h" |
| 17 | #include "src/gpu/GrDeinstantiateProxyTracker.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTargetProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/ops/GrMeshDrawOp.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 20 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 21 | class GrGpu; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | class GrGpuCommandBuffer; |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 23 | class GrGpuRTCommandBuffer; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 24 | class GrResourceProvider; |
| 25 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 26 | /** Tracks the state across all the GrOps (really just the GrDrawOps) in a GrOpList flush. */ |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 27 | class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp::Target { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 28 | public: |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 29 | // vertexSpace and indexSpace may either be null or an alloation of size |
| 30 | // GrBufferAllocPool::kDefaultBufferSize. If the latter, then CPU memory is only allocated for |
| 31 | // vertices/indices when a buffer larger than kDefaultBufferSize is required. |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 32 | GrOpFlushState(GrGpu*, GrResourceProvider*, GrTokenTracker*, |
Brian Salomon | 601ac80 | 2019-02-07 13:37:16 -0500 | [diff] [blame] | 33 | sk_sp<GrBufferAllocPool::CpuBufferCache> = nullptr); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 34 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 35 | ~GrOpFlushState() final { this->reset(); } |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 36 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 37 | /** This is called after each op has a chance to prepare its draws and before the draws are |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 38 | executed. */ |
| 39 | void preExecuteDraws(); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 40 | |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 41 | void doUpload(GrDeferredTextureUploadFn&); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 42 | |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 43 | /** Called as ops are executed. Must be called in the same order as the ops were prepared. */ |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 44 | void executeDrawsAndUploadsForMeshDrawOp( |
Chris Dalton | baa1b35 | 2019-04-03 12:03:00 -0600 | [diff] [blame] | 45 | const GrOp* op, const SkRect& chainBounds, GrProcessorSet&&, |
| 46 | GrPipeline::InputFlags = GrPipeline::InputFlags::kNone, |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 47 | const GrUserStencilSettings* = &GrUserStencilSettings::kUnused); |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 48 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 49 | GrGpuCommandBuffer* commandBuffer() { return fCommandBuffer; } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 50 | // Helper function used by Ops that are only called via RenderTargetOpLists |
| 51 | GrGpuRTCommandBuffer* rtCommandBuffer(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 52 | void setCommandBuffer(GrGpuCommandBuffer* buffer) { fCommandBuffer = buffer; } |
| 53 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 54 | GrGpu* gpu() { return fGpu; } |
| 55 | |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 56 | void reset(); |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 57 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 58 | /** Additional data required on a per-op basis when executing GrOps. */ |
| 59 | struct OpArgs { |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 60 | GrSurfaceOrigin origin() const { return fProxy->origin(); } |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 61 | GrRenderTarget* renderTarget() const { return fProxy->peekRenderTarget(); } |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 62 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 63 | GrOp* fOp; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 64 | // TODO: do we still need the dst proxy here? |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 65 | GrRenderTargetProxy* fProxy; |
| 66 | GrAppliedClip* fAppliedClip; |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 67 | GrSwizzle fOutputSwizzle; |
Robert Phillips | bb581ce | 2017-05-29 15:05:15 -0400 | [diff] [blame] | 68 | GrXferProcessor::DstProxy fDstProxy; |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 69 | }; |
| 70 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 71 | void setOpArgs(OpArgs* opArgs) { fOpArgs = opArgs; } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 72 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 73 | const OpArgs& drawOpArgs() const { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 74 | SkASSERT(fOpArgs); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 75 | SkASSERT(fOpArgs->fOp); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 76 | return *fOpArgs; |
| 77 | } |
| 78 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 79 | /** Overrides of GrDeferredUploadTarget. */ |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 80 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 81 | const GrTokenTracker* tokenTracker() final { return fTokenTracker; } |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 82 | GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final; |
| 83 | GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 84 | |
| 85 | /** Overrides of GrMeshDrawOp::Target. */ |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 86 | void recordDraw( |
| 87 | sk_sp<const GrGeometryProcessor>, const GrMesh[], int meshCnt, |
| 88 | const GrPipeline::FixedDynamicState*, const GrPipeline::DynamicStateArrays*) final; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 89 | void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*, |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 90 | int* startVertex) final; |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 91 | uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) final; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 92 | void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 93 | sk_sp<const GrBuffer>*, int* startVertex, |
| 94 | int* actualVertexCount) final; |
| 95 | uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, |
| 96 | sk_sp<const GrBuffer>*, int* startIndex, |
| 97 | int* actualIndexCount) final; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 98 | void putBackIndices(int indexCount) final; |
| 99 | void putBackVertices(int vertices, size_t vertexStride) final; |
| 100 | GrRenderTargetProxy* proxy() const final { return fOpArgs->fProxy; } |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 101 | const GrAppliedClip* appliedClip() final { return fOpArgs->fAppliedClip; } |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 102 | GrAppliedClip detachAppliedClip() final; |
| 103 | const GrXferProcessor::DstProxy& dstProxy() const final { return fOpArgs->fDstProxy; } |
| 104 | GrDeferredUploadTarget* deferredUploadTarget() final { return this; } |
| 105 | const GrCaps& caps() const final; |
| 106 | GrResourceProvider* resourceProvider() const final { return fResourceProvider; } |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 107 | |
Herb Derby | 081e6f3 | 2019-01-16 13:46:02 -0500 | [diff] [blame] | 108 | GrStrikeCache* glyphCache() const final; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 109 | |
| 110 | // At this point we know we're flushing so full access to the GrAtlasManager is required (and |
| 111 | // permissible). |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 112 | GrAtlasManager* atlasManager() const final; |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 113 | |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 114 | GrDeinstantiateProxyTracker* deinstantiateProxyTracker() { return &fDeinstantiateProxyTracker; } |
| 115 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 116 | private: |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 117 | /** GrMeshDrawOp::Target override. */ |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 118 | SkArenaAlloc* allocator() override { return &fArena; } |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 119 | |
| 120 | struct InlineUpload { |
| 121 | InlineUpload(GrDeferredTextureUploadFn&& upload, GrDeferredUploadToken token) |
| 122 | : fUpload(std::move(upload)), fUploadBeforeToken(token) {} |
| 123 | GrDeferredTextureUploadFn fUpload; |
| 124 | GrDeferredUploadToken fUploadBeforeToken; |
| 125 | }; |
| 126 | |
| 127 | // A set of contiguous draws that share a draw token, geometry processor, and pipeline. The |
| 128 | // meshes for the draw are stored in the fMeshes array. The reason for coalescing meshes |
| 129 | // that share a geometry processor into a Draw is that it allows the Gpu object to setup |
| 130 | // the shared state once and then issue draws for each mesh. |
| 131 | struct Draw { |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 132 | ~Draw(); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 133 | sk_sp<const GrGeometryProcessor> fGeometryProcessor; |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 134 | const GrPipeline::FixedDynamicState* fFixedDynamicState; |
| 135 | const GrPipeline::DynamicStateArrays* fDynamicStateArrays; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 136 | const GrMesh* fMeshes = nullptr; |
Brian Osman | e801210 | 2018-11-29 14:05:07 -0500 | [diff] [blame] | 137 | const GrOp* fOp = nullptr; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 138 | int fMeshCnt = 0; |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 141 | // Storage for ops' pipelines, draws, and inline uploads. |
| 142 | SkArenaAlloc fArena{sizeof(GrPipeline) * 100}; |
| 143 | |
| 144 | // Store vertex and index data on behalf of ops that are flushed. |
| 145 | GrVertexBufferAllocPool fVertexPool; |
| 146 | GrIndexBufferAllocPool fIndexPool; |
| 147 | |
| 148 | // Data stored on behalf of the ops being flushed. |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 149 | SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads; |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 150 | SkArenaAllocList<InlineUpload> fInlineUploads; |
| 151 | SkArenaAllocList<Draw> fDraws; |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 152 | |
| 153 | // All draws we store have an implicit draw token. This is the draw token for the first draw |
| 154 | // in fDraws. |
| 155 | GrDeferredUploadToken fBaseDrawToken = GrDeferredUploadToken::AlreadyFlushedToken(); |
| 156 | |
| 157 | // Info about the op that is currently preparing or executing using the flush state or null if |
| 158 | // an op is not currently preparing of executing. |
| 159 | OpArgs* fOpArgs = nullptr; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 160 | |
Brian Salomon | 6d4b65e | 2017-05-03 17:06:09 -0400 | [diff] [blame] | 161 | GrGpu* fGpu; |
| 162 | GrResourceProvider* fResourceProvider; |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 163 | GrTokenTracker* fTokenTracker; |
Brian Salomon | 7dc6e75 | 2017-11-02 11:34:51 -0400 | [diff] [blame] | 164 | GrGpuCommandBuffer* fCommandBuffer = nullptr; |
| 165 | |
| 166 | // Variables that are used to track where we are in lists as ops are executed |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 167 | SkArenaAllocList<Draw>::Iter fCurrDraw; |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 168 | SkArenaAllocList<InlineUpload>::Iter fCurrUpload; |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 169 | |
| 170 | // Used to track the proxies that need to be deinstantiated after we finish a flush |
| 171 | GrDeinstantiateProxyTracker fDeinstantiateProxyTracker; |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 174 | #endif |