blob: 8626ada7d816a643b9dbf03c97cb9e51f211a201 [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"
Robert Phillips901aff02019-10-08 12:32:56 -040018#include "src/gpu/GrProgramInfo.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040019#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/GrRenderTargetPriv.h"
Chris Dalton4ece96d2019-08-30 11:26:39 -060021#include "src/gpu/GrTexturePriv.h"
egdaniel9cb63402016-06-23 08:37:05 -070022
Greg Daniel2d41d0d2019-08-26 11:08:51 -040023void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
Robert Phillips4912d902018-04-27 12:09:35 -040024 SkASSERT(fRenderTarget);
Michael Ludwigc39d0c82019-01-15 10:03:43 -050025 // A clear at this level will always be a true clear, so make sure clears were not supposed to
26 // be redirected to draws instead
27 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
28 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040029 this->onClear(clip, color);
egdaniel9cb63402016-06-23 08:37:05 -070030}
31
Greg Daniel2d41d0d2019-08-26 11:08:51 -040032void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
Michael Ludwigc39d0c82019-01-15 10:03:43 -050033 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
34 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
Robert Phillips19e51dc2017-08-09 09:30:51 -040035 this->onClearStencilClip(clip, insideStencilMask);
egdaniel9cb63402016-06-23 08:37:05 -070036}
37
Robert Phillips901aff02019-10-08 12:32:56 -040038bool GrOpsRenderPass::draw(const GrProgramInfo& programInfo,
Greg Daniel2d41d0d2019-08-26 11:08:51 -040039 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
Robert Phillips901aff02019-10-08 12:32:56 -040040 if (!meshCount) {
41 return true;
42 }
43
Chris Daltonbca46e22017-05-15 11:03:26 -060044#ifdef SK_DEBUG
Chris Dalton79f336d2020-02-11 14:42:56 -070045 SkASSERT(GrPrimitiveType::kPatches != programInfo.primitiveType() ||
46 this->gpu()->caps()->shaderCaps()->tessellationSupport());
Robert Phillips901aff02019-10-08 12:32:56 -040047 SkASSERT(!programInfo.primProc().hasInstanceAttributes() ||
48 this->gpu()->caps()->instanceAttribSupport());
Chris Daltonce425af2019-12-16 10:39:03 -070049 SkASSERT(!programInfo.pipeline().usesConservativeRaster() ||
50 this->gpu()->caps()->conservativeRasterSupport());
Chris Dalton1215cda2019-12-17 21:44:04 -070051 SkASSERT(!programInfo.pipeline().isWireframe() ||
52 this->gpu()->caps()->wireframeSupport());
Robert Phillips865d8d62019-10-09 14:15:55 -040053
Chris Dalton5a2f9622019-12-27 14:56:38 -070054 programInfo.compatibleWithMeshes(meshes, meshCount, *this->gpu()->caps());
Robert Phillips2d8a95e2019-10-10 12:50:22 -040055 programInfo.checkAllInstantiated();
56 programInfo.checkMSAAAndMIPSAreResolved();
Robert Phillips12c46292019-04-23 07:36:17 -040057#endif
Robert Phillipsa91e0b72017-05-01 13:12:20 -040058
Robert Phillips901aff02019-10-08 12:32:56 -040059 if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
egdaniel9cb63402016-06-23 08:37:05 -070060 this->gpu()->stats()->incNumFailedDraws();
61 return false;
62 }
Robert Phillips901aff02019-10-08 12:32:56 -040063 this->onDraw(programInfo, meshes, meshCount, bounds);
64
Chris Dalton8c4cafd2019-04-15 19:14:36 -060065#ifdef SK_DEBUG
Robert Phillips901aff02019-10-08 12:32:56 -040066 GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures();
Chris Dalton8c4cafd2019-04-15 19:14:36 -060067 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
68 // Verify we always have the same sample pattern key, regardless of graphics state.
69 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
70 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
71 }
72#endif
egdaniel9cb63402016-06-23 08:37:05 -070073 return true;
74}