blob: 3ba49d06cab880dd3244110acb1b08d539087ea5 [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
8#include "GrGpuCommandBuffer.h"
9
robertphillips28a838e2016-06-23 14:07:00 -070010#include "GrCaps.h"
Robert Phillipsbe9aff22019-02-15 11:33:22 -050011#include "GrContext.h"
12#include "GrContextPriv.h"
csmartdalton29df7602016-08-31 11:55:52 -070013#include "GrFixedClip.h"
egdaniel9cb63402016-06-23 08:37:05 -070014#include "GrGpu.h"
Brian Salomon2a55c8e2017-05-09 09:57:19 -040015#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070016#include "GrPrimitiveProcessor.h"
17#include "GrRenderTarget.h"
18#include "SkRect.h"
19
Brian Osman9a9baae2018-11-05 15:06:26 -050020void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040021 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050022 // A clear at this level will always be a true clear, so make sure clears were not supposed to
23 // be redirected to draws instead
24 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
25 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040026 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070027}
28
Greg Daniel500d58b2017-08-24 15:59:33 -040029void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050030 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
31 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040032 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070033}
34
Brian Salomon49348902018-06-26 09:12:38 -040035bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
36 const GrPipeline::FixedDynamicState* fixedDynamicState,
37 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
38 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060039#ifdef SK_DEBUG
Brian Salomon92be2f72018-06-19 14:33:47 -040040 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060041 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060042 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060043 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Brian Salomon92be2f72018-06-19 14:33:47 -040044 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
Chris Dalton906430d2019-02-27 18:16:59 -070045 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
Chris Daltonbca46e22017-05-15 11:03:26 -060046 }
47#endif
Brian Salomond818ebf2018-07-02 14:08:49 +000048 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
Brian Salomon49348902018-06-26 09:12:38 -040049 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
50
Robert Phillips9da87e02019-02-04 13:26:26 -050051 auto resourceProvider = this->gpu()->getContext()->priv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060052
Brian Salomon7eae3e02018-08-07 14:02:38 +000053 if (pipeline.isBad()) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040054 return false;
55 }
Brian Salomonf7232642018-09-19 08:58:08 -040056 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
57 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
58 if (!fixedDynamicState->fPrimitiveProcessorTextures[i]->instantiate(resourceProvider)) {
59 return false;
60 }
61 }
62 }
63 if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
64 int n = primProc.numTextureSamplers() * meshCount;
65 const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
66 for (int i = 0; i < n; ++i) {
67 if (!textures[i]->instantiate(resourceProvider)) {
68 return false;
69 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000070 }
Greg Daniel9a51a862018-11-30 10:18:14 -050071#ifdef SK_DEBUG
72 SkASSERT(meshCount >= 1);
73 const GrTextureProxy* const* primProcProxies =
74 dynamicStateArrays->fPrimitiveProcessorTextures;
75 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
76 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
77 GrTextureType type = primProcProxies[i]->textureType();
78 GrPixelConfig config = primProcProxies[i]->config();
79 for (int j = 1; j < meshCount; ++j) {
80 const GrTextureProxy* testProxy =
81 primProcProxies[j*primProc.numTextureSamplers() + i];
82 SkASSERT(testProxy->backendFormat() == format);
83 SkASSERT(testProxy->textureType() == type);
84 SkASSERT(testProxy->config() == config);
85 }
86 }
87#endif
88
Brian Salomon7eae3e02018-08-07 14:02:38 +000089 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -040090
Brian Salomon92be2f72018-06-19 14:33:47 -040091 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070092 this->gpu()->stats()->incNumFailedDraws();
93 return false;
94 }
Brian Salomon49348902018-06-26 09:12:38 -040095 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
96 bounds);
egdaniel9cb63402016-06-23 08:37:05 -070097 return true;
98}