blob: f408b3fff0567b2f806a183e26bd5805ee119cef [file] [log] [blame]
egdaniel9cb63402016-06-23 08:37:05 -07001/*
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 Daniel2d41d0d2019-08-26 11:08:51 -04008#include "src/gpu/GrOpsRenderPass.h"
egdaniel9cb63402016-06-23 08:37:05 -07009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkRect.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrCaps.h"
Michael Ludwig1e632792020-05-21 12:45:31 -040012#include "src/gpu/GrCpuBuffer.h"
Chris Daltona6a3d052021-02-07 20:56:36 -070013#include "src/gpu/GrDrawIndirectCommand.h"
Robert Phillips787fd9d2021-03-22 14:48:09 -040014#include "src/gpu/GrGeometryProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrGpu.h"
Robert Phillips901aff02019-10-08 12:32:56 -040016#include "src/gpu/GrProgramInfo.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040017#include "src/gpu/GrRenderTarget.h"
Michael Ludwig1e632792020-05-21 12:45:31 -040018#include "src/gpu/GrScissorState.h"
Chris Daltoneb694b72020-03-16 09:25:50 -060019#include "src/gpu/GrSimpleMesh.h"
Brian Salomon4cfae3b2020-07-23 10:33:24 -040020#include "src/gpu/GrTexture.h"
egdaniel9cb63402016-06-23 08:37:05 -070021
Chris Dalton2c3e1692020-03-20 12:32:55 -060022void 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
34void GrOpsRenderPass::end() {
35 this->onEnd();
Chris Daltonb60c8a22020-03-31 17:24:22 -060036 this->resetActiveBuffers();
Chris Dalton2c3e1692020-03-20 12:32:55 -060037}
38
Brian Salomon07bc9a22020-12-02 13:37:16 -050039void GrOpsRenderPass::clear(const GrScissorState& scissor, std::array<float, 4> color) {
Robert Phillips4912d902018-04-27 12:09:35 -040040 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050041 // 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 Ludwig1e632792020-05-21 12:45:31 -040044 SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Chris Dalton4386ad12020-02-19 16:42:06 -070045 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
Michael Ludwig1e632792020-05-21 12:45:31 -040046 this->onClear(scissor, color);
egdaniel9cb63402016-06-23 08:37:05 -070047}
48
Michael Ludwig1e632792020-05-21 12:45:31 -040049void GrOpsRenderPass::clearStencilClip(const GrScissorState& scissor, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050050 // 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 Ludwig1e632792020-05-21 12:45:31 -040052 SkASSERT(!scissor.enabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Chris Dalton4386ad12020-02-19 16:42:06 -070053 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
Michael Ludwig1e632792020-05-21 12:45:31 -040054 this->onClearStencilClip(scissor, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070055}
56
Chris Dalton4386ad12020-02-19 16:42:06 -070057void GrOpsRenderPass::executeDrawable(std::unique_ptr<SkDrawable::GpuDrawHandler> drawable) {
58 fDrawPipelineStatus = DrawPipelineStatus::kNotConfigured;
59 this->onExecuteDrawable(std::move(drawable));
60}
Robert Phillips901aff02019-10-08 12:32:56 -040061
Chris Daltonaa0e45c2020-03-16 10:05:11 -060062void GrOpsRenderPass::bindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060063#ifdef SK_DEBUG
Chris Dalton56c09f02020-03-13 17:30:03 -060064 // 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);
Robert Phillips787fd9d2021-03-22 14:48:09 -040067 if (programInfo.geomProc().hasInstanceAttributes()) {
Chris Daltona77cdee2020-04-03 14:50:43 -060068 SkASSERT(this->gpu()->caps()->drawInstancedSupport());
Chris Dalton4386ad12020-02-19 16:42:06 -070069 }
70 if (programInfo.pipeline().usesConservativeRaster()) {
71 SkASSERT(this->gpu()->caps()->conservativeRasterSupport());
Chris Dalton4386ad12020-02-19 16:42:06 -070072 }
73 if (programInfo.pipeline().isWireframe()) {
74 SkASSERT(this->gpu()->caps()->wireframeSupport());
75 }
Chris Dalton3d28b6a2020-04-13 11:12:28 -060076 if (this->gpu()->caps()->twoSidedStencilRefsAndMasksMustMatch() &&
Chris Dalton1b6a43c2020-09-25 12:21:18 -060077 programInfo.isStencilEnabled()) {
78 const GrUserStencilSettings* stencil = programInfo.userStencilSettings();
Chris Dalton3d28b6a2020-04-13 11:12:28 -060079 if (stencil->isTwoSided(programInfo.pipeline().hasStencilClip())) {
80 SkASSERT(stencil->fCCWFace.fRef == stencil->fCWFace.fRef);
81 SkASSERT(stencil->fCCWFace.fTestMask == stencil->fCWFace.fTestMask);
82 SkASSERT(stencil->fCCWFace.fWriteMask == stencil->fCWFace.fWriteMask);
83 }
84 }
Chris Dalton4386ad12020-02-19 16:42:06 -070085 if (GrPrimitiveType::kPatches == programInfo.primitiveType()) {
86 SkASSERT(this->gpu()->caps()->shaderCaps()->tessellationSupport());
87 }
Robert Phillips2d8a95e2019-10-10 12:50:22 -040088 programInfo.checkAllInstantiated();
89 programInfo.checkMSAAAndMIPSAreResolved();
Robert Phillips12c46292019-04-23 07:36:17 -040090#endif
Robert Phillipsa91e0b72017-05-01 13:12:20 -040091
Chris Daltonb60c8a22020-03-31 17:24:22 -060092 this->resetActiveBuffers();
93
Robert Phillips787fd9d2021-03-22 14:48:09 -040094 if (programInfo.geomProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
Chris Dalton4386ad12020-02-19 16:42:06 -070095 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
96 return;
egdaniel9cb63402016-06-23 08:37:05 -070097 }
Chris Dalton4386ad12020-02-19 16:42:06 -070098
99 if (!this->onBindPipeline(programInfo, drawBounds)) {
100 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
101 return;
102 }
Robert Phillips901aff02019-10-08 12:32:56 -0400103
Chris Dalton8c4cafd2019-04-15 19:14:36 -0600104#ifdef SK_DEBUG
Chris Dalton2e7ed262020-02-21 15:17:59 -0700105 fScissorStatus = (programInfo.pipeline().isScissorTestEnabled()) ?
106 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
Robert Phillips787fd9d2021-03-22 14:48:09 -0400107 bool hasTextures = (programInfo.geomProc().numTextureSamplers() > 0);
Chris Dalton2e7ed262020-02-21 15:17:59 -0700108 if (!hasTextures) {
Brian Salomon7e67dca2020-07-21 09:27:25 -0400109 programInfo.pipeline().visitProxies([&hasTextures](GrSurfaceProxy*, GrMipmapped) {
Chris Dalton2e7ed262020-02-21 15:17:59 -0700110 hasTextures = true;
111 });
112 }
113 fTextureBindingStatus = (hasTextures) ?
114 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
Chris Daltonded43702020-03-02 11:45:27 -0700115 fHasIndexBuffer = false;
Robert Phillips787fd9d2021-03-22 14:48:09 -0400116 fInstanceBufferStatus = (programInfo.geomProc().hasInstanceAttributes()) ?
Chris Daltonded43702020-03-02 11:45:27 -0700117 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
Robert Phillips787fd9d2021-03-22 14:48:09 -0400118 fVertexBufferStatus = (programInfo.geomProc().hasVertexAttributes()) ?
Chris Daltonded43702020-03-02 11:45:27 -0700119 DynamicStateStatus::kUninitialized : DynamicStateStatus::kDisabled;
Chris Dalton8c4cafd2019-04-15 19:14:36 -0600120#endif
Chris Dalton4386ad12020-02-19 16:42:06 -0700121
122 fDrawPipelineStatus = DrawPipelineStatus::kOk;
Greg Danield358cbe2020-09-11 09:33:54 -0400123 fXferBarrierType = programInfo.pipeline().xferBarrierType(*this->gpu()->caps());
Chris Dalton2e7ed262020-02-21 15:17:59 -0700124}
125
126void GrOpsRenderPass::setScissorRect(const SkIRect& scissor) {
127 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
128 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
129 return;
130 }
131 SkASSERT(DynamicStateStatus::kDisabled != fScissorStatus);
132 this->onSetScissorRect(scissor);
133 SkDEBUGCODE(fScissorStatus = DynamicStateStatus::kConfigured);
134}
135
Robert Phillips787fd9d2021-03-22 14:48:09 -0400136void GrOpsRenderPass::bindTextures(const GrGeometryProcessor& geomProc,
137 const GrSurfaceProxy* const geomProcTextures[],
Chris Daltondb20afc2020-03-05 12:13:53 -0700138 const GrPipeline& pipeline) {
Chris Dalton1b1b0d52020-03-03 12:00:59 -0700139#ifdef SK_DEBUG
Robert Phillips787fd9d2021-03-22 14:48:09 -0400140 SkASSERT((geomProc.numTextureSamplers() > 0) == SkToBool(geomProcTextures));
141 for (int i = 0; i < geomProc.numTextureSamplers(); ++i) {
142 const auto& sampler = geomProc.textureSampler(i);
143 const GrSurfaceProxy* proxy = geomProcTextures[i];
Chris Dalton3bf2f3a2020-03-17 11:48:23 -0600144 SkASSERT(proxy);
145 SkASSERT(proxy->backendFormat() == sampler.backendFormat());
146 SkASSERT(proxy->backendFormat().textureType() == sampler.backendFormat().textureType());
147
148 const GrTexture* tex = proxy->peekTexture();
149 SkASSERT(tex);
Brian Salomone69b9ef2020-07-22 11:18:06 -0400150 if (sampler.samplerState().mipmapped() == GrMipmapped::kYes &&
Chris Dalton3bf2f3a2020-03-17 11:48:23 -0600151 (tex->width() != 1 || tex->height() != 1)) {
152 // There are some cases where we might be given a non-mipmapped texture with a mipmap
153 // filter. See skbug.com/7094.
Brian Salomon4cfae3b2020-07-23 10:33:24 -0400154 SkASSERT(tex->mipmapped() != GrMipmapped::kYes || !tex->mipmapsAreDirty());
Chris Dalton3bf2f3a2020-03-17 11:48:23 -0600155 }
Chris Dalton1b1b0d52020-03-03 12:00:59 -0700156 }
157#endif
158
Chris Dalton2e7ed262020-02-21 15:17:59 -0700159 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
160 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
161 return;
162 }
Chris Dalton1b1b0d52020-03-03 12:00:59 -0700163
Chris Dalton2e7ed262020-02-21 15:17:59 -0700164 // Don't assert on fTextureBindingStatus. onBindTextures() just turns into a no-op when there
165 // aren't any textures, and it's hard to tell from the GrPipeline whether there are any. For
166 // many clients it is easier to just always call this method.
Robert Phillips787fd9d2021-03-22 14:48:09 -0400167 if (!this->onBindTextures(geomProc, geomProcTextures, pipeline)) {
Chris Dalton2e7ed262020-02-21 15:17:59 -0700168 fDrawPipelineStatus = DrawPipelineStatus::kFailedToBind;
169 return;
170 }
Chris Dalton1b1b0d52020-03-03 12:00:59 -0700171
Chris Dalton2e7ed262020-02-21 15:17:59 -0700172 SkDEBUGCODE(fTextureBindingStatus = DynamicStateStatus::kConfigured);
Chris Dalton4386ad12020-02-19 16:42:06 -0700173}
174
Greg Daniel426274b2020-07-20 11:37:38 -0400175void GrOpsRenderPass::bindBuffers(sk_sp<const GrBuffer> indexBuffer,
176 sk_sp<const GrBuffer> instanceBuffer,
177 sk_sp<const GrBuffer> vertexBuffer,
178 GrPrimitiveRestart primRestart) {
Chris Daltonded43702020-03-02 11:45:27 -0700179 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
180 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
181 return;
182 }
183
184#ifdef SK_DEBUG
185 if (indexBuffer) {
186 fHasIndexBuffer = true;
187 }
188
189 SkASSERT((DynamicStateStatus::kDisabled == fInstanceBufferStatus) != SkToBool(instanceBuffer));
190 if (instanceBuffer) {
191 fInstanceBufferStatus = DynamicStateStatus::kConfigured;
192 }
193
194 SkASSERT((DynamicStateStatus::kDisabled == fVertexBufferStatus) != SkToBool(vertexBuffer));
195 if (vertexBuffer) {
196 fVertexBufferStatus = DynamicStateStatus::kConfigured;
197 }
198
199 if (GrPrimitiveRestart::kYes == primRestart) {
200 SkASSERT(this->gpu()->caps()->usePrimitiveRestart());
201 }
202#endif
203
Greg Daniel426274b2020-07-20 11:37:38 -0400204 this->onBindBuffers(std::move(indexBuffer), std::move(instanceBuffer), std::move(vertexBuffer),
205 primRestart);
Chris Daltonded43702020-03-02 11:45:27 -0700206}
207
Chris Dalton33db9fc2020-02-25 18:52:12 -0700208bool GrOpsRenderPass::prepareToDraw() {
Chris Dalton4386ad12020-02-19 16:42:06 -0700209 if (DrawPipelineStatus::kOk != fDrawPipelineStatus) {
210 SkASSERT(DrawPipelineStatus::kNotConfigured != fDrawPipelineStatus);
211 this->gpu()->stats()->incNumFailedDraws();
Chris Dalton33db9fc2020-02-25 18:52:12 -0700212 return false;
Chris Dalton4386ad12020-02-19 16:42:06 -0700213 }
Chris Dalton2e7ed262020-02-21 15:17:59 -0700214 SkASSERT(DynamicStateStatus::kUninitialized != fScissorStatus);
215 SkASSERT(DynamicStateStatus::kUninitialized != fTextureBindingStatus);
Chris Dalton4386ad12020-02-19 16:42:06 -0700216
Chris Dalton2e7ed262020-02-21 15:17:59 -0700217 if (kNone_GrXferBarrierType != fXferBarrierType) {
218 this->gpu()->xferBarrier(fRenderTarget, fXferBarrierType);
Chris Dalton4386ad12020-02-19 16:42:06 -0700219 }
Chris Dalton33db9fc2020-02-25 18:52:12 -0700220 return true;
221}
222
Chris Daltonded43702020-03-02 11:45:27 -0700223void GrOpsRenderPass::draw(int vertexCount, int baseVertex) {
Chris Dalton33db9fc2020-02-25 18:52:12 -0700224 if (!this->prepareToDraw()) {
225 return;
226 }
Chris Daltonded43702020-03-02 11:45:27 -0700227 SkASSERT(!fHasIndexBuffer);
228 SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus);
229 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
230 this->onDraw(vertexCount, baseVertex);
Chris Dalton33db9fc2020-02-25 18:52:12 -0700231}
232
Chris Daltonded43702020-03-02 11:45:27 -0700233void GrOpsRenderPass::drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
234 uint16_t maxIndexValue, int baseVertex) {
Chris Dalton33db9fc2020-02-25 18:52:12 -0700235 if (!this->prepareToDraw()) {
236 return;
237 }
Chris Daltonded43702020-03-02 11:45:27 -0700238 SkASSERT(fHasIndexBuffer);
239 SkASSERT(DynamicStateStatus::kConfigured != fInstanceBufferStatus);
240 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
241 this->onDrawIndexed(indexCount, baseIndex, minIndexValue, maxIndexValue, baseVertex);
Chris Dalton33db9fc2020-02-25 18:52:12 -0700242}
243
Chris Daltonded43702020-03-02 11:45:27 -0700244void GrOpsRenderPass::drawInstanced(int instanceCount, int baseInstance, int vertexCount,
Chris Dalton33db9fc2020-02-25 18:52:12 -0700245 int baseVertex) {
Chris Daltona77cdee2020-04-03 14:50:43 -0600246 SkASSERT(this->gpu()->caps()->drawInstancedSupport());
Chris Dalton33db9fc2020-02-25 18:52:12 -0700247 if (!this->prepareToDraw()) {
248 return;
249 }
Chris Daltonded43702020-03-02 11:45:27 -0700250 SkASSERT(!fHasIndexBuffer);
251 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
252 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
253 this->onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex);
Chris Dalton33db9fc2020-02-25 18:52:12 -0700254}
255
Chris Daltonded43702020-03-02 11:45:27 -0700256void GrOpsRenderPass::drawIndexedInstanced(int indexCount, int baseIndex, int instanceCount,
257 int baseInstance, int baseVertex) {
Chris Daltona77cdee2020-04-03 14:50:43 -0600258 SkASSERT(this->gpu()->caps()->drawInstancedSupport());
Chris Dalton33db9fc2020-02-25 18:52:12 -0700259 if (!this->prepareToDraw()) {
260 return;
261 }
Chris Daltonded43702020-03-02 11:45:27 -0700262 SkASSERT(fHasIndexBuffer);
263 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
264 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
265 this->onDrawIndexedInstanced(indexCount, baseIndex, instanceCount, baseInstance, baseVertex);
egdaniel9cb63402016-06-23 08:37:05 -0700266}
Chris Daltonbb768422020-03-12 12:13:29 -0600267
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600268void GrOpsRenderPass::drawIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset,
269 int drawCount) {
270 SkASSERT(this->gpu()->caps()->drawInstancedSupport());
271 SkASSERT(drawIndirectBuffer->isCpuBuffer() ||
272 !static_cast<const GrGpuBuffer*>(drawIndirectBuffer)->isMapped());
273 if (!this->prepareToDraw()) {
274 return;
275 }
276 SkASSERT(!fHasIndexBuffer);
277 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
278 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
279 if (!this->gpu()->caps()->nativeDrawIndirectSupport()) {
280 // Polyfill indirect draws with looping instanced calls.
281 SkASSERT(drawIndirectBuffer->isCpuBuffer());
Chris Daltona6a3d052021-02-07 20:56:36 -0700282 auto* cpuIndirectBuffer = static_cast<const GrCpuBuffer*>(drawIndirectBuffer);
283 auto* cmds = reinterpret_cast<const GrDrawIndirectCommand*>(
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600284 cpuIndirectBuffer->data() + bufferOffset);
Chris Daltona6a3d052021-02-07 20:56:36 -0700285 for (int i = 0; i < drawCount; ++i) {
Chris Daltona6a3d052021-02-07 20:56:36 -0700286 auto [vertexCount, instanceCount, baseVertex, baseInstance] = cmds[i];
287 this->onDrawInstanced(instanceCount, baseInstance, vertexCount, baseVertex);
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600288 }
289 return;
290 }
291 this->onDrawIndirect(drawIndirectBuffer, bufferOffset, drawCount);
292}
293
294void GrOpsRenderPass::drawIndexedIndirect(const GrBuffer* drawIndirectBuffer, size_t bufferOffset,
295 int drawCount) {
296 SkASSERT(this->gpu()->caps()->drawInstancedSupport());
297 SkASSERT(drawIndirectBuffer->isCpuBuffer() ||
298 !static_cast<const GrGpuBuffer*>(drawIndirectBuffer)->isMapped());
299 if (!this->prepareToDraw()) {
300 return;
301 }
302 SkASSERT(fHasIndexBuffer);
303 SkASSERT(DynamicStateStatus::kUninitialized != fInstanceBufferStatus);
304 SkASSERT(DynamicStateStatus::kUninitialized != fVertexBufferStatus);
305 if (!this->gpu()->caps()->nativeDrawIndirectSupport() ||
306 this->gpu()->caps()->nativeDrawIndexedIndirectIsBroken()) {
307 // Polyfill indexedIndirect draws with looping indexedInstanced calls.
308 SkASSERT(drawIndirectBuffer->isCpuBuffer());
Chris Daltona6a3d052021-02-07 20:56:36 -0700309 auto* cpuIndirectBuffer = static_cast<const GrCpuBuffer*>(drawIndirectBuffer);
310 auto* cmds = reinterpret_cast<const GrDrawIndexedIndirectCommand*>(
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600311 cpuIndirectBuffer->data() + bufferOffset);
Chris Daltona6a3d052021-02-07 20:56:36 -0700312 for (int i = 0; i < drawCount; ++i) {
Chris Daltona6a3d052021-02-07 20:56:36 -0700313 auto [indexCount, instanceCount, baseIndex, baseVertex, baseInstance] = cmds[i];
314 this->onDrawIndexedInstanced(indexCount, baseIndex, instanceCount, baseInstance,
315 baseVertex);
Chris Dalton03fdf6a2020-04-07 12:31:59 -0600316 }
317 return;
318 }
319 this->onDrawIndexedIndirect(drawIndirectBuffer, bufferOffset, drawCount);
320}
321
Chris Daltonbb768422020-03-12 12:13:29 -0600322void GrOpsRenderPass::drawIndexPattern(int patternIndexCount, int patternRepeatCount,
323 int maxPatternRepetitionsInIndexBuffer,
324 int patternVertexCount, int baseVertex) {
325 int baseRepetition = 0;
326 while (baseRepetition < patternRepeatCount) {
327 int repeatCount = std::min(patternRepeatCount - baseRepetition,
328 maxPatternRepetitionsInIndexBuffer);
329 int drawIndexCount = repeatCount * patternIndexCount;
330 // A patterned index buffer must contain indices in the range [0..vertexCount].
331 int minIndexValue = 0;
332 int maxIndexValue = patternVertexCount * repeatCount - 1;
333 this->drawIndexed(drawIndexCount, 0, minIndexValue, maxIndexValue,
334 patternVertexCount * baseRepetition + baseVertex);
335 baseRepetition += repeatCount;
336 }
337}