egdaniel | 9cb6340 | 2016-06-23 08:37:05 -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 | #include "src/gpu/GrOpsRenderPass.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkRect.h" |
| 11 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrCaps.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
| 14 | #include "src/gpu/GrFixedClip.h" |
| 15 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrPrimitiveProcessor.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrProgramInfo.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTargetPriv.h" |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 20 | #include "src/gpu/GrSimpleMesh.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 21 | #include "src/gpu/GrTexturePriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 23 | void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 24 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 25 | // A clear at this level will always be a true clear, so make sure clears were not supposed to |
| 26 | // be redirected to draws instead |
| 27 | SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws()); |
| 28 | SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 29 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 30 | this->onClear(clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 33 | void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 34 | // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings |
| 35 | SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws()); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 36 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 37 | this->onClearStencilClip(clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 40 | void GrOpsRenderPass::executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable) { |
| 41 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
| 42 | this->onExecuteDrawable(std::move(drawable)); |
| 43 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 44 | |
Chris Dalton | 012f849 | 2020-03-05 11:49:15 -0700 | [diff] [blame] | 45 | void GrOpsRenderPass::bindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds, |
| 46 | const SkIRect* optionalScissorRect) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 47 | #ifdef SK_DEBUG |
Chris Dalton | 56c09f0 | 2020-03-13 17:30:03 -0600 | [diff] [blame] | 48 | // Both the 'programInfo' and this renderPass have an origin. Since they come from the same |
| 49 | // place (i.e., the target renderTargetProxy) they had best agree. |
| 50 | SkASSERT(programInfo.origin() == fOrigin); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 51 | if (programInfo.primProc().hasInstanceAttributes()) { |
| 52 | SkASSERT(this->gpu()->caps()->instanceAttribSupport()); |
| 53 | } |
| 54 | if (programInfo.pipeline().usesConservativeRaster()) { |
| 55 | SkASSERT(this->gpu()->caps()->conservativeRasterSupport()); |
| 56 | // Conservative raster, by default, only supports triangles. Implementations can |
| 57 | // optionally indicate that they also support points and lines, but we don't currently |
| 58 | // query or track that info. |
| 59 | SkASSERT(GrIsPrimTypeTris(programInfo.primitiveType())); |
| 60 | } |
| 61 | if (programInfo.pipeline().isWireframe()) { |
| 62 | SkASSERT(this->gpu()->caps()->wireframeSupport()); |
| 63 | } |
| 64 | if (GrPrimitiveType::kPatches == programInfo.primitiveType()) { |
| 65 | SkASSERT(this->gpu()->caps()->shaderCaps()->tessellationSupport()); |
| 66 | } |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 67 | programInfo.checkAllInstantiated(); |
| 68 | programInfo.checkMSAAAndMIPSAreResolved(); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 69 | #endif |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 70 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 71 | if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 72 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 73 | return; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 74 | } |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 75 | |
| 76 | if (!this->onBindPipeline(programInfo, drawBounds)) { |
| 77 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 78 | return; |
| 79 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 80 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 81 | #ifdef SK_DEBUG |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 82 | GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures(); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 83 | if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) { |
| 84 | // Verify we always have the same sample pattern key, regardless of graphics state. |
| 85 | SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget) |
| 86 | == fRenderTarget->renderTargetPriv().getSamplePatternKey()); |
| 87 | } |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 88 | fScissorStatus = (programInfo.pipeline().isScissorTestEnabled()) ? |
| 89 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
| 90 | bool hasTextures = (programInfo.primProc().numTextureSamplers() > 0); |
| 91 | if (!hasTextures) { |
| 92 | programInfo.pipeline().visitProxies([&hasTextures](GrSurfaceProxy*, GrMipMapped) { |
| 93 | hasTextures = true; |
| 94 | }); |
| 95 | } |
| 96 | fTextureBindingStatus = (hasTextures) ? |
| 97 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 98 | fHasIndexBuffer = false; |
| 99 | fInstanceBufferStatus = (programInfo.primProc().hasInstanceAttributes()) ? |
| 100 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
| 101 | fVertexBufferStatus = (programInfo.primProc().hasVertexAttributes()) ? |
| 102 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 103 | #endif |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 104 | |
| 105 | fDrawPipelineStatus = DrawPipelineStatus::kOk; |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 106 | fXferBarrierType = programInfo.pipeline().xferBarrierType(fRenderTarget->asTexture(), |
| 107 | *this->gpu()->caps()); |
Chris Dalton | 012f849 | 2020-03-05 11:49:15 -0700 | [diff] [blame] | 108 | |
| 109 | if (optionalScissorRect) { |
| 110 | SkASSERT(programInfo.pipeline().isScissorTestEnabled()); |
| 111 | this->setScissorRect(*optionalScissorRect); |
| 112 | } |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void GrOpsRenderPass::setScissorRect(const SkIRect& scissor) { |
| 116 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 117 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 118 | return; |
| 119 | } |
| 120 | SkASSERT(DynamicStateStatus::kDisabled != fScissorStatus); |
| 121 | this->onSetScissorRect(scissor); |
| 122 | SkDEBUGCODE(fScissorStatus = DynamicStateStatus::kConfigured); |
| 123 | } |
| 124 | |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 125 | void GrOpsRenderPass::bindTextures(const GrPrimitiveProcessor& primProc, |
| 126 | const GrSurfaceProxy* const primProcTextures[], |
| 127 | const GrPipeline& pipeline) { |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 128 | #ifdef SK_DEBUG |
| 129 | SkASSERT((primProc.numTextureSamplers() > 0) == SkToBool(primProcTextures)); |
| 130 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
| 131 | SkASSERT(primProcTextures[i]->backendFormat() == |
| 132 | primProc.textureSampler(i).backendFormat()); |
| 133 | } |
| 134 | #endif |
| 135 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 136 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 137 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 138 | return; |
| 139 | } |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 140 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 141 | // Don't assert on fTextureBindingStatus. onBindTextures() just turns into a no-op when there |
| 142 | // aren't any textures, and it's hard to tell from the GrPipeline whether there are any. For |
| 143 | // many clients it is easier to just always call this method. |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 144 | if (!this->onBindTextures(primProc, primProcTextures, pipeline)) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 145 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 146 | return; |
| 147 | } |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 148 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 149 | SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Chris Dalton | 012f849 | 2020-03-05 11:49:15 -0700 | [diff] [blame] | 152 | void GrOpsRenderPass::bindTextures(const GrPrimitiveProcessor& primProc, |
| 153 | const GrSurfaceProxy& singlePrimProcTexture, |
| 154 | const GrPipeline& pipeline) { |
| 155 | SkASSERT(primProc.numTextureSamplers() == 1); |
| 156 | const GrSurfaceProxy* ptr = &singlePrimProcTexture; |
| 157 | this->bindTextures(primProc, &ptr, pipeline); |
| 158 | } |
| 159 | |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 160 | void GrOpsRenderPass::drawMeshes(const GrProgramInfo& programInfo, const GrSimpleMesh meshes[], |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 161 | int meshCount) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 162 | if (programInfo.hasFixedScissor()) { |
| 163 | this->setScissorRect(programInfo.fixedScissor()); |
| 164 | } |
| 165 | if (!programInfo.hasDynamicPrimProcTextures()) { |
| 166 | auto primProcTextures = (programInfo.hasFixedPrimProcTextures()) ? |
| 167 | programInfo.fixedPrimProcTextures() : nullptr; |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 168 | this->bindTextures(programInfo.primProc(), primProcTextures, programInfo.pipeline()); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 169 | } |
| 170 | for (int i = 0; i < meshCount; ++i) { |
| 171 | if (programInfo.hasDynamicScissors()) { |
| 172 | this->setScissorRect(programInfo.dynamicScissor(i)); |
| 173 | } |
| 174 | if (programInfo.hasDynamicPrimProcTextures()) { |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 175 | this->bindTextures(programInfo.primProc(), programInfo.dynamicPrimProcTextures(i), |
| 176 | programInfo.pipeline()); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 177 | } |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 178 | meshes[i].draw(this); |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 182 | void GrOpsRenderPass::bindBuffers(const GrBuffer* indexBuffer, const GrBuffer* instanceBuffer, |
| 183 | const GrBuffer* vertexBuffer, GrPrimitiveRestart primRestart) { |
| 184 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 185 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | #ifdef SK_DEBUG |
| 190 | if (indexBuffer) { |
| 191 | fHasIndexBuffer = true; |
| 192 | } |
| 193 | |
| 194 | SkASSERT((DynamicStateStatus::kDisabled == fInstanceBufferStatus) != SkToBool(instanceBuffer)); |
| 195 | if (instanceBuffer) { |
| 196 | fInstanceBufferStatus = DynamicStateStatus::kConfigured; |
| 197 | } |
| 198 | |
| 199 | SkASSERT((DynamicStateStatus::kDisabled == fVertexBufferStatus) != SkToBool(vertexBuffer)); |
| 200 | if (vertexBuffer) { |
| 201 | fVertexBufferStatus = DynamicStateStatus::kConfigured; |
| 202 | } |
| 203 | |
| 204 | if (GrPrimitiveRestart::kYes == primRestart) { |
| 205 | SkASSERT(this->gpu()->caps()->usePrimitiveRestart()); |
| 206 | } |
| 207 | #endif |
| 208 | |
| 209 | this->onBindBuffers(indexBuffer, instanceBuffer, vertexBuffer, primRestart); |
| 210 | } |
| 211 | |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 212 | bool GrOpsRenderPass::prepareToDraw() { |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 213 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 214 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 215 | this->gpu()->stats()->incNumFailedDraws(); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 216 | return false; |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 217 | } |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 218 | SkASSERT(DynamicStateStatus::kUninitialized != fScissorStatus); |
| 219 | SkASSERT(DynamicStateStatus::kUninitialized != fTextureBindingStatus); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 220 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 221 | if (kNone_GrXferBarrierType != fXferBarrierType) { |
| 222 | this->gpu()->xferBarrier(fRenderTarget, fXferBarrierType); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 223 | } |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 224 | return true; |
| 225 | } |
| 226 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 227 | void GrOpsRenderPass::draw(int vertexCount, int baseVertex) { |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 228 | if (!this->prepareToDraw()) { |
| 229 | return; |
| 230 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 231 | SkASSERT(!fHasIndexBuffer); |
| 232 | SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus); |
| 233 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 234 | this->onDraw(vertexCount, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 237 | void GrOpsRenderPass::drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, |
| 238 | uint16_t maxIndexValue, int baseVertex) { |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 239 | if (!this->prepareToDraw()) { |
| 240 | return; |
| 241 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 242 | SkASSERT(fHasIndexBuffer); |
| 243 | SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus); |
| 244 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 245 | this->onDrawIndexed(indexCount, baseIndex, minIndexValue, maxIndexValue, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 248 | void GrOpsRenderPass::drawInstanced(int instanceCount, int baseInstance, int vertexCount, |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 249 | int baseVertex) { |
| 250 | if (!this->prepareToDraw()) { |
| 251 | return; |
| 252 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 253 | SkASSERT(!fHasIndexBuffer); |
| 254 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 255 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 256 | this->onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 259 | void GrOpsRenderPass::drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, |
| 260 | int baseInstance, int baseVertex) { |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 261 | if (!this->prepareToDraw()) { |
| 262 | return; |
| 263 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 264 | SkASSERT(fHasIndexBuffer); |
| 265 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 266 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 267 | this->onDrawIndexedInstanced(indexCount, baseIndex, instanceCount, baseInstance, baseVertex); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 268 | } |
Chris Dalton | bb76842 | 2020-03-12 12:13:29 -0600 | [diff] [blame] | 269 | |
| 270 | void GrOpsRenderPass::drawIndexPattern(int patternIndexCount, int patternRepeatCount, |
| 271 | int maxPatternRepetitionsInIndexBuffer, |
| 272 | int patternVertexCount, int baseVertex) { |
| 273 | int baseRepetition = 0; |
| 274 | while (baseRepetition < patternRepeatCount) { |
| 275 | int repeatCount = std::min(patternRepeatCount - baseRepetition, |
| 276 | maxPatternRepetitionsInIndexBuffer); |
| 277 | int drawIndexCount = repeatCount * patternIndexCount; |
| 278 | // A patterned index buffer must contain indices in the range [0..vertexCount]. |
| 279 | int minIndexValue = 0; |
| 280 | int maxIndexValue = patternVertexCount * repeatCount - 1; |
| 281 | this->drawIndexed(drawIndexCount, 0, minIndexValue, maxIndexValue, |
| 282 | patternVertexCount * baseRepetition + baseVertex); |
| 283 | baseRepetition += repeatCount; |
| 284 | } |
| 285 | } |