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