blob: b1215f6f195c9d746d2c9d9ccb95391abc397fc0 [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"
Chris Dalton8c4cafd2019-04-15 19:14:36 -060018#include "GrRenderTargetPriv.h"
egdaniel9cb63402016-06-23 08:37:05 -070019#include "SkRect.h"
20
Brian Osman9a9baae2018-11-05 15:06:26 -050021void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040022 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050023 // A clear at this level will always be a true clear, so make sure clears were not supposed to
24 // be redirected to draws instead
25 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
26 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040027 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070028}
29
Greg Daniel500d58b2017-08-24 15:59:33 -040030void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050031 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
32 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040033 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070034}
35
Brian Salomon49348902018-06-26 09:12:38 -040036bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
37 const GrPipeline::FixedDynamicState* fixedDynamicState,
38 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
39 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
Chris Daltonbca46e22017-05-15 11:03:26 -060040#ifdef SK_DEBUG
Brian Salomon92be2f72018-06-19 14:33:47 -040041 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
Chris Daltonbca46e22017-05-15 11:03:26 -060042 for (int i = 0; i < meshCount; ++i) {
Chris Daltonb894c2b2017-06-14 12:39:19 -060043 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
Chris Dalton3809bab2017-06-13 10:55:06 -060044 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
Brian Salomon92be2f72018-06-19 14:33:47 -040045 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
Chris Dalton906430d2019-02-27 18:16:59 -070046 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
Chris Daltonbca46e22017-05-15 11:03:26 -060047 }
48#endif
Brian Salomond818ebf2018-07-02 14:08:49 +000049 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
Brian Salomon49348902018-06-26 09:12:38 -040050 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
51
Brian Salomon7eae3e02018-08-07 14:02:38 +000052 if (pipeline.isBad()) {
Robert Phillipsa91e0b72017-05-01 13:12:20 -040053 return false;
54 }
Robert Phillips12c46292019-04-23 07:36:17 -040055#ifdef SK_DEBUG
Brian Salomonf7232642018-09-19 08:58:08 -040056 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
Robert Phillips7eeb74f2019-03-29 07:26:46 -040057 GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
Brian Salomonf7232642018-09-19 08:58:08 -040058 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
Robert Phillips12c46292019-04-23 07:36:17 -040059 SkASSERT(processorProxies[i]->isInstantiated());
Brian Salomonf7232642018-09-19 08:58:08 -040060 }
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) {
Robert Phillips12c46292019-04-23 07:36:17 -040066 SkASSERT(textures[i]->isInstantiated());
Brian Salomon7eae3e02018-08-07 14:02:38 +000067 }
Greg Daniel9a51a862018-11-30 10:18:14 -050068 SkASSERT(meshCount >= 1);
69 const GrTextureProxy* const* primProcProxies =
70 dynamicStateArrays->fPrimitiveProcessorTextures;
71 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
72 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
73 GrTextureType type = primProcProxies[i]->textureType();
74 GrPixelConfig config = primProcProxies[i]->config();
75 for (int j = 1; j < meshCount; ++j) {
76 const GrTextureProxy* testProxy =
77 primProcProxies[j*primProc.numTextureSamplers() + i];
78 SkASSERT(testProxy->backendFormat() == format);
79 SkASSERT(testProxy->textureType() == type);
80 SkASSERT(testProxy->config() == config);
81 }
82 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000083 }
Robert Phillips12c46292019-04-23 07:36:17 -040084#endif
Robert Phillipsa91e0b72017-05-01 13:12:20 -040085
Brian Salomon92be2f72018-06-19 14:33:47 -040086 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070087 this->gpu()->stats()->incNumFailedDraws();
88 return false;
89 }
Brian Salomon49348902018-06-26 09:12:38 -040090 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
91 bounds);
Chris Dalton8c4cafd2019-04-15 19:14:36 -060092#ifdef SK_DEBUG
93 GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
94 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
95 processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
96 }
97 processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
98 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
99 // Verify we always have the same sample pattern key, regardless of graphics state.
100 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
101 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
102 }
103#endif
egdaniel9cb63402016-06-23 08:37:05 -0700104 return true;
105}