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" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrCaps.h" |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrCpuBuffer.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrPrimitiveProcessor.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrProgramInfo.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrRenderTargetPriv.h" |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrScissorState.h" |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 19 | #include "src/gpu/GrSimpleMesh.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 20 | #include "src/gpu/GrTexturePriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 21 | |
Chris Dalton | 2c3e169 | 2020-03-20 12:32:55 -0600 | [diff] [blame] | 22 | void GrOpsRenderPass::begin() { |
| 23 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
| 24 | #ifdef SK_DEBUG |
| 25 | fScissorStatus = DynamicStateStatus::kDisabled; |
| 26 | fTextureBindingStatus = DynamicStateStatus::kDisabled; |
| 27 | fHasIndexBuffer = false; |
| 28 | fInstanceBufferStatus = DynamicStateStatus::kDisabled; |
| 29 | fVertexBufferStatus = DynamicStateStatus::kDisabled; |
| 30 | #endif |
| 31 | this->onBegin(); |
| 32 | } |
| 33 | |
| 34 | void GrOpsRenderPass::end() { |
| 35 | this->onEnd(); |
Chris Dalton | b60c8a2 | 2020-03-31 17:24:22 -0600 | [diff] [blame] | 36 | this->resetActiveBuffers(); |
Chris Dalton | 2c3e169 | 2020-03-20 12:32:55 -0600 | [diff] [blame] | 37 | } |
| 38 | |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 39 | void GrOpsRenderPass::clear(const GrScissorState& scissor, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 40 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 41 | // A clear at this level will always be a true clear, so make sure clears were not supposed to |
| 42 | // be redirected to draws instead |
| 43 | SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws()); |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 44 | SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 45 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 46 | this->onClear(scissor, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 49 | void GrOpsRenderPass::clearStencilClip(const GrScissorState& scissor, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 50 | // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings |
| 51 | SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws()); |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 52 | SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws()); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 53 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 54 | this->onClearStencilClip(scissor, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 57 | void GrOpsRenderPass::executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable) { |
| 58 | fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured; |
| 59 | this->onExecuteDrawable(std::move(drawable)); |
| 60 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 61 | |
Chris Dalton | aa0e45c | 2020-03-16 10:05:11 -0600 | [diff] [blame] | 62 | void GrOpsRenderPass::bindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds) { |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 63 | #ifdef SK_DEBUG |
Chris Dalton | 56c09f0 | 2020-03-13 17:30:03 -0600 | [diff] [blame] | 64 | // Both the 'programInfo' and this renderPass have an origin. Since they come from the same |
| 65 | // place (i.e., the target renderTargetProxy) they had best agree. |
| 66 | SkASSERT(programInfo.origin() == fOrigin); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 67 | if (programInfo.primProc().hasInstanceAttributes()) { |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 68 | SkASSERT(this->gpu()->caps()->drawInstancedSupport()); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 69 | } |
| 70 | if (programInfo.pipeline().usesConservativeRaster()) { |
| 71 | SkASSERT(this->gpu()->caps()->conservativeRasterSupport()); |
| 72 | // Conservative raster, by default, only supports triangles. Implementations can |
| 73 | // optionally indicate that they also support points and lines, but we don't currently |
| 74 | // query or track that info. |
| 75 | SkASSERT(GrIsPrimTypeTris(programInfo.primitiveType())); |
| 76 | } |
| 77 | if (programInfo.pipeline().isWireframe()) { |
| 78 | SkASSERT(this->gpu()->caps()->wireframeSupport()); |
| 79 | } |
Chris Dalton | 3d28b6a | 2020-04-13 11:12:28 -0600 | [diff] [blame] | 80 | if (this->gpu()->caps()->twoSidedStencilRefsAndMasksMustMatch() && |
| 81 | programInfo.pipeline().isStencilEnabled()) { |
| 82 | const GrUserStencilSettings* stencil = programInfo.pipeline().getUserStencil(); |
| 83 | if (stencil->isTwoSided(programInfo.pipeline().hasStencilClip())) { |
| 84 | SkASSERT(stencil->fCCWFace.fRef == stencil->fCWFace.fRef); |
| 85 | SkASSERT(stencil->fCCWFace.fTestMask == stencil->fCWFace.fTestMask); |
| 86 | SkASSERT(stencil->fCCWFace.fWriteMask == stencil->fCWFace.fWriteMask); |
| 87 | } |
| 88 | } |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 89 | if (GrPrimitiveType::kPatches == programInfo.primitiveType()) { |
| 90 | SkASSERT(this->gpu()->caps()->shaderCaps()->tessellationSupport()); |
| 91 | } |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 92 | programInfo.checkAllInstantiated(); |
| 93 | programInfo.checkMSAAAndMIPSAreResolved(); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 94 | #endif |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 95 | |
Chris Dalton | b60c8a2 | 2020-03-31 17:24:22 -0600 | [diff] [blame] | 96 | this->resetActiveBuffers(); |
| 97 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 98 | if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 99 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 100 | return; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 101 | } |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 102 | |
| 103 | if (!this->onBindPipeline(programInfo, drawBounds)) { |
| 104 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 105 | return; |
| 106 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 107 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 108 | #ifdef SK_DEBUG |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 109 | GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures(); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 110 | if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) { |
| 111 | // Verify we always have the same sample pattern key, regardless of graphics state. |
| 112 | SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget) |
| 113 | == fRenderTarget->renderTargetPriv().getSamplePatternKey()); |
| 114 | } |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 115 | fScissorStatus = (programInfo.pipeline().isScissorTestEnabled()) ? |
| 116 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
| 117 | bool hasTextures = (programInfo.primProc().numTextureSamplers() > 0); |
| 118 | if (!hasTextures) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 119 | programInfo.pipeline().visitProxies([&hasTextures](GrSurfaceProxy*, GrMipmapped) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 120 | hasTextures = true; |
| 121 | }); |
| 122 | } |
| 123 | fTextureBindingStatus = (hasTextures) ? |
| 124 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 125 | fHasIndexBuffer = false; |
| 126 | fInstanceBufferStatus = (programInfo.primProc().hasInstanceAttributes()) ? |
| 127 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
| 128 | fVertexBufferStatus = (programInfo.primProc().hasVertexAttributes()) ? |
| 129 | DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 130 | #endif |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 131 | |
| 132 | fDrawPipelineStatus = DrawPipelineStatus::kOk; |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 133 | fXferBarrierType = programInfo.pipeline().xferBarrierType(fRenderTarget->asTexture(), |
| 134 | *this->gpu()->caps()); |
| 135 | } |
| 136 | |
| 137 | void GrOpsRenderPass::setScissorRect(const SkIRect& scissor) { |
| 138 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 139 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 140 | return; |
| 141 | } |
| 142 | SkASSERT(DynamicStateStatus::kDisabled != fScissorStatus); |
| 143 | this->onSetScissorRect(scissor); |
| 144 | SkDEBUGCODE(fScissorStatus = DynamicStateStatus::kConfigured); |
| 145 | } |
| 146 | |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 147 | void GrOpsRenderPass::bindTextures(const GrPrimitiveProcessor& primProc, |
| 148 | const GrSurfaceProxy* const primProcTextures[], |
| 149 | const GrPipeline& pipeline) { |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 150 | #ifdef SK_DEBUG |
| 151 | SkASSERT((primProc.numTextureSamplers() > 0) == SkToBool(primProcTextures)); |
| 152 | for (int i = 0; i < primProc.numTextureSamplers(); ++i) { |
Chris Dalton | 3bf2f3a | 2020-03-17 11:48:23 -0600 | [diff] [blame] | 153 | const auto& sampler = primProc.textureSampler(i); |
| 154 | const GrSurfaceProxy* proxy = primProcTextures[i]; |
| 155 | SkASSERT(proxy); |
| 156 | SkASSERT(proxy->backendFormat() == sampler.backendFormat()); |
| 157 | SkASSERT(proxy->backendFormat().textureType() == sampler.backendFormat().textureType()); |
| 158 | |
| 159 | const GrTexture* tex = proxy->peekTexture(); |
| 160 | SkASSERT(tex); |
Brian Salomon | e69b9ef | 2020-07-22 11:18:06 -0400 | [diff] [blame^] | 161 | if (sampler.samplerState().mipmapped() == GrMipmapped::kYes && |
Chris Dalton | 3bf2f3a | 2020-03-17 11:48:23 -0600 | [diff] [blame] | 162 | (tex->width() != 1 || tex->height() != 1)) { |
| 163 | // There are some cases where we might be given a non-mipmapped texture with a mipmap |
| 164 | // filter. See skbug.com/7094. |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 165 | SkASSERT(tex->texturePriv().mipmapped() != GrMipmapped::kYes || |
| 166 | !tex->texturePriv().mipmapsAreDirty()); |
Chris Dalton | 3bf2f3a | 2020-03-17 11:48:23 -0600 | [diff] [blame] | 167 | } |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 168 | } |
| 169 | #endif |
| 170 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 171 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 172 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 173 | return; |
| 174 | } |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 175 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 176 | // Don't assert on fTextureBindingStatus. onBindTextures() just turns into a no-op when there |
| 177 | // aren't any textures, and it's hard to tell from the GrPipeline whether there are any. For |
| 178 | // many clients it is easier to just always call this method. |
Chris Dalton | db20afc | 2020-03-05 12:13:53 -0700 | [diff] [blame] | 179 | if (!this->onBindTextures(primProc, primProcTextures, pipeline)) { |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 180 | fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind; |
| 181 | return; |
| 182 | } |
Chris Dalton | 1b1b0d5 | 2020-03-03 12:00:59 -0700 | [diff] [blame] | 183 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 184 | SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Greg Daniel | 426274b | 2020-07-20 11:37:38 -0400 | [diff] [blame] | 187 | void GrOpsRenderPass::bindBuffers(sk_sp<const GrBuffer> indexBuffer, |
| 188 | sk_sp<const GrBuffer> instanceBuffer, |
| 189 | sk_sp<const GrBuffer> vertexBuffer, |
| 190 | GrPrimitiveRestart primRestart) { |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 191 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 192 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | #ifdef SK_DEBUG |
| 197 | if (indexBuffer) { |
| 198 | fHasIndexBuffer = true; |
| 199 | } |
| 200 | |
| 201 | SkASSERT((DynamicStateStatus::kDisabled == fInstanceBufferStatus) != SkToBool(instanceBuffer)); |
| 202 | if (instanceBuffer) { |
| 203 | fInstanceBufferStatus = DynamicStateStatus::kConfigured; |
| 204 | } |
| 205 | |
| 206 | SkASSERT((DynamicStateStatus::kDisabled == fVertexBufferStatus) != SkToBool(vertexBuffer)); |
| 207 | if (vertexBuffer) { |
| 208 | fVertexBufferStatus = DynamicStateStatus::kConfigured; |
| 209 | } |
| 210 | |
| 211 | if (GrPrimitiveRestart::kYes == primRestart) { |
| 212 | SkASSERT(this->gpu()->caps()->usePrimitiveRestart()); |
| 213 | } |
| 214 | #endif |
| 215 | |
Greg Daniel | 426274b | 2020-07-20 11:37:38 -0400 | [diff] [blame] | 216 | this->onBindBuffers(std::move(indexBuffer), std::move(instanceBuffer), std::move(vertexBuffer), |
| 217 | primRestart); |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 220 | bool GrOpsRenderPass::prepareToDraw() { |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 221 | if (DrawPipelineStatus::kOk != fDrawPipelineStatus) { |
| 222 | SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus); |
| 223 | this->gpu()->stats()->incNumFailedDraws(); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 224 | return false; |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 225 | } |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 226 | SkASSERT(DynamicStateStatus::kUninitialized != fScissorStatus); |
| 227 | SkASSERT(DynamicStateStatus::kUninitialized != fTextureBindingStatus); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 228 | |
Chris Dalton | 2e7ed26 | 2020-02-21 15:17:59 -0700 | [diff] [blame] | 229 | if (kNone_GrXferBarrierType != fXferBarrierType) { |
| 230 | this->gpu()->xferBarrier(fRenderTarget, fXferBarrierType); |
Chris Dalton | 4386ad1 | 2020-02-19 16:42:06 -0700 | [diff] [blame] | 231 | } |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 232 | return true; |
| 233 | } |
| 234 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 235 | void GrOpsRenderPass::draw(int vertexCount, int baseVertex) { |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 236 | if (!this->prepareToDraw()) { |
| 237 | return; |
| 238 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 239 | SkASSERT(!fHasIndexBuffer); |
| 240 | SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus); |
| 241 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 242 | this->onDraw(vertexCount, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 245 | void GrOpsRenderPass::drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, |
| 246 | uint16_t maxIndexValue, int baseVertex) { |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 247 | if (!this->prepareToDraw()) { |
| 248 | return; |
| 249 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 250 | SkASSERT(fHasIndexBuffer); |
| 251 | SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus); |
| 252 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 253 | this->onDrawIndexed(indexCount, baseIndex, minIndexValue, maxIndexValue, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 256 | void GrOpsRenderPass::drawInstanced(int instanceCount, int baseInstance, int vertexCount, |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 257 | int baseVertex) { |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 258 | SkASSERT(this->gpu()->caps()->drawInstancedSupport()); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 259 | if (!this->prepareToDraw()) { |
| 260 | return; |
| 261 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 262 | SkASSERT(!fHasIndexBuffer); |
| 263 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 264 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 265 | this->onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 268 | void GrOpsRenderPass::drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, |
| 269 | int baseInstance, int baseVertex) { |
Chris Dalton | a77cdee | 2020-04-03 14:50:43 -0600 | [diff] [blame] | 270 | SkASSERT(this->gpu()->caps()->drawInstancedSupport()); |
Chris Dalton | 33db9fc | 2020-02-25 18:52:12 -0700 | [diff] [blame] | 271 | if (!this->prepareToDraw()) { |
| 272 | return; |
| 273 | } |
Chris Dalton | ded4370 | 2020-03-02 11:45:27 -0700 | [diff] [blame] | 274 | SkASSERT(fHasIndexBuffer); |
| 275 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 276 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 277 | this->onDrawIndexedInstanced(indexCount, baseIndex, instanceCount, baseInstance, baseVertex); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 278 | } |
Chris Dalton | bb76842 | 2020-03-12 12:13:29 -0600 | [diff] [blame] | 279 | |
Chris Dalton | 03fdf6a | 2020-04-07 12:31:59 -0600 | [diff] [blame] | 280 | void GrOpsRenderPass::drawIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset, |
| 281 | int drawCount) { |
| 282 | SkASSERT(this->gpu()->caps()->drawInstancedSupport()); |
| 283 | SkASSERT(drawIndirectBuffer->isCpuBuffer() || |
| 284 | !static_cast<const GrGpuBuffer*>(drawIndirectBuffer)->isMapped()); |
| 285 | if (!this->prepareToDraw()) { |
| 286 | return; |
| 287 | } |
| 288 | SkASSERT(!fHasIndexBuffer); |
| 289 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 290 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 291 | if (!this->gpu()->caps()->nativeDrawIndirectSupport()) { |
| 292 | // Polyfill indirect draws with looping instanced calls. |
| 293 | SkASSERT(drawIndirectBuffer->isCpuBuffer()); |
| 294 | auto cpuIndirectBuffer = static_cast<const GrCpuBuffer*>(drawIndirectBuffer); |
| 295 | auto cmd = reinterpret_cast<const GrDrawIndirectCommand*>( |
| 296 | cpuIndirectBuffer->data() + bufferOffset); |
| 297 | auto end = cmd + drawCount; |
| 298 | for (; cmd != end; ++cmd) { |
| 299 | this->onDrawInstanced(cmd->fInstanceCount, cmd->fBaseInstance, cmd->fVertexCount, |
| 300 | cmd->fBaseVertex); |
| 301 | } |
| 302 | return; |
| 303 | } |
| 304 | this->onDrawIndirect(drawIndirectBuffer, bufferOffset, drawCount); |
| 305 | } |
| 306 | |
| 307 | void GrOpsRenderPass::drawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset, |
| 308 | int drawCount) { |
| 309 | SkASSERT(this->gpu()->caps()->drawInstancedSupport()); |
| 310 | SkASSERT(drawIndirectBuffer->isCpuBuffer() || |
| 311 | !static_cast<const GrGpuBuffer*>(drawIndirectBuffer)->isMapped()); |
| 312 | if (!this->prepareToDraw()) { |
| 313 | return; |
| 314 | } |
| 315 | SkASSERT(fHasIndexBuffer); |
| 316 | SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus); |
| 317 | SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus); |
| 318 | if (!this->gpu()->caps()->nativeDrawIndirectSupport() || |
| 319 | this->gpu()->caps()->nativeDrawIndexedIndirectIsBroken()) { |
| 320 | // Polyfill indexedIndirect draws with looping indexedInstanced calls. |
| 321 | SkASSERT(drawIndirectBuffer->isCpuBuffer()); |
| 322 | auto cpuIndirectBuffer = static_cast<const GrCpuBuffer*>(drawIndirectBuffer); |
| 323 | auto cmd = reinterpret_cast<const GrDrawIndexedIndirectCommand*>( |
| 324 | cpuIndirectBuffer->data() + bufferOffset); |
| 325 | auto end = cmd + drawCount; |
| 326 | for (; cmd != end; ++cmd) { |
| 327 | this->onDrawIndexedInstanced(cmd->fIndexCount, cmd->fBaseIndex, cmd->fInstanceCount, |
| 328 | cmd->fBaseInstance, cmd->fBaseVertex); |
| 329 | } |
| 330 | return; |
| 331 | } |
| 332 | this->onDrawIndexedIndirect(drawIndirectBuffer, bufferOffset, drawCount); |
| 333 | } |
| 334 | |
Chris Dalton | bb76842 | 2020-03-12 12:13:29 -0600 | [diff] [blame] | 335 | void GrOpsRenderPass::drawIndexPattern(int patternIndexCount, int patternRepeatCount, |
| 336 | int maxPatternRepetitionsInIndexBuffer, |
| 337 | int patternVertexCount, int baseVertex) { |
| 338 | int baseRepetition = 0; |
| 339 | while (baseRepetition < patternRepeatCount) { |
| 340 | int repeatCount = std::min(patternRepeatCount - baseRepetition, |
| 341 | maxPatternRepetitionsInIndexBuffer); |
| 342 | int drawIndexCount = repeatCount * patternIndexCount; |
| 343 | // A patterned index buffer must contain indices in the range [0..vertexCount]. |
| 344 | int minIndexValue = 0; |
| 345 | int maxIndexValue = patternVertexCount * repeatCount - 1; |
| 346 | this->drawIndexed(drawIndexCount, 0, minIndexValue, maxIndexValue, |
| 347 | patternVertexCount * baseRepetition + baseVertex); |
| 348 | baseRepetition += repeatCount; |
| 349 | } |
| 350 | } |