blob: a33254e53ff14d6ec0af5befa60c5577c5f3fe4b [file] [log] [blame]
Robert Phillips865d8d62019-10-09 14:15:55 -04001/*
2 * Copyright 2019 Google LLC
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 "src/gpu/GrProgramInfo.h"
9
Robert Phillipsa87c5292019-11-12 10:12:42 -050010#include "src/gpu/GrStencilSettings.h"
11
12GrStencilSettings GrProgramInfo::nonGLStencilSettings() const {
13 GrStencilSettings stencil;
14
15 if (this->pipeline().isStencilEnabled()) {
16 stencil.reset(*this->pipeline().getUserStencil(),
17 this->pipeline().hasStencilClip(),
18 8);
19 }
20
21 return stencil;
22}
Robert Phillips865d8d62019-10-09 14:15:55 -040023
24#ifdef SK_DEBUG
25#include "src/gpu/GrTexturePriv.h"
26
Robert Phillips8053c972019-11-21 10:44:53 -050027void GrProgramInfo::validate(bool flushTime) const {
28 if (flushTime) {
29 SkASSERT(fPipeline->allProxiesInstantiated());
30 }
Robert Phillips865d8d62019-10-09 14:15:55 -040031
32 if (this->hasDynamicPrimProcTextures()) {
33 SkASSERT(!this->hasFixedPrimProcTextures());
Robert Phillips67a625e2019-11-15 15:37:07 -050034 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040035 } else if (this->hasFixedPrimProcTextures()) {
Robert Phillips67a625e2019-11-15 15:37:07 -050036 SkASSERT(fPrimProc->numTextureSamplers());
Chris Dalton012f8492020-03-05 11:49:15 -070037 // TODO: We will soon remove dynamic state from GrProgramInfo. But while migrating to the new
38 // bind/draw API on GrOpsRenderPass, some code will not set the dynamic state because it calls
39 // bindTextures() directly. Once dynamic state (including this validation code) is moved out of
40 // GrProgramInfo, we can restore this assert.
41 // } else {
42 // SkASSERT(!fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040043 }
44
Chris Dalton012f8492020-03-05 11:49:15 -070045
46 // TODO: We will soon remove dynamic state from GrProgramInfo. But while migrating to the new
47 // bind/draw API on GrOpsRenderPass, some code will not set the dynamic state because it calls
48 // setScissorRect() directly. Once dynamic state (including this validation code) is moved out
49 // of GrProgramInfo, we can restore this assert.
50#if 0
51 SkASSERT((fPipeline->isScissorTestEnabled()) ==
52 (this->hasFixedScissor() || this->hasDynamicScissors()));
53#else
54 if (!fPipeline->isScissorTestEnabled()) {
55 SkASSERT(!this->hasFixedScissor() && !this->hasDynamicScissors());
56 }
57#endif
Robert Phillips865d8d62019-10-09 14:15:55 -040058
59 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips865d8d62019-10-09 14:15:55 -040060 // Check that, for a given sampler, the properties of the dynamic textures remain
61 // the same for all the meshes
62 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
63 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0);
64
65 const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat();
Michael Ludwigfcdd0612019-11-25 08:34:31 -050066 GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType();
Robert Phillips865d8d62019-10-09 14:15:55 -040067
Robert Phillips2d8a95e2019-10-10 12:50:22 -040068 for (int m = 1; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -040069 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
70
71 auto testProxy = dynamicPrimProcTextures[s];
Michael Ludwigfcdd0612019-11-25 08:34:31 -050072 SkASSERT(testProxy->asTextureProxy());
Robert Phillips865d8d62019-10-09 14:15:55 -040073 SkASSERT(testProxy->backendFormat() == format);
Michael Ludwigfcdd0612019-11-25 08:34:31 -050074 SkASSERT(testProxy->backendFormat().textureType() == type);
Robert Phillips865d8d62019-10-09 14:15:55 -040075 }
76 }
77 }
78}
79
Robert Phillips2d8a95e2019-10-10 12:50:22 -040080void GrProgramInfo::checkAllInstantiated() const {
81 if (this->hasFixedPrimProcTextures()) {
82 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
83 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
84 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
85 }
86 }
87
88 if (this->hasDynamicPrimProcTextures()) {
89 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
90 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
91 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
92 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
93 }
94 }
95 }
96}
97
98void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Brian Salomonccb61422020-01-09 10:46:36 -050099 auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400100 SkASSERT(tex);
101
102 // Ensure mipmaps were all resolved ahead of time by the DAG.
103 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
104 (tex->width() != 1 || tex->height() != 1)) {
105 // There are some cases where we might be given a non-mipmapped texture with a mipmap
106 // filter. See skbug.com/7094.
107 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
108 !tex->texturePriv().mipMapsAreDirty());
109 }
110 };
111
112 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400113 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400114 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
115
116 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
117 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
118 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
119 }
120 }
121 } else if (this->hasFixedPrimProcTextures()) {
122 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
123
124 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
125 auto* tex = fixedPrimProcTextures[s]->peekTexture();
126 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
127 }
128 }
129
Brian Salomonc241b582019-11-27 08:57:17 -0500130 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
131 assertResolved(sampler.peekTexture(), sampler.samplerState());
Robert Phillips865d8d62019-10-09 14:15:55 -0400132 }
133}
134
Robert Phillips865d8d62019-10-09 14:15:55 -0400135#endif