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 | |
| 8 | #ifndef GrGpuCommandBuffer_DEFINED |
| 9 | #define GrGpuCommandBuffer_DEFINED |
| 10 | |
| 11 | #include "GrColor.h" |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 12 | #include "GrPipeline.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 13 | #include "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; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 21 | class GrRenderTarget; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | struct SkIRect; |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 23 | struct SkRect; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 24 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 25 | /** |
| 26 | * The GrGpuCommandBuffer is a series of commands (draws, clears, and discards), which all target |
| 27 | * the same render target. It is possible that these commands execute immediately (GL), or get |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 28 | * buffered up for later execution (Vulkan). GrOps will execute their draw commands into a |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 29 | * GrGpuCommandBuffer. |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 30 | * |
| 31 | * Ideally we'd know the GrRenderTarget, or at least its properties when the GrGpuCommandBuffer, is |
| 32 | * created. We also then wouldn't include it in the GrPipeline or as a parameter to the clear and |
| 33 | * discard methods. The logical place for that will be in GrRenderTargetOpList post-MDB. For now |
| 34 | * the render target is redundantly passed to each operation, though it will always be the same |
| 35 | * render target for a given command buffer even pre-MDB. |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 36 | */ |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 37 | class GrGpuCommandBuffer { |
| 38 | public: |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 39 | enum class LoadOp { |
| 40 | kLoad, |
| 41 | kClear, |
| 42 | kDiscard, |
| 43 | }; |
| 44 | |
| 45 | enum class StoreOp { |
| 46 | kStore, |
| 47 | kDiscard, |
| 48 | }; |
| 49 | |
| 50 | struct LoadAndStoreInfo { |
| 51 | LoadOp fLoadOp; |
| 52 | StoreOp fStoreOp; |
| 53 | GrColor fClearColor; |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | GrGpuCommandBuffer() {} |
| 57 | virtual ~GrGpuCommandBuffer() {} |
| 58 | |
| 59 | // Signals the end of recording to the command buffer and that it can now be submitted. |
| 60 | virtual void end() = 0; |
| 61 | |
| 62 | // Sends the command buffer off to the GPU object to execute the commands built up in the |
| 63 | // buffer. The gpu object is allowed to defer execution of the commands until it is flushed. |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 64 | void submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 65 | |
| 66 | // We pass in an array of meshCount GrMesh to the draw. The backend should loop over each |
| 67 | // GrMesh object and emit a draw for it. Each draw will use the same GrPipeline and |
| 68 | // GrPrimitiveProcessor. This may fail if the draw would exceed any resource limits (e.g. |
| 69 | // number of vertex attributes is too large). |
| 70 | bool draw(const GrPipeline&, |
| 71 | const GrPrimitiveProcessor&, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 72 | const GrMesh[], |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 73 | const GrPipeline::DynamicState[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 74 | int meshCount, |
| 75 | const SkRect& bounds); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 76 | |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 77 | // Performs an upload of vertex data in the middle of a set of a set of draws |
Greg Daniel | dbd11ec | 2017-03-21 16:56:31 -0400 | [diff] [blame] | 78 | virtual void inlineUpload(GrOpFlushState* state, GrDrawOp::DeferredUploadFn& upload, |
| 79 | GrRenderTarget* rt) = 0; |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 80 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 81 | /** |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 82 | * Clear the passed in render target. Ignores the draw state and clip. |
| 83 | */ |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 84 | void clear(GrRenderTarget*, const GrFixedClip&, GrColor); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 85 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 86 | void clearStencilClip(GrRenderTarget*, const GrFixedClip&, bool insideStencilMask); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 87 | |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 88 | /** |
Greg Daniel | 77b53f6 | 2016-10-18 11:48:51 -0400 | [diff] [blame] | 89 | * Discards the contents render target. nullptr indicates that the current render target should |
| 90 | * be discarded. |
| 91 | */ |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 92 | // TODO: This should be removed in the future to favor using the load and store ops for discard |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 93 | virtual void discard(GrRenderTarget*) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 94 | |
| 95 | private: |
| 96 | virtual GrGpu* gpu() = 0; |
Greg Daniel | 65a0927 | 2016-10-12 09:47:22 -0400 | [diff] [blame] | 97 | virtual GrRenderTarget* renderTarget() = 0; |
| 98 | |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 99 | virtual void onSubmit() = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 100 | |
| 101 | // overridden by backend-specific derived class to perform the draw call. |
| 102 | virtual void onDraw(const GrPipeline&, |
| 103 | const GrPrimitiveProcessor&, |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 104 | const GrMesh[], |
| 105 | const GrPipeline::DynamicState[], |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 106 | int meshCount, |
| 107 | const SkRect& bounds) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 108 | |
| 109 | // overridden by backend-specific derived class to perform the clear. |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 110 | virtual void onClear(GrRenderTarget*, const GrFixedClip&, GrColor) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 111 | |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 112 | virtual void onClearStencilClip(GrRenderTarget*, const GrFixedClip&, |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 113 | bool insideStencilMask) = 0; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 114 | |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | #endif |