blob: 26842190f50e89f315c8f83e41eaaccfff6ed403 [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
Robert Phillips9bee2e52017-05-29 12:37:20 -040010#include "GrContext.h"
robertphillips28a838e2016-06-23 14:07:00 -070011#include "GrCaps.h"
csmartdalton29df7602016-08-31 11:55:52 -070012#include "GrFixedClip.h"
egdaniel9cb63402016-06-23 08:37:05 -070013#include "GrGpu.h"
Brian Salomon2a55c8e2017-05-09 09:57:19 -040014#include "GrMesh.h"
egdaniel9cb63402016-06-23 08:37:05 -070015#include "GrPrimitiveProcessor.h"
16#include "GrRenderTarget.h"
17#include "SkRect.h"
18
Brian Osman9a9baae2018-11-05 15:06:26 -050019void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040020 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050021 // A clear at this level will always be a true clear, so make sure clears were not supposed to
22 // be redirected to draws instead
23 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
24 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040025 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070026}
27
Greg Daniel500d58b2017-08-24 15:59:33 -040028void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050029 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
30 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040031 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070032}
33
Brian Salomon49348902018-06-26 09:12:38 -040034bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
35 const GrPipeline::FixedDynamicState* fixedDynamicState,
36 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
37 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060038#ifdef SK_DEBUG
Brian Salomon92be2f72018-06-19 14:33:47 -040039 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060040 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060041 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060042 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Brian Salomon92be2f72018-06-19 14:33:47 -040043 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
44 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].isInstanced());
Chris Daltonbca46e22017-05-15 11:03:26 -060045 }
46#endif
Brian Salomond818ebf2018-07-02 14:08:49 +000047 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
Brian Salomon49348902018-06-26 09:12:38 -040048 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
49
Robert Phillips9da87e02019-02-04 13:26:26 -050050 auto resourceProvider = this->gpu()->getContext()->priv().resourceProvider();
Chris Daltonbca46e22017-05-15 11:03:26 -060051
Brian Salomon7eae3e02018-08-07 14:02:38 +000052 if (pipeline.isBad()) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040053 return false;
54 }
Brian Salomonf7232642018-09-19 08:58:08 -040055 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
56 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
57 if (!fixedDynamicState->fPrimitiveProcessorTextures[i]->instantiate(resourceProvider)) {
58 return false;
59 }
60 }
61 }
62 if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
63 int n = primProc.numTextureSamplers() * meshCount;
64 const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
65 for (int i = 0; i < n; ++i) {
66 if (!textures[i]->instantiate(resourceProvider)) {
67 return false;
68 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000069 }
Greg Daniel9a51a862018-11-30 10:18:14 -050070#ifdef SK_DEBUG
71 SkASSERT(meshCount >= 1);
72 const GrTextureProxy* const* primProcProxies =
73 dynamicStateArrays->fPrimitiveProcessorTextures;
74 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
75 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
76 GrTextureType type = primProcProxies[i]->textureType();
77 GrPixelConfig config = primProcProxies[i]->config();
78 for (int j = 1; j < meshCount; ++j) {
79 const GrTextureProxy* testProxy =
80 primProcProxies[j*primProc.numTextureSamplers() + i];
81 SkASSERT(testProxy->backendFormat() == format);
82 SkASSERT(testProxy->textureType() == type);
83 SkASSERT(testProxy->config() == config);
84 }
85 }
86#endif
87
Brian Salomon7eae3e02018-08-07 14:02:38 +000088 }
Robert Phillipsa91e0b72017-05-01 13:12:20 -040089
Brian Salomon92be2f72018-06-19 14:33:47 -040090 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070091 this->gpu()->stats()->incNumFailedDraws();
92 return false;
93 }
Brian Salomon49348902018-06-26 09:12:38 -040094 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
95 bounds);
egdaniel9cb63402016-06-23 08:37:05 -070096 return true;
97}