| 1 |
/* |
| 2 |
* Copyright 2021 Google LLC |
| 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 GrMeshDrawTarget_DEFINED |
| 9 |
#define GrMeshDrawTarget_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" // IWYU pragma: keep |
| 12 |
#include "include/private/base/SkTArray.h" |
| 13 |
#include "src/base/SkArenaAlloc.h" |
| 14 |
#include "src/gpu/ganesh/GrAppliedClip.h" |
| 15 |
#include "src/gpu/ganesh/GrDrawIndirectCommand.h" |
| 16 |
#include "src/gpu/ganesh/GrSimpleMesh.h" |
| 17 |
|
| 18 |
#include <cstddef> |
| 19 |
#include <cstdint> |
| 20 |
|
| 21 |
class GrAtlasManager; |
| 22 |
class GrBuffer; |
| 23 |
class GrCaps; |
| 24 |
class GrDeferredUploadTarget; |
| 25 |
class GrDstProxyView; |
| 26 |
class GrGeometryProcessor; |
| 27 |
class GrRenderTargetProxy; |
| 28 |
class GrResourceProvider; |
| 29 |
class GrSurfaceProxy; |
| 30 |
class GrSurfaceProxyView; |
| 31 |
class GrThreadSafeCache; |
| 32 |
enum class GrLoadOp; |
| 33 |
enum class GrPrimitiveType : uint8_t; |
| 34 |
enum class GrXferBarrierFlags; |
| 35 |
|
| 36 |
namespace skgpu::ganesh { |
| 37 |
class SmallPathAtlasMgr; |
| 38 |
} |
| 39 |
|
| 40 |
namespace skgpu { |
| 41 |
struct IndexWriter; |
| 42 |
struct VertexWriter; |
| 43 |
} // namespace skgpu |
| 44 |
|
| 45 |
namespace sktext::gpu { |
| 46 |
class StrikeCache; |
| 47 |
} |
| 48 |
|
| 49 |
/* |
| 50 |
* Abstract interface that supports creating vertices, indices, and meshes, as well as |
| 51 |
* invoking GPU draw operations. |
| 52 |
*/ |
| 53 |
class GrMeshDrawTarget { |
| 54 |
public: |
| 55 |
virtual ~GrMeshDrawTarget() {} |
| 56 |
|
| 57 |
/** Adds a draw of a mesh. 'primProcProxies' must have |
| 58 |
* GrGeometryProcessor::numTextureSamplers() entries. Can be null if no samplers. |
| 59 |
*/ |
| 60 |
virtual void recordDraw(const GrGeometryProcessor*, |
| 61 |
const GrSimpleMesh[], |
| 62 |
int meshCnt, |
| 63 |
const GrSurfaceProxy* const primProcProxies[], |
| 64 |
GrPrimitiveType) = 0; |
| 65 |
|
| 66 |
/** |
| 67 |
* Helper for drawing GrSimpleMesh(es) with zero primProc textures. |
| 68 |
*/ |
| 69 |
void recordDraw(const GrGeometryProcessor* gp, |
| 70 |
const GrSimpleMesh meshes[], |
| 71 |
int meshCnt, |
| 72 |
GrPrimitiveType primitiveType) { |
| 73 |
this->recordDraw(gp, meshes, meshCnt, nullptr, primitiveType); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Makes space for vertex data. The returned pointer is the location where vertex data |
| 78 |
* should be written. On return the buffer that will hold the data as well as an offset into |
| 79 |
* the buffer (in 'vertexSize' units) where the data will be placed. |
| 80 |
*/ |
| 81 |
virtual void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*, |
| 82 |
int* startVertex) = 0; |
| 83 |
|
| 84 |
/** |
| 85 |
* Makes space for index data. The returned pointer is the location where index data |
| 86 |
* should be written. On return the buffer that will hold the data as well as an offset into |
| 87 |
* the buffer (in uint16_t units) where the data will be placed. |
| 88 |
*/ |
| 89 |
virtual uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) = 0; |
| 90 |
|
| 91 |
/** |
| 92 |
* This is similar to makeVertexSpace. It allows the caller to use up to 'actualVertexCount' |
| 93 |
* vertices in the returned pointer, which may exceed 'minVertexCount'. |
| 94 |
* 'fallbackVertexCount' is the maximum number of vertices that should be allocated if a new |
| 95 |
* buffer is allocated on behalf of this request. |
| 96 |
*/ |
| 97 |
virtual void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, |
| 98 |
int fallbackVertexCount, sk_sp<const GrBuffer>*, |
| 99 |
int* startVertex, int* actualVertexCount) = 0; |
| 100 |
|
| 101 |
/** |
| 102 |
* This is similar to makeIndexSpace. It allows the caller to use up to 'actualIndexCount' |
| 103 |
* indices in the returned pointer, which may exceed 'minIndexCount'. |
| 104 |
* 'fallbackIndexCount' is the maximum number of indices that should be allocated if a new |
| 105 |
* buffer is allocated on behalf of this request. |
| 106 |
*/ |
| 107 |
virtual uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, |
| 108 |
sk_sp<const GrBuffer>*, int* startIndex, |
| 109 |
int* actualIndexCount) = 0; |
| 110 |
|
| 111 |
/** |
| 112 |
* Makes space for elements in a draw-indirect buffer. Upon success, the returned pointer is a |
| 113 |
* CPU mapping where the data should be written. |
| 114 |
*/ |
| 115 |
virtual GrDrawIndirectWriter makeDrawIndirectSpace(int drawCount, sk_sp<const GrBuffer>* buffer, |
| 116 |
size_t* offsetInBytes) = 0; |
| 117 |
|
| 118 |
/** |
| 119 |
* Makes space for elements in a draw-indexed-indirect buffer. Upon success, the returned |
| 120 |
* pointer is a CPU mapping where the data should be written. |
| 121 |
*/ |
| 122 |
virtual GrDrawIndexedIndirectWriter makeDrawIndexedIndirectSpace(int drawCount, |
| 123 |
sk_sp<const GrBuffer>*, |
| 124 |
size_t* offsetInBytes) = 0; |
| 125 |
|
| 126 |
/** Helpers for ops that only need to use the VertexWriter to fill the data directly. */ |
| 127 |
skgpu::VertexWriter makeVertexWriter(size_t vertexSize, int vertexCount, |
| 128 |
sk_sp<const GrBuffer>*, int* startVertex); |
| 129 |
skgpu::VertexWriter makeVertexWriterAtLeast(size_t vertexSize, int minVertexCount, |
| 130 |
int fallbackVertexCount, sk_sp<const GrBuffer>*, |
| 131 |
int* startVertex, int* actualVertexCount); |
| 132 |
|
| 133 |
/** Helpers for ops which over-allocate and then return excess data to the pool. */ |
| 134 |
virtual void putBackIndices(int indices) = 0; |
| 135 |
virtual void putBackVertices(int vertices, size_t vertexStride) = 0; |
| 136 |
virtual void putBackIndirectDraws(int count) = 0; |
| 137 |
virtual void putBackIndexedIndirectDraws(int count) = 0; |
| 138 |
|
| 139 |
GrSimpleMesh* allocMesh() { return this->allocator()->make<GrSimpleMesh>(); } |
| 140 |
GrSimpleMesh* allocMeshes(int n) { return this->allocator()->makeArray<GrSimpleMesh>(n); } |
| 141 |
const GrSurfaceProxy** allocPrimProcProxyPtrs(int n) { |
| 142 |
return this->allocator()->makeArray<const GrSurfaceProxy*>(n); |
| 143 |
} |
| 144 |
|
| 145 |
virtual GrRenderTargetProxy* rtProxy() const = 0; |
| 146 |
virtual const GrSurfaceProxyView& writeView() const = 0; |
| 147 |
|
| 148 |
virtual const GrAppliedClip* appliedClip() const = 0; |
| 149 |
virtual GrAppliedClip detachAppliedClip() = 0; |
| 150 |
|
| 151 |
virtual const GrDstProxyView& dstProxyView() const = 0; |
| 152 |
virtual bool usesMSAASurface() const = 0; |
| 153 |
|
| 154 |
virtual GrXferBarrierFlags renderPassBarriers() const = 0; |
| 155 |
|
| 156 |
virtual GrLoadOp colorLoadOp() const = 0; |
| 157 |
|
| 158 |
virtual GrThreadSafeCache* threadSafeCache() const = 0; |
| 159 |
virtual GrResourceProvider* resourceProvider() const = 0; |
| 160 |
uint32_t contextUniqueID() const; |
| 161 |
|
| 162 |
virtual sktext::gpu::StrikeCache* strikeCache() const = 0; |
| 163 |
virtual GrAtlasManager* atlasManager() const = 0; |
| 164 |
#if !defined(SK_ENABLE_OPTIMIZE_SIZE) |
| 165 |
virtual skgpu::ganesh::SmallPathAtlasMgr* smallPathAtlasManager() const = 0; |
| 166 |
#endif |
| 167 |
|
| 168 |
// This should be called during onPrepare of a GrOp. The caller should add any proxies to the |
| 169 |
// array it will use that it did not access during a call to visitProxies. This is usually the |
| 170 |
// case for atlases. |
| 171 |
virtual skia_private::TArray<GrSurfaceProxy*, true>* sampledProxyArray() = 0; |
| 172 |
|
| 173 |
virtual const GrCaps& caps() const = 0; |
| 174 |
|
| 175 |
virtual GrDeferredUploadTarget* deferredUploadTarget() = 0; |
| 176 |
|
| 177 |
virtual SkArenaAlloc* allocator() = 0; |
| 178 |
}; |
| 179 |
|
| 180 |
#endif |