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