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