19#define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
29 fUseMultisampleFBO = useMSAASurface;
30 fContentBounds = contentBounds;
31 fColorLoadAndStoreInfo = colorInfo;
32 fStencilLoadAndStoreInfo = stencilInfo;
35GrNativeRect GrGLOpsRenderPass::dmsaaLoadStoreBounds()
const {
48void GrGLOpsRenderPass::onBegin() {
50 if (fUseMultisampleFBO &&
52 glRT->hasDynamicMSAAAttachment()) {
63 fColorLoadAndStoreInfo, fStencilLoadAndStoreInfo);
66void GrGLOpsRenderPass::onEnd() {
69 fStencilLoadAndStoreInfo);
71 if (fUseMultisampleFBO &&
73 glRT->hasDynamicMSAAAttachment()) {
81bool GrGLOpsRenderPass::onBindPipeline(
const GrProgramInfo& programInfo,
82 const SkRect& drawBounds) {
87void GrGLOpsRenderPass::onSetScissorRect(
const SkIRect& scissor) {
96 program->
bindTextures(geomProc, geomProcTextures, pipeline);
109 fDidBindInstanceBuffer =
false;
110 fDidBindVertexBuffer =
false;
119 auto* cpuIndexBuffer =
static_cast<const GrCpuBuffer*
>(indexBuffer.
get());
120 fIndexPointer =
reinterpret_cast<const uint16_t*
>(cpuIndexBuffer->data());
122 fIndexPointer =
nullptr;
128 this->bindInstanceBuffer(instanceBuffer.
get(), 0);
129 SkDEBUGCODE(fDidBindInstanceBuffer =
true;)
138 this->bindVertexBuffer(vertexBuffer.
get(), 0);
139 SkDEBUGCODE(fDidBindVertexBuffer =
true;)
145void GrGLOpsRenderPass::bindInstanceBuffer(
const GrBuffer* instanceBuffer,
int baseInstance) {
152 size_t bufferOffset = baseInstance *
static_cast<size_t>(instanceStride);
156 static constexpr int kDivisor = 1;
157 fAttribArrayState->
set(fGpu, attrib.fLocation, instanceBuffer, attrib.fCPUType,
158 attrib.fGPUType, instanceStride, bufferOffset + attrib.fOffset,
164void GrGLOpsRenderPass::bindVertexBuffer(
const GrBuffer* vertexBuffer,
int baseVertex) {
171 size_t bufferOffset = baseVertex *
static_cast<size_t>(vertexStride);
174 static constexpr int kDivisor = 0;
175 fAttribArrayState->
set(fGpu, attrib.fLocation, vertexBuffer, attrib.fCPUType,
176 attrib.fGPUType, vertexStride, bufferOffset + attrib.fOffset,
182void GrGLOpsRenderPass::onDraw(
int vertexCount,
int baseVertex) {
189 GL_CALL(DrawArrays(glPrimType, baseVertex, vertexCount));
193void GrGLOpsRenderPass::onDrawIndexed(
int indexCount,
int baseIndex, uint16_t minIndexValue,
194 uint16_t maxIndexValue,
int baseVertex) {
199 if (baseVertex != 0) {
200 GL_CALL(DrawElementsInstancedBaseVertexBaseInstance(
202 this->offsetForBaseIndex(baseIndex), 1, baseVertex, 0));
210 GL_CALL(DrawRangeElements(glPrimType, minIndexValue, maxIndexValue, indexCount,
214 this->offsetForBaseIndex(baseIndex)));
219void GrGLOpsRenderPass::onDrawInstanced(
int instanceCount,
int baseInstance,
int vertexCount,
228 for (
int i = 0;
i < instanceCount;
i += maxInstances) {
230 int instanceCountForDraw =
std::min(instanceCount -
i, maxInstances);
231 int baseInstanceForDraw = baseInstance +
i;
234 GL_CALL(DrawArraysInstancedBaseInstance(glPrimType, baseVertex, vertexCount,
235 instanceCountForDraw, baseInstanceForDraw));
238 GL_CALL(DrawArraysInstanced(glPrimType, baseVertex, vertexCount, instanceCountForDraw));
244void GrGLOpsRenderPass::onDrawIndexedInstanced(
int indexCount,
int baseIndex,
int instanceCount,
245 int baseInstance,
int baseVertex) {
247 for (
int i = 0;
i < instanceCount;
i += maxInstances) {
249 int instanceCountForDraw =
std::min(instanceCount -
i, maxInstances);
250 int baseInstanceForDraw = baseInstance +
i;
254 GL_CALL(DrawElementsInstancedBaseVertexBaseInstance(
256 this->offsetForBaseIndex(baseIndex), instanceCountForDraw, baseVertex,
257 baseInstanceForDraw));
262 this->offsetForBaseIndex(baseIndex), instanceCountForDraw));
272 return (
offset) ?
reinterpret_cast<const void*
>(
offset) :
nullptr;
276void GrGLOpsRenderPass::onDrawIndirect(
const GrBuffer* drawIndirectBuffer,
size_t offset,
292 this->multiDrawArraysANGLEOrWebGL(drawIndirectBuffer,
offset, drawCount);
298 if (drawCount > 1 && fGpu->
glCaps().
multiDrawType() == MultiDrawType::kMultiDrawIndirect) {
300 GL_CALL(MultiDrawArraysIndirect(glPrimType,
306 for (
int i = 0;
i < drawCount; ++
i) {
308 GL_CALL(DrawArraysIndirect(glPrimType,
315void GrGLOpsRenderPass::multiDrawArraysANGLEOrWebGL(
const GrBuffer* drawIndirectBuffer,
316 size_t offset,
int drawCount) {
320 constexpr static int kMaxDrawCountPerBatch = 128;
321 GrGLint fFirsts[kMaxDrawCountPerBatch];
322 GrGLsizei fCounts[kMaxDrawCountPerBatch];
323 GrGLsizei fInstanceCounts[kMaxDrawCountPerBatch];
324 GrGLuint fBaseInstances[kMaxDrawCountPerBatch];
327 auto* cpuBuffer =
static_cast<const GrCpuBuffer*
>(drawIndirectBuffer);
331 int countInBatch =
std::min(drawCount, kMaxDrawCountPerBatch);
332 for (
int i = 0;
i < countInBatch; ++
i) {
333 auto [vertexCount, instanceCount, baseVertex, baseInstance] = cmds[
i];
334 fFirsts[
i] = baseVertex;
335 fCounts[
i] = vertexCount;
336 fInstanceCounts[
i] = instanceCount;
337 fBaseInstances[
i] = baseInstance;
339 if (countInBatch == 1) {
340 GL_CALL(DrawArraysInstancedBaseInstance(glPrimType, fFirsts[0], fCounts[0],
341 fInstanceCounts[0], fBaseInstances[0]));
343 GL_CALL(MultiDrawArraysInstancedBaseInstance(glPrimType, fFirsts, fCounts,
344 fInstanceCounts, fBaseInstances,
347 drawCount -= countInBatch;
348 cmds += countInBatch;
353void GrGLOpsRenderPass::onDrawIndexedIndirect(
const GrBuffer* drawIndirectBuffer,
size_t offset,
366 this->multiDrawElementsANGLEOrWebGL(drawIndirectBuffer,
offset, drawCount);
372 if (drawCount > 1 && fGpu->
glCaps().
multiDrawType() == MultiDrawType::kMultiDrawIndirect) {
380 for (
int i = 0;
i < drawCount; ++
i) {
389void GrGLOpsRenderPass::multiDrawElementsANGLEOrWebGL(
const GrBuffer* drawIndirectBuffer,
390 size_t offset,
int drawCount) {
394 constexpr static int kMaxDrawCountPerBatch = 128;
395 GrGLint fCounts[kMaxDrawCountPerBatch];
396 const void* fIndices[kMaxDrawCountPerBatch];
397 GrGLsizei fInstanceCounts[kMaxDrawCountPerBatch];
398 GrGLint fBaseVertices[kMaxDrawCountPerBatch];
399 GrGLuint fBaseInstances[kMaxDrawCountPerBatch];
402 auto* cpuBuffer =
static_cast<const GrCpuBuffer*
>(drawIndirectBuffer);
406 int countInBatch =
std::min(drawCount, kMaxDrawCountPerBatch);
407 for (
int i = 0;
i < countInBatch; ++
i) {
408 auto [indexCount, instanceCount, baseIndex, baseVertex, baseInstance] = cmds[
i];
409 fCounts[
i] = indexCount;
410 fIndices[
i] = this->offsetForBaseIndex(baseIndex);
411 fInstanceCounts[
i] = instanceCount;
412 fBaseVertices[
i] = baseVertex;
413 fBaseInstances[
i] = baseInstance;
415 if (countInBatch == 1) {
416 GL_CALL(DrawElementsInstancedBaseVertexBaseInstance(glPrimType, fCounts[0],
422 GL_CALL(MultiDrawElementsInstancedBaseVertexBaseInstance(glPrimType, fCounts,
424 fInstanceCounts, fBaseVertices,
425 fBaseInstances, countInBatch));
427 drawCount -= countInBatch;
428 cmds += countInBatch;
433void GrGLOpsRenderPass::onClear(
const GrScissorState& scissor, std::array<float, 4>
color) {
437void GrGLOpsRenderPass::onClearStencilClip(
const GrScissorState& scissor,
bool insideStencilMask) {
#define GR_GL_UNSIGNED_SHORT
static const void * buffer_offset_to_gl_address(const GrBuffer *drawIndirectBuffer, size_t offset)
virtual bool isCpuBuffer() const =0
bool nativeDrawIndirectSupport() const
bool nativeDrawIndexedIndirectIsBroken() const
bool drawInstancedSupport() const
GrDirectContextPriv priv()
void set(GrGLGpu *, int attribIndex, const GrBuffer *vertexBuffer, GrVertexAttribType cpuType, SkSLType gpuType, GrGLsizei stride, size_t offsetInBytes, int divisor=0)
bool drawRangeElementsSupport() const
Is there support for glDrawRangeElements?
bool baseVertexBaseInstanceSupport() const
Are the glDraw*Base(VertexBase)Instance methods, and baseInstance fields in indirect draw.
int maxInstancesPerDrawWithoutCrashing(int pendingInstanceCount) const
bool drawArraysBaseVertexIsBroken() const
MultiDrawType multiDrawType() const
How are multi draws implemented (if at all)?
bool framebufferResolvesMustBeFullSize() const
bool canResolveSingleToMSAA() const
void flushScissorRect(const SkIRect &scissor, int rtHeight, GrSurfaceOrigin)
const GrGLCaps & glCaps() const
void clear(const GrScissorState &, std::array< float, 4 > color, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
void clearStencilClip(const GrScissorState &, bool insideStencilMask, GrRenderTarget *, bool useMultisampleFBO, GrSurfaceOrigin)
GrGLProgram * currentProgram()
GrGLenum prepareToDraw(GrPrimitiveType primitiveType)
void didDrawTo(GrRenderTarget *)
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer *)
void resolveRenderFBOs(GrGLRenderTarget *, const SkIRect &resolveRect, ResolveDirection, bool invalidateReadBufferAfterBlit=false)
void beginCommandBuffer(GrGLRenderTarget *, bool useMultisampleFBO, const SkIRect &bounds, GrSurfaceOrigin, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
bool flushGLState(GrRenderTarget *, bool useMultisampleFBO, const GrProgramInfo &)
void drawSingleIntoMSAAFBO(GrGLRenderTarget *rt, const SkIRect &drawBounds)
void endCommandBuffer(GrGLRenderTarget *, bool useMultisampleFBO, const GrOpsRenderPass::LoadAndStoreInfo &colorLoadStore, const GrOpsRenderPass::StencilLoadAndStoreInfo &stencilLoadStore)
GrGLAttribArrayState * bindInternalVertexArray(const GrBuffer *indexBuffer, int numAttribs, GrPrimitiveRestart primitiveRestart)
void set(GrRenderTarget *, bool useMSAASurface, const SkIRect &contentBounds, GrSurfaceOrigin, const LoadAndStoreInfo &, const StencilLoadAndStoreInfo &)
int numVertexAttributes() const
int instanceStride() const
const Attribute & vertexAttribute(int i) const
void bindTextures(const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)
int numInstanceAttributes() const
const Attribute & instanceAttribute(int i) const
const GrDirectContext * getContext() const
const GrCaps * caps() const
sk_sp< const GrBuffer > fActiveIndexBuffer
sk_sp< const GrBuffer > fActiveInstanceBuffer
sk_sp< const GrBuffer > fActiveVertexBuffer
void set(GrRenderTarget *rt, GrSurfaceOrigin origin)
GrRenderTarget * fRenderTarget
GrPrimitiveType primitiveType() const
SkISize dimensions() const
static float min(float r, float g, float b)
SkIRect asSkIRect() const
static GrNativeRect MakeRelativeTo(GrSurfaceOrigin origin, int rtHeight, SkIRect devRect)
static constexpr SkIRect MakeSize(const SkISize &size)
std::shared_ptr< const fml::Mapping > data