blob: 7b97af43823f3e5f7d3790bf2c89c7c3303ac246 [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
Robert Phillips67a625e2019-11-15 15:37:07 -050042 SkASSERT(!fPipeline->isScissorEnabled() || 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();
52 GrTextureType type = dynamicPrimProcTextures[s]->textureType();
53 GrPixelConfig config = dynamicPrimProcTextures[s]->config();
54
Robert Phillips2d8a95e2019-10-10 12:50:22 -040055 for (int m = 1; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -040056 dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
57
58 auto testProxy = dynamicPrimProcTextures[s];
59 SkASSERT(testProxy->backendFormat() == format);
60 SkASSERT(testProxy->textureType() == type);
61 SkASSERT(testProxy->config() == config);
62 }
63 }
64 }
65}
66
Robert Phillips2d8a95e2019-10-10 12:50:22 -040067void GrProgramInfo::checkAllInstantiated() const {
68 if (this->hasFixedPrimProcTextures()) {
69 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
70 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
71 SkASSERT(fixedPrimProcTextures[s]->isInstantiated());
72 }
73 }
74
75 if (this->hasDynamicPrimProcTextures()) {
76 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
77 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
78 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
79 SkASSERT(dynamicPrimProcTextures[s]->isInstantiated());
80 }
81 }
82 }
83}
84
85void GrProgramInfo::checkMSAAAndMIPSAreResolved() const {
Robert Phillips865d8d62019-10-09 14:15:55 -040086
87 auto assertResolved = [](GrTexture* tex, const GrSamplerState& sampler) {
88 SkASSERT(tex);
89
90 // Ensure mipmaps were all resolved ahead of time by the DAG.
91 if (GrSamplerState::Filter::kMipMap == sampler.filter() &&
92 (tex->width() != 1 || tex->height() != 1)) {
93 // There are some cases where we might be given a non-mipmapped texture with a mipmap
94 // filter. See skbug.com/7094.
95 SkASSERT(tex->texturePriv().mipMapped() != GrMipMapped::kYes ||
96 !tex->texturePriv().mipMapsAreDirty());
97 }
98 };
99
100 if (this->hasDynamicPrimProcTextures()) {
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400101 for (int m = 0; m < fNumDynamicStateArrays; ++m) {
Robert Phillips865d8d62019-10-09 14:15:55 -0400102 auto dynamicPrimProcTextures = this->dynamicPrimProcTextures(m);
103
104 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
105 auto* tex = dynamicPrimProcTextures[s]->peekTexture();
106 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
107 }
108 }
109 } else if (this->hasFixedPrimProcTextures()) {
110 auto fixedPrimProcTextures = this->fixedPrimProcTextures();
111
112 for (int s = 0; s < this->primProc().numTextureSamplers(); ++s) {
113 auto* tex = fixedPrimProcTextures[s]->peekTexture();
114 assertResolved(tex, this->primProc().textureSampler(s).samplerState());
115 }
116 }
117
118 GrFragmentProcessor::Iter iter(this->pipeline());
119 while (const GrFragmentProcessor* fp = iter.next()) {
120 for (int s = 0; s < fp->numTextureSamplers(); ++s) {
121 const auto& textureSampler = fp->textureSampler(s);
122 assertResolved(textureSampler.peekTexture(), textureSampler.samplerState());
123 }
124 }
125}
126
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400127void GrProgramInfo::compatibleWithMeshes(const GrMesh meshes[], int meshCount) const {
128 SkASSERT(!fNumDynamicStateArrays || meshCount == fNumDynamicStateArrays);
129
130 for (int i = 0; i < meshCount; ++i) {
Robert Phillips67a625e2019-11-15 15:37:07 -0500131 SkASSERT(fPrimProc->hasVertexAttributes() == meshes[i].hasVertexData());
132 SkASSERT(fPrimProc->hasInstanceAttributes() == meshes[i].hasInstanceData());
Robert Phillips2d8a95e2019-10-10 12:50:22 -0400133 }
134}
135
Robert Phillips865d8d62019-10-09 14:15:55 -0400136#endif