blob: c3ac9de128e31c3325794b24983f262e627f7810 [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
Robert Phillips2d8a95e2019-10-10 12:50:22 -040025#include "src/gpu/GrMesh.h"
Robert Phillips865d8d62019-10-09 14:15:55 -040026#include "src/gpu/GrTexturePriv.h"
27
Robert Phillips8053c972019-11-21 10:44:53 -050028void GrProgramInfo::validate(bool flushTime) const {
29 if (flushTime) {
30 SkASSERT(fPipeline->allProxiesInstantiated());
31 }
Robert Phillips865d8d62019-10-09 14:15:55 -040032
33 if (this->hasDynamicPrimProcTextures()) {
34 SkASSERT(!this->hasFixedPrimProcTextures());
Robert Phillips67a625e2019-11-15 15:37:07 -050035 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040036 } else if (this->hasFixedPrimProcTextures()) {
Robert Phillips67a625e2019-11-15 15:37:07 -050037 SkASSERT(fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040038 } else {
Robert Phillips67a625e2019-11-15 15:37:07 -050039 SkASSERT(!fPrimProc->numTextureSamplers());
Robert Phillips865d8d62019-10-09 14:15:55 -040040 }
41
Chris Dalton2e7ed262020-02-21 15:17:59 -070042 SkASSERT(!fPipeline->isScissorTestEnabled() || this->hasFixedScissor() ||
Robert Phillips865d8d62019-10-09 14:15:55 -040043 this->hasDynamicScissors());
Robert Phillips865d8d62019-10-09 14:15:55 -040044
45 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips865d8d62019-10-09 14:15:55 -040046 // Check that, for a given sampler, the properties of the dynamic textures remain
47 // the same for all the meshes
48 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
49 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(0);
50
51 const GrBackendFormat& format = dynamicPrimProcTextures[s]->backendFormat();
Michael Ludwigfcdd0612019-11-25 08:34:31 -050052 GrTextureType type = dynamicPrimProcTextures[s]->backendFormat().textureType();
Robert Phillips865d8d62019-10-09 14:15:55 -040053
Robert Phillips2d8a95e2019-10-10 12:50:22 -040054 for (int m = 1; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -040055 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
56
57 auto testProxy = dynamicPrimProcTextures[s];
Michael Ludwigfcdd0612019-11-25 08:34:31 -050058 SkASSERT(testProxy->asTextureProxy());
Robert Phillips865d8d62019-10-09 14:15:55 -040059 SkASSERT(testProxy->backendFormat() == format);
Michael Ludwigfcdd0612019-11-25 08:34:31 -050060 SkASSERT(testProxy->backendFormat().textureType() == type);
Robert Phillips865d8d62019-10-09 14:15:55 -040061 }
62 }
63 }
64}
65
Robert Phillips2d8a95e2019-10-10 12:50:22 -040066void GrProgramInfo::checkAllInstantiated() const {
67 if (this->hasFixedPrimProcTextures()) {
68 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
69 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
70 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
71 }
72 }
73
74 if (this->hasDynamicPrimProcTextures()) {
75 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
76 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
77 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
78 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
79 }
80 }
81 }
82}
83
84void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Brian Salomonccb61422020-01-09 10:46:36 -050085 auto assertResolved = [](GrTexture* tex, GrSamplerState sampler) {
Robert Phillips865d8d62019-10-09 14:15:55 -040086 SkASSERT(tex);
87
88 // Ensure mipmaps were all resolved ahead of time by the DAG.
89 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
90 (tex->width() != 1 || tex->height() != 1)) {
91 // There are some cases where we might be given a non-mipmapped texture with a mipmap
92 // filter. See skbug.com/7094.
93 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
94 !tex->texturePriv().mipMapsAreDirty());
95 }
96 };
97
98 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -040099 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400100 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
101
102 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
103 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
104 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
105 }
106 }
107 } else if (this->hasFixedPrimProcTextures()) {
108 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
109
110 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
111 auto* tex = fixedPrimProcTextures[s]->peekTexture();
112 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
113 }
114 }
115
Brian Salomonc241b582019-11-27 08:57:17 -0500116 for (auto [sampler, fp] : GrFragmentProcessor::PipelineTextureSamplerRange(this->pipeline())) {
117 assertResolved(sampler.peekTexture(), sampler.samplerState());
Robert Phillips865d8d62019-10-09 14:15:55 -0400118 }
119}
120
Robert Phillips865d8d62019-10-09 14:15:55 -0400121#endif