blob: 3876a424450213e106908a713401f41caaf1f9c6 [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"
11#include "include/gpu/GrContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrCaps.h"
13#include "src/gpu/GrContextPriv.h"
14#include "src/gpu/GrFixedClip.h"
15#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrMesh.h"
17#include "src/gpu/GrPrimitiveProcessor.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040018#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/GrRenderTargetPriv.h"
egdaniel9cb63402016-06-23 08:37:05 -070020
Greg Daniel2d41d0d2019-08-26 11:08:51 -040021void GrOpsRenderPass::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 Daniel2d41d0d2019-08-26 11:08:51 -040030void GrOpsRenderPass::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
Greg Daniel2d41d0d2019-08-26 11:08:51 -040036bool GrOpsRenderPass::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 }
Chris Dalton6f31cc32019-08-26 20:18:44 +000048#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
Robert Phillips82774f82019-06-20 14:38:27 -040052 SkASSERT(!pipeline.isBad());
53
Chris Dalton6f31cc32019-08-26 20:18:44 +000054#ifdef SK_DEBUG
Brian Salomonf7232642018-09-19 08:58:08 -040055 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
Robert Phillips7eeb74f2019-03-29 07:26:46 -040056 GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
Brian Salomonf7232642018-09-19 08:58:08 -040057 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
Robert Phillips12c46292019-04-23 07:36:17 -040058 SkASSERT(processorProxies[i]->isInstantiated());
Brian Salomonf7232642018-09-19 08:58:08 -040059 }
60 }
61 if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
62 int n = primProc.numTextureSamplers() * meshCount;
63 const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
64 for (int i = 0; i < n; ++i) {
Robert Phillips12c46292019-04-23 07:36:17 -040065 SkASSERT(textures[i]->isInstantiated());
Brian Salomon7eae3e02018-08-07 14:02:38 +000066 }
Greg Daniel9a51a862018-11-30 10:18:14 -050067 SkASSERT(meshCount >= 1);
68 const GrTextureProxy* const* primProcProxies =
69 dynamicStateArrays->fPrimitiveProcessorTextures;
70 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
71 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
72 GrTextureType type = primProcProxies[i]->textureType();
73 GrPixelConfig config = primProcProxies[i]->config();
74 for (int j = 1; j < meshCount; ++j) {
75 const GrTextureProxy* testProxy =
76 primProcProxies[j*primProc.numTextureSamplers() + i];
77 SkASSERT(testProxy->backendFormat() == format);
78 SkASSERT(testProxy->textureType() == type);
79 SkASSERT(testProxy->config() == config);
80 }
81 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000082 }
Robert Phillips12c46292019-04-23 07:36:17 -040083#endif
Robert Phillipsa91e0b72017-05-01 13:12:20 -040084
Brian Salomon92be2f72018-06-19 14:33:47 -040085 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070086 this->gpu()->stats()->incNumFailedDraws();
87 return false;
88 }
Brian Salomon49348902018-06-26 09:12:38 -040089 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
90 bounds);
Chris Dalton8c4cafd2019-04-15 19:14:36 -060091#ifdef SK_DEBUG
92 GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
93 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
94 processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
95 }
96 processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
97 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
98 // Verify we always have the same sample pattern key, regardless of graphics state.
99 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
100 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
101 }
102#endif
egdaniel9cb63402016-06-23 08:37:05 -0700103 return true;
104}