egdaniel | 066df7c | 2016-06-08 14:02:27 -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 | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 8 | #ifndef GrOpsRenderPass_DEFINED |
| 9 | #define GrOpsRenderPass_DEFINED |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkDrawable.h" |
| 12 | #include "src/gpu/GrPipeline.h" |
| 13 | #include "src/gpu/ops/GrDrawOp.h" |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 14 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 15 | class GrOpFlushState; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 16 | class GrFixedClip; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 17 | class GrGpu; |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 18 | class GrMesh; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 19 | class GrPipeline; |
| 20 | class GrPrimitiveProcessor; |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 21 | class GrProgramInfo; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 22 | class GrRenderTarget; |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 23 | class GrSemaphore; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 24 | struct SkIRect; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 25 | struct SkRect; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 26 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 27 | /** |
| 28 | * The GrOpsRenderPass is a series of commands (draws, clears, and discards), which all target the |
| 29 | * same render target. It is possible that these commands execute immediately (GL), or get buffered |
| 30 | * up for later execution (Vulkan). GrOps execute into a GrOpsRenderPass. |
| 31 | */ |
| 32 | class GrOpsRenderPass { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 33 | public: |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 34 | virtual ~GrOpsRenderPass() {} |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 35 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 36 | struct LoadAndStoreInfo { |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 37 | GrLoadOp fLoadOp; |
| 38 | GrStoreOp fStoreOp; |
| 39 | SkPMColor4f fClearColor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 42 | // Load-time clears of the stencil buffer are always to 0 so we don't store |
| 43 | // an 'fStencilClearValue' |
| 44 | struct StencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 45 | GrLoadOp fLoadOp; |
| 46 | GrStoreOp fStoreOp; |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 49 | virtual void begin() = 0; |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 50 | // Signals the end of recording to the GrOpsRenderPass and that it can now be submitted. |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 51 | virtual void end() = 0; |
| 52 | |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 53 | // Updates the internal pipeline state for drawing with the provided GrProgramInfo. |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 54 | // Enters an internal "bad" state if the pipeline could not be set. |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 55 | void bindPipeline(const GrProgramInfo&, const SkRect& drawBounds); |
| 56 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 57 | // The scissor rect is always dynamic state and therefore not stored on GrPipeline. If scissor |
| 58 | // test is enabled on the current pipeline, then the client must call setScissorRect() before |
| 59 | // drawing. The scissor rect may also be updated between draws without having to bind a new |
| 60 | // pipeline. |
| 61 | void setScissorRect(const SkIRect&); |
| 62 | |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame^] | 63 | // Binds textures for the primitive processor and any FP on the GrPipeline. Texture bindings are |
| 64 | // dynamic state and therefore not set during bindPipeline(). If the current program uses |
| 65 | // textures, then the client must call bindTextures() before drawing. The primitive processor |
| 66 | // textures may also be updated between draws by calling bindTextures() again with a different |
| 67 | // array for primProcTextures. (On subsequent calls, if the backend is capable of updating the |
| 68 | // primitive processor textures independently, then it will automatically skip re-binding |
| 69 | // FP textures from GrPipeline.) |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 70 | // |
| 71 | // If the current program does not use textures, this is a no-op. |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame^] | 72 | void bindTextures(const GrPrimitiveProcessor&, const GrSurfaceProxy* const primProcTextures[], |
| 73 | const GrPipeline&); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 74 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 75 | void bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer, |
| 76 | const GrBuffer* vertexBuffer, GrPrimitiveRestart = GrPrimitiveRestart::kNo); |
| 77 | |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 78 | // Draws the given array of meshes using the current pipeline state. The client must call |
| 79 | // bindPipeline() before using this method. |
| 80 | // |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 81 | // NOTE: This method will soon be deleted. While it continues to exist, it takes care of calling |
| 82 | // setScissor() and bindTextures() on the client's behalf. |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 83 | void drawMeshes(const GrProgramInfo&, const GrMesh[], int meshCount); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 84 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 85 | // These methods issue draws using the current pipeline state. Before drawing, the caller must |
| 86 | // configure the pipeline and dynamic state: |
| 87 | // |
| 88 | // - Call bindPipeline() |
| 89 | // - If the scissor test is enabled, call setScissorRect() |
| 90 | // - If the current program uses textures, call bindTextures() |
| 91 | // - Call bindBuffers() (even if all buffers are null) |
| 92 | void draw(int vertexCount, int baseVertex); |
| 93 | void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 94 | int baseVertex); |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 95 | void drawInstanced(int instanceCount, int baseInstance, int vertexCount, int baseVertex); |
| 96 | void drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance, |
| 97 | int baseVertex); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 98 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 99 | // Performs an upload of vertex data in the middle of a set of a set of draws |
Brian Salomon | 943ed79 | 2017-10-30 09:37:55 -0400 | [diff] [blame] | 100 | virtual void inlineUpload(GrOpFlushState*, GrDeferredTextureUploadFn&) = 0; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 101 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 102 | /** |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 103 | * Clear the owned render target. Ignores the draw state and clip. |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 104 | */ |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 105 | void clear(const GrFixedClip&, const SkPMColor4f&); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 106 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 107 | void clearStencilClip(const GrFixedClip&, bool insideStencilMask); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 108 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 109 | /** |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 110 | * Executes the SkDrawable object for the underlying backend. |
| 111 | */ |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 112 | void executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>); |
Greg Daniel | 64cc9aa | 2018-10-19 13:54:56 -0400 | [diff] [blame] | 113 | |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 114 | protected: |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 115 | GrOpsRenderPass() : fOrigin(kTopLeft_GrSurfaceOrigin), fRenderTarget(nullptr) {} |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 116 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 117 | GrOpsRenderPass(GrRenderTarget* rt, GrSurfaceOrigin origin) |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 118 | : fOrigin(origin) |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 119 | , fRenderTarget(rt) { |
| 120 | } |
| 121 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 122 | void set(GrRenderTarget* rt, GrSurfaceOrigin origin) { |
| 123 | SkASSERT(!fRenderTarget); |
| 124 | |
| 125 | fRenderTarget = rt; |
| 126 | fOrigin = origin; |
| 127 | } |
| 128 | |
| 129 | GrSurfaceOrigin fOrigin; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 130 | GrRenderTarget* fRenderTarget; |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 131 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 132 | private: |
| 133 | virtual GrGpu* gpu() = 0; |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 134 | |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 135 | bool prepareToDraw(); |
| 136 | |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 137 | // overridden by backend-specific derived class to perform the rendering command. |
| 138 | virtual bool onBindPipeline(const GrProgramInfo&, const SkRect& drawBounds) = 0; |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 139 | virtual void onSetScissorRect(const SkIRect&) = 0; |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame^] | 140 | virtual bool onBindTextures(const GrPrimitiveProcessor&, |
| 141 | const GrSurfaceProxy* const primProcTextures[], |
| 142 | const GrPipeline&) = 0; |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 143 | virtual void onBindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer, |
| 144 | const GrBuffer* vertexBuffer, GrPrimitiveRestart) = 0; |
| 145 | virtual void onDraw(int vertexCount, int baseVertex) = 0; |
| 146 | virtual void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, |
| 147 | uint16_t maxIndexValue, int baseVertex) = 0; |
| 148 | virtual void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount, |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 149 | int baseVertex) = 0; |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 150 | virtual void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, |
| 151 | int baseInstance, int baseVertex) = 0; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 152 | virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 153 | virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0; |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 154 | virtual void onExecuteDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler>) {} |
| 155 | |
| 156 | enum class DrawPipelineStatus { |
| 157 | kOk = 0, |
| 158 | kNotConfigured, |
| 159 | kFailedToBind |
| 160 | }; |
| 161 | |
| 162 | DrawPipelineStatus fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 163 | GrXferBarrierType fXferBarrierType; |
| 164 | |
| 165 | #ifdef SK_DEBUG |
| 166 | enum class DynamicStateStatus { |
| 167 | kDisabled, |
| 168 | kUninitialized, |
| 169 | kConfigured |
| 170 | }; |
| 171 | |
| 172 | DynamicStateStatus fScissorStatus = DynamicStateStatus::kDisabled; |
| 173 | DynamicStateStatus fTextureBindingStatus = DynamicStateStatus::kDisabled; |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 174 | bool fHasIndexBuffer = false; |
| 175 | DynamicStateStatus fInstanceBufferStatus = DynamicStateStatus::kDisabled; |
| 176 | DynamicStateStatus fVertexBufferStatus = DynamicStateStatus::kDisabled; |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 177 | #endif |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 178 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 179 | typedef GrOpsRenderPass INHERITED; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | #endif |